Bug
On any worker session page (e.g. /sessions/ao-8), clicking the "Orchestrator" button in the top-right navigates to the wrong orchestrator (e.g. ao-orchestrator-1) instead of the correct parent (ao-orchestrator-9).
Root Cause
Two-part failure:
-
No parent tracking. Sessions have no parentOrchestratorId field — neither in the Session type nor in metadata. When orchestrator-9 spawns worker ao-8, that relationship is never recorded.
-
Fallback picks wrong orchestrator. When the frontend fetches /api/sessions?project=agent-orchestrator&orchestratorOnly=true:
- The API returns all orchestrator sessions for the project sorted lexicographically by ID
orchestratorId is set to null when there are multiple orchestrators (sessions/route.ts:36)
- The client fallback (
page.tsx:162) does .find() which returns the first match — ao-orchestrator-1 (alphabetically first), not the active ao-orchestrator-9
Fix
Apply both approaches:
A — Store parent orchestrator in session metadata
- When an orchestrator spawns a worker, write
parentOrchestratorId to the worker metadata (in session-manager spawn flow)
- Frontend reads
session.metadata["parentOrchestratorId"] directly — no API fallback needed for the correct parent
B — Smart fallback when parent metadata is missing
- Sort orchestrators by recency (prefer non-exited, then by
createdAt desc) instead of lexicographic
- This fixes the common case for sessions created before the metadata fix
Affected files:
packages/core/src/session-manager.ts — write parentOrchestratorId metadata on worker spawn
packages/web/src/lib/serialize.ts:95 — sort by recency, not lexicographic
packages/web/src/app/sessions/[id]/page.tsx:160-163 — read parent from metadata, fallback to smart sort
packages/web/src/app/api/sessions/route.ts:36 — return per-project orchestrator ID properly
Bug
On any worker session page (e.g.
/sessions/ao-8), clicking the "Orchestrator" button in the top-right navigates to the wrong orchestrator (e.g.ao-orchestrator-1) instead of the correct parent (ao-orchestrator-9).Root Cause
Two-part failure:
No parent tracking. Sessions have no
parentOrchestratorIdfield — neither in theSessiontype nor in metadata. When orchestrator-9 spawns worker ao-8, that relationship is never recorded.Fallback picks wrong orchestrator. When the frontend fetches
/api/sessions?project=agent-orchestrator&orchestratorOnly=true:orchestratorIdis set tonullwhen there are multiple orchestrators (sessions/route.ts:36)page.tsx:162) does.find()which returns the first match —ao-orchestrator-1(alphabetically first), not the activeao-orchestrator-9Fix
Apply both approaches:
A — Store parent orchestrator in session metadata
parentOrchestratorIdto the worker metadata (in session-manager spawn flow)session.metadata["parentOrchestratorId"]directly — no API fallback needed for the correct parentB — Smart fallback when parent metadata is missing
createdAtdesc) instead of lexicographicAffected files:
packages/core/src/session-manager.ts— writeparentOrchestratorIdmetadata on worker spawnpackages/web/src/lib/serialize.ts:95— sort by recency, not lexicographicpackages/web/src/app/sessions/[id]/page.tsx:160-163— read parent from metadata, fallback to smart sortpackages/web/src/app/api/sessions/route.ts:36— return per-project orchestrator ID properly