← Back to Pull requests

Keep @role chat working after a failover #256

Open
unknown opened this pull request with 298 lines diff across 3 files
View on GitHub
unknown unknown commented on Oct 22, 2026 04:21 UTC
Author

Problem

After a failover, @<role> chat could not reach the role. Seen live on 2026-10-21: the planner failed over from agy (429 quota) to Claude, and @planner ... went to the backend side session with "No finished planner session is recorded".

Cause: _run_with_failover clears the result's session_id, on purpose, so no later dispatch resumes a session that belongs to another agent. But the dispatch record and the in-memory chat entry then stored the configured primary provider (antigravity) with session_id: null, so the @role lookup had nothing to resume.

Fix

  • DispatchResult and SubagentResult gain fallback_ran and fallback_session_id. _run_with_failover sets them on both its role and support-role branches. session_id stays None and session_invalidated stays set, so dispatch resume is unchanged.

  • New _dispatched_session() in orchestrator.py returns the provider, session id, and fallback flag of the agent that actually ran. _remember_role_session (chat entry) and _record_role_dispatch (dispatch record) use it.

  • RoleDispatch gains a fallback flag. _role_session_lookup in __main__.py resumes a fallback session with the fallback's AgentConfig (provider, binary, model), so chat launches the CLI that owns the session.

  • The finalizer goes through the epic-close ledger, not the shared dispatch path. EpicCloseResult carries the same fields, and _remember_finalizer_session uses them, so @finalizer works after a failover too.

  • CONFIGURATION.md (Fallback Agents rules) and CHANGELOG.
  • This covers every role dispatch: planner, tpm, backend, frontend, single auditor, and the finalizer.

    Not covered: the audit fan-out reviewers. They are read-only, answer in JSON, and keep no chat session today, so their fallback behavior is unchanged.

    Testing

  • python -m pytest tests -q: 4580 passed, 46 skipped.

  • New and updated tests:

  • - failover results keep the fallback session id (role and support-role);
    - planner, backend, and tpm failovers keep the fallback's provider and session for chat, and the lookup returns the fallback config;
    - the dispatch record names the fallback;
    - a dispatch that did not fail over still records and resumes the primary;
    - a finalizer failover keeps the fallback session for @finalizer.

    🤖 Generated with Claude Code

    Diff: 298 lines (+223 / -75) across 3 files Reviewer: chatgpt-codex-connector[bot] Review duration: 3m
    All Vouch review confidence checks passed
    Residual risk 0.34 = Change Risk (0.45) × (1 − Review Confidence (0.24)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.45 · 298 lines diff across 3 files
    0.45
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 43% · Reviewer familiarity: 35%
    24%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Shallow Review Depth shallow_review_depth
    0.344
    Diff Size diff_size
    0.341
    Ai Authored ai_authored
    0.050
    Real PR Conversation Timeline
    1 comments
    "Review active on #256"
    general weight: 0.35
    Assignees
    Unassigned
    Labels
    risk: low confidence: 24.4% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 45% (MEDIUM) · Higher = larger blast radius
    45%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 24.4% · Lower = rushed or shallow review
    24.4%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 34% · Safe to merge
    34%