Skip to content

The agent that grows with you

fix(state): coerce imported session flags like the int columns

kshitijk4poor66999df56c8c
diff --git a/hermes_state_portability.py b/hermes_state_portability.py
index e170aab84fb..7432505408f 100644
--- a/hermes_state_portability.py
+++ b/hermes_state_portability.py
@@ -548,7 +548,7 @@ class SessionPortabilityMixin:
"id": session_id, "source": str(raw.get("source") or "import"),
"system_prompt_hash": self._store_system_prompt(conn, raw.get("system_prompt")),
"started_at": time.time() if started_at is None else started_at,
- **{col: 1 if raw.get(col) else 0 for col in _IMPORT_FLAG_COLS},
+ **{col: 1 if self._coerce_or(raw.get(col), int, 0) else 0 for col in _IMPORT_FLAG_COLS},
**{col: raw.get(col) for col in _IMPORT_PASSTHROUGH_COLS},
**{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},
diff --git a/tests/hermes_state/test_session_import_keep_flags.py b/tests/hermes_state/test_session_import_keep_flags.py
index d164fdb565d..e01a67a6439 100644
--- a/tests/hermes_state/test_session_import_keep_flags.py
+++ b/tests/hermes_state/test_session_import_keep_flags.py
@@ -39,8 +39,11 @@ 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.
+ flags = ("archived", "auto_archived", "pinned", "hidden")
+ payload.append({"id": "edited", "source": "cli", **{flag: "0" for flag in flags}})
- assert target.import_sessions(payload)["imported"] == 3
+ assert target.import_sessions(payload)["imported"] == 4
target.maybe_auto_prune_and_vacuum(retention_days=90, vacuum=False)
restored = target.get_session(SESSION_ID)
@@ -49,8 +52,8 @@ def test_restored_sessions_keep_the_pin_and_the_sweeps_archive_provenance(tmp_pa
assert target.get_session(swept)["archived"]
target.reopen_session(swept)
assert not target.get_session(swept)["archived"], "a restored sweep archive became a manual one"
- legacy = target.get_session("legacy")
- assert all(legacy[flag] == 0 for flag in ("archived", "auto_archived", "pinned", "hidden"))
+ for sid in ("legacy", "edited"):
+ assert all(target.get_session(sid)[flag] == 0 for flag in flags), sid
finally:
source.close()
target.close()