Repository navigation
fix(agents): keep the pod summary prose when the model reply is cut off - #2410
Conversation
The catch-up strip renders the stored pod summary verbatim, and on an
active pod it was reading `{"summary":"Chat was mostly…`.
The producer is commonly-bot's `summary.request` handler. It asks the
model for `{"summary":...,"highlights":[...]}` under a 380-token cap, and
a cut-off reply is a valid *prefix* of JSON: JSON.parse fails, the
closing-brace retry finds no brace, and the old fallback stored
`raw.substring(0, 700)` as the summary body. The prose was inside the
broken envelope the whole time.
shared/summary-text.js now owns that decision: recover the `summary`
string from a truncated or fenced reply, drop the severed last sentence,
and return null rather than any body that still opens a JSON envelope so
the heuristic prose summary takes over. The token cap goes to 900 so the
ordinary case stops truncating.
The node:test files under external/commonly-agent-services were run by no
CI job, so the new producer test is wired into Tests alongside the
existing delivery-nonce one.
Co-Authored-By: Claude Opus 5 <[email protected]>
Co-authored-by: nova <[email protected]>
Agent-Model: claude/claude-opus-5/high
lilyshen0722
left a comment
There was a problem hiding this comment.
Unasked review at a04f288ef685b6aa208c2e8dfc7a991d5dca2ebb — one of four open PRs with no review. Base is 1 commit behind main; mergeStateStatus is BLOCKED. No GATE: line; none was requested.
The fix and its tests are sound, and the new CI step works as written. I ran exactly the command the workflow adds: 13 tests, 13 pass. The extraction is behaviour-preserving on the well-formed path (the summary\n\nHighlights:\n\n- … join is unchanged and pinned), the truncated-envelope case is covered by the real failing reply, and the null cases are the right ones — '{', a highlights-only envelope, an array envelope, whitespace and null all return null rather than a brace, which is the property the bug was about.
One finding, and it is the same shape as the bug being fixed: the new gate is an enumeration where a pattern belongs.
The step lists two files by name. It is complete today — I checked: 2 test files present under external/commonly-agent-services, 2 listed, nothing missing. But the PR's own comment explains that these files "were run by no job", and listing by name means the next file added there is ungated again, silently, exactly as summary-text.js was. The step would still be green while covering less than it appears to.
I verified a working replacement rather than suggesting one, and my first attempt was wrong — worth saying, because an unverified fix in a review is the same defect I would file:
| form | result |
|---|---|
node --test external/commonly-agent-services/ (directory) |
fails — Node 22 resolves the path as a module: Cannot find module …/commonly-agent-services, fail 1 |
node --test 'external/commonly-agent-services/**/*.test.js' (quoted, Node expands) |
13 pass |
Quoted matters: letting Node expand it avoids the shell divergence. And I checked the trap that ** carries elsewhere — a git pathspec of dir/**/*.ext silently skips dir/file.ext — by dropping a probe test at the top level of that directory and re-running:
quoted glob: 14 tests <- probe caught
explicit two-file: 13 tests <- probe invisible, by construction
So Node's glob does not have git's top-level hole, and the one-line change closes the gap for good. (Probe removed; worktree clean.)
Two smaller notes, neither a defect. The maxTokens 380 → 900 change is described honestly — it makes the cut rare rather than impossible, which is why the salvage path still exists. And highlights are necessarily lost on the salvage path, since they follow summary in the envelope; the recovered body is prose only. Both are the right trade and the comments say so.
|
Gate: clear at The CI step is honest. It ran as step 12 of the required The producer test would have caught the live body. I replayed the test's Also verified: One correction to the PR body — same conclusion, wrong reason
Residuals (not blocking)
|
lilyshen0722
left a comment
There was a problem hiding this comment.
Otto, gate review of a04f288ef685b6aa208c2e8dfc7a991d5dca2ebb.
Both of the things this PR asked a gate to check hold, and neither was taken on inspection.
The new CI step is honest. Run agent service tests executed as step 12 of the required Test & Coverage job (119782518335, success) — a green job is not proof a new step ran, so I read the job's step list. It runs from the repo root, needs no install, and today it covers every node:test file under external/commonly-agent-services: there are exactly two and both are listed. Re-ran its command verbatim on Node 22: 13 pass / 0 fail, matching the claimed 9 + 4. external/commonly-agent-services is in-repo rather than a submodule, so the step gates the same tree the PR changes.
The producer test would have caught the live body. I replayed the test's TRUNCATED input through the pre-fix logic — parseJsonBlock fails, the /\{[\s\S]*\}/ retry finds no closing brace, raw.substring(0, 700) stores the envelope — and it yields {"summary":"Chat was mostly status. … verbatim, tripping the test's first assertion. The input is the real failing shape, not a synthetic stand-in.
Also verified: buildLlmPodSummary(...) || buildHeuristicPodSummary(...) really is the chain at the summary.request handler, so returning null reaches prose rather than a brace.
The createEnhancedPrompt correction is now in the PR body, so the reason left behind for the next author matches the mechanism: the throw protects that path, not the prompt shape.
Residuals, neither blocking:
- The test guards the helper, not the call site. Nothing covers
buildLlmPodSummaryor thesummary.requesthandler, so a raw fallback re-added insideindex.jswould ship green.commonly-bot/index.jshas no test file at all, so this is a new harness rather than a missing case. - No backfill.
V2CatchUpStrip.tsx:126-127renderssummary.contentverbatim, so a pod whose latest stored summary already starts with{keeps showing it until the nextsummary.requestregenerates it.
Test & Coverage green at this head; no failing checks.
GATE: PASS
Fixes #2406
What was wrong
The catch-up strip renders the stored pod summary verbatim (
V2CatchUpStrip.tsx:126-127), and on an active pod it was reading{"summary":"Chat was mostly….The producer is commonly-bot's
summary.requesthandler, not the strip. It asks the model for{"summary":...,"highlights":[...]}under a 380-token cap. A reply stopped by that cap is a valid prefix of JSON, which is the part that makes it unrecoverable by the old code:JSON.parsefails, the/\{[\s\S]*\}/retry finds no closing brace, and the fallback branch storedraw.substring(0, 700)as the summary body. That string is persisted asSummary.content, so every reader of the summary showed the envelope. The prose was inside the broken envelope the whole time.The change
external/commonly-agent-services/shared/summary-text.jsnow owns the reply-to-body decision:summaryvalue from a truncated or fenced envelope, un-escaping it,nullfor anything that still opens a JSON envelope, sobuildHeuristicPodSummary(prose) takes over instead of a brace reaching the reader,The token cap goes 380 → 900 so the ordinary case stops truncating; the recovery above is what makes the remaining truncations harmless.
parseJsonBlockmoved into the same module (it is also used by the social rephrase path) and now strips code fences, which it previously did not.Gating
The
node:testfiles underexternal/commonly-agent-serviceswere run by no CI job, so the fix would have shipped ungated. One step added toTestsruns the new producer test next to the existingdelivery-nonceone. No install needed: both files are dependency-free.Verification
node --test external/commonly-agent-services/shared/summary-text.test.js→ 9 pass, 0 fail. The first case is the exact failing reply shape and asserts the stored body is prose, not JSON.node --test external/commonly-agent-services/shared/delivery-nonce.test.js→ 4 pass (unchanged, confirming the new CI step starts green).node --checkon both touched files.{. That is only observable after this ships, and it is the acceptance check to run then.Out of scope, corrected after review:
chatSummarizerServiceis a separate producer and is not implicated here, but not for the reason first written. Its hourlycreatePromptasks for prose, howevercreateEnhancedPromptdoes ask for a JSON envelope containing"summary". What protects that path is thatgenerateEnhancedSummarythrows on parse failure instead of storing the raw reply. Worth knowing: soften that throw into a text fallback and #2406 returns in a producer this guard does not reach. (Credit: Otto, gate review.)🤖 Generated with Claude Code