Skip to content

fix(accounts): keep Claude's bypass when an account switch restarts the session - #36359

Closed
Nelef wants to merge 3 commits into
stablyai:mainfrom
Nelef:fix/claude-account-restart-permission
Closed

Nelef wants to merge 3 commits into
stablyai:mainfrom
Nelef:fix/claude-account-restart-permission

Conversation

@Nelef

@Nelef Nelef commented Oct 30, 2026 •

Copy link
Copy Markdown

ELI5

When you switch Claude accounts, Orca restarts the running Claude sessions on the new account. If Orca had no record of how a session was started, it restarted it without --dangerously-skip-permissions, so a session that was skipping permission prompts started asking again. Claude already tells Orca which permission mode it is in, so the restart now keeps the bypass when Claude reports it was on.

What Changed

Before: an account-switch restart resumes a Claude pane with its recorded launch arguments. A pane with no record resumes as plain claude --resume <id> (#29898's guard against giving a hand-typed claude a bypass it never had). As #34690 reports, that includes Orca-launched panes whose launch was not recorded, and a claude --dangerously-skip-permissions typed by hand. The restart then records agentArgs: "" for the pane, so later restarts drop the flag even when the recorded launch is found.

After:

  • The Claude hook listener keeps the lead session's permission_mode on providerSession.permissionMode, the way it keeps effort (fix(agent-resume): resume Claude sessions at their own effort level #33765). Claude sends the field on prompt, tool and stop hooks but not on SessionStart, so hooks without it keep the last value. Subagent hooks are ignored.
  • normalizeAgentProviderSession, the sleeping-session schema and the recovery-record comparison keep the field, validated as a short alphabetic token. effort and the new field are read by one helper so agent-session-resume.ts stays within its line budget.
  • agentProviderSessionForHostEnsure leaves the field out of agentSession.ensure, whose strict ProviderSession schema would reject it, as it already does for cwd.
  • resolveAgentAccountRestartResumeStartup adds Claude's bypass argument when the session reports bypassPermissions and the resume arguments don't already bypass. Recorded arguments are kept as they are. A recorded agentCommand replaces the arguments on resume, so the bypass is spliced into it as well, before any -- terminator, with the builder the resume selectors use; that covers the claude with empty arguments an earlier restart records.

Why

This is the first fix suggested in #34690. It keeps #29898's guarantee: only a session that reports bypassPermissions gets the flag, and Claude only enters that mode when its own flags or settings allow it, so a hand-typed claude without the bypass still gets none. The mode comes from Claude's hooks, which already supply the resume identity, cwd and effort. Terminal OSC status never carries a provider session, so terminal output cannot set it.

The other suggestion in #34690, falling back to Settings → Agents arguments, would also bring back --add-dir and similar flags, but it would give the configured bypass to a hand-typed claude that never had it. That is the case #29898 guards against, so this PR keeps only the permission mode. The restarted pane records the flags it actually launched with, like any Orca launch, so a later restart keeps them even if the session changes mode in between, the same as for a session Orca started with the bypass. Cold restore resumes from the same recorded recipe and could read the field in a follow-up (#32245).

Linked Issue

Fixes #34690

Visual Proof

N/A: no UI change. The change is in the command a restart runs, and the tests below assert that command.

Testing

  • Rebased on main a29461b (the resume module moved to src/shared/agent-session/lifecycle/). pnpm check:changed --maxWorkers=4 passes on macOS for format, lint, typecheck, ratchets and the affected unit tests, except the tests/e2e/cross-version-wire suites. Those fail the same way without this change: with the v1.4.246 tag fetched, the harness imports src/shared/agent-session-record.ts and similar paths that v1.4.246 moved under src/shared/agent-session/.

  • New tests:

    • The listener records the mode, ignores a subagent's mode and keeps the mode across hooks without the field.
    • Normalization and the sleeping-session schema round-trip the mode and drop malformed values.
    • The restart command keeps a hand-started bypass, adds it to recorded arguments or a recorded command that lost it, places it before a recorded --, and never repeats a recorded one.
    • The provider session sent to agentSession.ensure still passes the strict ProviderSession schema.
  • Without the fix, 11 of the new cases fail.

  • Captured Claude Code 2.1.284's real UserPromptSubmit hook input, blocked with exit code 2 so nothing reached the API. claude --dangerously-skip-permissions reports "permission_mode": "bypassPermissions", and plain claude reports "auto", its default mode on that machine.

  • Not yet run end to end in a packaged build with two real accounts; I will run it in a local build and update this section.

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

AI Disclosure

Written with Claude Code using Claude Opus 5.5; I reviewed the change and the evidence.

Review

Agent review summary:

  • Cross-platform: the bypass check tokenizes with the restart's own startup shell (POSIX, PowerShell or cmd). The added flag goes through the same resume command builder as recorded arguments, so it is quoted per shell; [Bug]: Claude sessions restarted by an account switch lose --dangerously-skip-permissions and come back in auto mode #34690 was reported on Windows.
  • SSH / remote and mixed versions: account-switch restarts only move local panes. The field is optional: older hosts and saved records lack it and keep today's behavior. It never goes into agentSession.ensure, so no host's strict schema sees it (a new test parses the shaped value with that schema), and terminal.create's non-strict resume param drops it.
  • Agent compatibility: Claude only. Other agents' provider sessions never carry the field, and Codex restarts are unchanged.
  • Performance: one string read per Claude hook.
  • Security: the mode can only keep a bypass the running session already has. It is accepted only from authenticated hook payloads and from saved records validated against ^[A-Za-z]{1,32}$.

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

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)

🤖 Generated with Claude Code

@coderabbitai

coderabbitai Bot commented Oct 30, 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: b1b2c62b-7fbe-4823-8546-726561a351bc
Commits

Reviewing files that changed from the base of the PR and between 2858ffe and 828f315.

Files selected for processing: 2
  • src/renderer/src/lib/agent-account-restart-startup.test.ts
  • src/renderer/src/lib/agent-account-restart-startup.ts

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

Walkthrough

Claude permission mode is validated, read from hook data, and retained in provider-session metadata. Recovery matching now compares permission mode. The host ensure payload omits permission mode. When a Claude session recorded with bypassPermissions restarts, startup arguments add the bypass flag only if it is not already present.

Severity of issue fixed: Medium

Merge Risk: Moderate · up to 828f3

A later restrictive mode change can be lost on account-switch restart, causing Claude to resume without the permissions the user selected. Fix this before merging.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 66.67% 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 and concisely describes the main change: preserving Claude's bypass permission mode during account-switch restarts.
Description check Passed The description is detailed and covers the change, rationale, linked issue, testing, compatibility, security, and checklist items. It omits the required Risk section, including an explicit risk level …
Linked Issues check Passed [#34690] Requirement: an account-switch restart must keep the permission mode that the Claude session runs in. The PR meets this requirement, which is the first fix that #34690 proposes. Evidence at t…
Out of Scope Changes check Passed Every changed area supports permission-mode preservation for the Claude account-switch restart in [#34690]. The changed areas are: the hook listener field and reader (pane-provider-session.ts); the li…
Full details: Description check

Explanation

The description is detailed and covers the change, rationale, linked issue, testing, compatibility, security, and checklist items. It omits the required Risk section, including an explicit risk level and rollback plan, and manual packaged end-to-end testing remains pending, but the overall description is mostly complete.

Full details: Linked Issues check

Explanation

[#34690] Requirement: an account-switch restart must keep the permission mode that the Claude session runs in. The PR meets this requirement, which is the first fix that #34690 proposes. Evidence at the reviewed head: (1) src/shared/agent-hook-listener/pane-provider-session.ts stores the lead session's permission_mode on providerSession.permissionMode. It ignores hooks with agent_id, so subagent modes are not used, and it keeps the prior value when a hook omits the field. (2) src/shared/agent-provider-session-live-settings.ts validates the value against ^[A-Za-z]{1,32}$. normalizeAgentProviderSession, the sleeping-session schema, and recoveryRecordMatches keep the field. (3) src/renderer/src/lib/agent-account-restart-startup.ts keepLiveClaudeBypass adds the Claude bypass argument only when providerSession.permissionMode is 'bypassPermissions' and the recorded agentArgs or agentCommand do not already enable bypass. Recorded arguments are kept. A recorded agentCommand is spliced through buildClaudeResumeLaunchCommand, which places the flag before any '--' terminator. Tests cover hook persistence, validation, schema round-trip, the strict ProviderSession shape sent to agentSession.ensure, and restart commands. The Settings-arguments fallback is not required here. #34690 offers it as an alternative, and the PR states why it is excluded. The bug text also names --add-dir. That flag is not restored for unrecorded panes, but the linked issue's central requirement is permission-mode preservation, and the proposed fix covers it. Remaining uncertainty: end-to-end behavior in a packaged build with real accounts is not yet verified by the author, and this review did not run tests.

Full details: Out of Scope Changes check

Explanation

Every changed area supports permission-mode preservation for the Claude account-switch restart in [#34690]. The changed areas are: the hook listener field and reader (pane-provider-session.ts); the live-settings validator and reader (agent-provider-session-live-settings.ts); the provider-session type and normalization (agent-session-resume.ts); the sleeping-session schema and its hydration test; recoveryRecordMatches comparison; the restart recipe (agent-account-restart-startup.ts); and agentProviderSessionForHostEnsure, which omits permissionMode from agentSession.ensure so the strict ProviderSession schema accepts the payload. The ensure change is needed because the field is new. The restart code path touches only Claude when the mode is bypassPermissions. Other agents and Codex keep their existing recipe. The PR does not add unrelated product behavior, and it does not change cold restore. The author identifies cold restore as a follow-up in #32245. No unrelated change was found in the reviewed diff.

Full details: Docstring Coverage

Explanation

Docstring coverage is 66.67% 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 9 functions across 12 files.

Resolution

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

  • 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

…he session

An account-switch restart resumes a Claude pane with its recorded launch
arguments, and a pane with no record resumes as plain `claude --resume`
so a hand-typed claude never gains a bypass. That also dropped a bypass
the session did have, and the restart then recorded empty arguments, so
later restarts dropped it too.

Claude reports its live permission mode on its prompt, tool and stop
hooks. The hook listener now keeps the lead session's `permission_mode`
on the provider session, like effort, and the restart adds Claude's
bypass argument only when the session reports bypassPermissions.

Fixes stablyai#34690

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Nelef
Nelef force-pushed the fix/claude-account-restart-permission branch from 0088194 to fc14385 Compare November 2, 2026 03:30

@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


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: 7307371a-798b-422e-8199-711e3a0b6d96
Commits

Reviewing files that changed from the base of the PR and between 0088194 and fc14385.

Files selected for processing: 7
  • src/renderer/src/lib/agent-account-restart-startup.ts
  • src/shared/agent-hook-listener/pane-provider-session.ts
  • src/shared/agent-provider-session-live-settings.ts
  • src/shared/agent-resume-record-equivalence.ts
  • src/shared/agent-session/lifecycle/agent-session-resume.test.ts
  • src/shared/agent-session/lifecycle/agent-session-resume.ts
  • src/shared/workspace-session-sleeping-agents.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.

) {
return agentArgs
}
return [agentPermissionArgs('claude', 'full-access'), agentArgs].filter(Boolean).join(' ')

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 · Security & Privacy · Heavy lift

Supported by static analysis

Script executed:

rg -n -C 5 -e 'registerAgentLaunchConfig\(' -e 'queuePaneAccountRestarts\(' -e 'resumeProviderSession' src/renderer/src

Repository: stablyai/orca

Length of output: 42820


Script executed:

set -o pipefail
printf '%s\n' '--- restart startup ---'
nl -ba src/renderer/src/lib/agent-account-restart-startup.ts | sed -n '1,190p'
printf '%s\n' '--- recipe registration callers ---'
rg -n -F --glob '*.ts' --glob '*.tsx' -e 'registerLaunchRecipe(' -e 'registerAgentLaunchConfig(' src/renderer/src | sed -n '1,240p'
printf '%s\n' '--- restart queue and executor symbols ---'
rg -n -F --glob '*.ts' --glob '*.tsx' -e 'queuePaneAccountRestarts' -e 'resolveAgentAccountRestartResumeStartup' -e 'agent-account-restart-startup' -e 'consumeTabStartupCommand' src/renderer/src | sed -n '1,260p'

Repository: stablyai/orca

Length of output: 24399


Script executed:

set -o pipefail
printf '%s\n' '--- launch recipe registration call ---'
nl -ba src/renderer/src/hooks/ipc-events/terminal-presentation-ipc-bridge.ts | sed -n '145,205p'
printf '%s\n' '--- terminal pane startup actions ---'
nl -ba src/renderer/src/components/terminal-pane/use-terminal-pane-startup-actions.ts | sed -n '1,120p'
printf '%s\n' '--- pane-created startup handling ---'
nl -ba src/renderer/src/components/terminal-pane/terminal-pane-pane-created.ts | sed -n '130,215p'
printf '%s\n' '--- restart state ---'
nl -ba src/renderer/src/store/terminals/terminal-restart-state.ts | sed -n '1,115p'
printf '%s\n' '--- resume startup plan definitions/callers ---'
rg -n -F --glob '*.ts' -e 'function buildAgentResumeStartupPlan' -e 'export function buildAgentResumeStartupPlan' -e 'buildAgentResumeStartupPlan(' src | sed -n '1,120p'

Repository: stablyai/orca

Length of output: 23929


Script executed:

set -o pipefail
printf '%s\n' '--- account restart executor ---'
nl -ba src/renderer/src/components/terminal-pane/use-terminal-pane-process-exit-actions.ts | sed -n '1,180p'
printf '%s\n' '--- terminal presentation bridge start and startup handoff ---'
nl -ba src/renderer/src/hooks/ipc-events/terminal-presentation-ipc-bridge.ts | sed -n '1,145p'
printf '%s\n' '--- resume startup plan ---'
nl -ba src/shared/tui-agent-resume-startup.ts | sed -n '1,190p'
printf '%s\n' '--- queued startup consumer ---'
rg -n -F --glob '*.ts' -e 'function createQueuedStartupConsumer' -e 'createQueuedStartupConsumer(' src/renderer/src/components/terminal-pane src/renderer/src | sed -n '1,100p'

Repository: stablyai/orca

Length of output: 23064


Script executed:

set -o pipefail
printf '%s\n' '--- remaining account restart handler ---'
nl -ba src/renderer/src/components/terminal-pane/use-terminal-pane-process-exit-actions.ts | sed -n '180,380p'
printf '%s\n' '--- connectPanePty definition and startup forwarding ---'
rg -n -F --glob '*.ts' -e 'export function connectPanePty' -e 'function connectPanePty' -e 'startup.launchConfig' -e 'startup?.launchConfig' -e 'onCreateTerminal' src/renderer/src/components/terminal-pane/pty-connection src/renderer/src | sed -n '1,220p'

Repository: stablyai/orca

Length of output: 9652


Script executed:

set -o pipefail
printf '%s\n' '--- connect pane PTY ---'
nl -ba src/renderer/src/components/terminal-pane/pty-connection/connect-pane-pty.ts | sed -n '1,180p'
printf '%s\n' '--- process-exit startup ---'
nl -ba src/renderer/src/components/terminal-pane/pty-connection/process-exit-startup.ts | sed -n '1,120p'
printf '%s\n' '--- PTY spawn request startup fields ---'
rg -n -F --glob '*.ts' -e 'startupCommandDelivery' -e 'launchConfig: startup.launchConfig' -e 'resumeProviderSession: startup.resumeProviderSession' src/renderer/src/components/terminal-pane/pty-connection src/renderer/src/store/terminals | sed -n '1,180p'

Repository: stablyai/orca

Length of output: 13667


Do not persist the injected bypass as a launch preference.

The account-restart path adds the bypass to agentArgs, copies those arguments into startupPlan.launchConfig, and registers that configuration for the pane. A later restart in plan or auto mode can reuse the persisted bypass because existing arguments are kept unchanged.

Keep the injected bypass separate from the recorded launch preference. Apply it only to the current restart command.

…mmand

A recorded `agentCommand` replaces the arguments on resume, so adding
the bypass to `agentArgs` alone did nothing for panes that recorded one,
including the `claude` with empty arguments a lossy restart records.
The restart now adds the bypass to the recorded command too.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@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: 1


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: 6e1319e2-a0f6-443d-9190-908d63456220
Commits

Reviewing files that changed from the base of the PR and between fc14385 and 2858ffe.

Files selected for processing: 2
  • src/renderer/src/lib/agent-account-restart-startup.test.ts
  • src/renderer/src/lib/agent-account-restart-startup.ts

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

Appending the bypass to a recorded `claude --` made it a positional
argument. Splice it in with the same terminator-aware builder the resume
selectors use.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Jinwoo-H

Jinwoo-H commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

Thanks for this. Capturing Claude's reported permission mode is part of #38998, where it decides whether an unrecorded Claude session resumes with bypass across every restart path, not only account switch. You're credited in the PR description.

Jinwoo-H added a commit that referenced this pull request Nov 6, 2026
Claude names its live permission mode on prompt, tool and Stop hooks. Keep the
root agent's latest value on the provider session, next to effort, so a resume
without a recorded launch can tell whether the session ran in bypass.

Ports the capture from #36359 by Nelef.
Jinwoo-H added a commit that referenced this pull request Nov 6, 2026
Claude names its live permission mode on prompt, tool and Stop hooks. Keep the
root agent's latest value on the provider session, next to effort, so a resume
without a recorded launch can tell whether the session ran in bypass.

Ports the capture from #36359 by Nelef.
@Nelef

Nelef commented Nov 6, 2026

Copy link
Copy Markdown
Author

Thanks @Jinwoo-H, and thanks for the credit. Covering every restart path in #38998 is a better fix than the account-switch-only change here. I'll close this PR once #38998 is merged.

If it helps, I can try #38998 on my setup before it lands (macOS, two managed Claude accounts, Claude sessions started by hand with --dangerously-skip-permissions) and report back.

Jinwoo-H added a commit that referenced this pull request Nov 10, 2026
…8998)

* feat(agent-session): keep the permission mode a Claude session reports

Claude names its live permission mode on prompt, tool and Stop hooks. Keep the
root agent's latest value on the provider session, next to effort, so a resume
without a recorded launch can tell whether the session ran in bypass.

Ports the capture from #36359 by Nelef.

* fix(agent-launch): resume an unrecorded launch bare unless it reported bypass

Without a recorded launch, every restart path now resumes with no settings
Arguments, env or permission default; the configured Command still runs. A
session whose root agent last reported bypassPermissions keeps its bypass flag,
so a hand-typed claude --dangerously-skip-permissions keeps it while a bare
hand-typed claude never gains one (#29898).

Account-switch restart used the shared rule only for Claude; it now uses it
for every agent. Thanks to JustinCMR (#37304) for finding the account-switch
and cold-restore gaps.

* fix(terminal): keep the launch recipe of a window-started agent in main

A window spawn hands main its recipe, but main kept only the token and agent,
so restarts that main runs (workspace sleep capture, closed-worker reopen)
found no recipe and resumed bare. Keep it with the launch authority, the same
gate that admits the token.

* fix(orchestration): reopen a closed worker with the recipe it launched with

A closed worker's pane record goes away with its tab, so orchestration send
reopened it bare (#37693). The worker row now keeps the recipe Orca launched
the agent with, keeps it when a later capture of the same launch arrives
without one (main loses it on a daemon reattach), and a reopen prefers it over
a pane record that may hold another launch of the conversation.

Adapted from #37757 by Pr1p, without a new column.

* fix(terminal): keep a slept pane's earlier recipe only for the same launch

A host sleep capture without a recipe reused the pane's earlier record for the
same conversation. That is right after a daemon reattach, when Orca's launch
still runs but main lost its recipe, and wrong for an agent typed into the
shell that resumed the conversation: it never ran that launch.

* fix(agent-session): restore a paired pane with the recipe its host recorded

A client restoring a pane on a paired host sends only its recorded Arguments,
and the host filled the rest from its current settings. A saved restore now
replays the host's own record for that pane, or, with none at all, resumes
bare and keeps a bypass only when this host's hooks saw it reported. History
and other user-chosen resumes keep current settings.

* fix(terminal): replay a saved note only for the launch main still holds

A note belongs to the agent in a pane only while main holds that launch's
token: main admits it at spawn and retires it when the launch command
finishes, and a daemon reattach restores neither. Worker, host sleep and
hook/quit captures now take a note only from that attested launch, and no
longer copy an earlier record's note by agent or conversation match, which a
typed resume in the same shell also satisfies. With no attested launch the
unrecorded rule applies.

Replaces the inferred orcaLaunched / recipeLostPaneKeys flags and drops the
mock-only reopen and fixture-echo worker tests.

* fix(agent-status): take a pane's note from the launch main attests

The window carried a pane's saved note into each new record by agent and
conversation match, so an agent typed into the shell that resumed the same
conversation inherited an earlier launch's bypass. Main now sends the note of
the launch it still holds with each status, and the window records only that,
its own launch registration, or, for a restored replay of the very status a
record was written from, that record's note. /clear and compact keep the note
because main still holds the same launch.

* fix(orchestration): reopen a worker with its own recipe or none

A worker without its own note took the note of whichever pane record held the
same conversation. Its reopen now always passes a complete recipe: its own
note, or the unrecorded rule. The unrecorded bypass is also scoped to Claude,
whose hooks are the ones that report a root agent's permission mode.

* fix(agent-session): restore a paired pane from its source pane, never current settings

A saved restore on a paired host looked up the destination pane, which a Wake
opens as a new tab, and fell back to the host's current settings whenever the
client sent its partial Arguments. The client now names the source pane (to
hosts advertising agent-session.restore-source-pane.v1), and the host replays
its note for that pane or, with none, resumes bare keeping only a bypass its
own hooks saw there. Older hosts keep today's behavior.

* fix(terminal): re-arm a launch across a main restart while its agent still runs

The daemon outlives main, so it now keeps main's admitted launch (token and
note) and drops it when that launch's command finishes. On reattach main
re-arms the launch only when the same agent still runs in the foreground:
nothing can be typed into a daemon PTY while main is down, so a running agent
there is the one the unretired note launched. A shell foreground clears the
daemon's note; an unknown read, including every Windows read, declines.

Older daemons keep no note, so restore declines there as before.

* fix(terminal): the daemon retires a launch note when its command finishes

A launch can finish while main is down, so main's own retirement never sees it and a
hand-typed agent in that pane would later pass the reattach foreground check.

* fix(agent-status): a fresh Claude start never inherits the last process's permission mode

A hand-typed resume of the same conversation may run without the bypass the previous
process had, so only /clear and compact carry the mode forward.

* fix(agent-session): name a restore's source pane in the host's own keys

A mirrored pane's key carries the desktop tab prefix, so the host's exact lookup missed
its saved note.

* fix(terminal): retire a daemon launch note by its token from the one retirement owner

A delayed reattach result or a late retire could clear a newer launch's note. Retires now
name the token they retire, the reattach checks its PTY before clearing, and re-arming the
same launch keeps the daemon's completion scanner.

* fix(agent-status): only the launch owner's statement changes a pane's note

Main now states the attested note, or null for none, on every hook status. An OSC or
display update makes no statement, so after a completed turn it no longer erases an Orca
launch's note; a typed resume still drops it through main's null.

* fix(terminal): an attach leaves alone a launch main already holds

The renderer attaches a pane the CLI just launched before its agent starts, so the
attach saw the shell and retired the new launch's daemon note.

* fix(agent-status): a paired client keeps a pane's note only on its host owner's word

The host's session-tabs frame now says whether the Orca launch it admitted still runs on
the published incarnation, and the client applies that fact whichever writer wins the
status. With an owner's word the conversation no longer decides; an older host that says
nothing keeps the same-conversation rule.

* refactor(agent-status): one decision picks a pane's note for every reader

The live entry, quit capture, provider-session updates, account restart and cold
restore now ask the same owner-aware decision. An owner's none is final and, when it
turns, ends the pane's registry entry and saved note, locally and from a paired host's
frame. Cold restore and account restart take that answer for a live invocation and read
the saved record only when none is live. Inlines single-use wrappers.

* refactor(agent-status): a paired retirement test reaches the cold-restore command; trim comments

Replaces the projection and continuity tests with one transition: host frame retires the
launch, the next OSC keeps no note, and the cold-restore command has no old bypass.

* fix(agent-status): an owner's none retires the pane's matched launch registry entry

* chore: satisfy changed-code gates (type guards, SAFETY notes, fixed test clock)

* fix(agent-launch): a teams launch keeps its note; a legacy leaf id restores without throwing

* refactor(daemon): keep the session launch note on the process base so session.ts stays in budget

* fix(agent-launch): a restarted terminal main can't vouch for keeps main's earlier launch rule

* fix(agent-launch): read the pane's current terminal; a finished launch settles an undecided pane

* fix(agent-launch): undecided and held launches end with their process

A finished command, a fresh launch or a replacement process settles an undecided pane;
a newer attach or finish supersedes a foreground read still in flight; a legacy relay
reattach without an incarnation stays undecided; a held launch applies only to the
process it was recorded for.

* refactor(terminal): watch and arm a created terminal's launch in one call

Keeps terminal-create.ts within the 300-line budget after main's growth.

* refactor(terminal): keep main's launch evidence in one immutable record

Replace the undecided flag, the reattach check map and the re-arm's writes
to main's orchestration launch fields with one launchEvidence object
(unknown, gone for an incarnation, or held with its recipe), owned by
launch-evidence.ts.

- A fresh admitted launch is held; any other fresh process is gone.
- A finished command or confirmed exit is gone, sticky for its process:
  no reattach, legacy or noted, can revive it.
- A replacement retires its predecessor's evidence without deciding the
  newcomer, which may still prove its own launch through a reattach.
- A reattach note is held only after a foreground read sees its agent;
  the evidence object fences that read.
- A gone launch clears its recipe and blocks both refill sites; a
  deliberate sleep snapshot keeps its recipe past the launch it captured.
- launchToken, launchIncarnationId and launchAgent writes match main.

* fix(terminal): keep launch evidence through a first incarnation and sleep snapshots

- Learning a process's first incarnation binds its held or gone evidence
  to it, so a later attach can neither revive a finished launch nor drop
  a running one; a known X->Y replacement is fenced as before and now also
  clears the predecessor's recipe.
- A status from no Orca launch leaves a sleep snapshot of its session for
  the wake and never takes that snapshot's recipe into a live or quit
  record.

* fix(terminal): record a runtime split's fresh shell as running no launch

* chore: rerun CI on main with the typecheck fix
@nwparker

Copy link
Copy Markdown
Contributor

Thanks for this! The change already landed on main in 533a31b, so I'm closing this PR. We appreciate the contribution.

@nwparker nwparker closed this Nov 16, 2026
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.

[Bug]: Claude sessions restarted by an account switch lose --dangerously-skip-permissions and come back in auto mode

3 participants