Skip to content

feat(gateway): bring /undo [N] to messaging platforms (parity with CLI/TUI)#36699

Merged
teknium1 merged 1 commit into
mainfrom
hermes/gw-undo-parity
Jun 1, 2026
Merged

feat(gateway): bring /undo [N] to messaging platforms (parity with CLI/TUI)#36699
teknium1 merged 1 commit into
mainfrom
hermes/gw-undo-parity

Conversation

@teknium1

@teknium1 teknium1 commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

Summary

/undo [N] now works the same on every messaging platform as it does in the CLI/TUI. The gateway command was wired into all platforms but still ran the old single-turn hard-truncate — this brings it to parity.

Changes

  • gateway/session.py: new SessionStore.rewind_session(session_id, n) wraps SessionDB.rewind_to_message — soft-deletes the truncated rows (active=0, kept for audit, hidden from re-prompts and search) instead of hard-rewriting the transcript. load_transcript already returns the active-only view.
  • gateway/run.py: _handle_undo_command parses [N], calls rewind_session, evicts the cached agent (so the next turn rebuilds from the truncated transcript and memory caches refresh — the gateway's equivalent of the CLI's in-place history surgery), and echoes the backed-up message text so the user can copy/edit and resend. The destructive-confirm detail is count-aware.
  • locales: undo.removed gains {turns}; new undo.invalid_count — all 16 languages.
  • tests: tests/gateway/test_undo_rewind_session.py (6 cases).

Why echo instead of prefill

Messaging platforms have no editable composer to pre-fill (unlike CLI/TUI), so the gateway echoes the backed-up message text in its reply with "Copy/edit the text above and send it to re-prompt from here." Same soft-delete + N-turn semantics, platform-appropriate UX.

Behavior

Input Effect
/undo back up 1 user turn, echo its text
/undo 3 back up 3 user turns
/undo 99 clamps to the oldest user turn
/undo abc "Invalid count" error

Validation

  • 6 gateway rewind_session tests + 261 across the full related suites (test_undo_command, test_hermes_state, test_memory_session_switch, test_i18n).
  • E2E: soft-delete (6 rows → 2 active), N-turn back-up, default n=1, empty-session → None, clamp-to-oldest.
  • i18n render verified for EN/ZH/FR removed + invalid_count (no format errors, all placeholders resolve).

Follow-up to the merged CLI/TUI /undo [N] work (#21910).

Infographic

undo-gateway-trigger-burst

…I/TUI)

Gateway /undo was wired into every platform but still ran the old
single-turn hard-truncate. Now it matches the CLI/TUI: /undo [N] backs
up N user turns (default 1, clamps to oldest), soft-deletes the
truncated rows on disk (active=0, kept for audit, hidden from re-prompts
and search) via SessionDB.rewind_to_message, evicts the cached agent so
the next turn rebuilds from the active-only transcript (the gateway's
equivalent of the CLI's in-place history surgery + memory invalidation),
and echoes the backed-up message text so the user can copy/edit and
resend — platforms have no editable composer to prefill.

- gateway/session.py: SessionStore.rewind_session(session_id, n) wraps
  the soft-delete primitive; load_transcript already returns active-only
- gateway/run.py: _handle_undo_command parses [N], calls rewind_session,
  evicts the agent, echoes target text; confirm-prompt detail is count-aware
- locales: undo.removed gains {turns}; new undo.invalid_count, all 16 langs
- tests: tests/gateway/test_undo_rewind_session.py (6 cases)
@github-actions

github-actions Bot commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

🔎 Lint report: hermes/gw-undo-parity vs origin/main

ruff

Total: 0 on HEAD, 0 on base (➖ 0)

🆕 New issues: none

✅ Fixed issues: none

Unchanged: 0 pre-existing issues carried over.

ty (type checker)

Total: 9578 on HEAD, 9577 on base (🆕 +1)

🆕 New issues (1):

Rule Count
unresolved-import 1
First entries
tests/gateway/test_undo_rewind_session.py:13: [unresolved-import] unresolved-import: Cannot resolve imported module `pytest`

✅ Fixed issues: none

Unchanged: 4962 pre-existing issues carried over.

Diagnostics are surfaced as warnings — this check never fails the build.

@alt-glitch alt-glitch added type/feature New feature or request comp/gateway Gateway runner, session dispatch, delivery P3 Low — cosmetic, nice to have labels Jun 1, 2026
@teknium1 teknium1 merged commit 0622a70 into main Jun 1, 2026
23 checks passed
@teknium1 teknium1 deleted the hermes/gw-undo-parity branch June 1, 2026 09:04
JoeKowal pushed a commit to JoeKowal/hermes-agent that referenced this pull request Jun 4, 2026
…I/TUI) (NousResearch#36699)

Gateway /undo was wired into every platform but still ran the old
single-turn hard-truncate. Now it matches the CLI/TUI: /undo [N] backs
up N user turns (default 1, clamps to oldest), soft-deletes the
truncated rows on disk (active=0, kept for audit, hidden from re-prompts
and search) via SessionDB.rewind_to_message, evicts the cached agent so
the next turn rebuilds from the active-only transcript (the gateway's
equivalent of the CLI's in-place history surgery + memory invalidation),
and echoes the backed-up message text so the user can copy/edit and
resend — platforms have no editable composer to prefill.

- gateway/session.py: SessionStore.rewind_session(session_id, n) wraps
  the soft-delete primitive; load_transcript already returns active-only
- gateway/run.py: _handle_undo_command parses [N], calls rewind_session,
  evicts the agent, echoes target text; confirm-prompt detail is count-aware
- locales: undo.removed gains {turns}; new undo.invalid_count, all 16 langs
- tests: tests/gateway/test_undo_rewind_session.py (6 cases)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/gateway Gateway runner, session dispatch, delivery P3 Low — cosmetic, nice to have type/feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants