Skip to content

Commit 3d1165f

Browse files
authored
fix(workflow): drain the lane's queue when a takeover reap ends a run (#2789)
Drain the lane's queue when a takeover reap ends a run (#2787). Fixes #2787 Owner: Dev-5 Reviewer: Birfy Written-by: Dev-5 Bot: Dev-5 Risk tier: T3 (path rule T2; risk-gate bumps by size — 365 changed lines > T2's 250) Base: 74d08c5 Claim-Id: 1f80bc23d7b74967b0fea86f03af325f ## What changed `takeover()` — the first writable call after this window started read-only — re-reads `workflows.json` and runs the load-time reap on that adopted store. That reap ended the dead window's run as `host-ended`, but unlike `reap()` it never drained `lane.queue`, so a card parked behind that run stayed queued until some unrelated assign or ingest. #2757 fixed the same hole for `reap()` only. `plugins/workflow/src/service.js` extracts `reapOnce()` = `reapRuns()` then `hostSerial(() => drainAll())`. `takeover()` calls it, and `reap()` returns the in-flight takeover (`takingOver ?? reapOnce()`) instead of stacking a second drain on top — the drain stays on the serial tail, so #2757's cap-1 race stays closed. `docs/subsystems/workflow.md` §3: the takeover sentence now says the reap itself leaves `lane.queue` alone and the drain that follows the reap starts the card, and notes a takeover reap drains like the load reap. A changelog fragment is added. ## Red first On the merged tree with `plugins/workflow/src/service.js` taken from base `74d08c5d` (blob `bae4c7e6`): ```text takeover-transition-drain.test.js # tests 2 # pass 0 # fail 2 not ok 1 - the takeover reap starts the card parked behind the run it ends (#2787) the parked card did not start after the takeover reap ended the run actual [] / expected ['dead-queued'] not ok 2 - a takeover reap drains like the load reap, and a later reap does not drain twice (#2787) terminal-transition-drain.test.js # tests 8 # pass 7 # fail 1 not ok 8 - every terminal transition drains: a takeover reap ``` `terminal-transition-drain.test.js` is the P-682 table: one bench (cap 1 plus a card parked behind the running one) and one row per terminal transition — step done, step failed, deadline, Stop, Reset, graph edit dropping a running node, load reap, takeover reap. Every row but the takeover reap is already green at base, so the table pins the gap without changing source. Injecting each drain removal turns only its own row red (step done/failed share `afterStep`, the two reaps share `reapOnce`); reverting only the takeover line turns just the two #2787 tests and the table's takeover row red. ## Ran at this tip ```text $ (cd plugins/workflow && TZ=UTC npm test) # tests 528 # pass 528 # fail 0 $ npm_config_cache=<worktree>/.cache/npm node scripts/lint-plugins.mjs Found 16 warnings and 0 errors. (existing warnings) lint-plugins: packed @flybot/workflow imported $ node .github/scripts/changelog.mjs check changelog: 20 fragment(s) in changelog.d/ are well formed $ ARCH_DOCS_BASE=74d08c5dab7a6f3f60ac1cc499921941549d5c23 node core/scripts/check-arch-docs.mjs arch-docs: OK (5 changed file(s)) ``` Not run: `npm run verify` end to end and the core suite — this worktree has no `core/node_modules`, and the change touches no `core/` file (the diff is exactly 5 paths: `plugins/workflow/src/service.js`, its two tests, `docs/subsystems/workflow.md`, one changelog fragment). No `generate`: `plugins/**` is not mirrored under `patches/ds-bot/`. ## Merge note `git merge` of live main `74d08c5d` conflicted only in `docs/subsystems/workflow.md` §3 (main landed #2785's sentence on the same line); resolved by taking main's text and re-applying the #2787 wording. `service.js` merged automatically. ## Checkpoint <!-- flybot:checkpoint --> ```json { "pr": 2789, "claim": "Dev-5", "issue": 2787, "summary": "A takeover reap ended the dead window's run but never drained the lane's queue, so a card parked behind it waited for an unrelated assign. reapOnce() now reaps and then drains on the serial tail; takeover() uses it and reap() returns the in-flight takeover instead of stacking a second drain. A table test pins that every terminal transition drains, and the subsystem doc says the reap leaves the queue alone and the following drain starts the card.", "files": [ "plugins/workflow/src/service.js", "plugins/workflow/test/takeover-transition-drain.test.js", "plugins/workflow/test/terminal-transition-drain.test.js", "docs/subsystems/workflow.md", "changelog.d/2787-takeover-drain.fixed.md" ], "checks": { "ran": "(cd plugins/workflow && TZ=UTC npm test)", "result": "green", "at": "b9c3735e8570aef8d523d8ae786c68e0a1fd4a2e" }, "next": "none — ready for review" } ``` <!-- /flybot:checkpoint -->
1 parent 74d08c5 commit 3d1165f

5 files changed

Lines changed: 351 additions & 14 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
A card queued behind a run ended by the reap a window runs when it **takes the store over** now starts on its own: the takeover reap drains the lane's queue like the load-time reap, instead of leaving the card parked with a free slot until some unrelated assign or ingest. See [#2787](https://github.com/ThinkFlowLab/FlyBot/issues/2787).

0 commit comments

Comments
 (0)