← Back to Pull requests

fix(terminal): refuse resume records whose reported cwd belongs to another tabbed worktree #37848

Open
unknown opened this pull request with 650 lines diff across 8 files
View on GitHub
unknown unknown commented on Nov 03, 2026 16:04 UTC
Author

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 empty ORCA_PANE_KEY from 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 type cd <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 cwd lies 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.

  • hookStatusResumeCommand and quitResumeRecords: 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 cwd outside 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 test targeted: 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 -L socket) | 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 canonical ORCA_PANE_KEY absent (reporter's tmux.conf unset, or Claude's CLAUDE_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 test suite (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 per windowSaveKeepingMainSleepRecords).

    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

  • The fix covers exactly the reported case: a hook whose conversation folder belongs to another tabbed worktree can no longer write, replace, clear, or restore a pane's resume record.

  • Sibling uses of the same judgment were checked (rg over every sleepingAgentSessionsByPaneKey writer 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.

  • A test that fails without the fix pins each guarded funnel; ablation baseline is the branch parent.

  • Failure semantics: missing/empty cwd keeps current behavior; unreadable or differently-spelled paths (WSL/SSH) fail open rather than dropping a legitimate record.
  • Diff: 650 lines (+487 / -163) across 8 files Reviewer: ggbdpq Review duration: 39139m
    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
    0.57
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 57% (MEDIUM) · Higher = larger blast radius
    57%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 46.7% · Lower = rushed or shallow review
    46.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 30.4% · Safe to merge
    30.4%
    Repository