Skip to content

fix: serialize Telegram card sends against in-flight chat turns, surface session reset (#281) - #775

Merged
getappz merged 2 commits into
masterfrom
task/281-telegram-bot-has-no-conversational-sessi
Sep 18, 2026
Merged

getappz merged 2 commits into
masterfrom
task/281-telegram-bot-has-no-conversational-sessi

Conversation

@getappz

@getappz getappz commented Sep 18, 2026 •

Copy link
Copy Markdown
Owner

Summary

Item #281 reported two distinct problems in the Telegram bot's inbound handling:

  1. Plan/PR-approval cards were getting interleaved into unrelated conversational replies, because notify_human_gate/request_channel_approval (in src/supervisor/notify.rs) sent their Telegram API calls with no ordering against chat_channel::run_chat_turn's reply to the same chat.
  2. When a chat's resumed agent session turned out to be stale and fell back to a brand-new zero-history session, the reply carried no indication of that — so a user's "Go ahead" / "Approved" answered by a session with no memory of the pending request read as the bot ignoring it, not as having genuinely forgotten.

Changes

  • src/chat_channel.rs: chat_turn_lock is now pub(crate) so notify.rs can take the same per-chat lock run_chat_turn holds for its whole turn. Also adds prefix_session_reset_note, which prepends [my memory of this chat was reset -- replying fresh, with no earlier context] to a reply whenever the turn detected a stale resumed session (item chore: release #159's failure mode) and retried fresh.
  • src/supervisor/notify.rs: notify_human_gate and request_channel_approval (shared by notify_pr_approval_gate and notify_plan_approval_gate) now take chat_turn_lock before sending, so a side-channel card can no longer land interleaved with an in-flight chat reply to the same chat.

Test plan

  • cargo build --bin agentflare
  • cargo test --bin agentflare chat_channel:: (new test: prefix_session_reset_note_prepends_context_loss_note)
  • cargo test --bin agentflare supervisor:: (94 tests, all passing)
  • cargo clippy --bin agentflare clean on both changed files
  • cargo fmt --check clean

Note: a full-repo cargo test --bin agentflare run in this environment hits one unrelated failure, mcp_prompts::tests::optimize_review_returns_full_skill_body, caused by the sandbox mounting ~/.local/state read-only (that test's set_active() call has no test-time state-dir override) -- confirmed unrelated to this change by reproducing the same read-only-fs failure with a direct echo > ~/.local/state/... write, independent of any code change.

Summary by CodeRabbit

  • New Features

    • Added a clear notice when a stale chat session is discarded and restarted, informing users that previous context was lost.
  • Bug Fixes

    • Improved Telegram message sequencing so notifications and chat replies are delivered in the correct order without interleaving.
    • Ensured notification delivery continues even when an internal synchronization lock encounters an error.

…t turns, surface a session reset (item #281)

A plan-approval or PR-approval card is now sent under the same per-chat
turn lock run_chat_turn holds, so it can no longer land interleaved with
an unrelated conversational reply to the same chat. Separately, when a
chat turn's resumed agent session turns out to be stale and falls back
to a brand-new zero-history one, the reply is now prefixed with a note
explaining the bot has lost context -- instead of silently answering a
"yes"/"approved" as if it understood what it refers to.

Agentflare-Agent: claude-code
Agentflare-Branch: task/281-telegram-bot-has-no-conversational-sessi
Agentflare-Item: 281
Agentflare-Session: 673e5d10-e8d5-4a5b-b5d3-2d76b468aeab
@coderabbitai

coderabbitai Bot commented Sep 18, 2026 •

Copy link
Copy Markdown

Review Change StackReview Change Stack

Warning

Review limit reached

Next included review available in 51 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available. Your 60 included PR review attempts over the past 7 days set your current allowance at 1 review per hour.

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Essentials

Run ID: 6aa435c9-0141-4031-80be-05efba601d0d

📥 Commits

Reviewing files that changed from the base of the PR and between c31c464 and 1ec52b2.

📒 Files selected for processing (2)
  • src/chat_channel.rs
  • src/supervisor/notify.rs
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

Comment @coderabbitai help to get the list of available commands.

@getappz

getappz commented Sep 18, 2026

Copy link
Copy Markdown
Owner Author

Tracking this PR for automated review (flared:51bb8de6c33b).

@getappz
getappz merged commit 1e735f4 into master Sep 18, 2026
16 checks passed
@getappz
getappz deleted the task/281-telegram-bot-has-no-conversational-sessi branch September 18, 2026 10:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant