#14576: Fix/memory loss bugs
docs
channel: bluebubbles
channel: slack
channel: telegram
channel: voice-call
channel: whatsapp-web
app: macos
app: web-ui
gateway
cli
scripts
commands
agents
channel: feishu
stale
size: XL
Cluster:
Memory Management Enhancements
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR hardens session/memory recovery paths:
- Adds `saveSessionSnapshotToMemory` to persist a short markdown snapshot of recent transcript content into the agent workspace `memory/` folder before auto-resetting sessions (compaction failure, role ordering conflict, Gemini session corruption).
- Improves QMD memory manager robustness by atomically exporting session markdown via temp-file+rename, reducing SQLite busy sensitivity (busy_timeout increase), and skipping doc-path resolution when the index is locked.
- Prevents duplicate QMD manager instantiation via a singleflight in `getMemorySearchManager`, and adjusts memory flush logging + behavior when sandbox workspaces are read-only.
Key functional integration is in the reply agent reset/corruption handlers, which now attempt to preserve context in workspace memory before deleting transcripts or rotating session IDs.
<h3>Confidence Score: 3/5</h3>
- This PR is close to safe to merge but has a couple of correctness issues in recovery/snapshot path handling.
- Most changes are defensive and well-scoped (singleflight manager creation, atomic exports, additional recovery snapshots). However, the Gemini corruption cleanup currently resolves transcript paths without agent/topic context, which can leave corrupted transcripts in place for non-default agents/threads, and snapshotting prefers `sessionEntry.sessionFile` even when it may not correspond to the provided sessionId—both can undermine the PR’s stated goal of preventing memory loss during resets.
- src/auto-reply/reply/agent-runner-execution.ts, src/auto-reply/reply/session-memory-snapshot.ts
<!-- greptile_other_comments_section -->
<sub>(4/5) You can add custom instructions or style guidelines for the agent [here](https://app.greptile.com/review/github)!</sub>
<!-- /greptile_comment -->
Most Similar PRs
#8919: Pr/memory flush improvements
by shortbus · 2026-02-04
82.7%
#15127: fix: clean up transcript paths on session corruption with proper er...
by mverrilli · 2026-02-13
80.9%
#15852: fix: pass agentId when resolving IRC session paths
by MisterGuy420 · 2026-02-14
79.1%
#14243: fix: fire session-memory hook on auto-resets + topic-aware memory p...
by TheDude135 · 2026-02-11
78.3%
#20183: fix(memory): index reset/deleted session transcripts
by VACInc · 2026-02-18
78.2%
#3401: fix(memory-lancedb): improve autoCapture with turn-by-turn processing
by mike-nott · 2026-01-28
77.9%
#9085: fix: improve stability for terminated responses and telegram retries
by vladdick88 · 2026-02-04
77.9%
#11364: fix(memory/qmd): prevent cascading failure when query fails or retu...
by blazerui · 2026-02-07
77.4%
#8471: fix(subagent): add defensive checks for undefined string fields
by adam-smeth · 2026-02-04
77.4%
#19341: Mind Memory Fork
by juliopx · 2026-02-17
77.1%