Skip to content

CONTRACT: fix(ui-server): let another owner login continue a chat's retained voice history (#3963) - #4139

Merged
schlessera merged 8 commits into
mainfrom
fix/3963-voice-account-ownership
Nov 17, 2026
Merged

schlessera merged 8 commits into
mainfrom
fix/3963-voice-account-ownership

Conversation

@schlessera

@schlessera schlessera commented Nov 17, 2026 •

Copy link
Copy Markdown
Owner

Closes #3963

What changed

A chat's retained voice history now belongs to its account, as its safety history does since #3952/#3962. Each owner sign-in is its own principal, so before this a second device's login was refused with Dialogue ownership mismatch when it opened voice in an existing chat. Now another owner login can open voice on the chat's history by sessionId or historyOwnerId. It can read the history, bind and adopt it, and it receives its live pages and dialogue storage errors. This still works after the login that started the chat has been pruned. A typed-first chat's first voice, from either login, reuses the chat's safety history owner instead of forking a second one. Live conversations and epochs stay with the exact login that opened them: another login of the account starts a new conversation on the shared history and cannot reopen or close someone else's. Agent, ambient, system and unknown principals still match only themselves. Exact-principal deletion is unchanged.

  • History access goes through dialogueOwner (packages/ui-server/src/ws/dialogue-storage.ts), which uses sameAccount with the owner row's stored principal_account from 089. Every lookup, open, bind, read, write and close path goes through it.
  • Typed-first adoption matches safety_sessions by account. A safety owner from another account, or with unknown or contradictory evidence, is refused.
  • Epoch authority: migration 090_dialogue_conversation_principal.sql adds dialogue_conversations.principal_id and backfills it from each row's owner. Before this change the owner was always the login that opened the conversation. openDialogue refuses to reopen a known conversation for a different login, and closeDialogue refuses to close another login's conversation. The catalog's ActiveDialogueEpoch carries its opening principalId. Liveness compares the owner's attribution and account, not the caller.
  • Coverage: hasUnretainedVoice counts native voice recovery from any login of the account and from a login whose row is gone, so the chat stays legacy. Another login's unclosed epoch still makes coverage partial.
  • Audience: GET /api/sessions?includeRetainedConversations=true lists the account's host-only histories, using SQL that mirrors sameAccount with IS comparisons. Live dialogue_history pages and dialogue storage errors go to every connected login of the account (dialogueAudience) and to no other account.
  • Contract (additive): changes are recorded in wire, HTTP, package-API and the index. DialogueOwner.principal_account?, SessionCatalog.dialogueAudience? and an optional third owner argument on the DialogueJournal publish callback are all optional, and the api report is regenerated.

Why this shape

The maintainer chose option A on the issue (2026-11-11). This reuses #3962's ownership model (principal_account on dialogue_owners and sameAccount) and adds no second ownership store. The new dialogue_conversations.principal_id is per-conversation attribution and authority. It grants no history access. It is needed because a shared history otherwise leaves the storage layer nothing to stop one login from closing or reopening another login's epoch. conversation_epochs was rejected for that job: it is LRU-pruned to 64 rows and written only after the open.

Proof

bun run check:pr --base origin/main   # passed at 2274f53bf, receipt below

New keyless test file packages/ui-server/tests/dialogue-account-ownership.test.ts has 15 tests on real SQLite with real principals and the real prunePrincipals cleanup path. It covers the storage, catalog, GET /api/sessions route and a live start through WsHost with the offline fake live provider.

Failing first, with packages/ui-server/src and migrations checked out from origin/main: 12 of 13 tests fail. The original same-owner mismatch is error: Dialogue ownership mismatch at dialogue-account-ownership.test.ts:81, where the home login opens voice with the ship's historyOwnerId. The typed-first test fails on DIALOGUE_TYPED_FIRST_REUSES_THE_SAFETY_OWNER (a divergent owner was created), and the live start never opens for the second login.

Mutations, each restored, with the named assertion that failed:

Mutation Fails
M1: openDialogue stores principal_account NULL (removes durable ownership) the pruned-origin continuation: Dialogue ownership mismatch at test line 129 (DIALOGUE_PRUNED_ORIGIN_READS), for both revoked and expired; also DIALOGUE_LIST_INCLUDES_PRUNED_LOGINS_HISTORY
M2: dialogueOwner admits any caller to an owner-account history DIALOGUE_FOREIGN_READ_REFUSED_AFTER_PRUNING: agent, DIALOGUE_FOREIGN_OPEN_REFUSED: agent sessionId, DIALOGUE_CONTRADICTED_EVIDENCE_REFUSED; in the live start the foreign login opened
M3: closeDialogue drops the opening-login check DIALOGUE_OTHER_LOGIN_CANNOT_CLOSE_AN_EPOCH, DIALOGUE_CATALOG_REFUSES_FOREIGN_EPOCH_CLOSE
M4: host live-page audience back to the exact owner principal the live start never delivers the second login's dialogue_history (checkpoint for home.of("dialogue_history"))
M5: appendDialogue drops the conversation-opener check (review finding) DIALOGUE_OTHER_LOGIN_CANNOT_WRITE_AN_EPOCH: voice (received admitted)
M6: the journal writes voice evidence as the history owner, not the epoch's login live start: Dialogue source scope mismatch on the second login's own speech (DIALOGUE_LIVE_SECOND_LOGIN_WRITES_ITS_EPOCH)
M7: catalog bind reconciles live scopes only for the binding login (second review finding) DIALOGUE_CROSS_LOGIN_ADOPTION_STAYS_HEALTHY (expected complete, received partial)
M8: journal adoption overwrites and deletes a live conversation's owner mapping DIALOGUE_ADOPTION_KEEPS_LIVE_INGRESS (expected true, received false)

Existing tests: the 15 affected files (dialogue storage/queue/drain/deadline, conversation and live history, chat lifecycle, principals, #3962's safety-account partition) give 192 pass and 0 fail. A wider set of 132 ui-server files gave 1872 pass and 59 fail. All 59 are in 10 host-boundary/bwrap files, and those 10 files produce an identical failure set with origin/main's source on this host (no unprivileged user namespaces). bun run build and bun run typecheck are clean. The api-surface test passes after regenerating api-report/ui-server.txt.

Provider history: no provider-facing path changed. The live test checks that the first session's seed is byte-identical after the second login continues, and that no ownership metadata reaches the provider options. Both keyless guards (ui-backend-claude and ui-backend-pi provider-history.test.ts) could not run on this host. Both fail at worker launch with bwrap: No permissions to create a new namespace, also with sandbox escalation, so they are left to hosted CI.

{"version":1,"kind":"brain-check-pr-receipt","head":"c4ade520e78976a6ced73a2a010b40a0620885a0","base":"origin/main","mode":"focused","startedAt":"2026-11-17T06:06:47.611Z","finishedAt":"2026-11-17T06:07:56.567Z","checks":[{"name":"all lint and leakage gates","categories":["changeset"],"outcome":"passed","elapsedMs":12650.619726},{"name":"environment documentation","categories":["changeset"],"outcome":"passed","elapsedMs":110.70801299999948},{"name":"pending changeset package names","categories":["changeset"],"outcome":"passed","elapsedMs":67.22769200000039},{"name":"contribution changeset","categories":["changeset"],"outcome":"passed","elapsedMs":19.96509800000058},{"name":"affected fast invariants","categories":["verify","unit"],"outcome":"passed","elapsedMs":56090.941141}]}

Review finding (record on this PR, reviewed head f853cb55b): appendDialogue did not check a voice-sourced record's conversation opener. It was reproduced failing first by the new test "another login of the account cannot write voice evidence into an epoch it did not open": DIALOGUE_OTHER_LOGIN_CANNOT_WRITE_AN_EPOCH: voice expected Dialogue source scope mismatch and received admitted. It is fixed in 2ba7d12fc: storage requires the opener, and the journal writes each epoch as its own login. Audit of the other write paths that take a conversation: reopen (openDialogue) and close (closeDialogue) already check the opener; voice, interruption and end appends now do. bindDialogue deliberately stays history-level: adoption keys a provisional owner by the first conversation's id, binds the owner and changes no epoch state. Backend request/text evidence has no conversation. saveConversationEpoch/saveConversationTask were already exact-principal.

Second review finding (reviewed head 2ba7d12fc): when login B adopted login A's live provisional history into B's session history, the catalog skipped updating A's live scope. It was reproduced failing first by the test "another login's adoption of a live provisional history keeps its live identity and healthy coverage", which uses real SQLite, the catalog and DialogueJournal: DIALOGUE_CROSS_LOGIN_ADOPTION_STAYS_HEALTHY expected complete and received partial. It is fixed in d34c080db. Every live scope of the previous owner now takes the canonical identity in place, whoever bound it, and the bind returns the shared live object, so journal callbacks and published pages name the canonical owner. Grepping the adoption path turned up one more instance of the same class. The journal's backend() adoption replaced a live conversation's owner with a fresh copy and deleted the mapping until the bind settled, so the live epoch's voice was dropped meanwhile (voice() returned false; pre-existing, also for one login). That is fixed in the same commit. Pending opens resolve stale ids through the alias, and storage's bindDialogue flattens alias chains, so neither keeps a stale reference.

Proportionate containment (changed ownership guards)

  • Trigger / not covered: a caller whose account differs from the owner's stored or live evidence, or a different login touching a conversation it did not open. It does not cover the caller's own authorization, which the connection checks already enforce.
  • Restricts: one chat's history owner, or one conversation. Unrelated chats stay usable (DIALOGUE_UNRELATED_CHAT_USABLE).
  • Restricted mode: a contradictory owner is refused rather than forked, because a fork would split the chat's canonical history and safety identity.
  • Clears: there is nothing to clear for a foreign caller. Unknown legacy evidence stays unknown by ruling: it is never reconstructed.
  • Recorded: the refusal reaches the caller as the existing DIALOGUE_UNAVAILABLE or conversation start error. Stored evidence is not rewritten.

Checklist

  • Focused local preflight/behavioral receipts passed; hosted proof pending on this draft.
  • Acceptance criteria from the issue are met (see "Anything left open" for the deletion consequence).
  • Recorded independent review: the orchestrator starts it.
  • Milestone 0.45.0 on the PR and ui-server: an owner continuing a chat by voice from another device is refused as a dialogue ownership mismatch #3963.
  • Changeset .changeset/3963-dialogue-account-ownership.md.
  • No personal data; the leakage gate passes.
  • Integration contract index and components are updated in the CONTRACT: commits.
  • Docs updated; seven drifted citations into touched files repaired.
  • Proportionate-containment answers above.
  • Provider-history guards run on hosted CI (environment-blocked locally, see Proof).

Anything left open

Collisions (bun scripts/collisions.ts --json --pr) at head 2274f53bf: closure #3056; closure #3059; closure #3069; closure #3581; textual #3622; closure #4002; closure #4036; closure #4102. The textual one (#3622) is documentation only (docs/http-api.md, docs/integration-contract/package-api.md), and there is no path collision in packages/ui-server/src.

🤖 Generated with Claude Code

schlessera and others added 3 commits November 17, 2026 04:59
…etained voice history (#3963)

Every owner sign-in is its own principal, and a chat's retained dialogue
belonged to the exact login that started it, so a second device's login
was refused with "Dialogue ownership mismatch". Under the maintainer's
ruling (option A) the history now belongs to the account, as its safety
history does since #3952/#3962.

`dialogueOwner` decides history access with `sameAccount` over the owner
row's stored account (089's `principal_account`), so owner/session/alias
lookup, opening, binding and adoption, reads, writes and close accept
another owner login, also after the starting login is pruned. A
typed-first chat's first voice reuses the chat's safety owner from any
login of its account; a safety owner of another account, or with
unknown or contradictory evidence, is refused rather than forked. The
retained-conversation list and live dialogue pages and storage errors
reach every login of the account and nobody else.

Live-epoch authority stays exact and separate from history ownership.
Migration 090 records the opening login on each dialogue conversation
(backfilled from its owner, which was always the opener before this
change); only that login reopens or closes it. The catalog's active
epochs carry their opening principal, and liveness checks compare the
owner's attribution and account instead of the caller. Native voice
recovery of any login of the account, or of a pruned login, keeps a
chat legacy; another login's unclosed epoch still marks it partial.

Attribution, records, aliases, generations and deletion's exact-principal
rule are unchanged, and nothing enters provider history.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…k additive (#3963)

The owner the host needs to reach every login of the account is now an
optional third argument after the unchanged page and principalId, so an
existing two-argument callback still fits. The api report and the package
component record the three optional additions.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@schlessera schlessera added this to the 0.45.0 milestone Nov 17, 2026
@schlessera schlessera added type: fix Something is broken and must behave the way it is documented. area: ui-server Hono app factory: turn coordinator, auth, session catalog, routes, cron. contract Touches the integration contract: CONTRACT: commit, contract doc updated in the same commit. labels Nov 17, 2026
@schlessera

Copy link
Copy Markdown
Owner Author

Independent review

Reviewed head f853cb5 against base be0bb07. Reviewer: agent. 1 finding: 0 fixed, 0 filed, 0 rejected, 1 without a disposition.

{
  "version": 1,
  "kind": "brain-review-receipt",
  "pr": 4139,
  "head": "f853cb55beca1fa1720604b8448b515fa78cbb2e",
  "base": "be0bb0708e693e5492d63a10af38b112bfc3a6c0",
  "reviewer": "agent",
  "outcome": "findings",
  "findings": [
    {
      "summary": "packages/ui-server/src/ws/dialogue-storage.ts:303: appendDialogue checks a voice source's owner, epoch and provider but never its new conversation principal_id. With account-wide dialogueOwner access, login B can append voice, interruption or end evidence to login A's epoch by supplying its identifiers. This misses #3963's explicit refusal of submissions to another principal's pending epoch; the journal must also pass the opening login when enforcing this guard."
    }
  ]
}

…och (#3963)

appendDialogue checked a voice-sourced record's owner, epoch and provider,
but not the login that opened its conversation. With account-wide history
access another owner login could append voice, interruption or end
evidence to the first login's epoch by naming it. Storage now requires the
appending principal to be the conversation's recorded opener, and the
journal writes each epoch's evidence as its own scope's login instead of
the history owner's attribution. Backend evidence is still written as the
history owner.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@schlessera

Copy link
Copy Markdown
Owner Author

Independent review

Reviewed head f853cb5 against base be0bb07. Reviewer: agent. 1 finding: 1 fixed, 0 filed, 0 rejected, 0 without a disposition.

{
  "version": 1,
  "kind": "brain-review-receipt",
  "pr": 4139,
  "head": "f853cb55beca1fa1720604b8448b515fa78cbb2e",
  "base": "be0bb0708e693e5492d63a10af38b112bfc3a6c0",
  "reviewer": "agent",
  "outcome": "findings",
  "findings": [
    {
      "summary": "packages/ui-server/src/ws/dialogue-storage.ts:303: appendDialogue checks a voice source's owner, epoch and provider but never its new conversation principal_id. With account-wide dialogueOwner access, login B can append voice, interruption or end evidence to login A's epoch by supplying its identifiers. This misses #3963's explicit refusal of submissions to another principal's pending epoch; the journal must also pass the opening login when enforcing this guard.",
      "disposition": "fixed",
      "commit": "2ba7d12fc90725f640dee2e6974544cf6148edd8"
    }
  ]
}

@schlessera

Copy link
Copy Markdown
Owner Author

Independent review

Reviewed head 2ba7d12 against base be0bb07. Reviewer: agent. 1 finding: 0 fixed, 0 filed, 0 rejected, 1 without a disposition.

{
  "version": 1,
  "kind": "brain-review-receipt",
  "pr": 4139,
  "head": "2ba7d12fc90725f640dee2e6974544cf6148edd8",
  "base": "be0bb0708e693e5492d63a10af38b112bfc3a6c0",
  "reviewer": "agent",
  "outcome": "findings",
  "findings": [
    {
      "summary": "packages/ui-server/src/ws/session-catalog.ts:366: Cross-login adoption skips updating active owner references when login B binds login A's provisional conversation. If it merges into B's existing history, activeEpochFor rejects the stale attribution and falsely reports partial coverage; journal callbacks also retain the obsolete owner identity. Reproduced with real SQLite/catalog: a healthy open conversation becomes partial immediately after the cross-login bind."
    }
  ]
}

…provisional history (#3963)

The catalog updated its live scopes' owner identity after a bind only
when the binding login had opened the conversation. When login B's typed
turn adopted login A's live provisional history into B's session history,
A's scope kept the retired owner and its attribution, so activeEpochFor
no longer recognised the healthy epoch and reads reported partial, and
the journal kept publishing the obsolete owner id. Every live scope of
the previous owner now takes the canonical identity in place, whoever
bound it; epoch authority stays with each scope's own principal.

The journal's adoption path also replaced a live conversation's owner
object with a freshly read copy and deleted the mapping until the bind
settled, dropping that epoch's voice in the meantime. A live conversation
now keeps its own object through adoption.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@schlessera

Copy link
Copy Markdown
Owner Author

Independent review

Reviewed head 2ba7d12 against base be0bb07. Reviewer: agent. 1 finding: 1 fixed, 0 filed, 0 rejected, 0 without a disposition.

{
  "version": 1,
  "kind": "brain-review-receipt",
  "pr": 4139,
  "head": "2ba7d12fc90725f640dee2e6974544cf6148edd8",
  "base": "be0bb0708e693e5492d63a10af38b112bfc3a6c0",
  "reviewer": "agent",
  "outcome": "findings",
  "findings": [
    {
      "summary": "packages/ui-server/src/ws/session-catalog.ts:366: Cross-login adoption skips updating active owner references when login B binds login A's provisional conversation. If it merges into B's existing history, activeEpochFor rejects the stale attribution and falsely reports partial coverage; journal callbacks also retain the obsolete owner identity. Reproduced with real SQLite/catalog: a healthy open conversation becomes partial immediately after the cross-login bind.",
      "disposition": "fixed",
      "commit": "d34c080dba56222ef8afdcb76039c6ea02bb08dc"
    }
  ]
}

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@schlessera

Copy link
Copy Markdown
Owner Author

Independent review

Reviewed head 2274f53 against base 1140799. Reviewer: agent. No findings.

{
  "version": 1,
  "kind": "brain-review-receipt",
  "pr": 4139,
  "head": "2274f53bf89fa43e5f367f7265128f3c991780b5",
  "base": "1140799f2f13a37b1fee8f1fa8fe46c171966789",
  "reviewer": "agent",
  "outcome": "no-findings",
  "findings": []
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: ui-server Hono app factory: turn coordinator, auth, session catalog, routes, cron. contract Touches the integration contract: CONTRACT: commit, contract doc updated in the same commit. type: fix Something is broken and must behave the way it is documented.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ui-server: an owner continuing a chat by voice from another device is refused as a dialogue ownership mismatch

1 participant