Repository navigation
fix(core): coalesce concurrent Config.initialize() calls #11037
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2991,14 +2991,24 @@ export class Config { | |
| } | ||
|
|
||
| /** | ||
| * Must only be called once, throws if called again. | ||
| * Must only be called once, throws if called again after the first call | ||
| * settled. Callers arriving while the first call is still in flight join | ||
| * that flight instead of throwing. | ||
| * @param options Optional initialization options including sendSdkMcpMessage callback | ||
| */ | ||
| async initialize(options?: ConfigInitializeOptions): Promise<void> { | ||
| if (isDerivedConfig(this)) { | ||
| throw new Error('Derived Configs cannot be initialized'); | ||
| } | ||
| if (this.initialized) { | ||
| // Joining the in-flight run matters: callers that swallow the old | ||
| // throw (the OpenTUI submit path, slash-command loading) proceeded on | ||
| // a config whose chat had not started yet, and the first prompt died | ||
| // with "Chat not initialized" (#11002). | ||
| if (!this.initializationSettled) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Confirmed — Suggestion] R1-1 + R1-4: The join branch silently drops the joining caller's
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Confirmed — Suggestion] R1-2: |
||
| await this.initializationPromise; | ||
| return; | ||
| } | ||
| throw Error('Config was already initialized'); | ||
| } | ||
| if (this.shutdownRequested) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Confirmed — Suggestion] R1-3: The mutation
!this.initializationSettled→!this.initializationSucceededsurvives the added tests (ci-bot mutation witness). After a failed settle,initializationSucceededstays false, so the mutant re-enters the join branch and callers get the stale startup error instead of'Config was already initialized'. Fix: add at the end of the failure test: