Skip to content

Telegram session repair deletes previous assistant response from transcript #76329

@Countermarch

Description

@Countermarch

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

  1. Send a Telegram message.
  2. OpenClaw/Jeeves responds.
  3. The assistant response appears in both Telegram and the web chat gateway.
  4. Send another Telegram message.
  5. The previous assistant response disappears from the web chat gateway.
  6. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions