Skip to content

fix(desktop): stop cold-start ACP init from awaiting Claude OAuth in-band - #10478

Merged
Git-on-my-level merged 1 commit into
BasedHardware:mainfrom
aryanorastar:fix/10407-acp-init-auth-nonblocking
Jul 29, 2026
Merged

Git-on-my-level merged 1 commit into
BasedHardware:mainfrom
aryanorastar:fix/10407-acp-init-auth-nonblocking

Conversation

@aryanorastar

@aryanorastar aryanorastar commented Jul 24, 2026 •

Copy link
Copy Markdown
Collaborator

What

Closes #10407.

Cold-start ACP initializeAcp() awaited startAuthFlow() when the agent returned -32000 (auth required), then retried init. With expired Claude credentials and no OAuth callback, init sat inside that await for the entire callback timeout — and because no turn was on the wire yet, the user's very first send had nothing to terminalize behind it and simply hung until the timeout elapsed.

This applies the same terminalize-first contract the active turn already follows (#10417): signal auth_required to Swift, then start — never await — the OAuth flow and return. isInitialized stays false, so the pending send reaches the ACP request, hits the same -32000, and terminalizes as authentication through the kernel's existing recoverable-error path instead of blocking.

The flow is still started, not dropped: Swift ChatProvider.startClaudeAuth refuses to open sign-in without the bridge-issued authUrl that only this flow mints, so dropping the call would strand the user in an auth-required state with no way to sign in. The bug was the await, not the call.

Why a shared seam + failure class

index.ts cannot be imported under vitest (module scope spawns the ACP subprocess and binds stdin), so its coverage is source-scraping — a static tripwire, not behavior. The kickoff is extracted to acp.ts as beginProviderAuthWithoutBlocking, a seam with a real injectable boundary, and tested behaviourally.

This is the second instance of one root cause — an ACP path awaiting interactive OAuth in-band so nothing can terminalize. The first (#10417) hardened the active-turn path. Per AGENTS.md ("two or more recent fixes share the cause → add a reusable guard surface"), this declares Failure-Class: new and registers FC-in-band-auth-await-stall (.github/failure-classes/) citing both PRs, with beginProviderAuthWithoutBlocking as the code-level guard.

Test

desktop/macos/agent/tests/acp-init-auth-nonblocking.test.ts (new, mirrors the issue's falsifiable T1):

  • Returns without waiting for the OAuth callback (never-settling flow ⇒ control still reaches the assertions).
  • Signals auth_required before the flow produces anything, so a pending send terminalizes as authentication.
  • Still starts the flow — guards the tempting over-fix of dropping the call, which would leave Swift with no authUrl.
  • A failed flow logs instead of leaking an unhandled rejection.

Verification evidence

# agent package (vitest)
acp-init-auth-nonblocking.test.ts .... 4 passed
acp-auth-terminal.test.ts ............ 2 passed
+ acp-tool-activity / protocol-v2 / adapter-selection ... 27 passed total

# mutation check — reintroduce `await startAuthFlow()` before the signal:
acp-init-auth-nonblocking.test.ts .... 3 failed / 1 passed  (as intended)

tsc --noEmit ......................... exit 0
scripts/failure-class validate ....... passes

I exercised the extracted seam directly (the real code path init now runs); I did not boot the full macOS app for this change — the behaviour lives entirely in the agent bridge's auth kickoff, covered by the seam above.

Scope

Agent-bridge TypeScript only — no Swift touched. User-facing changelog fragment included.

Failure-Class: new

Review in cubic

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@Git-on-my-level

Copy link
Copy Markdown
Member

Thanks for the focused fix here. The shape looks directionally right to me: extracting a non-blocking auth kickoff seam and reusing it from cold-start ACP init addresses the hang without dropping the OAuth flow entirely, and the new Vitest coverage guards the important ordering/rejection behavior.

I’m not approving this yet because it touches the Claude auth/ACP initialization path and the required Desktop Swift test gate is currently failing. Before merge, I’d want a maintainer to verify the end-to-end desktop behavior with expired Claude credentials, especially that repeated first-send/auth-required attempts do not spawn confusing duplicate sign-in prompts and that successful OAuth still restarts/re-initializes ACP cleanly.

No concrete code change request from me based on the static diff, but this needs the failing CI resolved or explained plus human maintainer sign-off for the auth-flow behavior.


by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.

@Git-on-my-level Git-on-my-level added needs-maintainer-review Needs a human maintainer to sign off before merge needs-tests PR introduces logic that should be covered by tests security-review Touches auth, provider routing, secrets, or security-sensitive surfaces labels Jul 24, 2026
…band

initializeAcp() awaited startAuthFlow() when ACP returned -32000
(auth required) on cold start, then retried init. With expired
credentials and no OAuth callback, init sat inside that await for the
whole callback timeout — and because no turn was on the wire yet, the
user's first send had nothing to terminalize behind and simply hung.

Apply the same terminalize-first contract the active turn already
follows (BasedHardware#10417): signal auth_required to Swift, then start — never
await — the OAuth flow and return. isInitialized stays false, so the
pending send reaches the ACP request, hits the same -32000, and
terminalizes as `authentication` via the kernel's recoverable-error
path instead of blocking. The flow is still started (not dropped): Swift
startClaudeAuth needs the bridge-issued authUrl only that flow mints, so
dropping it would strand the user with no way to sign in.

The kickoff is extracted to acp.ts as beginProviderAuthWithoutBlocking,
a shared seam with a real injectable boundary, so it is covered
behaviourally rather than by index.ts source-scraping.

This is the second instance of the same root cause (the first, BasedHardware#10417,
hardened the active-turn path), so it declares Failure-Class: new and
registers FC-in-band-auth-await-stall citing both PRs as the shared
guard surface.

Verify:
- agent vitest: acp-init-auth-nonblocking (4) + acp-auth-terminal (2)
  green; mutation (reintroduce await-first) fails 3/4 as intended.
- tsc --noEmit clean; scripts/failure-class validate ok.

Failure-Class: new

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@aryanorastar
aryanorastar force-pushed the fix/10407-acp-init-auth-nonblocking branch from baf5d7b to 30fac1f Compare July 26, 2026 16:51
@aryanorastar

Copy link
Copy Markdown
Collaborator Author

CI is resolved — 0 failing checks on the rebased head 30fac1f7 (11 success / 15 skipped / 1 neutral), including Desktop Swift Build & Tests.

The failure was not this diff. Rather than argue that, I rebased onto current main and let CI answer it, but the diagnosis holds up on the evidence too:

  • This PR changes 5 files, none of them Swift (acp.ts, index.ts, one test, the failure-class JSON, the changelog fragment) — there is no path from it to PushToTalkStateMachineTests, QueryTracerTests, QuitAndReopenActionTests or RawWebSocketValidationTests.
  • All four failed the same way — suite timed out after 120s, which is the harness's own per-suite cap (SUITE_TIMEOUT_SECONDS in desktop/macos/scripts/swift-test-suites.sh, default 120) — and the same run also logged timed out after 4s waiting for ./run.sh build lock. Four suites hitting the wall clock together with build-lock contention is one loaded runner, not four logic failures.
  • The Desktop Swift Build & Tests red was downstream of that: it is a gate job asserting TEST_RESULT = success, which is why it "failed" in 4s without running anything.
  • No other open PR currently shows Desktop Swift Test Suites failing, and main's own Desktop Swift CI is green.

Re-verified on the rebased head: agent suites 6/6 (acp-init-auth-nonblocking 4, acp-auth-terminal 2), tsc --noEmit exit 0, and scripts/failure-class validate → ok: true with no errors.

Your substantive ask stands and I have not tried to satisfy it from here: the end-to-end check with genuinely expired Claude credentials — no duplicate sign-in prompts across repeated first-send attempts, and a clean ACP re-init after successful OAuth — needs a maintainer on a real desktop build. I called that limitation out in the PR body and it is unchanged.

@aryanorastar

Copy link
Copy Markdown
Collaborator Author

Correcting my previous comment — I got the diagnosis partly wrong, and the green is weaker than I implied.

What I got wrong. I attributed the four timed-out suites to a single contended runner. That is not right for the first one: PushToTalkStateMachineTests.testOwnerTransitionTerminatesActiveHubAndDrainsItsPhysicalSession is a known hang on main, tracked in #10492 and #10499 — it blocks on await transitionOwner(... to: "owner-b"), whose hub drain never completes headless. #10499 also records that peer suites then fail on SwiftPM lock wait, which is the real explanation for QueryTracerTests, QuitAndReopenActionTests and RawWebSocketValidationTests and for the run.sh build lock timeout I quoted. So it was one genuine hang plus collateral, not four victims of load.

What I overstated. Desktop Swift Build & Tests is green on 30fac1f7, but Desktop Swift Test Suites did not run on that head — it was skipped by the path filter, where the earlier run had executed it. So the green means "this diff no longer triggers the Swift lane", not "the hang is fixed". I should have checked that before calling CI resolved.

What still holds — and is now better supported than my original argument: this failure is not caused by this PR. #10492 records that it reproduces on a branch with no product changes at all, so it is a main-side regression, and this PR's 5 files contain no Swift.

The rest of my verification stands: agent suites 6/6, tsc --noEmit exit 0, failure-class validate → ok: true. And your substantive ask is unchanged — the expired-credentials end-to-end still needs a maintainer on a real build.

I am picking up #10492 separately rather than leaving it as a footnote here.

@Git-on-my-level

Copy link
Copy Markdown
Member

Thanks for the follow-up and for correcting the CI interpretation.

I re-reviewed the current head (30fac1f7) and ran the focused agent checks locally in a stripped environment:

  • npm test -- tests/acp-init-auth-nonblocking.test.ts — 4/4 passing
  • npm run build — passing (tsc)
  • python3 scripts/failure-class validate --base origin/main --head HEAD --pr-body-file /tmp/omi-pr-10478-body.md — ok: true

Static review still looks positive to me: the change preserves the needed OAuth kickoff while moving the interactive wait out of the cold-start init path, and the extracted seam covers the important ordering and rejection behavior. I do not see a concrete code change to request from this diff.

I’m still not formally approving because this is Claude auth / ACP initialization behavior and the remaining risk is end-to-end desktop UX rather than just TypeScript correctness. Before merge, a maintainer should verify on a real desktop build with expired Claude credentials that repeated first-send/auth-required attempts do not create confusing duplicate sign-in prompts, and that completing OAuth restarts/re-initializes ACP cleanly.


by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.

@Git-on-my-level
Git-on-my-level merged commit 0be628a into BasedHardware:main Jul 29, 2026
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-maintainer-review Needs a human maintainer to sign off before merge needs-tests PR introduces logic that should be covered by tests security-review Touches auth, provider routing, secrets, or security-sensitive surfaces

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Desktop chat: cold-start initializeAcp() still awaits OAuth in-band (same stall as .113, at bridge init)

2 participants