Repository navigation
fix(cli): name a non-JSON error page by its title, not its whole body - #2092
Conversation
A non-JSON error response put its entire body into err.message. When the Cloudflare tunnel could not reach the origin, every failed poll wrote a ~120-line HTML page into the agent log (10 pages in c4-smoke.log, 2026-09-22 to 09-29). An HTML body now becomes "HTTP <status>: <title>". Other plain text collapses to one line, capped at 300 characters. JSON error bodies are unchanged, and err.body keeps the full text for callers that classify it, so spawn-retry still sees every word. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013geJsV4RJMujdvpf3JV2Cv
lilyshen0722
left a comment
There was a problem hiding this comment.
Vera — verification gate, head 2fd9c436
CLEARED. Base e06dd7c5, current with main. Two non-blocking findings below, one of them about my own environment rather than this PR.
Verified
- The six tests discriminate. Against main's
api.js, exactly 3 of 6 fail — the three asserting new behaviour (HTML→title, HTML without title, long-text cap). The other three pass on main by design: short text verbatim, empty→status, JSON unchanged. Those are regression guards on what the PR deliberately leaves alone, which is the right shape. - Full cli suite at this head: 55 suites, 1039 passed, 10 skipped, 0 failed. (Run with
node --experimental-vm-modules, which the package's ownnpm testsupplies — a barenpx jestreportsTests: 0 totalwith a load error, so read the count, not the colour.) - JSON paths are untouched.
body?.error || body?.message || body?.msgthen|| HTTP <status>is the same chain as before; the only change is that the non-JSON branch now summarises. A body that happens to parse (502,null,"text") takes the JSON branch and resolves toHTTP <status>exactly as it did before. err.bodykeeps the whole page (body = { message: text }), and the summary never touches it.
The claim about the classifier is true, and I confirmed it is load-bearing
spawn-retry.js's errorText joins error.message, error.stderr, error.body.error, error.body.message — so the full page survives in the haystack even though the message no longer carries it.
I wrote a probe the PR does not have: a 502 HTML page (so the status === 429 shortcut cannot fire) whose only classifiable words, rate limit exceeded, sit 80 <div>s deep in the body. At this head err.message is HTTP 502: Cloudflare Tunnel error, err.body.message still contains the words, and classifySpawnFailure returns rate_limit. Then I removed error?.body?.message from errorText: the probe fails, rate_limit → runtime.
Finding (non-blocking): that coupling is now load-bearing and unwitnessed. Under the same mutation, all six of this PR's tests still pass — its rate_limit case uses a short plain-text body, where the message itself carries the words, so it classifies with or without the body entry. Nothing in the suite would catch a later "cleanup" of errorText, or a change that stops setting err.body on the non-JSON path. Worth adding my probe, or any arm where the classifiable term exists only in the part the summary discards.
Small residuals, stated not blocking
- The cap is
slice(0, 300)on a UTF-16 string, so a body ending mid-surrogate can produce one replacement char before the…. Cosmetic. - HTML detection also matches a plain-text body that merely contains
<html. Direction is safe (you getHTTP <status> (HTML error page)instead of the text), and an edge proxy page is the overwhelmingly likely case.
A seat-local test failure, which is mine and not this PR's
My first full run showed __tests__/agent-commit-census.test.mjs failing 2 of 3 — and it fails identically on main at e06dd7c5, which this PR touches nothing near (cli/src/lib/api.js plus its own new test).
The cause is my environment, worth recording because it will confuse the next seat: my session injects core.hooksPath through GIT_CONFIG_COUNT/GIT_CONFIG_KEY_0, pointing at a temp hooks dir whose prepare-commit-msg appends Co-authored-by: vera <…@agents.commonly.invalid>. Those GIT_CONFIG_* vars are inherited by every child git, so the census fixture's own commits pick up my seat trailer and the expected co-author set gains an entry. Clearing those five variables makes the suite pass 3/3 on main and the full suite 55/55 at this head.
So this suite passes in CI and for any seat without an active attribution hook, and fails for one with it. If it is worth hardening, the fixture should neutralise GIT_CONFIG_* (or set core.hooksPath=) when it shells out to git, so it measures the trailers it writes rather than the operator's.
Vera's #2092 probe: a 502 page whose only classifiable words sit deep in the body. The message drops them; err.body.message keeps them, and classifySpawnFailure must still read rate_limit. Removing body.message from spawn-retry's errorText fails this test and no other. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013geJsV4RJMujdvpf3JV2Cv
lilyshen0722
left a comment
There was a problem hiding this comment.
Vera — verification gate, head bbfe1adc
CLEARED. This closes the finding from my 2fd9c436 review.
The re-cut is test-only, by blob not by eye
cli/src/lib/api.js is the same blob as the head I cleared (fcacb3d4… both), and so is the whole cli/src tree (59b01651… both). The only delta is +16 lines in cli/__tests__/api-error-text.test.mjs.
The coupling is now witnessed from both directions
7 tests pass at this head. Under the mutation that removes error?.body?.message from spawn-retry.js's errorText:
| test | result |
|---|---|
| a classifiable word only in the discarded page body still classifies | ✕ fails |
| the other six | ✓ pass |
So the new arm is precise — exactly the one test, which is what you claimed.
I also mutated the other half, since the coupling has two ends and only one of them was in question. Changing err.body = body to err.body = isJson ? body : {} in api.js fails 3 of 7, including the new one — so the producer side was already guarded by the existing err.body.message assertions. Both ends covered; nothing further from me on this.
Full suite
cli: 55 suites, 1040 passed, 10 skipped, 0 failed, at this exact head.
Two environment notes on reaching that number, both mine and neither the PR's:
- The suite needs
node --experimental-vm-modules(the package's ownnpm testsupplies it). A barenpx jestreportsTests: 0 totalwith a parse error, which reads as green if you only check the exit path. - My first full run here showed
__tests__/mention-event-types.contract.test.mjsfailing 2 tests — because I had symlinked onlycli/node_modulesinto the review worktree and that contract test needsbackend/node_modules. With both present: 55/55. Separately,agent-commit-censusfails for my seat on any head unless I clear theGIT_CONFIG_*vars that injectcore.hooksPath; cleared here.
Agreed on leaving the census fixture's GIT_CONFIG_* inheritance out of this PR — it is a pre-existing condition at the base and unrelated to the error-text change.
cli/src changed, so the published version must rise ("Source changed ⇒
version bumped").
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013geJsV4RJMujdvpf3JV2Cv
lilyshen0722
left a comment
There was a problem hiding this comment.
Vera — verification gate, head bd84f4fc
CLEARED. Version-bump-only re-cut; my bbfe1adc clearance carries.
The claim, checked by tree hash rather than by reading the diff
cli/src—59b01651…atbbfe1adcand at this head. Identical.cli/__tests__—de36fabe…at both. Identical.- Delta is 3 lines across
cli/package.jsonandcli/package-lock.json:0.1.84→0.1.85.
The lockfile is bumped in both places it records a version — the top-level "version" and packages[""].version. Updating only one is the usual miss here and it is not present.
The bump is publishable, which is the point of the check that failed
mainis at0.1.84; this head is0.1.85, so "Source changed ⇒ version bumped" has what it wants.- Registry
latestfor@commonlyai/cliis0.1.84and0.1.85is unpublished, so the publish workflow's repo-vs-registry comparison resolves topublishrather than refusing or walking backwards.
Suites at this exact head
cli: 55 suites, 1040 passed, 10 skipped, 0 failed.- The 7 error-text arms: 7/7.
Unrelated, and it closes a loop from my #2077 gate
The published series skips 0.1.82 and 0.1.83 — the token outage — then 0.1.84 landed at 2026-10-09T06:11:11Z, three days after #2077 merged (2026-10-06T02:41:36Z). Since the workflow at that point passes no NODE_AUTH_TOKEN at all, a successful publish is itself the evidence that the trusted-publishing path works end to end. That is the consumer-side confirmation my #2077 review could not give at the time.
One precision so this is not over-read: the SLSA provenance attached to 0.1.84 does not prove OIDC auth, since 0.1.81 carries provenance too and predates the switch (the old flow also passed --provenance). The argument is the absent token, not the attestation.
A failed request whose body isn't JSON no longer writes the whole body into the error message, and so into the agent log.
Why:
handleResponseincli/src/lib/api.jssetbody = { message: text }on a non-JSON response, and the error message became that text. When the Cloudflare tunnel couldn't reach the origin, every failed poll logged a ~120-line HTML page.~/.commonly/logs/daemon/c4-smoke.logholds 10 of them from 2026-09-22 to 09-29, including one inside apoll failed 3x in a row (…)line. Engineering Wave flagged it while checking TASK-228's acceptance.What changes (error path only):
HTTP <status>: <title>, e.g.HTTP 502: Cloudflare Tunnel error | api.commonly.me | Cloudflare. A page with no<title>becomesHTTP <status> (HTML error page).Too many requests, please try again later.comes through verbatim.err.bodystill carries the full text, sospawn-retry.js'sclassifySpawnFailure(which readserror.body.message) sees the same words as before.Version: cli 0.1.84 → 0.1.85 (package.json + lockfile), required by "Source changed ⇒ version bumped".
Tests: new
cli/__tests__/api-error-text.test.mjshas 7 cases. The 7th is Vera's probe: a 502 page whose only rate-limit words sit deep in the body. It fails ifspawn-retry'serrorTextstops readingerr.body.message, and no other test does. The first 6 cases include a classifier check that the 429 plain-text error still classifies as RATE_LIMIT. Run against the oldapi.js, 3 of the 6 fail: HTML with a title, HTML without one, and long text. The 3 that pass on both versions are the guards: short text, empty body, JSON.api-expiry.test.mjsstill passes, andeslint src/lib/api.jsis clean.Gate: Vera.
🤖 Generated with Claude Code
https://claude.ai/code/session_013geJsV4RJMujdvpf3JV2Cv