#15493: feat(telegram): session state memory for diagnostic continuity
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
#14243: fix: fire session-memory hook on auto-resets + topic-aware memory p...
by TheDude135 · 2026-02-11
79.5%
#15684: fix(telegram): persist relative session transcript paths
by Jdo300 · 2026-02-13
77.7%
#11273: fix(telegram): prevent status command crash during thinking
by avirweb · 2026-02-07
76.9%
#7751: Telegram: persist inbound history (SQLite) + add read action
by welttowelt · 2026-02-03
76.5%
#8166: fix(telegram): lifecycle fixes for duplicate messages and auto-reco...
by cheenu1092-oss · 2026-02-03
76.4%
#9012: fix(memory): resilient flush for large sessions [AI-assisted]
by cheenu1092-oss · 2026-02-04
76.1%
#12075: feat(browser): session-aware context isolation for multi-agent brow...
by xiaoyaner0201 · 2026-02-08
76.1%
#9085: fix: improve stability for terminated responses and telegram retries
by vladdick88 · 2026-02-04
75.7%
#3368: fix: sessions navigation, DM thread display, and DM thread delivery...
by Lukavyi · 2026-01-28
75.4%
#16061: fix(sessions): tolerate invalid sessionFile metadata
by haoyifan · 2026-02-14
75.4%