Skip to content

fix(orb): review-grounding.ts's 'never rendered as omitted' guarantee breaks under thin remaining budget #8646

Description

@JSONbored

⚠️ Definition of Done: this issue must be completed in full, in a single PR. Do not split this
work across multiple PRs, and do not defer any Deliverable below to a follow-up issue. A PR that
satisfies only some of the Deliverables, stubs a required test, or leaves a checkbox
partially-done does NOT resolve this issue and will be closed.

Context

src/review/review-grounding.ts's module header states, twice (lines 79-80 and 360-362), that a
file the grounding fetch successfully reads is "NEVER rendered as pure 'omitted' content again, no
matter how large it grows" — the fix for the #7465 class of bug.

That guarantee is broken by fetchFullFileContents (lines 297-319): when cumulative used lands
within MIN_SAMPLE_CHARS (400 chars) of FILE_CONTENT_BUDGET (96,000 chars), the computed share
becomes too small, sampleHeadAndTail returns "" by its own design (if (budget < MIN_SAMPLE_CHARS) return "", around line 106), and the file — despite being genuinely fetched —
gets pushed into the result as { text: "", truncated: true }. formatFilesSection renders that
exact shape as the same "(no content available...)" placeholder the header says can't happen for a
successfully-read file.

test/unit/review-grounding.test.ts:548-562 ("falls all the way back to full omission when the
remaining share is too thin for even a sample") already exercises this with a genuinely-fetched 1MB
src/huge.ts fixture, proving the contradiction is live today, not hypothetical — the test currently
asserts the broken behavior as if it were correct.

Consequence: the AI reviewer cannot distinguish "the file was fetched but the budget ran out before
any content could be sampled" from "the file was never fetched at all" — both render identically as
an empty placeholder, undermining the entire point of the omission-tracking guarantee this module
exists to provide.

Requirements

  • Reserve a minimum non-zero sample budget for any file that was genuinely fetched, even when the
    remaining overall budget share computed for it falls below MIN_SAMPLE_CHARS — so a
    successfully-read file always yields at least some distinguishing sampled text, never the same
    empty placeholder used for a never-fetched file.
  • Do not change behavior for files that were never fetched at all (the legitimate "omitted" case
    must still render as omitted).
  • Update test/unit/review-grounding.test.ts:548-562 to assert the corrected behavior: a
    genuinely-fetched 1MB file's rendered output must be distinguishable from a never-fetched file's
    output, even under extreme budget pressure.

Deliverables

  • fetchFullFileContents (or sampleHeadAndTail) is changed so a file that was genuinely
    fetched always receives at least a minimal non-empty sample, never the { text: "", truncated: true } shape currently produced under thin remaining budget.
  • formatFilesSection's rendering of a genuinely-fetched, thin-budget file is verifiably
    different from its rendering of a never-fetched file (distinct enough that the AI reviewer's
    prompt can tell the two cases apart).
  • test/unit/review-grounding.test.ts:548-562 is updated (not deleted) to assert the corrected
    behavior for the exact same 1MB src/huge.ts fixture it already uses.
  • The module header's claim (lines 79-80, 360-362) is verified true again by the updated test.

All four Deliverables are required in the same PR.

Test Coverage Requirements

src/** is measured by codecov/patch (99%+ target, branch-counted). The updated test must
exercise both the "thin remaining budget, file fetched" branch and the "file never fetched" branch
in the same test file, asserting they now produce distinguishable output.

Expected Outcome

A file the grounding pipeline successfully fetches is never rendered identically to a file that was
never fetched at all, restoring the guarantee this module's own header claims to provide.

Links & Resources

Metadata

Metadata

Assignees

No one assigned

    Labels

    gittensor:bugGittensor-scored bug fix — scores a 0.05x multiplier.help wantedExtra attention is needed

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions