fix: queen dm session loading

This commit is contained in:
Richard Tang
2026-04-17 20:11:48 -07:00
parent e3154ca0ee
commit 8c10fc2e1c
3 changed files with 27 additions and 15 deletions
+9 -2
View File
@@ -207,9 +207,16 @@ async def handle_queen_session(request: web.Request) -> web.Response:
initial_prompt = body.get("initial_prompt")
initial_phase = body.get("initial_phase")
# 1. Check for an existing live session bound to this queen.
# 1. Check for an existing live DM session bound to this queen.
# Skip colony sessions: a colony forked from this queen also carries
# queen_name == queen_id, but it has a worker loaded (colony_id /
# worker_path set) and is the colony's chat, not the queen's DM.
for session in manager.list_sessions():
if session.queen_name == queen_id:
if (
session.queen_name == queen_id
and session.colony_id is None
and session.worker_path is None
):
return web.json_response(
{
"session_id": session.id,
+1 -2
View File
@@ -1282,8 +1282,7 @@ export default function ColonyChat() {
// user hasn't dismissed it (via the X button). Cleanup clears it so
// the panel closes when we leave the colony room.
useEffect(() => {
if (!agentState.sessionId) return;
setCtxSessionId(agentState.sessionId);
setCtxSessionId(agentState.sessionId ?? null);
return () => setCtxSessionId(null);
}, [agentState.sessionId, setCtxSessionId]);
+17 -11
View File
@@ -157,18 +157,18 @@ export default function QueenDM() {
(async () => {
try {
let bootstrapSessionId: string | null = null;
if (isBootstrap) {
// Pass the pending message as initial_prompt so the queen
// processes it immediately (no phantom "Hello" greeting).
await queensApi.createNewSession(
const bootstrapResult = await queensApi.createNewSession(
queenId,
pendingFirstMessage ?? undefined,
"independent",
);
bootstrapSessionId = bootstrapResult.session_id;
} else if (selectedSessionParam) {
await queensApi.selectSession(queenId, selectedSessionParam);
} else {
await queensApi.getOrCreateSession(queenId, undefined, "independent");
}
if (cancelled) return;
let sid: string;
@@ -206,14 +206,20 @@ export default function QueenDM() {
setSearchParams({ session: sid }, { replace: true });
}
} else {
// No session specified - get or create one
const result = await queensApi.getOrCreateSession(
queenId,
undefined,
"independent",
);
if (cancelled) return;
sid = result.session_id;
// Bootstrap uses the session id from createNewSession directly so a
// stale live session for this queen can't steal the flow. Otherwise
// fall back to get-or-create.
if (bootstrapSessionId) {
sid = bootstrapSessionId;
} else {
const result = await queensApi.getOrCreateSession(
queenId,
undefined,
"independent",
);
if (cancelled) return;
sid = result.session_id;
}
setSessionId(sid);
setQueenReady(true);