Repository navigation
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📥 CommitsReviewing files that changed from the base of the PR and between d01308b3a73ca5d557d25d49cd10abb7a70a970c and b13235211c8df37c612215a46c76ba8d0c70c189. 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughAdds runtime close intent schemas, an in-memory authorization policy, decision-based terminal and session-tab teardown, attachment and creation tracking, and persisted close attribution spans. RPC dispatch now forwards device identity and the shared policy to handlers. Tests cover allowed and blocked closes, malformed or mismatched intents, replay detection, rollback ownership, rate limiting, lifecycle sources, tracing outcomes, token redaction, and local identity fallbacks. Daemon session-killed logs now include the requesting control client identifier. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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 |
774cd39 to
811c765
Compare
There was a problem hiding this comment.
Actionable comments posted: 3
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 93b0880d-936a-4472-8bb6-1b8f6e3a019b
📥 Commits
Reviewing files that changed from the base of the PR and between 774cd39fb608ae5fbce71f4c4951be8b66721d5b and 811c765b4b7c1caa463435997125aa23184f2126.
📒 Files selected for processing (13)
src/main/daemon/daemon-server.test.tssrc/main/daemon/daemon-server.tssrc/main/runtime/rpc/core.tssrc/main/runtime/rpc/dispatcher.tssrc/main/runtime/rpc/methods/session-tabs-schemas.tssrc/main/runtime/rpc/methods/session-tabs.tssrc/main/runtime/rpc/methods/terminal.tssrc/main/runtime/rpc/runtime-close-attribution.tssrc/main/runtime/rpc/runtime-close-intent-schema.tssrc/main/runtime/rpc/runtime-close-policy.tssrc/main/runtime/rpc/runtime-terminal-close-policy.test.tssrc/main/runtime/rpc/session-close-attribution.test.tssrc/main/runtime/runtime-rpc.ts
🚧 Files skipped from review as they are similar to previous changes (3)
- src/main/daemon/daemon-server.test.ts
- src/main/runtime/runtime-rpc.ts
- src/main/runtime/rpc/core.ts
|
Follow-up
Verification after the follow-up: 10 related test files / 161 tests passed; full node/CLI/web typecheck passed; exact changed-file oxlint passed; max-lines ratchet passed; The remaining CodeRabbit docstring-coverage item is a non-blocking style warning rather than a functional finding. I kept the repository convention of a concise |
b132352 to
5a32f0e
Compare
|
@Jinwoo-H Rebased onto current Conflict resolution notes:
|
|
Associating this PR with related issue(s): #8871 |
|
Related to #9952 (sessions vanishing over remote Orca link). |
|
Associating this PR with related issue(s): #8871 |
|
Rebased onto current Integration notes (vs pre-rebase shape):
ahead=4 behind=0. |
5a32f0e to
f41134e
Compare
Coordination note (close / kill cluster)Related open PRs share the destructive-close surface. Do not add a third confirm modal here.
This PR should remain host-side policy (soft-deny + rate limit + durable allow/block audit), not a second Resource Manager confirm UX. Restacked onto latest main when clean; residual unique vs main is the RuntimeClosePolicy / soft-deny layer (not on main’s #9804 liveness path). |
f41134e to
c23c384
Compare
… split Keep main's close/closeLifecycle method split and missing-intent refuse gate while applying stablyai#8888's RuntimeClosePolicy + attribution to user closes and terminal close/closeTab. Update tests for reason:user wiring, runtime soft-deny, and dedupeTerminalCreate create stubs.
c23c384 to
f55c031
Compare
Re-restack noteRebased onto latest
Coordination unchanged: policy layer only — no third confirm modal vs #10013/#8467. Ready for upstream review; community author cannot merge. |
f55c031 to
a6e4cd1
Compare
a6e4cd1 to
87a1a84
Compare
… split Keep main's close/closeLifecycle method split and missing-intent refuse gate while applying stablyai#8888's RuntimeClosePolicy + attribution to user closes and terminal close/closeTab. Update tests for reason:user wiring, runtime soft-deny, and dedupeTerminalCreate create stubs.
… split Keep main's close/closeLifecycle method split and missing-intent refuse gate while applying stablyai#8888's RuntimeClosePolicy + attribution to user closes and terminal close/closeTab. Update tests for reason:user wiring, runtime soft-deny, and dedupeTerminalCreate create stubs.
87a1a84 to
5ddee4f
Compare
Greptile SummaryThis PR adds host-side defense-in-depth against remote destructive closes on
Confidence Score: 5/5The close-intent policy is sound and all destructive code paths are covered. The change is safe to merge. The policy logic is correct across all client kinds: runtime clients require validated intent, mobile and in-process callers retain their established contracts, and rollback tokens are correctly scoped to the creating connection and consumed on first use. All call sites that invoke retireProvider now pass an owner; the type-level optional is defensive API flexibility rather than a live gap. The widening of RuntimeMobileSessionTabCloseResult.closed from literal true to boolean is handled consistently on both the host and all client-side resync paths. The two observations flagged are a documentation nuance and a minor requestId retention asymmetry — neither affects correctness or security. Files Needing Attention: No files require special attention before merging. The schema file would benefit from inline comments clarifying which fields are required per target kind, but this is cosmetic.
|
| Filename | Overview |
|---|---|
| src/main/runtime/rpc/runtime-close-policy.ts | New core policy class — deduplication, rate limiting, rollback ownership, and attachment evidence all work correctly; minor inconsistency with requestId not being released on userInitiated=false mismatch unlike the rate-limit path. |
| src/main/runtime/rpc/runtime-close-intent-schema.ts | New Zod schema for close intent; hostTabId and ptyOrHandle are marked optional but policy silently rejects their absence as a target mismatch rather than a schema validation error. |
| src/main/runtime/rpc/methods/session-tab-close-methods.ts | Rewrites session.tabs.close to route through RuntimeClosePolicy for runtime clients; in-process refusal and legacy-mobile paths preserved correctly; attribution spans are consistent. |
| src/main/runtime/rpc/methods/terminal.ts | Adds closeIntent gating to terminal.close and terminal.closeTab; terminal.create and agent-session creates now record rollback ownership; multiplex/subscribe attach-target recording is gated behind the live-stream check. |
| src/main/runtime/rpc/runtime-close-attribution.ts | New attribution helper wrapping withSpan; correctly emits deviceId (not clientId/bearer token), target kind, decision, and intent source for every close attempt. |
| src/renderer/src/runtime/web-runtime-session.ts | Mints user-tab-close and user-pane-close intents for all runtime close calls; adds owningWorktreeId lookup guard and resync-on-denial flow for both session-tab and terminal closes. |
| src/renderer/src/lib/retire-unowned-background-terminal.ts | Adds mintClientCreatedRollbackIntent and passes it to all retireProvider callers; owner is now required at all call sites; soft-denial is surfaced as a warning. |
| src/shared/runtime-types.ts | Widens RuntimeMobileSessionTabCloseResult.closed from literal true to boolean and adds blockedReason; adds blockedReason to RuntimeTerminalClose for soft-denial signaling. |
Sequence Diagram
sequenceDiagram
participant C as Runtime Client
participant D as RpcDispatcher
participant P as RuntimeClosePolicy
participant R as OrcaRuntimeService
C->>D: session.tabs.close / terminal.close / terminal.closeTab
note over D: Attach runtimeClosePolicy from dispatcher
D->>P: evaluate(ctx, target, closeIntent?)
alt "clientKind !== runtime"
P-->>D: "allowed=true, reason=legacy-client"
else no closeIntent
P-->>D: "allowed=false, reason=close_intent_required"
else target mismatch
P-->>D: "allowed=false, reason=close_intent_mismatch"
else duplicate requestId
P-->>D: "allowed=false, reason=close_intent_duplicate"
else "user source + userInitiated=true"
P->>P: consumeRateSlot(deviceActor)
alt rate limit hit
P-->>D: "allowed=false, reason=close_rate_limited"
else
P-->>D: "allowed=true, reason=explicit-user"
end
else client-created-rollback + terminal kind
P->>P: check createdTerminalHandles[connectionActor]
alt owned + within TTL
P-->>D: "allowed=true, reason=owned-rollback"
else
P-->>D: "allowed=false, reason=close_rollback_not_owned"
end
else lifecycle or mirror source
P-->>D: "allowed=false, reason=close_source_not_allowed"
end
D->>D: recordRuntimeCloseAttribution(span)
alt decision.allowed
D->>R: closeMobileSessionTab / closeTerminal
R-->>D: "ptyKilled=true"
else
D-->>C: "ptyKilled=false, blockedReason"
end
C-->>C: "if ptyKilled !== true, warn and resync snapshot"
Reviews (2): Last reviewed commit: "fix(runtime): tighten close policy state" | Re-trigger Greptile
Closing as already fixed on
|
|
Thanks for the detailed verification. The two pieces you called out landed as #12238 (merged 2026-08-04,
Nothing else from this branch is outstanding — the negotiated-capability close policy on |
Summary
Refs #8871. This is the host-side defense-in-depth companion to #8872.
session.tabs.close,terminal.close, andterminal.closeTabwhen a paired desktop/runtime client omits explicit close intent; the RPC succeeds but no host tab or PTY is destroyedclient-created-rollbackonly for a terminal created by the same connection within a short ownership windowsession-killedlogsScreenshots
No visual change.
Testing
pnpm lint— exact changed-fileoxlintand repository pre-commit lint/React Doctor checks pass; max-lines ratchet passes; remaining full verify chain deferred to CIpnpm typecheck— node, CLI, and web tsconfigs passpnpm test— focused RPC/runtime/daemon/CLI suites pass (7 files / 112 tests); final policy, attribution, and daemon rerun passes (3 files / 42 tests)pnpm build— not run locally; deferred to CIThe failing-first tests proved that a legacy runtime client still invoked all three destructive methods before this patch. Coverage now includes explicit user closes, target mismatch, schema rejection, duplicate ids across reconnects, same-connection rollback ownership, forged rollback, per-device rate limiting, recent-attach evidence, lifecycle-only intent, mobile compatibility, attribution success/failure, token exclusion, and daemon requester logging.
AI Review Report
The review traced the destructive call chain from authenticated WebSocket context through dispatcher schemas, runtime tab/terminal handlers, PTY controller shutdown, and daemon logging. It rejected the initial attribution-only design because it diagnosed the next incident but did not stop it. It also rejected using client wall-clock age as an authorization gate: macOS, Linux, Windows, WSL, and SSH hosts can have clock skew, so replay protection uses device-scoped request-id dedupe instead.
The final policy is default-deny only for paired desktop/runtime clients. Mobile and in-process callers retain the established contract. The client-created rollback exception is connection-scoped and consumed once. Bulk closes have a high enough rate ceiling for normal UI use, while repeated destructive RPCs remain bounded.
Cross-platform review found no shortcut, label, shell, path-separator, Git, or platform-specific API changes. The policy and intent are transport-neutral JSON and apply equally to macOS, Linux, Windows, WSL, and SSH-backed runtime hosts.
Security Audit
Close intent is not an authentication credential and does not elevate a client; the existing paired-device scope remains the trust boundary. The intent only distinguishes an explicit destructive action from lifecycle/reconciliation noise. Untrusted fields are bounded and parsed with Zod, targets must match the RPC, duplicate ids are suppressed per device, and rollback ownership is tied to the creating connection.
RpcContext.clientIdcontains the E2EE bearer token and is never read by the attribution path. Only the non-sensitivedeviceIdis persisted, with a regression test searching the complete serialized trace. The daemon-side client id names a local control connection, not a paired-device credential. No command execution, filesystem path, dependency, secret, or auth mechanism changed.Notes
Older runtime clients will receive a successful no-op for destructive close requests until upgraded to a client that sends intent (#8872). This intentionally favors preserving host processes over honoring ambiguous legacy close requests. Mobile and local CLI behavior is unchanged.
ELI5
Remote clients could close host tabs or terminals without clear user intent, which is dangerous. Destructive closes now require validated intent, rate limits, and source checks on the host.