Skip to content

fix(pool): settle tasks after worker failures - #186

Merged
jerome-benoit merged 3 commits into
masterfrom
fix/settle-worker-failures
Oct 16, 2026
Merged

jerome-benoit merged 3 commits into
masterfrom
fix/settle-worker-failures

Conversation

@jerome-benoit

@jerome-benoit jerome-benoit commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Faithful port of poolifier/poolifier#3343 at 8a2ee92d7.

  • Reject unfinished dispatched tasks without replay; preserve healthy tasks and redistribute queued work using current ownership and affinity, including bootstrap metadata fallback.
  • Preserve cancellation, isolate synchronous send failures, and defer backPressureEnd until removal handoffs complete. Settle tasks even if replacement construction throws.
  • Make worker termination idempotent, detach closed-channel handlers, and bridge Bun's native close to the existing worker-node exit signal. Keep pool restart/intentional-destruction policy unchanged.
  • Document the failure contract in docs/api.md; no new options, error classes or runtime dependencies.

Runtime adaptations

Node-only cluster/async-hooks/synchronous port-drain APIs are omitted. Deno/browser silent shutdown has no native exit notification; only responses received before cleanup are guaranteed. Bun close and Web ErrorEvent are handled directly. The buffered response/error regression checks this delivery boundary without assuming cross-channel event ordering.

Validation

  • Eight shared lifecycle method bodies match upstream after TypeScript transpilation/token normalization.
  • Two independent fidelity/correctness reviews: approved.
  • deno task format:check, deno task lint, deno check src/mod.ts, deno task bundle: passed.
  • Full suite: 19 suites, 300 passed steps, 9 ignored; coverage run: 93.3% lines / 92.7% branches.
  • Focused lifecycle/node suites: 44 passed steps.
  • Real Deno/Bun crash, healthy-task survival, migration and DataCloneError recovery smokes; Bun native silent-close recovery; Deno subprocess replacement-construction regression.
  • CI at c96a910d: all 15 checks successful, including Deno latest/LTS/canary, bundles, CodeQL and SonarCloud. No CI reruns.
  • Browser execution attempted but blocked by pre-existing worker runtime detection (src/utils.ts requires window); browser bundle builds. No workaround included.

PR Checklist

  • Conventional Commit title
  • Changes described
  • Behavioral regression tests
  • Applicable API documentation updated
  • Upstream task linked above

Does this PR introduce a breaking change?

  • Yes
  • No

Port poolifier/poolifier#3343 at 8a2ee92d7 with native Web Worker lifecycle adaptations.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-16T13:32:35.971090Z c96a910 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7fa51bc8a4

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/pools/abstract-pool.ts Resolved
@sonarqubecloud

Copy link
Copy Markdown

@jerome-benoit
jerome-benoit merged commit cca8fbb into master Oct 16, 2026
15 checks passed
@jerome-benoit
jerome-benoit deleted the fix/settle-worker-failures branch October 16, 2026 17:29
@jerome-benoit

Copy link
Copy Markdown
Contributor Author

Follow-up fidelity/correctness audit

Compared merged port cca8fbb2 (PR head c96a910d) with poolifier/poolifier#3343 at 8a2ee92d7, including all 40 failure regressions. Independent read-only review found no new patch-introduced defect or omitted applicable lifecycle hunk. Checked ownership/reindexing, exactly-once settlement, named/default/bootstrap affinity, cancellation routing, synchronous send and replacement failures, and removal-callback ordering.

Fresh native probes on both this revision and #188, under Deno and Bun, exercised crash → migration → queued cancellation → clone-error recovery, plus native worker removal from a structured-clone getter. Healthy tasks survived; captured total/per-function counters rolled back to zero; survivor counters stayed intact; no retained task promises or duplicate exit. Additional Bun self.close() probes on both revisions confirmed native-close rejection, queued migration and one exit. No browser execution claim.

Inherited issue, not a port omission: queued cancellation loses an Error-valued abort(reason) after reassignment. abortTask() deletes the wrapper before getAbortError() reads its signal (abstract-pool.ts:2609–2611 at this merge). The identical order exists before this PR (5372cd1e) and in upstream #3343 (1465–1468). Reproduced in both ports on Deno/Bun: cancellation rejects a generic task-aborted Error, not the supplied reason. This is distinct from detached-before-reassignment cancellation, whose reason-preserving behavior was ported and documented. A fix should be coordinated upstream and in the port, separately from fidelity changes.

No repository code changed during this audit. Temporary probes and reference worktrees removed.

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