Skip to content

fix(cli): choose OpenCode 2 for managed account login - #36292

Merged
brennanb2025 merged 8 commits into
mainfrom
brennanb2025/sta-12816-opencode-account-add
Oct 30, 2026
Merged

brennanb2025 merged 8 commits into
mainfrom
brennanb2025/sta-12816-opencode-account-add

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​714 $\color{#cf222e}{\Huge{\mathbf{−}}}$​3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​711
Prod 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​251 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​250

Adding an OpenCode account failed when opencode resolved to OpenCode 1.x: Orca passed the unsupported --standalone option, OpenCode printed help, and no account was saved. Managed capture requires OpenCode 2's credential database, so removing the option would leave account addition broken.

The generated login checks opencode2, then opencode, and selects the first executable whose successful login help declares standalone support. If neither supports it, Orca explains what is required before starting login and gives installation guidance that preserves an existing OpenCode 1 default. Settings already copies this same CLI command. Windows preparation failures retain the affected launcher path; recovery guidance uses a safe absolute separate prefix and addresses earlier suffixed launchers without replacing the generic command default.

Each captured help probe has a ten-second execution deadline, bounded output, separate process-exit and output-close handling, and a bounded drain after exit. Its existing account session owns termination and reader cleanup through fallback, interruption and login handoff. Probes use the same Windows launch preparation as interactive login. Interactive login keeps its terminal attachment.

Tracked in STA-12816; tracked in #35953. Thanks to Alonsojrr14 and #35956 for reporting the unsupported-login boundary and capability probe.

Plan and review path: Full path because this changes account login, process ownership and a capability check that can refuse an action. Keep executable discovery, isolated standalone login and validated credential capture as one coherent change. Use the common pattern's scoped process/output lifetime, adapted to an externally installed provider. No saved field, wire format, host-version requirement, automatic installation or user default changes. New capability or changed requested outcome: none. Older phone/server/agent or saved-data flow worsened: none. Unsettled UI choice: none. Conflicting ruling: none. The growth replan keeps the complete mechanism in this PR.

Intended differences from the common pattern: Orca discovers an external executable because the provider is independently installed and multiple generations share a command name; selecting Orca's own executable cannot perform provider login. The help probe has an execution deadline and bounded capture because a broken installed candidate must permit fallback. The existing outer session spans private login and credential capture; external help cannot implement the provider's internal server lease. Interactive authentication retains terminal input, while captured help uses owned process scope and closed stdin. Windows uses the existing guarded, tracked tree-termination implementation. Separate-prefix manual installation preserves the existing command default. No temporary differences.

Validation: Five review rounds completed with no open finding; an unchanged Settings Copy renderer-test coverage concern is deferred without a failing input. The loop repaired probe ownership/completion, Windows preparation parity, effective installation/recovery guidance, and actual CLI coverage. The process architecture received independent panel review and final whole-mechanism comparison. Five focused files passed 53 tests; eight affected tests passed after type/test guard conformity repairs; the final Windows diagnostic regression failed before repair and all 39 account tests passed afterward. These suites overlap. Real CLI regressions use the actual ten-second deadline and prove fallback, interruption, capture handoff, cleanup, and actual CLI exit with descendant-held pipes. Fixture agents do not prove authentication. Normal pre-commit passed. The single main sync is complete; CI is green on 8ed9dd98be8e4c73b5e0cbb0ffb45b50e02c95ce, including static analysis/typecheck, selected unit shards, packages and native smoke.

Real QA: On Windows, actual OpenCode 1.19.0 reproduced the unsupported standalone failure on main; the branch refused it before login without adding an account. Baseline project and empty-account state survived a graceful restart and upgrade. Actual OpenCode 2.2.2 was selected alongside v1 and completed real ChatGPT authorization: the provider and Orca CLI exited 0, native capture imported its validated credential database, and the saved account was listed as active in both the CLI and Settings while the baseline project remained. The passing enrollment, redirect submission and Settings checks ran through qa-drive after two diagnosed browser-interception rig failures were repaired. Real OpenCode and Claude prompt cancellation and Codex SIGINT cancellation completed with child close before private-home cleanup, no account import, and baseline state retained. OpenCode and Claude returned provider 130 / Orca CLI 1 through unchanged exit mapping; Codex exercised the default SIGINT helper and exited 130. Probe timeout and held-pipe cases remain fixture-test evidence. The final app stop used Browser.close through the recorded-identity helper; the 34 PIDs in the final audit were absent, all three enrollment homes were removed, and selected app/callback ports had no listeners; the successful CLI/help exit and close events were separately traced. Runtime QA used 9b76bde301d58562c3e0e04128d92bbe3755522e; later reviewed commit 8ed9dd98 only repairs a platform-specific test expectation and preserves this runtime evidence.

@brennanb2025
brennanb2025 marked this pull request as ready for review October 30, 2026 07:59
@coderabbitai

coderabbitai Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
Walkthrough

The account handler now resolves the opencode login command before launch. The resolver checks opencode2 and then opencode, and accepts a candidate only if its help command succeeds, does not time out, and includes --standalone. If neither candidate qualifies, it raises an invalid_environment error. Tests cover command selection, login setup, account capture, cleanup, and interruption handling.

Merge Risk: Moderate · up to d4e0c

Managed login can reject an installed compatible CLI. Fix the PATH mismatch before merging.

Pre-merge checks: Passed 3 · Failed 2

Failed Failed checks: 2 warnings

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 28.57% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta… Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check Warning The description provides detailed change rationale, implementation scope, validation results, and QA evidence. However, it does not follow the required template. It omits the required section headings… Restructure the description using every required template heading. Add a plain-language ELI5 summary, explicit What Changed and Why sections, an actual linked issue under Linked Issue, and N/A with a reason under Visual Proof if no UI cha…
Passed Passed checks: 3 passed
Check name Status Explanation
Title check Passed The title clearly and concisely identifies the main change: selecting OpenCode 2 for managed account login.
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.
Full details: Docstring Coverage

Explanation

Docstring coverage is 28.57% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 7 functions across 6 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Full details: Description check

Explanation

The description provides detailed change rationale, implementation scope, validation results, and QA evidence. However, it does not follow the required template. It omits the required section headings and content for ELI5, What Changed, Why, Visual Proof, Testing checkboxes, AI Disclosure, Review, Agent skill upstream boundary, Notes, and Checklist. It also lists issue references without an actual linked issue in the required Linked Issue section.

Resolution

Restructure the description using every required template heading. Add a plain-language ELI5 summary, explicit What Changed and Why sections, an actual linked issue under Linked Issue, and N/A with a reason under Visual Proof if no UI change exists. Add Testing results and platform coverage, complete the AI Disclosure section as applicable, complete Review, Agent skill upstream boundary, Notes, and Checklist sections. Preserve the existing detailed validation and QA information within the appropriate sections.

Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additional comments: 1
src/cli/handlers/opencode-account-login-command.ts-19-19: 1

19-19: Minor · Functional Correctness · Quick win

Unverified finding
Verification ran but could not confirm this finding. It is shown for review, not as a verified issue.

Match the complete --standalone option.

The word boundary in /--standalone\b/ also matches --standalone-mode. If opencode2 help lists only that longer option, the resolver selects opencode2 instead of trying a supported opencode. The subsequent login then passes an unsupported --standalone argument. Reject letters, digits, underscores, and hyphens after the option name. (raw.githubusercontent.com)


Review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: f97ac44d-5869-4e7b-aa91-e2a516fef49c
Commits

Reviewing files that changed from the base of the PR and between 5dd43d0 and 7640c53.

Files selected for processing: 3
  • src/cli/handlers/account.test.ts
  • src/cli/handlers/account.ts
  • src/cli/handlers/opencode-account-login-command.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


Review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: ff6f34fb-bd39-43a6-9580-55c33db3198f
Commits

Reviewing files that changed from the base of the PR and between 7640c53 and 97a2695.

Files selected for processing: 4
  • src/cli/account-add-process.test.ts
  • src/cli/handlers/account.test.ts
  • src/cli/handlers/account.ts
  • src/cli/handlers/opencode-account-login-command.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to GitHub limitations.

⚠️ Outside diff range comments (1)

Major · Resolve OpenCode with the effective login PATH. · opencode-account-login-command.ts:1-51

src/cli/handlers/opencode-account-login-command.ts:1-51
Major · Functional Correctness · Quick win

Resolve OpenCode with the effective login PATH.

addAgentNodePaths prepends agent Node directories to the environment used by the probe and login. Both resolveCliCommand calls instead search the parent process.env.PATH first. If that PATH contains an older opencode, the resolver returns its absolute path and probes it, even when the effective login PATH contains a supported candidate. Login then fails with invalid_environment.

Pass the effective environment PATH to both resolver calls and reuse that environment for login.

Suggested fix
 async function runAgentLoginInTerminal(
   command: string,
   args: string[],
   extraEnv: Record<string, string>,
   json: boolean,
   session: InteractiveLoginSession
 ): Promise<void> {
+  const loginEnv = addAgentNodePaths({ ...stripElectronRunAsNode(process.env), ...extraEnv })
   if (command === 'opencode') {
     command = await resolveOpenCodeLoginCommand(
-      addAgentNodePaths({ ...stripElectronRunAsNode(process.env), ...extraEnv }),
+      loginEnv,
       session
     )
   }
   await new Promise<void>((resolvePromise, rejectPromise) => {
-    const resolvedCommand = resolveCliCommand(command)
+    const resolvedCommand = resolveCliCommand(command, {
+      pathEnv: loginEnv.PATH ?? loginEnv.Path
+    })
...
-    const env = withCliRuntimeOnPath(
-      resolvedCommand,
-      addAgentNodePaths({ ...stripElectronRunAsNode(process.env), ...extraEnv })
-    )
+    const env = withCliRuntimeOnPath(resolvedCommand, loginEnv)
-      const resolvedCommand = resolveCliCommand(command)
+      const resolvedCommand = resolveCliCommand(command, {
+        pathEnv: env.PATH ?? env.Path
+      })

Review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: d72b4ed4-fe75-45fc-95dd-27c076db200d
Commits

Reviewing files that changed from the base of the PR and between d652283 and d4e0c55.

Files selected for processing: 3
  • src/cli/account-add-process.test.ts
  • src/cli/handlers/opencode-account-login-command.test.ts
  • src/cli/handlers/opencode-account-login-command.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Adding an OpenCode account failed when the generic command resolved to OpenCode 1.x: its login lacks standalone mode, while managed capture needs the OpenCode 2 credential database. The generated login now tries compatible opencode2, then opencode, or explains how to install the required version before authentication starts. It preserves the existing generic command default; Settings copies the same CLI command. Tracked in STA-12816 and #35953; thanks to Alonsojrr14/#35956 for the report.

Full-path review is complete: five rounds fixed six P2 findings in probe ownership/completion, Windows launch preparation, installation/recovery guidance and production-CLI coverage. The process architecture received independent panel review; final whole-mechanism reference comparison and readiness code review are complete. Deferred P3: no dedicated renderer test for the unchanged Settings Copy button, with no failing input; its command reaches the tested CLI route.

Validation: five focused files passed 53 tests, eight affected conformity cases passed, and the final 39 account cases passed (overlapping suites). Real production-CLI fixture regressions failed before repair and passed afterward. CI is green on reviewed head 8ed9dd98be8e4c73b5e0cbb0ffb45b50e02c95ce (run 41049866901); one main sync is included. Runtime QA used 9b76bde301d58562c3e0e04128d92bbe3755522e. The only later commit, 8ed9dd98, repairs a Windows-compatible test assertion; production code is identical and the runtime evidence carries.

Real Windows QA:

Flow Observed result
Actual OpenCode 1.19.0 on main c610633 and branch Main printed unsupported standalone help and failed without an account; branch probed and refused before login. Baseline project/empty-account state survived a graceful restart and upgrade.
Actual OpenCode 2.2.2 beside generic v1 Real ChatGPT authorization, provider exit 0, native accounts.addDataFromHome, CLI exit 0, saved active OpenAI account in the CLI and Settings, and baseline project retained. The whole passing attempt ran through qa-drive.
Actual OpenCode and Claude prompt cancellation Provider 130 / Orca CLI 1 through unchanged mapping, child close before private-home cleanup, no import. Claude parent SIGINT-helper execution is not established by this run.
Actual Codex SIGINT cancellation Default SIGINT helper exercised; CLI 130 after launcher close and private-home cleanup, no import.

Two browser-interception rig failures were diagnosed and repaired in the slot before the passing enrollment. Probe deadlines and descendant-held pipes remain fixture evidence. The final helper log independently proves graceful Browser.close. The final absence audit covers its 34 numeric PIDs, three enrollment homes and selected ports; successful CLI/help closure is separately traced, rather than claiming a universal descendant census. No chat-send or post-enrollment restart test is claimed.

QA evidence: CLI/process flows ran against pinned main c610633 and runtime 9b76bde3; no renderer code changed. Retained main/branch logs and cancellation audits are indexed in ~/orca-qa/pr-36292/qa-report-final.md and qa-evidence-final-review.md. Successful enrollment trace, account/repo listings, driver results, full stop log and bounded cleanup audit are independently checked in qa-evidence-signin-review.md and signin-audit/. Auth URLs, redirects and credential values are excluded from public evidence. QA copies/drivers/lead are stopped and tickets released.

For Brennan's review

Saved OpenCode account after real authorization (whole window):

settings-account-2.png

Retained actual OpenCode prompt-cancellation result (whole window):

opencode-cancellation.png

Judgment points: candidate capability and recovery, captured process lifetime, shared cleanup.

@Alonsojrr14

Copy link
Copy Markdown
Contributor

Thanks @brennanb2025 for the fix, and for crediting #35956 and me in the description. I really appreciate it.

One request for next time: when a fix builds on a contributor's issue or PR, could you add a Co-authored-by trailer to the squash commit? Having my name in the repository history would mean a lot to me. For me that's:

Co-authored-by: Alonso Almeida <alonsojr1269@gmail.com>

While testing this, I found a gap your PR didn't cover: without a TTY, orca account add couldn't pass OpenCode's --method/--answer. I opened #37621 and a PR for it, #37622.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

So sorry @Alonsojrr14, your Co-authored-by credit should have been included in the squash commit, my agent missed it. I’m making sure all my agents receive that instruction so it happens next time. Your contributions are super appreciated, thank you for the fixes and for letting me know!

@Alonsojrr14

Copy link
Copy Markdown
Contributor

No worries @brennanb2025, thanks a lot for the quick reply and for updating your agents. I really appreciate it!

I opened a new PR for the follow-up gap: #37622 lets orca account add pass OpenCode's --method/--answer so login can finish without a TTY (fixes #37621). It's waiting on workflow approval, since I'm an outside contributor. Would be great if you could take a look when you have a moment.

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.

2 participants