Repository navigation
Conversation
Admission now records whether it requested automatic execution on the durable inbox row, so restart recovery can tell a prompt that was meant to run from an admit-only one. The intent is optional on the event and defaults to false in the projection, so legacy events and existing rows stay ineligible.
A turn that keeps dying must not crash-loop across restarts, and the rows that made it a candidate must stop being resumable once recovery terminalizes it. Retirement is a durable event committed in the same transaction as the terminal, scoped to an admission watermark captured at the decision, so a prompt admitted while the turn settles stays eligible.
A prompt admitted to the durable inbox is lost when the process dies before the execution claim is written: the row stays pending but the claim-only sweep never sees it. Startup recovery now also selects top-level Sessions holding eligible rows and resumes them with the same forced, input-scoped drain the lost wake would have used. Only a claimed turn gets the restart-continuation notice, since only it was actually working.
The interrupt reason now reads the durable admission watermark only after the coordinator accepts an interruption, so an idle interrupt does no work. Because that read suspends, the coordinator captures the owner first and re-checks it before recording a reason or forking, treating a departed owner as the settlement-window no-op instead of interrupting a stale fiber.
The regenerated types carry the admission resume flag and the internal retirement event on experimental.session.log.
There was a problem hiding this comment.
The fix works. Startup recovery now resumes a top-level Session whose prompt was admitted with resume but never claimed, and leaves admit-only and retired rows alone. To check this, I put the base restart.ts back into the PR tree: the new recovery tests in session-execution.test.ts fail, and with the PR they pass. The session-execution, session-projector, session-prompt and session-run-coordinator tests and the packages/schema suite pass. typecheck:tsc in packages/core is clean.
Public API: two additive, backwards-compatible changes to the durable session event log and the generated client types:
session.inbox.enqueuedgets an optionalresume: boolean.- A new durable event,
session.inbox.resume.retired(sessionID,reason: "exhausted" | "interrupted",through). It is published on budget exhaustion and also on every user interrupt while rows are pending.
Clients that switch over every event type will see the new type. The SQLite migration adds session_inbox.resume and session_inbox.resume_retired, both defaulting to false.
Concerns:
- Design: writing the claim when the prompt is admitted might fix the same crash window much more simply. Details are inline on
prepareResume. - Interrupt path: this is a live-path change beyond crash recovery and adds a new public event; inline on the interrupt code in
execution.ts. - Tests: about 600 lines of tests for about 400 lines of code, including roughly 400 in
session-execution.test.ts. Please trim them to the core cases: a row-only prompt is resumed once, an admit-only or retired row is not, and exhaustion retires the rows.
| }) | ||
|
|
||
| const prepareResume = Effect.fnUntraced(function* (sessionID: SessionSchema.ID) { | ||
| const prepareResume = Effect.fnUntraced(function* ( |
There was a problem hiding this comment.
Was writing the execution claim in the same transaction as the admission (when resume !== false) considered? The #60596 handoff suggested it as one option. A crash before the wake would then leave a normal claim, which listSuspended, countResume and store.release already handle. That would make the separate row-only candidate path, the resume/resume_retired columns, the through watermark and the new public event unnecessary, as well as the interrupt-path changes. The retirement design adds a second source of truth for "should this Session run after a restart" alongside the claim, and the two need to agree. If that approach can't work, please say why.
| // runs again on its own". The boundary is read lazily, only once the coordinator has | ||
| // accepted an interruption and while it still holds that execution, so an idle interrupt | ||
| // does no work and a boundary read never outlives its owner. | ||
| const interrupted = yield* coordinator.interrupt( |
There was a problem hiding this comment.
With this, a user interrupt reads the inbox before it is acknowledged, and run-coordinator's interrupt accepts an Effect for its reason, which adds the owner re-check. It can also publish session.inbox.resume.retired to the client-visible log on every interrupt while rows are pending. This is needed only because the per-row resume flag would otherwise re-run stopped work after a restart. A claim-based approach gets that for free: Interrupted already releases the claim. If the row-flag design stays, maintainers should decide whether this bookkeeping belongs on the public event contract (DurableDefinitions, generated client types) or should stay internal.
Issue for this PR
Closes #60596
Type of change
What does this PR do?
A prompt admitted right before a crash stays stuck when the process dies between
Session.promptenqueuing its inbox row and the turn writing its execution claim. Startup recovery only looked at claims, and the row itself did not record whether its admission asked to run, so nothing could tell that prompt apart from admit-only work.Three changes:
session.inbox.enqueuedgains an optionalresumefield, so the durable row records the wake its admission requested. Events written before this decode as admit-only, so existing rows stay ineligible.session.inbox.resume.retiredrecords an admission watermark, and the projector stops treating rows at or below it as resumable. The event commits in the terminal's own transaction, so a crash cannot separate the terminal from the eligibility decision, and pending rows are kept rather than deleted.A candidate recovered only from its row gets no "continuing after restart" synthetic: it never started a turn, so its pending prompt is the instruction. Only a claimed Session gets the notice.
Known limits, unchanged from the earlier review:
syntheticreads the revert gate before admission, so a revert staged in between no longer suppresses the wake.session.inbox.resume.retiredand theresumeflag are durable recovery state on the client-visible event log. Hiding them would break replay, andexperimental.session.logalready streams internal durable facts for the same reason. If you want that bookkeeping kept out of the public contract, say where the boundary should sit and I will move it.No flag: this restores a wake the crashed process lost, and retirement bounds it. An opt-out for #56032 / #59635 covers this path too, because a recovered drain goes through the same
prepareResumeand the same forced, input-scopedexecution.resumeas the claim path.Supersedes #60788, which the compliance bot closed because one template heading was wrong; the code review there had no open findings beyond the event-contract question above.
How did you verify your code works?
Rebased onto
d759c548aa. Dev moved to Job-based subagent recovery in between, so I re-integrated the selection logic around it and re-ran everything at this head instead of carrying the earlier numbers over.session-execution.test.ts,session-projector.test.ts,session-prompt.test.ts,session-run-coordinator.test.ts: 187 pass, 0 fail.packages/schemasuite: 93 pass, 0 fail.typecheck:tscinpackages/core: only the errors already present ond759c548aa(@effect/sql-sqlite-node,undici/index.js,src/mcp/client.ts), none in the files this touches.bun run generateinpackages/client: zero diff.bun run migration --check: no schema drift; one migration adds bothresumeandresume_retired.The crash matrix is still covered by tests: recovery in both crash windows, admit-only and retired rows not resumed, no duplicate when a Session is claimed and also a candidate, budget exhaustion (including a second sweep doing nothing), and the coordinator's owner re-check when the durable boundary read suspends.
Checklist
Added by the opencode bot (AI-generated).
Related: #60245, #63875
Public API: adds optional
resumetosession.inbox.enqueuedand a new durablesession.inbox.resume.retiredevent (backwards compatible, additive)