Repository navigation
feat: advance the fallback chain after inference failures (#6) - #9
Merged
Merged
Conversation
`failover()` selected with `chain.find(...)` over availability and cooldown only. The first chain entry stayed eligible forever, so every `session.execution.failed` moved the session to it again until `maxAttempts` ran out and later entries, including other providers, were never reached. - Per session, remember the refs already tried in this failure sequence and the ref the session is on (`session.model.selected`, `session.step.started`); selection skips both. - A completed switch records the new ref immediately instead of waiting for the matching `model.selected` event, which can arrive after the next failure. - `attempts` is now consumed only when `switchModel` resolves. A rejected switch cools the model down and leaves the chain position and budget alone, so the next failure picks the entry after it. - A failed inference does not cool the model down: it advances this session only, so a sibling session can still use the model. Cooldown stays reserved for a failed switch, per the issue's "keep them separate". - A sequence ends on `session.execution.succeeded` / `.interrupted` (state reset, so the next failure starts at the top of the chain) and on `session.deleted` (state dropped). - `event.data?.error`: a malformed failed event no longer throws inside the event loop where the outer catch would swallow the subscription. Tests: five new cases (advance, no bounce-back to the failed model, reset after success, per-session isolation, failed switch does not consume an attempt). Three fail against the previous implementation, verified by reverting the corresponding lines.
nabheet
marked this pull request as ready for review
October 31, 2026 04:03
|
Beta prerelease published: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #6.
Problem
failover()picked withchain.find(...)over availability and cooldown only. The first chain entry stayed eligible forever, so everysession.execution.failedmoved the session to it again untilmaxAttemptsran out; later entries, including other providers, were never reached.Fix
session.model.selected,session.step.started). Selection skips both.model.selectedevent, which can arrive after the next failure.attemptsis consumed only whenswitchModelresolves. A rejected switch cools the model down and leaves the chain position and the budget alone, so the next failure picks the entry after it (previously the attempt was consumed before the switch).session.execution.succeeded/.interruptedend the sequence, so the next failure starts at the top of the chain again;session.deleteddrops the session's state.event.data?.error— a malformed failed event no longer throws inside the loop, where the outercatch {}would silently end the subscription.Tests
Five new cases: advance through the chain; never return to the model that just failed; fresh state after success; per-session isolation; a failed switch does not consume an attempt.
Proven against the old implementation rather than assumed:
index.jsnpm test→ 13/13 pass.npm run lint→ clean (biome + markdownlint).Review
Adversarial pass found one blocker and fixed it: the selection originally added only refs the plugin had switched to, so with
[one, two, three]and the session onone, the second failure returned toone. The failed model is now added to the tried set, and a regression test emitsmodel.selectedto reproduce exactly that path.Also fixed from the review:
event.data?.error, the README's "four methods" count, and the undocumented cooldown decision (now stated: an inference failure advances one session rather than freezing a model for everyone).Scope
Only #6. The three per-session maps clear on success/interruption/deletion; they are not otherwise expired, so a long-lived server retains one small entry per live session, which matches how session state is expected to live. Not addressed here:
busyis now redundant because the event loop is serial — left in place rather than widening the diff.This repo publishes a patch on every push to
main, so merging cuts a release.