Skip to content

fix(review): keep a fetched file distinguishable from an omitted one under thin budget - #8711

Merged
JSONbored merged 1 commit into
JSONbored:mainfrom
shin-core:fix/grounding-min-sample-fetched-file-8646
Jul 26, 2026
Merged

fix(review): keep a fetched file distinguishable from an omitted one under thin budget#8711
JSONbored merged 1 commit into
JSONbored:mainfrom
shin-core:fix/grounding-min-sample-fetched-file-8646

Conversation

@shin-core

Copy link
Copy Markdown
Contributor

What & why

Closes #8646.

review-grounding.ts's header guarantees (twice) that a file whose content is successfully fetched is "NEVER rendered as pure 'omitted' content again, no matter how large it grows" (#7465-class fix). fetchFullFileContents broke that: when cumulative used lands within MIN_SAMPLE_CHARS (400) of FILE_CONTENT_BUDGET (96,000), the computed share is too small, sampleHeadAndTail returns "" by design, and the fetched file gets pushed as { text: "", truncated: true } — the same empty placeholder a never-fetched file uses.

Consequence: the AI reviewer can't distinguish "fetched but budget ran out" from "never fetched" — both render identically, undermining the omission-tracking guarantee. test/unit/review-grounding.test.ts even asserted this broken behavior as correct.

The fix

Sample at the MIN_SAMPLE_CHARS floor for a genuinely-fetched file — sampleHeadAndTail(text, Math.max(share, MIN_SAMPLE_CHARS)) — so a fetched file always yields a minimal, non-empty head+tail with the omission marker. This is a small, bounded overrun of the overall budget only on the last thin file, not a per-file unbounded cost. A never-fetched file (text == null) still skips/omits, unchanged.

Tests

  • Updated the existing 1MB-src/huge.ts fixture test (was asserting { text: "", truncated: true }) to assert the corrected behavior: the fetched file is truncated but non-empty, carries genuine content (z), and includes the omission marker — verifiably distinguishable from a never-fetched file's empty placeholder.
  • The never-fetched → omitted path is still covered by the existing "nothing readable" test (requirement 2, unchanged).

Verified bug-catching: reverting the fix (back to the empty-placeholder degrade) fails the updated test.

Validation

  • test/unit/review-grounding.test.ts: 50 tests pass; typecheck clean; 100% of changed lines/branches covered.
  • Branched off current main, mergeable-clean.

…under thin budget

review-grounding.ts guarantees a file whose content is successfully fetched is
never rendered as the empty '(no content available)' placeholder a never-fetched
file uses. fetchFullFileContents broke that: when the remaining share fell below
MIN_SAMPLE_CHARS, sampleHeadAndTail returned '' and the fetched file was pushed as
{ text: '', truncated: true } -- identical to an unreadable file, so the AI
reviewer couldn't tell 'fetched but budget exhausted' from 'never fetched'. Sample
at the MIN_SAMPLE_CHARS floor for a genuinely-fetched file so it always carries a
minimal, distinguishing head+tail (a small bounded overrun only on the last thin
file). A never-fetched file (text == null) still skips/omits, unchanged. Updates
the existing 1MB-fixture test to assert the corrected, distinguishable output.
@shin-core
shin-core requested a review from JSONbored as a code owner July 26, 2026 00:14
@superagent-security superagent-security Bot added the contributor:flagged Contributor flagged for review by trust analysis. label Jul 26, 2026
@superagent-security

Copy link
Copy Markdown
Contributor

🚨 Contributor flagged. Click here for more info: Superagent Dashboard

@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.59%. Comparing base (8f4a1f4) to head (0347dab).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8711      +/-   ##
==========================================
+ Coverage   90.56%   90.59%   +0.03%     
==========================================
  Files          96       97       +1     
  Lines       22490    22589      +99     
  Branches     3884     3921      +37     
==========================================
+ Hits        20367    20465      +98     
  Misses       1945     1945              
- Partials      178      179       +1     
Flag Coverage Δ
backend 98.98% <100.00%> (?)

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

Files with missing lines Coverage Δ
src/review/review-grounding.ts 98.98% <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

Warning

⏸️ LoopOver review result - manual review recommended

Review updated: 2026-07-26 00:23:29 UTC

2 files · 1 AI reviewer · no blockers · CI green · unstable

⏸️ Suggested Action - Manual Review

Review summary
The fix correctly moves the MIN_SAMPLE_CHARS floor into the sampleHeadAndTail call at fetchFullFileContents.ts (was: `sampleHeadAndTail(text, share)` degrading to `{text:"",truncated:true}` when share fell below MIN_SAMPLE_CHARS; now: `sampleHeadAndTail(text, Math.max(share, MIN_SAMPLE_CHARS))`), so a genuinely-fetched file always yields a non-empty head+tail sample instead of the same empty placeholder a never-fetched file produces. I traced the overrun bound claim: since `used` is only ever incremented past FILE_CONTENT_BUDGET on this one thin-share branch, the very next loop iteration's `used >= FILE_CONTENT_BUDGET` guard fires before any further fetch, so the overrun really is capped to a single file, as described. The updated test exercises the real call path (three files, last one thin) and asserts non-empty text + marker + real content — a faithful, non-fabricated regression test for the #8646 bug.

Nits — 3 non-blocking
  • test/unit/review-grounding.test.ts: `expect(huge?.text).toContain("z")` is trivially true since the entire 1MB fixture is `z` repeated — it doesn't actually verify head/tail slicing correctness the way the earlier `sampleHeadAndTail` boundary tests do (e.g. asserting `startsWith`/`endsWith` on distinct head/tail markers) — consider a fixture with distinct head/tail sentinels for a stronger assertion.
  • review-grounding.ts:307-311's comment references 'fix(orb): review-grounding.ts's 'never rendered as omitted' guarantee breaks under thin remaining budget #8646' inline in code — fine, but worth double-checking that issue number matches the one this PR is meant to close (per the description it does).
  • Consider asserting in the test that `used` after this thin-file sample can exceed FILE_CONTENT_BUDGET by at most `MIN_SAMPLE_CHARS`, to lock in the 'small bounded overrun' invariant explicitly rather than only implicitly via the next-file skip behavior.
Flagged checks (non-blocking)
  • Contributor trust — Contributor flagged for review

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 #8646
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: 44 registered-repo PR(s), 24 merged, 0 issue(s).
Contributor context ✅ Confirmed Gittensor contributor shin-core; Gittensor profile; 44 PR(s), 0 issue(s).
Improvement ✅ Minor risk: clean · value: minor · LLM: moderate
Linked issue satisfaction

Addressed
The diff changes fetchFullFileContents to sample at Math.max(share, MIN_SAMPLE_CHARS) so a genuinely-fetched file always gets a non-empty sample instead of the empty placeholder, and updates the exact test at lines 548-562 to assert the corrected, distinguishable behavior on the same 1MB fixture while leaving the never-fetched path untouched.

Review context
  • Author: shin-core
  • Role context: outside_contributor
  • Public audience mode: oss maintainer
  • Lane context: Repository is configured for direct PR review.
  • Public profile languages: not available
  • Official Gittensor activity: 44 PR(s), 0 issue(s).
  • PR-specific overlap: none found.
Contributor next steps
  • Keep the PR focused and include validation evidence before maintainer review.
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.

@JSONbored
JSONbored merged commit 50966ab into JSONbored:main Jul 26, 2026
7 of 8 checks passed
JSONbored added a commit that referenced this pull request Jul 26, 2026
…of approving into a silent stall (#8758) (#8783)

PR #8711 exposed the seam: a non-required third-party check concluded
action_required, GitHub reported mergeable_state "unstable", and ORB's four
surfaces disagreed — the unified comment said Manual Review, approve fired
("gate satisfied and CI is green"), the ready-to-merge label landed, the merge
silently self-suppressed (mergeableClean requires "clean"), and the only
record of why lived in an internal audit_events row. A human had to notice.

- heldForManualReview gains a mergeableState === "unstable" term: no approve,
  no ready-to-merge label, manual-review label + comment naming the culprit
  non-required check(s) (threaded via the CI aggregate's
  nonRequiredFailingDetails; generic wording when unitemized).
- New 1f fallback mirrors 1d so the hold stays visible on repos where
  review_state_label autonomy isn't acting but merge is.
- The executor live-rechecks mergeable_state before posting an approve
  (denied on live dirty/unstable, fails open on ambiguous reads), the same
  #3863-shaped guard merge-adjacent actions already had.
- dirty/behind/blocked semantics deliberately unchanged: dirty stays the
  close path, behind stays the rebase rail's, blocked stays approvable (the
  approval itself can be the unblocking act).

Co-authored-by: loopover-orb[bot] <296761690+loopover-orb[bot]@users.noreply.github.com>
JSONbored added a commit that referenced this pull request Jul 26, 2026
…umed by planner, comment, and labels (#8800)

* refactor(disposition): one shared mergeable-state interpretation consumed by planner, comment, and labels (#8759)

The #8711 incident's root CLASS: four surfaces each re-derived their own
meaning for GitHub's raw mergeable_state string (comment {dirty,behind,
unstable}; merge !== clean; approve {dirty}; hold-label none pre-#8758).
#8758 unified the predicates; this removes the class:

- src/settings/pr-disposition.ts (new, pure, dependency-free):
  assessMergeableState — THE single raw-string interpretation point — and
  derivePrDisposition (heldForManualReview / wouldApprove / wouldMerge /
  commentMergeStateHeld), each semantic documented as a contract.
- agent-actions.ts derives the disposition once and consumes its fields for
  heldForManualReview, the approve gate, and canMerge; isConflict routes
  through assessMergeableState. Byte-identical: all 308 existing planner
  tests pass unchanged.
- unified-comment.ts's readiness gains mergeStateHeld — resolved by
  processors.ts via isCommentMergeStateHeld so the self-contained renderer
  consumes a boolean instead of re-deriving meaning (zero-import contract
  intact); legacy callers keep the byte-identical raw-string fallback.
- test/unit/pr-disposition-invariants.test.ts: the cross-surface invariant
  suite — module invariants over the full state matrix, planner-vs-
  disposition agreement per state, renderer-vs-disposition agreement through
  the bridge boolean, and the legacy-fallback equivalence pin.

* test(disposition): include the #8759 mergeStateHeld field in the merge-facts exact-shape expectation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor:flagged Contributor flagged for review by trust analysis. 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(orb): review-grounding.ts's 'never rendered as omitted' guarantee breaks under thin remaining budget

2 participants