fix(config): recover from corrupted config.toml instead of crashing boot#1537
Draft
graycyrus wants to merge 6 commits into
Draft
fix(config): recover from corrupted config.toml instead of crashing boot#1537graycyrus wants to merge 6 commits into
graycyrus wants to merge 6 commits into
Conversation
On Windows + CEF, `tauri.conf.json` declares the main window with `visible: false` (so we can restore window state before the first paint). When `setup()` later calls `window.show()`, Windows transitions the window to the foreground but does not synthesize the `WM_SETFOCUS` that CEF's window subclass needs in order to fire `BrowserHost::OnSetFocus(true)` and propagate the focused state to the renderer. The renderer's `is_keyboard_input_target` flag is left in its initial `false` state. The user-visible symptom: cold launch -> click chat textarea -> cursor blinks (mouse routing works) but typing is silently dropped. The only known workaround was to click outside the app window and click back, which produces a real `WM_KILLFOCUS`+`WM_SETFOCUS` cycle that CEF's window handler observes as a state transition. Calling `webview.set_focus()` from Rust does not fix this: it dispatches `WebviewMessage::SetFocus` -> `host.set_focus(1)`, which is idempotent from CEF's host point of view (the host already considers itself focused because the OS window is foreground). CEF's renderer only wires keyboard routing on an observed state *transition*, not a state assertion. The fix mimics the manual click-outside / click-back gesture in code: 300ms after `window.show()`, spawn an async task that `minimize()`s the window (forces `WM_KILLFOCUS` -> `host.set_focus(0)`), waits 80ms for Windows to process the message, then `unminimize()`s (forces `WM_SETFOCUS` -> `host.set_focus(1)`). Trailing explicit `window.set_focus()` + `webview.set_focus()` calls serve as belt-and-suspenders in case the minimize/restore raced ahead of CEF's browser-create. Side effect: a brief minimize/restore animation (~120ms) immediately after the window first appears on cold launch. A cleaner fix would expose `BrowserHost::SetFocus(false)` in the vendored tauri-cef so we could cycle focus without touching window state, but that requires vendor surgery; this is the minimum viable change. Also pulls in the openhuman-1475 worktree's PATH/MSVC improvements to `scripts/run-dev-win.sh` so a clean checkout can `pnpm dev:app:win` without a pre-warm cache: probes Git-for-Windows install for cygpath when not on PATH, restores the Windows-side PATH that `/etc/profile` would otherwise wipe, and prepends the VS Installer dir to cmd's PATH before invoking vcvars64 (so vswhere is reachable and the Windows SDK LIB/INCLUDE entries land in the captured env). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
On TOML parse failure, try loading from .bak backup before resetting to defaults. Stop deleting .bak after successful save so a last-known-good config is always available. Add #[serde(default)] to default_temperature so schema additions don't break existing config files. Closes tinyhumansai#1523
Contributor
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Comment |
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.
Summary
.bakbackup before resetting toConfig::default().bakafter successful save so a last-known-good config is always available for recovery#[serde(default = "default_temperature_value")]todefault_temperatureso schema additions don't break existing config filesload_from_default_paths(debug utility, zero external callers)Recovery flow (after this PR)
What's NOT changed (and why)
#[serde(deny_unknown_fields)]— would break downgrades (newer config has fields old version doesn't know)active_workspace.toml/active_user.tomlparsing — those already handle corruption gracefullyTest plan
test_corrupt_config_no_backup_falls_back_to_defaultstest_corrupt_config_valid_backup_recoverstest_corrupt_config_corrupt_backup_falls_back_to_defaultstest_missing_default_temperature_uses_correct_defaulttest_save_preserves_backup_filetest_save_then_corrupt_then_recoverpnpm typecheck— passpnpm lint— pass (0 errors)pnpm format:check— passpnpm build— passcargo check— passcargo fmt --check— passPR checklist
[config]prefix on all recovery pathsCloses #1523