{"record":{"id":"dc2085a3e1f0052d","repo":"dotnet/aspnetcore","slug":"circuit-state-this-statename-not-initialized","errorCode":null,"errorMessage":"Circuit state ${this._stateName} not initialized","messagePattern":"Circuit state (.+?) not initialized","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/Components/Web.JS/src/Platform/Circuits/CircuitManager.ts","lineNumber":699,"sourceCode":"  private _reject?: (reason: any) => void;\n\n  private _lastValue?: T;\n\n  public reset(): void {\n    if (this._promise) {\n      throw new Error(`Circuit state ${this._stateName} is already in progress`);\n    }\n\n    const { promise, resolve, reject } = Promise.withResolvers<T>();\n    this._promise = promise;\n    this._resolve = resolve;\n    this._reject = reject;\n    this._lastValue = this._resetValue;\n  }\n\n  public complete(value: T): void {\n    if (!this._resolve) {\n      throw new Error(`Circuit state ${this._stateName} not initialized`);\n    }\n\n    const resolve = this._resolve;\n    this._lastValue = value;\n\n    this._promise = undefined;\n    this._resolve = undefined;\n    this._reject = undefined;\n\n    resolve(value);\n  }\n\n  public fail(reason: any): void {\n    if (!this._reject) {\n      throw new Error(`Circuit state ${this._stateName} not initialized`);\n    }\n\n    const reject = this._reject;","sourceCodeStart":681,"sourceCodeEnd":717,"githubUrl":"https://github.com/dotnet/aspnetcore/blob/3600ca084e9c8b5f4174fc5e747f4c52d2100806/src/Components/Web.JS/src/Platform/Circuits/CircuitManager.ts#L681-L717","documentation":"`CircuitState.complete(value)` resolves the in-flight operation's promise. It throws if `_resolve` is undefined, i.e. no operation was started with `reset()` (or the prior operation already completed/failed and cleared the resolvers). Calling `complete` on an uninitialized state would resolve a non-existent promise, so it fails fast.","triggerScenarios":"`complete()` is called on a `CircuitState` whose `reset()` was never called, or was already completed/failed (which clears `_resolve`).","commonSituations":"A server callback (`JS.RenderBatch`/`JS.RequestPause` completion) firing for a state that was never started or already settled; a logic bug double-completing a pause/resume; an error path that already called `fail()` then a success path calls `complete()`.","solutions":["Always pair `reset()` with exactly one terminal call (`complete` or `fail`); guard terminal calls with `isInprogress()`.","Ensure error and success paths cannot both run — use try/catch/finally that resolves the state once.","Add `if (state.isInprogress()) state.complete(...)` around server-driven completions to tolerate out-of-order messages.","Trace which SignalR handler invoked `complete` to find the duplicated/out-of-order settlement."],"exampleFix":"// before\nthis._pausingState.complete(true); // throws if not in progress\n\n// after\nif (this._pausingState.isInprogress()) {\n  this._pausingState.complete(true);\n}","handlingStrategy":"validation","validationCode":"function safeComplete<T>(s: { isInprogress(): boolean; complete(v: T): void }, v: T) {\n  if (s.isInprogress()) s.complete(v);\n}","typeGuard":null,"tryCatchPattern":"try { state.complete(value); }\ncatch (e) { if (/not initialized/.test(e.message)) { /* already settled - ignore */ return; } throw e; }","preventionTips":["Pair reset() with exactly one terminal call.","Guard completions with isInprogress().","Make success and error paths mutually exclusive.","Tolerate out-of-order server messages with an isInprogress check."],"tags":["circuit","state-machine","lifecycle","blazor-server"],"backgroundTag":null,"analyzedSha":"3600ca084e9c8b5f4174fc5e747f4c52d2100806","analyzedAt":"2026-08-11T16:32:30.678Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}