fix(host-sweep): grace period for freshly-woken containers with stale processing claims#2736
Merged
Conversation
… processing claims The sweep tick that wakes a container for due messages also ran the running-container SLA check in the same iteration. A fresh container that inherits stale processing_ack rows from a previous crash hasn't had a chance to run its startup cleanup (clearStaleProcessingAcks) yet, so the per-claim stuck rule saw an hours-old claim, concluded the just-spawned container was stuck, and SIGKILL'd it — an immediate spawn-kill loop. Carry a justWoke flag from the wake step into the SLA gate and skip the check for that one tick. The next tick (60s later) enforces the SLA normally, so a genuinely stuck container is still killed. Guarded by src/host-sweep-grace.test.ts, which drives two real sweep ticks against on-disk session DBs: the wake tick must not kill, a later tick with the claim still stale must kill claim-stuck. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This was referenced Jun 12, 2026
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.
Type of Change
.claude/skills/<name>/, no source changes)Description
What: The host-sweep tick that wakes a container for due messages no longer runs the running-container SLA check in that same iteration. A
justWokeflag carries from the wake step (sweep step 2) into the SLA gate (step 3).Why: A container that crashes mid-turn leaves stale
processing_ackrows inoutbound.db. The agent-runner clears those on startup (clearStaleProcessingAcks), but the sweep's wake and SLA check ran back-to-back in one tick: wake spawns a fresh container,isContainerRunningnow reports alive, the per-claim stuck rule sees the hours-old claim with no heartbeat movement, and the host SIGKILLs the container it spawned milliseconds earlier — a spawn-kill loop that pins the session. This is adjacent to, but distinct from, the orphan-claim cleanup inresetStuckProcessingRows: that path only fires after the host itself kills a container, so claims left by a container that died on its own (OOM, crash) still hit the wake-tick race.How: Three small edits inside
sweepSession(src/host-sweep.ts): declarelet justWoke = false;after the due-message count, set it afterawait wakeContainer(session), and gate the SLA check with&& !justWoke. The grace lasts exactly one tick — the next sweep (60s later) enforces the ceiling and per-claim rules normally, so a genuinely stuck container is still killed.Tested: New guard test
src/host-sweep-grace.test.tsdrives the real sweep loop against a real central DB and on-disk session DBs (only the container runner is mocked), seeding a due message plus a 2h-oldprocessingclaim: the wake tick must not kill, and a later tick with the claim still stale must killclaim-stuck. Removing the!justWokegate turns the test red. Full validation: 350 host tests pass (pnpm test), build/typecheck/lint at baseline, 101 container tests pass (bun test).🤖 Generated with Claude Code