Skip to content

AI chats private by default: seeded personal collection + invariant membership rule - #3158

Merged
malibio merged 3 commits into
mainfrom
issue-1740-ai-chat-private-by-default
Sep 27, 2026
Merged

malibio merged 3 commits into
mainfrom
issue-1740-ai-chat-private-by-default

Conversation

@malibio

@malibio malibio commented Sep 27, 2026

Copy link
Copy Markdown
Collaborator

Summary

Implements issue #1740 / ADR-061 §1–§3: every AI chat is private by default, achieved entirely within ADR-037's existing restricted-collection access model.

  • Every install seeds one personal AI-chat collection (restrictedToMembers = true, random node id, one admin member_of edge to the local PersonNode) — mirrors ADR-037 §6's auto-admin bootstrap pattern.
  • A new seeded invariant Play gives every ai-chat node a member_of edge into that collection in the same transaction that creates it (ADR-060), so a chat is never observable unrestricted.
  • The invariant rule's add_relationship target binds to {trigger.node.personal_collection_id} rather than a literal collection id — same-graph-scope eligibility validation rejects literal targets, and the collection's id is random per install. The seed step stamps that id onto the ai-chat schema's own field default directly (bypassing the user-facing update_schema path, following the same "mutate this schema's own declaration list" pattern already allowlisted for handle_update_schema).

Already shipped before this issue, verified rather than re-implemented:

  • ADR-061 §4 (AiChatNodeBehavior::get_embeddable_content() returns None unconditionally, no ai-chat rows enter the vector index)
  • ADR-061 §6/§7 (localOnly schema classification, PTY capture fields, capture.sync removal)

Out of scope for this repo/PR:

  • ADR-061 §3's Pro-tenant-schema insert constraint — that enforcement lives in the private nodespace-cloud repo, not checked out alongside nodespace-core. Tracked in NodeSpaceAI/nodespace-cloud#183.
  • ADR-061 §8's known-but-inaccessible source_chat_node marker — investigation found source_chat_node doesn't exist anywhere in the codebase yet (no schema field, no writer, no reader). Rather than build speculative UI with no real call site, the agreed direction is to prevent ai-chat nodes from being reference targets at all (mentions, wikilinks, and any future source_chat_node), which supersedes §8 outright. Tracked in Prevent ai-chat nodes from being referenced (mentions, wikilinks, source_chat_node) #3155.
  • "Teammate cannot read another user's chat" / "sharing works" ACs — these are consequences of Harden the RLS access walk: assert member_of classification, minimum-depth tie resolution, and cycle bound as tested invariants #1735's already-tested, generic Postgres RLS access walk (user_can_access_node), which applies to any restrictedToMembers collection regardless of node type. No new enforcement needed here; not independently re-tested in this PR since the enforcement mechanism itself isn't in this repo.

Test plan

  • bun run rust:test:lib — 1823/1823 passed
  • bun run rust:test:workspace — 3748/3748 passed (0 unexpected failures; 63 skipped are pre-existing)
  • bun run test (frontend) — 281 files / 5444 tests passed, matches baseline exactly (no frontend changes in this PR)
  • bun run quality:fix — clean, no lint/format changes needed
  • Fixed 4 pre-existing tests whose exact collection/Play counts predated this change's new seeded collection/Play (collection_membership_test.rs ×3, parent_task_completion_play_test.rs, services/collection_service.rs)
  • Allowlisted one intentional own-declarations-only schema-field mutation in schema_chain_blindness_guard_test.rs
  • /pragmatic-code-review + /address-review — not yet run

Related

🤖 Generated with Claude Code

@malibio

malibio commented Sep 27, 2026

Copy link
Copy Markdown
Collaborator Author

Code Review: PR #3158 — AI chats private by default (closes #1740)

Recommendation: COMMENT (would be APPROVE if not self-authored — see note below)

This is a self-authored PR (author malibio, matching the reviewing git identity), so GitHub rejects --approve/--request-changes. Stating the real verdict here: this PR is a net positive and I would approve it. It implements the hard part of ADR-061 correctly — the schema-default-as-binding-target mechanism is sound, the invariant Play passes the actual eligibility validator (not just its own doc comments), the test-count adjustments are legitimate, and all three claimed deferrals check out against the actual codebase. There is one real gap (missing end-to-end test of the mechanism's own novel contribution) that should be fixed, either in this PR or as fast-follow — it does not block merge on its own given the strength of the surrounding unit coverage, but it is the one place this PR's central claim is currently unverified by any test.


Requirements Checklist (issue #1740)

Acceptance Criterion Status Notes
Every install seeds a personal AI-chat collection (restrictedToMembers=true, one admin member_of edge to local PersonNode) ✅ Met seed_personal_ai_chat_collection_if_needed, tested (test_seed_personal_ai_chat_collection)
Collection id is random, not symbolic/username-derived ✅ Met Node::new default UUID; explicitly tested (test_personal_ai_chat_collection_id_is_not_deterministic)
Creating an ai-chat node writes member_of in the same transaction; never observable without it ⚠️ Implemented, not end-to-end tested Play + binding mechanism verified correct against real validation code; no test creates an ai-chat via create_node and asserts the edge actually lands (see Critical/Improvement below)
A failed membership write fails the chat creation (fail-closed) ⚠️ Implemented, not specifically tested Generic invariant fail-closed rollback is well covered in playbook_invariant_integration_test.rs (pre-existing), but not exercised against this specific Play/trigger
Rule ships as a seeded, inspectable, modifiable, resettable Play, warns on edit/disable ✅ Met ai_chat_privacy_play(), is_seeded_play, _seed.default_rules — same pattern as the pre-existing rollup Play; edit/disable warning is generic ADR-060 §8 machinery, not re-verified here (reasonable — not new in this PR)
Pro tenant schema rejects ai-chat insert lacking restricted member_of ⏸️ Deliberately deferred Legitimate — lives in private nodespace-cloud, not checked out here. NodeSpaceAI/nodespace-cloud#183 exists, is well-scoped (concrete constraint pattern, 3 regression-test ACs, correct precedent cited)
Teammate without membership cannot read another's chat ⏸️ Deferred, argued as already covered Legitimate — this is Pro/cloud RLS (user_can_access_node), which ADR-037's Tier Boundary table places outside nodespace-core entirely. #1735 (already merged) is the generic access-walk mechanism; nothing type-specific to ai-chat is needed since the RLS walk is node-type-agnostic. Not independently spot-checked with a new test in this PR, but there is no repo to add cloud-RLS tests to — correctly out of scope
Sharing works (add member_of to open collection) ⏸️ Same as above Same reasoning — ordinary membership mechanics, unaffected by this PR, already covered generically
get_embeddable_content() returns None unconditionally for ai-chat ✅ Already shipped Verified directly: AiChatNodeBehavior::get_embeddable_content in packages/core/src/behaviors/mod.rs (untouched by this diff) returns None unconditionally
SearchScope::Conversations/Everything return no ai-chat results ✅ Already shipped (consequence of the above) Not independently re-verified in this review beyond the embeddable-content check, consistent with "verified rather than re-implemented"
Dangling source_chat_node renders as known-but-inaccessible ⏸️ Deferred, superseded Verified: grep -rn "source_chat_node" across the repo (excluding target/node_modules/.git) returns zero hits — the field genuinely doesn't exist anywhere. #3155 is filed, well-scoped, and explicitly supersedes ADR-061 §8 with a prevention-based design (block ai-chat as a reference target) rather than building a marker for a mechanism that doesn't exist. Legitimate.
Tests pass (bun run test:all) Per PR description 1823/1823 + 3748/3748 + 281 files/5444 claimed; not independently re-run in this review
bun run quality:fix clean Per PR description Claimed clean

ADR-061 §4 and §6/§7 "already shipped" claim: independently verified. local_only: true already exists in core_schemas.rs (lines ~977, 1000) for the machine-bound capture fields, and AiChatNodeBehavior::get_embeddable_content returns None unconditionally. Neither is touched by this diff, consistent with the PR only needing to verify them.


Findings

Critical Issues

None. The core mechanism is architecturally sound and correctly validated against the real eligibility checker, not just its own comments.

Suggested Improvements

1. [packages/core/src/services/node_service/mod.rs] Missing end-to-end test of the seeded Play's actual effect on a real ai-chat node.

Every piece of this mechanism is unit-tested in isolation:

  • Collection seeding + idempotency/repair (test_seed_personal_ai_chat_collection*, test_seed_personal_ai_chat_collection_repairs_missing_admin_edge)
  • Schema default stamping and that it's picked up by ordinary default-application onto a new node's properties (test_ai_chat_schema_default_points_at_personal_collection)
  • The Play's shape passes static eligibility rules in isolation (core_plays.rs unit tests: invariant class, binding-not-literal target, explicit order)

But nothing creates a real ai-chat node through NodeService::create_node in a service that has gone through full seeding (collection + Play both seeded, as NodeService::new does in production) and then asserts a member_of relationship edge exists from the chat to the collection. test_ai_chat_schema_default_points_at_personal_collection gets close but only checks chat_node.properties["ai-chat"]["personal_collection_id"] — the schema-default value landing in properties — not that the invariant Play actually fired and wrote the edge via get_related_nodes/get_relationship_record. I confirmed by grep that no test anywhere in the repo does this (searched packages/core/tests/*.rs and the node_service/mod.rs test module for ai-chat + member_of together — no hits). The generic invariant-execution machinery (fail-closed, rollback, sync-suppression) is well covered by the pre-existing playbook_invariant_integration_test.rs, but that file has zero ai-chat-specific tests, so it doesn't close this gap.

This matters because the binding mechanism — {trigger.node.personal_collection_id} resolving through apply_schema_defaults_with_fields before the invariant rule ever evaluates — is exactly the novel, easy-to-get-subtly-wrong part of this PR (ordering dependency between default-application and rule dispatch within a single create_node call). It's the one place a regression would be invisible to every existing test: if the ordering ever changed such that the invariant rule evaluated its binding before defaults were applied, personal_collection_id would resolve to nothing, target_id would be empty/null, and either the write would silently fail closed (acceptable, if noisy) or — worse — succeed with a bad target depending on how the executor treats an empty binding. Nothing pins today's correct behavior.

Recommendation: add one test that creates an ai-chat node via create_node() against a fully-seeded NodeService, then asserts a member_of edge exists from the new chat to the seeded collection (e.g. via get_related_nodes(&chat_id, "member_of", "out")), and ideally one negative test proving that if the collection is somehow unreachable, chat creation genuinely fails (the AC's "failed membership write fails the chat creation" requirement) rather than silently succeeding open.

2. [packages/core/src/services/node_service/mod.rs:1550-1659] seed_personal_ai_chat_collection_if_needed's three writes (create collection, create admin edge, stamp schema default) are not transactional.

A crash or error between steps leaves a partially-seeded state. This is explicitly by design and follows the established precedent of seed_database_settings_if_needed (also non-transactional, repaired via idempotency-check-on-next-open rather than atomicity) — so it's consistent with the codebase's existing seeding philosophy, not a new risk class introduced by this PR. Flagging as an Improvement rather than Critical because:

  • It's a one-time startup path, not a hot path or user-facing write.
  • The repair logic (walking the schema-default-as-anchor) correctly handles the "collection created, edge failed" and "collection+edge created, default-stamp failed" partial-failure shapes, and both are tested.
  • One gap in the repair story: if the schema-default stamp succeeds but the admin edge also exists (the more common non-partial-failure case), the code takes the "existing_admin_collection" fast path and never touches set_ai_chat_personal_collection_default redundantly — good, that's idempotent by the field.default.as_ref() == Some(&default_value) short-circuit at line 1687.
  • The one truly-unrecoverable partial state is: collection node created, but its id was written to neither the admin edge nor the schema default (e.g. crash between create_node(collection) and create_relationship(...)) — in that case, the orphaned collection is unreachable by both of this function's lookup strategies (no admin edge to find it by, no schema default to find it by) and a brand-new collection gets minted on repair, silently orphaning the first one as an unlinked, unrestricted collection node forever. This is a narrow window (a crash inside two back-to-back writes at startup) and pre-existing-pattern-consistent, but worth a one-line doc acknowledgment given the function's docstring otherwise reads as though every partial-failure shape is handled.

3. [packages/core/src/services/node_service/mod.rs:1669-1734] set_ai_chat_personal_collection_default has no defense against concurrent multi-process seeding.

NodeService::new takes &mut Arc<SqliteStore>, which structurally prevents concurrent seeding within one process (the borrow checker permits only one live construction). But nothing prevents two separate OS processes opening the same fresh SQLite database concurrently (e.g. daemon + a CLI tool both doing first-launch seeding against the same file). In that scenario both could pass the existing_admin_collection/orphaned_collection checks (neither commits before the other reads) and mint two distinct personal collections, each stamping the schema default over the other's — last-writer-wins on the schema field, leaving one collection's admin edge pointing at a "ghost" collection the schema default no longer references. This is a narrow, first-launch-only race, and the project's own standards (no gradual rollout, no half-measures) argue against over-engineering a lock for a case that may not be reachable in the actual deployment topology — worth confirming NodeSpace's process model genuinely guarantees single-process-per-database before treating this as a non-issue, but not blocking.

Nitpicks

  • Nit: packages/core/src/services/node_service/mod.rs:1626-1632 — the seeded collection's title is the literal string "AI Chats", with no i18n/localization consideration. Consistent with how the rest of the codebase seeds content today (e.g. the rollup Play's name), so not a regression, just noting for whenever i18n becomes a concern.
  • Nit: set_ai_chat_personal_collection_default's doc comment (line 1664-1668) explaining why it bypasses handle_update_schema is excellent and exactly the kind of "why, not what" comment CLAUDE.md's maintainability guidance asks for — no change needed, just calling out as a good example.
  • Nit: The PR body's test plan checkbox for /pragmatic-code-review + /address-review is unchecked — per CLAUDE.md's workflow this step is mandatory before merge regardless of review outcome; this review itself satisfies the first half.

Deferral Evaluations (explicit)

a. Pro tenant-schema insert-rejection constraint (#3154): Legitimate. Verified NodeSpaceAI/nodespace-cloud#183 exists, is unassigned (correct per backlog convention), and is well-scoped: concrete constraint pattern cited (enforce_last_admin/enforce_restriction_admin precedent), three specific regression-test ACs (reject bare insert, reject insert with non-restricted member_of, accept insert with restricted member_of), and correctly notes the exact mechanism (trigger vs. deferred constraint) needs design against the actual tenant-schema repo, which isn't available here. This is real follow-up work, not a dodge — the private-repo boundary is real, not fabricated.

b. ADR-061 §8 source_chat_node marker (#3155): Legitimate, and stronger than a typical deferral — it's an architectural improvement (prevention over graceful degradation) that correctly identifies the ADR text describes an unbuilt mechanism. Verified via grep -rn "source_chat_node" . (excluding target/node_modules/.git): zero matches anywhere in the codebase. Building a "known-but-inaccessible" marker for a reference type that doesn't exist would be speculative work with no real call site to validate against — deferring to #3155's prevention-based design (block ai-chat as a reference target entirely, superseding §8) is the more defensible engineering call. #3155 is well-scoped with concrete ACs and explicitly notes ADR-061 needs updating to mark §8 superseded.

c. "Teammate cannot read" / sharing (#1735 coverage claim): Legitimate. This is not really a deferral so much as a correct scope boundary: per ADR-037's own Tier Boundary table, RLS enforcement (nearest-boundary walk, break-inheritance, person-only) is explicitly a Pro/cloud concern with no free-tier equivalent, and the walk (user_can_access_node) is generic across all restrictedToMembers collections regardless of node type — #1735 already merged and already tests this generically. There is nothing ai-chat-specific to test here precisely because the access model treats the ai-chat's collection like any other restricted collection; that's the whole design win ADR-061 §1 claims ("no new RLS branch"). Spot-checked plausibility rather than re-deriving from scratch, per the task's own instruction — the claim holds up against ADR-037's documented tier split.


Summary

The riskiest part of this PR — stamping a random collection id onto a schema field default so an invariant rule's same-graph-scope binding can reach it — is implemented correctly and checked directly against the real validation.rs eligibility code (trigger support, local-write-only, explicit-order requirement for member_of, same-graph-scope binding-template check, and the self-chaining matcher's _ => false fallthrough for (NodeCreated, AddRelationship)), not just asserted true in doc comments. The schema_chain_blindness_guard_test.rs allowlist addition is correctly justified — personal_collection_id is genuinely own-declared on ai-chat, not inherited, so there's no chain-merged set to bypass. All three test-count adjustments are legitimate arithmetic corrections (N → N+1 for the new seeded collection/Play), not loosened assertions — one of them (collection_service.rs) actually adds a stronger assertion (names.contains(&"AI Chats")) rather than just bumping a count. All three claimed deferrals check out against actual verification (grep, ADR text, issue scoping), not just the PR author's word.

The one substantive gap is Improvement #1: no test exercises the mechanism end-to-end against a real, fully-seeded NodeService creating a real ai-chat node and checking the resulting member_of edge. Given how solid the surrounding unit coverage is and how directly the Play was checked against the real validator, I'd call this a net positive worth merging, with that gap closed either now or as an immediate fast-follow before this mechanism sees more edits.

@malibio malibio left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Self-authored PR (author malibio matches the reviewing git identity), so GitHub blocks --approve/--request-changes on this PR. Stating the real verdict explicitly: this is a net positive I would APPROVE. The core mechanism (schema-default-as-binding-target for the invariant Play) is implemented correctly and verified directly against packages/core/src/playbook/validation.rs's real eligibility checks, not just its own doc comments. All three claimed deferrals (#3154, #3155, and the #1735 RLS-coverage claim) check out as legitimate against the actual codebase/ADR text. Test-count adjustments are legitimate, not loosened. One real gap found: no test creates a real ai-chat node end-to-end and asserts the member_of edge actually lands (see full report in the separate PR comment) — recommended as a fast-follow, not a blocker.

malibio added a commit that referenced this pull request Sep 27, 2026
…'s non-atomicity

Adds two tests that were missing: creating a real ai-chat node
actually produces the member_of edge (not just the schema-default
property value, which was already covered), and a failed invariant
action rolls back the whole chat creation (fail-closed). Both require
wiring a PlaybookEngine lifecycle manager and activating the already-
seeded privacy play against it — create_test_service alone never
activates any play, so invariant dispatch is a no-op without this,
which is why the first draft of the positive test silently asserted
against an inert path.

Also documents the one unrecoverable edge case in
seed_personal_ai_chat_collection_if_needed's non-transactional writes:
a crash between creating the collection node and writing either the
admin edge or the schema default leaves an inert orphan neither
repair path can find.

Addresses reviewer recommendations from PR #3158's pragmatic-code-review
(#3158 (comment)).
Skipped: multi-process concurrent first-launch seeding defense (narrow,
first-launch-only race; this is a single-process-per-database desktop
app) and the i18n nitpick (consistent with existing codebase patterns).

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@malibio

malibio commented Sep 27, 2026

Copy link
Copy Markdown
Collaborator Author

Address-review summary

Addressed the one real gap from the pragmatic-code-review (#3158 (comment)):

✅ Addressed: Missing end-to-end test of the seeded invariant Play's actual effect. Added two tests to packages/core/src/services/node_service/mod.rs:

  • test_creating_an_ai_chat_node_joins_the_personal_collection — proves a real ai-chat node created via create_node gets an actual member_of edge, not just the personal_collection_id property value.
  • test_ai_chat_creation_fails_closed_when_the_collection_is_unreachable — proves a failed invariant action rolls back the whole chat creation (fail-closed).

Writing these caught a real bug in my own test setup, not the implementation: create_test_service() never wires up a PlaybookEngine lifecycle manager, so invariant dispatch is a no-op by design (documented directly in dispatch_invariant_rules_in_tx's own doc comment) until a lifecycle manager is set and the play is activated. The first draft of the positive test silently passed against a path that had never actually run the invariant rule. Fixed by following the exact pattern packages/core/tests/playbook_invariant_integration_test.rs already uses (PlaybookEngine::new + set_playbook_lifecycle + activate_play, no engine loop needed since dispatch is synchronous). Both tests now genuinely exercise and pass through the real code path.

✅ Addressed: Doc acknowledgment of the seed's non-atomicity edge case, added to seed_personal_ai_chat_collection_if_needed's doc comment.

⏭️ Skipped: Multi-process concurrent first-launch seeding defense — narrow, first-launch-only race; this is a single-process-per-database desktop app, not a deployment topology where two processes open the same fresh DB concurrently.

⏭️ Skipped: i18n nitpick on the "AI Chats" collection title — consistent with existing codebase patterns (no i18n infrastructure exists yet for any seeded content).

Tests: bun run rust:test:workspace — 3749/3749 passed. bun run quality:fix — clean.

Re-Review Decision

Decision: NO RE-REVIEW NEEDED

Rationale: The only change was adding two new tests (135 lines, one file) that exercise an already-implemented code path — no production code changed, no new functionality, no architectural changes. The original review's verdict was already effectively APPROVE with no critical issues; this closes the one identified test-coverage gap using a pattern lifted directly from existing, reviewed test code in the same codebase. Low-risk, additive, straightforward.

malibio added a commit that referenced this pull request Sep 27, 2026
…'s non-atomicity

Adds two tests that were missing: creating a real ai-chat node
actually produces the member_of edge (not just the schema-default
property value, which was already covered), and a failed invariant
action rolls back the whole chat creation (fail-closed). Both require
wiring a PlaybookEngine lifecycle manager and activating the already-
seeded privacy play against it — create_test_service alone never
activates any play, so invariant dispatch is a no-op without this,
which is why the first draft of the positive test silently asserted
against an inert path.

Also documents the one unrecoverable edge case in
seed_personal_ai_chat_collection_if_needed's non-transactional writes:
a crash between creating the collection node and writing either the
admin edge or the schema default leaves an inert orphan neither
repair path can find.

Addresses reviewer recommendations from PR #3158's pragmatic-code-review
(#3158 (comment)).
Skipped: multi-process concurrent first-launch seeding defense (narrow,
first-launch-only race; this is a single-process-per-database desktop
app) and the i18n nitpick (consistent with existing codebase patterns).

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@malibio
malibio force-pushed the issue-1740-ai-chat-private-by-default branch from e0c93c5 to b89927c Compare September 27, 2026 18:10
malibio added a commit that referenced this pull request Sep 27, 2026
…'s non-atomicity

Adds two tests that were missing: creating a real ai-chat node
actually produces the member_of edge (not just the schema-default
property value, which was already covered), and a failed invariant
action rolls back the whole chat creation (fail-closed). Both require
wiring a PlaybookEngine lifecycle manager and activating the already-
seeded privacy play against it — create_test_service alone never
activates any play, so invariant dispatch is a no-op without this,
which is why the first draft of the positive test silently asserted
against an inert path.

Also documents the one unrecoverable edge case in
seed_personal_ai_chat_collection_if_needed's non-transactional writes:
a crash between creating the collection node and writing either the
admin edge or the schema default leaves an inert orphan neither
repair path can find.

Addresses reviewer recommendations from PR #3158's pragmatic-code-review
(#3158 (comment)).
Skipped: multi-process concurrent first-launch seeding defense (narrow,
first-launch-only race; this is a single-process-per-database desktop
app) and the i18n nitpick (consistent with existing codebase patterns).

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@malibio
malibio force-pushed the issue-1740-ai-chat-private-by-default branch from b89927c to 9347307 Compare September 27, 2026 18:11
malibio added a commit that referenced this pull request Sep 27, 2026
…'s non-atomicity

Adds two tests that were missing: creating a real ai-chat node
actually produces the member_of edge (not just the schema-default
property value, which was already covered), and a failed invariant
action rolls back the whole chat creation (fail-closed). Both require
wiring a PlaybookEngine lifecycle manager and activating the already-
seeded privacy play against it — create_test_service alone never
activates any play, so invariant dispatch is a no-op without this,
which is why the first draft of the positive test silently asserted
against an inert path.

Also documents the one unrecoverable edge case in
seed_personal_ai_chat_collection_if_needed's non-transactional writes:
a crash between creating the collection node and writing either the
admin edge or the schema default leaves an inert orphan neither
repair path can find.

Addresses reviewer recommendations from PR #3158's pragmatic-code-review
(#3158 (comment)).
Skipped: multi-process concurrent first-launch seeding defense (narrow,
first-launch-only race; this is a single-process-per-database desktop
app) and the i18n nitpick (consistent with existing codebase patterns).

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@malibio
malibio force-pushed the issue-1740-ai-chat-private-by-default branch from 9347307 to 86f565a Compare September 27, 2026 18:17
malibio and others added 3 commits September 27, 2026 20:22
…embership rule (closes #1740)

Every install now seeds one restricted personal AI-chat collection
(random id, admin member_of edge to the local PersonNode), mirroring
ADR-037 §6's auto-admin bootstrap pattern. A new seeded invariant Play
gives every ai-chat node a member_of edge into that collection in the
same transaction that creates it, so a chat is never observable
unrestricted (ADR-060, ADR-061 §1/§3).

The invariant rule's add_relationship target binds to
{trigger.node.personal_collection_id} rather than a literal id, since
same-graph-scope eligibility validation rejects literal targets and the
collection's id is random per install. The seed step stamps that id
onto the ai-chat schema's field default directly (bypassing the
user-facing update_schema path), which ordinary schema-default
stamping then carries onto every new ai-chat node.

ADR-061 §4 (never embed ai-chat) and §6/§7 (localOnly classification,
capture.sync removal) were already shipped before this issue; verified
rather than re-implemented. §8 (known-but-inaccessible source_chat_node
marker) and the Pro tenant-schema insert constraint are out of scope
for this repo/PR — tracked in #3155 and #3154 respectively.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Existing collection-listing and core-Play-count assertions were exact
counts that predate this change; every fresh install now also seeds
one "AI Chats" personal collection and one privacy Play (ADR-061),
so those counts grow by one. Also allowlists the new
set_ai_chat_personal_collection_default's own-declarations-only
.fields mutation in the schema_chain_blindness_guard_test — same
shape as handle_update_schema's existing allowlisted entries, not the
extends-chain-blindness bug the guard watches for.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
…'s non-atomicity

Adds two tests that were missing: creating a real ai-chat node
actually produces the member_of edge (not just the schema-default
property value, which was already covered), and a failed invariant
action rolls back the whole chat creation (fail-closed). Both require
wiring a PlaybookEngine lifecycle manager and activating the already-
seeded privacy play against it — create_test_service alone never
activates any play, so invariant dispatch is a no-op without this,
which is why the first draft of the positive test silently asserted
against an inert path.

Also documents the one unrecoverable edge case in
seed_personal_ai_chat_collection_if_needed's non-transactional writes:
a crash between creating the collection node and writing either the
admin edge or the schema default leaves an inert orphan neither
repair path can find.

Addresses reviewer recommendations from PR #3158's pragmatic-code-review
(#3158 (comment)).
Skipped: multi-process concurrent first-launch seeding defense (narrow,
first-launch-only race; this is a single-process-per-database desktop
app) and the i18n nitpick (consistent with existing codebase patterns).

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@malibio
malibio force-pushed the issue-1740-ai-chat-private-by-default branch from 86f565a to d66257d Compare September 27, 2026 18:22
@malibio
malibio merged commit 549f579 into main Sep 27, 2026
@malibio
malibio deleted the issue-1740-ai-chat-private-by-default branch September 27, 2026 18:27
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.

AI chats private by default: seeded personal collection, transactional membership, and implement the non-embeddable revision

1 participant