Skip to content

fix(cognition): scope persona tool calls to the turn's room, not nil - #1703

Merged
joelteply merged 1 commit into
canaryfrom
fix/cognition-context-scope
Jun 20, 2026
Merged

joelteply merged 1 commit into
canaryfrom
fix/cognition-context-scope

Conversation

@joelteply

Copy link
Copy Markdown
Contributor

Problem (correctness + security)

The deliberation faculty built ToolExecutionContext with context_id = Uuid::nil(), so command_executor's scoped(ctx.context_id) scoped every persona tool call to a phantom nil room. A persona's hands acted in the wrong room — and, per the trust model, that's a security bug too: commands land outside the authorized context.

This is the cognition instance of the identity-model work: per IDENTITY-SCOPE-PEER-LIVENESS-MODEL.md Part A (airc #1273), Context (the room / contextId) is the third ID tier and must be carried, never dropped to nil — and never conflated with Session (which stays nil here, deliberately: it's ephemeral and not load-bearing for scope/trust, per A.5). A.6 step 3.

Fix

Thread the turn's room through the cognition cycle:

  • Workspace gains room_id (the contextId the tick reasons within). Workspace::new is the nil-room shorthand for faculty-isolation tests; Workspace::in_room / WorkspaceCycle::run_in_room carry the real room.
  • WorkspaceTrace gains room_id so a replayed trace correlates to its room.
  • LlmDeliberationFaculty::tool_context(ws) stamps context_id = ws.room_id; session_id stays nil deliberately.
  • service_loop runs the cycle via run_in_room(burst, ctx.identity.default_room) — the room the burst header already declares.

Note surfaced (not fixed here)

IncomingMessage carries no per-message room (lamport, peer_id, text only) — itself an instance of the missing context axis on the cognition input. A per-message contextId is the deeper follow-up; today default_room is the correct available context.

Test

tool_calls_are_scoped_to_the_turns_room asserts the executor receives context_id == the turn's room (and never nil) — the regression guard for the nil-scope bug.

Full cargo test -p continuum-core --lib: 4599 pass; the only failure is the known parallelism flake record_turn_writes_fixture_json_under_home (task #7 — passes in isolation, confirmed), unrelated to this change. No #[derive(TS)] types touched (ts-rs binding guard unaffected).

🤖 Generated with Claude Code

The deliberation faculty built ToolExecutionContext with context_id =
Uuid::nil(), so command_executor's `scoped(ctx.context_id)` scoped every
persona tool call to a PHANTOM nil room. That's both a correctness bug (a
persona's hands act in the wrong room) and a security one (commands land
outside the authorized context) — see
docs/architecture/IDENTITY-SCOPE-PEER-LIVENESS-MODEL.md Part A: context
(the room/contextId) is the third ID tier and must be carried, never
dropped to nil.

Thread the turn's room through the cognition cycle:
- Workspace gains `room_id` (the contextId the tick reasons within);
  `Workspace::new` is the nil-room shorthand for faculty-isolation tests,
  `Workspace::in_room` / `WorkspaceCycle::run_in_room` carry the real room.
- WorkspaceTrace gains `room_id` so a replayed trace correlates to its room.
- LlmDeliberationFaculty::tool_context(ws) stamps context_id = ws.room_id;
  session_id stays nil deliberately (ephemeral, never load-bearing for
  scope/trust per A.5).
- service_loop runs the cycle via run_in_room(burst, default_room) — the
  room the burst already declares. (IncomingMessage carries no per-message
  room yet; a per-message contextId on the cognition input is the deeper
  fix — the missing context axis. Today default_room is the correct
  available context.)

Test: tool_calls_are_scoped_to_the_turns_room asserts the executor receives
context_id == the turn's room (and never nil). Full lib suite: 4599 pass;
the only failure is the known parallelism flake
record_turn_writes_fixture_json_under_home (task #7, passes in isolation),
unrelated to this change.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@joelteply
joelteply merged commit 55d1dc5 into canary Jun 20, 2026
4 checks passed
@joelteply
joelteply deleted the fix/cognition-context-scope branch June 20, 2026 23:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant