Skip to content

fix(session): report the characters a request excerpt really drops - #868

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

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

Conversation

@aniruddhaadak80

Copy link
Copy Markdown
Contributor

What does this PR do, and why?

The compaction handoff tells the summarizer how large the request it is about to summarize was, and that number was inflated every time the request was too big to quote whole.

requestText quotes the opening ask and the closing instructions, with a marker between them:

const tail = Math.floor(max / 4)
const omitted = text.length - (max - tail)
return `${text.slice(0, max - tail).trimEnd()}\n[… ${omitted} characters omitted …]\n${text.slice(-tail).trimStart()}`

Both slices are kept, so the excerpt carries max characters, but omitted subtracts only max - tail and never counts the tail as kept — the same arithmetic the neighbouring tool-output cap had. A 50,000-character request with the default max = 2,000 keeps 1,500 + 500 = 2,000 characters and reports "48,500 characters omitted" for the 48,000 that are really gone. That count is the summarizer's only evidence about the size of what it is condensing, and it overstates it by a quarter of the excerpt budget.

The count now derives the two retained slices once and subtracts their real lengths, so it also accounts for the whitespace trimEnd()/trimStart() discard at the cut. The excerpt itself is byte-for-byte the same size and the same content as before; only the number changes.

Linked issue

small fix, no issue

How did you verify it?

Reproduction, before the fix (50,000-character request, default max = 2,000):

really dropped: 48,026
marker says omitted: 48,526   (overstates by 500)
EXIT=1

and with whitespace on both cuts:

really dropped: 50,604
marker says omitted: 50,900   (overstates by 296)

After the fix both report marker agrees and the script exits 0.

Tests and gates:

  • bun test --timeout 15000 ./test/session/compaction.test.ts — 76 pass, 0 fail, 1221 expect() calls (3 new assertions added to the existing requestText excerpt cases, in the session shard per tooling/repo/test-shards.ts)
  • Regression proof: reverting only backend/cli/src/session/compaction.ts and re-running gives 1 fail with omitted: 48526 received against 48026 expected — exactly the 500-character tail inflation. The test asserts the invariant (reported + still-quoted == request length) rather than a hard-coded formula, so it also pins the whitespace case.
  • 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

@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