fix(gateway): debounce restart with single-flight queue#248
Merged
1186258278 merged 1 commit intomainfrom Apr 24, 2026
Merged
Conversation
Root cause for #243 / #244 / #240: model edits trigger api.restartGateway() with only 300ms debounce. Fast consecutive edits stack up restart calls, creating zombie Gateway processes, failed restarts, and CPU fan spikes. Layer A (frontend): - New src/lib/gateway-restart-queue.js: 3s debounce + single-flight lock + reschedule on in-flight request - Refactor src/pages/models.js doAutoSave: write config immediately, schedule restart via queue with 'Apply now' toast button - Subscribe to queue state for unified success/failure toast - Add i18n: models.configQueued, models.applyNow Layer B (backend): - src-tauri/src/commands/config.rs: wrap restart_gateway / reload_gateway with tokio::sync::Mutex + 2s cooldown - Cargo.toml: add tokio 'sync' feature - scripts/dev-api.js: same guard for Web mode (inflight promise reuse + 2s cooldown) Effects: - 10 rapid edits within 3s -> 1 restart (was 10+ with races) - Backend serializes concurrent restart calls, no zombie spawns - User sees single 'Apply now' toast instead of restart storm Refs #243 #244 #240
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.
Problem
Root cause for #243 / #244 / #240: when users edit models on the config page,
api.restartGateway()is called with only a 300ms debounce. Fast consecutive edits stack up restart calls, which leads to:Hidden-starton Windows even after Gateway isready(ClawPanel 在 Windows 上会在 Gateway 已成功 ready 后重复 Hidden-start / ClawPanel repeatedly hidden-starts Gateway on Windows after successful ready #244)Fix — Layer A + B
Layer A (frontend,
src/lib/gateway-restart-queue.js+src/pages/models.js)scheduleGatewayRestartwith 3s debounce + single-flight lockdoAutoSavenow writes config immediately but schedules restart via queueApply nowtoast button instead of a restart stormLayer B (backend,
config.rs+dev-api.js)restart_gateway/reload_gatewaywithtokio::sync::Mutex(single-flight)dev-api.js) mirrors the same guard using in-flight promise reuseConfig
Cargo.toml: addtokio[sync]featuresrc/locales/modules/models.js: new i18n keysconfigQueued+applyNowEffects
Verification
npm run buildpassescargo checkpassescargo fmt --checkpassescargo clippy -D warningspassesOut of scope (follow-up PRs)
Layers C / D / E from the design doc will land separately:
Refs
Closes #243 (pending verification)
Fixes part of #244 (Hidden-start repeats — reduced via restart frequency cap)
Fixes #240 (auto-restart failures on Ubuntu — reduced restart pressure)