Skip to content

Hand a leaver's pages to the owner with gbrain access member handover (GBRA-593) - #9684

Merged
capy-ai[bot] merged 1029 commits into
masterfrom
gbra593-member-handover
Nov 19, 2026
Merged

capy-ai[bot] merged 1029 commits into
masterfrom
gbra593-member-handover

Conversation

@garrytan

@garrytan garrytan commented Nov 18, 2026 •

Copy link
Copy Markdown
Owner

An admin can now run gbrain access member handover <member> after switching a teammate off. It previews, then applies, giving the pages only that person read, and folder rules naming only them, to the owner or to a member they pick. Pages other people read stay as they are.
Undo (--undo <id>, once the member is enabled again) restores each page's and rule's recorded readers and the source bindings it moved. Pages edited since are skipped.
Nothing changes on upgrade. The new access_handovers table is created empty, and every write needs a preview plus --yes --expect <plan_hash>.

What changed

When a teammate leaves a company brain, the pages only they could read stay readable by nobody until someone relabels them by hand. The new handover command finds those pages, shows the plan, and moves them in one approved step that can be undone.

  • Handover command (src/core/access/handover.ts, src/commands/access-handover.ts). The preview puts the leaver's pages in groups:

    • kept and folder: go to the owner by default.
    • shared and source: kept as they are by default.
    • memory: listed only, never changed.

    It also shows who gains and who loses access, the leaver's credentials and groups, and a plan_hash. --set kept=<member>|everyone|keep, folder=…, shared=drop and source=<member> change a group's target. Opening pages to everyone is never a default.

  • Apply writes exactly the approved items through the existing writers: page readers through the label-only write, rules through the store's rule write. It rechecks each item first and records old and new readers per item on an access_handovers row. A run that skips an item exits 1 with handover_partial, and the same command resumes it. --status <id> moves a Git-backed handover from publishing to applied once Git has committed the page files.

  • Refusals, each with the command that fixes it: handover_member_enabled, handover_owner_unset, handover_rules_held (a rule change on that source is already waiting for approval; now checked on a resumed run too), handover_partial and handover_undo_member_disabled. access_member_invalid gets two new reasons, audience_target and leaver.

  • Handing over again after an undo works: a new preview after an undo gets a new plan_hash, so the apply writes again instead of returning the undone record.

  • Doctor: a new check, access_pages_read_by_nobody, lists pages no enabled member reads. It names the handover command when those pages name a disabled member. It reads members through SQL, so doctor takes no member flags.

  • member disable and member rm now print the handover command.

  • Label-write fix (its own commit, f663a16). The label-only write refused every readable_by written as a list with one reader per line, which is how put_page writes it. So on a Git-backed brain, both the handover and gbrain repair visibility --readers skipped those pages. repair visibility --readers now also edits those pages: it replaces the list with one readable_by: [...] line and keeps every other byte of the file. A list holding a comment, a nested item, or a block scalar is still refused, and the file is left byte for byte. A new test covers each refused form on a managed git source.

    • Moved assertion 1, test/readers-label-setter.test.ts. Before: spliceLabelLines on readable_by:\n - alice-example returned null. After: it returns the file with readable_by: [owner-example], or without the key for a remove. The forms that are still refused moved into their own case, and comment and nested-item forms were added to it.
    • Moved assertion 2, test/label-repair-derived-stamps-gst2603.test.ts, the fixture for declined pages. Before: readable_by:\n - bob-example. After: readable_by:\n # kept by hand\n - bob-example, which is still refused, so the test still checks that a declined page counts as declined and the run still exits 0.
  • The new access_handovers table is registered in the graduation and deletion inventories, and the schema and doctor goldens are refreshed.

  • Docs: docs/guides/member-handover.md, a "When someone leaves" section in company-brain.md and access-designations.md, a line in the mcp-access skill, and an entry in docs/architecture/key-files/access.md.

Why

A company brain should stay readable by the people still on it. Today, switching a teammate off strands every page they kept to themselves; this gives an admin one previewed, reversible step to hand those pages to someone who still reads.

Blast radius

It touches page labels, folder rules and source bindings, but only through the existing label-only write, rule write and binding helpers, and only for items the operator approved by plan_hash (src/core/access/handover.ts applyHandover, read in full; walked by test/access-member-handover.test.ts on PGLite, repo-less and managed git). On a brain with no repository the labels and rules go to the database and the access_handovers row is the record; on a Git-backed source the page files and .gbrain/access.yml are committed and the row stores the commit ids. Migration v322 only creates an empty table.

Test Coverage

Coverage audit (read-only, no tests generated): 14 of 22 traced paths have a test (64%), 13 of 22 at two stars or better (59%). Untested: an invalid --set value, an unknown or self target, a removed leaver, the 10,000-page truncation warning, handover_partial from a page edited between preview and apply, --set source=<member>, and CLI usage refusals. Two new tests came from the review: a default handover after an undo applies again, and a resumed handover refuses while another rule change is held.

The audit also flagged the stress gate's 256-shard guard as removed. That was its two-dot diff against a newer master, not this branch: the three-dot diff does not touch scripts/stress/gate.ts.

Pre-Landing Review

Two blockers were found and fixed in one fix round, each with a test that failed before the fix and passes after:

  • src/core/access/handover.ts:196: after an undo, a fresh default preview produced the same plan_hash as the undone handover, so the apply returned the undone record, wrote nothing and exited 0, leaving the pages readable by nobody. The hash now includes the newest undone handover of that member. Test: "a default handover after an undo applies again".
  • src/core/access/handover.ts:300: a resumed handover skipped the held-rule check, so writeApprovedRules could approve another operator's held widening rule change nobody previewed. The check (refuseHeldRules, handover.ts:361) now runs before every rule write, the resume included. Test: "a resumed handover refuses while another rule change is held".

One finding is left open: after a crash between the rule write and its approval inside writeApprovedRules, a resume now refuses with handover_rules_held on the handover's own held change (src/core/access/handover.ts:300). The second-model review rated it blocking; nothing is lost, and gbrain access apply --source <id> installs exactly that change, after which the same command resumes. It is not fixed here because the one fix round was used; it is the first follow-up.

Not fixed (below the blocking bar):

  • src/core/access/handover.ts:280: forward and undo plans share the member-handover approval key, so --undo X --expect <forward hash> runs a forward handover; it needs a hash the operator previewed for something else.
  • src/core/access/handover.ts:284: the --expect hash is not checked against the member named on the command line.
  • src/commands/access-handover.ts:86: --undo does not check that the named member is the handover's member.
  • src/core/access/handover.ts:155: the 10,001-row scan also counts pages that never change, so a brain with more than 10,000 pages naming the leaver can relist the same window.
  • src/core/access/handover.ts:116: the owner is not checked as enabled or as someone other than the leaver.
  • src/core/access/handover.ts:404: undoing a source handover can unbind a target that was bound before.
  • src/commands/doctor/checks/access-pages-read-by-nobody.ts:71: a timed-out scan reports ok.
  • src/core/access/handover.ts:298: a multi-source resume that refuses on a later source leaves the row applying with no item reasons.
  • src/commands/access-rules.ts:352 and src/core/access/handover.ts:300: a widening queued in the milliseconds between the check and the write is still approved with the handover's change.
  • src/core/access/handover.ts:196: the after_undo lookup has no fallback on a brain behind v322; migrations gate this.

Second-model review (openai/gpt-6.1-sol): completed, one finding (the open one above).

Documentation

Status: updated. One factual entry was added to the per-file index for the access code; no blockers.

Scope: committed changes on gbra593-member-handover (base e9044af, head 27256e1): the leaver handover command gbrain access member handover, migration v322 access_handovers, the access_pages_read_by_nobody doctor check, a stricter list of blocked label edits, the new handover guide and updates to the access guides, the error codes, the company-brain tutorial and the mcp-access skill copies.

Documentation health:

  • docs/guides/member-handover.md: current (new guide; groups, defaults and refusal codes match the source)
  • docs/guides/access-designations.md: current
  • docs/guides/error-codes.md: current
  • docs/tutorials/company-brain.md: current
  • skills/mcp-access/SKILL.md and its plugin copies: current, consistent with each other
  • docs/architecture/key-files/access.md: updated (adds an entry for handover.ts, access-handover.ts and the doctor check)

Coverage debt: llms.txt and llms-full.txt are generated and were not changed by this audit; whether they need regenerating for the new guide is up to the generation step. No diagram drift was found.

Tests
  • bun test test/access-member-handover.test.ts test/doctor-access-pages-read-by-nobody.test.ts test/readers-label-setter.test.ts test/label-repair-derived-stamps-gst2603.test.ts test/graduation-inventory.test.ts test/cli-flag-equals.test.ts at 37b7ca5: 99 pass, 0 fail (PGLite).
  • bun test test/access-member-handover.test.ts after the review fixes: 5 pass, 0 fail (PGLite); the two new cases failed before the fix.
  • bun run typecheck: clean.
  • Full suites (bun run test, bun run test:serial, bun run test:slow, bun run test:e2e) are carried from full-ci at the pushed head; not run on this 4-core machine.

Agent notes

  • Plan: approved: autoplan-20261117010353 (plans/company-brains/leaver-handover.md, PR 2).
  • Migration: placeholder v322. The final number is set at landing with bun run migrations:renumber.
  • VERSION: skipped (this repo writes versions at release).
  • /ship receipt: not written yet. The write refused with PREGATE_REMOTE_UNCLEARED (macos-validation, native-locks and the full remote gate have no run at this head), and the raw-SQL baseline commit 19dfbad after the review asks for one more voices read before the receipt can bind.
  • Tests: test/access-member-handover.test.ts (repo-less and managed git), test/doctor-access-pages-read-by-nobody.test.ts, test/readers-label-setter.test.ts and test/label-repair-derived-stamps-gst2603.test.ts.
  • REVIEW_LOOP: passes=2 blocking_found=3 deferred=0 noted=1 fixed=2 scope=frozen unrecorded=1 ledgers_read=4 dispatches=4
  • Gate edits: 60 listed, 17 read, 0 findings (RH-14 tagged src/core/cli-flag-registry.generated.ts: the regenerated flag list gains --set, --status and --undo for the new subcommand; no check was relaxed)
  • Open blocking-rated finding left for the owner: s11/outside-voice#1 (src/core/access/handover.ts:300, resume refuses on its own interrupted rule change).
  • Refs p1/red-team#1
  • Refs p1/specialist-batched#1

Approvals

Plan: approved (record r-6ce4f204a4eb)
Plan check: approved (record r-6ce4f204a4eb)

{"head":"27256e1c70b47a4f01163d2dc4131c458a9c919f","run":"ship-9684-b","status":"started","review_loop":{"passes":1,"blocking_found":2,"deferred":0,"noted":0,"fixed":2,"scope":"frozen","rounds":1,"dispatches":{"specialist":1,"red-team":1}}}

@trunk-io

trunk-io Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

😎 This pull request was merged.

garrytan and others added 13 commits November 18, 2026 10:45
A rebuilt brain numbers its pages in another order, so a restored occurrence could name an unrelated page; the purge cascade then kept the original when its real page was purged. Restore now looks the page up by source and slug.

Review-Finding: p2/outside-voice#1 reader=outside-voice
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
…ript changes (#9648)

A oneshot child that decides correctly to write nothing but answers in prose instead of the skip JSON dead-letters under require_writes and releases its key, so every cycle paid for the same transcript again and doctor reported dream_paid_loop. A dead synthesize child that finished cleanly with no page write now counts as settled for that content key; a changed transcript has a new key and is synthesized again.

Reported by @andreineacsu; first fixed by @Masashi-Ono0611 in #9651.

Co-Authored-By: Masashi-Ono0611 <98894508+Masashi-Ono0611@users.noreply.github.com>
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
Known limits from #9707's final review: the room mark is judged with the caller's own fact grant (GST-3066), and owner tokens minted with gbrain auth create store ['world'].

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
A timestamp like 2026-02-30 or 25:61 used to be accepted by the Rust store and stored as written. The store now checks the calendar: the day must exist in its month, hours, minutes and seconds must be in range, and 24:00:00 and a :60 leap second roll over the same way Postgres does. Page dates (effective_date) use the same check.

Review-Finding: specialist-batched#1 reader=specialist-batched
…d) pages

Three writes could leave a segmented page's search text wrong on the Rust store:
- sealChunks accepted a segmented page and replaced the chunks built from its segments. It now refuses (invalid_state), and a page in an archived source is not found, as on Postgres.
- deleteChunks removed the chunks but kept the page's seal, so a later unsealed write was read as current. It now clears the seal.
- createVersion of a segmented page wrote a version with no body and no reference to one. It now refuses with a typed capability_missing instead of writing an empty version. This changes the store's contract on purpose: the old test that pinned a version of a shell page is rewritten to expect the refusal.

Also adds a test that an impossible effective date is refused and writes nothing.

Review-Finding: adversarial-native#2 reader=adversarial-native
Review-Finding: adversarial-native#3 reader=adversarial-native
Review-Finding: adversarial-native#1 reader=adversarial-native
… holds

Creating a segmented page, or moving or reviving one with a new body, skipped the check that two live pages never share one source file. Both paths now run the same check as an ordinary page write and refuse with origin_claimed, as Postgres refuses with its unique index.

Review-Finding: red-team#1 reader=red-team
…EXCLUDE names

The Rust store hid only its built-in prefixes (test/, attachments/, .raw/). Pages under prefixes the operator lists in GBRAIN_SEARCH_EXCLUDE showed up in results. The adapter now passes the same resolved list Postgres uses, and include_slug_prefixes still brings a prefix back.

Review-Finding: outside-voice#1 reader=outside-voice
…it locked

If close() ran while an open() waited in the worker queue, the open finished afterwards and held the brain's lock with no handle to release it. The open now sees the close and refuses with store_closed, so the brain can be opened again.

Review-Finding: outside-voice#3 reader=outside-voice
…d) page

The export read the body of every page as one string, which a segmented page refuses, so it stopped with no manifest. It now skips each segmented page and counts it in the manifest (skipped_pages_segmented).

Review-Finding: outside-voice#4 reader=outside-voice
…s, search excludes, close during open, corpus export)
…er-reads-protected-sections-3058

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

# Conflicts:
#	src/mcp/http-transport.ts
The census shells out to git grep, which made the structural-suite classifier list the whole database suite as structural; on its own file only the census is.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
@capy-ai capy-ai Bot added the full-ci Maintainer-only: run the full Test and E2E suite on this PR head label Nov 18, 2026
@github-actions github-actions Bot removed the full-ci Maintainer-only: run the full Test and E2E suite on this PR head label Nov 18, 2026
garrytan and others added 5 commits November 18, 2026 10:57
…d the pages.ts size

verify on the master merge: the test's Postgres arm runs in the Postgres lane, bodyStripsFor (inline pages only) and protectedTakesFilter (body flags on a segmented page) are reviewed body readers, and pages.ts grows 8 lines for the owner option and the room body check.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
… login-shaped word

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
The export holds the full text of a private brain, so it refuses an output
directory inside a git working tree unless --allow-in-repo is passed. The check
read every git error as "outside a repository": an inherited invalid GIT_DIR,
a missing git or unsafe ownership let the export write into a working tree.

Now inherited GIT_* settings are dropped for the probe, only git's own
"not a git repository" answer counts as outside, and any other failure refuses
with the git error and the --allow-in-repo way out.

Red before: with GIT_DIR pointing nowhere, the unfixed exporter passed the
guard and created its output directory inside a git repository.

Review-Finding: targeted#1
@capy-ai capy-ai Bot added the full-ci Maintainer-only: run the full Test and E2E suite on this PR head label Nov 18, 2026
@github-actions github-actions Bot removed the full-ci Maintainer-only: run the full Test and E2E suite on this PR head label Nov 18, 2026
garrytan and others added 4 commits November 18, 2026 11:10
…re when only its occurrences change

The page purge cascade (removing a purged page's sealed originals), the rename move of occurrence slugs, the
restore rule that skipped originals whose page is missing, and doctor's count of unreferenced originals move to
their own change (GST-3074). This change now never deletes a secret store row: a restore only adds rows, ties each
restored place to the page that holds its slug now, and never overwrites an existing entry.

The backup is now due when only occurrences changed, for example a new page that uses an existing secret.

Review-Finding: p4/outside-voice#3 reader=outside-voice
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
…, and honour embedding_disabled on every embedding route (#9653, #9715)

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
garrytan added a commit that referenced this pull request Nov 18, 2026
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

# Conflicts:
#	src/core/schema-migrations/latest.generated.ts
#	src/core/schema-migrations/registry.generated.ts
#	test/fixtures/goldens/migrations/records.json
garrytan added a commit that referenced this pull request Nov 18, 2026
garrytan and others added 19 commits November 19, 2026 11:29
…remember-valid-from-starter

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
… identity

apple/helper/scripts/install.sh builds, signs, installs and registers the helper, reusing the signing identity it made on the first run so macOS grants carry over, and refuses to make a second one. gbrain-apple-helper register registers the background agent with SMAppService. The helper's macOS CI job runs install, reinstall, repair and the no-keychain refusal.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
…nclaw-skill-resolver-real-gateway

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
…hed off, and slow to build

A failed first run removes its half-made signing keychain. An interrupted swap restores the installed app on the next run. One install runs at a time. The keychain no longer locks itself during a long build. register leaves an agent that was switched off in Login Items alone and says how to turn it on. CI checks each refusal's exit code and message.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
…member-handover

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

# Conflicts:
#	src/core/schema-migrations/registry.generated.ts
#	test/fixtures/goldens/exports/types.json
#	test/fixtures/goldens/migrations/records.json
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
…calls-docs

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
…s an id is confirmed alone

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
…member-handover

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

# Conflicts:
#	skills/skills.lock.json
@capy-ai capy-ai Bot added the full-ci Maintainer-only: run the full Test and E2E suite on this PR head label Nov 19, 2026
@github-actions github-actions Bot removed the full-ci Maintainer-only: run the full Test and E2E suite on this PR head label Nov 19, 2026
@capy-ai
capy-ai Bot merged commit b6adf16 into master Nov 19, 2026
65 checks passed
garrytan added a commit that referenced this pull request Nov 19, 2026
Master's v326 (pages title hash index) took the number #9684's access
handovers held, so in this local tree access handovers moves to v327 as

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
#9684 will, and this branch's owner-only reads migration moves to v328.
garrytan added a commit that referenced this pull request Nov 19, 2026
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
garrytan added a commit that referenced this pull request Nov 19, 2026
@garrytan garrytan mentioned this pull request Nov 19, 2026
capy-ai Bot added a commit that referenced this pull request Nov 19, 2026
Releases v0.60.747.0 with seven changes since v0.60.746.0, including `gbrain access member handover` for when someone leaves a company brain (#9684, adds migration v327, an empty new table).
- A person's pages are never linked without you: a person pair that shares an id is confirmed on its own, after you read why it was proposed (#9762)
- A remote put_page now tells the brain owner when it kept private fact rows the content left out or reworded, and points at forget_fact (#9760)

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
Co-authored-by: garrytan <garrytan@gmail.com>
garrytan pushed a commit that referenced this pull request Nov 19, 2026
What users get from master in this sync:
- gbrain access member handover hands a leaver's pages to the owner (#9684)
- Duplicate-person linking now asks first and confirms people who share an id one at a time (#9762)
- Company-brain tutorial explains how imported calls are kept to their attendees; --propose heading fixed for partly matched calls (#9718)
- One-script install of GBrain Helper on a Mac that keeps its macOS permissions (#9816)
- The brain owner is told when a remote put_page kept private fact rows (#9760)
- The brain owner sees the same private fact rows in as_of and known_as_of reads as in get_page (#9733)
- Turning iMessage sending off cancels a text still on its way, and --off only reports success it can show (#9791)
- Starter MCP clients can date a remembered fact with valid_from (#9802)
- A secret store restore ties an original only to a page that still holds its marker (#9806)
- Concepts hidden by a purged input come back rebuilt from their current members (#9794)
- Nightly test of the OpenClaw skill-resolver plugin inside a real gateway (#9799)
- Version stamps v0.60.746.0 and v0.60.747.0 (#9814, #9828)

Conflict resolution: valid-time-read.ts keeps the trunk's engine-sql imports and adds master's owner fence view. The generated files (migration registry, CLI flag registry, raw-SQL baseline, export and migration goldens) take master's copy for now and are regenerated in the next commit. Master took migration v327 (access handovers), which clashes with the trunk's v327; the renumber follows.
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