Skip to content

Remove the superseded replicated-apply client id (closes #3435) - #3754

Merged
mstomar125 merged 2 commits into
mainfrom
issue-3435-remove-superseded-id
Oct 12, 2026
Merged

mstomar125 merged 2 commits into
mainfrom
issue-3435-remove-superseded-id

Conversation

@mstomar125

@mstomar125 mstomar125 commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Closes #3435. This is phase 2 of 2, on top of #3752 (merged).

Merge condition met. nodespace-sync now uses the typed write context (NodeSpaceAI/nodespace-sync#679, merged to Sync main 2b25acf): its apply services are built with with_write_context(WriteContext { skip_playbook_triggers: true, skip_invariant_rules: true }), and its daemon reserves the id with DaemonExtensions::reserved_client_id(SYNC_SERVICE_CLIENT_ID). Sync's canary and test suite pass against this PR's head (evidence in the review comment). Sync never imported the constant, so this does not break its compilation.

What changes

  • Deleted: REPLICATED_APPLY_CLIENT_ID, is_replicated_apply, and the client-id comparisons in the engine gate (write_context_of) and in skips_invariant_rules. Only a WriteContext set in process now skips playbook triggers or invariant rules. A client id, including the formerly reserved value, is only a label for echo suppression.
  • Tests: the tests of the superseded path are removed. New test (d) checks that the old value no longer skips anything when it is not reserved. It is added at every level where it could matter, and builds the old value from fragments, as CLAUDE.md asks of absence tests:
    • core: the invariant matrix refuses create, update and relationship writes labelled with it; bulk_create is refused; a play fires on such a write;
    • daemon: a request whose x-ns-client-id is the old value is still refused by an invariant;
    • fixture through build_shared_services: a play fires for a request presenting it.
  • Doc comments: the proto CLIENT_ID_HEADER doc now says the id never changes how the daemon treats a write.
  • Second commit (c361cb5fe): the last three incidental sync-service strings in core are gone. Two comments in remote-update-policy.ts and its test are reworded, and a serverId test fixture in mcp-integration.test.ts is renamed. Nothing in core now mentions the value.

Core behaviour

  • No change for core users. Nothing in core ever set the old value.
  • The only behaviour change is the security fix: a local client (CLI, agent, any gRPC caller) presenting x-ns-client-id: sync-service can no longer switch off invariants and playbook triggers.

Tests

  • Targeted runs pass: core 727 tests, daemon 29.

  • Mutation testing put the old-value comparison back:

    • in skips_invariant_rules: killed by the core invariant tests and the daemon invariant-refusal test;
    • in the engine's trigger gate: killed by the core engine test and the fixture play test.

    The daemon's a_client_id_header_never_sets_a_write_context checks that the header never sets a context. It does not guard the engine gate, because the old path never set a context.

  • Before merge, the PR goes through the full gate (bun run merge) like any other.

🤖 Generated with Claude Code

@mstomar125

Copy link
Copy Markdown
Contributor Author

HOLD: do not merge yet. This is phase 2 of #3435 and it deletes the superseded "sync-service" path that Sync's pull apply still uses. It merges only after the Sync adaptation (typed write context + reserved client id) has landed and Sync's canary is green against core main. Phase 1 (#3752) is merged.

🤖 Generated with Claude Code

@mstomar125

Copy link
Copy Markdown
Contributor Author

Independent review: APPROVE (head c361cb5fe; no blocker, no should-fix; 4 nits)

Question: does deleting the string path change any behaviour for core users or for Sync's typed-context writes?

(a) Core users: no change, except the intended security fix. A local gRPC client that presents x-ns-client-id: sync-service to a core-only daemon no longer switches off invariant rules or playbook triggers. Nothing in core ever set the value outside tests: at the base, the literal appears only in the constant (events.rs:285), its test, and a frontend serverId fixture that no code branches on. At the head nothing references it, and the merge tree with main fc7dc3770 is clean. The 3 newer main commits don't touch engine.rs, node_service/ or events.rs.

(b) Sync's typed-context writes: no change. Every Sync-labelled handle carries both flags, and core keeps the label and the context together on every path to the engine and the invariant checks.

Findings

  1. Core, none. handle_event gets write_context from emitted.write_context (engine.rs:126 → :505). The removed let write_context = write_context_of(..) was the only rebinding, and nothing shadows the parameter; its uses are :601 (repair) and :610 (trigger skip). For a context with both flags, write_context_of returned it unchanged, so the outcome is identical. skips_invariant_rules (mod.rs:2697) now reads only the flag, and every invariant check goes through it: create, including both bulk-create paths (invariants.rs:134), update (:280) and relationship (:338). Clone copies both fields. Events are created in two places, and both pair the label with the context: emitted() (mod.rs:2948) and the store notifier (mod.rs:1676). The batch key includes both. Three store methods (create_node, create_child_node_atomic, switch_node_type_atomic) notify with WriteContext::default(). Their only production caller is schema seeding with source: None, which the old rule never skipped either.
  2. Sync, none. On Sync main 2b25acf, the only production with_client(SYNC_SERVICE_CLIENT_ID) is src/echo.rs:86-88, chained into .with_write_context(REPLICATED_APPLY_WRITE_CONTEXT) (both flags). These all use that handle: the apply path, the conflict resolver, the chat policy task, cold pull and catch-up, the status watch, the subtree gate, mention reconciliation, and the removal wipe (status.rs:429 re-wraps with replicated_apply_service). Settings and binding writes were never labelled, and still aren't.
  3. Echo suppression, none. It still keys on the client id alone (Sync's EchoGuard::is_own_event, set_excluded_event_origin, WatchNodes own-echo), and the diff touches none of it.
  4. c361cb5fe, none. Two comments and one test-fixture serverId changed; nothing branches on them.
  5. Nit, PR description. Every removed old-id test has a typed-context twin, and the new "old value no longer skips" tests would fail if the comparison came back: the core engine test, the invariant matrix, bulk_create, the daemon invariant refusal (node_service.rs:7627) and the fixture play. One test is overstated: a_client_id_header_never_sets_a_write_context (daemon node_service.rs:7598) would not catch a restored comparison, because the old path never set a context. At the daemon level only the invariant side is caught; the core and fixture tests catch the engine gate.
  6. Nit, Sync-side. tests/sync_client_id_source_guard.rs matches only exact textual forms. It would miss an alias, .to_string(), or a store-level create_node(.., Some(id), ..), and its production-code scan of src/push/supabase.rs stops at the first inline #[cfg(test)] mod (line 697 of ~2200). Nothing violates it today.
  7. Nit, docs. ADR-060 ("Remote-origin events are distinguishable") and ADR-073 (Decision, second bullet) still say the engine gates on the event's origin client tag. Only ADR-082 was amended.

Evidence that Sync is unaffected (run against this PR's head, before merge)

  • Sync canary on Sync main 2b25acf (which has the typed-context adoption), bun run canary --core-ref c361cb5fe1591faaf5d9079f89c93d1d6ab4f815: canary OK. All 9 checks passed: core lock alignment, cargo check --workspace --all-targets, tauri config, app crate tests, frontend build, svelte-check, Sync frontend tests, frontend import boundary, mirrored workarounds.
  • With the pins on this head:
    • tests/replicated_apply_rules.rs: 4/4
    • tests/sync_client_id_source_guard.rs: 5/5
    • the daemon's sync_settings:: tests: 12/12, including a_request_presenting_the_sync_client_id_is_refused (PERMISSION_DENIED)
  • Full Sync workspace (cargo test --workspace --exclude nodespace-sync-app, isolated home, no model): 1101 passed, 0 failed, 15 ignored.

🤖 Generated with Claude Code

@mstomar125

Copy link
Copy Markdown
Contributor Author

Review addressed (no code change was needed; head stays c361cb5fe):

  • 5. PR description: corrected. The mutation-testing line now says which test kills which mutation, and that a_client_id_header_never_sets_a_write_context does not guard the engine gate. The stale "do not merge" hold is replaced with the met condition: Sync adopted the typed context in NodeSpaceAI/nodespace-sync#679.
  • 6. Sync source guard gaps: filed as NodeSpaceAI/nodespace-sync#681. They cover exact-text matching, the production slice stopping at the first inline test module, and the stale doc name. Nothing in Sync violates the guard today, and it lives in Sync, not here.
  • 7. ADR-060 / ADR-073 still describe gating by origin client tag: this is the open architect question from Add a typed in-process write context and reserved client ids (refs #3435) #3752, so it is left for an amendment decision and not changed here. ADR-082 §5 and the extension-points guide (nodespace-docs e22a839) already describe the write context and reserved client ids in final-state terms.

The HOLD from the earlier comment is lifted. Next: mark ready, then bun run merge 3754.

🤖 Generated with Claude Code

@mstomar125
mstomar125 marked this pull request as ready for review October 12, 2026 08:36
mstomar125 and others added 2 commits October 12, 2026 10:47
REPLICATED_APPLY_CLIENT_ID and is_replicated_apply are deleted: only a
WriteContext set in process through NodeService::with_write_context skips
playbook triggers or invariant rules. A client id, the former reserved
value included, is only a label for echo suppression.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ture

remote-update-policy describes a stale broadcast as a replayed write and its
test names another client as the foreign writer; the MCP integration test's
external update uses a neutral server id.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@mstomar125
mstomar125 force-pushed the issue-3435-remove-superseded-id branch from c361cb5 to d4a07db Compare October 12, 2026 08:47
@mstomar125
mstomar125 merged commit af46b30 into main Oct 12, 2026
@mstomar125
mstomar125 deleted the issue-3435-remove-superseded-id branch October 12, 2026 08:47
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.

Remove the replicated-apply client id switch from core (post-release)

1 participant