|
9 | 9 | ContextTransferId, |
10 | 10 | CheckpointRef, |
11 | 11 | CheckpointScopeId, |
| 12 | + ContextHandoffId, |
12 | 13 | MessageId, |
13 | 14 | type ModelSelection, |
14 | 15 | type OrchestrationV2ProviderThread, |
@@ -55,6 +56,7 @@ import { |
55 | 56 | THREAD_HISTORY_PAGE_POLICY, |
56 | 57 | THREAD_HISTORY_TURN_SNAPSHOT_ROW_LIMIT, |
57 | 58 | } from "./threadHistoryPaging.ts"; |
| 59 | +import { buildBoundedThreadStreamSnapshot } from "./ThreadStream.ts"; |
58 | 60 | import { limitRecoveryCommand } from "./UsageLimitRecoveryWorker.ts"; |
59 | 61 |
|
60 | 62 | import { layerReaderDatabase, traceSqlRouting } from "../persistence/testkit/SqliteRouting.ts"; |
@@ -2594,6 +2596,142 @@ it.effect("SQL snapshot windows keep cards for requests still pending", () => |
2594 | 2596 | }).pipe(Effect.provide(layerTest)), |
2595 | 2597 | ); |
2596 | 2598 |
|
| 2599 | +it.effect("SQL snapshot windows leave handoff bodies in SQLite without changing the wire", () => |
| 2600 | + Effect.gen(function* () { |
| 2601 | + const store = yield* ProjectionStore.ProjectionStoreV2; |
| 2602 | + const now = yield* DateTime.now; |
| 2603 | + const threadId = ThreadId.make("thread:handoff-window"); |
| 2604 | + yield* store.apply({ |
| 2605 | + id: EventId.make("event:handoff-window:thread"), |
| 2606 | + type: "thread.created", |
| 2607 | + threadId, |
| 2608 | + occurredAt: now, |
| 2609 | + payload: { |
| 2610 | + createdBy: "user", |
| 2611 | + creationSource: "web", |
| 2612 | + id: threadId, |
| 2613 | + projectId: ProjectId.make("project:handoff-window"), |
| 2614 | + title: "Handoff window", |
| 2615 | + providerInstanceId, |
| 2616 | + modelSelection, |
| 2617 | + runtimeMode: "full-access", |
| 2618 | + interactionMode: "default", |
| 2619 | + branch: null, |
| 2620 | + worktreePath: null, |
| 2621 | + activeProviderThreadId: null, |
| 2622 | + lineage: { parentThreadId: null, relationshipToParent: null, rootThreadId: threadId }, |
| 2623 | + forkedFrom: null, |
| 2624 | + createdAt: now, |
| 2625 | + updatedAt: now, |
| 2626 | + archivedAt: null, |
| 2627 | + settledOverride: null, |
| 2628 | + settledAt: null, |
| 2629 | + lastVisitedAt: null, |
| 2630 | + deletedAt: null, |
| 2631 | + }, |
| 2632 | + }); |
| 2633 | + const providerThreadId = ProviderThreadId.make("provider-thread:handoff-window"); |
| 2634 | + const earlierItemId = TurnItemId.make("item:handoff-window:earlier"); |
| 2635 | + const handoff = (id: string, status: "ready" | "superseded") => ({ |
| 2636 | + id: ContextHandoffId.make(`handoff:handoff-window:${id}`), |
| 2637 | + transferId: null, |
| 2638 | + threadId, |
| 2639 | + targetRunId: RunId.make("run:handoff-window"), |
| 2640 | + fromProviderThreadIds: [providerThreadId], |
| 2641 | + toProviderThreadId: providerThreadId, |
| 2642 | + coveredRunOrdinals: { from: 1, to: 1 }, |
| 2643 | + strategy: "full_thread_summary" as const, |
| 2644 | + status, |
| 2645 | + summaryMessageId: null, |
| 2646 | + summaryText: `Summary ${id}`, |
| 2647 | + history: { |
| 2648 | + messages: [ |
| 2649 | + { |
| 2650 | + role: "user" as const, |
| 2651 | + text: "Earlier request ".repeat(1_000), |
| 2652 | + threadId, |
| 2653 | + runId: null, |
| 2654 | + itemId: earlierItemId, |
| 2655 | + providerThreadId, |
| 2656 | + status: "completed", |
| 2657 | + kind: "user_message", |
| 2658 | + }, |
| 2659 | + ], |
| 2660 | + coverage: "full", |
| 2661 | + omittedItems: 0, |
| 2662 | + }, |
| 2663 | + delivery: { nativeThreadId: "native", status: "injected" as const, itemIds: [earlierItemId] }, |
| 2664 | + createdByProviderInstanceId: providerInstanceId, |
| 2665 | + createdAt: now, |
| 2666 | + updatedAt: now, |
| 2667 | + }); |
| 2668 | + // The window keeps a ready handoff and one its rows show; the third is outside it. |
| 2669 | + const handoffs = [ |
| 2670 | + handoff("ready", "ready"), |
| 2671 | + handoff("shown", "superseded"), |
| 2672 | + handoff("old", "superseded"), |
| 2673 | + ]; |
| 2674 | + for (const payload of handoffs) { |
| 2675 | + yield* store.apply({ |
| 2676 | + id: EventId.make(`event:${payload.id}`), |
| 2677 | + type: "context-handoff.updated", |
| 2678 | + threadId, |
| 2679 | + occurredAt: now, |
| 2680 | + payload, |
| 2681 | + }); |
| 2682 | + } |
| 2683 | + yield* store.apply({ |
| 2684 | + id: EventId.make("event:handoff-window:item"), |
| 2685 | + type: "turn-item.updated", |
| 2686 | + threadId, |
| 2687 | + occurredAt: now, |
| 2688 | + payload: { |
| 2689 | + id: TurnItemId.make("item:handoff-window:handoff"), |
| 2690 | + threadId, |
| 2691 | + runId: null, |
| 2692 | + nodeId: null, |
| 2693 | + providerThreadId: null, |
| 2694 | + providerTurnId: null, |
| 2695 | + nativeItemRef: null, |
| 2696 | + parentItemId: null, |
| 2697 | + ordinal: 1, |
| 2698 | + status: "completed", |
| 2699 | + title: null, |
| 2700 | + startedAt: now, |
| 2701 | + completedAt: now, |
| 2702 | + updatedAt: now, |
| 2703 | + type: "handoff", |
| 2704 | + contextHandoffId: handoffs[1]!.id, |
| 2705 | + fromProviderThreadIds: [providerThreadId], |
| 2706 | + toProviderThreadId: providerThreadId, |
| 2707 | + fromProviderInstanceIds: [providerInstanceId], |
| 2708 | + toProviderInstanceId: providerInstanceId, |
| 2709 | + strategy: "full_thread_summary", |
| 2710 | + }, |
| 2711 | + }); |
| 2712 | + |
| 2713 | + const window = yield* store.getThreadSnapshotWindow(threadId, { rowLimit: 10 }); |
| 2714 | + const windowHandoffs = window.projection.contextHandoffs; |
| 2715 | + assert.deepEqual( |
| 2716 | + windowHandoffs.map((row) => row.id), |
| 2717 | + [handoffs[0]!.id, handoffs[1]!.id], |
| 2718 | + ); |
| 2719 | + for (const row of windowHandoffs) { |
| 2720 | + assert.isUndefined(row.history); |
| 2721 | + assert.isUndefined(row.delivery); |
| 2722 | + } |
| 2723 | + const full = yield* store.getThreadSnapshot(threadId); |
| 2724 | + assert.deepEqual(full.projection.contextHandoffs, handoffs); |
| 2725 | + assert.deepEqual( |
| 2726 | + buildBoundedThreadStreamSnapshot(window), |
| 2727 | + buildBoundedThreadStreamSnapshot({ |
| 2728 | + ...window, |
| 2729 | + projection: { ...window.projection, contextHandoffs: handoffs.slice(0, 2) }, |
| 2730 | + }), |
| 2731 | + ); |
| 2732 | + }).pipe(Effect.provide(layerTest)), |
| 2733 | +); |
| 2734 | + |
2597 | 2735 | it.effect("lists only active subagent IDs without loading shell data", () => |
2598 | 2736 | Effect.gen(function* () { |
2599 | 2737 | const store = yield* ProjectionStore.ProjectionStoreV2; |
|
0 commit comments