The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(cli): heal a managed Desktop worker surface to desktop
David Dudok de Witb48624716afe
diff --git a/hermes_state_runtime.py b/hermes_state_runtime.pyindex ff6a3d639fd..f1814bdd189 100644--- a/hermes_state_runtime.py+++ b/hermes_state_runtime.py@@ -866,9 +866,10 @@ def _worker_usage(db, conn, session_id, payload, *, auxiliary=False):from hermes_state_usage import _MODEL_USAGE_FIELDS, _TOKEN_COUNTERSsource = Noneif not auxiliary:- # ``source`` is the agent's surface (turn_usage._agent_session_source). The row is- # usually stamped at admission. A compression child can still have a NULL- # created_source, and this worker never create_session's it, so fill only that NULL.+ # ``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.raw = payload.get('source')source = raw if isinstance(raw, str) else Nonepayload = {k: v for k, v in payload.items() if k != 'source'}@@ -892,10 +893,14 @@ def _worker_usage(db, conn, session_id, payload, *, auxiliary=False):db._record_model_usage(conn, session_id, **({'api_call_count': 1} | payload))else:db._update_token_counts_in_transaction(conn, session_id, **payload)- if source not in (None, '', 'local', 'unknown'):+ # The managed worker's platform is the policy label (gui), not the in-process+ # agent surface (desktop). Stamp the same created_surface the insert uses.+ from gateway.session_policy import created_surface+ surfaced = created_surface(source)+ if surfaced:conn.execute("UPDATE sessions SET created_source=? WHERE id=? AND created_source IS NULL",- (source, session_id))+ (surfaced, session_id))return {'value': None}diff --git a/tests/hermes_state/test_compression_created_source.py b/tests/hermes_state/test_compression_created_source.pyindex 7f2166243c8..07123b7a5bc 100644--- a/tests/hermes_state/test_compression_created_source.py+++ b/tests/hermes_state/test_compression_created_source.py@@ -79,3 +79,23 @@ def test_worker_usage_fills_a_null_compression_child(tmp_path):assert _created(db, kept) == "tui"finally:db.close()+++def test_desktop_worker_heals_gui_to_desktop(tmp_path):+ """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."""+ 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+ 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")+ rt.mutate_worker_execution(db, **scope, sequence=1, operation="usage.main", payload={+ "input_tokens": 4, "output_tokens": 1, "api_call_count": 1, "model": "m",+ "billing_provider": "p", "source": "gui"})+ assert _created(db, child) == "desktop"+ finally:+ db.close()