← Back to PRs

#15493: feat(telegram): session state memory for diagnostic continuity

by tangcruz open 2026-02-13 14:40 View on GitHub →
channel: telegram stale size: M
## Summary Add session state memory system for Telegram to maintain diagnostic context across messages. Solves the "diagnostic amnesia" problem where agents lose context when waiting for user confirmation in multi-step troubleshooting. ## What Changed - `src/telegram/bot-message-context.ts`: Add `injectSessionStateContext()` function that reads state markers from session history and injects active task context into incoming messages - `src/telegram/feedback-integration.ts`: Auto-memory feedback button integration (useful/not-useful/record/context) - `src/telegram/feedback-patch.ts`: Delivery integration for feedback buttons ## How It Works 1. When agent starts a diagnostic task, state markers are written to session JSONL 2. When user replies, `injectSessionStateContext()` parses markers and injects context with active tasks, steps, and waiting status 3. Agent sees full context and continues seamlessly instead of starting from scratch ## Testing - Built successfully with pnpm build - Tested locally with simulated session files - Non-breaking: only injects context when state markers exist ## Notes - B-2 implementation (state messages in session history) - Backward compatible: agents without state markers work normally - Works with external Auto-Memory skill for full task management <!-- greptile_comment --> <h2>Greptile Overview</h2> <h3>Greptile Summary</h3> This PR extends the Telegram inbound context builder to prepend a “session state” block by scanning the per-session JSONL history for `[INTERNAL_STATE]` markers, and adds a new `feedback-integration.ts` helper for attaching Auto-Memory feedback inline buttons and handling callback clicks. Key integration points: - `src/telegram/bot-message-context.ts` now calls `injectSessionStateContext(sessionKey, storePath)` and prepends the returned text to the inbound envelope. - `src/telegram/feedback-integration.ts` introduces helper functions to decide when to attach inline buttons, to encode callback metadata, and to record/acknowledge feedback callbacks. Issues to fix before merge: - `injectSessionStateContext()` performs synchronous filesystem reads for every inbound message, which can block the Node event loop under large session logs or slow disks. - Feedback callbacks won’t parse for normal session keys because callback_data encoding includes `:` while the parser forbids it, causing feedback to silently no-op. <h3>Confidence Score: 2/5</h3> - This PR has functional issues that will cause features to not work as intended in common cases. - Session-state injection currently uses sync fs reads on the hot path, which can degrade responsiveness, and the feedback callback parser cannot handle real session keys containing colons so feedback handling won’t trigger for typical Telegram sessions. - src/telegram/bot-message-context.ts, src/telegram/feedback-integration.ts <sub>Last reviewed commit: 14c5bef</sub> <!-- greptile_other_comments_section --> <!-- /greptile_comment -->

Most Similar PRs