Skip to content

The agent that grows with you

fix(state): let a managed worker repair an unknown created_source

kshitijk4poor1bb96a5d6bfe
diff --git a/hermes_state_runtime.py b/hermes_state_runtime.py
index ea141db2c84..ffbfd0b7a22 100644
--- a/hermes_state_runtime.py
+++ b/hermes_state_runtime.py
@@ -868,8 +868,9 @@ def _worker_usage(db, conn, session_id, payload, *, auxiliary=False):
if not auxiliary:
# ``source`` is the worker platform (turn_usage._agent_session_source). A Desktop
# managed worker passes ``gui``; created_surface maps that to ``desktop``. The row
- # is usually stamped at admission. A compression child can still be NULL, and this
- # worker never create_session's it, so fill only that NULL.
+ # is usually stamped at admission. A compression child can still be NULL (or an
+ # auxiliary-usage ``unknown``), and this worker never create_session's it, so fill
+ # only an unset column, as the creator upsert does.
raw = payload.get('source')
source = raw if isinstance(raw, str) else None
payload = {k: v for k, v in payload.items() if k != 'source'}
@@ -899,7 +900,8 @@ def _worker_usage(db, conn, session_id, payload, *, auxiliary=False):
surfaced = created_surface(source)
if surfaced:
conn.execute(
- "UPDATE sessions SET created_source=? WHERE id=? AND created_source IS NULL",
+ "UPDATE sessions SET created_source=? WHERE id=? "
+ "AND (created_source IS NULL OR created_source = 'unknown')",
(surfaced, session_id))
from hermes_state_compression import stamp_compression_ancestors
stamp_compression_ancestors(conn, session_id)
diff --git a/tests/hermes_state/test_compression_created_source.py b/tests/hermes_state/test_compression_created_source.py
index 0cc4a63d1b4..7026c55ec2b 100644
--- a/tests/hermes_state/test_compression_created_source.py
+++ b/tests/hermes_state/test_compression_created_source.py
@@ -3,6 +3,8 @@
Automatic compression does not create the child again, so the worker's ``usage.main``
is the write that fills the column, and it carries the surface to the NULL root.
"""
+import pytest
+
from hermes_state import SessionDB
@@ -23,15 +25,19 @@ def _created(db, sid):
return db.get_session(sid)["created_source"]
-def test_desktop_worker_heals_gui_to_desktop(tmp_path):
[email protected]("child_created", [None, "unknown"])
+def test_desktop_worker_heals_gui_to_desktop(tmp_path, child_created):
"""A managed Desktop worker's platform is the policy label ``gui``. The healed
- column is ``desktop``, the same surface the in-process agent and the insert stamp."""
+ column is ``desktop``, the same surface the in-process agent and the insert stamp.
+ An auxiliary-usage ``unknown`` placeholder is unset too, as in the creator upsert."""
import hermes_state_runtime as rt
db = SessionDB(db_path=tmp_path / "state.db")
try:
child = _compress(db, None, "desktop-child")
- assert _created(db, child) is None
+ with db._lock:
+ db._conn.execute("UPDATE sessions SET created_source=? WHERE id=?", (child_created, child))
+ db._conn.commit()
epoch = rt.begin_runtime_epoch(db, instance_id="owner")
scope = dict(epoch=epoch, execution_id="w", session_id=child, generation=0)
rt.register_worker_execution(db, **scope, kind="compute", adoption_secret="private")