-
Notifications
You must be signed in to change notification settings - Fork 52.8k
fix(dashboard): show full session history safely #59585
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
proCaj
wants to merge
1
commit into
NousResearch:main
Choose a base branch
from
proCaj:fix/dashboard-session-history
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3701,19 +3701,29 @@ def _do(conn): | |
|
|
||
|
|
||
| def get_messages( | ||
| self, session_id: str, include_inactive: bool = False | ||
| self, | ||
| session_id: str, | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Current main has added |
||
| include_inactive: bool = False, | ||
| include_compacted: bool = False, | ||
| ) -> List[Dict[str, Any]]: | ||
| """Load messages for a session in insertion order. | ||
|
|
||
| By default only active messages are returned. Pass | ||
| ``include_inactive=True`` to load soft-deleted rows (e.g. for | ||
| audit / debug views of rewound history). See | ||
| ``include_compacted=True`` to include durable compaction-archived rows | ||
| (``active=0, compacted=1``) while still excluding user-rewound/undone | ||
| rows (``active=0, compacted=0``). Pass ``include_inactive=True`` to load | ||
| every soft-deleted row (e.g. for low-level audit / debug views). See | ||
| :meth:`rewind_to_message` for the soft-delete mechanic. | ||
|
|
||
| Ordered by AUTOINCREMENT id (true insertion order) rather than | ||
| timestamp — see c03acca50 for the WSL2 clock-regression rationale. | ||
| """ | ||
| active_clause = "" if include_inactive else " AND active = 1" | ||
| if include_inactive: | ||
| active_clause = "" | ||
| elif include_compacted: | ||
| active_clause = " AND (active = 1 OR compacted = 1)" | ||
| else: | ||
| active_clause = " AND active = 1" | ||
| with self._lock: | ||
| cursor = self._conn.execute( | ||
| "SELECT * FROM messages WHERE session_id = ?" | ||
|
|
||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| import asyncio | ||
|
|
||
| from hermes_cli import web_server | ||
| from hermes_state import SessionDB | ||
|
|
||
|
|
||
| def test_get_messages_include_compacted_keeps_compression_history_but_not_rewound(tmp_path): | ||
| db = SessionDB(tmp_path / "state.db") | ||
| db.create_session("telegram_session", source="telegram") | ||
| db.append_message("telegram_session", role="user", content="original prompt") | ||
| db.append_message("telegram_session", role="assistant", content="original answer") | ||
|
|
||
| db.archive_and_compact( | ||
| "telegram_session", | ||
| [ | ||
| {"role": "user", "content": "current prompt"}, | ||
| {"role": "assistant", "content": "current answer"}, | ||
| ], | ||
| ) | ||
| rewound_id = db.append_message("telegram_session", role="user", content="undone prompt") | ||
| db._execute_write( | ||
| lambda conn: conn.execute( | ||
| "UPDATE messages SET active = 0, compacted = 0 WHERE id = ?", | ||
| (rewound_id,), | ||
| ) | ||
| ) | ||
|
|
||
| live = [m["content"] for m in db.get_messages("telegram_session")] | ||
| history = [ | ||
| m["content"] | ||
| for m in db.get_messages("telegram_session", include_compacted=True) | ||
| if m["role"] in {"user", "assistant"} | ||
| ] | ||
| audit = [m["content"] for m in db.get_messages("telegram_session", include_inactive=True)] | ||
|
|
||
| assert live == ["current prompt", "current answer"] | ||
| assert history == [ | ||
| "original prompt", | ||
| "original answer", | ||
| "current prompt", | ||
| "current answer", | ||
| ] | ||
| assert "undone prompt" in audit | ||
| assert "undone prompt" not in history | ||
|
|
||
| db.close() | ||
|
|
||
|
|
||
| class _FakeDB: | ||
| def __init__(self): | ||
| self.calls = [] | ||
| self.closed = False | ||
|
|
||
| def resolve_session_id(self, session_id): | ||
| return f"resolved-{session_id}" | ||
|
|
||
| def resolve_resume_session_id(self, session_id): | ||
| return f"tip-{session_id}" | ||
|
|
||
| def get_messages(self, session_id, **kwargs): | ||
| self.calls.append((session_id, kwargs)) | ||
| return [{"role": "user", "content": "hello"}] | ||
|
|
||
| def close(self): | ||
| self.closed = True | ||
|
|
||
|
|
||
| def test_web_session_messages_endpoint_accepts_compacted_history_flag(monkeypatch): | ||
| fake = _FakeDB() | ||
| monkeypatch.setattr(web_server, "_open_session_db_for_profile", lambda profile=None: fake) | ||
|
|
||
| response = asyncio.run( | ||
| web_server.get_session_messages("abc", include_compacted=True) | ||
| ) | ||
|
|
||
| assert response == { | ||
| "session_id": "tip-resolved-abc", | ||
| "messages": [{"role": "user", "content": "hello"}], | ||
| } | ||
| assert fake.calls == [ | ||
| ( | ||
| "tip-resolved-abc", | ||
| {"include_inactive": False, "include_compacted": True}, | ||
| ) | ||
| ] | ||
| assert fake.closed is True |
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Current main's endpoint now preserves
limit/offset, clamps a requested limit to 500, and returns pagination metadata. Carry those fields forward when adding these history flags.