Skip to content

fix(harness): Name the login rather than spawn it - #661

Merged
omesser merged 3 commits into
mainfrom
fix/654-harness-login-handshake
Sep 14, 2026
Merged

omesser merged 3 commits into
mainfrom
fix/654-harness-login-handshake

Conversation

@omesser

@omesser omesser commented Sep 13, 2026 •

Copy link
Copy Markdown
Owner

Why

Connecting an unauthenticated Harness from Chat spawned codex login from a GUI process with no terminal of its own, on inherited stdio. The browser flow reported success, but the CLI handshake and the token reached nothing Chat could use, and the Harness stayed unusable.

The two localhost:1455 servers in #654's log were two codex login spawns: one per Connect click. The user clicked Connect, was thrown out, and clicked again. The ACP child (npx -y @agentclientprotocol/codex-acp@latest) played no part. codex-acp starts Codex's login server only when the client sends authenticate or when DEFAULT_AUTH_REQUEST is set, and ai-buddy does neither.

A second defect hid behind it: select_harness wrote settings directly and never called harness::retarget. A Harness picked from Chat only became the Completer at the next launch, and no ReloadChat was sent, so the open window kept its stale opening. That is the other half of "the Harness stays unusable".

What changed

This takes the third outcome #654 lists: Chat does not start the flow, it names the command and waits.

  • harness_login is deleted, along with its invoke_handler row. Nothing in the product spawns an auth process any more.
  • The six-row login command table moved into harness::login_hint, which is now the single place those strings exist. login_command keeps its precedence — a known fix first, then the handshake's own words, then this table.
  • select_harness routes through SettingsSession::apply instead of writing the file, so the pick retargets the attachment now rather than at the next launch, and the ReloadChat it sends carries the new state back to the window that asked. It answers with the login command.
  • src/chat.js shows that command instead of spawning it.

Acceptance 1 is not reachable any other way from ai-buddy's side: a GUI process cannot host the terminal codex login expects, and ADR-0010 / ADR-0018 / #371 forbid hosting the redirect ourselves. settings.rs already committed this repo to naming the command rather than running it, so Chat now says the same sentence from the same table.

What the user does now

The user signs in to the Harness CLI in their own terminal, with the command Chat and Settings show (for example codex login). It can be done before or after picking the Harness in Chat. Nothing in ai-buddy has to be running for it.

After signing in, ai-buddy picks it up at the next session/new attempt. The auth retry gate is 60 seconds (AI_BUDDY_HARNESS_AUTH_RETRY_SECS), and reopening Chat re-reads login state. A CLI already signed in before ai-buddy ever ran needs nothing at all: the subprocess runs as the same user (ADR-0018).

This matches the ACP spec. Clients that cannot host an interactive terminal must not spawn terminal-type auth, and every non-terminal-hosting ACP client (JetBrains, Emacs agent-shell, Neovim plugins) tells the user to log in in their own terminal.

How to verify

cargo test -p ai-buddy
cargo clippy -p ai-buddy --all-targets -- -D warnings
node --test tests/

417 Rust tests pass, clippy clean, 108 node tests pass.

every_named_harness_documents_a_login_for_the_users_own_terminal asserts every named Harness answers Connect with a hint, and that the hint equals login_command(name, &Handshake::default()).

That ai-buddy no longer spawns an auth process is a compile-time fact, not a test's: harness_login does not exist, and a command absent from the invoke_handler cannot be reached from the webview.

Notes

  • Acceptance bullet 2 is only partly met. chat_opening re-reads login on every opening, so reopening Chat picks up a completed sign-in without restarting the app. But nothing fires when the user finishes codex login in their terminal minutes later. This branch adds no regression there and no trigger either. Building a poller or watcher is a design decision, not a review fix — worth its own issue if a live trigger is wanted.
  • A follow-up commit removed three things review found: a test asserting include_str!("main.rs") contains no Command::new (the invariant is already false — MenuAction::OpenMemory spawns via platform::open_path), a circular test that fed login_hint in and found it again, and a manual chat_opening re-invoke in chat.js that dropped showPrompt and raced the Rust-side push.
  • src/chat.html ships Connect buttons for only four of the six named Harnesses — no hermes, no pi. Pre-existing, not this branch's doing. Worth its own issue.
  • Settings and Chat can legitimately show different commands: login_command prefers an auth method the handshake advertises, so an adapter answering with codex login --device-auth makes Settings say that while Chat shows the table default. That divergence is intended — Settings has more information later — and nothing now claims otherwise.

Closes #654

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

🤖 Generated with Claude Code

@omesser
omesser force-pushed the fix/654-harness-login-handshake branch from e1151dc to d0efdcd Compare September 13, 2026 18:05
@omesser

omesser commented Sep 13, 2026

Copy link
Copy Markdown
Owner Author

Rebased onto e0702166 (fix(macos): Draw the whole "What is this?" label (#660)). Six commits had landed under this branch, including #656, which reworked model.rs and boxed AnyCompleter::Http, and #660, which rewrote platform/macos/settings_window.rs.

The rebase was textually clean — no conflicts. git range-diff confirms both commits replayed byte-identical; only line offsets moved.

Because a clean replay is not evidence the branch's claims survived, each was re-checked against the new base:

  • The harness_login deletion still holds. grep -rn harness_login src src-tauri docs tests scripts .cursor matches nothing at all — not the command, not a caller, not a stale mention in prose. No merged commit reintroduced a reference.
  • Every invoke("...") in src/ and tests/ still resolves. All ten invoked names (character, chat_opening, chat_prompt, chat_ready, chat_send, overlay_hotspots, overlay_open_chat, permission_answer, select_harness, show_settings) are present in the generate_handler! table in main.rs.
  • harness::login_hint is still the one table. The six login command strings live only at harness.rs:1382-1387. The other pi-acp@latest hits are the launch argv (harness.rs:135), which is a different thing, and the rest are test fixtures. No merged commit added a second table.
  • select_harness still routes through SettingsSession::apply and returns the hint. feat(settings): Make the Completer's reasoning effort a Development setting #656 added fields to Settings, but none to SettingsSession, so the settings_session helper's struct literal still matches the struct exactly.

Suite against the new base:

  • cargo test -p ai-buddy — 411 passed, 0 failed, 4 ignored. Includes this branch's every_named_harness_documents_a_login_for_the_users_own_terminal.
  • cargo clippy --workspace --all-targets -- -D warnings — clean.
  • node --test tests/ — 105 passed, 0 failed.
  • pre-commit run --files over the four touched files — all hooks pass, including the workspace clippy hook.

Nothing broke, so the branch carries no rebase fixup commit. Still two commits, same content, new base.

The acceptance gap disclosed in the PR body is unchanged: Chat still needs a restart to leave the not-authenticated state, and this rebase did not touch that.

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

omesser and others added 3 commits September 14, 2026 15:58
Chat's Connect chained a `harness_login` that spawned the Harness's own
login from the GUI process, racing the child it had just attached for
`localhost:1455`. #654.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The source scan false-positived and its invariant is already false;
the Settings row test fed itself the table it then found. #654.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
codex-acp opens no listener on attach. Two Connect clicks made two spawns.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
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.

fix(harness): Auth started by a Harness subprocess does not finish the handshake

1 participant