corbits-mailbox: createMailboxPersist accepts refs at insert time - #13
Merged
Conversation
Covers refs landing inside the same transaction (visible to a bus subscriber on the create event), a resolver called once per frame regardless of recipient count, a throwing resolver leaving zero rows while upstream still completes, and over-cap refs truncated to MAX_MAILBOX_REFS.
resolveRefs(args) is called once per frame, before the transaction opens, receiving the persist args plus the resolved senderAuthorization and the decoded frame (or null). Its result is validated with MailboxRefArraySchema and capped at MAX_MAILBOX_REFS (boundRefs, now exported from write.ts), then stored on every recipient row inside the existing single transaction, so the post-commit bus event already carries refs. A throwing resolver follows the wrapper's existing dual-write contract: logged, upstream unaffected, no mailbox row for that frame.
Document the seam in ARCHITECTURE.md's persist section, add a README snippet, and a CHANGELOG entry.
…m, truncation ordering
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.
Fixes CL-7451
Part of CL-7445
Summary
CreateMailboxPersistOpts.resolveRefs?(args)— persist args plus theresolved
senderAuthorizationand thedecodedframe (ornull) —is called once per frame, before the transaction opens.
MailboxRefArraySchemaand capped atMAX_MAILBOX_REFS(boundRefs, now exported fromwrite.ts), thenstored on every recipient row inside the existing single
transaction, so the post-commit bus
createevent already carriesrefs.
resolveRefsfollows the wrapper's existing dual-writecontract: logged, upstream unaffected, no mailbox row for that
frame.
onRowis unchanged.Test plan
bun run typecheckbun test src(362 pass, including 4 newresolveRefscases inpersist.test.ts: refs visible to a bus subscriber oncreate,resolver called once for three recipients, throwing resolver ->
zero rows with upstream completing, over-cap refs truncated to
MAX_MAILBOX_REFS)bun run buildbun test --cwd examples/reference-host(reference-hostacceptance, 20 pass)