Skip to content

CONTRACT: feat(ui-server): same-account chat deletion for owner logins (#4138) - #4168

Merged
schlessera merged 7 commits into
mainfrom
feat/4138-same-account-chat-deletion
Nov 17, 2026
Merged

schlessera merged 7 commits into
mainfrom
feat/4138-same-account-chat-deletion

Conversation

@schlessera

@schlessera schlessera commented Nov 17, 2026 •

Copy link
Copy Markdown
Owner

Closes #4138. Part of #3234.

What

Any currently authorized owner login may now explicitly delete a chat when every deletion-relevant ownership record proves that same owner account (maintainer ruling, option B). Before this, resolveChat aggregated exact principal IDs across the dialogue owner, voice epochs and typed-creation binding and refused more than one, so a chat two owner logins used by voice could be deleted by neither.

  • resolveChat now returns every ownership record (owners: AccountRecord[]) with the durable account stored beside it. chatOwnedBy requires each record to be the caller's account through the existing sameAccount (current principal row, or stored principal_account; corrupt, contradictory, missing or mixed-account evidence matches nobody). It is checked at the catalog preflight and again inside the commit transaction. authorizedOwner still re-reads the caller's own row at both points, so stored evidence never authorizes a caller.
  • Migration 091 adds principal_account to conversation_epochs and chat_session_owners. The writers (saveConversationEpoch, upsertSession) fill it from the principal's own row once and never rewrite it. Legacy rows are backfilled only where a principal row still proves an owner login, and unknowns stay NULL. This builds on ui-server: a chat whose starting owner login was pruned can never be continued #3962's column (089) and ui-server: an owner continuing a chat by voice from another device is refused as a dialogue ownership mismatch #3963's per-conversation login (090); there is no second ownership store.
  • Provisional (typed-first, no session) chats accept one safety collection per login, provided all collections share one generation. Every collection is a record that must prove the account.
  • The lifecycle row records the initiating login, so the receipt, the retry key and chatRetirement stay bound to it. No record's original principal is rewritten. A stale provisional target is reported as stale to the owner account (previously only to the exact principal), so it is still never revealed to another account.
  • The GitHub detail route's owns uses the same chatOwnedBy. Its policy was already account-scoped (sameAccount on the single principal); now a chat whose records name two logins of the account is no longer "unknown", and pruned records keep their stored evidence.
  • Live conversation/epoch control, busy refusal, stale generation/backend review, permanent fences and per-store outcomes are unchanged. chat_retired still goes to the initiating login's capable connections (documented); every reader already refuses a retired chat.

Docs/contract (CONTRACT: commit): dated amendment and rejected alternatives in docs/decisions/chat-history-deletion.md; admission semantics in docs/http-api.md; index entry in docs/integration-contract.md; wire note and plan cross-references; minor changeset. The pending #3963 changeset's "exact-principal chat deletion is unchanged" now points at this rule. No request, receipt, refusal or frame shape changes.

Tests that changed meaning: several existing deletion tests used a second owner login ("Penelope tablet", passkey) as the "foreign" caller. Under the ruling every owner login is the one owner account, so those fixtures now use a proxy-ambient principal for the other person and a second owner login for the same-account cases. Positional INSERT INTO chat_session_owners VALUES(...) in 16 test files now name their columns, because the table gained a column.

Proof

Real SQLite with the real write worker, through actual catalog admission and commit (tests/dialogue-account-ownership.test.ts, chat-lifecycle.test.ts, chat-deletion.test.ts, chat-session-owner.test.ts):

  • Deletion by the ship login, the home login and a third login that never touched the chat. The operation belongs to the caller, attribution is unchanged, the receipt and handle are not another login's, and the fences refuse the other login afterwards.
  • After the other login is revoked or expired and then pruned, the remaining login deletes; the pruned caller gets unauthorized.
  • Agent, ambient, system, unknown, revoked and expired (unpruned) callers get unauthorized.
  • Twelve unproven-evidence cases (a pruned epoch, creation binding or dialogue owner with no stored account; corrupt accounts on each; an agent epoch claiming owner; agent, ambient, system and unknown epochs; an unknown principal with a corrupt account) each refuse as unavailable, retire nothing, rewrite nothing, and leave an unrelated chat of the account deletable.
  • A provisional chat shared by two logins deletes; with an agent's or ambient's collection beside them it refuses.
  • The write worker's creation binding stores its account and outlives the creator's pruning; an agent's typed chat stays the agent's.
  • Upgrade: migration 091 backfills only verified rows; the unproven legacy chat refuses and the proven one deletes.
  • Commit-boundary rechecks for a second login while the writer is held: revocation gives unauthorized; a foreign epoch or corrupted evidence landing between preflight and commit gives unavailable; busy gives busy.
  • A second login's deletion with failed stores is honestly partial. The other login cannot read or retry it, and restart reconciliation finishes it under the initiator.

Failing-first

The admission files (chat-lifecycle.ts, session-catalog.ts, app.ts) were reverted to origin/main, keeping the migration and writers, and tests/dialogue-account-ownership.test.ts was run: 28 pass, 5 fail, each on the claimed assertion. DELETION_ADMITS_THE_ACCOUNTS_LOGIN failed for ship, home and a third login, and DELETION_DURABLE_EVIDENCE_OUTLIVES_PRUNING failed for revoked and expired. Every refusal case already passed on base (the old code refused everything). After restoring the files, all pass.

Mutations (each applied, run, restored)

Mutation Named failure
M1 chatOwnedBy ignores accounts (owners.length > 0) DELETION_UNPROVEN_OWNERSHIP_REFUSES ×12, FOREIGN_REFUSAL_LEAKS_NOTHING, STALE_NEVER_REVEALS_ANOTHER_ACCOUNT
M2 records compared as bare ids (no stored evidence) DELETION_DURABLE_EVIDENCE_OUTLIVES_PRUNING ×2, corrupt-evidence cases ×3
M3 provisional path back to a single distinct collection PROVISIONAL_RECORDS_EACH_LOGIN ×3
M4 commit-transaction ownership check removed (preflight kept) DELETION_UNPROVEN_OWNERSHIP_REFUSES ×12, PROVISIONAL_MIXED_ACCOUNT_REFUSES ×2, FOREIGN_REFUSAL_LEAKS_NOTHING
M5 lifecycle principal = first record instead of caller DELETION_OPERATION_IS_THE_CALLERS, SECOND_LOGIN_PARTIAL_IS_HONEST (6 fail)
M6 epoch writer stores no account DELETION_RECORDS_CARRY_DURABLE_ACCOUNTS ×3, DELETION_DURABLE_EVIDENCE_OUTLIVES_PRUNING ×2
M7 creation-binding writer stores no account CREATION_BINDING_STORES_ITS_ACCOUNT
M8 stale-alias disclosure back to exact principal STALE_FOR_THE_ACCOUNTS_OTHER_LOGIN
M9 migration backfills without a verifying principal row UPGRADE_EPOCH_ACCOUNTS

Local runs

  • 46 affected ui-server test files: 986 pass, 26 fail before the chat-session-owner fix (which flipped exactly as predicted and is now updated, 2/2 pass). The other 25 failures are in governance-policy.test.ts and http-supported-mounts.test.ts and fail identically (25) on a clean origin/main worktree: sandbox environment failures.
  • Keyless provider-history guards (ui-backend-claude and ui-backend-pi tests/provider-history.test.ts) fail on a clean origin/main worktree in this sandbox, because the native runtimes cannot spawn here. This change touches no provider-facing path, and hosted proof covers both.
  • bun run typecheck: exit 0.

Review round 1 (record at 08c3d18cf, both findings fixed in d2a53cd63bb03723c6a2adac09fc8d2a5d9a0ab8)

  1. Unbound safety collections skipped when a dialogue owner exists. resolveChat now records every unbound collection (session_id IS NULL) under every history owner and alias, in every branch. Grepping for the same class found it under a session chat's history owner too, and that case is fixed and tested. Alias owner rows are deleted on adoption, so they are not another skipped source.
    • Failing-first: UNBOUND_COLLECTION_EVIDENCE_REFUSES failed for {provisional dialogue owner, session history owner} × {corrupt, another account's}, 4 tests.
    • Mutation R1 (drop the lookup): the same 4 fail.
    • The account's own unbound collection still retires (UNBOUND_COLLECTION_OF_THE_ACCOUNT_RETIRES).
  2. Expiry checked against the pre-wait stamp. The commit transaction and the catalog preflight now pass Date.now() to authorizedOwner; input.at stays only as the recorded time.
    • Failing-first: EXPIRY_CHECKED_AT_COMMIT_BY_CURRENT_TIME (held writer, expiry lands after the preflight) and EXPIRY_CHECKED_AT_PREFLIGHT_BY_CURRENT_TIME both retired before the fix.
    • Mutation R2 (commit back to input.at): EXPIRY_CHECKED_AT_COMMIT_BY_CURRENT_TIME fails.
    • Mutation R3 (preflight back to input.at): EXPIRED_CALLER_NEVER_REACHES_BUSY fails.
    • Class grep: the GitHub detail route's principalValid already reads Date.now() after each await, and safety reviews read the clock inside their transaction. Reference-grant creation stamps now before awaiting the writer; that is outside this issue and filed as ui-server: reference-grant creation checks login expiry against a time stamped before the writer wait #4169.

Also: 26fbb98 makes two test fixtures as const. The earlier typecheck predated those tests; the 8 GB bun run typecheck now exits 0. origin/main was merged in f51773e4f (clean; 5 unrelated files). The affected deletion/safety files pass 210/0. Decision record, changeset and moved citations are updated with the fix.

Collisions (bun scripts/collisions.ts --json --pr 4168, head 26fbb985596e7df6f57c4ab3bc181469059e9e1d)

check:pr receipt

{"version":1,"kind":"brain-check-pr-receipt","head":"26fbb985596e7df6f57c4ab3bc181469059e9e1d","base":"origin/main","mode":"focused","startedAt":"2026-11-17T10:00:30.791Z","finishedAt":"2026-11-17T10:02:06.295Z","checks":[{"name":"all lint and leakage gates","categories":["changeset"],"outcome":"passed","elapsedMs":22297.702263},{"name":"environment documentation","categories":["changeset"],"outcome":"passed","elapsedMs":150.54491699999926},{"name":"pending changeset package names","categories":["changeset"],"outcome":"passed","elapsedMs":124.03690699999424},{"name":"contribution changeset","categories":["changeset"],"outcome":"passed","elapsedMs":29.810262999999395},{"name":"affected fast invariants","categories":["verify","unit"],"outcome":"passed","elapsedMs":72876.904884}]}

🤖 Generated with Claude Code

#4138)

A chat two owner logins used by voice refused deletion to both of them:
resolveChat aggregated exact principal IDs across the dialogue owner, voice
epochs and typed-creation binding and refused more than one. Under the
maintainer's option B ruling, any currently authorized owner login may delete
a chat whose every deletion-relevant ownership record proves that same owner
account.

- resolveChat returns every ownership record with its stored durable account;
  chatOwnedBy requires each one to be the caller's account via sameAccount,
  at the catalog preflight and again in the commit transaction. Missing,
  corrupt, contradictory or mixed-account evidence refuses that chat alone.
- Migration 091 adds principal_account to conversation_epochs and
  chat_session_owners, written from the principal's own row and backfilled
  only where a principal row still proves it, so evidence outlives pruning.
- The lifecycle, receipt and retry key stay with the initiating login; no
  record's attribution is rewritten. Provisional chats accept one safety
  collection per login of one generation. A stale provisional target is
  reported to the owner account rather than the exact principal.
- Decision record amended, HTTP admission semantics and contract index
  updated, minor changeset added; existing tests that used a second owner
  login as a foreign caller now use a different account.

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: feat A new capability or a change in user-visible behaviour. 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. security Auth, isolation, egress, secrets, or anything in the threat model. labels Nov 17, 2026
@schlessera

Copy link
Copy Markdown
Owner Author

Independent review

Reviewed head 08c3d18 against base 9f9147f. Reviewer: agent. 2 findings: 0 fixed, 0 filed, 0 rejected, 2 without a disposition.

{
  "version": 1,
  "kind": "brain-review-receipt",
  "pr": 4168,
  "head": "08c3d18cf3241126d9627e38eaec6b982d759704",
  "base": "9f9147f0ec7d335a82c30e07c7c442e21832949a",
  "reviewer": "agent",
  "outcome": "findings",
  "findings": [
    {
      "summary": "packages/ui-server/src/ws/chat-lifecycle.ts:120: When a provisional dialogue owner exists, resolveChat skips its safety collections entirely. A collection with corrupt or mixed-account evidence therefore does not prevent retirement. Reproduced with a corrupt principal_account: retirement succeeded, violating the requirement that every relevant ownership record prove the account."
    },
    {
      "summary": "packages/ui-server/src/ws/chat-lifecycle.ts:198: Commit authorization checks expiry against input.at, the timestamp captured before asynchronous catalog/writer waits. A login expiring during that wait still retires the chat because both authorization checks use the old time. Reproduced successful retirement with expires_at before the current time but after input.at; commit must check current time."
    }
  ]
}

…the current clock (#4138)

Review of 08c3d18 found two holes in same-account deletion admission:

- resolveChat consulted a history owner's unbound safety collections only when
  no dialogue owner existed. With a provisional dialogue owner, or under a
  session chat's history owner, a collection with corrupt or another
  account's evidence did not stop retirement. Every branch now records each
  unbound collection under every history owner and alias.
- The catalog preflight and the commit transaction checked the caller's
  expiry against input.at, stamped before the catalog and writer waits, so a
  login that expired in between still retired the chat. Both now check the
  current clock; input.at stays only as the recorded retirement time.

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

Copy link
Copy Markdown
Owner Author

Independent review

Reviewed head 08c3d18 against base 9f9147f. Reviewer: agent. 2 findings: 2 fixed, 0 filed, 0 rejected, 0 without a disposition.

{
  "version": 1,
  "kind": "brain-review-receipt",
  "pr": 4168,
  "head": "08c3d18cf3241126d9627e38eaec6b982d759704",
  "base": "9f9147f0ec7d335a82c30e07c7c442e21832949a",
  "reviewer": "agent",
  "outcome": "findings",
  "findings": [
    {
      "summary": "packages/ui-server/src/ws/chat-lifecycle.ts:120: When a provisional dialogue owner exists, resolveChat skips its safety collections entirely. A collection with corrupt or mixed-account evidence therefore does not prevent retirement. Reproduced with a corrupt principal_account: retirement succeeded, violating the requirement that every relevant ownership record prove the account.",
      "disposition": "fixed",
      "commit": "d2a53cd63bb03723c6a2adac09fc8d2a5d9a0ab8"
    },
    {
      "summary": "packages/ui-server/src/ws/chat-lifecycle.ts:198: Commit authorization checks expiry against input.at, the timestamp captured before asynchronous catalog/writer waits. A login expiring during that wait still retires the chat because both authorization checks use the old time. Reproduced successful retirement with expires_at before the current time but after input.at; commit must check current time.",
      "disposition": "fixed",
      "commit": "d2a53cd63bb03723c6a2adac09fc8d2a5d9a0ab8"
    }
  ]
}

@schlessera

Copy link
Copy Markdown
Owner Author

Independent review

Reviewed head 26fbb98 against base 9f9147f. Reviewer: agent. No findings.

{
  "version": 1,
  "kind": "brain-review-receipt",
  "pr": 4168,
  "head": "26fbb985596e7df6f57c4ab3bc181469059e9e1d",
  "base": "9f9147f0ec7d335a82c30e07c7c442e21832949a",
  "reviewer": "agent",
  "outcome": "no-findings",
  "findings": []
}

@schlessera
schlessera marked this pull request as ready for review November 17, 2026 16:16
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. security Auth, isolation, egress, secrets, or anything in the threat model. type: feat A new capability or a change in user-visible behaviour.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ui-server: a chat two owner logins used by voice can no longer be deleted by either login

1 participant