GeezerVison is showing github.com — feat(core): time-based model availability with fallback by ooaklee · Pull Request #64222 · anomalyco/opencode
Conversation
ooaklee
commented
Nov 16, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
Issue for this PR
Related to #63712. Replaces #63728, automatically closed for an incomplete PR template.
Closes #63712
Type of change
- Bug fix
- New feature
- Refactor / code improvement
- Documentation
What does this PR do?
Adds opt-in model availability windows and configured fallbacks, evaluated before each LLM step. Windows use an IANA timezone and include the start but exclude the end. Equal endpoints cover the whole local calendar day; overnight windows retain the starting day's filter.
Blocked models follow fallback chains, including across providers with the target provider's credentials. Invalid chains return a no-route error, and plugin overrides are availability-checked.
The prompt footer and model picker retain the configured selection; the assistant message footer and cost accounting reflect the serving fallback. No UI changes are introduced. Behavior is enabled by model-level availability; there is no separate experimental flag.
How did you verify your code works?
Validated d128a51e4b, including the merge of dev at 26f2522e60:
- 20 focused tests passed across ten randomized runs (200 executions), plus 378 wider session/resolver regressions.
- Boundary tests fail against the previous evaluator and pass with the fix.
- The session suite now uses real services for five core cases, reduced from 328 to 122 lines.
- Root
bun run check, core bun run typecheck:tsc, protocol bun run check:generated, and site bun typecheck / bun run build passed.
No live-provider end-to-end test was run for this update.
Screenshots / recordings
Not applicable; no UI changes.
Checklist
- I have tested my changes locally
- I have not included unrelated changes in this PR
Added by the opencode bot (AI-generated).
Related: #63712, #48991
Public API: adds optional availability to model config and Model.Info/OpenAPI, plus two new session error types; blocked models returned by experimental.model.resolve are now ignored (backwards compatible)
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
…yers
- ModelBlockedByAvailabilityError now carries a reason code (no-fallback,
fallback-not-found, cycle-detected, depth-exceeded, malformed-fallback)
and the offending fallback ref, with a message per case
- detect fallback cycles explicitly via a visited set instead of only
relying on the three-hop depth cap
- rebuild session-model-availability tests on a per-test layer factory so
agent/resolver stub state is no longer shared between tests
- document that fallback substitution is logged server-side but not
surfaced in the UI, and note chain limits and cycle reporting
- regenerate the OpenAPI spec for the new availability schemas
…ion in tests
- extract FALLBACK_HOP_LIMIT so the depth-exceeded message prints the
actual limit instead of undefined
- read the blocked reason via Cause.findErrorOption + instanceof instead
of parsing the serialized error, and assert the depth-exceeded message
- gate the experimental.model.resolve hook: a hook-chosen model that a
window currently blocks is ignored and the availability-approved
selection (or its fallback) is used, with a log line; same-provider
restriction and unchanged-model fast path preserved
- bound the per-timezone Intl.DateTimeFormat cache (32 entries,
evict-oldest with recency refresh) so catalog input cannot grow it
- validate Model.Availability start/end against the HH:mm pattern in the
schema (defense in depth) and regenerate the OpenAPI spec
- drop the unreachable malformed-fallback branch after Model.Ref.parse
- keep the provider overlay's days array copy in spread style
- docs: start === end matches one minute; windows evaluate as wall-clock
in the named zone with DST per its rules; model-level availability
replaces catalog/plugin-provided availability; cost accounting uses
the effective (fallback) model while the display stays configured
- tests: hook override blocked -> fallback wins, hook override allowed ->
honored, #variant fallback ref through the runner, and a wrapping
window with only its head day listed
The experimental.model.resolve hook's availability gate looked the
override model up only in the picker list; a same-provider target hidden
from that list passed as 'unknown' and the resolver could still load it
from the broader catalog, letting a hidden model with a blocking window
serve the request. Look the override up through Model.Service.get (the
full catalog) and availability-check that instead; a blocked override
still falls back to the availability-approved selection.
Tests: same-provider hook override to a blocked (picker-listed) model,
a blocked model hidden from the picker, and an allowed model hidden
from the picker; the layer now stubs Model.Service with a catalog
option.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The feature works as described: while a window blocks a model, its configured fallback serves the request. I ran OpenCode from source on the base and on this branch with a simulated model blocked all day and a fallback set. On the base the availability key is ignored. With this change the request goes to the fallback, and the message footer shows the fallback model. The new tests, the wider packages/core session and runner suites, a tsc -b type check of core and check:generated all pass.
Public API (all additive, backwards compatible):
- Config: optional
providers.<id>.models.<id>.availability with mode, windows[] (days, start, end), timezone and fallback.
Model.Info: optional availability field, also in the OpenAPI spec (Model.Availability, Config.Model.Availability.Window).
- New session errors:
ModelBlockedByAvailabilityError and ModelAvailability.TimezoneError.
- Plugin hook: models returned by
experimental.model.resolve are now ignored while a window blocks them.
Concerns, details inline:
- The window
end is inclusive by minute. This is worth settling before it becomes a config contract.
- The docs say the UI keeps showing the configured model, but the message footer shows the fallback.
test/session-model-availability.test.ts is 328 lines of mostly stubs (resolver, agents, hooks and catalog, with as never casts). Please cut it down to a few core cases: a fallback, a chain of fallbacks, a cycle, no fallback, and a hook override that is blocked.
Related: #63712, #48991


Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both earlier points are fixed. Windows now include start and exclude end, and equal endpoints cover the whole local day. The docs now say which parts of the UI show the configured model and which show the fallback. The session test is now small and uses real services. I re-ran the new tests, the core type check, check:generated, and the TUI with a blocked simulated model, and the fallback still served the request. The public API is the same as in my last review: optional availability on model config and on Model.Info (with its OpenAPI entries), two new session errors, and availability checks on experimental.model.resolve overrides. All of it is backwards compatible. No new concerns.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Addressed the remaining test-simplification point from the review in d128a51. The session suite is now 122 lines with the five requested cases: fallback, fallback chain, cycle, no fallback, and blocked hook override. It uses the real runner, resolver, catalog and hooks through existing fixtures, without local service stubs or as never casts. The hidden-hook case also verifies that the same hook succeeds once its target is unblocked.
Validation passed: 20 focused tests across ten randomized runs, 378 wider regressions, repository checks, core TypeScript, generated API checks and the full site build. The reduction intentionally removes direct tests for some additional fallback/selection cases; it does not change those production paths. The two inline points are addressed in their respective threads.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This branch has not been deployed
No deployments
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
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.
|