Orchestration Plan 8
Scope: Fix defects and gaps identified during verification (Phase.md Items E1–E12) and re-run all open verification criteria (V1, V2, V4, V6, V8, V9).
Spec: Orchestration Spec
Prior plan: Plan 7
Task 1 — Fix Project Runner Agent MCP Configuration
E1: Project Runner agent fails with “Missing required tools: list_projects, get_project_phase” despite forge-discovery being listed in its
mcpServerNamesinagent-sync.ts. Root cause: for master→variant families,agent-sync.tssyncs fields from master to variants, but never updates the master agent’s ownmcpServerNamesfrom the family config. The master update (buildVariantUpdate) only copiesVARIANT_FIELDS+instructions, andmcpServerNamesis aSYNCED_FIELDthat gets copied FROM master TO variants — never set ON the master itself.
- In
orchestrator/src/agent-sync.ts, modify the master→variant sync logic to explicitly setmcpServerNameson the master agent from the family config (family.mcpServerNames). Add this to themasterUpdateobject in the sync function. - Run
npx tsx agent-sync.ts --dry-runto verify the change would setmcpServerNamescorrectly on Project Runner and Task Runner agents. - Run
npx tsx agent-sync.tslive to apply the fix. - Verify: spawn Project Runner via
forge-spawn(monitor mode) and confirm it can calllist_projectsandget_project_phasewithout errors.
Deliverable: Project Runner and Task Runner agents have correct mcpServerNames in MongoDB. E1 resolved.
Task 2 — Fix Orchestrator SSE Client
E2: The orchestrator’s
wireHandlers()uses named SSE events (addEventListener('on_run_step', ...)) while LibreChat’s SSE stream sends events via theevent:SSE field. forge-spawn’s approach uses the genericmessageevent with embedded event-field parsing — this was tested and fixed. E3:createEventSource()does not passAuthorizationheader to SSE streams, which would cause 401 errors. E10: Monitor-mode SSE connection errors stem from these two issues.
- In
orchestrator/src/chat-client.ts, fixcreateEventSource()to passAuthorization: Bearer ${token}header in the customfetchoverride. Get the token fromthis.auth.getValidToken()— this requires makingcreateEventSourceasync or caching the token. Pattern: store the token before creating EventSource, then pass it in the fetch headers alongsideUser-Agent. - Replace
wireHandlers()to usees.addEventListener('message', handler)instead of named events. Parse the event type from the SSE data: LibreChat sendsevent: <type>\ndata: <json>format. Themessageevent listener receives all events; inspectevent.typeor parse the data to determine which handler to invoke. Reference: forge-spawn’s SSE parsing approach inmcp-servers/forge-spawn/. - Handle reconnection: if the SSE stream disconnects, use
resumeStream()with?resume=trueto reconnect. - Test: spawn an agent in monitor mode and verify SSE events are received, Authorization succeeds, and no “SSE connection error” occurs.
Deliverable: SSE client passes Authorization and parses events correctly. E2, E3, E10 resolved.
Task 3 — Fix Dispatcher Job Management
E5: 9 jobs stuck in “running” status (some since April 28) with no cleanup/reaper mechanism. E11: Dispatcher’s
createJobdoesn’t record metadata (mode, requiredTools, etc.), making debugging difficult.
-
In
orchestrator/src/dispatcher.ts, update thedispatch()function to pass metadata todb.createJob(): -
Add a job reaper function to
orchestrator/src/db.ts(or a neworchestrator/src/reaper.ts):- Query all jobs with
status = 'running'andstartedAt < NOW() - interval '2 hours'(configurable threshold) - For each stale job, call
chatClient.checkStatus(conversationId)to determine if the agent is actually still running - If the agent is completed/failed/absent, update the job status to
completedorfailedwithcompletedAt = NOW() - Log each reaped job for audit
- Query all jobs with
-
Add a scheduled Inngest function or a startup + periodic check (every 15 minutes) that runs the reaper.
-
Clean up the 9 currently stuck jobs by running the reaper once manually.
-
Add a
POST /jobs/reapadmin endpoint for manual reaper triggers.
Deliverable: Stale running jobs are auto-detected and cleaned up. Job metadata is recorded. E5, E11 resolved.
Task 4 — Fix Agent Registration and Dead Code
E6:
modelSpecsinlibrechat.yamlonly includes 10 Forge family agents. The 9 SRP/Master/Task Runner agents are missing from the model picker. E7:upsertProject()andgetActiveProjects()indb.tsare dead code — never called.
- Run
npx tsx agent-sync.tsand capture thegenerateModelspecs()output. Apply the fullmodelSpecsblock toForge/Configs/LibreChat_Service/librechat.yaml, replacing the existing incomplete list. - Verify: check the LibreChat model picker contains all 19 agents (10 Forge + 4 SRP + 2 Project Runner + 2 Task Runner + 1 Page Manager = note: verify exact count against
AGENT_FAMILIES). - For E7: decide disposition — either:
- Option A (wire it up): Call
upsertProject()when the dispatcher creates a job (sync project index from Phase files). Add a startup sync that reads all Phase files and populates the Project table. - Option B (remove it): Remove
upsertProject(),getActiveProjects(), and theProjecttable schema if not needed now. The forge-discovery MCP already provides project data via filesystem reads. - Recommend Option B — the Project table adds complexity without clear benefit while forge-discovery already serves this purpose. Remove the dead code and the
Projecttable fromSCHEMA_SQL.
- Option A (wire it up): Call
- If Option B: remove
upsertProject(),getActiveProjects(),Projecttype, and theProjecttable DDL fromdb.ts. Drop the table from the forge database.
Deliverable: All agents appear in the model picker. Dead code removed or wired up. E6, E7 resolved.
Task 5 — Complete Schedule Configuration
E4: Missing schedules per Spec §10.1: Memory Compaction (daily) and Infrastructure Check (monthly) are not configured in
SCHEDULE_CONFIGor Inngest functions.
- In
orchestrator/src/schedules.ts, add placeholder entries for the two missing schedules. These won’t have real agent IDs yet (the agents don’t exist), but the config should be present for documentation and future use: - In
orchestrator/src/inngest.ts, add Inngest scheduled functions for these two (with guards: ifagent_idis empty, skip and log a warning instead of dispatching). - Verify the
/schedulesendpoint returns all 4 schedules.
Deliverable: All 4 Spec schedules are configured. E4 resolved.
Task 6 — End-to-End Verification
Re-run all verification criteria that were Open in the Phase.md verification report. This task addresses V1, V2, V6, V8, V9, V12, and E12.
-
V1 — Cron scheduling: Trigger Project Runner schedule manually via Inngest dashboard. Verify: Inngest →
POST /orchestrator/run→ agent invoked → AgentJob record created. Let one natural cycle run (wait for hourly Task Runner) and verify it fires. -
V2 — Project discovery by agent: Spawn Project Runner in monitor mode. Verify it successfully calls
list_projectsandget_project_phaseand reports project status. (Depends on Task 1 fix.) -
V8 — Project Runner detects completed phases: Create a test scenario where a project phase is marked complete. Trigger Project Runner. Verify it either initiates the next phase or adds an item to
Erik_Todo.md. -
V9 — Task Runner dispatches correct sub-agent: Add a test item to
Agent_Todo.md. Trigger Task Runner. Verify it dispatches the appropriate SRP agent and updates the todo item state. -
V6 — Stalled agent detection and resume: Start an agent in monitor mode, then abort it mid-execution. Verify the reaper (from Task 3) detects the stalled job. Test resume by spawning a new agent in the same conversation.
-
V12/E12 — Transcript review: Spawn a sub-agent via
forge-spawn. After completion, queryGET /api/convosto find the conversation. Verify: (a) it appears in chat history, (b) it has an auto-generated title, (c) tool-call details are visible in the messages. -
V4 — Todo/checklist MCP (E9): R4 was explicitly skipped in the Spec (marked ⏭️). The flat-file
Agent_Todo.md/Erik_Todo.mdapproach is the current substitute. Mark V4 as “Deferred” in the Phase.md — no code change needed. Record this disposition in the Resolution Log. -
Update
Orchestration_Phase.md: for each verified criterion, change status from 🔴 to 🟢. For each resolved item, fill in the Disposition and Action taken columns. Set V4/E9 disposition to “Deferred” (flat-file replacement is adequate for now).
Deliverable: All verification criteria verified or documented as deferred. Phase.md updated with results.
Deferred Items
| # | Description | Reason |
|---|---|---|
| E8 | Dispatcher ignores mode parameter for on-demand triggers | Spec §10.1 states scheduled agents run in disconnect mode only. On-demand monitor mode would require wiring up Ralph Wiggum in the dispatcher — defer to a future enhancement. |
| E9 | R4 (Todo/checklist MCP) was explicitly skipped | Spec marks R4 as ⏭️. Flat-file Agent_Todo.md / Erik_Todo.md is the current substitute. |