Skip to content

fix(session): report the characters a capped tool result really drops - #867

Open
ANIRUDDHA ADAK (aniruddhaadak80) wants to merge 1 commit into
synthetic-sciences:mainfrom
aniruddhaadak80:fix/tool-output-omitted-count
Open

ANIRUDDHA ADAK (aniruddhaadak80) wants to merge 1 commit into
synthetic-sciences:mainfrom
aniruddhaadak80:fix/tool-output-omitted-count

Conversation

@aniruddhaadak80

Copy link
Copy Markdown
Contributor

What does this PR do, and why?

A tool result that gets cut down for a reduced-fidelity handoff is reported with a marker counting how many characters were left out. The count was wrong in one direction, every time.

capOutput keeps the head of the result and then re-appends its tail:

const tail = Math.floor(max / 5)
const omitted = text.length - (max - tail)
return `${text.slice(0, max - tail).trimEnd()}\n[… ${omitted} characters of this result omitted for the handoff …]\n${text.slice(-tail).trimStart()}`

The two slices together carry max characters, but omitted subtracts only max - tail — the tail is never counted as kept, even though the very next expression prints it. The marker therefore over-reports the omission by exactly tail characters. A 10,000-character result cut to 2,000 keeps 2,000 characters and drops 8,000, but the marker reads "8,400 characters of this result omitted for the handoff". The model reading the handoff is told a 400-character stretch was removed that it is in fact looking at.

The count now derives the two retained slices once and subtracts their real lengths, so it also accounts for the whitespace trimEnd()/trimStart() discards at the cut.

Linked issue

small fix, no issue

How did you verify it?

Reproduction, before the fix (10,000-character result, max = 2000):

marker reports = 8,400
really dropped = 8,000
over-report by = 400
BUG = true

After the fix:

marker reports = 8,000
really dropped = 8,000
over-report by = 0
BUG = false

A second fixture with whitespace on both cuts behaves the same way (it reported 2,000 dropped for 1,603 really dropped).

Tests and gates:

  • bun test --timeout 15000 ./test/session/cap-output.test.ts — 3 pass, 0 fail (3 new tests, in the session shard per tooling/repo/test-shards.ts)
  • bun test --timeout 15000 ./test/session/message-v2.test.ts — the existing message tests are unchanged and pass
  • Regression proof: with only backend/cli/src/session/message-v2.ts reverted and the new test left in place, 2 of the 3 new tests fail (Expected: 8000 / Received: 8400 and Expected: 1603 / Received: 2000); the third, which covers the unmarked case, still passes.
  • bun run typecheck in backend/cli — exit 0
  • Prettier: checked against the committed blobs rather than this Windows working tree, which checks markdown out as CRLF and so reports a false failure. On the exact blob bytes CI will read: All matched files use Prettier code style!

Not run locally: the full bun run --cwd backend/cli test suite (~10 min) and Deep CI.

Checklist

  • bun run check is green (format, typecheck, backend + frontend/ui + SDK tests) — run the touched shard, the backend typecheck and the format check; the full bun run check aggregate was not run locally
  • bun run --cwd frontend/workspace build succeeds if I touched frontend/workspace or frontend/ui — not applicable
  • ./tooling/repo/generate.ts was run and the tooling/sdk output committed if I changed backend/cli/src/server — not applicable
  • CHANGELOG.md has an Unreleased entry if the change is user-visible
  • The matching docs page under frontend/docs/src/content/openscience/ is updated if behavior changed — the marker wording is unchanged, only the number it prints
  • Screenshots or a short video are attached for UI changes — not applicable
  • No version bumps (package.json versions and tags are written by the release workflow)
  • install and frontend/landing/public/install are still byte-identical if I touched either — not applicable

The marker counted only the head it cut, so the tail the same line keeps was reported as omitted: a 10,000-character result cut to 2,000 said 8,400 omitted while all 2,000 kept characters were shown. Count both retained slices, less the whitespace the trims drop at the cut.
@vercel

vercel Bot commented Sep 30, 2026

Copy link
Copy Markdown

ANIRUDDHA ADAK (@aniruddhaadak80) is attempting to deploy a commit to the InkVell Team on Vercel.

A member of the Team first needs to authorize it.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant