Repository navigation
Conversation
There was a problem hiding this comment.
This fixes the startup gap. I ran the #60596 reproduction on the base and with this PR. On the base, the stored prompt is never resumed. With the PR, a prompt stored with resume: true is resumed once, and resume: false or a missing flag stays admit-only. I had to change the script so the restart layer is built inside a scope that stays open; as written, the forked resume is interrupted. The four session test files (166 tests) and the schema suite (91) pass, and typecheck:tsc is clean in core and schema.
Public API (additive, backwards compatible):
session.inbox.enqueuedgains an optionalresume: booleanfield. Older events decode as admit-only.- New durable event
session.inbox.resume.retiredwith{ sessionID, reason: "exhausted" | "interrupted", through }. It appears inExperimentalSessionLogOutputand the generated promise client types. - New
session_inboxcolumnsresumeandresume_retired, added by two migrations.
Consumers that switch exhaustively on event types will see a new variant. No existing caller breaks.
Concerns:
- Auto-resume after restart. This adds a second automatic-resume path at startup, for sessions that never started a turn. Users in #56032 / #59635 are asking for fewer unattended resumes, so any opt-out added for those issues must cover this path too. Also, the recovered turn gets the "Continuing after restart" notice although no turn was running. See the inline comment.
- Bookkeeping in the public event stream. The retirement event and the
resumeflag are internal recovery state, but they now become part of the durable, client-visible event log. See the inline comment. - Two migrations. One feature adds two migrations for the same table. They could be folded into one before merge.
- Tests. The test additions are very large for what they check: about 650 lines in
session-execution.test.ts, coordinated by manyDeferreds and interleavings. Please cut them down to a few clear cases: resumes once, admit-only not resumed, retired not resumed, no duplicate when a session is claimed and also a candidate, plus the coordinator owner re-check. The rest is expensive to maintain and hard to follow.
c5a60ba to
ca1e2cb
Compare
|
Reworked in Concern 1 — fixed. The restart continuation notice is now gated on the claimed path only. On #56032 / #59635: the row-only path goes through the same Concern 3 — folded. Both migrations are gone; one migration now adds both Concern 4 — cut. Concern 2 — no change, with respect for the opposite view. Hiding the retirement event or the At your suggestion the history is now five commits, each independently green (147 / 150 / 157 / 158 / 158): schema intent, retirement, recovery selection, lazy interrupt resolution, and the regenerated client types. |
There was a problem hiding this comment.
The fix still works. I re-ran the #60596 reproduction at this head: a prompt stored with resume: true is resumed on startup and one stored with resume: false is not. The session test files (158 tests) pass and typecheck:tsc is clean in core.
Earlier points addressed:
- The restart notice is no longer posted for a session recovered only from a pending prompt. That path shares the claim path's
prepareResumeandexecution.resume, so an opt-out for #56032 / #59635 would apply to it as well. - The two migrations are now one.
- The test additions are much smaller.
The event-contract thread stays open for maintainers to decide.
Public API: unchanged since the last review, all additive and backwards compatible. session.inbox.enqueued gets an optional resume field, and there is a new durable event session.inbox.resume.retired.
No new concerns.
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.
ca1e2cb to
478f909
Compare
|
Rebased onto Two things the rebase surfaced, both worth knowing:
The rebase also exposed a stale fixture, not a product bug: our claimed-candidate guard test seeded a background child into KV, but background jobs moved to a durable Re-verified on the new base: five commits each green in isolation, core |
There was a problem hiding this comment.
The fix still works after the rebase. Since my last review, the only changes are the migration (renamed and now ordered after the new job migration on dev) and one test that now seeds its background job in JobTable. Session source is unchanged. I re-ran the #60596 reproduction: a prompt stored with resume: true is resumed and one with resume: false is not. The session test files (158 tests) and the schema suite (91 tests) pass, and typecheck:tsc is clean in core.
The event-contract thread is not addressed and stays open for maintainers.
Public API: unchanged since the last review, all additive and backwards compatible. session.inbox.enqueued gets an optional resume field, and there is a new durable event session.inbox.resume.retired.
No new concerns.
|
Could a maintainer approve the pending CI workflows? |
There was a problem hiding this comment.
This push is a merge of the latest dev, and the fix still works. The projector conflict was resolved correctly: the PR's resume field and the session.inbox.resume.retired projection sit on top of dev's new helpers. The migration is still last in the list. I re-ran the #60596 reproduction: a prompt stored with resume: true is resumed and one with resume: false is not. The session test files (158 tests) and the schema suite (91 tests) pass, and typecheck:tsc is clean in core.
Public API: unchanged since the last review, all additive and backwards compatible. session.inbox.enqueued gets an optional resume field, and there is a new durable event session.inbox.resume.retired.
No new concerns.
|
This PR doesn't fully meet our contributing guidelines and PR template. What needs to be fixed:
Please edit this PR description to address the above within 72 hours, or it will be automatically closed. If you believe this was flagged incorrectly, please let a maintainer know. |
|
This pull request has been automatically closed because it was not updated to meet our contributing guidelines within the 72-hour window. Feel free to open a new pull request that follows our guidelines. |
Issue for this PR
Closes #60596
Type of change
What does this PR do?
When a process crashes between
Session.promptenqueuing an inbox row and a turn acquiring an execution claim, the prompt remains stranded because recovery only scanned claimed sessions and inbox rows did not record wake intent.resumefield onsession.inbox.enqueued.session.inbox.resume.retiredscoped by an admission watermark, preventing restart loops without deleting pending rows.CONTINUE_AFTER_SERVER_RESTARTnotices for sessions recovered solely from pending rows where no turn ever began.Known limits, deliberate and unchanged
syntheticdetermines revert-gated intent before admission. A revert staged between that read and publication no longer suppresses the wake.session.inbox.resume.retiredand theresumeflag onsession.inbox.enqueuedare durable recovery state streamable viaexperimental.session.log; the unresolved question for maintainers is whether this recovery bookkeeping belongs in the public event contract. Hiding durable definitions from the log would break replay.How was this verified?
Reported verification across session test suites:
session-execution.test.ts,session-projector.test.ts,session-prompt.test.ts, andsession-run-coordinator.test.ts(158 pass); schema suite (91 pass);typecheck:tscclean in core and schema; migration checks, oxlint, and ast-grep clean.packages/coresuite: 7,160 pass / 35 skip / 29 baseline failures (byte-identical to base commit1908fcb8b7: 11 Ripgrep, 5 pty, 1 pty defaults, 12 search tools).Checklist
Added by the opencode bot (AI-generated).
Related: #56032, #59635, #60245
Public API: adds optional
resumeto session.inbox.enqueued and a new durable session.inbox.resume.retired event (backwards compatible)