Repository navigation
fix(orchestration): own mailbox pointer recovery from durable reservations - #19644
brennanb2025 wants to merge 1 commit into
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Advanced Run ID: 📥 CommitsReviewing files that changed from the base of the PR and between 5070bee437f7a2880bf70c742a2b3bf827ab4d09 and d4a467b. 📒 Files selected for processing (8)
🚧 Files skipped from review as they are similar to previous changes (1)
Included review availability: Your plan provides up to 10 included reviews per hour; 6 remain after this review. 📝 WalkthroughWalkthroughThe change adds database queries for pending mailbox pointer reservations. Pointer flights retain database and connection identity. Submission and settlement reject stale database ownership. Recovery validates live PTYs and process incarnations. Recovery reconciles reservations during working observations, database attachment, PTY retirement, and settlement. Tests cover recovery phases, database replacement, PTY reuse, uncertain writes, and repeated observations. Merge Risk: ⚪ Minimal · up to The prior recovery-ordering concern is resolved: ambiguous Enter writes made after an earlier working signal remain eligible for redelivery. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Full details: Description checkExplanation The description gives a detailed explanation of the behavior change, rationale, scope, and validation. However, it omits the required Linked Issue entry, does not provide the required Visual Proof section or explicit N/A statement, and does not follow several required template sections and checklist items. Resolution Add the required template sections. Include a linked issue after “Fixes #”, provide visual proof or state exactly “N/A” with a reason, and complete the Testing, AI Disclosure, Review, Agent skill upstream boundary, Notes, and Checklist sections as applicable.
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
13e23db to
d13f56c
Compare
|
Note GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer. |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: bc755cb6-5d76-4a63-853e-4087726675f0
📒 Files selected for processing (11)
src/main/runtime/orca-runtime-automation-operations.tssrc/main/runtime/orchestration/db/messages/mailbox-pointer-enter-state.tssrc/main/runtime/orchestration/mailbox-pointer-delivery.tssrc/main/runtime/orchestration/mailbox-pointer-recovery.test.tssrc/main/runtime/orchestration/mailbox-pointer-recovery.tssrc/main/runtime/orchestration/mailbox-pointer-release-query.test.tssrc/main/runtime/orchestration/mailbox-pointer-stage.test.tssrc/main/runtime/orchestration/mailbox-pointer-stage.tssrc/main/runtime/orchestration/mailbox-pointer-state.tssrc/main/runtime/orchestration/mailbox-pointer-submit.tssrc/main/runtime/orchestration/structured-mailbox-pointer-delivery.ts
🚧 Files skipped from review as they are similar to previous changes (5)
- src/main/runtime/orchestration/structured-mailbox-pointer-delivery.ts
- src/main/runtime/orchestration/mailbox-pointer-stage.test.ts
- src/main/runtime/orchestration/mailbox-pointer-submit.ts
- src/main/runtime/orchestration/mailbox-pointer-recovery.test.ts
- src/main/runtime/orchestration/mailbox-pointer-recovery.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review.
| if (flight.workingObserved && flight.reservation) { | ||
| try { | ||
| this.recovery.settle(ptyId, flight.stagedMessageIds, flight.reservation.processIncarnation) |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift
Do not settle an unverifiable Enter from a prior working observation.
An agent can report working after pointer text is written but before delayed submitEnter runs. That sets flight.workingObserved. If the later '\r' write is unverifiable, mailbox-pointer-submit.ts leaves the reservation at MAILBOX_POINTER_ENTER_ATTEMPTED, but this call removes the flight and recovery settles that phase as delivered.
Record that working was observed after the Enter attempt, or exclude ambiguous Enter attempts from this recovery path. Otherwise an SSH disconnect can mark an undelivered message as delivered and prevent redelivery.
6421245 to
5070bee
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: f4d810b9-b4e1-49a1-b565-fa47d204b9d3
📥 Commits
Reviewing files that changed from the base of the PR and between 6421245 and 5070bee437f7a2880bf70c742a2b3bf827ab4d09.
📒 Files selected for processing (7)
src/main/runtime/orca-runtime-test-orchestration-messages.spec.tssrc/main/runtime/orchestration/db/messages/mailbox-pointer-enter-state.tssrc/main/runtime/orchestration/db/schema/schema-column-probes.tssrc/main/runtime/orchestration/mailbox-pointer-recovery.test.tssrc/main/runtime/orchestration/mailbox-pointer-recovery.tssrc/main/runtime/orchestration/mailbox-pointer-release-query.test.tssrc/main/runtime/terminal-send-stale-leaf-liveness.test.ts
💤 Files with no reviewable changes (1)
- src/main/runtime/orca-runtime-test-orchestration-messages.spec.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 6 remain after this review.
5070bee to
d4a467b
Compare
Review statusThis PR was reviewed across several passes and substantially rewritten. It previously bundled four independent concerns, was red on tests, broke lint, conflicted with 43 files / +2211 −193 (conflicting) → 16 files / +730 −114 (mergeable). Defects found and fixed
Also removed: a mutating accessor used as a predicate, a parameter with no callers, a dead function, a dropped redrive, and a test that asserted SQLite's transactionality rather than this code. ArchitectureThe PR's SQLite statement- Recovery instead reads durable rows through the partial index added in #19390 — Validation
Ablations confirm the new tests are regression guards rather than pins — reverting the phase split, the incarnation fence, or the already-read reclamation each turns tests red. Two failures are pre-existing and reproduce on ElectronClean start, and orchestration mail delivered end-to-end into the receiving pane at this head: Scope deferredA terminal-agent-status evidence reducer, a |
Correction and full Electron evidenceMy previous comment attached two screenshots and described them as taken "at this head". That was wrong on both counts, and I'm replacing them.
What was verified, at
|
d4a467b to
348f876
Compare
…tions Mailbox pointer recovery inferred eligibility from transient delivery state, so a reservation could outlive the PTY that made it and a pointer that never submitted could be recorded as delivered. Recovery now reads reservations straight from the durable message rows through the existing `idx_messages_pending_pointer_pty` partial index, and is fenced by database connection identity, PTY id, and process incarnation. There is no in-memory mirror of the reservation set, so nothing can drift from the database. Also fixes a delivery-loss path: when a PTY retires, the Enter timer is cleared first, which is positive evidence that a reserved or merely-written pointer never submitted. Those phases are now released as redeliverable and only an attempted Enter is settled as ambiguous. Previously every in-flight phase was stamped delivered, and since mailbox selection filters `delivered_at IS NULL`, that mail was never re-pointed. - Reconcile a stranded reservation on attach and on the next working edge. - Redrive mailboxes parked behind a flight stranded by a database swap. - Use the named pointer phase constants instead of bare literals.
348f876 to
789f323
Compare
Correction: the index was already in useAn earlier note in this thread implied this PR is what makes
So the change is an index-served write per title frame becoming an index-served read that writes nothing when the pane holds no reservation — measured at roughly 2.4 µs → 0.16 µs. Real, but small. This should be read as durability and correctness work, not a throughput improvement. The index itself is untouched: it ships on Scope noteThe PR body now calls out the one user-visible behavior change explicitly — what happens to mail that is mid-delivery when a PTY dies. It was considered as a separate PR. It is left here because it is built on the reservation record this change introduces and cannot land before it, but it is flagged prominently so it gets reviewed as the delivery-semantics decision it is rather than as an implementation detail. |
Closing — superseded by #19911Measurement did not support this PR's stated benefits. Recording the numbers so this does not get re-litigated from the original claims. Performance — measured, not estimated. Against a copy of a real 368 MB orchestration database (50,866 messages), WAL +
1.84 µs per title frame, with zero I/O difference. At 20 panes × 10 Hz that is 368 µs/s — 0.037% of one core. Three claims did not hold:
What was real is the delivery-semantics change: The remaining ~700 lines restructured a delicate mail-delivery path without a demonstrated bug fix or a measurable performance gain, so the regression risk is not worth carrying. Also worth recording for whoever picks this up: the branch originally carried a byte-identical duplicate of #19390 (which is what made it conflict), a deleted Cursor Agent auto-submit guard, a The deferred agent-status evidence work referenced above is unaffected and still waiting on #19683. |






Summary
Mailbox pointer recovery decided what to do with a pane's outstanding pointer reservations from transient in-memory delivery state. This moves that decision onto the durable rows.
This is the one user-visible change here and it deserves deliberate review.
When a pane's PTY retires mid-delivery,
maincalledmarkAsUndeliveredon every staged message, blanket-clearing all phases and making them fully redeliverable — including an Enter keystroke that may already have landed, which could produce a second submission.Now the Enter timer is cleared first, which is positive evidence about what actually happened:
RESERVEDWRITE_ATTEMPTEDENTER_ATTEMPTEDOnly the genuinely ambiguous case changes. It follows the policy already documented in
mailbox-pointer-submit.ts— "neither settling it as delivered nor rolling it back ... is provable here" — and preserves at-least-once without risking a duplicate Enter.What else changes versus
mainNo durable write per title frame. On
main, every working/permission title frame — including each spinner animation tick — ran a blanketUPDATEclearing that PTY's reservations (mailbox-pointer-delivery.ts:183). That frame now runs aSELECTand writes nothing unless a reservation actually exists.Reservations are fenced by process incarnation.
maincleared reservations for a PTY id without checking which process incarnation owned them, so a replacement process reusing a PTY id could clear a predecessor's reservation. Reconciliation now requires the pane to still run both the same PTY and the same incarnation.There is no in-memory mirror of the reservation set, so nothing can drift from the database.
Scale of the win, stated honestly
This is not a performance win, and the index is not newly used. The partial index
idx_messages_pending_pointer_ptyfrom #19390 already servedmain's per-frameUPDATE—EXPLAIN QUERY PLANshowsSEARCH messages USING INDEX idx_messages_pending_pointer_ptyfor both the old statement and the new one. Measured, the per-frame cost goes from roughly 2.4 µs to 0.16 µs.The value is that a display-driven animation frame no longer performs durable cleanup at all, that reconciliation is correctly fenced, and that recovery can no longer disagree with the database. Treat it as durability and correctness work.
Also
releasePendingMailboxPointerForPty, which this change leaves with no callers, and retarget its query-plan test at the live consumer so the index guarantee is kept.No schema or DDL change: the index already ships on
mainand existing databases already receive it throughmigrateMailboxPointerEnterV33. The only edit toschema-column-probes.tsis a comment.Validation
pnpm tc:node,oxlint,oxfmt --checkand the changed-code quality gate are clean; CI green (16 passed, 11 skipped, 0 failures).Two pre-existing failures reproduce on
mainand are unrelated: theorchestration-cli-subprocesskeepalive assertion, and load-sensitive timeouts inautomation-change-publication.Scope
Cut down from a larger change. A terminal-agent-status evidence reducer, a
hasProviderChildliveness narrowing, andruntime-agent-row-store.tschanges were removed and deferred so they do not compete with the agent-status store work in #19683, which schedules that store for deletion. No renderer, mobile, or wire surface is touched.