Skip to content

fix(orchestrator): open most recently active session, not newest-created#3041

Open
AllBeingsFuture wants to merge 1 commit into
AgentWrapper:mainfrom
AllBeingsFuture:ao/agent-orchestrator-27/fix-orch-clearhist
Open

fix(orchestrator): open most recently active session, not newest-created#3041
AllBeingsFuture wants to merge 1 commit into
AgentWrapper:mainfrom
AllBeingsFuture:ao/agent-orchestrator-27/fix-orch-clearhist

Conversation

@AllBeingsFuture

Copy link
Copy Markdown

Problem

Clicking Orchestrator (sidebar / topbar / board / command palette) sometimes opened an empty conversation as if history had been wiped. History was still on another live orchestrator session; the UI/daemon had attached to a different, newer empty one.

Root cause

When more than one non-terminated orchestrator existed for a project (overlap during replacement, accidental duplicates, etc.), both the frontend picker (newestActiveOrchestrator) and the daemon ensure path (SpawnOrchestrator clean=false → newestSession) ranked by createdAt first.

That preferred a brand-new empty spawn over an older still-active orchestrator that held the real conversation — matching the “wrong session / empty history on open” report and the recency intent of #1362 (most recently used/active, not lex-smallest or newest-created).

Fix

Rank live orchestrators by:

  1. activity.lastActivityAt (most recently used)
  2. updatedAt
  3. createdAt
  4. session id

Applied in both:

  • frontend/.../workspace.ts (newestActiveOrchestrator — all open entry points already use this)
  • backend/.../service/session/service.go (sessionNewer — ensure/reuse when clean=false)

What was deliberately not changed

Path Behavior preserved
SpawnOrchestrator(clean=false) with one active orchestrator Still returns that session; no spawn
SpawnOrchestrator(clean=true) / restart / settings / restore-dialog Still retires then spawns
Kill / terminate / multi-project isolation / worker spawn / review Untouched
#3032 sidebar pinned Orchestrator row Not duplicated; that remains a separate UX PR
#2501 false terminate + silent replace Not fixed here (lifecycle); residual risk noted below

Tests

  • Frontend: cd frontend && npm test -- --run src/renderer/types/workspace.test.ts — prefers recently-active over newer empty spawn
  • Backend: cd backend && go test ./internal/service/session/ -count=1 — ensure returns most recently active among duplicates; existing clean=false/true tests still pass

Residual risks / follow-ups

Closes nothing automatically; addresses the open-path half of the “click Orchestrator clears history” report and improves #1362 targeting.

When multiple live orchestrators overlap, ranking by createdAt sent Open
Orchestrator / ensure-reuse to a brand-new empty session while conversation
history still lived on an older still-active orchestrator. Prefer agent
activity (then updatedAt, createdAt, id) so casual open reuses the session
the user was actually using. clean=true relaunch and single-orchestrator
ensure paths are unchanged.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant