You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Gateway users can now see useful same-chat history in /sessions and bare or numeric-fallback /resume, even when newer sessions from other chats on the same platform would previously consume the entire database fetch window.
The normal gateway path now applies the caller's indexed session_key before the SQL limit. Compression projection, current-session exclusion, and the existing _resume_row_visible and _resume_target_allowed authorisation checks remain in place. Telegram commands use the same recovered topic lane as normal message routing, while explicit authorised cross-lane resumes keep a compressed lineage on one routing peer.
This is preferable to increasing the source-wide over-fetch cap because a larger fixed window only postpones starvation. It does not migrate or backfill session data, and admin-only widening retains its existing behaviour.
Session-settled decisions carried from planning: exact lane filtering before limiting (user-approved); retaining post-query IDOR checks (user-directed); fixing both listing paths (user-approved); and avoiding migration while preserving one routing peer per moved compression lineage (user-directed).
PR #62138 overlaps only on the optional list_sessions_rich(session_key=...) primitive. If it lands first, this branch can rebase and drop that small overlapping hunk without changing the gateway fix.
Type of Change
🐛 Bug fix (non-breaking change that fixes an issue)
✨ New feature (non-breaking change that adds functionality)
🔒 Security fix
📝 Documentation update
✅ Tests (adding or improving test coverage)
♻️ Refactor (no behavior change)
🎯 New skill (bundled or hub)
Changes Made
hermes_state.py: add indexed exact-lane filtering before result limiting, and keep compression ancestors aligned during an explicit routing move.
hermes_cli/session_listing.py: expose exact-lane selection to shared session-listing policy without changing callers that omit it.
gateway/slash_commands.py and gateway/session.py: scope both gateway list entry points, recover Telegram topic lanes, preserve admin widening, and keep explicit switch metadata consistent.
Create more than 50 newer Telegram sessions under unrelated session_key values and at least 11 named roots in the caller's lane.
Run /sessions, bare /resume, /sessions full, and /sessions search <query> from the caller's lane. Verify the lists contain only exact-lane rows, retain older logical conversations, and exclude the current projected lineage where applicable.
I've updated cli-config.yaml.example if I added/changed config keys - N/A, no config changes
I've updated CONTRIBUTING.md or AGENTS.md if I changed architecture or workflows - N/A, no architecture or workflow changes
I've considered cross-platform impact (Windows, macOS) per the compatibility guide - no OS-specific runtime behaviour added; the Windows footgun scan passes
I've updated tool descriptions/schemas if I changed tool behavior - N/A, no tool schema changes
Screenshots / Logs
Affected gateway reproduction
Personal and internal session identifiers are redacted. The affected Telegram lane returned only one named session even though the database contained 15 logical roots for that lane.
Query-order visual
This is a backend listing fix with no visual surface. An anonymised read-only reproduction on the affected installation produced:
Path
Source-wide candidates
Same-lane rows left after filtering
Exact-lane page after fix
/sessions
10
1
10 prior logical conversations
bare /resume
10
2, including the current conversation
10 same-lane candidates
The database contained 77 physical rows and 15 logical roots for the affected lane; session data, reset boundaries, compression metadata, and origin metadata were intact. No live database mutation was used to validate or implement the fix.
Thanks for addressing the query-ordering bug. The premise is confirmed on current main: bare/numeric /resume limits same-platform rows before _resume_row_visible (gateway/slash_commands.py:3786-3798), and /sessions similarly limits before its post-query visibility cut (hermes_cli/session_listing.py:65-83, gateway/slash_commands.py:3983-3989).
The proposed exact session_key predicate is aligned with the existing indexed routing field (hermes_state.py:907-908) and keeps the existing authorization checks in place. I found no substantive correctness issue in the PR diff during static review. GitHub reports the branch merge state as clean against current main.
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
area/sessionsSession lifecycle, resume, persistence, historycomp/cliCLI entry point, hermes_cli/, setup wizardcomp/gatewayGateway runner, session dispatch, deliveryP2Medium — degraded but workaround existsplatform/telegramTelegram bot adaptersweeper:blast-moderateSweeper blast radius: moderate — a subsystem or single platformsweeper:risk-session-stateSweeper risk: may lose/corrupt/mis-associate session or context statetype/bugSomething isn't working
3 participants
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.
What does this PR do?
Gateway users can now see useful same-chat history in
/sessionsand bare or numeric-fallback/resume, even when newer sessions from other chats on the same platform would previously consume the entire database fetch window.The normal gateway path now applies the caller's indexed
session_keybefore the SQL limit. Compression projection, current-session exclusion, and the existing_resume_row_visibleand_resume_target_allowedauthorisation checks remain in place. Telegram commands use the same recovered topic lane as normal message routing, while explicit authorised cross-lane resumes keep a compressed lineage on one routing peer.This is preferable to increasing the source-wide over-fetch cap because a larger fixed window only postpones starvation. It does not migrate or backfill session data, and admin-only widening retains its existing behaviour.
Session-settled decisions carried from planning: exact lane filtering before limiting (user-approved); retaining post-query IDOR checks (user-directed); fixing both listing paths (user-approved); and avoiding migration while preserving one routing peer per moved compression lineage (user-directed).
Related Issue
Fixes #65500
Related: #54326
Related: #60138
Related: #62138
Related: #62278
PR #62138 overlaps only on the optional
list_sessions_rich(session_key=...)primitive. If it lands first, this branch can rebase and drop that small overlapping hunk without changing the gateway fix.Type of Change
Changes Made
hermes_state.py: add indexed exact-lane filtering before result limiting, and keep compression ancestors aligned during an explicit routing move.hermes_cli/session_listing.py: expose exact-lane selection to shared session-listing policy without changing callers that omit it.gateway/slash_commands.pyandgateway/session.py: scope both gateway list entry points, recover Telegram topic lanes, preserve admin widening, and keep explicit switch metadata consistent.tests/: cover busy same-platform installations, compression projection, current-session exclusion, full/search modes, Telegram topic recovery, admin and non-admin boundaries, null-key fail-closed behaviour, and cross-lane compressed resumes.How to Test
Create more than 50 newer Telegram sessions under unrelated
session_keyvalues and at least 11 named roots in the caller's lane.Run
/sessions, bare/resume,/sessions full, and/sessions search <query>from the caller's lane. Verify the lists contain only exact-lane rows, retain older logical conversations, and exclude the current projected lineage where applicable.Run the regression suite:
Result: 565 tests passed, 0 failed.
Checklist
Code
fix(scope):,feat(scope):, etc.)pytest tests/ -qand all tests passDocumentation & Housekeeping
docs/, docstrings) - N/A beyond affected API docstringscli-config.yaml.exampleif I added/changed config keys - N/A, no config changesCONTRIBUTING.mdorAGENTS.mdif I changed architecture or workflows - N/A, no architecture or workflow changesScreenshots / Logs
Affected gateway reproduction
Personal and internal session identifiers are redacted. The affected Telegram lane returned only one named session even though the database contained 15 logical roots for that lane.
Query-order visual
This is a backend listing fix with no visual surface. An anonymised read-only reproduction on the affected installation produced:
/sessions/resumeThe database contained 77 physical rows and 15 logical roots for the affected lane; session data, reset boundaries, compression metadata, and origin metadata were intact. No live database mutation was used to validate or implement the fix.