Skip to content

feat(memory): an end user's turn writes only to their own namespace (PRD-274 Wave 3) - #1484

Merged
daarthur merged 2 commits into
mainfrom
afp/w3-c-end-user-turn-context
Nov 11, 2026
Merged

daarthur merged 2 commits into
mainfrom
afp/w3-c-end-user-turn-context

Conversation

@daarthur

@daarthur daarthur commented Nov 11, 2026 •

Copy link
Copy Markdown
Collaborator

What and why

PRD-274 Wave 3 PR 2 is end-user chat turns: a server key's chat turn names the end user it's for. This PR is the first of four, stacked so each can be reviewed alone:

  1. This PR: what an end user's turn writes stays theirs.
  2. Recall on their turn reads their namespace and the workspace tier (feat(memory): an end user's turn recalls their facts and the workspace's, never another's (PRD-274 Wave 3) #1485).
  3. The API: endUserId on a server key's POST /api/chat, with consent required (feat(chat): a server key's chat turn for one of its end users (PRD-274 Wave 3) #1486).
  4. Erasing an end user also deletes their chats; PRD-274 §6 is updated (feat(memory): erasing an end user deletes their conversations and sessions too (PRD-274 Wave 3) #1487).

Nothing sets the end user until PR 3, so this PR changes no behaviour on its own.

The rule is held where memory is written, by a context variable for the turn's end user (core/security/end_user_turn.py). That's how memory_audience holds the reader (Wave 4b), rather than path by path:

  • Every durable write of an end user's turn lands in mem:{ws}:end_user:{id} (writes_to_its_end_user on DurableMemoryStore.add).
    • That covers the turn's distilled facts, a tool's outcome and the context guard's flush. Each names the workspace's namespace or an agent's, and each is written to the end user's instead.
    • Each is tagged with their subject, end_user:{id}, so their erasure finds it.
    • A write to another workspace during the turn is refused.
  • Nothing is written where the whole workspace reads (shared_with_no_end_user): no L2 row in memory_short_term, so no mem:{ws}:l2 mirror, and no daily log. The Context Router reads both on every chat turn of the workspace, so another end user's turn, or the owner's Auto, would otherwise recall this person's conversation.

How it was verified

  • tests/test_afp_w3_end_user_turn_writes.py (6 tests):

    • The real store's add writes to the end user's namespace from the workspace's and from an agent's, and their metadata names them.
    • Any other turn writes where it always has.
    • The routed write carries their subject. A namespace of another workspace, a look-alike workspace id, or no namespace prefix is refused.
    • During their turn, store_short_term, store_daily_log and store_daily_summary write nothing.
    • The cache key names the end user only on their turn, and the variable resets after it.
  • With the three wired files taken back to main, the three wiring tests fail; the other three test the new module itself.

  • Every test file touching memory writes, the durable store, SmartMemoryManager, memory_audience or end users passes: 41 files, 550 tests.

  • Code shape has no errors. Its warnings are smart_memory.py and unified_memory_service.py growing, by one import and their decorators. lint-imports is clean, and ruff finds nothing on the changed lines.

  • Tests added or updated, and they fail without this change

  • CI green (a lane marked non-required counts too)

  • Both editions considered: local (AUTH_EDITION=local) and hosted (the same code; nothing sets the end user yet)

  • UI change: screenshots below (none)

AI assistance

  • None
  • Assisted: tool(s): Claude Code; it wrote or changed: the module, its wiring and the tests
  • I have read and understood every line of this change, and can explain it in review

Checklist (AGENTS.md)

  • Every commit signed off (git commit -s)
  • No secrets, customer data or credentials anywhere in the change
  • Settings through orchestrator/config.py; no hardcoded values
  • Replaced paths deleted in this pull request (no shims or V2 copies)
  • Migration (if any): one head, chained onto the current head, safe on a create_all-built database, head pins moved (none)
  • New routes the frontend calls are in orchestrator/reports/route-manifest.json (none)
  • Docs updated where behaviour changed (no behaviour changes yet; PR 4 updates PRD-274)

🤖 Generated with Claude Code

…PRD-274 Wave 3)

The turn's end user is a context variable (core/security/end_user_turn.py),
held where memory is written, as memory_audience holds the reader:

- the durable store's add lands every write of an end user's turn in
  mem:{ws}:end_user:{id}, tagged end_user:{id} for their erasure; a write to
  another workspace during the turn is refused;
- no L2 row (so no mem:{ws}:l2 mirror) and no daily log is written: the
  Context Router reads those on every chat turn of the workspace.

Nothing sets the end user yet, so every write goes where it always has.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Dave Arthur <davidarthur@hotmail.com>

@claude claude 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.

⚠️ Code review skipped — your organization has no extra usage available to pay for this review.

If your organization's extra usage balance is empty, an organization admin can add extra usage credits at claude.ai/admin-settings/usage. If its monthly spend limit was reached, an admin can raise it on the same page. If neither applies, contact Anthropic support.

Once extra usage is available, someone with write access to this repository can comment @claude review on this pull request to trigger a review.

@coderabbitai

coderabbitai Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor
Pre-merge checks: Inconclusive 2

Failed Failed checks: 2 inconclusive

Check name Status Explanation Resolution
Title check Pending This assessment has not completed. The check will be retried on the next pre-merge check run.
Description check Pending This assessment has not completed. The check will be retried on the next pre-merge check run.
  • 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

…, not the key's service user's

The routed write rewrote the namespace and the subject tag but kept metadata.owner, which the private-row and standing-rule filters read: every end user of a key shares its service user, so they would have shared private facts. An owner is now the end user's subject.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Dave Arthur <davidarthur@hotmail.com>
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