Skip to content

fix(harness): Expired OAuth mid-session dumps a raw internal error into chat #991

Closed

Description

@omesser

Why

An expired OAuth session mid-conversation dumps a raw internal error into the
chat surface. It names no cause the user recognises and offers no way out.

The Harness reported an error: harness: Internal error: Failed to
authenticate: OAuth session expired and could not be refreshed

Three prefixes stack up before the sentence that matters: The Harness reported an error:, then harness:, then Internal error:. The user sent the same
message twice and got the same wall back, which is what a dead end looks like.

The product already knows how to say this well. When a Harness is not signed in
at attach time, not_authenticated (src-tauri/src/harness.rs:1521) produces
"harness not authenticated: run claude /login", and login_command
(:1546) works out the command per Harness. An OAuth token that expires after a
successful attach never reaches that path.

Where it goes wrong

session/new and session/load translate the auth refusal. session/prompt
does not.

src-tauri/src/acp_wire.rs:693, the open path:

if error.code == ErrorCode::AuthRequired {
    OpenError::AuthRequired
} else if cx.is_incoming_closed() {
    OpenError::Lost
} else {
    OpenError::Failed(error.message)
}

src-tauri/src/acp_wire.rs:757, the turn path:

Err(_) if cx.is_incoming_closed() => Err(TurnError::Lost),
Err(error) => Err(TurnError::Failed(error.message)),

No AuthRequired arm. TurnError (:211) has no variant for it either, so the
raw string travels to src/chat-settle.js:65, which wraps it in a fourth prefix
and renders it:

note: `The Harness reported an error: ${payload.error}`,

Two candidate causes, and they need different fixes

If the agent sent -32000 (auth_required), the turn path simply fails to
check the code the open path checks. Mirror :693, add a TurnError::Auth
variant, and route it to the same login_command copy the attach path uses.

If the agent sent -32603 (internal_error) — which is what the words
"Internal error" suggest — then no code check catches it, because the adapter
has flattened an auth failure into a generic one. That needs either a
message-shaped fallback or a fix upstream in the adapter.

Whoever takes this should capture error.code first. It decides the fix, and
the screenshot does not carry it. AI_BUDDY_TRACE_HARNESS is the way in.

Done when

The failure is terminal until a human signs in elsewhere, so this is a state and
not a message. See the correction comment on this issue.

  • While a Harness is unauthenticated, the chat composer is disabled. Today
    it accepts a second send that is guaranteed to fail, which is how the same
    wall appeared twice.
  • The surface names the login, using the login_command
    (src-tauri/src/harness.rs:1546) the attach path already renders through
    not_authenticated (:1521). Never the raw adapter string.
  • Signing in from another terminal brings the buddy back without a restart,
    and the composer re-enables when it does.
  • The chat item carries one prefix, not four.
  • A test pins the turn-path translation the way the attach path is pinned.

Notes

Reported on claude, session 51d9179d, BMO instance. Not reproduced yet; the
trigger is a token expiring in a live session, which no test currently forces.

Activity

  1. added
    bugSomething isn't working
    needs-triageMaintainer needs to evaluate this issue
    p2Eventually: real, but nothing waits on it
    on Sep 24, 2026
  2. added this to the V1 milestone on Sep 24, 2026
  3. omesser commented on Sep 24, 2026

    @omesser
    OwnerAuthor

    The chat surface as the user saw it. Two identical questions at 01:57, two identical walls of error.

    One detail this adds to the report. At 01:59 the same Harness answered a when summoned wake normally ("You called me! BMO is on top of the Dock…"). So the failure was transient and the session recovered on its own, without a restart. That makes the presentation worse rather than better: the chat gave the user a flat dead end for something that healed two minutes later, and nothing in the item suggested waiting or retrying was worth doing.

    — Claude Code agent, on @omesser's behalf.

    BMO chat showing two OAuth errors at 01:57 and a normal summoned reply at 01:59

  4. omesser commented on Sep 24, 2026

    @omesser
    OwnerAuthor

    Correction to my previous comment, which was wrong.

    I wrote that the 01:59 summoned reply meant the failure was transient and the session recovered on its own. It did not. Oded opened the Harness independently in a terminal, signed in there, and ai-buddy came back to life after that. The recovery was manual and external, not automatic.

    I inferred self-healing from two timestamps in a screenshot. The screenshot could not show the login that happened between them, and I should have labelled that a guess instead of stating it. Disregard that reading.

    What this actually changes about the fix

    The failure is terminal until a human signs in somewhere else. That makes this a state, not a message.

    While a Harness is unauthenticated:

    1. The chat composer should be disabled. Right now it accepts input and sends it. Oded asked the same question twice and got the same wall twice, because nothing stopped him. Every send into an unauthenticated Harness is guaranteed to fail.
    2. The surface needs a hint naming the login. Not a raw adapter error. The command already exists in the code, login_command at src-tauri/src/harness.rs:1546, and the attach path already renders it through not_authenticated at :1521. The turn path reaches neither.
    3. Recovery has to be noticed. The user signs in in another terminal, and ai-buddy has to come back without a restart. It evidently does come back, so the re-enable path exists; what is missing is the disable and the hint on the way in.

    So the shape is a per-Harness auth state that gates the composer and carries the login command, not a prettier error string. The four stacked prefixes are still worth removing, but they are the smaller half.

    — Claude Code agent, on @omesser's behalf.

  5. added
    p1Next up: the default for work that should happen
    and removed
    p2Eventually: real, but nothing waits on it
    on Sep 24, 2026
  6. omesser commented on Sep 24, 2026

    @omesser
    OwnerAuthor

    On the in-app login button

    Measured today, one probe attach per Harness, reading what each advertises in initialize.authMethods:

    Harness authMethods
    claude none
    codex API Key, ChatGPT
    cursor-agent Cursor Login
    opencode Login with opencode
    goose Configure Provider
    hermes custom runtime credentials, Configure Hermes provider
    grok xai.api_key, cached_token, Grok
    pi Launch pi in the terminal

    For claude, the Harness in this report, a button is not possible. It advertises no auth methods at all, so there is nothing for ai-buddy to call session/authenticate with. Its login is claude /login in a terminal and ACP never sees it. This is not a policy choice, it is what the Harness offers.

    So the hint is the fix here, not a fallback.

    What the button would take, for the Harnesses that could have one

    ACP auth methods come in two types. terminal means the client re-runs the agent binary in an interactive terminal, which ADR-0018 forbids, since ai-buddy hosts no terminal and does not set clientCapabilities.auth.terminal. agent means the client sends authenticate and the agent logs itself in, which is the only shape a button could use.

    We currently throw that distinction away. auth_hint (src-tauri/src/acp_wire.rs:1043) flattens AuthMethod::Terminal and AuthMethod::Agent into one AuthHint { name, description } with no kind. So today the app cannot tell which of the rows above are button-able. Keeping the type is the precondition for any button work, and it is a one-field change.

    Two known limits on top of that, recorded 2026-09-14 during #654 / #661 and not re-verified today: claude-code-acp throws not-implemented on authenticate, and opencode no-ops. On that reading the button would help Codex and maybe cursor-agent, and nobody in this bug report.

    Recommendation

    Ship the hint and the disabled composer under this issue. File the button separately, scoped to agent-type methods, starting with keeping the kind in AuthHint. That keeps this bug unblocked and gives the button an honest precondition instead of a hope.

    — Claude Code agent, on @omesser's behalf.

  7. omesser commented on Sep 25, 2026

    @omesser
    OwnerAuthor

    Shipped on main via #993 (5449f4f6655b57fffc6e272bdde61db774dd8189).

    Done-when checked against main:

    • Turn-path auth refusal → TurnError::AuthRequired → refuse_login / not_authenticated + login_command; composer gates on opening.login via AttachSettled → ReloadChat → attached().
    • auth_refused covers -32000 and data.errorKind == "authentication_failed" (no message sniffing).
    • Next answered turn clears via signed_in; session kept (session/new once).
    • Chat item is the Shell line under no second prefix (chat-settle.js).
    • Fixture auth-turn / auth-turn-32000 + an_auth_refusal_on_the_turn_names_the_login_and_the_next_answer_clears_it pins both wire shapes.

    Deliberately not in this fix: in-app login button / preserving ACP auth method kind. Filed as #1000.

    — Cursor agent (Coder), on @omesser's behalf.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingharnessneeds-triageMaintainer needs to evaluate this issuep1Next up: the default for work that should happen

    Projects

    • Status
      Done

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions