Skip to content

The agent that grows with you

fix(verify): clear workspace stale after hermes verify on another session

686f6c615fe3a06729e2
diff --git a/agent/verification_evidence.py b/agent/verification_evidence.py
index f514772a5e4..49c7154a3e5 100644
--- a/agent/verification_evidence.py
+++ b/agent/verification_evidence.py
@@ -511,6 +511,16 @@ def _insert_evidence(evidence: VerificationEvidence) -> dict[str, Any]:
" changed_paths_json = '[]'",
(e.session_id, e.root, event_id),
)
+ # ``hermes verify`` proves the workspace, not a session. Share the
+ # pointer with every session that already has a row for this root so
+ # a CLI run under ``default`` can clear an editing session's stale flag.
+ if e.kind == "verify":
+ conn.execute(
+ "UPDATE verification_state"
+ " SET last_event_id = ?, last_edit_at = NULL, changed_paths_json = '[]'"
+ " WHERE root = ? AND session_id != ?",
+ (event_id, e.root, e.session_id),
+ )
_prune_old_events(conn, session_id=e.session_id, root=e.root)
conn.commit()
@@ -554,10 +564,31 @@ def mark_workspace_edited(
return {"session_id": sid, "root": root, "last_edit_at": edited_at, "changed_paths": changed_paths}
+def _newest_workspace_verify(
+ conn: sqlite3.Connection, *, root: str, since: str | None
+) -> Optional[sqlite3.Row]:
+ """Latest ``hermes verify`` event for ``root``, optionally not older than ``since``."""
+ if since:
+ return conn.execute(
+ "SELECT * FROM verification_events"
+ " WHERE root = ? AND kind = 'verify' AND created_at >= ?"
+ " ORDER BY id DESC LIMIT 1",
+ (root, since),
+ ).fetchone()
+ return conn.execute(
+ "SELECT * FROM verification_events"
+ " WHERE root = ? AND kind = 'verify'"
+ " ORDER BY id DESC LIMIT 1",
+ (root,),
+ ).fetchone()
+
+
def verification_status(*, session_id: str | None, cwd: str | Path | None) -> dict[str, Any]:
"""Return the best known verification state for a session/workspace.
- Evidence recorded before the latest edit is reported as ``stale``.
+ Evidence recorded before the latest edit is reported as ``stale``. A
+ ``hermes verify`` event for the same ``root`` that is at least as new as
+ that edit satisfies the guard even if another session recorded it.
"""
if not _ledger_enabled():
return {"status": "disabled", "evidence": None}
@@ -578,13 +609,20 @@ def verification_status(*, session_id: str | None, cwd: str | Path | None) -> di
event = None
if state["last_event_id"] is not None:
event = conn.execute("SELECT * FROM verification_events WHERE id = ?", (state["last_event_id"],)).fetchone()
-
- result = {
- "evidence": None, "root": root, "session_id": sid, "changed_paths": _load_changed_paths(state["changed_paths_json"])
- }
- if event is None:
- return {"status": "unverified", **result}
-
- evidence = dict(event)
- stale = bool(state["last_edit_at"]) and state["last_edit_at"] > evidence["created_at"]
- return {"status": "stale" if stale else evidence["status"], **result, "evidence": evidence}
+ last_edit_at = state["last_edit_at"]
+ stale = bool(event is not None and last_edit_at and last_edit_at > event["created_at"])
+ if event is None or stale:
+ shared = _newest_workspace_verify(conn, root=root, since=last_edit_at)
+ if shared is not None:
+ event = shared
+ stale = False
+
+ result = {
+ "evidence": None, "root": root, "session_id": sid,
+ "changed_paths": _load_changed_paths(state["changed_paths_json"]),
+ }
+ if event is None:
+ return {"status": "unverified", **result}
+
+ evidence = dict(event)
+ return {"status": "stale" if stale else evidence["status"], **result, "evidence": evidence}
diff --git a/tests/agent/test_verification_evidence.py b/tests/agent/test_verification_evidence.py
index 6a7124d8914..bceaaa2d4ff 100644
--- a/tests/agent/test_verification_evidence.py
+++ b/tests/agent/test_verification_evidence.py
@@ -10,6 +10,7 @@ from agent.verification_evidence import (
classify_verification_command,
mark_workspace_edited,
record_terminal_result,
+ record_verify_run,
verification_status,
)
@@ -346,6 +347,34 @@ def test_file_tool_stales_evidence_by_session_id_for_absolute_edit(tmp_path, mon
+def test_workspace_verify_clears_stale_on_other_session(tmp_path, monkeypatch):
+ """A hermes verify pass is a property of the workspace, not the session
+ that ran the CLI (#103271)."""
+ monkeypatch.setenv("HERMES_HOME", str(tmp_path / ".hermes"))
+ _python_project(tmp_path)
+ changed = str(tmp_path / "changed.py")
+ mark_workspace_edited(session_id="s-edit", cwd=tmp_path, paths=[changed])
+ assert verification_status(session_id="s-edit", cwd=tmp_path)["status"] == "unverified"
+
+ event = record_verify_run(root=tmp_path, session_id="default", ok=True, output="all green")
+ assert event is not None
+ status = verification_status(session_id="s-edit", cwd=tmp_path)
+ assert status["status"] == "passed"
+ assert status["evidence"]["canonical_command"] == "hermes verify"
+
+
+def test_older_workspace_verify_does_not_clear_later_edit(tmp_path, monkeypatch):
+ monkeypatch.setenv("HERMES_HOME", str(tmp_path / ".hermes"))
+ _python_project(tmp_path)
+ record_verify_run(root=tmp_path, session_id="default", ok=True, output="old pass")
+ mark_workspace_edited(
+ session_id="s-edit",
+ cwd=tmp_path,
+ paths=[str(tmp_path / "changed.py")],
+ )
+ assert verification_status(session_id="s-edit", cwd=tmp_path)["status"] == "unverified"
+
+
def test_recording_expires_old_edit_only_state(tmp_path, monkeypatch):
home = tmp_path / ".hermes"
monkeypatch.setenv("HERMES_HOME", str(home))
diff --git a/tests/verify/test_ledger_and_nudge_integration.py b/tests/verify/test_ledger_and_nudge_integration.py
index e993aaea8e3..4efb4a1e26c 100644
--- a/tests/verify/test_ledger_and_nudge_integration.py
+++ b/tests/verify/test_ledger_and_nudge_integration.py
@@ -126,6 +126,23 @@ def test_cli_run_uses_hermes_session_id_env(hermes_home, capsys, monkeypatch):
assert verification_status(session_id="sess-42", cwd=project)["status"] == "passed"
+def test_cli_verify_clears_stale_on_editing_session(hermes_home, capsys):
+ """Standalone ``hermes verify`` records under default; the editing session
+ must still see a pass (#103271)."""
+ project = _workspace(hermes_home, manifest_recipe={"name": "Fake", "test": ["echo ok"]})
+ changed = str(project / "src" / "app.ts")
+ edit_session = "20260717_230325_f2d00d"
+ mark_workspace_edited(session_id=edit_session, cwd=project, paths=[changed])
+ assert verification_status(session_id=edit_session, cwd=project)["status"] == "unverified"
+ assert build_verify_on_stop_nudge(session_id=edit_session, changed_paths=[changed]) is not None
+
+ assert run_verify_command(make_args(project)) == 0
+
+ assert verification_status(session_id=edit_session, cwd=project)["status"] == "passed"
+ assert verification_status(session_id="default", cwd=project)["status"] == "passed"
+ assert build_verify_on_stop_nudge(session_id=edit_session, changed_paths=[changed]) is None
+
+
# ---------------------------------------------------------------------------
# closed loop: edit -> stop guard nudge -> hermes verify -> guard satisfied
# ---------------------------------------------------------------------------