Skip to content

The agent that grows with you

fix(state): import auto_archived only on an archived row

kshitijk4poor47b7638e6ec3
diff --git a/hermes_state_portability.py b/hermes_state_portability.py
index 7432505408f..90d3cfa53e1 100644
--- a/hermes_state_portability.py
+++ b/hermes_state_portability.py
@@ -553,6 +553,7 @@ class SessionPortabilityMixin:
**{col: self._coerce_or(raw.get(col), float, None) for col in _IMPORT_FLOAT_COLS},
**{col: self._coerce_or(raw.get(col), int, 0) for col in _IMPORT_INT_COLS},
}
+ params["auto_archived"] &= params["archived"] # only the sweep sets it, and only on rows it archives
conn.execute(_IMPORT_SESSION_INSERT_SQL, params)
def _json_value(value: Any) -> Any:
return safe_json_loads(value, default=value) if isinstance(value, str) else value
diff --git a/tests/hermes_state/test_session_import_keep_flags.py b/tests/hermes_state/test_session_import_keep_flags.py
index e01a67a6439..4e39ab3a254 100644
--- a/tests/hermes_state/test_session_import_keep_flags.py
+++ b/tests/hermes_state/test_session_import_keep_flags.py
@@ -39,9 +39,10 @@ def test_restored_sessions_keep_the_pin_and_the_sweeps_archive_provenance(tmp_pa
payload = json.loads(json.dumps(source.export_all(include_inactive=True)))
# An export that predates the durable flags still imports as an ordinary, visible session.
payload.append({"id": "legacy", "source": "cli", "messages": [{"role": "user", "content": "old"}]})
- # A hand-edited export's string "0" flags are coerced like the int columns, not by truthiness.
+ # A hand-edited export's string "0" flags are coerced like the int columns, not by truthiness,
+ # and a live row is never marked as the sweep's archive.
flags = ("archived", "auto_archived", "pinned", "hidden")
- payload.append({"id": "edited", "source": "cli", **{flag: "0" for flag in flags}})
+ payload.append({"id": "edited", "source": "cli", **{flag: "0" for flag in flags}, "auto_archived": 1})
assert target.import_sessions(payload)["imported"] == 4
target.maybe_auto_prune_and_vacuum(retention_days=90, vacuum=False)