Skip to content

Commit 355a887

Browse files
authored
Merge pull request #9911 from loopx-project/codex/atomic-peer-mailbox-route
Commit local peer return routes with mailbox requests
2 parents 5d7ac0e + 6ac2e2b commit 355a887

17 files changed

Lines changed: 641 additions & 121 deletions

‎docs/architecture/rfcs/sqlite-collaboration-mailbox-v0.md‎

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
- **RFC status:** Accepted
44
- **Supersedes / closes:** none
5-
- **Delivery maturity:** Proposal (candidate Core peer mailbox implementation is under review in open PR [#9880](https://github.com/loopx-project/loopx/pull/9880) and not yet merged to `main`)
5+
- **Delivery maturity:** Core peer mailbox storage merged in [#9880](https://github.com/loopx-project/loopx/pull/9880). Atomic routing, indexed read receipts and team-load improvements have separate follow-ups.
66
- **Language mirror:** [中文版](sqlite-collaboration-mailbox-v0.zh-CN.md) is the semantic mirror.
77

8-
The lifecycle header takes effect on merge of this RFC, while implementation maturity is recorded independently. The schema, rollout and performance thresholds below are design choices awaiting agreement.
8+
The lifecycle header records the design decision. The implementation and qualification sections record what has shipped and which measurements remain open.
99

1010
## Problem
1111

@@ -27,13 +27,21 @@ The existing two-round review uses real CLI subprocesses and local conversation
2727

2828
A's outbox and B's inbox share one request. B's outbox and A's inbox share one result. The CLI retains request, read, acknowledge, report and acknowledge-return. MCP retains request_peer, read_context, return_result, read_peer_returns and consume_peer_result. B can send subsequent updates with distinct update IDs. A acknowledges each result individually and may defer it to another turn.
2929

30-
The candidate stores SQLite in the local runtime's private peer-mailbox-v1 directory. After validating the frozen return route, one transaction commits the request body, sender, recipient and timestamp. The receiver can read the committed message even if the publisher exits before materializing its file view. Controlled changes update the receiver view of the same row. B's result takes its recipient from the original request. The request ID and result key identify a single result. A terminal acknowledgement and removal from the unconsumed-result index commit together. The delegated executor checks the same result store on reconnect before attempting to publish a conclusion.
30+
New Core peer messages use SQLite by default in the local runtime's private peer-mailbox-v1 directory, independently of the Goal provider. After validating the frozen return route, one transaction commits the request body, sender, recipient and timestamp. The receiver can read the committed message even if the publisher exits before materializing its file view. Controlled changes update the receiver view of the same row. B's result takes its recipient from the original request. The request ID and result key identify a single result. A terminal acknowledgement and removal from the unconsumed-result index commit together. The delegated executor checks the same result store on reconnect before attempting to publish a conclusion.
3131

32-
The first implementation retains file-backed authorization routes, adoption decisions and turn-bound read receipts, and materializes a receiver entry for compatibility. Existing file operations can replay and finish under their original IDs. Upgrade all CLI, MCP and hosted processes sharing a runtime together. Older binaries require a reverse export to read new traffic. Production-scale historical migration remains unqualified. External-channel delivery and wake retain their existing mechanisms. The candidate uses rollback journaling and FULL synchronization. Enabling WAL requires qualifying the SQLite versions used by every participating process under concurrent recovery.
32+
The first implementation retains file-backed authorization routes, adoption decisions and turn-bound read receipts, and materializes a receiver entry for compatibility. Existing file operations can replay and finish under their original IDs. Upgrade all CLI, MCP and hosted processes sharing a runtime together. Older binaries require a reverse export to read new traffic. Production-scale historical migration remains unqualified. External-channel delivery and wake retain their existing mechanisms. The default uses rollback journaling and FULL synchronization. Enabling WAL requires qualifying the SQLite versions used by every participating process under concurrent recovery.
33+
34+
### Local peer return route
35+
36+
The immutable SQLite request now carries the original sender and recipient fields used to reconstruct its local return route. The request and its route become readable in the same commit. New local peer requests need no separate route file. File-backed requests and external destinations keep their route records. Cold reverse export reconstructs the matching legacy route from the immutable request and rejects conflicting route files in the snapshot. Adoption and Turn read receipts continue through their existing owners.
37+
38+
When the stored request identifies a local peer, the report entry point requires a local peer route before writing a result. A legacy route with a different route kind, channel or conversation recipient is a conflict. Restore the original route before retrying the same result.
39+
40+
A process-kill rehearsal used the ordinary CLI with a local rollback-journal database. On the mainline comparison, interrupting a request before commit left one route file. The candidate left zero. After a kill immediately following commit, the receiver reported a result before the compatibility entry had been materialized. Retrying publication and reporting preserved the same request and one result. An installed composition with v3 receipts also verified rollback before the consumption commit and replay of the original receipt after it.
3341

3442
## Proposed transaction boundaries
3543

36-
Keep a dedicated database in each local runtime's private manager-context directory, with foreign keys, WAL, FULL synchronization and the existing directory permissions. Place a storage adapter alongside the TypeScript collaboration owner. Python peers and roundtrip callers use the same transaction entry point. Reuse the identity checks, planners, public states, cursor formats and command contracts. File, SQLite and PostgreSQL Goal backends supply the existing scope and authority. This design covers a single-host runtime.
44+
Keep a dedicated database in each local runtime's private manager-context directory, with foreign keys, FULL synchronization and the existing directory permissions. Place a storage adapter alongside the TypeScript collaboration owner. Python peers and roundtrip callers use the same transaction entry point. Reuse the identity checks, planners, public states, cursor formats and command contracts. File, SQLite and PostgreSQL Goal backends supply the existing scope and authority. This design covers a single-host runtime.
3745

3846
| Durable facts | Keys, indexes and commit points |
3947
|---|---|
@@ -44,6 +52,8 @@ Keep a dedicated database in each local runtime's private manager-context direct
4452

4553
Keep network calls outside transactions. A short write transaction claims due work and records a generation before a worker calls the channel. Reject local commits by a superseded claimant. An already-started channel call can still take effect after its lease expires. The new claimant reconciles the original attempt against its frozen route. If readback confirms delivery, record that delivery against the original obligation. If the outcome remains ambiguous, including when readback finds nothing or local confirmation was lost, retain `verification_required` or the existing `explicit_unverified` state. After dispatch, retry the same delivery only when the provider explicitly confirms that the original attempt was rejected before any external write. Recheck authority, scope and original route before sending. Recovery cannot rerun agent work. [Delivery contract](../../../loopx/control_plane/collaboration/return_delivery.ts) · [Channel reconciliation](../../../loopx/capabilities/manager_context/README.md)
4654

55+
Trusted Chat registration and original-conversation route readback use their File owner. They remain available while an unrelated peer database is locked or missing. Local peer return actions resolve the route from their request row and reject a conflicting legacy copy.
56+
4757
### Peer lease takeover
4858

4959
An adopted request keeps its original receiver and linked Todo after the Todo changes owners. Readback identifies confirmed handoffs on the linked Todo IDs and distinguishes open work from completed work without exposing the successor or private Todo text. When other linked work remains with the original receiver, the handoff action calls for a progress result with remaining work. Unavailable evidence keeps the recovery action. The original return obligation stays open until the receiver reports the final conclusion. The current assignee can take a newly addressed request linked to the same Todo. The Todo owner grants takeover after expiry and rejects the old lease's completion attempt. The successor validates the actual artifact before completion, while the requester reviews the result before consuming it. [File and SQLite Goal regression](../../../tests/control_plane/test_peer_lease_handoff.py)
@@ -55,6 +65,9 @@ An adopted request keeps its original receiver and linked Todo after the Todo ch
5565
| Exit before publication commits, or lose the response after commit | The former leaves no visible request. Retrying the latter with the same operation returns one ID and one recipient entry. |
5666
| Terminate a reader halfway through a page, or race two decisions | Replaying the same cursor preserves committed receipts. A conflicting decision cannot overwrite the original. |
5767
| Kill the worker after result commit, or lose local confirmation after the channel accepts | The first obligation remains discoverable. Reconcile the second against its frozen intent. Unknown delivery blocks later updates from overtaking it. |
68+
| Restart App after the original conversation message was appended, with the peer SQLite mailbox unavailable | Reconcile the committed File-owned result against its frozen route and show the delivered receipt on the same message. For an owner-only conversation, matching the committed message and Turn can settle the receipt on the first drain even while the original admission is active. Missing or mismatched history does not settle it. The original conversation contains one return and other conversations receive none. |
69+
| Read and adopt a registered File-owned request by its original ID while peer SQLite is locked or unavailable | Match the entry and frozen chat route to the authorized Goal and Agent. Read, adopt and return using File, including the deferred read receipt after linked-work lookup. Mixed Inbox pages and peer-owned requests still require the peer store. |
70+
| Report a result for an already-adopted File-owned request while peer SQLite is unavailable | Verify the original entry, assessment and route under their existing fences. Reporting the same update twice yields one result on the original conversation. A peer result still requires its SQLite owner. |
5871
| Delay the original provider call until its lease expires and the new claimant's first readback finds nothing, then let the original call succeed | Observe one external send. Reject a late local commit by the old claimant. Keep the original delivery unverified until the new claimant reconciles it, and preserve the order of later obligations. |
5972
| The provider explicitly rejects the original call before any external write | Permit a new send attempt for the same delivery and original route after rechecking scope and authority. Confirm a single delivered result. |
6073
| Contend for a write lock, fill the disk, damage a receipt or revoke the original route | Bound the wait or return an explicit failure. No false success, silently empty inbox or retargeting. Use the same key to recover the local transaction or verify an in-flight attempt after storage recovers. |
@@ -63,6 +76,11 @@ An adopted request keeps its original receiver and linked Todo after the Todo ch
6376

6477
Replay identical inputs in isolated File and SQLite runtimes. Compare what both agents observe per request, including full text, order, page boundaries, decisions, results and delivery state. Inventory every direct reader and writer, including App, CLI, MCP, pumps and older processes. Quiesce admissions and pumps, drain in-flight calls and install a version fence covering every writer. Defer cutover where an old writer cannot be excluded. Keep a cold backup, import all historical identities and receipts into a staging database, then verify counts, canonical digests, references and continuation from old cursors. Unexplained partial records or conflicts block cutover and retain their originals. Atomically publish the backend selector before reopening admissions. Enable one writer backend at a time.
6578

79+
Each identifiable local return route must match a sender operation in the converted snapshot. If both the sender operation and receiver entry are lost while their route remains, the cold import fails and keeps the original snapshot available for recovery.
80+
Routes owned by an original conversation keep their File records when the persisted sender operation has the same conversation recipient.
81+
82+
An offline macOS rehearsal of the composed local mailbox converted 10,140 synthetic requests and 10,040 results, including 40 unconsumed results. Import took 291 seconds and reverse export took 132 seconds. The upgraded reader resumed the File cursor, then recorded a new terminal consumption. The earlier File reader resumed the SQLite cursor after restoring the export. Canonical comparison covered 80,580 original File records and verified the new consumption and updated read receipts. Both source snapshots retained their original contents. A separate 268-request rehearsal exercised the new route audit in the composed converter.
83+
6684
Before the first SQLite write, revert the selector directly. Afterwards, fence writers again and reverse-export changes, including unverified send attempts. Verify that the old reader can resume from those exact states before switching back. If export cannot represent a state or parity fails, stay paused and recover from the database. Restoring a stale backup would discard new mail.
6785

6886
## Performance qualification and review

0 commit comments

Comments
 (0)