(sessionId: string)
| 427 | } |
| 428 | |
| 429 | claimExecution(sessionId: string): RuntimeExecutionClaim { |
| 430 | if (this.stopIntents.has(sessionId)) { |
| 431 | throw new Error(`Session ${sessionId} is stopping and cannot admit a new execution`); |
| 432 | } |
| 433 | let resolveSettled!: () => void; |
| 434 | let rejectSettled!: (error: unknown) => void; |
| 435 | const settled = new Promise<void>((resolve, reject) => { |
| 436 | resolveSettled = resolve; |
| 437 | rejectSettled = reject; |
| 438 | }); |
| 439 | // A failed claim may have no concurrent stop subscriber; stop still observes this same promise. |
| 440 | void settled.catch(() => undefined); |
| 441 | const abortController = new AbortController(); |
| 442 | const cancellation = new RuntimeExecutionCancellation(sessionId); |
| 443 | const handle: RuntimeExecutionClaim = { |
| 444 | sessionId, |
| 445 | stopSignal: abortController.signal, |
| 446 | isStopRequested: () => state.stopIntent !== undefined, |
| 447 | release: () => this.releaseExecutionClaim(state), |
| 448 | }; |
| 449 | const state: PendingExecutionClaim = { |
| 450 | handle, |
| 451 | sessionId, |
| 452 | abortController, |
| 453 | cancellation, |
| 454 | admissionBarrier: this.sessionMutationTails.get(sessionId) ?? Promise.resolve(), |
| 455 | settled, |
| 456 | resolveSettled, |
| 457 | rejectSettled, |
| 458 | phase: 'pending', |
| 459 | }; |
| 460 | let claims = this.executionClaims.get(sessionId); |
| 461 | if (!claims) { |
| 462 | claims = new Set(); |
| 463 | this.executionClaims.set(sessionId, claims); |
| 464 | } |
| 465 | claims.add(state); |
| 466 | this.executionClaimStates.set(handle, state); |
| 467 | return handle; |
| 468 | } |
| 469 | |
| 470 | async runSessionAdmissionMutation<T>( |
| 471 | sessionIds: readonly string[], |
no test coverage detected