Repository navigation
fix(install-tend): surface the OAuth TUI's own error instead of waiting it out - #1105
Conversation
…ng it out `claude setup-token` reports a rejected code and then sits at "Press Enter to retry", emitting nothing further. The wrapper only watched for a token, so that state was indistinguishable from an approval still pending and the run went quiet for the rest of its 900s window — the caller's only signal being a timeout with a guessed cause. Watch for the TUI's error line, end on it, and report what the CLI said. Add a progress line at the paste prompt, and correct the docs: the CLI holds a localhost listener that takes the redirect, so approving in the browser normally completes the run on its own and the `code#state` paste is the fallback, not the main path. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
tend-agent
left a comment
There was a problem hiding this comment.
The watch-and-exit design is right and the two integration tests pin the behaviours that matter. Two things in the new error path make it report the wrong cause, though — which is the failure mode the PR exists to remove.
The sharper one: the loop breaks because TUI_ERROR matched, and then the message says the TUI reported no error. TUI_ERROR deliberately doesn't go through complete_match (it can't — on the retry path the error line is the last thing the TUI writes), so the capture is whatever the chunk boundary left, and an empty capture is falsy, so failure_message skips its own tui_error branch. Reproduced against the merged tree:
>>> detail = TUI_ERROR.search(b"OAuth error: ").group(1).decode().strip()
>>> failure_message("/tmp/tend-oauth-code", 1.0, True, detail)
'Error: the code from /tmp/tend-oauth-code was typed into the prompt and no token came back, and the TUI reported no error either. Rerun and approve the fresh URL.'That path also takes the docstring's "So does the TUI's own error line" with it — the line never reaches stderr at all. The second is \s* after the colon: \s includes \r\n, so an error line with no detail captures the next line, and b"OAuth error:\r\nPress Enter to retry." is reported as claude setup-token having said "Press Enter to retry." Both inline suggestions together keep all three of the new TUI_ERROR tests green.
Review of the parent commit found two bugs in it. `\s*` after the colon steps over the line break, so an error the CLI prints with no detail reported the following line — "Press Enter to retry." — as its cause; match horizontal whitespace only. And an empty capture is falsy, so that same detail-free error fell through to a message saying the TUI reported no error, about a run that ended because it did; distinguish "no error seen" from "an error with nothing after the label". Drop PASTE_PROMPT and the flag timing the stderr hint against it: the hint is more use alongside the authorize URL anyway, and matching TUI wording to schedule it is the coupling this change argues against elsewhere. Correct the comment at the break, which claimed a completeness nothing establishes — no read happens between it and the final scan, so a clipped detail is possible and naming the error is the point. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…ng it out (#1105) Rotating a consumer's `CLAUDE_CODE_OAUTH_TOKEN` today meant watching `oauth_token.py` sit silent for its full 900s window with no idea whether it was waiting on a person or had already failed. It had already failed: `claude setup-token` reports a rejected code as `OAuth error: Request failed with status code 400` and then parks at "Press Enter to retry", emitting nothing further. The wrapper watched only for a token, so that state was indistinguishable from an approval still pending. Watch for the TUI's error line, end the run on it, and report what the CLI actually said. A rejected code now fails in seconds and names its own cause instead of timing out under a guess. The same investigation corrected a factual error in the skill. `claude setup-token` holds a localhost listener (observed at `127.0.0.1:56305`) that takes the browser redirect, so approving is normally the whole of the user's job and the run completes with nothing typed. SKILL.md presented the `code#state` paste as a co-equal path; it's the fallback for when the browser shows a code page instead. A code is also good exactly once, so one the listener already redeemed fails at the prompt — which is the likely shape of today's failure. Two integration tests against a fake `claude`: a rejected code must fail fast (this hung for the harness's full 60s timeout before the fix), and the localhost path must produce a token with nothing typed. <details> <summary>Review rounds folded in</summary> Before the PR opened: - A comment claimed the error check's placement preserved a retry that the `break` right under it makes unreachable. - The `failed` flag it set was redundant and slightly wrong: the loop also ends on a closed pty and on an exited child, either of which can carry the error line in the read that ends it, leaving the flag false with the error sitting in the buffer. Reading the buffer unconditionally is both shorter and more correct. From tend's review of the first commit — two real bugs, both reproduced before fixing: - `\s*` after the colon crossed the line break, so an error the CLI prints with no detail captured the *next* line and reported "Press Enter to retry." as the cause. Horizontal whitespace only. - An empty capture is falsy, so that same detail-free error fell through to a message saying the TUI reported no error — about a run that ended because it did. "No error seen" and "an error with nothing after the label" are now distinct. - The comment at the break claimed the error line "has finished arriving"; nothing establishes that, since no read happens between it and the final scan. Rewritten to say the detail may be clipped and that naming the error is what matters. - `PASTE_PROMPT` and the flag timing the stderr hint against it are gone. The hint goes out with the authorize URL, where it's more use, and scheduling it by matching TUI wording was the coupling this change argues against elsewhere. </details> > _This was written by Claude Code on behalf of max-sixty_ --------- Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
Rotating a consumer's
CLAUDE_CODE_OAUTH_TOKENtoday meant watchingoauth_token.pysit silent for its full 900s window with no idea whether it was waiting on a person or had already failed. It had already failed:claude setup-tokenreports a rejected code asOAuth error: Request failed with status code 400and then parks at "Press Enter to retry", emitting nothing further. The wrapper watched only for a token, so that state was indistinguishable from an approval still pending.Watch for the TUI's error line, end the run on it, and report what the CLI actually said. A rejected code now fails in seconds and names its own cause instead of timing out under a guess.
The same investigation corrected a factual error in the skill.
claude setup-tokenholds a localhost listener (observed at127.0.0.1:56305) that takes the browser redirect, so approving is normally the whole of the user's job and the run completes with nothing typed. SKILL.md presented thecode#statepaste as a co-equal path; it's the fallback for when the browser shows a code page instead. A code is also good exactly once, so one the listener already redeemed fails at the prompt — which is the likely shape of today's failure.Two integration tests against a fake
claude: a rejected code must fail fast (this hung for the harness's full 60s timeout before the fix), and the localhost path must produce a token with nothing typed.Review rounds folded in
Before the PR opened:
breakright under it makes unreachable.failedflag it set was redundant and slightly wrong: the loop also ends on a closed pty and on an exited child, either of which can carry the error line in the read that ends it, leaving the flag false with the error sitting in the buffer. Reading the buffer unconditionally is both shorter and more correct.From tend's review of the first commit — two real bugs, both reproduced before fixing:
\s*after the colon crossed the line break, so an error the CLI prints with no detail captured the next line and reported "Press Enter to retry." as the cause. Horizontal whitespace only.PASTE_PROMPTand the flag timing the stderr hint against it are gone. The hint goes out with the authorize URL, where it's more use, and scheduling it by matching TUI wording was the coupling this change argues against elsewhere.