Skip to content

Orchestrator button on worker page links to wrong parent session #1211

@i-trytoohard

Description

@i-trytoohard

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:

  1. 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.

  2. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions