Skip to content

fix(db): preserve message timestamps across fork/compress/branch (#28841)#32522

Open
Jiahui-Gu wants to merge 1 commit into
NousResearch:mainfrom
Jiahui-Gu:fix/message-timestamp-preservation-28841
Open

fix(db): preserve message timestamps across fork/compress/branch (#28841)#32522
Jiahui-Gu wants to merge 1 commit into
NousResearch:mainfrom
Jiahui-Gu:fix/message-timestamp-preservation-28841

Conversation

@Jiahui-Gu

Copy link
Copy Markdown
Contributor

Fixes #28841.

Summary

  • SessionDB.append_message now accepts an optional timestamp: float. When omitted it falls back to time.time() (existing behavior).
  • SessionDB.replace_messages reads msg["timestamp"] per row and only synthesizes a monotonically-increasing now_ts for messages that lack one. This stops /compress, /retry and /undo from rewriting wall-clock times to the rewrite moment.
  • Six call sites that copy/replay messages (run_agent.py, cli.py, gateway/run.py, gateway/session.py, gateway/mirror.py, tui_gateway/server.py) now forward msg.get("timestamp") so /branch and mirror writes preserve origin times.

Tests

Added TestMessageTimestampPreservation in tests/test_hermes_state.py (8 tests): explicit timestamp, default-now fallback, 0.0 epoch is honored, replace_messages round-trip preserves, fallback assigns distinct increasing times, mixed explicit/missing, fork-chain preservation, and repeated-compress no-drift.

Test plan

  • pytest tests/test_hermes_state.py::TestMessageTimestampPreservation
  • Manual: start a conversation, /compress, query SELECT timestamp FROM messages — original times retained.
  • Manual: /branch — child session keeps parent timestamps.

@alt-glitch

Copy link
Copy Markdown
Collaborator

Duplicate of #28840 which already fixes the same timestamp preservation bug (#28841) with the same approach (optional timestamp in append_message, per-row reading in replace_messages).

@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/agent Core agent loop, run_agent.py, prompt builder comp/cli CLI entry point, hermes_cli/, setup wizard comp/gateway Gateway runner, session dispatch, delivery comp/tui Terminal UI (ui-tui/ + tui_gateway/) duplicate This issue or pull request already exists labels May 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent loop, run_agent.py, prompt builder comp/cli CLI entry point, hermes_cli/, setup wizard comp/gateway Gateway runner, session dispatch, delivery comp/tui Terminal UI (ui-tui/ + tui_gateway/) duplicate This issue or pull request already exists P2 Medium — degraded but workaround exists type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

messages.timestamp is always DB write-time, lost during fork/compress/branch

3 participants