Skip to content

[Bug] Snapshot worker pool: no false 'worker died', real lost-chunk count (stacked on #513) - #520

Merged
mcop1 merged 1 commit into
feature/index-snapshot-export-importfrom
fix/snapshot-worker-pool-exit-race
Sep 23, 2026
Merged

mcop1 merged 1 commit into
feature/index-snapshot-export-importfrom
fix/snapshot-worker-pool-exit-race

Conversation

@mcop1

@mcop1 mcop1 commented Sep 23, 2026

Copy link
Copy Markdown
Contributor

Changes in this pull request

Stacked on #513 (base branch feature/index-snapshot-export-import); the worker pool only exists there. Merge this into #513's branch before #513 itself is squash-merged.

  • False "worker died": WorkerPoolBulkDispatcher::pump() read a worker's output before checking whether it still ran. A worker that wrote its last OK line and exited in between was taken for one that died with chunks pending, which failed a healthy import. The running state is now checked first; everything written before the exit is read and handled afterwards.
  • Wrong lost-chunk count: the "worker died" message read the pending count after abort() had cleared it and always said 0 chunk(s). The count is captured before the abort.

Additional info

Tests: testAWorkerThatDiesReportsHowManyChunksWereLost fails without the fix (reported "0 chunk(s)"). testAWorkerThatExitsRightAfterItsLastAnswerIsNotReportedAsDead is a guard: the race window is microseconds, so it cannot be forced deterministically; the fix is by ordering. Locally: snapshot unit suite 68 OK, snapshot functional suite 37 OK, PHPStan and php-cs-fixer clean.

Both findings come from Copilot's suppressed note on #513 and a code reading during the CI-hang investigation (the hang itself was the test helper, see #519).

🤖 Generated with Claude Code

… the real number of lost chunks

pump() read a worker's output before checking whether it still ran. A
worker that wrote its last answer and exited in between was taken for
one that died with chunks pending, failing a healthy import. The running
state is now checked first; everything written before the exit is read
and handled afterwards.

The "worker died" message read the pending count after abort() had
cleared it and always said "0 chunk(s)"; the count is captured first.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings September 23, 2026 17:47
@sonarqubecloud

Copy link
Copy Markdown

@mcop1 mcop1 self-assigned this Sep 23, 2026
@mcop1 mcop1 added this to the 2.5.13 milestone Sep 23, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟢 Approved

The focused implementation correctly addresses both reported defects with appropriate regression coverage.

Review effort: Balanced
Findings: None

What changed in this PR

Fixes worker-pool shutdown handling and accurately reports chunks lost when a snapshot replay worker dies.

Changes:

  • Processes buffered worker output before declaring an exited worker dead.
  • Captures the pending chunk count before abort cleanup.
  • Adds regression tests for both scenarios.
File Description
src/​Service/​SearchIndex/​Snapshot/​WorkerPoolBulkDispatcher.php Corrects worker exit handling and lost-chunk reporting.
tests/​Unit/​Service/​SearchIndex/​Snapshot/​WorkerPoolBulkDispatcherTest.php Adds regression coverage for worker exit races and lost chunks.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@mcop1
mcop1 merged commit 7fc20e0 into feature/index-snapshot-export-import Sep 23, 2026
11 of 12 checks passed
@mcop1
mcop1 deleted the fix/snapshot-worker-pool-exit-race branch September 23, 2026 17:50
@github-actions github-actions Bot locked and limited conversation to collaborators Sep 23, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants