Skip to content

fix(desktop): stop chat freezes from outbox poison, ACP auth stall, and stdout deadlock - #10417

Merged
Git-on-my-level merged 6 commits into
mainfrom
cursor/d1048c0a
Jul 23, 2026
Merged

Git-on-my-level merged 6 commits into
mainfrom
cursor/d1048c0a

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Jul 23, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Quarantine canonical-hash-mismatched journal outbox rows and back off the outbox pump so one poison row cannot wedge chat mid-stream.
  • Terminalize ACP Authentication required on the active turn (no in-turn OAuth wait); leave reconnect out-of-band.
  • Drain agent→Swift JSONL under stdout backpressure and keep the Swift reader alive while the child process runs so a full pipe cannot deadlock the turn.

Product invariants affected

  • INV-AGENT-*
  • INV-AUTH-1
  • INV-CHAT-1

How it was verified

  • Agent hermetic suite including new tests/journal-pump-backoff.test.ts (node suite green at commit time).
  • Named QA bundle omi-auth-stall-qa rebuilt and exercised; chat send path no longer stuck after the auth/pipe scenarios under test.
  • Line-count baselines updated for AgentBridge / AgentRuntimeProcess / ChatProvider.
  • Pre-push local gate passed (SwiftLint clean; bounded desktop/agent checks).

Test plan

  • Agent hermetic: journal pump backoff + related suite
  • Named QA bundle omi-auth-stall-qa exercised locally
  • CI desktop Swift / agent checks green
  • Spot-check: unauthenticated Claude/ACP session fails closed with authentication disposition (no forever spinner)
  • Spot-check: long tool-heavy turn still completes (stdout drain)

Failure class (fixes)

Failure-Class: none

No registered failure class covers this chat-stall cluster yet. Minting registry classes is deferred to a separate PR per AGENTS.md (instance-fix PRs must not mutate .github/failure-classes/).

Made with Cursor

Review in cubic

Git-on-my-level and others added 6 commits July 23, 2026 13:57
…of wedging the pump

drainBackendTurnOutbox threw when a backend_turn_outbox row's stored
payload_hash diverged from the canonical journal turn. The throw aborted the
whole batch transaction, so the 1s journal outbox pump re-selected the same
poisoned row every tick and never drained any turn. Because the row is durable,
the loop began one second after bridge startup and survived restarts, spamming
"Backend turn outbox revision does not match the canonical journal turn" at 1Hz
forever and leaving in-flight chat turns stuck mid-stream with a spinning loader
(observed in the omi-auth-stall-qa bundle).

Fail closed on the divergence as before, but per-row: park the mismatched row
(status='failed', last_error_code='canonical_hash_mismatch', lease cleared) and
continue draining. Healthy turns still deliver, the poisoned row is never
re-selected, and a later updateJournalTurn re-stamps and re-arms it. An optional
onQuarantine callback lets the pump log the event once instead of at 1Hz.

Failure-Class: FC-outbox-pump-poison-wedge | new

Verification: added a regression test in conversation-journal.test.ts (no throw;
healthy turn delivers; row parks with the diagnostic code; re-drain does not
re-select it; a later mutation re-arms delivery). Full node suite
conversation-journal.test.ts 43/43 pass. tsc introduces no new errors in the
touched files (pre-existing worktree node-types resolution noise only).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
…t-loop the event loop

The journal outbox pump ran on a fixed 1s setInterval and swallowed any throw
from its drains. The prior commit fixed the one known poison (canonical-hash
mismatch), but the pump is still one require* throw away from the same wedge: a
missing journal turn/state row makes drainBackendTurnOutbox throw, and a fixed
interval re-throws it every second forever, surviving restarts (the exact shape
that froze chat mid-stream and spammed stderr at 1Hz).

Close the failure class at the pump instead of chasing each poison: convert the
timer to a self-rescheduling setTimeout with exponential backoff (base 1s,
capped ~1/min) driven by a consecutive-failure streak, and have pumpJournalOutbox
report whether it ran cleanly. A single clean pump snaps the cadence back to
base. Any future poison now throttles to one attempt (and one log line) per
minute rather than pinning the event loop — and it logs a one-line recovery
notice when it clears. Also wires the onQuarantine log from the prior fix.

The agent has no fallback-telemetry primitive (that contract is Swift/Rust), so
visibility here is the bounded backoff plus the recovery log line; the Swift side
still records the fallback when a turn fails to sync.

Failure-Class: FC-outbox-pump-poison-wedge | none

Verification: new hermetic test tests/journal-pump-backoff.test.ts covers the
backoff curve (base/doubling/cap/reset/non-finite). Full node suite 591/591 pass
(was 586 before these two fixes). tsc introduces no new errors in the touched
files.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
…ressure

Active chat turns no longer await Claude OAuth when ACP returns
Authentication required — they fail closed with an authentication
disposition and leave OAuth out-of-band. Agent→Swift JSONL also queues on
stdout drain, and Swift keeps reading while the child process is alive,
so a full pipe cannot wedge the turn mid-stream.

Failure-Class: new
Co-authored-by: Cursor <[email protected]>
Ratchet AgentBridge, AgentRuntimeProcess, and ChatProvider baselines for
the ACP auth terminalize and stdout drain changes so the product-file
line-count check stays green.

Failure-Class: none
Co-authored-by: Cursor <[email protected]>
@Git-on-my-level
Git-on-my-level merged commit 49f667e into main Jul 23, 2026
26 of 30 checks passed
@Git-on-my-level
Git-on-my-level deleted the cursor/d1048c0a branch July 23, 2026 18:29

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a45b93b4c8

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

isClaudeAuthRequired = true
startClaudeAuth()
// Provider auth is distinct from the Pro upgrade sheet.
isClaudeAuthRequired = false

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Keep opening valid Claude OAuth URLs

When an ACP session has no usable Claude credentials, initializeAcp() calls startAuthFlow(), which sends auth_required with an authUrl and then waits for the OAuth callback. This handler now stores that URL but neither calls startClaudeAuth() nor presents any replacement UI, so in user-Claude mode the browser never opens and the first Claude query stalls until the OAuth timeout instead of letting the user reconnect.

Useful? React with 👍 / 👎.

}

/** @deprecated Renamed to {@link isAcpProviderAuthFailure}; classify-only, no in-band recovery. */
export const isRecoverableAcpAuthError = isAcpProviderAuthFailure;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Remove the deprecated ACP auth alias

This leaves a deprecated in-repo compatibility alias for the old recoverable/retry API even though rg isRecoverableAcpAuthError shows the remaining macOS callers are tests that can be migrated in the same change. Keeping the retired name available makes it easy to reintroduce in-band OAuth retry semantics that this patch is removing, and the repo rule explicitly says to migrate in-tree callers rather than add deprecated aliases.

AGENTS.md reference: AGENTS.md:L90-L92

Useful? React with 👍 / 👎.

aryanorastar added a commit to aryanorastar/omi that referenced this pull request Jul 26, 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]>
Git-on-my-level added a commit that referenced this pull request Jul 29, 2026
…band (#10478)

## 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

<!-- This is an auto-generated description by cubic. -->
<a
href="https://cubic.dev/pr/BasedHardware/omi/pull/10478?utm_source=github"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img
alt="Review in cubic"
src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a>
<!-- End of auto-generated description by cubic. -->
undivisible pushed a commit to undivisible/omi that referenced this pull request Sep 29, 2026
…nd stdout deadlock (BasedHardware#10417)

## Summary
- Quarantine canonical-hash-mismatched journal outbox rows and back off
the outbox pump so one poison row cannot wedge chat mid-stream.
- Terminalize ACP `Authentication required` on the active turn (no
in-turn OAuth wait); leave reconnect out-of-band.
- Drain agent→Swift JSONL under stdout backpressure and keep the Swift
reader alive while the child process runs so a full pipe cannot deadlock
the turn.

## Product invariants affected
- INV-AGENT-*
- INV-AUTH-1
- INV-CHAT-1

## How it was verified
- Agent hermetic suite including new
`tests/journal-pump-backoff.test.ts` (node suite green at commit time).
- Named QA bundle `omi-auth-stall-qa` rebuilt and exercised; chat send
path no longer stuck after the auth/pipe scenarios under test.
- Line-count baselines updated for AgentBridge / AgentRuntimeProcess /
ChatProvider.
- Pre-push local gate passed (SwiftLint clean; bounded desktop/agent
checks).

## Test plan
- [x] Agent hermetic: journal pump backoff + related suite
- [x] Named QA bundle `omi-auth-stall-qa` exercised locally
- [ ] CI desktop Swift / agent checks green
- [ ] Spot-check: unauthenticated Claude/ACP session fails closed with
authentication disposition (no forever spinner)
- [ ] Spot-check: long tool-heavy turn still completes (stdout drain)

## Failure class (fixes)

Failure-Class: none

No registered failure class covers this chat-stall cluster yet. Minting
registry classes is deferred to a separate PR per AGENTS.md
(instance-fix PRs must not mutate `.github/failure-classes/`).


Made with [Cursor](https://cursor.com)

<!-- This is an auto-generated description by cubic. -->
<a
href="https://cubic.dev/pr/BasedHardware/omi/pull/10417?utm_source=github"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img
alt="Review in cubic"
src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a>
<!-- End of auto-generated description by cubic. -->
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