Skip to content

Wire the blob membership gate into id serve (#173) - #7181

Closed
dezren39 wants to merge 5 commits into
mainfrom
queue/5874-173-blob-gate-shepherd
Closed

dezren39 wants to merge 5 commits into
mainfrom
queue/5874-173-blob-gate-shepherd

Conversation

@dezren39

@dezren39 dezren39 commented Nov 8, 2026 •

Copy link
Copy Markdown
Member

Opened by the branch-disposition execution (2026-11-07) from branch queue/5874-173-blob-gate-shepherd.

Branch origin: queue branch for issue #5874.
This branch was laptop-local work (or a stranded remote branch) with real changes ahead of main and no PR. Per Drew's 2026-11-07 branch-disposition ruling, ahead branches with real changes get a PR; this PR surfaces the work for triage instead of leaving it stranded on a branch.

Triage owner: batch issue in developing-today/code, "Unowned PR batch from branch disposition (2026-11-07)". Outcome per batch triage: close with reason, or route to impl/finish/merge as a follow-on fix task.

Evidence: branch-ahead review ~/workspace/scratch/branch-ahead-review-2026-11-07.md; execution log ~/workspace/scratch/branch-disposition-2026-11-07.md.


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

dezren39 and others added 4 commits November 1, 2026 12:26
The blob gate (blob_gate::decide/blob_events) decided fetches and observes
from a reference index that had no producer, so it was never wired into a
serving path and blobs were served to any peer.

- blob_gate: build_reference_index (with transitive HashSeq children),
  hashseq_children, fold_group_events (group log -> Worlds, world key =
  group create-hash hex), RefreshingWorlds (producer-swappable fold).
- event_store: EventStore::document_references — applied, unremoved
  document.put events as (blob hash, group) pairs; LocalEvents exposes it.
- serve: when the event store is open (web UI), BlobsProtocol runs the
  gate handler (push still decided by the AccessPolicy); a refresh task
  re-folds on the group-warning cadence so removals revoke fetch. Without
  the store, serve keeps push-only handling and warns the gate is inactive.
- local: LocalNode::set_blob_gate lets an embedder supply the gate to
  serve(); default behavior unchanged.
- groups::worlds::Worlds::empty for fail-closed fallbacks.

Tests: blob_gate producer tests (index + HashSeq attribution, group-log
fold gating, refresh revoking a removed member); existing suites pass.
fold_group_events partitioned the group log by world, but
GroupLog::record names the log's global heads as after, so any second
group's events name dependencies living in another partition. fold::index
rejects those partitions with MissingDependency and build_blob_gate
failed the whole gate closed, denying even authorized members.

Keep only intra-partition after edges: ordering inside a world is
preserved and membership reads each world's own projection, so no
authority is lost.

Adds a regression test with two groups where the second create names
the first group's events, as a real group log would.
@dezren39
dezren39 requested a review from a team as a code owner November 8, 2026 04:36
@coderabbitai

coderabbitai Bot commented Nov 8, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 33 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: b3a498e8-062c-442b-9c2c-3f3f5875c596
Commits

Reviewing files that changed from the base of the PR and between 1e46b89 and fa56e7e.

Files selected for processing: 10

  • doc/2026-11-13T09-00-00Z_design_blob_gate_authorization_wiring.md
  • pkgs/id/src/blob_gate.rs
  • pkgs/id/src/commands/serve.rs
  • pkgs/id/src/event_store/documents.rs
  • pkgs/id/src/groups/worlds.rs
  • pkgs/id/src/local.rs
  • pkgs/id/src/local_events.rs
  • pkgs/id/tests/blob_gate.rs
  • pkgs/id/tests/content_removal.rs
  • pkgs/id/tests/documents.rs
  • 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

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-13T09:10:02.802028Z
We couldn’t complete this review. Comment @codex review to try again.
fa56e7e New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a3c1b38e47

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +995 to +999
Some(gate) => BlobsProtocol::new(
&store_handle,
Some(crate::blob_gate::blob_events(
Arc::clone(gate),
crate::blob_gate::BlobPolicy::default(),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Preserve local blob reads when enabling the gate

When the web UI is enabled, this installs the membership gate on the same blob protocol used by the local CLI and REPL. However, LocalEvents::record always writes group: None, so documents published through LocalEvents::publish (including editor saves) are excluded from the reference index; ordinary uploads in commands/put.rs do not create document references either. Consequently, cmd_get_local, cmd_gethash, and REPL fetches are denied for these files even though their metadata remains accessible and the local client is trusted by build_access_policy. Wire a compatible reference/authorization path for existing local operations before enabling this gate unconditionally.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in fa56e7e. The gate now counts local trust: decide_with_local admits fetch/observe from the node's own key and the data directory's client key — the two keys build_access_policy already trusts automatically for writes. id serve passes those as the gate's local readers; LocalNode passes its own node id. Locally published content (group: None documents, plain uploads) is therefore readable by the local CLI/REPL again, while remote peers still need world membership for every hash. Coverage: unit test a_local_reader_fetches_an_unreferenced_blob_but_a_stranger_cannot (blob_gate lib) and the peer-level test of the same name in pkgs/id/tests/blob_gate.rs (local reader fetches an unreferenced blob over the blobs protocol; a stranger is refused with the same denial code).

Comment on lines +775 to +778
let Ok(bytes) = store.get_bytes(hash).await else {
continue;
};
let kids = crate::blob_gate::hashseq_children(&bytes);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Bound blob reads while building the reference index

For every referenced document, this reads the entire blob into memory merely to guess whether it is a HashSeq, including documents with no group that are subsequently discarded from the index. hashseq_children then allocates another hash vector for any 32-byte-aligned payload. With large persisted documents, startup now requires memory proportional to their full contents and can exhaust memory before the router starts; the refresh task repeats this scan every 60 seconds. Identify collection roots explicitly and bound or stream their parsing rather than loading arbitrary document contents during authorization-index construction.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in fa56e7e. The HashSeq expansion in build_blob_gate is now bounded: (1) only group-referenced blobs are candidates — ungrouped references were read and then discarded from the index, exactly the waste named here; (2) a candidate is read into memory only when store.status reports it complete with a size that is a positive multiple of 32 and no larger than MAX_HASHSEQ_BYTES (1 MiB = 32768 children). The size comes from the store status, never from reading content, so building or refreshing the index no longer loads whole documents to guess whether they are HashSeq collections.

Comment on lines +959 to +962
#[cfg(feature = "web")]
let blob_gate: Option<Arc<crate::blob_gate::RefreshingWorlds>> = match &event_events {
Some(events) => {
let folded = build_blob_gate(

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Document the authorization wiring before activating it

This changes production blob authorization without adding the design record required by pkgs/id/AGENTS.md for significant behavioral and architectural changes. A repository-wide Markdown search found existing records describing the gate as unwired, but no design record covering this integration's document-reference source, HashSeq inference, refresh/revocation timing, or ungated behavior without the web event store. Add the required dated document so these authorization trade-offs have a reviewable record.

AGENTS.md reference: pkgs/id/AGENTS.md:L159-L168

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in fa56e7e. Added the dated design record the protocol requires: doc/2026-11-13T09-00-00Z_design_blob_gate_authorization_wiring.md (pkgs/id/docs is a symlink to doc/). It covers the document-reference source (event-store document references, world key agreement, why group: None documents and artifacts are not sources), HashSeq inference (all-children-present plus the size bound), refresh/revocation timing (RefreshingWorlds swaps folds; removal takes effect at the next refresh, fail-closed on unreadable sources), local trusted readers, and the ungated behavior without the web event store (announced by a startup warning naming #173; opening the store in non-web serve is a separate, deliberately unmade change).

@dezren39

Copy link
Copy Markdown
Member Author

🤖 Agent note · salvage check — PR #3917 is fully contained in this PR; closing it as the duplicate

@dezren39

Copy link
Copy Markdown
Member Author

Unblocked 2026-11-13 under Drew's order "fix all fixable and reblocked" (set decisions-2026-11-13-blocked-review): queue task(s) 13492 released to the queue. The block rested on the premise that dezren39-authored work is Drew-owned — revoked by Drew's 2026-11-11 authorship ruling (dezren39 is the fleet's working identity; its issues/PRs are fleet work product, not a hold). Verified live at release: issue open, no Drew-hold labels (user/owned, held, do-not-auto-edit).

… design record (#173)

P1 (serve wiring): the gate now trusts the node's own key and the data
directory client key as local readers (decide_with_local), mirroring
build_access_policy — the local CLI/REPL keep reading locally published
(group: None) and uploaded blobs with the gate on; remote peers still
need world membership for every hash.

P2 (reference index build): HashSeq expansion only considers
group-referenced blobs and reads a blob only when the store status
reports it complete with a positive multiple-of-32 size no larger than
MAX_HASHSEQ_BYTES (1 MiB), so index building no longer loads whole
documents into memory to guess at collections.

P1 (docs): dated design record for the authorization wiring —
reference source, HashSeq inference, refresh/revocation timing, local
trust, and the ungated non-web behavior — per pkgs/id AGENTS.md.

Tests: blob_gate lib 19 passed (new decide_with_local unit test),
blob_gate integration 11 passed (new peer-level local-reader test:
local reader fetches an unreferenced blob, stranger refused),
documents 7 passed, content_removal 5 passed; cargo check --features
web passes.
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@dezren39

Copy link
Copy Markdown
Member Author

🤖 Agent note · task 5874 parked — Codex findings fixed; merge now needs a crate-split port

  • Agent: repo-worker-code, Muse lane code-c
  • Session / ID: queue task 5874

Done this shift (commit fa56e7e on this PR's branch): all three Codex findings on a3c1b38 are fixed and each thread has its disposition reply:

  • P1 local reads (discussion_r4561547054): gate counts local trust via decide_with_local — node key + data-dir client key as local readers, mirroring build_access_policy; LocalNode passes its own node id.
  • P2 bounded index build (discussion_r4561547342): HashSeq expansion only for group-referenced blobs, read only when store status reports a positive multiple-of-32 size ≤ MAX_HASHSEQ_BYTES (1 MiB).
  • P1 design record (discussion_r4561547611): doc/2026-11-13T09-00-00Z_design_blob_gate_authorization_wiring.md.
  • Tests on the branch base: blob_gate lib 19 passed, blob_gate integration 11 passed (incl. the new peer-level local-reader test), documents 7, content_removal 5; cargo check --features web passes. (Pre-existing, unrelated: --all-features lib-test build and id-core lib tests are broken on the base — russh/web-assets/vt100 drift; not touched by this PR.)

Why not merged: this PR is now CONFLICTING with main — not from its own content but from the pkgs/id crate split (#4407/#4408) that landed on main after the branch base: the gate core moved into id-groups/id-worlds with pkgs/id/src/blob_gate.rs as a facade, and serve/LocalNode moved under crates/id-cli. Main still has NO serve wiring for the gate, so the work is still needed — as a port, not a merge.

Port plan (the resume steps, in order):

  1. id-groups/src/blob_gate.rs: add decide_with_local + the local_readers parameter on blob_events (reference: fa56e7e in this PR).
  2. Serve wiring in the id-cli serve command: rebuild build_blob_gate against id-store document references + the id-groups fold, pass node key + client key as local readers, keep the bounded HashSeq expansion and the non-web startup warning.
  3. LocalNode (crates/id-cli/src/local.rs): pass the node's own id as its local reader set.
  4. Port the tests: lib unit test for decide_with_local, the peer-level local-reader test in tests/blob_gate.rs, and the three blob_events call-site updates.
  5. Add the design record (already written on this branch; copy the file over).
  6. Re-run the same four test suites on main, then merge; close this PR as superseded by the port PR with a salvage note (diff the port PR against fa56e7e first — the fixes here are the reference implementation).

@dezren39

Copy link
Copy Markdown
Member Author

Agent note — shepherd map: Codex findings fixed at head; PR now needs a crate-split port before merge (task 13492, lane any-d, 2026-11-13)

State verified fresh: PR OPEN, head fa56e7e, CONFLICTING vs current main. Issue #173's old "Drew-owned hard stop" is withdrawn — dezren39 is the fleet identity (Drew 2026-11-11), and the 2026-11-12 cleanup already released this task on that basis.

Reviews: Codex's three findings (P1 local blob reads locked out when the gate is enabled; P1 design record required before activating authorization wiring; P2 unbounded HashSeq reference-index reads) were all fixed in head fa56e7e — the fixes are in this diff (decide_with_local local-trust admission, bounded/group-only HashSeq expansion, and doc/2026-11-13T09-00-00Z_design_blob_gate_authorization_wiring.md). Codex re-review of the fix head failed on usage limits, so the threads carry the author's fix replies without a bot re-check; the fixes must be re-verified by test at the ported head (below).

Reconciliation map (trial merge on current main, aborted clean; nothing pushed): the pkgs/id crate split (step 7b, #4411, and the blob_gate split) moved every file this PR touches:

  • pkgs/id/src/blob_gate.rs (+491/−23) — on main this path is now a facade; the gate implementation lives in pkgs/id/crates/id-groups/src/blob_gate.rs (with a piece in id-worlds). Port the gate changes (incl. decide_with_local) there; 2 conflict regions at the old path, both from the facade split.
  • pkgs/id/src/commands/serve.rs (+212/−21) — moved to pkgs/id/crates/id-cli/src/commands/serve.rs (deleted at the old path on main: UD conflict). Re-apply the serve wiring at the new home.
  • pkgs/id/src/local_events.rs (+13/−1) — moved to pkgs/id/crates/id-events/src/local_events.rs (UD).
  • pkgs/id/src/local.rs (+29/−1) — now pkgs/id/crates/id-cli/src/local.rs; 1 conflict region (imports: main uses id_core::access / id_sync::fileops; the PR's blob_gate imports must resolve to the post-split homes).
  • Unmoved and clean: pkgs/id/src/event_store/documents.rs, pkgs/id/src/groups/worlds.rs, the design doc, and the tests (pkgs/id/tests/blob_gate.rs +145, content_removal.rs, documents.rs).

Acceptance gate for the port session: port the 5 branch commits onto current main per the map; cargo test -p id --test blob_gate plus the blob_gate unit tests green; the three Codex fix behaviors covered by tests at the ported head (local client-key fetch of an unreferenced blob admitted; remote non-member refused; reference-index build does not read ungrouped blobs); then merge. Task 13492 is parked meanwhile — this is a dedicated port session, not a rebase-and-pray.

@dezren39 dezren39 added queue/claimed Queue worker lifecycle state and removed queue/queued Has a queued queue task labels Nov 14, 2026
@dezren39

Copy link
Copy Markdown
Member Author

🤖 Agent note · task 13492 picked up — resuming the crate-split port (lane any-a)

dezren39 added a commit that referenced this pull request Nov 14, 2026
…te-port

Port blob gate wiring from #7181 onto the pkgs/id crate split (#173)
@dezren39

Copy link
Copy Markdown
Member Author

agent-note:v1 — PR #7181 closed as superseded by PR #9723 (task 5874, lane code-b)

Salvage check (required before closing a duplicate): PR #9723 is a final-state port of this PR's five commits (f62c344, f588a77, 0b0736c, a3c1b38, fa56e7e) onto current main after the pkgs/id crate split, done as a per-file 3-way merge against the split's new homes and verified file by file. Nothing unique to this PR was left behind:

PR #9723 merged 2026-11-14T04:47:24Z (merge commit 3b8741d). Closing this PR as superseded; its branch can be deleted.

@dezren39

Copy link
Copy Markdown
Member Author

🤖 Agent note · task 13492 — this PR is superseded by the crate-split port, PR #9734

  • Agent: repo-worker-code (lane any-a) · task 13492 · issue Phase 3: blob gate is not wired into serve, so blobs are still served to any peer #173
  • Salvage check (diffed, not file-listed): every change in this PR's diff (head fa56e7e7d1, +1042/−47 over 10 files) is carried into PR Wire the blob membership gate into id serve (#173) — crate-split port of #7181 #9734 (+1032/−56 over 12 files) at its post-split home:
    • pkgs/id/src/blob_gate.rs → gate core in id-groups/src/blob_gate.rs (decide_with_local, build_reference_index, hashseq_children, local_readers on blob_events), folded-worlds adapter in id-worlds/src/blob_gate.rs (group-projection FoldedWorlds, fold_group_events, world_key, RefreshingWorlds), facade re-exports at pkgs/id/src/blob_gate.rs.
    • pkgs/id/src/commands/serve.rs → id-cli/src/commands/serve.rs (build_blob_gate, gated BlobsProtocol, refresh task; main's abuse_handle MetaProtocol argument and resolved groups-log path kept).
    • pkgs/id/src/local.rs → id-cli/src/local.rs (LocalNode::set_blob_gate; main's with_origin FileOps and MetaProtocol arguments kept).
    • pkgs/id/src/local_events.rs → id-events/src/local_events.rs (document_references wrapper); event_store/documents.rs → id-events/src/event_store/documents.rs; groups/worlds.rs → id-worlds/src/groups/worlds.rs; tests and the design record unchanged at their paths.
    • Nothing unique to this PR remains unported: the five commits were cherry-picked verbatim and then relocated, and the three Codex fixes (local reads, bounded HashSeq expansion, design record) are present and test-covered at the ported head.
  • Verification at the ported head: cargo check --all-features for id-groups/id-worlds/id-events/id-cli/id pass; lib suites 118 + 637 + 289 + 671 passed; integration tests/blob_gate.rs 16, documents 10, content_removal 12 passed.
  • This PR will be closed as superseded once PR Wire the blob membership gate into id serve (#173) — crate-split port of #7181 #9734 merges; its branch is left in place for reference.

@dezren39

Copy link
Copy Markdown
Member Author

🤖 Agent note · task 13492 — closing as superseded: the port merged as PR #9723

Update to the salvage note above: the canonical port is PR #9723 (merged 2026-11-14T04:47Z, commit 39b6187), built by the task 5874 lane in parallel with task 13492's identical port (PR #9734, now also closed as superseded). Verified fresh against origin/main: all of this PR's work is on main — gate core in id-groups, folded-worlds adapter in id-worlds, serve wiring in id-cli, document_references in id-events, facade re-exports, tests, and the design record. Nothing unique remains on this branch. Closing per the batch disposition rule (recorded reason + salvage verified by diff and symbol mapping, not file list alone).

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.

1 participant