Skip to content

fix(agents): report pdf tool progress via onUpdate per extraction chunk - #228

Merged
william-antoline-boon merged 5 commits into
boonfrom
fix/eng-20090-pdf-progress-signal
Sep 17, 2026
Merged

william-antoline-boon merged 5 commits into
boonfrom
fix/eng-20090-pdf-progress-signal

Conversation

@william-antoline-boon

@william-antoline-boon william-antoline-boon commented Sep 17, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • 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 Feature: Markdown rendering in Browser and Mac Node chat UIs openclaw/openclaw#702, merged) for the actual fix to that case: delegate to a sub-agent, which has no default timeout.

Test plan

  • New test: "reports progress via onUpdate once per extraction chunk" -- asserts one onUpdate call per chunk (6 chunks for a 59-page doc at the 10-page batch size), correct page-range text, and strictly-increasing chunkIndex.
  • Full pdf-tool.test.ts suite: 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 pdf tool now emits onUpdate progress 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.

  • Reuses the existing AgentToolUpdateCallback mechanism used by the exec tool, wrapped so a throwing subscriber can't abort processing.
  • Progress reports the pages actually processed per batch, not the full requested range, so a batch split on text_limit no longer overstates progress; a batch that omits the page count falls back to the already-tracked total.
  • Extraction-phase progress fires while extraction is still running, which is what resets the activity watchdog, since extraction is the long pole for large documents.
  • This alone doesn't remove the hard ceiling for documents that genuinely exceed the turn budget; the companion delegation-rule change in gandalf-manager routes those to a sub-agent with no default timeout.
  • Adds tests asserting one update per extraction batch arrives before the next batch starts, plus one update per analysis chunk with a strictly increasing chunk index.

Written for commit d395cac. Summary will update on new commits.

Review in cubic

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).
@william-antoline-boon
william-antoline-boon requested a review from a team September 17, 2026 04:05
@claude

claude Bot commented Sep 17, 2026 •

Copy link
Copy Markdown

Claude encountered an error —— View job


I'll analyze this and get back to you.

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

All reported issues were addressed across 2 files

Reply with feedback, questions, or to request a fix.

Fix all with cubic | Re-trigger cubic

Comment thread src/agents/tools/pdf-tool.ts Resolved
Comment thread src/agents/tools/pdf-tool.test.ts Resolved
…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

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

Comment thread src/agents/tools/pdf-tool.ts Resolved
Comment thread src/agents/tools/pdf-tool.ts Resolved
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

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

Comment thread src/agents/tools/pdf-tool.ts Resolved
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 augusteo left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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):

  1. Mechanism is real and wired end-to-end. AgentToolUpdateCallback is defined at packages/agent-core/src/types.ts:456 with onUpdate as the 4th execute param (:475); the pdf tool's new signature (_toolCallId, args, _signal, onUpdate) matches ToolExecuteArgsCurrent in src/agents/agent-tool-definition-adapter.ts. Every update lands in handleToolExecutionUpdate (embedded-agent-subscribe.handlers.tools.ts:1026), which emits a tool update agent event per call — the same consumer path the exec tool already uses, and what channel-side activity tracking sees.
  2. Extraction-phase progress fires DURING extraction (cubic P1, resolved): the safeEmitUpdate sits inside extractBatch immediately after each awaited extractPdfContent (pdf-tool.ts ~:786), and batches are strictly sequential, so each update lands before the next batch starts.
  3. Progress is accurate under text_limit splits (cubic P2, resolved): the emit uses extracted.coverage?.pagesProcessed ?? requestedPages and documentPageCount falls back to the already-tracked total — no overstated ranges.
  4. Throwing subscribers cannot abort the tool (cubic P2, resolved): safeEmitUpdate wraps every call in try/catch, deliberately keeping the exec-style content/details shape rather than emitToolProgress's separate progress-field shape — comment in code documents why.
  5. 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.
  6. 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.ts from a worktree at d395cac7: 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.

@william-antoline-boon
william-antoline-boon merged commit c57e349 into boon Sep 17, 2026
148 of 151 checks passed
@william-antoline-boon
william-antoline-boon deleted the fix/eng-20090-pdf-progress-signal branch September 17, 2026 09:22
orswn added a commit that referenced this pull request Sep 17, 2026
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.
orswn added a commit that referenced this pull request Sep 17, 2026
…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.
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.

2 participants