Skip to content

fix: prevent race conditions in SettingsManager setCwd and debounce#485

Merged
benbrandt merged 1 commit intoagentclientprotocol:mainfrom
tbounsiar:fix/settings-manager-race-conditions
Mar 27, 2026
Merged

fix: prevent race conditions in SettingsManager setCwd and debounce#485
benbrandt merged 1 commit intoagentclientprotocol:mainfrom
tbounsiar:fix/settings-manager-race-conditions

Conversation

@tbounsiar
Copy link
Copy Markdown
Contributor

Summary

  • 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.
  • 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.

Follows up on #454 which fixed the missing dispose() calls — this PR hardens the SettingsManager lifecycle against race conditions.

Test plan

  • npm run lint passes
  • All settings tests pass
  • Verified disposed flag prevents stale callback execution
  • Verified initPromise deduplicates concurrent initialize() calls

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 benbrandt enabled auto-merge (squash) March 27, 2026 12:11
@benbrandt benbrandt merged commit 7506223 into agentclientprotocol:main Mar 27, 2026
1 check passed
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants