fix(mobile): recognize merge-into-tail compaction envelope (P0 erased/unanswered chat) - #810
Merged
Merged
Conversation
|
Caution The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased. |
IgorGanapolsky
enabled auto-merge (squash)
July 22, 2026 18:08
Greptile SummaryThis PR updates the mobile chat compaction filter to handle merge-into-tail envelopes. The main changes are:
|
| Filename | Overview |
|---|---|
| hermes-mobile/src/utils/chatCompactionHandoff.ts | Adds merge-into-tail envelope detection and splitting while preserving real chat content and hiding scaffold text. |
| hermes-mobile/src/tests/chatCompactionHandoff.test.ts | Adds regression tests for merge-into-tail compaction handoff display behavior. |
Reviews (1): Last reviewed commit: "fix(mobile): recognize merge-into-tail c..." | Re-trigger Greptile
IgorGanapolsky
force-pushed
the
fix/chat-compaction-prior-context-20260722
branch
from
July 22, 2026 18:18
2dc757a to
9e103e5
Compare
…/unanswered chat)
Root cause of Igor's report ('Why we made zero dollars? #7' thread): the
gateway's ~/.hermes/hermes-agent agent/context_compressor.py has a
merge-into-tail compaction path (_MERGED_PRIOR_CONTEXT_HEADER /
_MERGED_SUMMARY_DELIMITER) used when head/tail role alternation would
otherwise collide. It wraps the real preserved turn in
'[PRIOR CONTEXT — for reference only; not a new message]' /
'[END OF PRIOR CONTEXT — COMPACTION SUMMARY BELOW]' before the compaction
summary scaffold. hermes-mobile's chatCompactionHandoff.ts only recognized
the standalone '[CONTEXT COMPACTION — REFERENCE ONLY]' prefix, so this
envelope rendered as a raw, scary wall of scaffold text with the user's
real turn buried and invisible inside it -- looking exactly like erased
input with no answer.
Fix: isContextCompactionHandoff / splitCompactionHandoff now detect the
merge-into-tail envelope, extract the real preserved turn as the visible
message, and hide the summary scaffold from the transcript -- the same
mobile-display-SSOT pattern as the #777 cron-delivery-scaffolding filter.
A malformed/truncated envelope (missing delimiter) is hidden rather than
shown raw. An envelope wrapping empty real content is dropped entirely
so it never renders as a scary empty wall.
Verification:
- Focused: 13/13 new chatCompactionHandoff cases (merge-into-tail detect/
extract/empty-drop/malformed-hide/prepareMessagesForDisplay), 5 related
suites 78/78 green.
- Full: 223 suites / 1969 tests green (1 pre-existing unrelated skip).
- tsc --noEmit clean.
Co-authored-by: Cursor <cursoragent@cursor.com>
IgorGanapolsky
force-pushed
the
fix/chat-compaction-prior-context-20260722
branch
from
July 22, 2026 18:52
19e03c9 to
3fd1920
Compare
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.
Root cause
Igor reported Hermes Mobile "erasing inputs and not answering" on thread "Why we made zero dollars? #7" (screenshot showed a raw wall of
[PRIOR CONTEXT — for reference only...]/[END OF PRIOR CONTEXT — COMPACTION SUMMARY BELOW]/[CONTEXT COMPACTION — REFERENCE ONLY]text with an empty composer).Traced to the gateway agent (
~/.hermes/hermes-agent,agent/context_compressor.py): when compaction needs to insert a summary but head/tail role alternation would collide, it uses a merge-into-tail path (_MERGED_PRIOR_CONTEXT_HEADER/_MERGED_SUMMARY_DELIMITER) that wraps the REAL preserved turn (often the user's actual next message, or an empty tail message) like this:hermes-mobile/src/utils/chatCompactionHandoff.tsonly recognized the standalone[CONTEXT COMPACTION — REFERENCE ONLY]prefix (added for #123/#164/#186). It never learned this merge-into-tail envelope, soisContextCompactionHandoff/splitCompactionHandoffboth fell through and the raw scaffold rendered unfiltered in the chat transcript — with the real turn buried and invisible inside it. That is the "erased input" illusion, and (per the compressor's own prompt engineering comments, #11475/#14521) is also a plausible contributor to weak-model non-answers when this format leaks into the prompt unexpectedly.Fix
chatCompactionHandoff.ts:isContextCompactionHandoffnow also matches the[PRIOR CONTEXT — for reference only; not a new message]header.splitCompactionHandoffextracts the real preserved turn (between the header and the delimiter) asremainder, and hides everything from the delimiter onward assummary— mirroring the Python side's own_is_context_summary_content/_strip_summary_prefixhandling of the same envelope.This flows through the existing
prepareMessagesForDisplay→stripCompactionHandoffsFromMessagespipeline already wired intoChatScreen.tsx, and reuses the exact SSOT filtering pattern already shipped for the #777 cron-delivery-scaffolding filter. The existing "Start fresh chat" CTA (lastTurnIsCompactionStall/shouldAutoOfferFreshOnCompactionStall, already onmain) now also sees through this envelope correctly.Scope note
Investigation also found PR #795 (merged same day) already fixed partial-history reconciliation, and PR #777 already established the scaffold-hiding pattern this PR extends. No
ChatScreen.tsx/chatMessageDisplay.tsedits were needed — the fix is fully contained in the mobile display SSOT (chatCompactionHandoff.ts), per the mission's "filter on mobile display SSOT" instruction. No Chrome/computer-use was used — CLI/git/Jest only.Verification
chatCompactionHandoffcases (merge-into-tail detect / extract / empty-drop / malformed-hide /prepareMessagesForDisplay).chatMessageDisplay,sessionTokenGuards,emptyStreamReplyRecovery,streamAssistantText,chatCompactionHandoff).tsc --noEmitclean.Made with Cursor