Skip to content

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

Closed

Description

@peppescg

Follow-up to #2588. That issue's main cause, a fire waiting on a stalled run in its origin session, is being addressed in #2631. This issue covers the other way a fire can stay in flight past its deadline: the fire's own run doesn't stop after the deadline cancel.

Problem

When a fire reaches its deadline, the watchdog cancels its run and logs scheduled fire overdue/degraded; termination unconfirmed; capacity quarantined. If the run doesn't stop (for example a provider stream or a tool that doesn't honor cancellation), then by design (#2277) the fire keeps three things until the run really ends:

  • its session lease, so a singleton schedule doesn't fire again;
  • its schedule's name fence;
  • one of the maxConcurrentFires slots (default 4).

The scheduler deliberately doesn't reap a live fire, and it shouldn't: the old run may still be changing the workspace. But if the run never ends, the schedule stays stuck until restart, and once all slots hold stuck fires, no schedule fires at all.

TestFireDeadlineNonclosingEventsKeepLeaseUntilRecovery covers this behavior with a test provider that ignores cancellation.

What to do

  1. Audit the fire path for steps that can block without honoring the fire deadline. Start with makeFireFunc in internal/app/scheduler_fire.go and what it calls: placement and run admission, carried context, the run's event loop, settleFireTerminalSnapshot, FinishRun, CloseSession, EndScheduledRun, and RecordFire* against remote stores. The origin-session notices are out of scope here (fix(scheduler): reap hung fires past FireDeadline (Fixes #2588) #2631).
  2. Check that provider adapters and tool execution stop promptly when the run context is cancelled. That includes the LLM resilience layer: a local mecated logs max_attempts=60 per_attempt_timeout=5m0s stream_idle_timeout=3m0s, so we need to know whether cancellation also stops retries right away.
  3. Decide whether quarantined capacity needs a metric or an alert, so that operators see stuck fires before every slot is taken.

Out of scope

Changing the #2277 guarantees: no reaping or recording of a fire as finished while its run is still alive.

Done when

  • Every blocking point found in step 1 either honors the fire deadline or has its own issue.
  • A fire whose run is cancelled at its deadline with a real provider adapter ends and releases its lease within a bounded time, verified with a test.

Activity

  1. added
    bug
    on Nov 23, 2026
  2. self-assigned this
    on Nov 23, 2026
  3. peppescg commented on Nov 23, 2026

    @peppescg
    ContributorAuthor

    Audit results

    I read the fire path and the run's cancellation on main, then measured the concrete points with local tests. #2958 fixes three of them. The rest stays open here.

    Fixed in #2958

    Step Measured on main Fix
    Placement (ReserveSuccessor on the execution provider) A placement that hangs holds the fire past its deadline. The claim stays pending and the schedule stops. The fire deadline, already computed from the claim, now bounds placement and session creation too.
    RecordFireStart / RecordFireProgress A schedule store that hangs (measured through the real grpcdriver client) holds the fire. The context has no deadline. A 10s bound per write. Both stay best-effort.
    Engine save after a cancelled read batch (loop.go) It used context.WithoutCancel, so it skipped the 5s sessionPersistenceTimeout. With a store that hangs, the run was still open after 15s. It now takes the same bounded path as every other save of a cancelled run.

    Deliberately not bounded

    The terminal RecordFire in the scheduler keeps no timeout. While a claim is still pending (the fire failed before RecordFireStart, or that record was lost), giving up would leave it pending. A lease-backed scheduler quarantines a pending claim, so the schedule would stop for good. Waiting holds the slot only until the store answers. The PR review caught this, and #2958 documents it in the code.

    Still open

    • A fire whose own run ignores cancellation. The dispatcher waits for every tool call with no timeout. Local Shell is bounded (SIGKILL to the process group, 5s WaitDelay). Remote runners, MCP SDK cancellation and foreground subagent trees are not verified yet.
    • Store calls under the name fence in the stale-fire reconciler (scheduler_reconcile.go) and in the one-shot re-arm (reArmOneShot) have no timeout. This is pre-existing.
    • The fire's terminal session settle (settleFireTerminalSnapshot → Persist) and its event-log appends have no timeout when the session store or the event log hangs.
    • A test with a real provider adapter showing that a run cancelled at its deadline releases its lease within a bounded time (this issue's "Done when").
    • Decide on a metric or alert for quarantined fire capacity.

    Checked and bounded already: the provider path (the resilience layer stops on cancellation and starts no new attempt), event emission (released 1s after Run.Cancel), and teardown (EndScheduledRun, lease release and attachment close all have timeouts).

  4. peppescg commented on Nov 23, 2026

    @peppescg
    ContributorAuthor

    How the fix for the stalled schedule comes together

    The schedule in #2588 stalls because a fire stays in flight, holding its lease, its name fence and a capacity slot, while it waits on something that never ends. The fix has two independent parts:

    1. The other steps a fire waits on (fix(scheduler): bound the steps a scheduled fire waits on (#2955) #2958). Placement, session creation, the in-flight record writes, and the engine save after a cancelled read batch are now bounded. This PR does not depend on fix(scheduler): reap hung fires past FireDeadline (Fixes #2588) #2631 and can be merged on its own.
    2. The origin session (Scheduler: hung schedule fire never reaped past Deadline; Singleton schedule stalls #2588). The "fire started" notice runs a full turn in the origin chat, and the fire waits for it with no deadline. This is the cause we reproduced for the reported symptoms. fix(scheduler): reap hung fires past FireDeadline (Fixes #2588) #2631 is being reworked to move only that run off the fire path.

    Once #2631 is merged too, the fix is complete: none of the steps we reproduced can hold a fire indefinitely any more. Everything else, including a run that ignores cancellation, stays tracked in the checklist above.

  5. peppescg commented on Nov 23, 2026

    @peppescg
    ContributorAuthor

    The remaining points from the checklist above moved to #2959. They are hardening for rarer failures and not needed for the stall in #2588. #2958 closes this issue once merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugkubernetes

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions