The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(acp): run the cwd backfill once when the session manager first opens the DB
teknium18155f4357b6a
diff --git a/acp_adapter/session.py b/acp_adapter/session.pyindex 56afcb46f56..0a323c50f5b 100644--- a/acp_adapter/session.py+++ b/acp_adapter/session.py@@ -164,6 +164,7 @@ class SessionManager:self._restore_lock = threading.Lock()self._agent_factory = agent_factoryself._db_instance = db # None → lazy-init on first use+ self._cwd_backfilled = False# ---- public API ---------------------------------------------------------@@ -293,6 +294,16 @@ class SessionManager:self._db_instance = acquire(get_hermes_home() / "state.db")except Exception:logger.debug("SessionDB unavailable for ACP persistence", exc_info=True)+ if self._db_instance is not None and not self._cwd_backfilled:+ # Rows minted before the adapter wrote the cwd column still carry the workspace+ # in model_config; one idempotent UPDATE per process repairs them (#115705).+ self._cwd_backfilled = True+ try:+ repaired = self._db_instance.backfill_acp_session_cwd()+ if repaired:+ logger.info("Backfilled cwd for %d ACP session(s) from model_config", repaired)+ except Exception:+ logger.debug("ACP session cwd backfill failed", exc_info=True)return self._db_instancedef _persist(self, state: SessionState) -> None:diff --git a/contributors/emails/[email protected] b/contributors/emails/[email protected]new file mode 100644index 00000000000..8554a3b8ca6--- /dev/null+++ b/contributors/emails/[email protected]@@ -0,0 +1 @@+jefuriiijdiff --git a/tests/acp_adapter/test_session_cwd_column.py b/tests/acp_adapter/test_session_cwd_column.pyindex 43612d87e00..33f5212a780 100644--- a/tests/acp_adapter/test_session_cwd_column.py+++ b/tests/acp_adapter/test_session_cwd_column.py@@ -89,3 +89,19 @@ def test_reopening_in_another_workspace_moves_the_cwd_column(tmp_path):# probe for the OLD cwd cannot publish onto the new one.assert (row["git_metadata_generation"] or 0) >= 1db.close()+++def test_legacy_rows_get_their_cwd_column_backfilled_when_the_manager_opens_the_db(tmp_path):+ """A row minted before the adapter wrote the column carries its workspace only in+ ``model_config``; the first DB use by the manager promotes it (#115705)."""+ db = SessionDB(tmp_path / "state.db")+ db.create_session(session_id="legacy", source="acp", model="m", model_config={"cwd": "/work/hs-wwd"})+ db.create_session(session_id="cli", source="cli", model="m", model_config={"cwd": "/somewhere"})+ assert db.get_session("legacy")["cwd"] in (None, "")++ manager = _manager(db)+ manager.create_session(cwd=str(tmp_path)) # first DB touch++ assert db.get_session("legacy")["cwd"] == "/work/hs-wwd"+ assert db.get_session("cli")["cwd"] in (None, ""), "only ACP rows are repaired"+ db.close()