@@ -90,6 +90,7 @@ async def fetch_current_tasks(
9090async def fetch_first_task_description (
9191 db_session : AsyncSession , session_id : asUUID
9292) -> Result [str | None ]:
93+ # The session title mirrors the first real task, not the planning section.
9394 query = (
9495 select (Task )
9596 .where (Task .session_id == session_id )
@@ -105,6 +106,7 @@ async def fetch_first_task_description(
105106async def _sync_session_display_title (
106107 db_session : AsyncSession , session_id : asUUID
107108) -> None :
109+ # Best-effort sync: only write when we have a non-empty title candidate.
108110 title , eil = (await fetch_first_task_description (db_session , session_id )).unpack ()
109111 if eil is None and title :
110112 await SD .update_session_display_title_once (db_session , session_id , title )
@@ -139,6 +141,7 @@ async def update_task(
139141 flag_modified (task , "data" )
140142
141143 await db_session .flush ()
144+ # Flush first so the title lookup sees the final task state for this edit.
142145 await _sync_session_display_title (db_session , task .session_id )
143146 # Changes will be committed when the session context exits
144147 return Result .resolve (task )
@@ -193,6 +196,8 @@ async def insert_task(
193196
194197 db_session .add (task )
195198 await db_session .flush ()
199+ # Insertions can change the first visible task, so sync the title after the
200+ # new row is persisted.
196201 await _sync_session_display_title (db_session , session_id )
197202 return Result .resolve (task )
198203
0 commit comments