fix(terminal): refuse resume records whose reported cwd belongs to another tabbed worktree #37848
All Vouch review confidence checks passed
Residual risk 0.30 = Change Risk (0.57) × (1 − Review Confidence (0.47)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.57 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.344
Ai Authored
ai_authored
0.050
Real PR Conversation Timeline
1 comments
"Review active on #37848"
general
weight: 0.35
ggbdpq
Summary
A tmux server started from an Orca pane freezes that pane's environment, including the scrub-safe pane alias
ORCA_AGENT_PANE(#22468). Any session a user later creates detached inside that server inherits the alias, and since #33286 the managed Claude hook refills an emptyORCA_PANE_KEYfrom it — so an agent of a different worktree posts its hooks under the creating pane's key. The claimed pane key and worktree id are inherited claims; the conversation folder the agent itself reports in its hook payload is not. A resume record written from such a hook made the next Orca restart typecd <other worktree> && claude --resume <other session>into the wrong tab, and the tab's own conversation was not restored anywhere (#37799).This guards the resume-record boundary on the execution host with one shared predicate: a hook status or capture whose provider-session
cwdlies inside another worktree that has its own tabs in the same window session never writes, replaces, clears, or restores that pane's record.cwdInsideOtherTabbedWorktree(new): boundary-aware, spelling-normalized comparison of the hook-reported folder against the session's tabbed worktree paths.hookStatusResumeCommandandquitResumeRecords: a foreign status leaves the pane's record exactly as it is — it can neither replace it with the foreign conversation nor clear it.applyWorktreeSleepResumeRecords: a foreign sleep capture is skipped, so worktree sleep does not persist the poison.resolvePaneOwnedResumeStartup: reopen refuses to auto-resume a stored record or a hook-store read naming another tabbed worktree; a stored record stays kept and the pane reopens as a plain shell, and a hook-store read vetoes like its other checks.A
cwdoutside every tabbed worktree keeps today's behavior (#16960): an agent started by hand in another folder from the same tab still auto-resumes there. A record whose conversation belongs to another tabbed worktree stays kept, so a later hook from the pane's own conversation still refreshes it, and nothing is deleted.Fixes #37799
Verification
| Check | Result |
| --- | --- |
|
pnpm testtargeted:hook-status-resume-records.test.ts,host-sleep-resume-record.test.ts,hook-status-resume-record.test.ts,hook-status-resume-sleep-ordering.test.ts,renderer-shutdown-checkpoint-sleep-records.test.ts,server-hook-session-binding.test.ts,agent-session-resume-claims.test.ts,pane-sleeping-record.test.ts,sleep-record-pane-claim.test.ts,layout-command-pane-starts-layout-owner.test.ts| 10 files, 93 tests pass (EXIT 0) || Ablation: new tests against parent
0a1340bf40c(pre-fix) | 6 red, each naming the guarded behavior: foreign sleep record written ({type:'sleep'}), foreign clear applied ({type:'wake'}), quit capture adopts foreign session, slept capture applies foreign record, reopen resumes a stored foreign-worktree record (--resume <foreign session>typed) ||
pnpm run typecheck:node| EXIT 0 ||
pnpm exec oxfmt --check <changed files>| clean ||
pnpm exec oxlint <changed files>| 0 warnings, 0 errors (pre-commit lint-staged also ran oxlint, ast-grep, oxfmt) ||
node config/scripts/check-max-lines-ratchet.mjs| OK || tmux mechanism reproduction (tmux 3.8, macOS, isolated
-Lsocket) | Reproduced the issue's mechanism chain: (1) a server started from a shell carrying Orca identity env captures it in the server global environment; (2) a session created detached from a shell with different identity inherits the server's captured identity, not the creating shell's; (3) with the canonicalORCA_PANE_KEYabsent (reporter'stmux.confunset, or Claude'sCLAUDE_CODE_SUBPROCESS_ENV_SCRUB), the #33286 prologue: "${ORCA_PANE_KEY:=${ORCA_AGENT_PANE:-}}"refills the creating pane's key, so the foreign agent's hook posts under it |Not run: full
pnpm testsuite (out of scope for this change; the touched area's suites above are green), Windows/WSL-specific resume paths (the predicate fails open when a WSL UNC worktree id and a Linux cwd spelling disagree, matching current behavior), and the renderer-authored record paths under the legacy renderer-layout-owner flag (main-owned workspace-sleep records override renderer saves perwindowSaveKeepingMainSleepRecords).AI use
Implemented by GLM-5.3-Flash (ZCode) from the issue report, the local tmux reproduction, and a reading of the current hook-admission pipeline (#31780, #33286, #36825). The reporter's evidence pinned the mechanism; the fix implements their suggestion 2 at the record boundary and the "do not run it in this tab" half of suggestion 1 for main-owned restores.
Checklist
rgover everysleepingAgentSessionsByPaneKeywriter in main and renderer): renderer hibernation/pane-owned captures build records from a pane's own launch, not hook identity, and main-owned records override renderer saves, so they are intentionally untouched.cwdkeeps current behavior; unreadable or differently-spelled paths (WSL/SSH) fail open rather than dropping a legitimate record.