fix(config): keep startup LLM fallback in-memory only (#3229)#3324
Merged
Conversation
A transient hydration failure (DB read race, secrets decryption hiccup) during startup used to overwrite the user's persisted llm_backend with "nearai" and delete selected_model from the DB, turning a one-off fallback into a permanent reversion of the configured provider. The fallback now stays in-memory: the runtime still demotes to NearAI to keep the instance usable (#2514), but the user's DB-persisted selection is preserved so the next restart with credentials available picks up their original config. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Contributor
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
Empty commit to refresh GitHub's pull/3324/head ref, which was not published when the PR was opened, blocking the regression-test enforcement workflow's git fetch. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Stop fetching `refs/pull/${PR_NUMBER}/head:pr-head` and source the head
SHA from `github.event.pull_request.head.sha` instead. GitHub occasionally
fails to publish `refs/pull/N/head` for in-repo PRs (#3324 hit this — the
workflow could not get past its first git command, blocking the
regression-test enforcement check before it ran any of its actual
heuristics). The merge commit produced by actions/checkout has the head
SHA as its second parent and is fetched in full by fetch-depth: 0, so
the SHA is always locally reachable.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Prevents the startup-time “fallback to NearAI” safety mechanism from permanently overwriting a user’s persisted LLM provider/model in the DB when secrets/config hydration is temporarily unavailable, while keeping the crash-loop prevention behavior (#2514) intact.
Changes:
- Removed the post-fallback DB synchronization in
Config::resolve_llm_with_secrets_innerso the fallback remains in-memory only (#3229). - Updated NearAI fallback commentary in
LlmConfig::resolve_nearai_fallbackto reflect the new persistence behavior. - Adjusted the regression-test enforcement workflow to use the PR head SHA directly instead of fetching
refs/pull/N/head.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/config/mod.rs | Stops persisting fallback backend/model into DB; adds regression test ensuring DB row is preserved on startup fallback. |
| src/config/llm.rs | Updates fallback comments to reflect in-memory-only behavior for selected_model. |
| .github/workflows/regression-test-check.yml | Makes the workflow more robust by comparing against the PR head SHA from the event payload. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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 #3229.
Summary
llm_backendwithnearaiand deleteselected_modelfrom the DB, turning a one-off fallback into a permanent reversion of the configured provider. After the fix, the fallback stays in-memory: the runtime still demotes to NearAI to keep the instance usable (Issue: Incomplete Provider Configuration Causes Instance Startup Failure (Non-TEE) #2514 crash-loop prevention is preserved), but the user's DB row is left untouched, so the next restart with credentials available picks up their original config.Config::resolve_llm_with_secrets_inner, plus the now-unusedfallback_fired/normalize_backendhelpers and their five unit tests (those existed solely to gate the deleted write). Net-88lines on the bug fix.LlmConfig::resolve_nearai_fallbackthat referenced the removed DB sync.Scope expansion: workflow brittleness fix
While debugging this PR's CI, GitHub failed to publish
refs/pull/3324/head(confirmed bygit ls-remoteagainst origin — onlypull/3324/mergeexists; comparable open PRs have both refs). Theregression-test-check.ymlworkflow was hard-failing ongit fetch origin pull/N/head:pr-headbefore any of its actual checks could run. This was a pre-existing brittleness — the workflow assumesrefs/pull/N/headis always published, which GitHub does not guarantee.Bundled fix: derive the head SHA from
github.event.pull_request.head.sha(always present in the event payload) instead of fetchingrefs/pull/N/head. The merge commitactions/checkoutalready produces withfetch-depth: 0has the head SHA as its second parent, so it's locally reachable. Future PRs hit by the same GitHub ref-publishing bug will not need this manual unsticking.The empty
ci: re-trigger workflowscommit in the history is residue from earlier debugging — it pushed a refreshed SHA to nudge GitHub into publishing the missing ref (didn't work, hence the workflow change).Test plan
cargo fmtcargo clippy --all --benches --tests --examples --all-features— zero warningscargo test --lib— 5614 passedconfig::tests::startup_fallback_must_not_overwrite_persisted_user_backend— seedsllm_backend = "openrouter"+selected_model = "openai/gpt-4o-mini", calls the startup path with no secrets store (forces the unusable-config fallback), asserts the runtime falls back to NearAI and the DB row is unchanged. Would have failed onmain(the row got rewritten tonearaiandselected_modeldeleted).scripts/pre-commit-safety.shpasses🤖 Generated with Claude Code