Python
Bookkeeping saves keep their place in Recents
Rohit C Prasada25274e683f3
diff --git a/coworker/conversations.py b/coworker/conversations.pyindex 1e6c5edb..eb829eca 100644--- a/coworker/conversations.py+++ b/coworker/conversations.py@@ -167,7 +167,10 @@ class ConversationStore:self._conn.commit()# -- API --------------------------------------------------------------------- def save(self, record: SessionRecord) -> None:+ def save(self, record: SessionRecord, touch: bool = True) -> None:+ # touch=False: a BOOKKEEPING write (persisted notice migration, mode marker with+ # no accompanying activity) — the row updates but keeps its place in Recents.+ # `updated_at` means "last worked on", never "last saved" (owner ruling 2026-08-24).sid = record.session_idwith self._lock:# lazily migrate a legacy inline blob into the .jsonl@@ -201,7 +204,7 @@ class ConversationStore:title = COALESCE(sessions.title, excluded.title), agent = excluded.agent,n_msgs = excluded.n_msgs, messages = NULL, extra_roots = excluded.extra_roots,grants = excluded.grants, compaction = excluded.compaction,- updated_at = CURRENT_TIMESTAMP+ updated_at = CASE WHEN ? THEN CURRENT_TIMESTAMP ELSE sessions.updated_at END""",(sid,@@ -216,10 +219,12 @@ class ConversationStore:json.dumps(record.compaction or {}),json.dumps(record.team or {}),json.dumps(record.bindings or {}),+ touch,),)self._conn.commit()- self.touch_workspace(record.workspace)+ if touch:+ self.touch_workspace(record.workspace)def load(self, session_id: str) -> Optional[SessionRecord]:with self._lock:diff --git a/coworker/server/app.py b/coworker/server/app.pyindex 97874547..b88fbec6 100644--- a/coworker/server/app.py+++ b/coworker/server/app.py@@ -2512,7 +2512,7 @@ def create_app(manager: SessionManager) -> FastAPI:engine._append_notice("mode_notice", AUTO_APPROVE_NOTICE, title="Auto-approve is on.")- manager.save(session_id, engine)+ manager.save(session_id, engine, touch=False) # migration ≠ activityawait ws.send_json({"type": "mode_notice",@@ -2668,7 +2668,11 @@ def create_app(manager: SessionManager) -> FastAPI:"mode_switch", f"{label} is on.")notice_data = {"text": f"{label} is on."}- manager.save(session_id, engine)+ # A mode switch with no accompanying message is bookkeeping,+ # not activity (owner ruling 2026-08-24): the transcript+ # records it, Recents doesn't reorder. The next real turn's+ # checkpoint save bumps recency as usual.+ manager.save(session_id, engine, touch=False)await manager.broadcast_session(session_id,{"type": "mode_notice", "data": notice_data},diff --git a/coworker/server/manager.py b/coworker/server/manager.pyindex 07ae30c3..c70790f7 100644--- a/coworker/server/manager.py+++ b/coworker/server/manager.py@@ -5000,7 +5000,7 @@ class SessionManager:self.task_store.save(task)return {"ok": True, "run": run.to_dict()}- def save(self, session_id: str, engine: TurnEngine) -> None:+ def save(self, session_id: str, engine: TurnEngine, touch: bool = True) -> None:executor = getattr(engine, "executor", None)workspace = os.path.realpath(str(executor.cwd)) if executor else ""self.session_store.save(@@ -5019,7 +5019,8 @@ class SessionManager:if getattr(engine, "compaction_state", None)else {}),- )+ ),+ touch=touch,)@staticmethoddiff --git a/tests/test_memory.py b/tests/test_memory.pyindex 59b20cfd..e52e4369 100644--- a/tests/test_memory.py+++ b/tests/test_memory.py@@ -692,3 +692,32 @@ def test_session_append_only_and_list(tmp_path):assert len(listed) == 1assert listed[0].message_count == 2assert listed[0].title == "a"+++def test_bookkeeping_saves_do_not_bump_recency(tmp_path):+ # touch=False (owner ruling 2026-08-24): `updated_at` means "last worked on", never+ # "last saved" — the banner migration and message-less mode switches must not reorder+ # Recents. A touch=True save still bumps as ever.+ from coworker.sessions import SessionRecord++ store = ConversationStore(tmp_path)+ store.save(SessionRecord(session_id="rec1", workspace=str(tmp_path), model="m", mode="interactive", messages=[]))+ store._conn.execute(+ "UPDATE sessions SET updated_at = '2020-01-01 00:00:00' WHERE session_id = 'rec1'"+ )+ store._conn.commit()++ store.save(+ SessionRecord(session_id="rec1", workspace=str(tmp_path), model="m", mode="interactive", messages=[]),+ touch=False,+ )+ row = store._conn.execute(+ "SELECT updated_at FROM sessions WHERE session_id = 'rec1'"+ ).fetchone()+ assert row["updated_at"] == "2020-01-01 00:00:00"++ store.save(SessionRecord(session_id="rec1", workspace=str(tmp_path), model="m", mode="interactive", messages=[]))+ row = store._conn.execute(+ "SELECT updated_at FROM sessions WHERE session_id = 'rec1'"+ ).fetchone()+ assert row["updated_at"] != "2020-01-01 00:00:00"