Skip to content

fix: recover fenced summary XML responses - #785

Closed
mturac wants to merge 3 commits into
rohitg00:mainfrom
mturac:fix/issue-783-summary-xml-recovery-work
Closed

mturac wants to merge 3 commits into
rohitg00:mainfrom
mturac:fix/issue-783-summary-xml-recovery-work

Conversation

@mturac

@mturac mturac commented Jun 2, 2026 •

Copy link
Copy Markdown

Fixes #783.

Summary:

  • extract the first fenced or embedded ... block before parsing
  • retry the final summary/reduce response once when XML parsing fails
  • add regressions for fenced output and final-response retry

Validation:

  • npm test -- test/summarize.test.ts
  • npm run build

Summary by CodeRabbit

  • Bug Fixes

    • Correctly extract summaries even when wrapped in fenced XML or embedded in surrounding text.
    • Retry final summary generation once on parse failure or transient LLM errors; logs a warning and returns the last raw response if parsing still fails.
  • Tests

    • Added tests covering fenced-XML extraction, retry behavior for failing/parsing responses, and persistence of parsed summary fields.

@vercel

vercel Bot commented Jun 2, 2026

Copy link
Copy Markdown

@mturac is attempting to deploy a commit to the rohitg00's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Jun 2, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 0e6a1e11-a572-4096-87c8-b58cb9615def

📥 Commits

Reviewing files that changed from the base of the PR and between 96800e8 and 5ca5216.

📒 Files selected for processing (1)
  • test/summarize.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • test/summarize.test.ts

📝 Walkthrough

Walkthrough

Normalize LLM output to extract a <summary> block (including fenced xml) before parsing, add a retrying final-summary helper used by both single and chunked final-summary flows, and add tests that validate fenced extraction and retry-on-failure behavior.

Changes

Summary Parsing and Retry Resilience

Layer / File(s) Summary
XML normalization & parser integration
src/functions/summarize.ts, test/summarize.test.ts
Adds SUMMARY_BLOCK_RE and normalizeSummaryXml to extract <summary> blocks from raw LLM output (including xml fenced content); parseSummaryXml normalizes input before extracting tags. Test verifies fenced XML is parsed and persisted (title, narrative, keyDecisions).
Final-summary retry helper and wiring
src/functions/summarize.ts, test/summarize.test.ts
Adds summarizeFinalXmlWithRetry which calls provider.summarize up to twice and accepts the response only when parseSummaryXml succeeds; wires this helper into single-session and chunked reduce final-summary code paths. Tests assert retry occurs on parse failure and on transient provider errors, and that the recovered summary is persisted.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 In fenced code shadows XML lay,

I nibble fences, pull the gems away.
I hop, retry when parsing stumbles—
the final tale persists and never crumbles. ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: recover fenced summary XML responses' clearly and concisely describes the main change: handling XML responses wrapped in markdown fences.
Linked Issues check ✅ Passed The PR fully addresses issue #783: normalizes fenced XML output via parseSummaryXml, adds summarizeFinalXmlWithRetry for final-call resilience, updates both final-summary paths, and includes comprehensive test coverage for fenced-output handling and retry logic.
Out of Scope Changes check ✅ Passed All changes are scoped to issue #783: XML normalization in parseSummaryXml, new summarizeFinalXmlWithRetry helper, updates to produceSummaryXml paths, and corresponding test coverage.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/functions/summarize.ts`:
- Around line 113-133: Wrap the provider.summarize call inside the retry loop in
a try/catch so transient provider errors are retried like in
summarizeChunkWithRetry; on catch, log a warning including the error plus
context.sessionId, attempt, context.mode and context.chunks, then continue to
the next attempt, and if all attempts fail rethrow the last caught error (or
propagate it) so callers see a final failure only after retries; keep
parseSummaryXml usage unchanged and return response immediately on successful
parse.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 1eab56f5-9065-4582-948e-d594dee6be26

📥 Commits

Reviewing files that changed from the base of the PR and between de95403 and dddcb3e.

📒 Files selected for processing (2)
  • src/functions/summarize.ts
  • test/summarize.test.ts

Comment thread src/functions/summarize.ts Resolved

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
test/summarize.test.ts (1)

236-238: 💤 Low value

Consider using a more specific type for the calls array.

The calls property is typed as any[], whereas the makeProvider helper function at lines 87-89 uses the more specific Array<{ system: string; user: string }>. Using the specific type would improve type safety and maintain consistency with other test helpers.

♻️ Optional type improvement
-    const provider: MemoryProvider & { calls: any[] } = {
+    const provider: MemoryProvider & { calls: Array<{ system: string; user: string }> } = {
       name: "test",
       calls: [],
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/summarize.test.ts` around lines 236 - 238, The provider stub declares
calls as any[]; change it to the specific shape used by makeProvider to improve
type safety by typing calls as Array<{ system: string; user: string }>. Locate
the provider object (typed MemoryProvider & { calls: any[] }) in this test and
replace the any[] with the more specific Array<{ system: string; user: string
}>, ensuring any code that pushes or reads from provider.calls matches that
structure.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@test/summarize.test.ts`:
- Around line 236-238: The provider stub declares calls as any[]; change it to
the specific shape used by makeProvider to improve type safety by typing calls
as Array<{ system: string; user: string }>. Locate the provider object (typed
MemoryProvider & { calls: any[] }) in this test and replace the any[] with the
more specific Array<{ system: string; user: string }>, ensuring any code that
pushes or reads from provider.calls matches that structure.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 90b891c6-141a-4ed3-b987-d5e8acca0561

📥 Commits

Reviewing files that changed from the base of the PR and between dddcb3e and 96800e8.

📒 Files selected for processing (2)
  • src/functions/summarize.ts
  • test/summarize.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/functions/summarize.ts

@rohitg00

rohitg00 commented Jun 2, 2026

Copy link
Copy Markdown
Owner

Thanks @mturac — fenced summary XML recovery shipped in v0.9.25 (PR #791 + release notes). Implementation matches your approach (strip markdown fences + retry final parse). Closing because the fix is on main.

@rohitg00 rohitg00 closed this Jun 2, 2026
@mturac
mturac deleted the fix/issue-783-summary-xml-recovery-work branch June 5, 2026 13:52
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.

parseSummaryXml: regex parser fails on markdown code fences and extra text around XML, no retry on final summarize

2 participants