Files
Rdmclin2 91f36af7de 🐛 fix(agent-runtime): dedupe archived tool results by content and page readKnowledge (#19665)
* 🐛 fix: dedupe archived tool results by content and page readKnowledge

Archived tool results were keyed by `{topicId}_{toolCallId}`, so the same
oversized knowledge-base read persisted a byte-identical document per topic,
and the `.tool-results` root folder could be created twice under concurrency.
`readKnowledge` also returned whole files, which pushed almost every call past
the archive threshold and bloated the model context.

- Archive under `./.tool-results/{sha256(content)}.txt`; reuse an existing
  identical archive and only add the topic binding. Fall back to
  `{hash}_{toolCallId}.txt` when the hash path holds different content.
- Run mkdir/stat/write/verify/associate inside one transaction guarded by a
  per-agent `pg_advisory_xact_lock`, so concurrent archives cannot create
  duplicate root folders or duplicate rows.
- `readKnowledge` returns a bounded window per file (default 400 lines,
  10k chars) with `offset`/`limit` for paging; the prompt carries the line
  range and a continue hint, the card shows the range, and the manifest and
  system role tell the model to page instead of re-reading.

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

* 🐛 fix: enforce the readKnowledge char cap on oversized single lines

A line longer than the per-call cap (minified JSON, generated text) was
returned whole, which defeated the bound and could still push the tool result
past the archive threshold. Cut such a line at the cap, keep advancing one
line so paging cannot stall, and tell the model the line was cut and where to
continue.

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

---------

Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-18 23:24:11 +08:00
..