Skip to content

fix(computer): close helper session review gaps - #11428

Merged
nwparker merged 2 commits into
mainfrom
nwparker/computer-helper-session-review-fixes
Jul 29, 2026
Merged

nwparker merged 2 commits into
mainfrom
nwparker/computer-helper-session-review-fixes

Conversation

@nwparker

@nwparker nwparker commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Follow-up to #11425 that closes all post-merge review findings before the computer-use supervisor work continues.

  • Require the existing trusted-peer identity check even if the agent is ever constructed without a token. The CLI currently rejects tokenless --agent launches, but the lower-level request and lifecycle checks now fail closed independently.
  • Register each authenticated socket once, so steady-state helper requests no longer take sessionLock or mutate the connection set.
  • Make session release terminal. A connection arriving after the final owner disconnect is rejected from lifecycle ownership and cannot queue another termination callback.
  • Return explicit rejected / sessionReleased / joined / claimed registration results so the listener distinguishes retryable authentication failures, terminal release, first ownership, and valid joins without repeating work.

Behavior and failure contract

The first trusted, token-valid request claims the session and cancels the unclaimed-startup deadline. Additional authenticated connections may join only while that session remains live. The final registered disconnect marks the session released and triggers exactly one close callback. Malformed, untrusted, token-invalid, duplicate, and post-release connections cannot add lifetime.

Normal provider request handling, explicit terminate, socket permissions, token generation, peer lookup, TCC identity, and caller-owned path cleanup remain unchanged.

Testing

  • swift test --package-path native/computer-use-macos — 43 tests passed
  • pnpm verify:computer-native
  • pnpm lint
  • git diff --check

Added coverage proves a released session cannot be reclaimed. Existing cases continue to cover unclaimed and unauthenticated disconnects, duplicate registration, multiple connections, and last-owner release.

AI Review Report

Reviewed the authentication gate, per-request hot path, session state transitions, concurrent connection ordering, descriptor cleanup, and late-arrival termination window. The new terminal release state closes the redundant callback race, while the connection-local registration flag removes the lock/set operation from authenticated steady-state requests.

No unresolved findings remain in this follow-up.

Security Audit

  • Tokenless construction now still requires a trusted peer for both request dispatch and lifecycle ownership.
  • Invalid tokens retain their existing failure classification.
  • No authority, command execution, filesystem path, dependency, or network surface was added.

Screenshots

No UI change.

@coderabbitai

coderabbitai Bot commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Agent session registration now returns explicit .rejected, .sessionReleased, .joined, and .claimed outcomes and tracks released sessions to prevent reclamation. Connection handling registers only after the first valid request and invokes session-claim callbacks only for newly claimed sessions. Peer authorization now rejects unauthorized connections independently of token configuration. Tests were updated for the new registration contract and released-session behavior.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title is concise and accurately reflects the PR's main focus on closing helper session review gaps.
Description check ✅ Passed The description includes the required summary, screenshots, testing, AI review, and security sections; only Notes is missing.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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

Comment @coderabbitai help to get the list of available commands.

@greptile-apps

greptile-apps Bot commented Jul 29, 2026 •

Copy link
Copy Markdown

Greptile Summary

This PR closes three security and correctness gaps in the computer-use helper's session management, all identified in post-merge review of #11425.

  • Terminal release state: AgentSessionOwnership now tracks wasReleased; any connection arriving after the final owner disconnects gets .sessionReleased, sets registrationComplete = true, and cannot retrigger onSessionClosed — eliminating the double-callback race identified in review.
  • Lock-free steady state: A per-connection registrationComplete flag skips the sessionLock acquisition and registerConnection call on every message after the first successful registration (.claimed or .joined), keeping the hot path lock-free.
  • Auth hardening: isAuthenticated now gates on authorizedPeer before the token check (fixing tokenless-construction bypass), and handleRequest enforces the peer check unconditionally rather than only when a token is configured.

Confidence Score: 5/5

Safe to merge — all three changed paths (auth gate, session state machine, hot-path lock avoidance) are internally consistent, covered by the updated test suite, and close real gaps without regressing existing behavior.

The auth fixes in isAuthenticated and handleRequest are straightforward and complementary: both now require an authorized peer regardless of whether a token is configured. The session state machine change (adding wasReleased) correctly prevents late connections from re-entering the ownership set or triggering a second close callback, and the new test case directly exercises this path.

Files Needing Attention: No files require special attention. The three changed files form a tight, self-contained unit and the test file directly validates the new terminal-state behavior.

Important Files Changed

Filename Overview
native/computer-use-macos/Sources/OrcaComputerUseMacOS/main.swift Fixes two auth gaps: isAuthenticated now requires authorizedPeer even when no token is configured, and handleRequest now rejects unauthorized peers unconditionally (was gated on expectedToken != nil). A per-connection registrationComplete flag removes lock contention from the steady-state request hot path.
native/computer-use-macos/Sources/OrcaComputerUseMacOSCore/AgentSessionOwnership.swift Adds wasReleased terminal state and richer AgentSessionRegistration enum; session can no longer be re-claimed after the final owner disconnects, and the new return values let callers distinguish claimed/joined/released/rejected without inspecting internal state.
native/computer-use-macos/Tests/OrcaComputerUseMacOSTests/AgentSessionOwnershipTests.swift Adds testReleasedSessionCannotBeReclaimed and updates all existing assertions to the new enum type; coverage now exercises the full state machine including the new terminal-released path.

Reviews (2): Last reviewed commit: "perf(computer): stop released session re..." | Re-trigger Greptile

@nwparker
nwparker merged commit 4f536ed into main Jul 29, 2026
31 checks passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
* fix(computer): close helper session review gaps

* perf(computer): stop released session registration retries
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.

1 participant