Skip to content

fix: close three v0.9.24 regressions before v0.9.25 (#778 #775 #783) - #791

Merged
rohitg00 merged 1 commit into
mainfrom
fix/778-fallback-model-resolution
Jun 2, 2026
Merged

rohitg00 merged 1 commit into
mainfrom
fix/778-fallback-model-resolution

Conversation

@rohitg00

@rohitg00 rohitg00 commented Jun 2, 2026 •

Copy link
Copy Markdown
Owner

Three independent v0.9.24 bug fixes bundled for the v0.9.25 release.

#778 fallback chain inherits primary's model

createFallbackProvider copied config.model from the primary into every fallback. With OpenAI primary + Gemini fallback, Gemini was called with gpt-4o-mini and 404'd on every call, which tripped the circuit breaker and blocked downstream LLM ops. New defaultModelFor() resolves each provider's env-driven default (OPENAI_MODEL / GEMINI_MODEL / ANTHROPIC_MODEL / MINIMAX_MODEL / OPENROUTER_MODEL).

#775 import-jsonl aborts on legacy session row missing id

Existing-session branch did kv.set(KV.sessions, existing.id, ...) but legacy rows can lack id. existing.id === undefined → JSON.stringify drops the key → engine returns missing field \key`→ whole handler aborts → entire import dies. One bad row killed the batch. Now re-keys onparsed.sessionId(always populated) + backfillsexisting.id`.

#783 parseSummaryXml fails on markdown fences

Many LLMs wrap structured XML in \``xml ... ```fences or add conversational text around it. The raw payload went straight to the tag regex, returningparse_failedsilently. AddedstripXmlWrappers()` to peel fences + pre/postamble before regex. Also extended the chunk-level 2-attempt retry pattern to the final-summarize merge so one flaky wrap doesn't drop the summary.

Tests

10 new across 3 files. Full suite: 125 files / 1379 tests pass.

Closes #778, closes #775, closes #783.

Summary by CodeRabbit

  • Bug Fixes

    • Fixed session import to handle legacy data with missing ID fields, preventing batch failures.
    • Improved summary generation with automatic retry logic and support for markdown-wrapped XML output.
    • Fixed fallback provider model selection to prevent repeated errors and circuit-breaking issues.
  • Tests

    • Added test coverage for session import handling, summary parsing resilience, and provider model resolution.

Bundles three independent bug fixes that block the v0.9.25 release.

fix(providers): fallback chain resolves its OWN model, not the primary's (#778)

  createFallbackProvider copied config.model from the primary into
  every fallback. With OpenAI primary + Gemini fallback, Gemini was
  called with 'gpt-4o-mini' and 404'd on every call, which tripped
  the circuit breaker and blocked downstream LLM ops entirely. New
  defaultModelFor() resolves each provider's env-driven default
  (OPENAI_MODEL, GEMINI_MODEL, ANTHROPIC_MODEL, MINIMAX_MODEL,
  OPENROUTER_MODEL) so a fallback config now does what it advertises.

fix(replay): import-jsonl re-keys on parsed.sessionId, not existing.id (#775)

  The existing-session branch wrote kv.set(KV.sessions, existing.id, ...)
  but legacy session rows can be missing the 'id' field. existing.id
  was then undefined, JSON.stringify dropped the key from the state::set
  payload, and the engine rejected the call with 'missing field key'.
  The rejection aborted the whole handler — a single legacy row killed
  the entire import. Now re-keys on parsed.sessionId (always populated
  by parseJsonlText's three-level fallback) and backfills missing
  existing.id so future reads stay clean.

fix(summarize): strip markdown fences + retry final parse on failure (#783)

  parseSummaryXml passed the raw LLM payload to the tag regex.
  DeepSeek, GPT, and others wrap XML in  fences or
  prepend a conversational sentence, which caused a silent
  parse_failed and the session was never summarized. Added
  stripXmlWrappers() that peels markdown fences and a surrounding
  pre/postamble before the regex runs. Also extended the chunk-level
  2-attempt retry pattern to the final summarize merge so a flaky
  wrap on the first attempt doesn't drop the summary.

Tests (10 new total)

  test/fallback-model-resolution.test.ts (5): primary/fallback model
  separation across OpenAI/Gemini/Anthropic/Minimax/OpenRouter,
  env override precedence, duplicate-provider skip.
  test/replay-import-key.test.ts (2): id-less existing row no longer
  aborts the import; fresh import path unchanged.
  test/summarize.test.ts (3): markdown-fenced XML parses cleanly,
  final retry recovers on first-attempt parse failure, double-fail
  still surfaces parse_failed.

Full suite: 125 files / 1379 tests pass.

Closes #778, closes #775, closes #783.
@vercel

vercel Bot commented Jun 2, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
agentmemory Ready Ready Preview, Comment Jun 2, 2026 11:19pm

Request Review

@coderabbitai

coderabbitai Bot commented Jun 2, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

This PR fixes three unrelated bugs affecting fallback provider failover, session import batch failures, and summary XML parsing robustness. Each fix includes corresponding test coverage for the corrected behavior.

Changes

Fallback Provider Model Resolution

Layer / File(s) Summary
Model resolution function and fallback config
src/providers/index.ts
defaultModelFor(providerType) resolves each provider's environment-driven default model. Fallback providers are now configured with their own model defaults instead of inheriting the primary provider's model, preventing cross-provider failover 404s.
Fallback model resolution tests
test/fallback-model-resolution.test.ts
Mocked provider suite validates that Gemini uses GEMINI_MODEL, multiple fallbacks use their own env-driven defaults without inheriting the primary model, env overrides take precedence, and duplicate providers are skipped.

Session ID Re-keying in Imports

Layer / File(s) Summary
Session ID re-keying fix
src/functions/replay.ts
Import handler now re-keys session upserts on parsed.sessionId instead of the potentially undefined existing.id, and backfills id on legacy sessions to prevent batch aborts.
Replay import key tests
test/replay-import-key.test.ts
Test suite with KV mock that detects undefined keys validates that legacy sessions (missing id field) import successfully with id backfilled, and fresh imports write exactly once with the correct sessionId key.

Summary XML Parsing Resilience

Layer / File(s) Summary
XML wrapper stripping and retry logic
src/functions/summarize.ts
New stripXmlWrappers helper removes markdown code fences and extra text. The summarize handler now runs a 2-attempt retry loop that re-produces and re-parses on empty responses or parse failures, deferring validation until a successful summary is obtained.
Summary parsing and retry tests
test/summarize.test.ts
Test cases validate that markdown-wrapped XML is parsed successfully and persisted, that first-attempt parse failures trigger a successful retry, and that both-attempt failures return parse_failed error.

🎯 3 (Moderate) | ⏱️ ~20 minutes

🐰 Three bugs hop away,
Fallbacks find their models true,
Sessions skip the void,
XML wraps itself up tight—
Memory flows unbroken! 🌿

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% 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 accurately summarizes the main changes as three bug fixes targeting v0.9.25, with issue numbers clearly referenced.
Linked Issues check ✅ Passed All code changes directly address the three linked issues: #778 (fallback provider model resolution), #775 (import-jsonl key handling), and #783 (summary XML parsing and retries).
Out of Scope Changes check ✅ Passed All changes are scoped to the three linked issues; no unrelated modifications were introduced.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/778-fallback-model-resolution

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.

@rohitg00
rohitg00 merged commit 1ab0a7d into main Jun 2, 2026
6 of 7 checks passed
@rohitg00
rohitg00 deleted the fix/778-fallback-model-resolution branch June 2, 2026 23:24
rohitg00 added a commit that referenced this pull request Jun 2, 2026
Bump to 0.9.25 across 9 files + CHANGELOG.

Closes #778 #775 #783 (PR #791), #758 #726 (PR #773), #759 (PR #772),
#752 (PR #774), #729 (PR #780), #781 (PR #782), #753 (PR #789), #771
(PR #786), #762 (PR #764).

Files bumped:
  - package.json
  - packages/mcp/package.json
  - plugin/.claude-plugin/plugin.json
  - plugin/.codex-plugin/plugin.json
  - plugin/plugin.json
  - src/version.ts
  - src/types.ts (ExportData.version union)
  - src/functions/export-import.ts (supportedVersions Set)
  - test/export-import.test.ts (assertion)

125 test files / 1379 tests pass. npm audit (root + website): 0 vulns.
healdigital pushed a commit to healdigital/agentmemory that referenced this pull request Jul 27, 2026
…resolution

fix: close three v0.9.24 regressions before v0.9.25 (rohitg00#778 rohitg00#775 rohitg00#783)
healdigital pushed a commit to healdigital/agentmemory that referenced this pull request Jul 27, 2026
Bump to 0.9.25 across 9 files + CHANGELOG.

Closes rohitg00#778 rohitg00#775 rohitg00#783 (PR rohitg00#791), rohitg00#758 rohitg00#726 (PR rohitg00#773), rohitg00#759 (PR rohitg00#772),
rohitg00#752 (PR rohitg00#774), rohitg00#729 (PR rohitg00#780), rohitg00#781 (PR rohitg00#782), rohitg00#753 (PR rohitg00#789), rohitg00#771
(PR rohitg00#786), rohitg00#762 (PR rohitg00#764).

Files bumped:
  - package.json
  - packages/mcp/package.json
  - plugin/.claude-plugin/plugin.json
  - plugin/.codex-plugin/plugin.json
  - plugin/plugin.json
  - src/version.ts
  - src/types.ts (ExportData.version union)
  - src/functions/export-import.ts (supportedVersions Set)
  - test/export-import.test.ts (assertion)

125 test files / 1379 tests pass. npm audit (root + website): 0 vulns.

This branch was successfully deployed

1 active deployment
Preview — aa386b78 Deployed Jun 2, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment