fix(gateway): always inject reply context into skill and chat prompts - #11581
Closed
el-analista wants to merge 1 commit into
Closed
fix(gateway): always inject reply context into skill and chat prompts#11581el-analista wants to merge 1 commit into
el-analista wants to merge 1 commit into
Conversation
The `[Replying to: ...]` marker was suppressed whenever the replied-to text happened to match something already in chat history. In practice this meant that replying to the immediately preceding assistant message (e.g. a cron response) always skipped the marker, leaving the LLM to guess the referent from recency bias. - Drop the `found_in_history` gate; always inject the marker. - Widen the snippet to the full reply body (cap 4000 chars, truncation marker appended when over). - For skill-slash commands, also inline the replied-to body directly into `user_instruction` so the anchor sits adjacent to the user's ask (the skill payload otherwise pushes the top-level marker far from the instruction). - Include an explicit disambiguation line telling the LLM that phrases like "this skill" refer to the replied-to message, not earlier conversation turns. Verified end-to-end on Telegram: replying to a cron response with `/claude_code improve this skill ...` now correctly anchors on the replied-to skill instead of drifting to recent chat topics.
el-analista
force-pushed
the
fix/telegram-reply-context
branch
from
April 17, 2026 12:29
971a14a to
bfe519e
Compare
Collaborator
Contributor
Author
|
Closing — the core fix (dropping the |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When a user replied to a previous message in a chat platform (e.g. Telegram), the gateway was suppressing the
[Replying to: ...]anchor whenever the replied-to text matched anything already in chat history. In practice, replying to the immediately preceding assistant message always skipped the marker, leaving the LLM to pick the referent from recency bias and causing it to act on the wrong subject.Concrete failure: replying to a
Cronjob Response: Hermes Daily System Auditmessage with/claude_code improve this skill ...would consistently send the model off to "improve the deep-research skill" (whatever had last been discussed), not the audit skill the user was actually pointing at.Changes —
gateway/run.pyfound_in_historygate. Presence in history ≠ being the referent of a reply. The marker is pointer information; always inject it.…[truncated]marker appended when over). Telegram's Bot API already provides the complete replied-totext/caption, so no adapter changes are needed; the runner stays platform-agnostic.user_instruction. The skill payload (full SKILL.md content) otherwise sits between the top-level marker and the user's ask, separating the anchor from the instruction by thousands of tokens.Both code paths (skill-command dispatcher at ~3229 and general inbound prep at ~3418) now use the same 4000-char cap logic. Mild duplication, intentional — the two sites inject at different points in the final prompt for prompt-structure reasons. Could be factored into a helper in a follow-up.
Test plan
python -c "import ast; ast.parse(open('gateway/run.py').read())"Cronjob Responsemessage with/claude_code improve this skill ...— LLM now correctly anchors on the replied-to audit skill.sessions/session_*.json).[Replying to message N: ...]block verbatim).