fix: restart resumes the process loop and the pulse emitter - #90
Open
jbiskur wants to merge 2 commits into
Open
Conversation
`restart()` calls `stop(true)`, which clears `running`, empties the buffer and stops the pulse emitter. The fetch loop revives itself from `restartTo`, but the process loop exits on `running` and only `start()` brought it back. A pump restarted while it was delivering kept pulling events and never delivered or checkpointed again — and stopped pulsing, so it looked dead to the control plane while its host reported healthy. This is the defect described on 2026-04-14 in Usable fragment 28875215-003d-4770-9d44-8e3488d25246. It stalled two production data-pathways pathways for 26 days (2026-08-02 → 2026-08-28): 417b8dd9-b6a3-4ce9-b254-6ea12ca97d57 and 5a32bd1c-9d0c-4aef-a813-4fee60280f8e. - `ensureProcessLoop()` starts the delivery loop whenever the pump is running with a processor and no loop is live. The fetch loop calls it every iteration, so a loop that exits for any reason comes back within one iteration instead of leaving a pump that pulls but never delivers. - `processLoopRunning` guards against a second loop when the existing one is only parked in `reserve()`. Two loops would race over the same buffer. - A loop that exits while the pump is running again — the restart landed mid-batch — restarts itself. - The restart path starts the pulse emitter again. `PulseEmitter.start()` is already idempotent. Tests: delivery continues after a restart issued from inside the handler; no second loop when one is parked; the pulse emitter is started again. All three fail on the previous behaviour. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
restart()callsstop(true), which clearsrunning, empties the buffer and stops the pulse emitter. The fetch loop revives itself fromrestartTo:But the process loop is a
while (this.running)loop and onlystart()calledstartProcessLoop(). A pump restarted while it was delivering keeps pulling events and never delivers or checkpoints again — and stops pulsing, so it looks dead to the control plane while its host still reports healthy.This is the defect written up on 2026-04-14 in Usable fragment
28875215-003d-4770-9d44-8e3488d25246.Production impact
It stalled two
data-pathwayspathways for 26 days (2026-08-02 → 2026-08-28):417b8dd9-b6a3-4ce9-b254-6ea12ca97d575a32bd1c-9d0c-4aef-a813-4fee60280f8eactiveA scoped replay asked for one flow type; the consumer restarted every source, and every restarted pump went quiet.
Change
ensureProcessLoop()starts the delivery loop whenever the pump is running with a processor and no loop is live. The fetch loop calls it once per iteration, so a loop that exits for any reason comes back within one iteration.processLoopRunningguards against a second loop when the existing one is only parked inreserve()— two loops would race over the same buffer.pulseEmitter.start()again. It is already idempotent.Tests
Three new cases in
data-pump-restart.test.ts, all of which fail on the previous behaviour:restart()issued from inside the handlerSuite: 57 pass / 0 fail.
tsc --noEmitandprettier --checkclean.🤖 Generated with Claude Code