Open History to see the last commit
1/**
2 * RuntimeReceiptBus - Internal checkpoint-reactor synchronization receipts.
3 *
4 * This service exists to expose short-lived orchestration milestones that are
5 * useful in tests and harnesses but are not part of the production runtime
6 * event model. `CheckpointReactor` publishes receipts such as baseline capture,
7 * diff finalization, and turn-processing quiescence so integration tests can
8 * wait for those exact points without inferring them indirectly from persisted
9 * state.
10 *
11 * Production code should only call `publish`. Test code may subscribe via
12 * `streamEventsForTest`, which is intentionally named to make the intended
13 * usage explicit.
14 *
15 * @module RuntimeReceiptBus
16 */
17import { CheckpointRef, IsoDateTime, NonNegativeInt, ThreadId, TurnId } from "@t3tools/contracts";
18import * as Schema from "effect/Schema";
19import * as Context from "effect/Context";
20import type * as Effect from "effect/Effect";
21import type * as Stream from "effect/Stream";
22
23export const CheckpointBaselineCapturedReceipt = Schema.Struct({
24 type: Schema.Literal("checkpoint.baseline.captured"),
25 threadId: ThreadId,
26 checkpointTurnCount: NonNegativeInt,
27 checkpointRef: CheckpointRef,
28 createdAt: IsoDateTime,
29});
30export type CheckpointBaselineCapturedReceipt = typeof CheckpointBaselineCapturedReceipt.Type;
31
32export const CheckpointDiffFinalizedReceipt = Schema.Struct({
33 type: Schema.Literal("checkpoint.diff.finalized"),
34 threadId: ThreadId,
35 turnId: TurnId,
36 checkpointTurnCount: NonNegativeInt,
37 checkpointRef: CheckpointRef,
38 status: Schema.Literals(["ready", "missing", "error"]),
39 createdAt: IsoDateTime,
40});
41export type CheckpointDiffFinalizedReceipt = typeof CheckpointDiffFinalizedReceipt.Type;
42
43export const TurnProcessingQuiescedReceipt = Schema.Struct({
44 type: Schema.Literal("turn.processing.quiesced"),
45 threadId: ThreadId,
46 turnId: TurnId,
47 checkpointTurnCount: NonNegativeInt,
48 createdAt: IsoDateTime,
49});
50export type TurnProcessingQuiescedReceipt = typeof TurnProcessingQuiescedReceipt.Type;
51
52export const OrchestrationRuntimeReceipt = Schema.Union([
53 CheckpointBaselineCapturedReceipt,
54 CheckpointDiffFinalizedReceipt,
55 TurnProcessingQuiescedReceipt,
56]);
57export type OrchestrationRuntimeReceipt = typeof OrchestrationRuntimeReceipt.Type;
58
59export interface RuntimeReceiptBusShape {
60 readonly publish: (receipt: OrchestrationRuntimeReceipt) => Effect.Effect<void>;
61 readonly streamEventsForTest: Stream.Stream<OrchestrationRuntimeReceipt>;
62}
63
64export class RuntimeReceiptBus extends Context.Service<RuntimeReceiptBus, RuntimeReceiptBusShape>()(
65 "t3/orchestration/Services/RuntimeReceiptBus",
66) {}