Summary
When using Telegram with the web chat gateway open, each new Telegram message can trigger session repair that deletes the previous assistant response from the durable session transcript. The response remains visible in Telegram because it was already delivered, but it disappears from the web chat gateway and is no longer available as conversation history for the next model turn.
Observed behavior
- Send a Telegram message.
- OpenClaw/Jeeves responds.
- The assistant response appears in both Telegram and the web chat gateway.
- Send another Telegram message.
- The previous assistant response disappears from the web chat gateway.
- The next response behaves as if the previous assistant reply never happened.
Node also pegs at or near 100% CPU during the repair/replay work.
Root cause
src/agents/session-file-repair.ts currently treats a session file ending in a non-tool-call assistant message as corrupted and trims trailing assistant entries from disk.
That is not safe for durable transcript history. A successful assistant reply is normally the final transcript entry until the next user message arrives.
Provider-specific assistant prefill stripping should happen only when constructing outbound model requests, not by mutating the persisted session transcript.
Local fix
Remove durable-history trimming of trailing assistant entries from repairSessionFileIfNeeded.
The repair function should still repair malformed JSONL lines, blank user messages, and empty error assistant messages, but it should preserve delivered assistant responses.
Locally validated by changing the session repair tests from "trim trailing assistant messages" to "preserve trailing assistant messages".
Touched files:
src/agents/session-file-repair.ts
src/agents/session-file-repair.test.ts
Verification
pnpm vitest run src/agents/session-file-repair.test.ts
pnpm build
- Restarted gateway
- Sent Telegram messages with dashboard open
- Previous assistant response remained in web chat and in context
- Gateway CPU settled after startup/history scan
Notes
The outbound path can still strip assistant-prefill turns per request where needed. The key distinction is that durable channel/session history should not be rewritten to remove already-delivered assistant replies.
Summary
When using Telegram with the web chat gateway open, each new Telegram message can trigger session repair that deletes the previous assistant response from the durable session transcript. The response remains visible in Telegram because it was already delivered, but it disappears from the web chat gateway and is no longer available as conversation history for the next model turn.
Observed behavior
Node also pegs at or near 100% CPU during the repair/replay work.
Root cause
src/agents/session-file-repair.tscurrently treats a session file ending in a non-tool-call assistant message as corrupted and trims trailing assistant entries from disk.That is not safe for durable transcript history. A successful assistant reply is normally the final transcript entry until the next user message arrives.
Provider-specific assistant prefill stripping should happen only when constructing outbound model requests, not by mutating the persisted session transcript.
Local fix
Remove durable-history trimming of trailing assistant entries from
repairSessionFileIfNeeded.The repair function should still repair malformed JSONL lines, blank user messages, and empty error assistant messages, but it should preserve delivered assistant responses.
Locally validated by changing the session repair tests from "trim trailing assistant messages" to "preserve trailing assistant messages".
Touched files:
src/agents/session-file-repair.tssrc/agents/session-file-repair.test.tsVerification
pnpm vitest run src/agents/session-file-repair.test.tspnpm buildNotes
The outbound path can still strip assistant-prefill turns per request where needed. The key distinction is that durable channel/session history should not be rewritten to remove already-delivered assistant replies.