Repository navigation
feat(schedule): in-flight fire state, progress, and wall-clock timeout (#386) - #400
Merged
Merged
Conversation
…ters (#386) Phase 1+2 of the in-flight scheduled-fire lifecycle. Today a claimed fire is invisible until RecordFire: inspect renders "fires: none" while one runs (ambiguous: running / stuck / crashed / RecordFire-failed), and the minted sched-- session id is only discoverable after the run completes. Promote the in-flight fire to a first-class persisted stage: - engine/port/schedule.go: ScheduleState gains LastFireStartedAt / LastFireProgressAt / FireDeadline; ScheduleFire gains StartedAt / ProgressAt / Deadline; ScheduleSpec gains FireTimeout (per-fire wall-clock deadline knob). ScheduleStore gains RecordFireStart (persist the in-flight fire + stamp the real session id early) and RecordFireProgress (advance the last-progress timestamp). RecordFire flips terminal + clears the in-flight fields; Claim/ClaimNow zero them. - engine/session: new StopTimeout StopReason ("timeout") — a clean, recoverable wall-clock-deadline terminal (StopBudget sibling), string passthrough on the wire. - memschedulestore (reference) + jsonlstore + redisstore implement the two methods; the scheduleconformance suite gains 5 in-flight subtests (persist-start, idempotent, progress-advances, record-clears, claim-alone-leaves-zero) and all three backends pass. - engine/api/*.txt regenerated; engine/CHANGELOG.md notes the Added (minor) surface. Composition wiring (fire lifecycle, wall-clock enforcement, started notice, stale reconcile) lands in the next commit.
…line, progress (#386) Phase 3 wires the in-flight lifecycle into the composition FireFunc (makeFireFunc): - Early persistence: after CreateSessionWithProfile, RecordFireStart stamps the real sched-- session id + StartedAt + the computed Deadline (best-effort WARN on failure; the at-most-once Claim already advanced). - Wall-clock deadline: a time.AfterFunc watchdog cancels the in-flight run via the blessed Service.Cancel/run.Cancel seam after effectiveFireDeadline (spec.FireTimeout, else defaultFireTimeout=30m). A deadline-fired run that drained to StopCancelled is overridden to StopTimeout with an Err naming the timeout; the session settles to a recoverable terminal snapshot via settleFireTerminalSnapshot. - Progress: RecordFireProgress fires on EvToolCall/EvTurnEnd/EvResult (not per chunk), advancing LastFireProgressAt. - Create-failure after Claim still records a terminal StopError fire. startScheduler rediscovers the ScheduleStore and threads it + the default timeout into makeFireFunc (storage-agnostic). Tests cover early-persist, StopTimeout on deadline, progress advance, and create-failure terminal.
Phase 4a. The originating conversation now gets a lightweight, fenced- untrusted, harness-authored notice when a fire STARTS (schedule name + fire id + session id), distinct from the terminal result report — the operator sees "it triggered, here's the fire" instead of silence until completion. deliverFireStarted mirrors deliverFireResult: enqueues to the same DeliveryQueue exactly-once ledger with a distinct "started" header so it never duplicates or collides with the terminal note, state-aware (busy/awaiting origin enqueues only, empty origin no-op), and carries NO model-authored fire content. makeFireFunc invokes it (nil-safe) right after the early RecordFireStart; wired in startScheduler. Tests cover enqueue-with-ids, busy/awaiting enqueue-only, empty-origin no-op, non-duplication of the terminal note, and fenced harness-authored body.
Phase 4b. A crashed process's claimed-but-never-terminal fire is now distinguishable from a live run after restart, instead of sitting "pending"/in-flight forever. The scheduler detects stale in-flight state store-only (pending sentinel past the window, or a real in-flight fire whose prior-fire lease is no longer live and whose start is past the window); a genuinely-live fire (lease held) is never reconciled. Reconciliation is a composition-injected ReconcileStaleFire callback (the scheduler stays storage-agnostic, never importing the server) that settles the two crash cases: crash-after-Claim records a terminal StopError fire; crash-after-session settles the session to cancelled (Interrupt-recoverable) and records StopError. Also fix TestFireDelivery_EmbeddedEndToEnd: it now waits for the terminal "completed with stop reason:" marker specifically, since the new started notice shares the "[scheduled task " prefix and would otherwise satisfy the looser match first.
#386) Phase 5 makes the in-flight fire VISIBLE and keeps the three surfaces (agent inspect / gRPC+HTTP / TUI overlay) in agreement. - renderScheduleInspect (engine/agent): a claimed fire (pending sentinel, run not started) renders "in-flight: claimed (session pending)" instead of the ambiguous "fires: none"; an in-flight fire (Stop empty) renders the in-flight marker + started/last-progress/deadline; a schedule-level in-flight summary shows when a live fire exists. fire_timeout surfaces in the spec summary. - schedule.proto: ScheduleState + last_fire_started_at / last_fire_progress_at / fire_deadline; ScheduleFire + started_at / progress_at / deadline; ScheduleSpec + fire_timeout (Duration). Regenerated contracts/gen. - grpc_schedule.go: all four wire mappers project the new fields (the ONE projection path gRPC + HTTP share). - TUI overlay: client structs + mappers carry the fields; the inspect render mirrors the agent (in-flight marker, claimed-pending, never "no fires recorded" when claimed). Tests: agent render (in-flight / claimed-pending / never-fired / terminal), a wire-projection test driving the real store, and TUI render.
- docs/adr/0097-scheduled-fire-inflight-state.md (new): the in-flight fire as a first-class persisted lifecycle stage; early session-id persistence; progress timestamps; the wall-clock deadline + StopTimeout; the started notice; the storage-agnostic detect-in-scheduler / reconcile-in-composition stale-fire seam. - docs/adr/README.md: index row. - docs/design/IMPLEMENTATION-NOTES.md: "In-flight fire state" paragraph. - docs/adr/0027-cloud-native.md: List-1 re-audit (no new row; the state lives in the durable store). - docs/usage/mecated.md: the fire_timeout spec field + in-flight inspect. - user-docs/what-you-get/scheduled-tasks.md: "Watching a fire while it runs" (in-flight state, timeout, started notice, crash recovery). - llms.txt regenerated.
Two Medium findings from the #386 panel: - RecordFireProgress now takes the fire ID (RecordFireProgress(ctx, name, fireID, at)) so the caller passes the known id instead of the store scanning for the in-flight fire. jsonlstore writes the single fire file directly (no ReadDir scan under the store mutex on every turn boundary); redisstore addresses the single key (no SCAN); memschedulestore looks it up directly. Engine-port widening; engine/CHANGELOG.md amended. - redisstore's progress write is now an atomic Lua CAS (byte-compare optimistic lock) so a concurrent terminal RecordFire landing mid-write can never revert a terminal record back to in-flight (the cross-replica lease-lapse race). The "Stop empty" guard + the byte-compare together guarantee the terminal record wins. Conformance gains two subtests across all three backends: progress targets the named fire only, and progress never reverts a terminal fire.
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
Fixes #386 — a scheduled task could be claimed and run for a long time with no useful indication it started, is progressing, or became stuck.
ScheduleQuery inspectrendered a claimed-but-running fire asfires: none(ambiguous: running / stuck / crashed /RecordFirefailed), the mintedsched--session id was only discoverable after the run completed, and there was no per-fire wall-clock bound. (Observed withmonitor-pr-6208: 16 turns, 26 tool calls, 1.2M tokens, all invisible until the operator inspected storage by hand.)The fix promotes the in-flight fire to a first-class, persisted lifecycle stage (ADR 0097) and gives each fire a wall-clock deadline.
Changes (6 commits)
engine/port/schedule.go:ScheduleStategainsLastFireStartedAt/LastFireProgressAt/FireDeadline;ScheduleFiregainsStartedAt/ProgressAt/Deadline;ScheduleSpecgainsFireTimeout.ScheduleStoregainsRecordFireStart(persist the in-flight fire + stamp the real session id at start) andRecordFireProgress.RecordFireflips terminal + clears the in-flight fields;Claimzeroes them. NewStopTimeoutreason (clean, recoverable, aStopBudgetsibling). memschedulestore/jsonlstore/redisstore implement it; 5 conformance subtests.makeFireFunc) — earlyRecordFireStartafter session create; atime.AfterFuncwatchdog cancels the run viaService.CancelaftereffectiveFireDeadline(FireTimeout, else 30m default), overriding a deadline-firedStopCancelledtoStopTimeoutwith an honest error;RecordFireProgresson turn boundaries; create-failure still records a terminal fire.deliverFireStarted) — a fenced-untrusted, harness-authored[scheduled task <name> started (fire <id>)]notice on the sharedDeliveryQueueexactly-once ledger (distinct from the terminal note; no model content), state-aware.ReconcileStaleFirecallback settles crash-after-Claim (terminalStopError) and crash-after-session (sessioncancelled+StopError). A live fire (lease held) is never reconciled.renderScheduleInspect, the gRPC/HTTP wire mappers (proto gained the fields), and the TUI overlay all render a claimed fire asin-flight: claimed (session pending)(neverfires: none) and an in-flight fire with started/last-progress/deadline.RecordFireProgressnow takes the fire id (no O(N) store scan on the hot path) and the redisstore progress write is an atomic Lua CAS (a terminal record can never be reverted to in-flight by a cross-replica race).Review
Adversarial panel (spec + concurrency) over the committed branch: all 9 acceptance criteria MET, no scope creep. Two Medium findings (the Redis non-atomic progress write and the jsonlstore hot-path scan) — both fixed in the final commit with regression-pinned conformance subtests. The watchdog run-scoping, the reconcile TOCTOU fencing, and the
StopTimeoutclassification were all verified clean.Tests
Per-criterion coverage: live fire, completed fire, timed-out fire (
StopTimeout+ recoverable session), crash after Claim, crash after session creation,RecordFire/create failure, the started-notice exactly-once/no-model-content, the stale-reconcile (incl. live-fire-not-reconciled), the wire projection, and the agent + TUI render.task build,task lint,task test,task api:check,task docs:check,task site:buildall green.Docs
docs/adr/0097-scheduled-fire-inflight-state.md(new) + README index.docs/design/IMPLEMENTATION-NOTES.md— "In-flight fire state" note.docs/adr/0027-cloud-native.md— List-1 re-audit (no new row; the state lives in the durable store).docs/usage/mecated.md— thefire_timeoutspec field + in-flight inspect.user-docs/what-you-get/scheduled-tasks.md— "Watching a fire while it runs".engine/CHANGELOG.md+engine/api/*.txt— theScheduleStorewidening +StopTimeout(Added/minor).Note on the port widening
ScheduleStoregains two methods — a breaking change for any external implementer, but every implementation is in-tree (monorepo lockstep), so there is no external break. Recorded per ADR 0037 (task api:update+ changelog).