Skip to content

fix(workers): prevent PDF cancellation from aborting Node - #150752

Merged
steipete merged 2 commits into
mainfrom
upd/flake-zlib-close-before-init
Sep 17, 2026
Merged

steipete merged 2 commits into
mainfrom
upd/flake-zlib-close-before-init

Conversation

@steipete

@steipete steipete commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

Related: #150494 — observed in CI run 35193123721, job 105110271154.

What Problem This Solves

Fixes Node aborting when PDF extraction is cancelled while PNG compression is initializing a native zlib handle. The failing stripe printed Google Meet export results immediately before the abort, but the reproduced producer was the PDF extraction worker.

User Impact

Cancelling PDF extraction returns the cancellation result and permits subsequent documents to run. PDF rendering stays immediately cancellable; cancellation during PNG encoding waits for that bounded operation and worker exit. No configuration, dependency, Node-version, or persistence changes are required.

Why This Change Was Made

The pool closes native-section admission atomically and waits for active sections before terminating a worker. Workers cannot enter another native section after cancellation; PDF extraction checks cancellation between pages, and admission capacity stays reserved until worker exit. Only PNG encoding is fenced. The worker-side server is extracted into a sibling module to retain the existing line cap and public exports.

This PR also touches the native wrapper component inventory, scripts/pr-lib/wrapper-components.txt: the pool eagerly imports worker-task-native-sections.ts and reexports worker-task-server.ts, so both modules must be materialized with the wrapper. Exactly those two entries were added in lexical order.

The existing task deadline requests cancellation; it cannot safely force termination through a stuck native call. Native sections must therefore contain bounded operations, not rendering, network waits, or an entire document.

Named follow-up — Archived-history zstd cancellation fence: src/config/sessions/archive-compression.ts:70 synchronously decompresses archive data reached from src/gateway/session-transcript-archive-reader.ts:223 and the history-page worker at src/config/sessions/session-transcript.worker.ts:189. The reader/materialization layers do not carry task control, and the codec API is synchronous. A separate change must propagate task control to the codec, preserve the synchronous reader contract, and add its regression proof. Fencing the entire history read would also defer cancellation during unrelated I/O.

Evidence

  • Linux, Node 24.19.0: the same pool-boundary fixture on the original pool terminates with SIGABRT, close before init, and the fatal HandleScope error. The repaired abort, timeout, close, and unexpected-worker-exit cases all exit 0. Focused pool validation: 51 tests passed.
  • 20 serial PDF-suite runs and 20 serial config-changed extension-stripe runs passed. Each PDF run passed 23 tests; each stripe passed 1,293 tests, preserving its 12 existing skips. Stripe command: OPENCLAW_VITEST_MAX_WORKERS=2 node scripts/run-vitest.mjs run --config test/vitest/vitest.extensions.config.ts --shard=2/6.
  • Testbox validation: run 35196936382, lease tbx_01m2q5s8ddshbeqr8a70h2a7bb; command result exit 0, lease stopped and verified completed. The provider command result is the proof; external lease cleanup can cancel the enclosing Actions workflow.
  • Cancellation latency in the synthetic pool probe, ten outside-native samples each: median 7.00 ms before → 6.46 ms after (maxima 9.18 ms and 9.51 ms). The repaired fenced-abort probe settled in 6.82 ms from cancellation, 6.28 ms after its native gate was released.
  • macOS focused validation passed 51 pool tests and 23 PDF tests. Local full-stripe limitation: no completed tests before the 120-second no-output watchdog stopped it with exit 143. The maintainer classified this as host overload on a Mac with sustained load above 50; it was not rerun or given a longer timeout. Hosted macOS lanes are the proof of record for the full stripe on that platform.
  • Before the two-line inventory correction, changed checks: all selected steps passed using the authorized nested-checkout extension-lint substitution. The wrapper hit Declaration input escapes checkout; direct oxlint --tsconfig test/tsconfig/tsconfig.extensions.test.json caught the temporary no-explicit-any canary (exit 1), then all four real extension files passed (exit 0). The canary was removed, and all eight remaining guards passed.
  • Committed-branch Codex autoreview: --mode branch --base origin/main --max-priority P1, scoped-clean, no actionable P0/P1 findings. Artifact: l555-branch-review.md with status artifact l555-branch-review-status.json.
  • Wrapper correction validation: the eager runtime import-closure regression passed. The macOS provisioning suite finished 17 passed, 1 skipped, 1 failed in 1,139.93 seconds; its cold/warm sparse-transition case at test/scripts/pr-worktree-provision.test.ts:378 took 139.97 seconds against a 120-second test budget on host load 55–123. The maintainer classified this as host overload and directed publication with hosted CI as proof. No rerun, timeout increase, or test change; the remaining local wrapper suites and another changed-check run were not run.
  • Inventory correction Codex autoreview: scoped-clean at P0/P1; artifact l555-inventory-review.md, status l555-inventory-review-status.json.
  • LOC: production +308/−132, tests/support +369/−81, docs +15, wrapper inventory +2.
  • Current head: a2f7a594fdfa5cba7337570b1de59f0365c571ec, rebased onto main 9ee5c26f4080b4f63243897c904243802efbc3bf. Verified that main contains the fix(runtime): close Bun watcher and harness gaps #150655 fix at 5764fa493344c0a041e0bc8319c07585d649b18e. Both lane commits are unchanged (=) in git range-diff; no conflict resolution or semantic changes.
  • pnpm install --frozen-lockfile passed in 18.2 seconds. The worktree remained clean.
  • Exact-head pull_request CI GREEN: run 35208006886 at a2f7a594fdfa5cba7337570b1de59f0365c571ec. Native watcher exited 0 with github_rollup=SUCCESS, pending=0, and GREEN. The previous red run was not rerun. Ready for maintainer landing; not merged.

Maintainer disposition of ClawSweeper feedback

Reviewed ClawSweeper revision 3 on the exact head above. It reports no correctness findings. Both merge-risk items are accepted under the scoped landing instruction:

  • Bounded native wait: retain the recommended wait. Interrupting zlib initialization can abort the entire Node process; only pixel- and dimension-bounded PNG encoding is fenced. Rendering stays immediately cancellable, and admission capacity remains charged until worker exit. A stuck native operation can still delay cancellation or closure beyond the deadline; that documented tradeoff is accepted. No forced-termination fallback or timeout change is added.
  • SDK termination deferral: retain the additive third handler argument and documented bounded-operation contract. Existing handlers remain compatible. Plugins must keep rendering, network waits, user input, and unbounded work outside the fence. No further code change is needed for this review item.

No Rank-up code changes are outstanding. The archived-history zstd fence remains the named separate follow-up above.

@clawsweeper

clawsweeper Bot commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@steipete
steipete marked this pull request as ready for review September 17, 2026 08:40
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation extensions: document-extract size: L maintainer Maintainer-authored PR labels Sep 17, 2026
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 17, 2026
@clawsweeper

clawsweeper Bot commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 17, 2026, 6:31 AM ET / 10:31 UTC (Revision 4).

ClawSweeper review

What this changes

The PR makes PDF cancellation wait for bounded PNG compression before stopping its worker, adds a documented worker-control API, and updates regression coverage and tooling imports.

Merge readiness

✅ Ready for maintainer review

The fix remains necessary and has no blocking correctness findings. The recorded maintainer disposition resolves the previous review’s tradeoff questions; no additional review action is required.

Priority: P1
Reviewed head: a2f7a594fdfa5cba7337570b1de59f0365c571ec

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, well-supported repair with no blocking findings and explicit disposition of the native-wait and SDK tradeoffs.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The submitted Node 24.19.0 before/after evidence exercises the actual pool with real zlib initialization and shows clean cancellation, joined worker exit, and subsequent work; the inspected PDF caller fences that same native path.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The submitted Node 24.19.0 before/after evidence exercises the actual pool with real zlib initialization and shows clean cancellation, joined worker exit, and subsequent work; the inspected PDF caller fences that same native path.
Evidence reviewed 9 items Atomic cancellation and worker custody: Native-section entry uses compare-and-exchange; retirement atomically closes admission before waiting. Cancellation retains the slot, input accounting, and compute permit until worker exit. Unexpected exit releases native waiters.
Narrow production fence: Only encodePng is fenced. Rendering remains outside the fence; cancellation checks prevent encoding or another page after cancellation. The renderer preserves pixel allocation, dimension limits, forms, and text fallback.
Verified dependency contract: The production import of clawpdf establishes the dependency signal. npm metadata identifies openclaw/clawpdf and gitHead 636ef3eaa32c4be964601cfa67f06e75ec833c4e for pinned version 0.3.2. Its PNG implementation calls Node deflateSync; inspection of the published rendering implementation also confirms dimension rounding and embedded-rotation handling.
Findings None None.
Security None None.

How this fits together

The document-extraction plugin sends PDFs to a reusable worker and returns extracted text or page images. The shared worker pool owns cancellation, worker termination, and capacity release.

flowchart TD
  A[PDF extraction request] --> B[Shared worker pool]
  B --> C[Extract text and render pages]
  C --> D[Bounded PNG compression]
  E[Cancellation or deadline] --> F[Close native admission]
  F --> D
  D --> G[Join worker exit]
  G --> H[Release capacity and settle cancellation]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +176, Tests +288, Docs +15, Other +2. Total +481 across 13 files.

View PR surface stats
Area Files Added Removed Net
Source 7 308 132 +176
Tests 4 369 81 +288
Docs 1 15 0 +15
Config 0 0 0 0
Generated 0 0 0 0
Other 1 2 0 +2
Total 13 694 213 +481

Review metrics

Metric Value Why it matters
Production versus regression coverage Production +176 net lines; tests/support +288 net lines Production growth implements atomic native-operation custody and separates rendering from compression; regression coverage checks process survival and cancellation ordering.

Technical review

Best possible solution:

Retain the documented, narrowly bounded PNG fence and immediate cancellation elsewhere, with archived-history compression handled separately.

Do we have a high-confidence way to reproduce the issue?

Yes: the inspected production-pool fixture targets cancellation during real zlib initialization, and the submitted Node 24.19.0 evidence reports the original abort. This read-only review did not rerun it.

Is this the best way to solve the issue?

Yes: the existing pool owns safe retirement, while the PDF plugin fences only compression; the documented deadline and SDK tradeoffs have been explicitly accepted.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 3bbe54346069.

Labels

Label changes:

  • remove merge-risk: 🚨 compatibility: Current PR review selected no merge-risk labels.
  • remove merge-risk: 🚨 availability: Current PR review selected no merge-risk labels.

Label justifications:

  • P1: Cancelling PDF extraction can abort the Node process, disrupting the running Gateway.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The submitted Node 24.19.0 before/after evidence exercises the actual pool with real zlib initialization and shows clean cancellation, joined worker exit, and subsequent work; the inspected PDF caller fences that same native path.
  • proof: sufficient: Contributor real behavior proof is sufficient. The submitted Node 24.19.0 before/after evidence exercises the actual pool with real zlib initialization and shows clean cancellation, joined worker exit, and subsequent work; the inspected PDF caller fences that same native path.

Evidence

What I checked:

  • Atomic cancellation and worker custody: Native-section entry uses compare-and-exchange; retirement atomically closes admission before waiting. Cancellation retains the slot, input accounting, and compute permit until worker exit. Unexpected exit releases native waiters. (src/infra/worker-task-pool.ts:626, a2f7a594fdfa)
  • Narrow production fence: Only encodePng is fenced. Rendering remains outside the fence; cancellation checks prevent encoding or another page after cancellation. The renderer preserves pixel allocation, dimension limits, forms, and text fallback. (extensions/document-extract/document-extractor.runtime.ts:149, a2f7a594fdfa)
  • Verified dependency contract: The production import of clawpdf establishes the dependency signal. npm metadata identifies openclaw/clawpdf and gitHead 636ef3eaa32c4be964601cfa67f06e75ec833c4e for pinned version 0.3.2. Its PNG implementation calls Node deflateSync; inspection of the published rendering implementation also confirms dimension rounding and embedded-rotation handling. (src/png.ts:76, 636ef3eaa32c)
  • Current main still needs the fix: At the supplied current-main revision, retirement still calls terminate without a native-section wait, and PDF extraction still invokes the combined image-extraction operation. (src/infra/worker-task-pool.ts:618, 3bbe54346069)
  • Latest release lacks the native wait: The v2026.9.4 worker pool also terminates directly. No merged replacement in the supplied related context fixes this cancellation behavior. (src/infra/worker-task-pool.ts:478, 3a9d69db306c)
  • Production-boundary cancellation evidence: The captured PR body reports SIGABRT on the original pool under Node 24.19.0 and successful repaired abort, timeout, close, and unexpected-exit cases. The inspected fixture uses the real worker pool and real deflateSync, pauses native initialization, and asserts retained capacity, native completion, worker disappearance, and successor execution. The captured sourceRevision is 5390b9d0bc051c22f1ee6a08e8458f8a32532900de67afef0d37aa2892023727. Testbox log retrieval was blocked at its storage redirect; unseen logs are not claimed as inspected, and this review did not execute tests. (src/infra/worker-task-pool.native-sections.test-support.ts:32, a2f7a594fdfa)

Likely related people:

  • Peter Steinberger: Raw commit d72a144 adds extensions/document-extract/document-extractor.runtime.ts:9 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: d72a144e7b01; files: extensions/document-extract/document-extractor.runtime.ts)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (3 earlier review cycles)
  • reviewed 2026-09-17T08:50:21.992Z sha b4be7685b87c7ac206ae0ef085abc50f00be4e1e :: blocked before merge. :: none
  • reviewed 2026-09-17T09:30:17.927Z sha e915d8a33976d003c658384cac69f30a5341fb78 :: blocked before merge. :: none
  • reviewed 2026-09-17T10:09:55.874Z sha a2f7a59 :: blocked before merge. :: none

@openclaw-barnacle openclaw-barnacle Bot added the scripts Repository scripts label Sep 17, 2026
@steipete
steipete force-pushed the upd/flake-zlib-close-before-init branch from cb6a70d to e915d8a Compare September 17, 2026 09:19
Fence bounded native operations before worker retirement and keep PDF rendering immediately cancellable. Hold admission until native completion and worker exit, and cover cancellation, deadlines, close, and unexpected exit.

Observed in CI run 35193123721, job 105110271154. Linux Node 24.19 reproduces SIGABRT before the fix and exits cleanly after it; 20 PDF and extension-stripe repetitions pass. The required macOS stripe remains blocked by a no-output watchdog failure, so publication is withheld.
@steipete
steipete force-pushed the upd/flake-zlib-close-before-init branch from e915d8a to a2f7a59 Compare September 17, 2026 09:58
@clawsweeper clawsweeper Bot removed merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. labels Sep 17, 2026
@steipete
steipete merged commit 15f2583 into main Sep 17, 2026
230 checks passed
@steipete
steipete deleted the upd/flake-zlib-close-before-init branch September 17, 2026 10:38
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

steipete added a commit that referenced this pull request Sep 17, 2026
Restore the configured pnpm store before activation so warm CI jobs reuse the pinned wrapper and native executable archives without another registry download. Verify private archive copies with the existing SHA-512 pins, retain image and registry fallback, and preserve bootstrap archives during dependency repair. The existing warmer remains the cache publisher.

Update isolated archive fixtures, acceptance guards, and CI documentation for the cache-first bootstrap. Store v2 and dependency v4 entries reseed once; application behavior and user data are unchanged.

Validation: exact-head CI run 35217823757 is green with no pending checks; retained hosted cold/warm proof records zero archive downloads on the warm run. The package-acceptance suite passed 558 tests on three full runs, followed by 23 final focused tests. The campaign review and exact-head ClawSweeper review report no actionable correctness findings.

Related: #150752, #150725.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 18, 2026
…50752)

Fix Node aborting when PDF extraction is cancelled during native PNG compression. Related: openclaw#150494; reproduced in CI run 35193123721, job 105110271154.

The shared worker pool atomically closes native-section admission and waits for active native work before terminating the worker. PDF extraction fences only pixel- and dimension-bounded PNG encoding, checks cancellation between pages, and keeps rendering immediately cancellable. Admission and execution capacity remain reserved until worker exit. The existing worker SDK exports and handlers stay compatible, and the two extracted pool modules are included in the native wrapper inventory.

Cancellation can wait beyond its deadline if a fenced native operation gets stuck; the bounded-operation SDK contract documents this accepted tradeoff. Archived-history zstd cancellation remains a separate follow-up. No configuration, dependency, Node-version, or persistence changes are required.

Validation: Linux Node 24.19.0 reproduced SIGABRT before the fix and clean abort, timeout, close, and unexpected-exit cases afterward. The author recorded 51 pool tests, 23 PDF tests, and 20 serial PDF and extension-stripe repetitions passing. Hosted exact-head CI run 35208006886 is green; local full-stripe and provisioning timing limitations are documented in the PR. Codex autoreview and the exact-head ClawSweeper review found no actionable P0/P1 correctness findings.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 18, 2026
Restore the configured pnpm store before activation so warm CI jobs reuse the pinned wrapper and native executable archives without another registry download. Verify private archive copies with the existing SHA-512 pins, retain image and registry fallback, and preserve bootstrap archives during dependency repair. The existing warmer remains the cache publisher.

Update isolated archive fixtures, acceptance guards, and CI documentation for the cache-first bootstrap. Store v2 and dependency v4 entries reseed once; application behavior and user data are unchanged.

Validation: exact-head CI run 35217823757 is green with no pending checks; retained hosted cold/warm proof records zero archive downloads on the warm run. The package-acceptance suite passed 558 tests on three full runs, followed by 23 final focused tests. The campaign review and exact-head ClawSweeper review report no actionable correctness findings.

Related: openclaw#150752, openclaw#150725.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation extensions: document-extract maintainer Maintainer-authored PR P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. scripts Repository scripts size: L status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant