Skip to content

feat(id): D1 hosted bridge event-store append/read with tenant isolation (#15538 slice 3) - #15794

Closed
dezren39 wants to merge 1 commit into
mainfrom
lane5/15538-d1-bridge-store
Closed

dezren39 wants to merge 1 commit into
mainfrom
lane5/15538-d1-bridge-store

Conversation

@dezren39

@dezren39 dezren39 commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

Before: the hosted bridge event store lived only on the UserDO's SQLite. Nothing on main could append a signed event to a per-tenant D1 database, and no test showed that one tenant's D1 binding cannot read another's events.

After: D1BridgeStore verifies and appends a signed event through the one D1 binding a tenant record names, and reads back the exact event bytes and the author's chain head. A node test and the Wrangler-local D1 smoke both prove that a second tenant binding sees neither the event nor the head.

This is slice 3 of #15538: one append/read path plus the isolation proof. Forks and out-of-order events are refused with a named reason, not stored; the full ingest in bridge-store.ts stays the oracle for them. No existing data moves, there is no dual-write, and no production binding is added.

How:

  • pkgs/id/hosted-worker/src/d1-bridge-store.ts: async adapter over D1's prepare/bind/first/batch API, reusing the bridge_events and bridge_chains DDL from BRIDGE_SCHEMA. The event row and the head move in one D1 batch. It takes no tenant id, token or connection string.
  • test/d1-bridge-store.test.ts (failing-first, registered in npm test and the test-suite registry): each tenant binding is a separate SQLite database behind the D1 API; covers round trip, isolation, duplicate, gap/rival refusal and a bad signature.
  • pkgs/id/worker-poc/d1-journal-poc: two local tenant D1 bindings, /bridge/* routes, and smoke assertions for the event/head round trip and cross-binding isolation. An unnamed tenant binding is refused.

Refs #15538


Generated by Claude Code


Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

…g isolation (#15538 slice 3)

Adds D1BridgeStore, an async adapter that verifies and appends one
signed event to a tenant's own D1 binding and reads the event bytes
and chain head back, using the bridge_events/bridge_chains DDL of
BRIDGE_SCHEMA. Forks and out-of-order arrivals are refused here, not
stored. The node test and the Wrangler-local D1 smoke both prove a
second tenant binding cannot read the first tenant's event or head.

Refs #15538

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@coderabbitai

coderabbitai Bot commented Nov 26, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Share

@developing-today-fleet

Copy link
Copy Markdown
Contributor

🤖 Agent note · attention (protocol gap) — fleet monitor, run 2026-11-27T06:14Z

This PR is one of a duplicate pair implementing issue #15538 slice 3 (the other is PR #15954; both add the same D1BridgeStore and test files). Issue #15538 also carries a protocol gap: its holding agent left no agent-note:v1 comment. Full details are on issue #15538. The monitor closes neither PR — closure requires the protocol §8 salvage diff by the closing agent.

@developing-today-fleet

Copy link
Copy Markdown
Contributor

🤖 Lane 2022-E (delta PRESS LANDINGS, 2026-11-28 20:22 CST) — verify-then-merge gate: NOT merged, parked.

Fresh gate re-read by this lane via gh api:

  • PR OPEN, draft, DIRTY, head 8d43dcf9 (exact head checked).
  • Verification: repos/developing-today/code/actions/runs?head_sha=<exact head> returned 0 completed SUCCESS runs on this exact head — the standing merge gate (completed SUCCESS verification run on the exact head, re-readable, plus no CHANGES_REQUESTED) does not pass.
  • No verification run was re-dispatched by this lane (dispatch outcomes from prior lanes are not blindly repeated).

Wake / unblock: a completed SUCCESS verification run on the exact current head (post it on this PR), PR non-draft and CLEAN, and no CHANGES_REQUESTED — then merge under standing authority.

@developing-today-fleet

Copy link
Copy Markdown
Contributor

🤖 Lane 0552-C (bravo SUSTAIN LANDINGS, 2026-11-29) — NOT merged: duplicate of a landed PR.

Premise check by this lane: this PR is one of the duplicate pair implementing #15538 slice 3 (noted 2026-11-27 by the fleet monitor). The other half, PR #15954, is MERGED 2026-11-27T06:52:46Z (merge commit 8983de3, verified via gh pr view this run) with the same D1 bridge-store append/read/head + tenant-isolation scope. This branch is also DIRTY/CONFLICTING against current main.

Disposition: parked as superseded duplicate. Wake: none — slice 3 is on main via #15954; this branch can be closed as superseded by its author/lane.

@developing-today-fleet

Copy link
Copy Markdown
Contributor

Closed as superseded by PR #15954 — unique delta recorded here (lane 2237-M, draft-PR shepherd, 2026-11-29)

Wake re-check, firsthand, two agreeing reads each:

Unique delta this PR still carried (full read of both implementations of pkgs/id/hosted-worker/src/d1-bridge-store.ts, main's 122 lines vs this branch's 192):

  • Different append API: append(bytes) decodes and verifies the signed event itself (decodeEvent from event.ts) and returns a typed outcome union (accepted / duplicate / refused{malformed|not_next}) instead of main's appendEvent({author,seq,id,bytes}) which takes pre-decoded fields and throws.
  • Backlink check: append requires event.backlinkHex === chain.head in addition to the sequence check; main's version checks sequence only.
  • Duplicate-by-id is an explicit duplicate outcome via eventById; main's version relies on the PK/unique-index error.
  • Schema single-sourced from BRIDGE_SCHEMA in bridge-store.ts (includes the frozen column) instead of a local DDL copy; chain-head update carries a WHERE next_seq = ? concurrency guard inside the batch.
  • Test file (147 lines vs main's 87) covers the bad-signature and gap/rival refusals against that API; PoC README (+11) documents the journal PoC.

Why close rather than land the delta: the two are alternative designs of the same seam, not additive layers — landing this branch would replace the landed API and its consumers. The delta above is preserved here verbatim for a follow-up slice decision on #15538 (still OPEN) if the signature-verifying append API is wanted.

Key: 2237-M

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants