Skip to content

fix(opencode): do not read a tracked tool part for each streamed input delta - #1

Merged
TheFabFab merged 1 commit into
documentor-pgfrom
tool-delta-reads
Oct 9, 2026
Merged

TheFabFab merged 1 commit into
documentor-pgfrom
tool-delta-reads

Conversation

@TheFabFab

Copy link
Copy Markdown
Owner

Why

A DocuMentor production bug report (2026-10-08 16:52, "the chat says it will revise the workspace and doesn't") led to a 93-second, 10,248-token propose_document_changes call. While it streamed, Jaeger recorded about 10,200 SessionProcessor.readToolCall / Session.getPart spans and 10,400 sql.execute spans for that one session: every tool-input-delta goes through ensureToolCall, which reads the stored part back, though the delta writes nothing. Upstream reads a local SQLite file; on this branch each read is a Postgres round trip.

What

  • processor.ts: tool-input-delta and tool-input-end call ensureToolCall only for a call not yet in ctx.toolcalls (its part exists from tool-input-start).
  • test/pg/processor-tool-call.test.ts: streams 2,000 deltas and counts getPart calls — 2,004 before, under 10 after. It also pins the other half of the report: a tool's error text (here kpg-agent-tools' refusal of overlapping proposals) is stored whole and reaches the model as { type: "error-text", value: <full text> }.
  • documentor/FORK.md: the processor.ts row.

Verification

Local, Postgres 18 (C.UTF-8): the new test, and test/session/ in full (419 pass, 0 fail, 8 skip); bun run typecheck clean.

No release tag: publishing an image is a separate, operator-approved step.

🤖 Generated with Claude Code

…t delta

Every tool-input-delta and tool-input-end went through ensureToolCall, which
reads the stored part back: one database round trip per streamed chunk of a
tool call's arguments, though neither event writes anything. A 10k-token
document edit in production produced about 10,200 reads in 93 seconds. A
call already in ctx.toolcalls has its part from tool-input-start, so those
events now only create one when it is missing.

The test streams 2,000 deltas (2,004 reads before, under 10 after) and also
pins that a tool's error text reaches the model unchanged, as an error-text
tool result.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@github-actions

github-actions Bot commented Oct 8, 2026

Copy link
Copy Markdown

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • PR description is missing required template sections. Please use the PR template.

Please edit this PR description to address the above within 72 hours, or it will be automatically closed.

If you believe this was flagged incorrectly, please let a maintainer know.

@github-actions

github-actions Bot commented Oct 8, 2026

Copy link
Copy Markdown

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@TheFabFab
TheFabFab merged commit 1715a8b into documentor-pg Oct 9, 2026
6 of 11 checks passed
@TheFabFab
TheFabFab deleted the tool-delta-reads branch October 9, 2026 07:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant