Skip to content

Native chats follow the account picker and keep the conversation - #36649

Open
Jinwoo-H wants to merge 1 commit into
mainfrom
jinwoo/chat-account-follow
Open

Jinwoo-H wants to merge 1 commit into
mainfrom
jinwoo/chat-account-follow

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

When you switch accounts in Orca's account picker, an open chat now moves to that account on its next message and keeps the same conversation. A short grey line in the chat says so: "Now on [email protected] · same conversation".

What Changed

Before

  • A Codex chat stayed on the account it was created with, forever. Switching the picker (for example because that account hit its usage limit) did nothing for chats that already existed.
  • A Claude chat used the new account, but if its history lived only in the old account's folder, the next message failed with "This chat's history is in another Claude account. Switch back to that account to continue it."

After

  • On the first message after the picker changes, the chat stops its idle agent, makes the conversation available to the selected account, records the new account on the chat, and resumes the same conversation there. One quiet line in the chat records the move.
  • A chat that is busy finishes its current turn first, exactly like terminals waiting for "Restart session".
  • If the conversation cannot be made available to the new account (the file is unreadable, or a different file already sits at that spot), the chat stays where it was: Codex keeps running on its old account as today, and Claude keeps today's "switch back" message, now only for that case.

Mechanism

  • The chat host's agent start asks the execution host which account a new chat would use right now. If it differs from the chat's saved account, it carries the conversation over, repins the saved account, then starts. Because the start reads the saved record, the ownership check, the conversation key and the Codex launch all agree on the new account.
  • Carrying reuses the step terminal restarts already use: find the Codex rollout by thread id and hard-link it (or copy it, never overwriting) into the new account's sessions/ folder at the same dated path. Claude transcripts get the same link-or-copy at the same projects/ path; when Claude accounts already share history, nothing is copied.
  • The existing "replace an outgrown agent before the next send" check (used today for sign-out and permission-mode changes) gains one more reason: the picker now selects another account. A move that failed is remembered, so a chat never restarts its agent on every message.
  • The line is an ordinary status row with English text plus an optional field; the desktop translates it.

Hosts and versions

  • Runs on the machine that owns the chat: the desktop, or a remote Orca server using its own account picker. Hosts whose accounts are decided by another machine (WSL guests) keep today's behaviour.
  • No RPC change. Older clients show the row's English sentence; older hosts simply don't move chats.

Why

Terminals already move a conversation to the selected account on restart. Reusing that step for chats gives one account model for chats and terminals and fixes every existing Codex chat, without a per-chat account setting or a second copy step. A per-chat account setting would be another place that decides accounts and drifts from the status bar; switching accounts automatically on a limit would spend another account's quota without asking.

Linked Issue

N/A (maintainer change)

Visual Proof

Isolated dev build, two test Codex accounts with fake credentials, and a stand-in codex app-server that only resumes a thread whose rollout exists under its CODEX_HOME and replies naming its account.

Before (main): after switching to the personal account, the next reply still comes from the work account.

before-main-codex-stays-on-old-account.png

After, light and dark:

01-switch-line-light.png
02-switch-line-dark.png

After, with "Share Codex history across accounts" off, so the rollout was carried by the move itself:

03-carry-without-history-sharing-light.png

Testing

  • I manually tested these changes locally (macOS, isolated dev profile, flows above)
  • Automated tests added/updated
    • Host: a send after the picker changed starts a new agent on the selected account, repins the chat, and writes one row; a failed move keeps the old account and does not loop; a busy chat is not replaced.
    • Execution host: Codex and Claude carry, no-conversation chats, chats already on the selected account, other agents, and hosts whose accounts another machine decides.
    • Carry: Codex rollout hard-linked at the same dated path, already-shared history left alone, missing thread reported; Claude transcript from any known account, shared history, missing transcript.
    • Renderer: the row renders as one faint line, with the account or System default.
  • pnpm tc, touched suites, every pr.yml static-analysis step and check:code-quality:changed pass locally. The real Claude CLI suites show the same 2 failures on main with Claude Code 2.1.316 (effort and model reporting on the init frame), unrelated to this change.

Review

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Ensure no issues in: Security, Cross-platform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance

  • Paths go through the existing cross-platform helpers; the link-or-copy step is the one terminal restarts already use on all platforms.
  • Mobile renders the row's text as a faint aside with no change.
  • Where a link isn't possible (different disks), each account keeps its own copy. A switch refreshes the target's copy from the newest one, and only when that copy is an older version of it; a copy that went its own way is never overwritten.
  • Claude chats from older builds already ran on the picked account even though their saved account didn't say so. Their first start after upgrading updates the saved account quietly, without the "Now on" line.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

@coderabbitai

coderabbitai Bot commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 535b104c-4b81-4f2b-a48a-9f5e6e9aad8d
Commits

Reviewing files that changed from the base of the PR and between 2526da0 and 6150d98.

Files selected for processing: 12
  • src/main/agent-conversation-file-install.ts
  • src/main/claude/claude-chat-account-move.test.ts
  • src/main/claude/claude-chat-account-move.ts
  • src/main/codex/codex-chat-account-move.test.ts
  • src/main/codex/codex-chat-account-move.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-account-follow.test.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-account-follow.ts
  • src/main/runtime/agent-session-record-founding.ts
  • src/main/runtime/agent-session-record-store.ts
  • src/main/runtime/structured-agent-account-follow.test.ts
  • src/main/runtime/structured-agent-account-follow.ts
  • src/shared/agent-session-record.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

Walkthrough

Structured sessions can follow a selected account before starting. The change adds Claude transcript and Codex thread carry behavior, updates session account records, and records account switches in the journal. The chat interface renders account-switch notices with the account name or “System default.” A shared no-overwrite file installer is also used for legacy Codex rollout materialization.

Merge Risk: Moderate · up to 6150d

A chat can switch accounts and resume a transcript missing recent turns. Resolve this before merging unless that behavior is explicitly accepted.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 42.31% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly identifies the main change: native chats follow the selected account while preserving the conversation.
Description check Passed The description covers the required sections, user-visible behavior, implementation, rationale, visual proof, testing, compatibility considerations, and checklist. The linked issue field says this is …
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description covers the required sections, user-visible behavior, implementation, rationale, visual proof, testing, compatibility considerations, and checklist. The linked issue field says this is a maintainer change and uses N/A, which is acceptable under the template’s maintainer exception.

Full details: Docstring Coverage

Explanation

Docstring coverage is 42.31% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 26 functions across 33 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches
Generate docstrings
  • Commit to this branch
  • Create a new PR
  • 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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Nitpick comments: 1
src/main/native-chat/agent-session-wire/structured-agent-session-account-follow.ts: 1

45-45: Trivial · Maintainability & Code Quality · Quick win

Log the swallowed selectedHome failure.

.catch(() => null) drops the error with no trace. The fallback is safe: a null result never retires the child. But nobody can see why a chat stopped following the picker. A sibling path in the same file, followSelectedAccountBeforeStart, logs the equivalent failure with deps.logger.warn.

Add logger to the Pick and log the error. The only caller passes the full StructuredAgentSessionHostDeps, so logger is available.

Proposed fix
 export async function launchedOnOtherAccount(
-  deps: Pick<StructuredAgentSessionHostDeps, 'accountFollow' | 'store'>,
+  deps: Pick<StructuredAgentSessionHostDeps, 'accountFollow' | 'store' | 'logger'>,
   sessionId: string,
   session: Pick<StructuredAgentSessionHostSession, 'accountFollowTried'> | undefined
 ): Promise<boolean> {
   const record = deps.store.getRecord(sessionId)
   if (!deps.accountFollow || !record) {
     return false
   }
-  const selected = await deps.accountFollow.selectedHome(record).catch(() => null)
+  const selected = await deps.accountFollow.selectedHome(record).catch((error: unknown) => {
+    // Unreadable selection never retires a running child; report it so the cause is visible.
+    deps.logger.warn('reading the selected account for a chat failed', {
+      scope: 'account-follow',
+      sessionId,
+      error
+    })
+    return null
+  })

Based on learnings: flag TypeScript code that silently swallows errors or falls back to defaults unless the fallback is explained by a comment or the error is reported.

Source: Learnings


Review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 7e4012a9-a841-4e96-9100-bc2843c178a2
Commits

Reviewing files that changed from the base of the PR and between 0d94c0b and 2526da0.

Files selected for processing: 32
  • src/main/agent-conversation-file-install.ts
  • src/main/claude/claude-chat-account-move.test.ts
  • src/main/claude/claude-chat-account-move.ts
  • src/main/codex/codex-chat-account-move.test.ts
  • src/main/codex/codex-chat-account-move.ts
  • src/main/codex/codex-legacy-session-resume.ts
  • src/main/native-chat/agent-session-journal/journal-storage-schema.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-account-follow.test.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-account-follow.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-agent-start.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-host-current-work.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-host-delivery.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-host-types.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-outgrown-child.ts
  • src/main/runtime/agent-session-record-store.ts
  • src/main/runtime/runtime-account-controller.ts
  • src/main/runtime/session-tabs/structured-session-account-home.ts
  • src/main/runtime/structured-agent-account-follow.test.ts
  • src/main/runtime/structured-agent-account-follow.ts
  • src/main/runtime/structured-agent-session-host-assembly.ts
  • src/main/runtime/structured-agent-session-runtime-contract.ts
  • src/main/runtime/workspaces/workspace-process-listing-dependencies.ts
  • src/main/runtime/workspaces/workspace-process-listing.ts
  • src/renderer/src/components/native-chat/NativeChatAccountSwitchRow.test.tsx
  • src/renderer/src/components/native-chat/NativeChatNoticeRow.tsx
  • src/renderer/src/i18n/locales/en.json
  • src/shared/agent-session-account-switch-row.ts
  • src/shared/agent-session-journal-schemas.ts
  • src/shared/agent-session-journal-types.ts
  • src/shared/native-chat-types.ts
  • src/shared/native-chat/native-chat-notice.ts
  • src/shared/structured-agent-session-status-block.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review.

Comment on lines +20 to +22
if (await claudeTranscriptIn(args.sessionId, args.targetHome)) {
return true
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Major · Functional Correctness · Quick win

Supported by static analysis

Script executed:

#!/bin/bash
# Check how the copy fallback and existing-target handling behave, and whether tests cover a diverged target.
rg -nP -C3 'copySessionFileWithoutOverwrite|installConversationFileWithoutOverwrite' src/main --type=ts -g '!**/*.test.ts'
rg -nP -C3 'ino|diverg|stale' src/main/claude/claude-chat-account-move.test.ts src/main/codex/codex-chat-account-move.test.ts

Repository: stablyai/orca

Length of output: 6318


Script executed:

#!/bin/bash
set -o pipefail
for f in \
  src/main/claude/claude-chat-account-move.ts \
  src/main/agent-conversation-file-install.ts \
  src/main/codex/codex-session-backfill-copy.ts \
  src/main/claude/claude-chat-account-move.test.ts \
  src/main/codex/codex-chat-account-move.ts \
  src/main/codex/codex-chat-account-move.test.ts
do
  echo "===== $f ====="
  nl -ba "$f"
done

Repository: stablyai/orca

Length of output: 14541


Script executed:

#!/bin/bash
set -o pipefail
for f in src/main/codex/codex-legacy-session-resume.ts src/main/codex/codex-session-resume-home.ts src/main/codex/codex-session-backfill.ts; do
  if [ -f "$f" ]; then
    echo "===== $f ====="
    nl -ba "$f"
  fi
done
echo "===== references ====="
rg -n -F -- 'prepareCodexAccountRestartResume' src/main --type=ts
rg -n -F -- 'findTrustedCodexSessionResume' src/main/codex --type=ts

Repository: stablyai/orca

Length of output: 39240


Do not treat an existing target transcript as proof that it is current.

When the initial hard link fails, installConversationFileWithoutOverwrite can create a copy. Later turns can update that copy independently. A subsequent move can return at the target-home check and resume an older transcript, which omits turns made after the copy. The Codex path has the same issue because it ranks the target home first and returns early when source and target are equal.

Reconcile an existing target with the source transcript before returning success. Use content comparison, not only inode, size, or mtime. If the files differ, refuse the move or replace the target safely. Add regression tests for a copied target that receives additional turns before the conversation moves back.

Comment on lines +94 to +105
return
}
await deps.store.repinAccountHome(sessionId, accountHome)
const journal = context.sessions.get(sessionId)?.journal
if (!journal || !activeProviderContext(current).head) {
return
}
const fence = structuredAgentSessionConversationFence(deps.store, sessionId)
await journal
.appendItem(
{ provider: 'orca', clientMessageId: `account-switch:${randomUUID()}` },
agentSessionAccountSwitchBody(account),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor · Stability & Availability · Quick win

Supported by static analysis

Script executed:

sed -n '44,120p' src/main/runtime/structured-agent-account-follow.ts
sed -n '1,75p' src/main/claude/claude-chat-account-move.ts
sed -n '1,85p' src/main/codex/codex-chat-account-move.ts
rg -n 'async commit|commit\(' src/main/native-chat/agent-session-wire/structured-agent-session-attach-lock.ts

Repository: stablyai/orca

Length of output: 5672


Script executed:

set -o pipefail
printf '%s\n' '--- carry helper dependencies ---'
rg -n -F --glob '*.ts' -e 'function installConversationFileWithoutOverwrite' -e 'const installConversationFileWithoutOverwrite' -e 'export .*installConversationFileWithoutOverwrite' -e 'function prepareCodexAccountRestartResume' -e 'export .*prepareCodexAccountRestartResume' src/main
printf '%s\n' '--- exact helper source ---'
claude_file=$(rg -l -F --glob '*.ts' 'export async function carryClaudeConversationToAccountHome' src/main | head -n1)
codex_file=$(rg -l -F --glob '*.ts' 'export async function carryCodexThreadToAccountHome' src/main | head -n1)
printf 'CLAUDE_FILE=%s\n' "$claude_file"
sed -n '1,220p' "$claude_file"
printf 'CODEX_FILE=%s\n' "$codex_file"
sed -n '1,240p' "$codex_file"
printf '%s\n' '--- dependency implementations ---'
install_file=$(rg -l -F --glob '*.ts' 'function installConversationFileWithoutOverwrite' src/main | head -n1)
resume_file=$(rg -l -F --glob '*.ts' 'function prepareCodexAccountRestartResume' src/main | head -n1)
printf 'INSTALL_FILE=%s\n' "$install_file"
sed -n '1,240p' "$install_file"
printf 'RESUME_FILE=%s\n' "$resume_file"
sed -n '1,300p' "$resume_file"
printf '%s\n' '--- attach lock and repin call ---'
rg -n -F --glob '*.ts' -e 'class StructuredAgentSessionAttachLock' -e 'commit(' -e 'repinAccountHome' src/main/native-chat/agent-session-wire src/main/runtime
lock_file=$(rg -l -F --glob '*.ts' 'class StructuredAgentSessionAttachLock' src/main | head -n1)
printf 'LOCK_FILE=%s\n' "$lock_file"
sed -n '1,260p' "$lock_file"
follow_file='src/main/native-chat/agent-session-wire/structured-agent-session-account-follow.ts'
sed -n '70,120p' "$follow_file"

Repository: stablyai/orca

Length of output: 22819


Script executed:

set -o pipefail
printf '%s\n' '--- carry helper dependencies ---'
rg -n -F --glob '*.ts' -e 'function installConversationFileWithoutOverwrite' -e 'const installConversationFileWithoutOverwrite' -e 'export .*installConversationFileWithoutOverwrite' -e 'function prepareCodexAccountRestartResume' -e 'export .*prepareCodexAccountRestartResume' src/main || true
printf '%s\n' '--- exact helper source ---'
claude_file=$(rg -l -F --glob '*.ts' 'export async function carryClaudeConversationToAccountHome' src/main | head -n1)
codex_file=$(rg -l -F --glob '*.ts' 'export async function carryCodexThreadToAccountHome' src/main | head -n1)
printf 'CLAUDE_FILE=%s\n' "$claude_file"
test -z "$claude_file" || sed -n '1,220p' "$claude_file"
printf 'CODEX_FILE=%s\n' "$codex_file"
test -z "$codex_file" || sed -n '1,240p' "$codex_file"
printf '%s\n' '--- dependency implementations ---'
install_file=$(rg -l -F --glob '*.ts' 'function installConversationFileWithoutOverwrite' src/main | head -n1)
resume_file=$(rg -l -F --glob '*.ts' 'function prepareCodexAccountRestartResume' src/main | head -n1)
printf 'INSTALL_FILE=%s\n' "$install_file"
test -z "$install_file" || sed -n '1,240p' "$install_file"
printf 'RESUME_FILE=%s\n' "$resume_file"
test -z "$resume_file" || sed -n '1,300p' "$resume_file"
printf '%s\n' '--- attach lock and repin call ---'
rg -n -F --glob '*.ts' -e 'class StructuredAgentSessionAttachLock' -e 'commit(' -e 'repinAccountHome' src/main/native-chat/agent-session-wire src/main/runtime || true
lock_file=$(rg -l -F --glob '*.ts' 'class StructuredAgentSessionAttachLock' src/main | head -n1)
printf 'LOCK_FILE=%s\n' "$lock_file"
test -z "$lock_file" || sed -n '1,260p' "$lock_file"
follow_file='src/main/native-chat/agent-session-wire/structured-agent-session-account-follow.ts'
sed -n '70,120p' "$follow_file"

Repository: stablyai/orca

Length of output: 22775


Script executed:

set -o pipefail
printf '%s\n' '--- account-follow imports and lock type ---'
sed -n '1,115p' src/main/native-chat/agent-session-wire/structured-agent-session-account-follow.ts
printf '%s\n' '--- lock declarations and implementations ---'
rg -n -F --glob '*.ts' -e 'structuredAgentSessionAttachLock' -e 'StructuredAgentSessionAttachLock' -e 'type StructuredAgentSessionAttachLock' -e 'interface StructuredAgentSessionAttachLock' -e 'commit: async' src/main
printf '%s\n' '--- repin and mutation implementation ---'
sed -n '145,205p' src/main/runtime/agent-session-record-store.ts
rg -n -F --glob '*.ts' -e 'mutate<T' -e 'async mutate' -e 'mutate = ' src/main/runtime/agent-session-record-store.ts src/main/runtime

Repository: stablyai/orca

Length of output: 16357


Script executed:

set -o pipefail
printf '%s\n' '--- account-follow imports and lock type ---'
sed -n '1,115p' src/main/native-chat/agent-session-wire/structured-agent-session-account-follow.ts
printf '%s\n' '--- lock declarations and implementations ---'
rg -n -F --glob '*.ts' -e 'structuredAgentSessionAttachLock' -e 'StructuredAgentSessionAttachLock' -e 'type StructuredAgentSessionAttachLock' -e 'interface StructuredAgentSessionAttachLock' -e 'commit: async' src/main || true
printf '%s\n' '--- repin and mutation implementation ---'
sed -n '145,205p' src/main/runtime/agent-session-record-store.ts
rg -n -F --glob '*.ts' -e 'mutate<T' -e 'async mutate' -e 'mutate = ' src/main/runtime/agent-session-record-store.ts src/main/runtime || true

Repository: stablyai/orca

Length of output: 16357


Script executed:

set -o pipefail
printf '%s\n' '--- attach lock implementation ---'
nl -ba src/main/native-chat/agent-session-wire/structured-agent-session-attach-lock.ts
printf '%s\n' '--- record-store mutation path ---'
nl -ba src/main/runtime/agent-session-record-store.ts | sed -n '300,380p'
printf '%s\n' '--- transaction implementation used by mutate ---'
rg -n -F --glob '*.ts' -e 'private async transact' -e 'async transact' -e 'transact<' src/main/runtime/agent-session-record-store.ts src/main/runtime/agent-session-store-transactions.ts
nl -ba src/main/runtime/agent-session-record-store.ts | sed -n '1,90p'
nl -ba src/main/runtime/agent-session-store-transactions.ts | sed -n '100,175p'

Repository: stablyai/orca

Length of output: 11285


Script executed:

set -o pipefail
printf '%s\n' '--- transaction commit and staging ---'
rg -n -F --glob '*.ts' -e 'commit<T' -e 'private commit' -e 'stage(' -e 'class AgentSessionStoreTransactions' src/main/runtime/agent-session-store-transactions.ts
nl -ba src/main/runtime/agent-session-store-transactions.ts | sed -n '120,300p'

Repository: stablyai/orca

Length of output: 5315


Handle a rejected repin as an account-follow failure.

repinAccountHome runs after the carry and can reject before the record changes. The rejection currently escapes followSelectedAccountBeforeStart, so the pending submission fails even though the original account still has the conversation. Catch and log the error, then return from the lock callback. Returning also skips the account-switch journal row, which must not be recorded when the repin failed.

Suggested fix
-    await deps.store.repinAccountHome(sessionId, accountHome)
+    try {
+      await deps.store.repinAccountHome(sessionId, accountHome)
+    } catch (error) {
+      deps.logger.warn('repinning a chat to the selected account failed', {
+        scope: 'account-follow',
+        sessionId,
+        error
+      })
+      return
+    }
Committable suggestion

IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
return
}
await deps.store.repinAccountHome(sessionId, accountHome)
const journal = context.sessions.get(sessionId)?.journal
if (!journal || !activeProviderContext(current).head) {
return
}
const fence = structuredAgentSessionConversationFence(deps.store, sessionId)
await journal
.appendItem(
{ provider: 'orca', clientMessageId: `account-switch:${randomUUID()}` },
agentSessionAccountSwitchBody(account),
return
}
try {
await deps.store.repinAccountHome(sessionId, accountHome)
} catch (error) {
deps.logger.warn('repinning a chat to the selected account failed', {
scope: 'account-follow',
sessionId,
error
})
return
}
const journal = context.sessions.get(sessionId)?.journal
if (!journal || !activeProviderContext(current).head) {
return
}
const fence = structuredAgentSessionConversationFence(deps.store, sessionId)
await journal
.appendItem(
{ provider: 'orca', clientMessageId: `account-switch:${randomUUID()}` },
agentSessionAccountSwitchBody(account),

…rsation

A Codex chat stayed on the account it was created with, and a Claude chat
whose history was not shared with the selected account failed with "switch
back to that account". Now the first start after the picker changes carries
the conversation to the selected account with the step terminals use on
restart, repins the chat's record, and records "Now on <account> · same
conversation". A busy chat finishes its turn first. When the conversation
cannot be carried the chat stays where it was, and Claude keeps its failure.

@BTForIT BTForIT left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I read carryClaudeConversationToAccountHome, refreshConversationFileCopy and the execution-host createStructuredAgentAccountFollow integration. This already covers the Claude transcript move that I proposed in #50095, and also handles next-send account following and cross-filesystem copies. I'm closing #50095 so upstream has one implementation to review.

Would you take the useful tests and safety details from it here?

  • 2f99cfbc1f5c5f8519bdad295534538d6b923e64 adds four real-filesystem cases in src/main/claude/transcripts/claude-session-account-move.test.ts: launch into a second account with a saved leaf, the same launch without a leaf, same-inode/later-append continuity with repeated preparation, and rejection of a symlink target. The names/imports need adapting to your carry function; this is an offer of the cases, not a claim that cherry-picking the commit directly fits your branch.
  • fee7d458d2cc9551c567fa6bb0c49251db2d3ea9 addresses the review's exact file-identity point: use lstat(..., { bigint: true }) for device/inode equality in an EEXIST race. Two different large inode values can compare equal as Numbers. Your refreshConversationFileCopy / assertMatchingExistingTarget currently use Number metadata too, so that concern applies to the shared installer as well.
  • Keep the actual resume-resolver read-back after materialization, including records with no leaf yet. A successful copy/link operation alone does not prove that Claude's resolver will accept the target directory and file.

Both commits are on the fork branch for #50095. The final head passed all26 pnpm check:changed checks on a Linux build server with Node24.22.3. On v1.4.278, reverting only my launch hook reproduces the two launch failures while the two filesystem-only cases still pass. These are results for #50095, not a validation claim for this PR.

One operational case worth covering in the same history path: subagent .meta.json files can be replaced by atomic rename. A previously hard-linked sidecar then diverges even while the main JSONL still shares its inode. Preserve a divergent copy and reconcile it deliberately; one chat's sidecar conflict should not prevent unrelated chats from being prepared. Our public issue #50093 has the account-switch resume failure; this PR is the broader fix for it.

@BTForIT

BTForIT commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

We are integrating this next-message move with the per-bot account / agent.account.resolve work in #48466. Our acceptance case there is #48466 (comment).

The integration changes the target of this mover, not its lifecycle: resolve the chat's bot/automation account using the same hook as a fresh Claude launch; obtain that account's existing/read or prepared/launch home through the existing Claude profile router; then retain this PR's conversation carry, lease-safe repin and restart. Fall back to the host selection only when the existing hook returns no requested account. No host-wide selection RPC is used by a bot-account change.

The factory dependency is the existing launch resolver, passed from bot wiring:

const requested = record.provider === 'claude'
  ? await deps.resolveClaudeRequestedAccount?.(record)
  : null
if (!requested) return deps.resolveSelectedHome(record, purpose)
// read: withClaudeLaunchAccountPin(router, {}, router.systemDefaultHome(), requested)
// launch: prepareClaudeLaunchAccount(router, {}, router.systemDefaultHome(), requested)

For child workspaces, the account resolver follows recorded workspace lineage to lookup.byHome, validating the parent instance and bounding cycles/depth. This lookup is account-only: it grants no bot tools, prompts or approval policy to a worker. Existing owned structured workers are excluded from in-place following through their native worker-custody authority; continuations still use orchestration admission.

On the current 1.4.279 native host, the port preserves the newer busy/owed-work, actual acquired-child-home, lease, and Codex deletion/hold guards. A failing regression on the host-picker target keeps account A after the bot requests B. With the resolver target connected, the same provider handle resumes on B on the next message, the host pointer stays byte-for-byte on A, and a busy running turn remains on A until completion. Missing/divergent history stays at its source. These cases, history carry and worker exclusion passed 60 tests in our build-server run; VM installation and real provider read-back are still pending.

Our downstream carry is temporary: remove the integration when upstream ships the paired behavior and an installed retained-conversation rehearsal proves the same provider handle on the requested login without changing the host selection. Happy to shape this dependency wiring and the account-only lineage tests to the preferred upstream owner.

This branch has not been deployed

No deployments
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.

2 participants