fix: prevent race conditions in SettingsManager setCwd and debounce#485
Merged
benbrandt merged 1 commit intoagentclientprotocol:mainfrom Mar 27, 2026
Conversation
Two race conditions fixed: 1. Concurrent setCwd() calls could produce duplicate file watchers because both calls cleared initialized before either completed initialize(). Added an initPromise guard so concurrent calls await the same initialization. 2. The debounce timer callback could fire after dispose(), reloading stale settings and calling onChange on a disposed manager. Added a disposed flag checked in the async callback before proceeding.
benbrandt
approved these changes
Mar 27, 2026
benbrandt
pushed a commit
that referenced
this pull request
Apr 3, 2026
🤖 I have created a release *beep* *boop* --- ## [0.25.0](v0.24.2...v0.25.0) (2026-04-03) ### Features * Add auto permission mode support ([#501](#501)) ([a161453](a161453)) * Add separate Claude and Console terminal logins ([#502](#502)) ([063cd35](063cd35)) * Update to claude-agent-sdk 0.2.91 ([#500](#500)) ([65a2230](65a2230)) ### Bug Fixes * log warnings for malformed settings files instead of silent fallback ([#486](#486)) ([ae6c388](ae6c388)) * prevent race conditions in SettingsManager setCwd and debounce ([#485](#485)) ([7506223](7506223)) * use current model's context window for usage_update size ([#412](#412)) ([d07799d](d07799d)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). Co-authored-by: acp-release-bot[bot] <246668977+acp-release-bot[bot]@users.noreply.github.com>
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
setCwd()calls could produce duplicate file watchers because both calls clearedinitializedbefore either completedinitialize(). Added aninitPromiseguard so concurrent calls await the same initialization.dispose(), reloading stale settings and callingonChangeon a disposed manager. Added adisposedflag checked in the async callback before proceeding.Follows up on #454 which fixed the missing
dispose()calls — this PR hardens theSettingsManagerlifecycle against race conditions.Test plan
npm run lintpassesdisposedflag prevents stale callback executioninitPromisededuplicates concurrentinitialize()calls