Repository navigation
fix(agents): report pdf tool progress via onUpdate per extraction chunk - #228
Conversation
The pdf tool reads a large document in bounded batches (10 pages each) but gave zero feedback while doing so -- a long-running read looked identical to a hung one, and on the customer-facing channel path a document needing enough batches to exceed the turn's idle/hard timeout was silently killed with no signal anything was happening (ENG-20090: a 922-page PDF read ran past the 480s hard ceiling this way). Wires the existing AgentToolUpdateCallback mechanism (already used by the exec tool) through runPdfPrompt and createPdfTool's execute signature. Each chunk in the extraction loop now emits an update reporting the page range just read and its position in the batch sequence, before continuing to the next chunk. This alone does not remove the hard ceiling for documents that genuinely need more time than the turn budget allows -- see the companion AGENTS.md delegation-rule change (gandalf-manager PR openclaw#702) for the actual fix to that case (delegate to a sub-agent, which has no default timeout).
|
Claude encountered an error —— View job I'll analyze this and get back to you. |
There was a problem hiding this comment.
All reported issues were addressed across 2 files
Reply with feedback, questions, or to request a fix.
Fix all with cubic | Re-trigger cubic
…lysis cubic-dev-ai correctly caught (P1) that the prior fix only reported progress in the per-chunk analysis loop, which doesn't even start until getExtractions() has already finished extracting every batch. For a document large enough to need many batches, the entire extraction phase -- likely the actual long pole for a 900+ page PDF -- still gave zero progress signal, so the activity watchdog could still fire before extraction even finishes. Emits an update immediately after each extractPdfContent() call inside extractBatch, reporting the page range just extracted and the document's total page count once known. onUpdate is already in scope here via closure (it's a parameter of the enclosing execute()). Test changes: - Updated the existing progress test: now 12 updates total (6 extraction-phase + 6 analysis-phase) instead of 6, split and asserted separately by phase. - Added a new test using deferred extraction promises to prove progress arrives incrementally, one update per batch, strictly before the next batch's extraction even starts -- not just after the whole multi-batch extraction (or the tool call as a whole) has already finished. Co-Authored-By: Claude Sonnet 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01SuXgTCr2Rxmn3SAfbt5fjT
There was a problem hiding this comment.
All reported issues were addressed across 2 files (changes from recent commits).
Reply with feedback, questions, or to request a fix.
Fix all with cubic | Re-trigger cubic
check-lint (oxlint typescript(no-unnecessary-type-assertion)) correctly flagged 5 `!` assertions in the new deferred-extraction test as unnecessary -- this project doesn't have noUncheckedIndexedAccess enabled, so array index access is already typed as non-undefined without them. Co-Authored-By: Claude Sonnet 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01SuXgTCr2Rxmn3SAfbt5fjT
There was a problem hiding this comment.
All reported issues were addressed across 2 files (changes from recent commits).
Tip: Review your code locally with the cubic CLI to iterate faster.
Fix all with cubic | Re-trigger cubic
Three more real findings from cubic-dev-ai: - The extraction-phase progress message reported requestedPages (the full range asked for) instead of extracted.coverage.pagesProcessed (what was actually read). When a batch hits text_limit and gets recursively split, the outer call's requestedPages overstates what was actually extracted at that point. - A later extraction call's coverage can omit documentPageCount even though an earlier call already established it; the message and details now fall back to the already-tracked documentPageCount variable instead of losing a known value. - A throwing onUpdate subscriber would abort PDF processing entirely, since both onUpdate call sites invoked it directly with no guard. Added a small safeEmitUpdate helper (try/catch, matching the established emitToolProgress rationale in tools/common.ts: "progress is best-effort UI state; tool execution must not depend on subscribers") and used it at both call sites -- kept the existing content/details shape the exec tool precedent already established, rather than switching to emitToolProgress's separate progress-field shape, which would have been an unrelated behavioral change. Co-Authored-By: Claude Sonnet 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01SuXgTCr2Rxmn3SAfbt5fjT
augusteo
left a comment
There was a problem hiding this comment.
Review: #228 — approve
Approve covers d395cac7 specifically (no prior augusteo review on this SHA; checked immediately before submitting).
What was verified in code (not from the PR body):
- Mechanism is real and wired end-to-end.
AgentToolUpdateCallbackis defined atpackages/agent-core/src/types.ts:456withonUpdateas the 4thexecuteparam (:475); the pdf tool's new signature(_toolCallId, args, _signal, onUpdate)matchesToolExecuteArgsCurrentinsrc/agents/agent-tool-definition-adapter.ts. Every update lands inhandleToolExecutionUpdate(embedded-agent-subscribe.handlers.tools.ts:1026), which emits a toolupdateagent event per call — the same consumer path the exec tool already uses, and what channel-side activity tracking sees. - Extraction-phase progress fires DURING extraction (cubic P1, resolved): the
safeEmitUpdatesits insideextractBatchimmediately after each awaitedextractPdfContent(pdf-tool.ts ~:786), and batches are strictly sequential, so each update lands before the next batch starts. - Progress is accurate under text_limit splits (cubic P2, resolved): the emit uses
extracted.coverage?.pagesProcessed ?? requestedPagesanddocumentPageCountfalls back to the already-tracked total — no overstated ranges. - Throwing subscribers cannot abort the tool (cubic P2, resolved):
safeEmitUpdatewraps every call in try/catch, deliberately keeping the exec-style content/details shape rather thanemitToolProgress's separate progress-field shape — comment in code documents why. - Tests prove timing, not just counts (cubic test P2, resolved): the deferred-promise test blocks each of 6 extraction batches and asserts update N arrives before batch N+1 is allowed to start. The count test pins 12 updates (6 extraction + 6 analysis), strictly-increasing chunkIndex 1..6, and no 13th update from the synthesis call. Both read correctly against the implementation.
- All 5 cubic review threads are resolved (verified via GraphQL reviewThreads, not the PR body's say-so).
Local verification (this host):
pnpm vitest run src/agents/tools/pdf-tool.test.tsfrom a worktree atd395cac7: 2 files matched, 68/68 tests passed (the body says 66/66; substring matching pulled one extra 2-test sibling suite — all green either way).pnpm tsgo:core: clean, no type errors.- CI is not independently readable from this token (403 on check-runs); the local runs above are the substitute, taking reported CI as stated.
Non-blocking nit: the single-extraction fast path (extractions.length <= 1) returns without an analysis-phase update — fine, the extraction update already fired and that path is the fast case; and if chunkCoverage is ever undefined the analysis text renders "Read pages of ?" (cosmetic only, coverage is effectively always present).
The companion timeout fix (delegation rule, gandalf-manager#702, merged) correctly stays out of scope here — this PR's job is the progress signal, and it does exactly that.
Routine release chore for the next train. Root package.json to 2026.6.11-boon.44, plugin package.json files synced via scripts/sync-plugin-versions.ts, changed npm-shrinkwrap.json files regenerated via scripts/generate-npm-shrinkwrap.mjs --changed, and a CHANGELOG.md section for boon.44. Ships #225 (ENG-20103), #224, #228 (ENG-20090) and #227. No separately published plugin source changed since boon.43 (#227 moves diagnostics-otel into the gateway bundle), so a gateway roll delivers the whole release.
…226) Routine release chore for the next train. Root package.json to 2026.6.11-boon.44, plugin package.json files synced via scripts/sync-plugin-versions.ts, changed npm-shrinkwrap.json files regenerated via scripts/generate-npm-shrinkwrap.mjs --changed, and a CHANGELOG.md section for boon.44. Ships #225 (ENG-20103), #224, #228 (ENG-20090) and #227. No separately published plugin source changed since boon.43 (#227 moves diagnostics-otel into the gateway bundle), so a gateway roll delivers the whole release.
Summary
pdftool reads a large document in bounded batches (10 pages each) but gave zero feedback while doing so -- a long-running read looked identical to a hung one, and on the customer-facing channel path a document needing enough batches to exceed the turn's idle/hard timeout was silently killed with no signal anything was happening (ENG-20090: a 922-page PDF read ran past the 480s hard ceiling this way).AgentToolUpdateCallbackmechanism (already used by theexectool) throughrunPdfPromptandcreatePdfTool'sexecutesignature. Each chunk in the extraction loop now emits an update reporting the page range just read and its position in the batch sequence, before continuing to the next chunk.Test plan
onUpdatecall per chunk (6 chunks for a 59-page doc at the 10-page batch size), correct page-range text, and strictly-increasingchunkIndex.pdf-tool.test.tssuite: 66/66 passing.node scripts/run-tsgo.mjs -p tsconfig.core.json: clean, no type errors.🤖 Generated with Claude Code
https://claude.ai/code/session_01SuXgTCr2Rxmn3SAfbt5fjT
Summary by cubic
The
pdftool now emitsonUpdateprogress events per 10-page batch during extraction and analysis, so long-running PDF reads no longer look hung and aren't silently killed by the turn's idle/hard timeout (ENG-20090). Previously the tool reported activity only at start/finish; now each extraction batch and analysis chunk reports the page range just read and its position in the batch before continuing.AgentToolUpdateCallbackmechanism used by theexectool, wrapped so a throwing subscriber can't abort processing.text_limitno longer overstates progress; a batch that omits the page count falls back to the already-tracked total.gandalf-managerroutes those to a sub-agent with no default timeout.Written for commit d395cac. Summary will update on new commits.