diff --git a/wwwroot/api/cockpit_chat.dspy b/wwwroot/api/cockpit_chat.dspy index 8f1bb7c..0edfbb5 100644 --- a/wwwroot/api/cockpit_chat.dspy +++ b/wwwroot/api/cockpit_chat.dspy @@ -83,6 +83,11 @@ async def _load_ctx(sor, uid): ctx = {'pid':'','pname':'','ws':'','skills_dir':'','repos':[]} if not recs: return ctx ctx['pid'] = getattr(recs[0],'current_project_id','') or '' + if not ctx['pid']: + # Fallback: recover from most recent conversation's iteration_id (which stores project_id) + last = await sor.sqlExe("SELECT iteration_id FROM pipeline_conversations WHERE created_by=${u}$ AND iteration_id != '' ORDER BY created_at DESC LIMIT 1",{"u":uid}) + if last: + ctx['pid'] = getattr(last[0],'iteration_id','') or '' if ctx['pid']: projs = await sor.sqlExe("SELECT name,workspace_dir,org_id FROM sd_projects WHERE id=${p}$",{"p":ctx['pid']}) if projs: