Skip to content

fix(agents): keep the pod summary prose when the model reply is cut off - #2410

Merged
lilyshen0722 merged 1 commit into
mainfrom
nova/summary-prose-not-json
Oct 22, 2026
Merged

lilyshen0722 merged 1 commit into
mainfrom
nova/summary-prose-not-json

Conversation

@lilyshen0722

@lilyshen0722 lilyshen0722 commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

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.request handler, 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.parse fails, the /\{[\s\S]*\}/ retry finds no closing brace, and the fallback branch stored raw.substring(0, 700) as the summary body. That string is persisted as Summary.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.js now owns the reply-to-body decision:

  • recovers the summary value from a truncated or fenced envelope, un-escaping it,
  • drops the last sentence when it was severed mid-word (only when that keeps most of the text),
  • returns null for anything that still opens a JSON envelope, so buildHeuristicPodSummary (prose) takes over instead of a brace reaching the reader,
  • keeps a well-formed reply's summary + highlights exactly as before.

The token cap goes 380 → 900 so the ordinary case stops truncating; the recovery above is what makes the remaining truncations harmless.

parseJsonBlock moved 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:test files under external/commonly-agent-services were run by no CI job, so the fix would have shipped ungated. One step added to Tests runs the new producer test next to the existing delivery-nonce one. 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 --check on both touched files.
  • Not verified here: that the latest stored summary for a live pod stops starting with {. That is only observable after this ships, and it is the acceptance check to run then.

Out of scope, corrected after review: chatSummarizerService is a separate producer and is not implicated here, but not for the reason first written. Its hourly createPrompt asks for prose, however createEnhancedPrompt does ask for a JSON envelope containing "summary". What protects that path is that generateEnhancedSummary throws 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

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 lilyshen0722 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@lilyshen0722

Copy link
Copy Markdown
Contributor Author

Gate: clear at a04f288e.

The CI step is honest. It ran as step 12 of the required Test & Coverage job (job 119782518335, success) — from the repo root, no install, and today it covers all the node:test files under external/commonly-agent-services: there are exactly two, and both are listed. Re-ran the step's command verbatim on Node 22 locally: 13 pass / 0 fail (9 + 4, as claimed).

The producer test would have caught the live body. I replayed the test's TRUNCATED input through the pre-fix logic (parseJsonBlock → no closing brace → raw.substring(0, 700)) and it stores {"summary":"Chat was mostly status. … verbatim, which trips the first assertion. The input is the real failing shape, not a synthetic one.

Also verified: buildLlmPodSummary(...) || buildHeuristicPodSummary(...) really is the fallback chain at the summary.request handler, so returning null reaches prose rather than a brace; external/commonly-agent-services is in-repo, not a submodule, so the step gates the same tree the PR changes.

One correction to the PR body — same conclusion, wrong reason

chatSummarizerService is not out of scope because "its prompt asks for 2-3 sentences of prose with no JSON contract". That is true of createPrompt, but createEnhancedPrompt asks for a JSON envelope whose first field is "summary". What actually protects it is that generateEnhancedSummary throws on parse failure instead of storing the raw reply. The distinction is load-bearing: if that throw is ever softened into a text fallback — the exact shape commonly-bot just lost — #2406 reappears in a producer this PR's guard does not cover.

Residuals (not blocking)

  1. The test guards the helper, not the call site. Nothing covers buildLlmPodSummary or the summary.request handler, so a raw fallback re-added inside index.js would ship green. commonly-bot/index.js has no test file at all, so this is a new harness rather than a missing case.
  2. No backfill. V2CatchUpStrip.tsx:126-127 renders summary.content verbatim, so a pod whose latest stored summary already starts with { keeps showing it until the next summary.request regenerates it. Worth a decision on whether natural regeneration is enough or stored rows need a sweep.
  3. The step lists files by name, so a third node:test file added under external/ is silently ungated again. Matches the frontend-scripts precedent, so noting rather than asking for a change.

@lilyshen0722 lilyshen0722 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. The test guards the helper, not the call site. Nothing covers buildLlmPodSummary or the summary.request handler, so a raw fallback re-added inside index.js would ship green. commonly-bot/index.js has no test file at all, so this is a new harness rather than a missing case.
  2. No backfill. V2CatchUpStrip.tsx:126-127 renders summary.content verbatim, so a pod whose latest stored summary already starts with { keeps showing it until the next summary.request regenerates it.

Test & Coverage green at this head; no failing checks.

GATE: PASS

@lilyshen0722
lilyshen0722 added this pull request to the merge queue Oct 22, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 22, 2026
@lilyshen0722
lilyshen0722 added this pull request to the merge queue Oct 22, 2026
Merged via the queue into main with commit be32f10 Oct 22, 2026
25 checks passed
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.

Pod catch-up strip shows raw JSON instead of the summary

1 participant