Skip to content

Filter low-value CLI agent sessions#1587

Closed
franksong2702 wants to merge 3 commits into
nesquena:masterfrom
franksong2702:franksong2702/1013-cli-session-pr3-rebased
Closed

Filter low-value CLI agent sessions#1587
franksong2702 wants to merge 3 commits into
nesquena:masterfrom
franksong2702:franksong2702/1013-cli-session-pr3-rebased

Conversation

@franksong2702
Copy link
Copy Markdown
Contributor

@franksong2702 franksong2702 commented May 4, 2026

Thinking Path

  • Clarify source-aware UX for Show agent sessions #1013 is about making Show Agent Sessions useful rather than noisy.
  • The earlier source-normalization and messaging-channel handoff slices made Weixin/Telegram/other channel sessions safer to show.
  • CLI sessions have a different product shape: users often do not title them, one-off test runs are common, and WebUI should not imply that it owns the original Hermes Agent CLI history.
  • The bug was that WebUI treated every importable CLI row as sidebar-worthy, then exposed full WebUI clone/delete actions once the row appeared.
  • This PR keeps meaningful CLI sessions visible while filtering obvious low-value/default one-off rows, and makes CLI-origin menus conservative.

Refs #1013.

What Changed

  • Added source-aware CLI visibility rules for importable agent sessions:
    • hide empty CLI rows
    • hide default/untitled CLI rows with fewer than 2 user turns
    • keep explicitly titled CLI sessions
    • keep compression-lineage CLI sessions, because they represent long-running conversations
  • Apply the CLI visible cap after filtering, so low-value rows do not consume the window.
  • Preserve the messaging-channel projection that shipped after Add messaging channel handoff summaries #1404, so Weixin/Telegram sessions remain deduplicated by their current channel rules.
  • Treat true CLI-origin sessions as external/imported sessions in the sidebar action menu:
    • keep pin, move, archive/restore
    • hide duplicate/delete
  • Add user-turn counts to compact session payloads so the filtering rule is based on actual user turns instead of raw assistant/tool/internal message count.
  • Hardened compatibility with older messages table fixtures that do not have a role column, so the CLI projection degrades to message-count based filtering instead of failing the whole list.
  • Added a short changelog entry for the user-visible behavior change.

PR2 Cross-check

This PR is intentionally built on top of the messaging-channel handoff work from #1404. It does not reimplement or weaken that layer:

  • Messaging sessions still bypass the new CLI visibility filter because session_source == "messaging" is explicitly treated as non-CLI.
  • Weixin/Telegram dedup still happens through the existing messaging identity projection, so distinct chats stay separate while stale continuation/reset segments remain hidden.
  • The Add messaging channel handoff summaries #1404 refresh/compaction safeguards remain in place: messaging state.db metadata wins over stale local snapshots, import refresh only extends safe prefixes, and shorter/stale refresh payloads do not overwrite active transcripts.
  • CLI compression chains are preserved by this PR's own filter because compression-lineage CLI sessions are treated as meaningful even when their generated title is still Cli Session. This is now covered by test_default_title_cli_compression_chain_is_kept_by_lineage.

CLI Compression Boundary

WebUI does not try to distinguish whether a CLI continuation came from auto-compression or a manual /compress action. At this layer, both are handled through the same Hermes Agent state.db lineage contract: parent_session_id plus end_reason='compression' or cli_close.

When that lineage exists, this PR collapses the chain into one logical sidebar row and points import/navigation at the latest importable tip segment, so the user continues from the current compressed context instead of reopening the stale root segment.

If a future Hermes Agent path creates a compressed continuation without recording that lineage metadata, WebUI cannot infer the chain safely from title/time alone. That would need to be fixed at the Hermes Agent/source-of-truth layer rather than guessed in this sidebar filter.

Why It Matters

  • Opening Show Agent Sessions should not flood the sidebar with old one-off CLI experiments.
  • Meaningful CLI conversations still remain available for import and continuation.
  • The menu now avoids destructive or misleading actions for sessions whose source of truth is outside WebUI.
  • This keeps the PR focused on correctness and safety. CLI default-title polish, such as derived display titles, should be handled as a separate follow-up instead of keeping Clarify source-aware UX for Show agent sessions #1013 open indefinitely.

Verification

  • python -m py_compile api/agent_sessions.py api/models.py api/routes.py tests/test_gateway_sync.py tests/test_session_lineage_collapse.py tests/test_1466_sidebar_cancel_clarify.py tests/test_cron_session_title.py tests/test_465_session_branching.py
  • node --check static/sessions.js
  • pytest -q tests/test_gateway_sync.py tests/test_session_lineage_collapse.py tests/test_1466_sidebar_cancel_clarify.py -> 59 passed
  • pytest -q tests/test_cron_session_title.py tests/test_465_session_branching.py -> 26 passed
  • git diff --check
  • Manual validation on a real local WebUI state:
    • Weixin Session: 1 visible
    • Telegram Session: 2 visible
    • Cli Session: 3 visible
    • CLI-origin menu hides duplicate/delete and keeps conservative actions

Risks / Follow-ups

  • This does not rename or retitle default CLI sessions. Multiple meaningful CLI sessions may still appear as Cli Session; a deterministic derived display-title polish can be a separate follow-up.
  • This does not implement real-time two-client synchronization between Hermes CLI and WebUI.
  • This does not delete or mutate hidden Hermes Agent CLI history; it only changes WebUI sidebar projection.

Model Used

  • OpenAI GPT-5.5 via Codex coordinator.
  • OpenAI gpt-5.3-codex-spark worker for the focused implementation pass.

@franksong2702 franksong2702 marked this pull request as ready for review May 4, 2026 03:07
@franksong2702 franksong2702 marked this pull request as draft May 4, 2026 03:10
@franksong2702
Copy link
Copy Markdown
Contributor Author

Put it in draft status for now to review session compaction handle. will update soon

@nesquena nesquena added the hold label May 4, 2026
@franksong2702 franksong2702 marked this pull request as ready for review May 4, 2026 07:23
@franksong2702 franksong2702 force-pushed the franksong2702/1013-cli-session-pr3-rebased branch 2 times, most recently from d6c05f9 to 00dbc44 Compare May 4, 2026 23:08
@franksong2702
Copy link
Copy Markdown
Contributor Author

Rebased this PR onto latest origin/master (v0.50.296, e6cf801) after the stage-296 release batch.

Conflict notes:

  • Kept the current profile-scoping flow in /api/sessions and applied the CLI visibility cap after profile scoping + messaging dedup.
  • Kept the PR's Unreleased changelog note above the latest released entries.

Verification after rebase:

python3 -m py_compile api/agent_sessions.py api/models.py api/routes.py
node --check static/sessions.js
/Users/xuefusong/hermes-webui/.venv_test/bin/python -m pytest \
  tests/test_gateway_sync.py \
  tests/test_cron_session_title.py \
  tests/test_1466_sidebar_cancel_clarify.py -q
# 61 passed in 10.01s

git diff --check

@franksong2702 franksong2702 force-pushed the franksong2702/1013-cli-session-pr3-rebased branch from 00dbc44 to 5c803c4 Compare May 4, 2026 23:18
@franksong2702
Copy link
Copy Markdown
Contributor Author

Rebased #1587 onto latest origin/master (v0.50.297 / 134433f) and resolved the overlap with the new profile-scoping session-list path.

Rebase note:

  • kept upstream profile scoping as the authoritative first filter
  • kept messaging-session dedupe inside the scoped result
  • applied the CLI visible cap after profile scoping / messaging dedupe
  • kept the PR's Unreleased changelog note above the latest release block

Verification:

  • python3 -m py_compile api/agent_sessions.py api/models.py api/routes.py
  • node --check static/sessions.js
  • pytest tests/test_gateway_sync.py tests/test_cron_session_title.py tests/test_1466_sidebar_cancel_clarify.py -q -> 61 passed in 9.43s

Note: a first local test attempt with system Python 3.9 failed during collection because current WebUI code uses Python 3.10+ union syntax. The verification above uses the project test venv.

@nesquena nesquena removed the hold label May 4, 2026
@nesquena-hermes
Copy link
Copy Markdown
Collaborator

Thanks for the back-to-back rebases against master (v0.50.296v0.50.297) and the explicit conflict notes on each one — the call to keep upstream profile-scoping as the authoritative first filter, then apply the messaging dedup, then the CLI visibility cap, reads correctly given the sequencing changes that landed in stage-296/297.

Quick status on what I see on the branch (origin/pull/1587/head):

  • Diff stat: +298 / -11 across 8 files — api/agent_sessions.py and api/routes.py carry most of the logic, with regression coverage in tests/test_1466_sidebar_cancel_clarify.py, tests/test_cron_session_title.py, and tests/test_gateway_sync.py.
  • The Unreleased CHANGELOG entry is correctly stacked above the released-stamp blocks, so it won't collide with the release-tagging script on the next stamp.
  • No new contributor-side commits were needed — the only post-rebase activity is your own comments, so the branch is in a reviewable state.

Queued for maintainer review on the next pass. No action needed from you right now; the rebase notes give enough context to land cleanly.

@nesquena-hermes
Copy link
Copy Markdown
Collaborator

Thanks @franksong2702 — this PR is currently in CONFLICTING state against master (a few PRs that touch session-list rendering / messaging-channel projection have shipped since you opened it). Could you rebase onto current master and force-push? Once it's clean we can pick it up in the next batch.

If a rebase isn't easy from your side just let me know and I can take it on with Co-authored-by: attribution preserved.

@nesquena-hermes
Copy link
Copy Markdown
Collaborator

Closed by the v0.51.2 release in PR #1682 (merged at fcc8328, deployed to production). Thanks for the contribution!

Live on production: https://github.com/nesquena/hermes-webui/releases/tag/v0.51.2

🚀

nesquena-hermes pushed a commit to Michaelyklam/hermes-webui that referenced this pull request May 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants