Repository navigation
Conversation
📝 WalkthroughWalkthroughThe PTY spawn path now validates launch-token authority and passes valid metadata to PTY registration. PTY registration stores the authority only when the PTY, pane, incarnation, token, and agent identity match. The compatibility verifier supports current runtime launch sufficiency and can return frozen caller authority for matching current panes. Legacy takeover uses this option. Tests cover valid and invalid launch proofs, SSH attachment validation, and current-runtime takeover. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/main/runtime/orca-runtime.ts (1)
12021-12033: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winBypass branch is correctly scoped, but consider documenting the invariant locally and removing duplication.
The new branch only returns frozen authority when
terminalProvenance === 'current_runtime'(which requires the caller'slaunchTokento hash to the live PTY's actuallaunchToken) andclaimedPaneKey === terminal.paneKey(the pane key resolved from the live PTY, not from caller input). Host-scope validation, including the SSH attachment/incarnation check, already runs unconditionally before this branch. This matches the PR's stated invariant that the recovery path requires an exact match on live PTY, pane, host scope, and launch-token hash, and it correctly excludes restored callers, since a restored terminal never reachesterminalProvenance === 'current_runtime'.Two smaller points:
- This function has no local comment explaining why skipping
attestAgentHookCompatibilityAuthorityFnis safe here. The rationale currently lives only in the caller (orchestration-legacy-compatibility.ts). Since this is a security-sensitive authorization function, a short comment at the definition site would help future readers auditing it in isolation.- The returned object (
hostScope,paneKey,terminalHandle,processIncarnation,launchTokenHash) duplicates the construction in the finalObject.freeze(...)return a few lines below. Extracting a small helper would prevent the two authority-construction sites from silently diverging if a future security-relevant field is added to one but not the other.♻️ Proposed refactor to share authority construction and document the invariant
+ // Why: a fresh, non-restored launch already proves its live PTY, host + // scope, and launch secret via the checks above, so it can skip hook + // attestation only when the caller's claimed pane also matches exactly. if ( options?.currentRuntimeLaunchSufficient && terminalProvenance === 'current_runtime' && claimedPaneKey === terminal.paneKey ) { - return Object.freeze({ - hostScope: Object.freeze({ ...terminal.hostScope }), - paneKey: claimedPaneKey, - terminalHandle, - processIncarnation: terminal.processIncarnation, - launchTokenHash - }) + return this.freezeOrchestrationCompatibilityCallerAuthority( + terminal, + claimedPaneKey, + terminalHandle, + launchTokenHash + ) } const attestation = this.attestAgentHookCompatibilityAuthorityFn?.({ paneKey: claimedPaneKey, launchTokenHash, connectionId: terminal.hostScope.kind === 'ssh' ? terminal.hostScope.targetId : null, terminalProvenance }) if (!attestation || attestation.paneKey !== terminal.paneKey) { return null } - return Object.freeze({ - hostScope: Object.freeze({ ...terminal.hostScope }), - paneKey: attestation.paneKey, - terminalHandle, - processIncarnation: terminal.processIncarnation, - launchTokenHash - }) + return this.freezeOrchestrationCompatibilityCallerAuthority( + terminal, + attestation.paneKey, + terminalHandle, + launchTokenHash + ) + } + + private freezeOrchestrationCompatibilityCallerAuthority( + terminal: OrchestrationCompatibilityTerminalAuthority, + paneKey: string, + terminalHandle: string, + launchTokenHash: string + ): OrchestrationCompatibilityCallerAuthority { + return Object.freeze({ + hostScope: Object.freeze({ ...terminal.hostScope }), + paneKey, + terminalHandle, + processIncarnation: terminal.processIncarnation, + launchTokenHash + }) }
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 79f47813-5ef9-4842-aaf8-2ca60a03754f
📒 Files selected for processing (3)
src/main/runtime/orca-runtime.tssrc/main/runtime/rpc/orchestration-legacy-compatibility.tssrc/main/runtime/rpc/orchestration-legacy-takeover-current-authority.test.ts
Jinwoo-H
left a comment
There was a problem hiding this comment.
Thanks—verified the takeover authorization direction and reproduced the migration failure. During review I found the reported renderer-backed terminal create --command claude path still dropped fresh launch authority before main could verify it, so I added a bounded PTY-registration handoff and regression coverage.
- Exact pre-hook legacy takeover now succeeds.
- Forged token, pane, and SSH attachment evidence remain rejected.
- New Runs and ordinary compatibility mutations remain hook-attested.
- 505 focused tests and typecheck pass on the pushable head; latest-main validation also passed full lint, 506 focused tests, and Electron E2E.
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/main/ipc/pty.test.ts (1)
7997-8004: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueAdd an at-limit launch-token boundary case.
AGENT_LAUNCH_TOKEN_MAX_LENGTH = 128accepts tokens up to 128 characters and rejects 129, but this test only covers "matching proof" and "oversized proof". If the cap changes or drifts, the boundary can become untested. Add a 128-characterexpectedTokencase to keep acceptance across the boundary pinned.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: cac44a9c-773a-43df-97e2-a47a663c8766
📒 Files selected for processing (3)
src/main/ipc/pty.test.tssrc/main/ipc/pty.tssrc/main/runtime/orca-runtime.ts
…lyai#12896) * fix(orchestration): allow fresh agents to take over legacy runs * test(orchestration): cover forged takeover evidence * fix(orchestration): retain renderer launch authority --------- Co-authored-by: Jinwoo-H <[email protected]>
Summary
Fixes #12804.
Explicit
orchestration run-use --takeover-legacycan now bind an adopted Run from a freshly launched current agent before that agent emits its first hook observation.The recovery path accepts the runtime's existing current-launch authority only when the caller exactly matches the live PTY, process incarnation, terminal handle, stable pane, host scope, and launch-token hash. Restored callers and ordinary legacy compatibility mutations continue to require agent-hook attestation.
The root cause was that explicit takeover, a current-contract recovery action, reused the stricter legacy compatibility verifier. That made
callerAuthoritynull until a matching hook observation existed, so the takeover guard always returnedlegacy_read_onlyeven though the runtime already held exact current-launch proof.An integrated dispatcher regression test reproduces the pre-fix failure without mocking the verifier, proves the fresh local-agent takeover, and covers forged token, forged pane, and caller-chosen SSH attachment rejection.
Screenshots
No visual change.
Testing
pnpm lintpnpm typecheckpnpm testpnpm buildAdditional validation:
v1.4.175: 4 tests passed.read ECONNRESET; a direct diagnostic reproduced the same network failure outside the suite.AI Review Report
The AI review checked the authority boundary from CLI evidence through compatibility preflight, the takeover guard, and the Run binding transaction.
current_runtimelaunch provenance with an exact pane match. Default legacy verification remains unchanged.No additional code changes were required after the final review.
Security Audit
This PR changes an authorization decision, so the review specifically checked spoofing and authority downgrade risks.
No security follow-up is needed.
Notes
This PR addresses the primary stuck-takeover recovery bug. The issue's secondary request for a general Run deletion/archive surface is intentionally left out to keep this authorization fix focused.
X handle: @Avichal2205