Skip to content

The agent that grows with you

refactor(state): one not-a-surface set for created_surface callers

kshitijk4poord093ff694db1
diff --git a/gateway/session_policy.py b/gateway/session_policy.py
index bc83fe4d910..f28538a7932 100644
--- a/gateway/session_policy.py
+++ b/gateway/session_policy.py
@@ -80,6 +80,8 @@ SURFACES = {'cli': 'cli', 'tui': 'tui', 'gui': 'desktop', 'acp': 'acp', 'tool':
# Every other creation label is rewritten to ``source='local'`` on peer refresh.
_KEEP_STORED_LABEL = frozenset({'tool', 'oneshot'})
STORED_AS_LOCAL = frozenset(SURFACES) - _KEEP_STORED_LABEL
+# Routing labels and the accounting placeholder: never a creating surface.
+_NOT_A_SURFACE = frozenset({None, '', 'local', 'unknown'})
def created_surface(label):
@@ -89,12 +91,9 @@ def created_surface(label):
through ``SURFACES`` (``gui`` is ``desktop``). Any other label, including
``tool`` and ``oneshot``, is kept as itself: created_source is provenance.
"""
- if label in (None, '', 'local', 'unknown'):
+ if label in _NOT_A_SURFACE:
return None
- mapped = SURFACES[label] if label in STORED_AS_LOCAL else label
- if mapped in ('', 'local', 'unknown'):
- return None
- return mapped
+ return SURFACES[label] if label in STORED_AS_LOCAL else label
def surface_groups():
diff --git a/hermes_cli/gateway_session_store.py b/hermes_cli/gateway_session_store.py
index db36771e319..12286dc67ef 100644
--- a/hermes_cli/gateway_session_store.py
+++ b/hermes_cli/gateway_session_store.py
@@ -382,11 +382,6 @@ class GatewaySessionStore:
}
-# Built from session_policy.SURFACES and STORED_AS_LOCAL. gui and desktop are one
-# conversation (in-process agent is desktop; the managed worker creates with gui).
-# acp is stored local too. tool and oneshot are not cli aliases.
-
-
class SurfaceLabelReader:
"""A read-only ``SessionDB`` whose source-filtered listings read main's labels: ``source='cli'``
also matches a gateway row labelled ``local`` that the CLI created (``created_source='cli'``), so
@@ -416,8 +411,11 @@ class SurfaceLabelReader:
def _expand(self, requested):
"""``(live source labels, created_source labels)`` or None for a raw source filter.
- Live labels include the other name of a gui/desktop pair, so a row that has not been
- peer-refreshed (``source='gui'``) still matches ``--source desktop``.
+ Groups come from session_policy.SURFACES and STORED_AS_LOCAL: gui and desktop are one
+ conversation (the in-process agent is desktop, the managed worker creates with gui), acp
+ is stored local too, and tool/oneshot are not cli aliases. Live labels include the other
+ name of a gui/desktop pair, so a row that has not been peer-refreshed (``source='gui'``)
+ still matches ``--source desktop``.
"""
wanted = {requested} if isinstance(requested, str) else set(requested or ())
created = set()
diff --git a/hermes_state_compression.py b/hermes_state_compression.py
index c4a43ba5dcf..803db894bd5 100644
--- a/hermes_state_compression.py
+++ b/hermes_state_compression.py
@@ -284,9 +284,7 @@ class SessionCompressionMixin:
# create the child again. The turn's ``update_token_counts(source=...)`` fills
# that NULL; auxiliary usage must not write ``unknown`` into it first.
from gateway.session_policy import created_surface
- created_source = parent["created_source"]
- if created_source in (None, "", "local", "unknown"):
- created_source = created_surface(source)
+ created_source = created_surface(parent["created_source"]) or created_surface(source)
# The child continues the parent's tools[] pin (the compaction refresh re-pinned it just
# before publish), or its first hop to another surface re-derives the array.
conn.execute(