Skip to content

Cap tool results at 20KB; restore full vault text on disk with grep-first steering#27

Merged
teddy-paris merged 1 commit into
mainfrom
agent/CD-1284-right-layer-caps
Jul 13, 2026
Merged

Cap tool results at 20KB; restore full vault text on disk with grep-first steering#27
teddy-paris merged 1 commit into
mainfrom
agent/CD-1284-right-layer-caps

Conversation

@teddy-paris

Copy link
Copy Markdown
Contributor

Why revisit #22

Session-log forensics on the incident (linc_sess_a40eptlm7ebo59u50kl23m62, the customer usage burn):

  1. The context stuffing came through the pi read tool: its limit is in lines, and 200–300 lines of legal text returned 40–50K chars per result — capped by the existing 50KB byte limit, i.e. nine maxed-out reads ≈ 450K chars into context → 190K-token context re-billed across 103 model calls.
  2. Those reads targeted the vault text and the agent's own 40K-char drafts — the 10K vault-file cap doesn't bound the latter at all, so it wouldn't have prevented the incident.
  3. The file on disk was never the cost. Disk is outside model context; grep over the complete text returns a few lines. The verified large-document flow (23M-char production doc → grep → page-cited answer in 5.5 min) requires the complete file — under the 10K cap that document is unsearchable past page ~3, which regresses the CD-1282/1284 capability shipping in casedotdev-mono #1977.

Changes

  • DEFAULT_MAX_BYTES 50KB → 20KB (core/tools/truncate.ts) — bounds what any single read/find/grep result can pull into billed context, for every file, agent-authored drafts included. Offset pagination + the existing truncation notices already guide continuation.
  • readCaseDevVaultObjectText writes the full text to disk again; the result note and both tool descriptions steer grep-first: "locate content with grep -n, read narrow line ranges, never page the full text."

Not in this PR (follow-ups being ticketed)

  • Bounding the 502 retry storm (21 provider-error stops in 2 minutes at the incident's tail, each re-billing the cached context) — retry machinery deserves a careful change, not an under-deadline one.
  • The events read model records every toolResult twice (ledger-side duplication).

Tests: full coding-agent suite 1,427 passed / 0 failed.

Counterpart casedotdev-mono PR (baked helper + templates + 0.79.6 pin) follows once this releases.

🤖 Generated with Claude Code

…ault text on disk

Production forensics on the incident behind the 10K vault-text cap
(#22) showed the context ballooning came through the pi read tool —
its limit is denominated in LINES, and 200-300 lines of legal text
returned 40-50K chars per result, nine times, on BOTH the vault text
and the agent's own drafts. The on-disk file was never the cost: disk
is outside model context, and grep over the complete text is what
makes large-document analysis work (a 23M-char production document
becomes unsearchable past page ~3 under a 10K file cap).

- DEFAULT_MAX_BYTES 50KB -> 20KB: bounds what any single read/find/
  grep result can drag into billed context; offset pagination and the
  existing truncation notices handle continuation
- readCaseDevVaultObjectText writes the FULL text to disk again; the
  result note and tool descriptions now steer grep-first ("locate with
  grep -n, read narrow ranges, never page the full text")
- tests updated accordingly (1427 passing)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@vercel

vercel Bot commented Jul 13, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
linc-docs Ready Ready Preview, Comment Jul 13, 2026 7:12pm

label: "vault_read_text",
description:
"Write up to the first 10,000 characters of an ingested matter document's extracted text into the workspace as a .txt file. Use targeted vault searches for additional context.",
"Write the full extracted text of an ingested matter document into the workspace as a .txt file, page-numbered when the source is paginated. The right tool for comprehensively analyzing document content at any size: locate content with grep -n and read only narrow line ranges around matches; never page the full text into the conversation.",

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale promptSnippet/promptGuidelines strings for the vault read-text tools contradict the updated full-text/grep-first tool descriptions, injecting conflicting guidance into the system prompt.

Fix on Vercel

@teddy-paris teddy-paris merged commit 45d3c4f into main Jul 13, 2026
6 checks passed
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.

3 participants