Skip to content

fix(scheduler): bound the steps a scheduled fire waits on (#2955) - #2958

Merged
peppescg merged 2 commits into
mainfrom
fix/2955-fire-step-bounds
Nov 23, 2026
Merged

peppescg merged 2 commits into
mainfrom
fix/2955-fire-step-bounds

Conversation

@peppescg

@peppescg peppescg commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

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)

  • Placement and session creation now run under the fire deadline. The deadline was already computed from the claim, but it was only applied from run admission on. A remote placement that never answered (ReserveSuccessor), or a session store that hung on Create, held the claim. A step that fails because the deadline lapsed now fails the fire with scheduled fire wall-clock deadline of … lapsed before the run started, the message run admission already used.
  • RecordFireStart and RecordFireProgress have a 10s bound. Both stay best-effort: a timeout logs a WARN and the fire continues.
  • The terminal RecordFire deliberately stays unbounded; the comment in fireClaimed explains 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)

  • The save after a cancelled read batch is bounded. dispatchTurn saved the batch's results with context.WithoutCancel(ctx). That context never reports an error, so save took its untimed branch and skipped the sessionPersistenceTimeout (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 every e.save call goes through the same policy. engine/CHANGELOG.md has a Fixed (patch) entry.

Before | After

Scenario (new test) main This PR
Placement hangs (TestFirePlacementIsBoundedByFireDeadline) The fire never returns. The fire fails at its 300ms deadline and names it. The next fire runs with one capacity slot.
Session Create hangs (TestFireSessionCreationIsBoundedByFireDeadline) The session is created without a deadline. The fire fails at its deadline. The model is never called.
RecordFireStart hangs (TestFireRecordStartIsBounded) The fire never returns. The write times out, the fire completes, and the next fire runs.
RecordFireProgress hangs (TestFireRecordProgressIsBounded) The fire never returns. Same as above.
Save of a cancelled read batch (TestCancelledReadBatchSaveIsBounded) The save has no deadline. With a store that hangs, the run was still open after 15s. Every save after the cancel has a deadline of at most 5s, and the run ends.

Mutation check: removing any one of the bounds, or skipping the batch save, makes its test fail.

One existing test changed. TestFireDeadlineDuringRunAdmissionNamesDeadline used 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 on main.

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:

    • a fire whose placement or session creation outlasts its fire_timeout now ends as a failed fire (stop=error, error text above) instead of staying claimed;
    • in-flight record writes to a store that hangs are dropped after 10s with a WARN. These writes were already best-effort;
    • with a store that hangs, a cancelled run reaches its terminal cancelled result 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)

  • The terminal RecordFire, unbounded by design (see above).
  • Store calls under the name fence in the stale-fire reconciler (scheduler_reconcile.go) and in the one-shot re-arm (reArmOneShot). These are pre-existing.
  • The fire's terminal session settle (settleFireTerminalSnapshot → Persist) and its event-log appends, which have no timeout when the session store or the event log hangs.
  • A fire whose own run ignores cancellation (provider or tool). The dispatcher waits for every tool call.
  • Cancellation in remote runners and the MCP SDK, and an alert for quarantined capacity.

Test plan

  • New tests: 10 runs with -race. They fail on main and pass here.
  • Mutation check: removing each bound, or skipping the batch save, makes its test fail.
  • 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 docs
  • go run ./cmd/mecademo (tool call, permission ask and approval, result)

🤖 Generated with Claude Code

peppescg and others added 2 commits November 23, 2026 16:05
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 rdimitrov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM.

  • Moving runCtx above placement is the right fix. The deadline was already computed from the claim, so this only applies it earlier. deadlineLapsed keeps the existing rule that an earlier caller deadline is not renamed.
  • The engine change is safe. dispatch reports cancelled only when ctx is done. In that case save now takes its sessionPersistenceTimeout branch, and with a live ctx it behaves exactly as before.
  • Bounding RecordFireStart and RecordFireProgress adds no new state. Both writes could already fail and be ignored. Leaving the terminal RecordFire unbounded is the right call, because a pending claim would otherwise be quarantined. The comment explains this well.

@peppescg
peppescg merged commit c0f766f into main Nov 23, 2026
46 checks passed
@peppescg
peppescg deleted the fix/2955-fire-step-bounds branch November 23, 2026 15:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Scheduler: a fire whose run ignores the deadline cancel keeps its lease and slot (follow-up to #2588)

2 participants