Browse Source

fix(pending-call-tracker): return most recent call from peekByParent, not oldest

When the orchestrator has multiple pending calls sharing the same parent
session ID (e.g. exp-1: explorer, exp-2: explorer, exp-3: librarian),
peekByParent was iterating in insertion order and returning the FIRST
match — always explorer — instead of the most recent one. This caused
the early board registration in session.created to register the wrong
agent type.

Fix: collect all matches and return the last (most recently inserted)
one, which corresponds to the task that just triggered session.created.
Michael Henke 3 weeks ago
parent
commit
d569463399
1 changed files with 4 additions and 3 deletions
  1. 4 3
      src/hooks/task-session-manager/pending-call-tracker.ts

+ 4 - 3
src/hooks/task-session-manager/pending-call-tracker.ts

@@ -39,12 +39,13 @@ export function createPendingCallTracker() {
       return pending;
     },
 
-    /** Peek oldest pending call for a parent without removing it. */
+    /** Peek most recent pending call for a parent without removing it. */
     peekByParent(parentSessionId: string) {
+      let latest: PendingTaskCall | undefined;
       for (const call of pendingCalls.values()) {
-        if (call.parentSessionId === parentSessionId) return call;
+        if (call.parentSessionId === parentSessionId) latest = call;
       }
-      return undefined;
+      return latest;
     },
 
     clearSession(sessionId: string) {