Repository navigation
fix(scheduler): bound the steps a scheduled fire waits on (#2955) - #2958
Merged
Merged
Conversation
A fire could stay in flight with its lease, name fence and capacity slot held when a step it waited on hung: - Placement and session creation ran before the fire deadline was applied, so a remote placement that never answered (ReserveSuccessor) or a session store that hung on Create held the claim. The deadline, already computed from the claim, now bounds the whole fire; a step that fails because it lapsed names the deadline. - RecordFireStart and RecordFireProgress used a context with no timeout, so a schedule store that hung held the fire. Each write now has a 10s bound and stays best-effort. The terminal RecordFire stays unbounded on purpose: giving it up while the claim is still pending would leave the claim quarantined on a lease-backed scheduler, stopping the schedule for good. TestFireDeadlineDuringRunAdmissionNamesDeadline now lets the deadline lapse during run admission, after the fire session exists: a 1ns deadline now lapses before the session is created. Co-Authored-By: Claude Opus 5.5 <[email protected]>
When a cancelled tool dispatch had results to record, the run saved the session with context.WithoutCancel. That context never reports an error, so save took its untimed branch and skipped the sessionPersistenceTimeout bound it applies to cancelled runs. A store that hung kept the run open, and with it a scheduled fire. Pass the run context so save detaches it with the bound, as for every other save of a cancelled run. Co-Authored-By: Claude Opus 5.5 <[email protected]>
rdimitrov
approved these changes
Nov 23, 2026
rdimitrov
left a comment
Member
There was a problem hiding this comment.
LGTM.
- Moving
runCtxabove placement is the right fix. The deadline was already computed from the claim, so this only applies it earlier.deadlineLapsedkeeps the existing rule that an earlier caller deadline is not renamed. - The engine change is safe.
dispatchreportscancelledonly whenctxis done. In that casesavenow takes itssessionPersistenceTimeoutbranch, and with a livectxit behaves exactly as before. - Bounding
RecordFireStartandRecordFireProgressadds no new state. Both writes could already fail and be ignored. Leaving the terminalRecordFireunbounded is the right call, because a pending claim would otherwise be quarantined. The comment explains this well.
3 tasks
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.
Summary
Closes #2955. A scheduled fire could stay in flight, holding its session lease, its schedule's name fence and a capacity slot, when a step it waited on hung. This PR bounds three of those steps, in two commits:
Scheduler fire path (
internal/app,internal/adapter/scheduler)ReserveSuccessor), or a session store that hung onCreate, held the claim. A step that fails because the deadline lapsed now fails the fire withscheduled fire wall-clock deadline of … lapsed before the run started, the message run admission already used.RecordFireStartandRecordFireProgresshave a 10s bound. Both stay best-effort: a timeout logs a WARN and the fire continues.RecordFiredeliberately stays unbounded; the comment infireClaimedexplains why. If it gave up while the claim was still pending, a lease-backed scheduler would quarantine the pending claim and the schedule would stop for good. Waiting holds the slot only until the store answers, as before.Engine (
engine/agent)dispatchTurnsaved the batch's results withcontext.WithoutCancel(ctx). That context never reports an error, sosavetook its untimed branch and skipped thesessionPersistenceTimeout(5s) bound it applies to every save of a cancelled run. A store that hung kept the cancelled run open. It now passes the run context, so everye.savecall goes through the same policy.engine/CHANGELOG.mdhas aFixed (patch)entry.Before | After
mainTestFirePlacementIsBoundedByFireDeadline)Createhangs (TestFireSessionCreationIsBoundedByFireDeadline)RecordFireStarthangs (TestFireRecordStartIsBounded)RecordFireProgresshangs (TestFireRecordProgressIsBounded)TestCancelledReadBatchSaveIsBounded)Mutation check: removing any one of the bounds, or skipping the batch save, makes its test fail.
One existing test changed.
TestFireDeadlineDuringRunAdmissionNamesDeadlineused a 1ns deadline to make the deadline lapse during run admission. That deadline now lapses before the fire session is created, so the test now uses a store that is slow to load the existing fire session during admission. The test asserts what it asserted before, and it still passes onmain.docs/architecture/api-surface.md: one sentence now says that the deadline covers placement and session creation.API compatibility
Assessment: compatible.
Rationale: no protobuf, request or response shape changes, and no exported Go identifiers change. Three effects are observable remotely:
fire_timeoutnow ends as a failed fire (stop=error, error text above) instead of staying claimed;cancelledresult within the persistence timeout.Clients already read these outcomes from the same fields, and error text is not a contract.
Major or feature changes: none. No major bump and no feature identifier.
Upgrade implications: none.
Not covered here (moved to #2959)
RecordFire, unbounded by design (see above).scheduler_reconcile.go) and in the one-shot re-arm (reArmOneShot). These are pre-existing.settleFireTerminalSnapshot→Persist) and its event-log appends, which have no timeout when the session store or the event log hangs.Test plan
-race. They fail onmainand pass here.go test -race ./internal/app/ ./internal/adapter/scheduler/go test ./cmd/mecak8s/cd engine && go test -race ./agent/...task test:engine-standalone(GOWORK=off)task lint,task docsgo run ./cmd/mecademo(tool call, permission ask and approval, result)🤖 Generated with Claude Code