Repository navigation
Conversation
A Mailbox given a state_dir appends every transition to <dir>/<identity>.jsonl before publishing it, and rebuilds letters, states, leases, claim tokens and idempotency keys from that journal on start; the journal is compacted to one line per letter at startup. A half-written last line (a crash during a write) is dropped; damage anywhere else is reported. MailboxDirectory takes an optional mailbox_state_dir and passes it to the mailboxes it creates. This covers a process restart, not power loss (the journal is flushed, not fsynced), and assumes one live mailbox per state directory. The actor event log stays an observation stream and is still never read back for recovery. The host and MCP commands do not wire the parameter yet, so the change is opt-in. Tests: letters, states, leases and claim tokens come back; idempotency keys come back; a half-written tail is dropped; the journal is compacted on start; mid-file damage is reported; nothing is written without a state_dir; and the directory hands the state dir to its mailboxes.
This branch has not been deployed
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.
Draft for now: not meant to be merged before it has been looked over.
Why
The mailbox prototype is RAM-only by design, and its event log says so explicitly: "append-only observations are never recovery input". A crash means every letter, state, lease and idempotency key is gone. That makes one thing impossible that the agent-team example in #87 needs: a run that survives a restart of the process that hosts the mailboxes.
This adds the smallest thing that makes that possible, opt-in.
What it does
Mailbox(..., state_dir=...): every transition is appended to<state_dir>/<identity>.jsonl(the full private row, including the claim token) before the event is emitted and before RAM is published. A failed journal append publishes nothing.MailboxDirectory(..., mailbox_state_dir=...)passes the directory to the mailboxes it creates, so the host that spawns them does not need to know each identity.Why a second log
The actor event log stays what it is: an observation stream with the public view of a letter (no claim token), replayed offline by
pulsing.mailbox replay. Recovery needs fields the observation stream deliberately omits, so it reads its own journal. The two logs have different contracts on purpose, and the existing document now says which is which.Scope and limits
hostand MCP commands do not wire the parameter yet, so nothing changes for current users; that is the follow-up, together with--resumein the example.mailbox_state_dirat its run directory and resume a run from its ledger.What was verified
tests/python/mailbox/test_recovery.py, 7 new tests: letters/states/leases/claim tokens come back; idempotency keys come back (and a conflicting re-send is still rejected); a half-written tail is dropped; the journal is compacted on start; mid-file damage is reported; nothing is written without a state_dir; the directory hands the state dir to its mailboxes.tests/python/mailbox/test_mailboxes.py(20 tests) still passes, andruff check/ruff format --checkpass on the changed files.mcp2.x installed while the suite needsmcp<2(asci.ymlinstalls it). CI will cover it.