Skip to content

feat(summarize): zero-LLM synthetic summary path + graceful fallback - #845

Closed
saatvik333 wants to merge 1 commit into
rohitg00:mainfrom
saatvik333:feat/synthetic-summarize
Closed

feat(summarize): zero-LLM synthetic summary path + graceful fallback#845
saatvik333 wants to merge 1 commit into
rohitg00:mainfrom
saatvik333:feat/synthetic-summarize

Conversation

@saatvik333

@saatvik333 saatvik333 commented Jun 6, 2026

Copy link
Copy Markdown

Problem

mem::summarize calls the external LLM provider on every session stop whenever a provider key is configured. AGENTMEMORY_AUTO_COMPRESS only gates per-observation compress (which already has a zero-LLM compress-synthetic.ts path since #138) — it does not gate summarize.

So when the provider is rate-limited or down, summarize keeps failing:

  • Gemini free tier returns 429 (generate_content_free_tier_requests, limit 20).
  • If the configured FALLBACK_PROVIDERS key is also invalid (401), there's no escape.
  • Each failure hits ResilientProvider.recordFailure(); after the threshold the shared circuit breaker opens, which then fails compress and embeddings too.

Net effect: one provider outage takes the whole memory hot-path down, and every session-stop summarize is a hard failure with no degraded mode.

Change

Add src/functions/summarize-synthetic.tsbuildSyntheticSummary(): a deterministic, zero-LLM session summary built from the already-compressed observations (titles, files, decisions, concepts derived from dirs/extensions, activity-tallied narrative). Mirrors the existing compress-synthetic.ts philosophy.

Wire it into mem::summarize as:

  1. Primary path when AUTO_COMPRESS is off or no provider key is configured — never touches the provider, no token spend, no breaker exposure.
  2. Graceful fallback when an enabled provider errors / returns empty / produces unparseable or invalid output — so summarize never hard-fails.

recap, handoff and skill-extract keep working in every failure mode. Users who want richer LLM narratives opt in with AGENTMEMORY_AUTO_COMPRESS=true (unchanged).

Notes

  • No new deps. No schema/state changes. Behavior for users with a healthy LLM + AUTO_COMPRESS=true is unchanged except that previously-fatal provider errors now degrade to a synthetic summary instead of returning {success:false}.
  • Quality scored via the existing scoreSummary(); a typical dev session scores 100, a conversation-only session ~60 (no fabricated decisions/files).
  • Removes the now-dead provider.name === "noop" branch (provider is always wrapped in ResilientProvider, so that string never matched); the noop case is handled by detectLlmProviderKind().

Summary by CodeRabbit

  • New Features
    • Session summarization now works without requiring a language model, using a deterministic approach to aggregate session observations and generate summaries.
    • Improved fallback behavior ensures summaries are reliably generated even when LLM services are unavailable or disabled.

mem::summarize always called the external LLM provider whenever a key was
configured (AGENTMEMORY_AUTO_COMPRESS only gates per-observation compress).
When the provider is rate-limited / down (e.g. Gemini free-tier 429) and the
fallback key is invalid, every summarize fails and trips the shared circuit
breaker, taking compress/embeddings down with it.

Add buildSyntheticSummary(): a deterministic, zero-LLM session summary built
from the already-compressed observations (mirrors compress-synthetic.ts, #138).
Wire it into mem::summarize as:
  - the PRIMARY path when AUTO_COMPRESS is off or no provider key is set, and
  - a graceful FALLBACK when an enabled provider errors / returns empty /
    produces unparseable or invalid output.

Result: summarize never hard-fails and can no longer trip the breaker; recap,
handoff and skill-extract keep working with no token spend. Opt back into
richer LLM summaries via AGENTMEMORY_AUTO_COMPRESS=true.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@vercel

vercel Bot commented Jun 6, 2026

Copy link
Copy Markdown

@qareai 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 6, 2026

Copy link
Copy Markdown
Contributor

Looking for one thing? Review this PR in Change Stack to search files, summaries, diffs, and code without losing your place.

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: 58607da2-58ae-4c1d-98cd-104cfe0a1e11

📥 Commits

Reviewing files that changed from the base of the PR and between a323fb0 and 4024d52.

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

📝 Walkthrough

Walkthrough

Adds a deterministic zero-LLM session summarizer that aggregates compressed observations into structured summaries, then integrates it into the main mem::summarize function as a fallback path for provider failures, validation errors, and noop providers.

Changes

Zero-LLM Session Summarization

Layer / File(s) Summary
Synthetic Summarizer Implementation
src/functions/summarize-synthetic.ts
New module provides utility helpers for path handling, text formatting, duration humanization, and frequency ranking, then implements buildSyntheticSummary to deterministically transform CompressedObservation[] into a SessionSummary by sorting by timestamp, tallying activity types, collecting modified file paths, deriving concept labels, extracting key decisions, computing duration, and assembling narrative text.
Integration into Main Summarize Flow
src/functions/summarize.ts
Imports synthetic summarizer and config detection helpers, adds a synthesize() helper that builds, scores, persists, and audits synthetic summaries, introduces an early zero-LLM path for noop providers and disabled auto-compress, and replaces all LLM failure branches (empty response, XML parse, validation, thrown errors) with synthetic fallback paths that record success metrics and mark audit events as synthetic.

Sequence Diagram(s)

sequenceDiagram
  participant mem as mem::summarize
  participant syn as buildSyntheticSummary
  participant KV as KV.summaries
  participant audit as safeAudit
  participant metrics as metricsStore
  
  mem->>mem: Detect noop/auto-compress disabled
  mem->>syn: Invoke synthesize(reason)
  syn->>KV: Store summary
  syn->>audit: Record synthetic event
  syn->>metrics: Record success=true
  syn->>mem: Return {success:true, synthetic:true}
  
  note over mem: Also fallback on:<br/>empty provider response<br/>XML parse failure<br/>validation failure<br/>LLM error
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A summary so swift, no models to call,
Observations compressed—we need not them all.
When the LLM stumbles or providers fall short,
Our rabbit-eared synthesizer saves the fort!
Zero-LLM magic, deterministic and true,
From observations to narrative through and through. ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 11.11% 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 'feat(summarize): zero-LLM synthetic summary path + graceful fallback' directly and clearly describes the main changes: adding a zero-LLM synthetic summary path and integrating graceful fallback behavior into the summarize function.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ 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.

@saatvik333 saatvik333 closed this by deleting the head repository Jun 8, 2026
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.

2 participants