Skip to content

fix(miner): AmsPolicySpec parse warnings are computed but never surfaced to the operator - #8978

Merged
loopover-orb[bot] merged 1 commit into
JSONbored:mainfrom
phamngocquy:miner/issue-8853
Jul 26, 2026
Merged

fix(miner): AmsPolicySpec parse warnings are computed but never surfaced to the operator#8978
loopover-orb[bot] merged 1 commit into
JSONbored:mainfrom
phamngocquy:miner/issue-8853

Conversation

@phamngocquy

Copy link
Copy Markdown
Contributor

Summary

resolveAmsPolicy() (packages/loopover-miner/lib/ams-policy.ts:18-22,53-63,74-88) returns a warnings: string[] specifically to surface a malformed .loopover-ams.yml field (per-field messages generated at packages/loopover-engine/src/ams-policy-spec.ts:163,170,179,188,195,213, e.g. AmsPolicySpec field "capLimits" must be a mapping; falling back to defaults.). .loopover-ams.yml.example explicitly documents "a single malformed field falls back to its default with a warning." But the only two real callers, packages/loopover-miner/lib/attempt-cli.ts (lines 693,758,775,874-875,995) and packages/loopover-miner/lib/loop-cli.ts (lines 309,434-437), read only .spec and discard .warnings/.source entirely -- never logged or printed. This contradicts the package's own stated design philosophy, honored elsewhere in the same package: discover-cli.ts:406 prints ai-policy warnings: ${result.warnings.length} and line 424 explicitly surfaces a goal-spec fallback rather than staying silent (README:43-44's documented rationale, "explicit rather than silent"). Additionally, readLocalAmsPolicyContent (ams-policy.ts:53-63) treats an unreadable existing file identically to an absent one (source: "default", warnings: [] either way), so a permissions error on an operator's real policy file is indistinguishable from never having configured one.

Deliverables

  • attempt-cli.ts prints non-empty amsPolicy.warnings in both human and --json output modes
  • loop-cli.ts prints non-empty amsPolicy.warnings in both human and --json output modes
  • A test for each of the two files asserting a malformed .loopover-ams.yml fixture produces visible warning output (not just a silently-defaulted policy)

All of the above Deliverables are required in the same PR unless the deliverable text itself states otherwise.

Test plan

packages/loopover-miner/** -- 99%+ patch coverage on both changed files, covering the non-empty-warnings branch in both human and JSON modes.

Fixes #8853

@phamngocquy
phamngocquy requested a review from JSONbored as a code owner July 26, 2026 14:49
@superagent-security

Copy link
Copy Markdown
Contributor

Superagent didn't find any vulnerabilities or security issues in this PR.

@codecov

codecov Bot commented Jul 26, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.79%. Comparing base (266b07d) to head (a4abee6).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8978      +/-   ##
==========================================
+ Coverage   90.56%   90.79%   +0.23%     
==========================================
  Files          96       99       +3     
  Lines       22490    23052     +562     
  Branches     3884     4076     +192     
==========================================
+ Hits        20367    20929     +562     
  Misses       1945     1945              
  Partials      178      178              
Flag Coverage Δ
backend 100.00% <100.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
packages/loopover-miner/lib/ams-policy.ts 100.00% <100.00%> (ø)
packages/loopover-miner/lib/attempt-cli.ts 100.00% <100.00%> (ø)
packages/loopover-miner/lib/loop-cli.ts 100.00% <100.00%> (ø)

@loopover-orb loopover-orb Bot added the gittensor:bug Gittensor-scored bug fix — scores a 0.05x multiplier. label Jul 26, 2026
@loopover-orb

loopover-orb Bot commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

Tip

✅ LoopOver review result - approve/merge recommended

Review updated: 2026-07-26 15:00:33 UTC

6 files · 1 AI reviewer · no blockers · readiness 93/100 · CI green · clean

✅ Suggested Action - Approve/Merge

  • safe to merge

Review summary
This PR wires the already-existing resolveAmsPolicy warnings/source fields through to visible output in both attempt-cli.ts and loop-cli.ts, via two new small helpers in ams-policy.ts (amsPolicyWarningJsonFields, renderAmsPolicyWarnings). It correctly threads warnings into JSON payloads and human-readable console lines at every real return point (dry_run excluded, correctly, since no policy is resolved yet), and adds regression tests exercising an actual malformed .loopover-ams.yml fixture through both CLIs' human and --json paths, which is real coverage of the real path (not a fabricated one). The unrelated token-obfuscation churn in the test files (fakeGithubToken etc.) is scope creep beyond the stated deliverables but appears to be pre-existing repo convention (secret-scanner workaround) rather than a new pattern invented for this PR.

Nits — 5 non-blocking
  • packages/loopover-miner/lib/loop-cli.ts:663-665 — amsPolicyWithWarnings is only ever set from the LAST cycle's amsPolicy that had non-empty warnings, and the summary output only reports that one; if a multi-repo/multi-cycle loop hits warnings on an earlier cycle then a clean one, the final human/JSON summary still shows the earlier warning even though per-cycle records only attach amsPolicyWarningJsonFields to the cycle where it actually occurred — this is a reasonable simplification but worth a one-line comment or a `warningCount` note since the top-level summary field can look stale relative to `cycles`.
  • The unrelated `fakeGithubToken`/`fakeGithubLoopToken`/password-obfuscation edits across miner-loop-cli.test.ts and miner-attempt-cli.test.ts are outside this PR's stated deliverables (surfacing AMS warnings) — worth calling out as scope creep even though it looks like a repo-wide secret-scanner convention rather than new risk.
  • packages/loopover-miner/lib/ams-policy.ts:24-38 — the two new exported helpers take a loosely-typed `{ source: string; warnings: string[] }` rather than the concrete `ResolvedAmsPolicy`/`AmsPolicySource` type already defined two lines above; consider tightening to `Pick<ResolvedAmsPolicy, "source" | "warnings">` for consistency.
  • Both attempt-cli.ts and loop-cli.ts are already very large files (1064 and 671 lines) that this PR adds further lines to — not a blocker, but the pattern of adding cross-cutting concerns (warnings surfacing) directly into these mega-files rather than a shared render layer keeps growing them.
  • Consider a per-cycle `note` or explicit `hadWarnings` boolean on the final loop summary so a reader can tell whether the top-level amsPolicySource/amsPolicyWarnings reflect the most recent cycle or a stale earlier one.

Decision drivers

  • ✅ Code review — No blockers (1 reviewer)
  • ✅ Gate result — Passing (No configured blocker found.)
Context & advisory signals — never blocks the verdict
Signal Result Evidence
Linked issue ✅ Linked #8853
Related work ✅ No active overlap found No same-issue or scoped active PR overlap found.
Change scope ✅ 20/20 Low review scope from cached public metadata (1 linked issue).
Validation posture ✅ 25/25 PR body includes validation/test evidence.
Contributor workload ✅ 10/10 Author activity: 1 registered-repo PR(s), 0 merged, 0 issue(s).
Contributor context ✅ Confirmed Gittensor contributor phamngocquy; Gittensor profile; 1 PR(s), 0 issue(s).
Improvement ✅ Minor risk: clean · value: minor · LLM: moderate
Linked issue satisfaction

Addressed
The diff adds amsPolicyWarningJsonFields/renderAmsPolicyWarnings helpers matching discover-cli's phrasing and wires them into both attempt-cli.ts and loop-cli.ts human and --json output paths, with dedicated regression tests in both CLI test files plus unit tests for the new helpers covering the malformed .loopover-ams.yml fixture scenario.

Review context
  • Author: phamngocquy
  • Role context: outside_contributor
  • Public audience mode: oss maintainer
  • Lane context: Repository is configured for direct PR review.
  • Public profile languages: Java, Python, Lua, Jupyter Notebook, C, Dockerfile, JavaScript, Shell
  • Official Gittensor activity: 1 PR(s), 0 issue(s).
  • PR-specific overlap: none found.
Contributor next steps
  • Start here: Triage stale or unlinked PRs.
Signal definitions
  • Related work = same linked issue, overlapping active PRs, or title/path similarity.
  • Change scope = cached public metadata such as size labels, draft state, and review-burden hints.
  • Validation posture = whether the PR provides enough public validation/test evidence for maintainer review.
  • Contributor workload = public contributor activity and cleanup pressure, not a repo-wide quality failure.
  • Contributor context = public GitHub/Gittensor identity context; non-Gittensor status is not a blocker.
🧪 Chat with LoopOver

Ask LoopOver a question about this PR directly in a comment — grounded only in the same cached, public-safe facts shown above, never a new claim.

  • @loopover ask &lt;question&gt; answers contribution-quality Q&A with source citations and freshness.
  • @loopover chat &lt;question&gt; answers in natural prose from cached decision-pack facts via local inference (maintainer/collaborator; read-only).
  • A plain-language @loopover mention with a real question is routed to the closest matching read-only command automatically — no exact syntax required.

Full command reference: https://loopover.ai/docs/loopover-commands

🧪 Experimental — new and may change.

🟩 Safe / merged · 🟦 Advisory · 🟨 Held for review · 🟥 Blocked / closed


💰 Earn for open-source contributions like this. Gittensor lets GitHub contributors earn for the work they already do — register to start earning →.

Checked by LoopOver, a quiet PR intelligence layer for OSS maintainers.

  • Re-run LoopOver review

@loopover-orb loopover-orb Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LoopOver approves — the gate is satisfied and CI is green.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gittensor:bug Gittensor-scored bug fix — scores a 0.05x multiplier.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(miner): AmsPolicySpec parse warnings are computed but never surfaced to the operator

1 participant