Skip to content

fix(agents): reroute recovered tasks through healthy fallback - #1556

Merged
Wibias merged 5 commits into
devfrom
fix/recovery-routed-fallback
Aug 12, 2026
Merged

fix(agents): reroute recovered tasks through healthy fallback#1556
Wibias merged 5 commits into
devfrom
fix/recovery-routed-fallback

Conversation

@Wibias

@Wibias Wibias commented Aug 12, 2026

Copy link
Copy Markdown
Owner

Summary

  • Re-run subagent model fallback after encrypted task recovery makes the task readable, this time allowing routed fallback candidates.
  • Preserve the exact preview-account result when rechecking the fallback chain.
  • Re-route route when recovery selects a different model so dispatch uses the healthy routed fallback instead of the unavailable primary.
  • Add a focused regression test for an unavailable routed primary with a healthy routed fallback.

Root cause

The initial fallback pass intentionally sets nativeFallbackOnly while the V2 task is still unreadable, so routed candidates are skipped. After recovery reparsed the now-readable request, fallback selection was not run again, leaving route bound to the unavailable routed primary.

Verification

TDD regression:

  • Before the fix (b5d8537), Cross-platform CI test 3/4 failed exactly on the new regression: expected grok-4.6, received grok-4.5.
  • After the fix (1f0d576), the same regression passes: agent task recovery fallback routing > routes a recovered task through the healthy routed fallback.
  • The repaired test 3/4 shard completed with 525 pass, 3 skip, 0 fail.
  • All four Linux test shards are green.
  • CI gates is green, including typecheck, GUI tests, privacy scan, release-helper syntax, and CLI help smoke.
  • Storage-policy, API-usage, keyring, and npm-global packaging checks shown in Cross-platform CI are green; the macOS full-test job is still running at the time of this update.

Refs #1540. Complements #1555.

@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 1331a5b0-7204-4585-982c-f56c5585bd9c

📥 Commits

Reviewing files that changed from the base of the PR and between db923d6 and 1f0d576.

📒 Files selected for processing (2)
  • src/server/responses/core.ts
  • tests/agent-task-recovery-fallback.test.ts

📝 Walkthrough

Walkthrough

Subagent fallback routing preserves the previewed Codex account, reruns fallback selection after encrypted task recovery, and rebuilds the route when the model changes. An integration test verifies routing from xai/grok-4.5 to xai/grok-4.6 after a 429.

Changes

Recovery fallback routing

Layer / File(s) Summary
Patch workflow and recovery routing
src/server/responses/core.ts
The response flow preserves the previewed fallback account, reruns fallback selection with the recovered payload, updates quota-failure tracking, rebuilds the route when the model changes, and returns routing errors when required.
Recovery fallback integration test
tests/agent-task-recovery-fallback.test.ts
The test resets recovery and fallback state, mocks recovery and provider requests, and verifies successful routing through xai/grok-4.6 after xai/grok-4.5 receives a 429.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant AgentTaskRecovery
  participant ResponsesCore
  participant FallbackRouter
  participant xAIProvider
  AgentTaskRecovery->>ResponsesCore: recover encrypted task payload
  ResponsesCore->>FallbackRouter: reevaluate fallback with recovered payload
  FallbackRouter-->>ResponsesCore: select xai/grok-4.6
  ResponsesCore->>xAIProvider: route request to xai/grok-4.6
  xAIProvider-->>ResponsesCore: return provider response
Loading

Possibly related PRs

Suggested reviewers: ingwannu, lidge-jun

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes rerouting recovered agent tasks through an available fallback model.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/recovery-routed-fallback

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown
Contributor

Deterministic PR hygiene checks passed.

@github-actions github-actions Bot added the bug Something isn't working label Aug 12, 2026
@Wibias
Wibias marked this pull request as ready for review August 12, 2026 19:46

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/server/responses/core.ts`:
- Around line 1743-1781: Update the recovery-path call to
applySubagentModelFallback so it only runs when route.codexAccountId ===
undefined, matching the initial fallback guard and preserving exact account
routing. Add a regression test covering a recovered account-qualified request
with an unavailable model, asserting that no global fallback is selected.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 7b0ab473-8ee7-43bd-be57-6d4904abcd7b

📥 Commits

Reviewing files that changed from the base of the PR and between db923d6 and 1f0d576.

📒 Files selected for processing (2)
  • src/server/responses/core.ts
  • tests/agent-task-recovery-fallback.test.ts

Comment thread src/server/responses/core.ts
@Wibias
Wibias merged commit cfc61c1 into dev Aug 12, 2026
35 of 36 checks passed
@Wibias
Wibias deleted the fix/recovery-routed-fallback branch August 12, 2026 20:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant