|
7 | 7 | ProjectId, |
8 | 8 | ProviderDriverKind, |
9 | 9 | ProviderInstanceId, |
| 10 | + ProviderTurnId, |
10 | 11 | ThreadId, |
11 | 12 | TurnItemId, |
12 | 13 | } from "@t3tools/contracts"; |
@@ -459,3 +460,49 @@ it.effect("thread.stop on a finished thread refuses a late agent watch", () => |
459 | 460 | assert.deepEqual(yield* threadState(threadId), { runs: ["completed"], watched: [] }); |
460 | 461 | }).pipe(Effect.provide(testLayer)), |
461 | 462 | ); |
| 463 | + |
| 464 | +it.effect("thread.stop marks a turn it cannot interrupt so a late agent watch is refused", () => |
| 465 | + Effect.gen(function* () { |
| 466 | + const orchestrator = yield* Orchestrator.OrchestratorV2; |
| 467 | + const projections = yield* ProjectionStore.ProjectionStoreV2; |
| 468 | + const threadId = ThreadId.make("thread:stop-lost-session"); |
| 469 | + yield* createWatchingThread(threadId, 11); |
| 470 | + yield* send(threadId, "work", "start_immediately"); |
| 471 | + const now = yield* DateTime.now; |
| 472 | + const run = (yield* orchestrator.getThreadProjection(threadId)).runs[0]!; |
| 473 | + // The turn is running, but its provider session is gone, so the interrupt fails. |
| 474 | + yield* projections.apply({ |
| 475 | + id: EventId.make("event:stop-lost-session:running"), |
| 476 | + type: "run.updated", |
| 477 | + threadId, |
| 478 | + runId: run.id, |
| 479 | + occurredAt: now, |
| 480 | + payload: { ...run, status: "running", startedAt: now }, |
| 481 | + }); |
| 482 | + yield* projections.apply({ |
| 483 | + id: EventId.make("event:stop-lost-session:turn"), |
| 484 | + type: "provider-turn.updated", |
| 485 | + threadId, |
| 486 | + occurredAt: now, |
| 487 | + payload: { |
| 488 | + id: ProviderTurnId.make("provider-turn:stop-lost-session"), |
| 489 | + providerThreadId: run.providerThreadId!, |
| 490 | + nodeId: run.rootNodeId!, |
| 491 | + runAttemptId: run.activeAttemptId!, |
| 492 | + nativeTurnRef: null, |
| 493 | + ordinal: 1, |
| 494 | + status: "running", |
| 495 | + startedAt: now, |
| 496 | + completedAt: null, |
| 497 | + }, |
| 498 | + }); |
| 499 | + |
| 500 | + yield* orchestrator.dispatch({ |
| 501 | + type: "thread.stop", |
| 502 | + commandId: CommandId.make("stop-lost-session"), |
| 503 | + threadId, |
| 504 | + }); |
| 505 | + assert.isTrue(Exit.isFailure(yield* Effect.exit(watch(threadId, 12)))); |
| 506 | + assert.deepEqual(yield* threadState(threadId), { runs: ["running"], watched: [] }); |
| 507 | + }).pipe(Effect.provide(testLayer)), |
| 508 | +); |
0 commit comments