Skip to content

fix(ai-orchestrator): ensure /query re-routes via mesh router before active persona#141

Merged
SteveJRobertson merged 3 commits into
mainfrom
140-fix-query-mesh-router-rerouting
Jun 4, 2026
Merged

fix(ai-orchestrator): ensure /query re-routes via mesh router before active persona#141
SteveJRobertson merged 3 commits into
mainfrom
140-fix-query-mesh-router-rerouting

Conversation

@SteveJRobertson

Copy link
Copy Markdown
Owner

Summary

Fixes routing bias and Anthropic 400 prefill errors caused by /query commands bypassing the mesh router entirely.

Previously, START used a conditional edge that dispatched directly to next_recipient (the currently active persona). If that persona was a11y (Claude 4.6), it would answer the question before the mesh router had a chance to reclassify it — and the assistant-prefill error would fire because the last message in history was from a previous mesh router run.

This PR refactors the graph topology to route START → mesh_router deterministically. Every graph entry now passes through query classification first. The mesh router's heuristic gate (skips LLM when no ? or @isolate- in message) keeps the performance cost negligible for routine linear workflows.

Closes #140

Changes

  • libs/ai-orchestrator/src/orchestrator/langgraph.ts: Replace addConditionalEdges(START, routeByRecipient, routeMap) with addEdge(START, 'mesh_router'). The existing mesh_router → routeByRecipient conditional edge remains unchanged, so post-persona routing is unaffected.

  • apps/webhook-listener/src/commands/query.ts: Add pause_context: null to the graph.invoke() payload in handleQuery. This clears any active stalemate pause so the graph routes through mesh_router instead of immediately hitting __pause__.

  • libs/ai-orchestrator/src/__tests__/graph.spec.ts: New topology test — start with next_recipient: 'qa' and a query message; mock LLM reclassifies to 'po'; assert qa is never visited (proves mesh_router ran before dispatch).

  • apps/webhook-listener/src/commands/query.spec.ts: Replace two stale tests that asserted pause_context is NOT cleared with updated tests that assert the new behaviour (pause_context: null is always passed explicitly).

Copilot Review Triage

Before opening the PR, confirm each tier has been addressed:

  • Blocker — No security or correctness issues. HMAC verification untouched. No secrets in logs. Topology change is additive (one line swap). All 490 tests pass.
  • Majorrun() vs invoke() architectural distinction documented in the new test comment. No regressions in existing mesh router, persona, or checkpoint tests.
  • Minor — No missing test coverage gaps introduced. Both conflicting query.spec.ts tests replaced with tests that capture the correct new behaviour and reference issue fix: ensure /query re-routes via mesh router before executing currently active persona #140.
  • Nit — Comments updated in both changed source files to replace stale explanations with accurate ones referencing the new topology.

Deferred follow-ups

None

…active persona

- Replace START → routeByRecipient conditional edge with a deterministic
  START → mesh_router edge in the LangGraph topology. Every graph entry
  now passes through mesh_router first, so /query commands are classified
  before any persona executes.

- Add pause_context: null to graph.invoke() in handleQuery so a
  mesh_stalemate (or any other pause) is cleared when a new question
  arrives, preventing the graph from routing immediately to __pause__.

- Update query.spec.ts to assert the new behaviour: pause_context is
  always explicitly null in the invoke payload.

- Add graph.spec.ts topology test: START → mesh_router reclassifies
  next_recipient before persona executes (qa → po scenario).

Closes #140
Copilot AI review requested due to automatic review settings June 4, 2026 14:55
@vercel

vercel Bot commented Jun 4, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
isolate-ui Ignored Ignored Preview Jun 4, 2026 3:07pm

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Refactors the LangGraph topology in libs/ai-orchestrator so every graph entry deterministically flows through mesh_router first, aiming to prevent /query executions from dispatching directly to the currently-active persona and to avoid the reported Anthropic “assistant prefill” error patterns.

Changes:

  • Updates the orchestrator graph topology to route START → mesh_router deterministically before any persona dispatch.
  • Updates /query to explicitly clear pause_context in the graph.invoke() payload so paused threads don’t immediately route to __pause__.
  • Adds/updates unit tests to validate the new start-routing topology and the new /query invocation payload behavior.

Reviewed changes

Copilot reviewed 4 out of 20 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
libs/ai-orchestrator/src/orchestrator/langgraph.ts Changes graph topology to ensure START always routes through mesh_router before dispatch.
libs/ai-orchestrator/src/tests/graph.spec.ts Adds a topology test intended to ensure mesh_router executes before persona dispatch on entry.
apps/webhook-listener/src/commands/query.ts Passes pause_context: null when invoking the graph for /query, intending to force re-routing via mesh_router.
apps/webhook-listener/src/commands/query.spec.ts Updates tests to assert /query always passes pause_context: null.
logs/webhook-listener-out-0.log Log artifact included in PR metadata (cleanup/untracking implied).
logs/webhook-listener-out-1.log Log artifact included in PR metadata (cleanup/untracking implied).
logs/webhook-listener-out-2.log Log artifact included in PR metadata (cleanup/untracking implied).
logs/webhook-listener-out-3.log Log artifact included in PR metadata (cleanup/untracking implied).
logs/webhook-listener-out-4.log Log artifact included in PR metadata (cleanup/untracking implied).
logs/webhook-listener-out-5.log Log artifact included in PR metadata (cleanup/untracking implied).
logs/webhook-listener-out-6.log Log artifact included in PR metadata (cleanup/untracking implied).
logs/webhook-listener-out-7.log Log artifact included in PR metadata (cleanup/untracking implied).
logs/webhook-listener-error-0.log Removes tracked error log contents (cleanup).
logs/webhook-listener-error-1.log Removes tracked error log contents (cleanup).
logs/webhook-listener-error-2.log Removes tracked error log contents (cleanup).
logs/webhook-listener-error-3.log Removes tracked error log contents (cleanup).
logs/webhook-listener-error-4.log Removes tracked error log contents (cleanup).
logs/webhook-listener-error-5.log Removes tracked error log contents (cleanup).
logs/webhook-listener-error-6.log Removes tracked error log contents (cleanup).
logs/webhook-listener-error-7.log Removes tracked error log contents (cleanup).

Comment thread apps/webhook-listener/src/commands/query.ts Outdated
Comment thread libs/ai-orchestrator/src/__tests__/graph.spec.ts Outdated
…est title

- Update query.ts comment to acknowledge that mesh_router currently returns
  null for generic queries (only classified when directed at specific persona).
  Add note about future improvement: update MESH_SYSTEM_PROMPT to classify
  generic queries to most appropriate persona.

- Rename graph.spec.ts test title from 'on invoke' to 'on run' to accurately
  reflect which API the test uses. Clarify why run() is needed (vs invoke()).
@SteveJRobertson SteveJRobertson merged commit d458080 into main Jun 4, 2026
6 checks passed
@SteveJRobertson SteveJRobertson deleted the 140-fix-query-mesh-router-rerouting branch June 4, 2026 15:08
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.

fix: ensure /query re-routes via mesh router before executing currently active persona

2 participants