@atolis-hq/wake 0.4.101 → 0.4.102
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/artifacts/application/operator-instructions-service.js +2 -2
- package/dist/src/bootstrap/artifact-mcp.js +3 -4
- package/dist/src/bootstrap/delegation-authority.js +1 -1
- package/dist/src/bootstrap/integration-runtime.js +1 -1
- package/dist/src/bootstrap/persistence-composition.js +1 -1
- package/dist/src/bootstrap/surface-api-delivery.d.ts +1 -1
- package/dist/src/bootstrap/surface-api-delivery.js +2 -2
- package/dist/src/bootstrap/version.js +1 -1
- package/dist/src/control-plane/application/activation-scheduler-ports.d.ts +2 -1
- package/dist/src/control-plane/application/activation-scheduler.js +2 -1
- package/dist/src/control-plane/application/advance-once-dispatch.d.ts +2 -4
- package/dist/src/control-plane/application/advance-once-dispatch.js +6 -4
- package/dist/src/control-plane/domain/delivery-capacity.d.ts +2 -5
- package/dist/src/control-plane/domain/delivery-capacity.js +3 -4
- package/dist/src/control-plane/domain/open-work-policy.d.ts +2 -10
- package/dist/src/control-plane/domain/open-work-policy.js +2 -3
- package/dist/src/execution/application/run-repository.d.ts +2 -2
- package/dist/src/execution/application/run-repository.js +3 -3
- package/dist/src/node_modules/@atolis-hq/eventing/dist/runtime/cached-journal-view.d.ts +9 -1
- package/dist/src/node_modules/@atolis-hq/eventing/dist/runtime/cached-journal-view.d.ts.map +1 -1
- package/dist/src/node_modules/@atolis-hq/eventing/dist/runtime/cached-journal-view.js +62 -7
- package/dist/src/node_modules/@atolis-hq/eventing/dist/store/event-journal.d.ts +2 -5
- package/dist/src/node_modules/@atolis-hq/eventing/dist/store/event-journal.d.ts.map +1 -1
- package/dist/src/node_modules/@atolis-hq/eventing-filesystem/dist/file-event-journal.d.ts +12 -13
- package/dist/src/node_modules/@atolis-hq/eventing-filesystem/dist/file-event-journal.d.ts.map +1 -1
- package/dist/src/node_modules/@atolis-hq/eventing-filesystem/dist/file-event-journal.js +168 -109
- package/dist/src/orchestration/application/deferred-signals.d.ts +4 -2
- package/dist/src/orchestration/application/deferred-signals.js +47 -37
- package/dist/src/orchestration/application/delegated-work.d.ts +2 -0
- package/dist/src/orchestration/application/delegated-work.js +10 -6
- package/dist/src/orchestration/application/delegation-commands.d.ts +1 -1
- package/dist/src/orchestration/application/delegation-commands.js +1 -2
- package/dist/src/orchestration/application/delegation-gate.d.ts +12 -5
- package/dist/src/orchestration/application/delegation-gate.js +36 -10
- package/dist/src/orchestration/application/orchestration-service.js +10 -5
- package/dist/src/work/application/work-index.d.ts +21 -0
- package/dist/src/work/application/work-index.js +73 -0
- package/dist/src/work/application/work-repository.d.ts +2 -2
- package/dist/src/work/application/work-repository.js +2 -2
- package/dist/src/work/application/work-service.d.ts +5 -2
- package/dist/src/work/application/work-service.js +5 -2
- package/dist/src/work/{application → domain}/delivery-availability.d.ts +4 -7
- package/dist/src/work/{application → domain}/delivery-availability.js +3 -3
- package/dist/src/work/index.d.ts +2 -1
- package/dist/src/work/index.js +2 -1
- package/package.json +2 -1
|
@@ -46,7 +46,7 @@ export class OperatorInstructionsService {
|
|
|
46
46
|
if (bytes.byteLength > this.config.maxWriteBytes)
|
|
47
47
|
throw new Error(`Operator instructions exceed ${this.config.maxWriteBytes} byte limit`);
|
|
48
48
|
const stream = artifactContextStream(input.contextScope);
|
|
49
|
-
const events = await this.journal.readStream(stream
|
|
49
|
+
const events = await this.journal.readStream(stream);
|
|
50
50
|
const revisions = this.selectRevisions(events);
|
|
51
51
|
const existing = revisions.find((item) => item.revisionId === input.revisionId);
|
|
52
52
|
if (existing !== undefined) {
|
|
@@ -88,7 +88,7 @@ export class OperatorInstructionsService {
|
|
|
88
88
|
}
|
|
89
89
|
async revisions(contextScope) {
|
|
90
90
|
artifactSharedContextNameSchema.parse(contextScope);
|
|
91
|
-
return this.selectRevisions(await this.journal.readStream(artifactContextStream(contextScope)
|
|
91
|
+
return this.selectRevisions(await this.journal.readStream(artifactContextStream(contextScope)));
|
|
92
92
|
}
|
|
93
93
|
selectRevisions(events) {
|
|
94
94
|
return events.flatMap((envelope) => {
|
|
@@ -84,9 +84,8 @@ export async function createArtifactMcpServerForSession(root, sessions, path, to
|
|
|
84
84
|
await sessions.read(path, token);
|
|
85
85
|
if (root.journal === undefined)
|
|
86
86
|
throw new Error('Delegation journal is unavailable');
|
|
87
|
-
const run = (await new RunRepository(root.journal).load(executionRunId(descriptor.runId)
|
|
88
|
-
|
|
89
|
-
})).view;
|
|
87
|
+
const run = (await new RunRepository(root.journal).load(executionRunId(descriptor.runId)))
|
|
88
|
+
.view;
|
|
90
89
|
if (run === null || run.activationId !== descriptor.activationId)
|
|
91
90
|
throw new Error('Delegation Run is unavailable');
|
|
92
91
|
const parent = await root.orchestration.get(workflowInstanceId(run.workflowInstanceId));
|
|
@@ -146,7 +145,7 @@ function operatorInstructionsPrompt(instructions) {
|
|
|
146
145
|
async function instructionsForRun(input, runId, contextScope) {
|
|
147
146
|
const prior = input.journal === undefined
|
|
148
147
|
? undefined
|
|
149
|
-
: (await input.journal.readStream(runStream(executionRunId(runId))
|
|
148
|
+
: (await input.journal.readStream(runStream(executionRunId(runId))))
|
|
150
149
|
.flatMap((envelope) => {
|
|
151
150
|
const event = selectRunExecutionEvent(envelope);
|
|
152
151
|
return event?.event.eventType === ExecutionEventType.RunOperatorInstructionsCaptured
|
|
@@ -13,7 +13,7 @@ export function createDelegationAuthority(journal, resources, activities, bindin
|
|
|
13
13
|
};
|
|
14
14
|
return {
|
|
15
15
|
async assertCaller(caller, parent) {
|
|
16
|
-
const run = (await runs.load(runId(caller.runId)
|
|
16
|
+
const run = (await runs.load(runId(caller.runId))).view;
|
|
17
17
|
if (run === null ||
|
|
18
18
|
!isActiveRunStatus(run.status) ||
|
|
19
19
|
run.cancellation !== undefined ||
|
|
@@ -134,7 +134,7 @@ export async function composeIntegrationRuntime(input) {
|
|
|
134
134
|
async function openWorkCapacityAvailable() {
|
|
135
135
|
const limit = input.config.controlPlane.maxOpenWorkItems ?? null;
|
|
136
136
|
return (limit === null ||
|
|
137
|
-
hasOpenWorkCapacity(
|
|
137
|
+
hasOpenWorkCapacity(readOpenWorkItemIds(await input.orchestration.listAll(), await input.work.deliverySnapshot()), limit));
|
|
138
138
|
}
|
|
139
139
|
const triggerReactors = input.config.controlPlane.triggers.map((config) => createTriggerReactor(triggers, config, decodeCanonicalEvent));
|
|
140
140
|
// Registration starts at the current journal boundary; historical facts are not sources.
|
|
@@ -10,7 +10,7 @@ function serializeJournalAppends(journal) {
|
|
|
10
10
|
appendTail = appended.then(() => undefined, () => undefined);
|
|
11
11
|
return appended;
|
|
12
12
|
},
|
|
13
|
-
readStream: (stream
|
|
13
|
+
readStream: (stream) => journal.readStream(stream),
|
|
14
14
|
...(journal.scanAll === undefined
|
|
15
15
|
? {}
|
|
16
16
|
: { scanAll: (signal) => journal.scanAll(signal) }),
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { type WorkDetailResponse } from '../surfaces/index.js';
|
|
2
|
-
import {
|
|
2
|
+
import type { WorkItemView } from '../work/index.js';
|
|
3
3
|
import type { CompositionRoot } from './composition-root.js';
|
|
4
4
|
export declare function presentDelivery(root: CompositionRoot, work: WorkItemView): Promise<Pick<WorkDetailResponse, 'delegation'>>;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { presentResource, toWorkItemKey } from '../surfaces/index.js';
|
|
2
|
-
import { readDeliveryAvailability } from '../work/index.js';
|
|
3
2
|
export async function presentDelivery(root, work) {
|
|
4
3
|
if (root.orchestration?.deliveryTree === undefined)
|
|
5
4
|
return {};
|
|
6
5
|
const cohorts = await root.orchestration.deliveryTree(work.workItemId);
|
|
7
6
|
if (cohorts.length === 0 && work.delegation === undefined)
|
|
8
7
|
return {};
|
|
8
|
+
const delivery = await root.work.deliverySnapshot();
|
|
9
9
|
return {
|
|
10
10
|
delegation: {
|
|
11
11
|
rootWorkItemKey: toWorkItemKey(work.delegation?.rootWorkItemId ?? work.workItemId),
|
|
@@ -13,7 +13,7 @@ export async function presentDelivery(root, work) {
|
|
|
13
13
|
? {}
|
|
14
14
|
: { parentWorkItemKey: toWorkItemKey(work.delegation.parentWorkItemId) }),
|
|
15
15
|
children: await Promise.all(cohorts.flatMap((cohort) => cohort.children.map(async (child) => {
|
|
16
|
-
const availability =
|
|
16
|
+
const availability = delivery.availability(child.workItemId);
|
|
17
17
|
const resources = await Promise.all((await root.resources.correlationsForWork(child.workItemId)).map((entry) => root.resources.get(entry.resourceId)));
|
|
18
18
|
return {
|
|
19
19
|
workItemKey: toWorkItemKey(child.workItemId),
|
|
@@ -124,6 +124,6 @@ export function resolveWakeVersion(options = {}) {
|
|
|
124
124
|
return `g${headHash.slice(0, 7)}`;
|
|
125
125
|
return '0.1.0-dev';
|
|
126
126
|
}
|
|
127
|
-
export const wakeVersion = "v0.4.
|
|
127
|
+
export const wakeVersion = "v0.4.102";
|
|
128
128
|
/** The registry-installable version used by packaged sandbox images. */
|
|
129
129
|
export const wakePackageVersion = packageVersion(defaultRepoRoot) ?? wakeVersion;
|
|
@@ -3,7 +3,7 @@ import type { ExecutionFailureCode, RepositoryAssignment, RunView, WorkspaceReco
|
|
|
3
3
|
import type { IdGenerator } from '../../kernel/index.js';
|
|
4
4
|
import type { ActivityActivationView, PendingActivationPriority, WorkflowInstanceView } from '../../orchestration/index.js';
|
|
5
5
|
import type { ResourceService } from '../../resources/index.js';
|
|
6
|
-
import type { WorkDelegation, WorkItemId, WorkStatus } from '../../work/index.js';
|
|
6
|
+
import type { DeliverySnapshot, WorkDelegation, WorkItemId, WorkStatus } from '../../work/index.js';
|
|
7
7
|
import type { DispatchPolicy } from '../domain/dispatch-policy.js';
|
|
8
8
|
export interface OrchestrationPort {
|
|
9
9
|
reconcileChildCompletions(context: CommandContext): Promise<void>;
|
|
@@ -64,6 +64,7 @@ export interface ActivationSchedulerDependencies {
|
|
|
64
64
|
readonly frozen?: boolean;
|
|
65
65
|
readonly deleted?: boolean;
|
|
66
66
|
} | null>;
|
|
67
|
+
deliverySnapshot(): Promise<DeliverySnapshot>;
|
|
67
68
|
};
|
|
68
69
|
readonly runnerIneligibility?: () => Promise<ReadonlySet<string>>;
|
|
69
70
|
readonly isDispatchPaused?: () => Promise<boolean>;
|
|
@@ -105,11 +105,12 @@ export function createActivationScheduler(orchestration, execution, resources, c
|
|
|
105
105
|
return { kind: 'paused' };
|
|
106
106
|
}
|
|
107
107
|
const rawPending = await orchestration.listPendingActivations(options.workItemId);
|
|
108
|
+
const delivery = rawPending.length === 0 ? undefined : await dependencies.work?.deliverySnapshot();
|
|
108
109
|
const pending = (await Promise.all(rawPending.map(async (candidate) => {
|
|
109
110
|
if (candidate.activation.notBefore !== undefined &&
|
|
110
111
|
Date.parse(candidate.activation.notBefore) > clock.now().getTime())
|
|
111
112
|
return null;
|
|
112
|
-
const work =
|
|
113
|
+
const work = delivery?.get(candidate.workflow.workItemId);
|
|
113
114
|
return work?.frozen || work?.deleted ? null : candidate;
|
|
114
115
|
}))).filter((candidate) => candidate !== null);
|
|
115
116
|
const blocked = ((await orchestration.listAll?.()) ?? []).flatMap((workflow) => workflow.status === WorkflowStatus.Blocked &&
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { CommandContext } from '@atolis-hq/eventing';
|
|
2
2
|
import type { ActivityActivationView, PendingActivationPriority, WorkflowInstanceView } from '../../orchestration/index.js';
|
|
3
3
|
import { type ResourceService } from '../../resources/index.js';
|
|
4
|
+
import type { WorkService } from '../../work/index.js';
|
|
4
5
|
import type { AdvanceResult } from '../contracts/views.js';
|
|
5
6
|
import { type DispatchPolicy } from '../domain/dispatch-policy.js';
|
|
6
|
-
import { type WorkAvailability } from '../domain/open-work-policy.js';
|
|
7
7
|
import type { ExecutionPort, OrchestrationPort } from './activation-scheduler-ports.js';
|
|
8
8
|
export interface DispatchLoopContext {
|
|
9
9
|
readonly orchestration: OrchestrationPort;
|
|
@@ -13,9 +13,7 @@ export interface DispatchLoopContext {
|
|
|
13
13
|
readonly maxConcurrentRuns: number;
|
|
14
14
|
readonly maxDispatches: number;
|
|
15
15
|
readonly maxOpenWorkItems: number | null;
|
|
16
|
-
readonly work:
|
|
17
|
-
get(id: string): Promise<WorkAvailability | null>;
|
|
18
|
-
} | undefined;
|
|
16
|
+
readonly work: Pick<WorkService, 'deliverySnapshot'> | undefined;
|
|
19
17
|
readonly runnerIneligibility: () => Promise<ReadonlySet<string>>;
|
|
20
18
|
readonly isDispatchPaused: () => Promise<boolean>;
|
|
21
19
|
readonly commandContext: (cause: string) => CommandContext;
|
|
@@ -4,7 +4,7 @@ import { isRunnerQuotaOutcome, reportUnappliedRunnerQuotaRetry, runnerQuotaMessa
|
|
|
4
4
|
import { ActivationClaimConflictError, isActiveRunStatus, NoEligibleRunnerError, RunStatus, WorkspaceMode, } from '../../execution/index.js';
|
|
5
5
|
import { DelegationPendingError, WorkflowStatus } from '../../orchestration/index.js';
|
|
6
6
|
import { neutralDispatchPriority } from '../domain/dispatch-policy.js';
|
|
7
|
-
import { canDispatchWorkItem, readOpenWorkItemIds
|
|
7
|
+
import { canDispatchWorkItem, readOpenWorkItemIds } from '../domain/open-work-policy.js';
|
|
8
8
|
import { isExecutionFailureTerminal } from './execution-reconciliation.js';
|
|
9
9
|
export async function advancementWasDurablyApplied(orchestration, workflowInstanceId, activationId) {
|
|
10
10
|
const current = await orchestration.get?.(workflowInstanceId);
|
|
@@ -43,13 +43,15 @@ export async function runDispatchLoop(pending, ctx) {
|
|
|
43
43
|
break;
|
|
44
44
|
}
|
|
45
45
|
const inventory = (await ctx.orchestration.listAll?.()) ?? pending.map((item) => item.workflow);
|
|
46
|
-
|
|
46
|
+
// One synchronisation with Work per pass; every item is then answered from memory.
|
|
47
|
+
const delivery = await ctx.work?.deliverySnapshot();
|
|
48
|
+
const capacity = await deliveryCapacity(inventory, allRuns, delivery, ctx.orchestration.deliveryRunLimit?.bind(ctx.orchestration));
|
|
47
49
|
// Legacy test ports may omit listAll; production supplies the journal-backed inventory.
|
|
48
50
|
const open = ctx.maxOpenWorkItems === null
|
|
49
51
|
? new Set()
|
|
50
|
-
:
|
|
52
|
+
: readOpenWorkItemIds(inventory.map((workflow) => startedWorkflowIds.has(workflow.workflowInstanceId)
|
|
51
53
|
? { ...workflow, hasStartedActivation: true }
|
|
52
|
-
: workflow),
|
|
54
|
+
: workflow), delivery);
|
|
53
55
|
const selectedCandidate = ctx.dispatchPolicy.select(pending
|
|
54
56
|
.filter((item) => !isolatedIds.has(item.workflow.workflowInstanceId) &&
|
|
55
57
|
!capacity.unavailable.has(item.workflow.workItemId) &&
|
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
import type { RunView } from '../../execution/index.js';
|
|
2
2
|
import { type WorkflowInstanceView } from '../../orchestration/index.js';
|
|
3
|
-
import {
|
|
4
|
-
import type { WorkAvailability } from './open-work-policy.js';
|
|
3
|
+
import type { DeliverySnapshot, WorkItemId } from '../../work/index.js';
|
|
5
4
|
/** A waiting workflow is not a Run; every actual Run, including watches, counts. */
|
|
6
|
-
export declare function deliveryCapacity(workflows: readonly WorkflowInstanceView[], runs: readonly RunView[], work: {
|
|
7
|
-
get(id: string): Promise<WorkAvailability | null>;
|
|
8
|
-
} | undefined, runLimit: ((id: WorkItemId) => Promise<number | undefined>) | undefined): Promise<{
|
|
5
|
+
export declare function deliveryCapacity(workflows: readonly WorkflowInstanceView[], runs: readonly RunView[], work: DeliverySnapshot | undefined, runLimit: ((id: WorkItemId) => Promise<number | undefined>) | undefined): Promise<{
|
|
9
6
|
roots: ReadonlyMap<string, string>;
|
|
10
7
|
unavailable: ReadonlySet<string>;
|
|
11
8
|
full: ReadonlySet<string>;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { isActiveRunStatus } from '../../execution/index.js';
|
|
2
2
|
import { WorkflowStatus } from '../../orchestration/index.js';
|
|
3
|
-
import { readDeliveryAvailability } from '../../work/index.js';
|
|
4
3
|
/** A waiting workflow is not a Run; every actual Run, including watches, counts. */
|
|
5
4
|
export async function deliveryCapacity(workflows, runs, work, runLimit) {
|
|
6
5
|
const activeWorkflowIds = new Set(runs.filter((run) => isActiveRunStatus(run.status)).map((run) => run.workflowInstanceId));
|
|
@@ -10,12 +9,12 @@ export async function deliveryCapacity(workflows, runs, work, runLimit) {
|
|
|
10
9
|
workflow.status !== WorkflowStatus.Superseded));
|
|
11
10
|
const roots = new Map();
|
|
12
11
|
const unavailable = new Set();
|
|
13
|
-
|
|
14
|
-
const delivery = work === undefined ? { rootWorkItemId: id } :
|
|
12
|
+
for (const id of new Set(live.map((workflow) => workflow.workItemId))) {
|
|
13
|
+
const delivery = work === undefined ? { rootWorkItemId: id } : work.availability(id);
|
|
15
14
|
roots.set(id, delivery.rootWorkItemId);
|
|
16
15
|
if (delivery.reason !== undefined)
|
|
17
16
|
unavailable.add(id);
|
|
18
|
-
}
|
|
17
|
+
}
|
|
19
18
|
const full = new Set();
|
|
20
19
|
// A root without an active Run cannot be at a positive limit.
|
|
21
20
|
await Promise.all([...activeRunCounts(live, runs, roots)].map(async ([root, count]) => {
|
|
@@ -1,15 +1,7 @@
|
|
|
1
1
|
import { type WorkflowInstanceView } from '../../orchestration/index.js';
|
|
2
|
-
import type {
|
|
3
|
-
export interface WorkAvailability {
|
|
4
|
-
readonly state?: string;
|
|
5
|
-
readonly delegation?: WorkDelegation;
|
|
6
|
-
readonly frozen?: boolean;
|
|
7
|
-
readonly deleted?: boolean;
|
|
8
|
-
}
|
|
2
|
+
import type { DeliverySnapshot } from '../../work/index.js';
|
|
9
3
|
/** Distinct started items with any nonterminal workflow, including waiting children. */
|
|
10
4
|
export declare function deriveOpenWorkItemIds(workflows: readonly WorkflowInstanceView[], unavailable?: ReadonlySet<string>): ReadonlySet<string>;
|
|
11
5
|
export declare function hasOpenWorkCapacity(open: ReadonlySet<string>, limit: number | null): boolean;
|
|
12
6
|
export declare function canDispatchWorkItem(workItemId: string, open: ReadonlySet<string>, limit: number | null): boolean;
|
|
13
|
-
export declare function readOpenWorkItemIds(workflows: readonly WorkflowInstanceView[], work?:
|
|
14
|
-
get(id: string): Promise<WorkAvailability | null>;
|
|
15
|
-
}): Promise<ReadonlySet<string>>;
|
|
7
|
+
export declare function readOpenWorkItemIds(workflows: readonly WorkflowInstanceView[], work?: DeliverySnapshot): ReadonlySet<string>;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { ActivityActivationStatus, WorkflowStatus, } from '../../orchestration/index.js';
|
|
2
|
-
import { readDeliveryAvailability } from '../../work/index.js';
|
|
3
2
|
/** Distinct started items with any nonterminal workflow, including waiting children. */
|
|
4
3
|
export function deriveOpenWorkItemIds(workflows, unavailable = new Set()) {
|
|
5
4
|
const started = new Set();
|
|
@@ -24,14 +23,14 @@ export function hasOpenWorkCapacity(open, limit) {
|
|
|
24
23
|
export function canDispatchWorkItem(workItemId, open, limit) {
|
|
25
24
|
return open.has(workItemId) || hasOpenWorkCapacity(open, limit);
|
|
26
25
|
}
|
|
27
|
-
export
|
|
26
|
+
export function readOpenWorkItemIds(workflows, work) {
|
|
28
27
|
const roots = new Set();
|
|
29
28
|
for (const id of deriveOpenWorkItemIds(workflows)) {
|
|
30
29
|
if (work === undefined) {
|
|
31
30
|
roots.add(id);
|
|
32
31
|
continue;
|
|
33
32
|
}
|
|
34
|
-
const delivery =
|
|
33
|
+
const delivery = work.availability(id);
|
|
35
34
|
if (delivery.reason === undefined)
|
|
36
35
|
roots.add(delivery.rootWorkItemId);
|
|
37
36
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type EventJournal
|
|
1
|
+
import { type EventJournal } from '@atolis-hq/eventing';
|
|
2
2
|
import type { ActivationId } from '../../activities/index.js';
|
|
3
3
|
import { type RunExecutionEvent, type RunExecutionEventData } from '../contracts/events.js';
|
|
4
4
|
import { type RunId } from '../contracts/identifiers.js';
|
|
@@ -8,7 +8,7 @@ export declare class RunRepository {
|
|
|
8
8
|
private readonly journal;
|
|
9
9
|
private readonly runs;
|
|
10
10
|
constructor(journal: EventJournal);
|
|
11
|
-
load(runId: RunId
|
|
11
|
+
load(runId: RunId): Promise<{
|
|
12
12
|
readonly sequence: number;
|
|
13
13
|
readonly events?: readonly RunExecutionEvent[];
|
|
14
14
|
readonly view: ReturnType<typeof foldRun>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { cachedJournalView
|
|
1
|
+
import { cachedJournalView } from '@atolis-hq/eventing';
|
|
2
2
|
import { decodeRunExecutionEvent, } from '../contracts/events.js';
|
|
3
3
|
import { runId } from '../contracts/identifiers.js';
|
|
4
4
|
import { isRunStream, runStream } from '../contracts/streams.js';
|
|
@@ -10,8 +10,8 @@ export class RunRepository {
|
|
|
10
10
|
this.journal = journal;
|
|
11
11
|
this.runs = cachedJournalView(journal, deriveRuns);
|
|
12
12
|
}
|
|
13
|
-
async load(runId
|
|
14
|
-
const events = await this.journal.readStream(runStream(runId)
|
|
13
|
+
async load(runId) {
|
|
14
|
+
const events = await this.journal.readStream(runStream(runId));
|
|
15
15
|
const decoded = events.map(decodeRunExecutionEvent);
|
|
16
16
|
return { sequence: events.length, events: decoded, view: foldRun(decoded) };
|
|
17
17
|
}
|
|
@@ -4,5 +4,13 @@ export declare const JOURNAL_CHANGE_FALLBACK_MS = 30000;
|
|
|
4
4
|
export interface CachedJournalView<Value> {
|
|
5
5
|
get(): Promise<Value>;
|
|
6
6
|
}
|
|
7
|
-
|
|
7
|
+
type ViewJournal = Pick<EventJournal, 'readAll' | 'latestGlobalPosition'>;
|
|
8
|
+
export declare function cachedJournalView<Value>(journal: ViewJournal, derive: (events: readonly EventEnvelope[]) => Value | Promise<Value>, _now?: () => number): CachedJournalView<Value>;
|
|
9
|
+
export interface JournalFold<Value> {
|
|
10
|
+
readonly initial: Value;
|
|
11
|
+
/** Returns the value after `events`, which follow everything already folded. Must not mutate `value`. */
|
|
12
|
+
extend(value: Value, events: readonly EventEnvelope[]): Value;
|
|
13
|
+
}
|
|
14
|
+
export declare function foldedJournalView<Value>(journal: ViewJournal, fold: JournalFold<Value>): CachedJournalView<Value>;
|
|
15
|
+
export {};
|
|
8
16
|
//# sourceMappingURL=cached-journal-view.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cached-journal-view.d.ts","sourceRoot":"","sources":["../../src/runtime/cached-journal-view.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAC5D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAE9D,eAAO,MAAM,0BAA0B,QAAS,CAAC;AAEjD,MAAM,WAAW,iBAAiB,CAAC,KAAK;IACtC,GAAG,IAAI,OAAO,CAAC,KAAK,CAAC,CAAC;CACvB;
|
|
1
|
+
{"version":3,"file":"cached-journal-view.d.ts","sourceRoot":"","sources":["../../src/runtime/cached-journal-view.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAC5D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAE9D,eAAO,MAAM,0BAA0B,QAAS,CAAC;AAEjD,MAAM,WAAW,iBAAiB,CAAC,KAAK;IACtC,GAAG,IAAI,OAAO,CAAC,KAAK,CAAC,CAAC;CACvB;AAED,KAAK,WAAW,GAAG,IAAI,CAAC,YAAY,EAAE,SAAS,GAAG,sBAAsB,CAAC,CAAC;AAe1E,wBAAgB,iBAAiB,CAAC,KAAK,EACrC,OAAO,EAAE,WAAW,EACpB,MAAM,EAAE,CAAC,MAAM,EAAE,SAAS,aAAa,EAAE,KAAK,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,EACpE,IAAI,GAAE,MAAM,MAAiB,GAC5B,iBAAiB,CAAC,KAAK,CAAC,CAsB1B;AAED,MAAM,WAAW,WAAW,CAAC,KAAK;IAChC,QAAQ,CAAC,OAAO,EAAE,KAAK,CAAC;IACxB,yGAAyG;IACzG,MAAM,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,aAAa,EAAE,GAAG,KAAK,CAAC;CAC/D;AAMD,wBAAgB,iBAAiB,CAAC,KAAK,EACrC,OAAO,EAAE,WAAW,EACpB,IAAI,EAAE,WAAW,CAAC,KAAK,CAAC,GACvB,iBAAiB,CAAC,KAAK,CAAC,CA+B1B"}
|
|
@@ -7,18 +7,73 @@ export const JOURNAL_CHANGE_FALLBACK_MS = 30_000;
|
|
|
7
7
|
// incremental batch. Depends only on the EventJournal port, not on any
|
|
8
8
|
// concrete persistence implementation, so it lives in Eventing rather than
|
|
9
9
|
// Persistence; domain and adapter modules may call it directly.
|
|
10
|
+
//
|
|
11
|
+
// The cached value is keyed by the last position actually read, never by the
|
|
12
|
+
// position sampled beforehand, so a value can never be held under a position
|
|
13
|
+
// newer than the events it was derived from. Callers that find the journal
|
|
14
|
+
// unchanged since a derivation already running share it.
|
|
10
15
|
export function cachedJournalView(journal, derive, _now = Date.now) {
|
|
11
16
|
let cache;
|
|
17
|
+
let inFlight;
|
|
12
18
|
return {
|
|
13
19
|
async get() {
|
|
14
|
-
const
|
|
15
|
-
if (cache !== undefined && cache.position
|
|
20
|
+
const sampled = await journal.latestGlobalPosition();
|
|
21
|
+
if (cache !== undefined && cache.position >= sampled)
|
|
16
22
|
return cache.value;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
23
|
+
if (inFlight?.sampled === sampled)
|
|
24
|
+
return inFlight.run;
|
|
25
|
+
const run = (async () => {
|
|
26
|
+
const events = await journal.readAll(0);
|
|
27
|
+
const value = await derive(events);
|
|
28
|
+
const position = events.at(-1)?.globalPosition ?? 0;
|
|
29
|
+
// An older derivation finishing late must not replace a newer one.
|
|
30
|
+
if (cache === undefined || position >= cache.position)
|
|
31
|
+
cache = { position, value };
|
|
32
|
+
return value;
|
|
33
|
+
})().finally(() => {
|
|
34
|
+
if (inFlight?.run === run)
|
|
35
|
+
inFlight = undefined;
|
|
36
|
+
});
|
|
37
|
+
inFlight = { sampled, run };
|
|
38
|
+
return run;
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
// An incremental counterpart of cachedJournalView for views that can be
|
|
43
|
+
// extended event by event: each journal move folds only the new events instead
|
|
44
|
+
// of re-deriving history. Folds are serialised, so every event is applied once
|
|
45
|
+
// and in order however many callers ask at the same time.
|
|
46
|
+
export function foldedJournalView(journal, fold) {
|
|
47
|
+
let state = {
|
|
48
|
+
position: 0,
|
|
49
|
+
value: fold.initial,
|
|
50
|
+
};
|
|
51
|
+
let running;
|
|
52
|
+
return {
|
|
53
|
+
async get() {
|
|
54
|
+
for (;;) {
|
|
55
|
+
const sampled = await journal.latestGlobalPosition();
|
|
56
|
+
if (state.position >= sampled)
|
|
57
|
+
return state.value;
|
|
58
|
+
if (running !== undefined) {
|
|
59
|
+
await running.catch(() => undefined);
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
const run = (async () => {
|
|
63
|
+
const events = await journal.readAll(state.position);
|
|
64
|
+
if (events.length > 0)
|
|
65
|
+
state = {
|
|
66
|
+
position: events.at(-1).globalPosition,
|
|
67
|
+
value: fold.extend(state.value, events),
|
|
68
|
+
};
|
|
69
|
+
return state.value;
|
|
70
|
+
})().finally(() => {
|
|
71
|
+
if (running === run)
|
|
72
|
+
running = undefined;
|
|
73
|
+
});
|
|
74
|
+
running = run;
|
|
75
|
+
return run;
|
|
76
|
+
}
|
|
22
77
|
},
|
|
23
78
|
};
|
|
24
79
|
}
|
|
@@ -2,13 +2,10 @@ import type { EventData, EventEnvelope, StreamRef } from '../contracts/events.js
|
|
|
2
2
|
import type { JournalChangeSignal } from '../subscriptions/journal-change-signal.js';
|
|
3
3
|
export declare class WrongExpectedSequenceError extends Error {
|
|
4
4
|
}
|
|
5
|
-
export interface JournalReadOptions {
|
|
6
|
-
/** Observe committed appends from other hosts without using a bounded freshness cache. */
|
|
7
|
-
readonly fresh?: boolean;
|
|
8
|
-
}
|
|
9
5
|
export interface EventJournal {
|
|
10
6
|
appendToStream(stream: StreamRef, expectedSequence: number, events: readonly EventData[]): Promise<readonly EventEnvelope[]>;
|
|
11
|
-
|
|
7
|
+
/** Every read observes all appends committed before the call, including by other processes. */
|
|
8
|
+
readStream(stream: StreamRef): Promise<readonly EventEnvelope[]>;
|
|
12
9
|
/** Optional bounded, cancellable snapshot reader for adapters with a streaming source. */
|
|
13
10
|
scanAll?(signal?: AbortSignal): AsyncIterable<EventEnvelope>;
|
|
14
11
|
readAll(afterGlobalPosition: number, limit?: number): Promise<readonly EventEnvelope[]>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event-journal.d.ts","sourceRoot":"","sources":["../../src/store/event-journal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAClF,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,2CAA2C,CAAC;AAErF,qBAAa,0BAA2B,SAAQ,KAAK;CAAG;AAExD,MAAM,WAAW,
|
|
1
|
+
{"version":3,"file":"event-journal.d.ts","sourceRoot":"","sources":["../../src/store/event-journal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAClF,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,2CAA2C,CAAC;AAErF,qBAAa,0BAA2B,SAAQ,KAAK;CAAG;AAExD,MAAM,WAAW,YAAY;IAC3B,cAAc,CACZ,MAAM,EAAE,SAAS,EACjB,gBAAgB,EAAE,MAAM,EACxB,MAAM,EAAE,SAAS,SAAS,EAAE,GAC3B,OAAO,CAAC,SAAS,aAAa,EAAE,CAAC,CAAC;IACrC,+FAA+F;IAC/F,UAAU,CAAC,MAAM,EAAE,SAAS,GAAG,OAAO,CAAC,SAAS,aAAa,EAAE,CAAC,CAAC;IACjE,0FAA0F;IAC1F,OAAO,CAAC,CAAC,MAAM,CAAC,EAAE,WAAW,GAAG,aAAa,CAAC,aAAa,CAAC,CAAC;IAC7D,OAAO,CAAC,mBAAmB,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,aAAa,EAAE,CAAC,CAAC;IACxF,UAAU,CAAC,CAAC,oBAAoB,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,aAAa,EAAE,CAAC,CAAC;IAI9F,oBAAoB,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;IACxC,kBAAkB,CAChB,mBAAmB,EAAE,MAAM,EAC3B,MAAM,EAAE,WAAW,EACnB,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,IAAI,CAAC,CAAC;IAGjB,QAAQ,CAAC,YAAY,EAAE,mBAAmB,CAAC;CAC5C"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { EventData, EventEnvelope, EventingClock, EventJournal, JournalChangeSignal,
|
|
1
|
+
import type { EventData, EventEnvelope, EventingClock, EventJournal, JournalChangeSignal, StreamRef } from '@atolis-hq/eventing';
|
|
2
2
|
export interface FileEventJournalWatcher {
|
|
3
3
|
unref(): void;
|
|
4
4
|
close(): void;
|
|
@@ -7,13 +7,11 @@ export interface FileEventJournalWatcher {
|
|
|
7
7
|
export type FileEventJournalWatcherFactory = (directory: string, notify: () => void) => Promise<FileEventJournalWatcher>;
|
|
8
8
|
export interface FileEventJournalOptions {
|
|
9
9
|
readonly watcherFactory?: FileEventJournalWatcherFactory;
|
|
10
|
-
readonly validationNow?: () => number;
|
|
11
10
|
}
|
|
12
11
|
export declare class FileEventJournal implements EventJournal {
|
|
13
12
|
private readonly root;
|
|
14
13
|
private readonly clock;
|
|
15
14
|
private readonly options;
|
|
16
|
-
private readonly validationNow;
|
|
17
15
|
constructor(root: string, clock: EventingClock, options?: FileEventJournalOptions);
|
|
18
16
|
private readonly changeSignalSource;
|
|
19
17
|
private changeWatcher;
|
|
@@ -21,13 +19,15 @@ export declare class FileEventJournal implements EventJournal {
|
|
|
21
19
|
get changeSignal(): JournalChangeSignal;
|
|
22
20
|
private cached;
|
|
23
21
|
private inFlightScan;
|
|
24
|
-
private
|
|
25
|
-
private
|
|
26
|
-
private
|
|
27
|
-
private
|
|
22
|
+
private readonly knownSegments;
|
|
23
|
+
private latestEntries;
|
|
24
|
+
private listing;
|
|
25
|
+
private runningListing;
|
|
26
|
+
private queuedListing;
|
|
27
|
+
private temporariesReclaimed;
|
|
28
28
|
appendToStream(stream: StreamRef, expectedSequence: number, drafts: readonly EventData[]): Promise<readonly EventEnvelope[]>;
|
|
29
29
|
private nextSegmentFile;
|
|
30
|
-
readStream(stream: StreamRef
|
|
30
|
+
readStream(stream: StreamRef): Promise<readonly EventEnvelope<EventData<string, unknown>, StreamRef<string, string>>[]>;
|
|
31
31
|
/** Live readers bypass the full-history cache and stop at captured segment sizes. */
|
|
32
32
|
scanAll(signal?: AbortSignal): AsyncIterable<EventEnvelope>;
|
|
33
33
|
private scanSegment;
|
|
@@ -39,15 +39,14 @@ export declare class FileEventJournal implements EventJournal {
|
|
|
39
39
|
private ensureChangeWatcher;
|
|
40
40
|
private startChangeWatcher;
|
|
41
41
|
private extendCache;
|
|
42
|
+
private adopt;
|
|
42
43
|
private manifestPath;
|
|
43
|
-
private cachedEventsForStream;
|
|
44
44
|
private persistManifest;
|
|
45
45
|
private loadManifest;
|
|
46
46
|
private scan;
|
|
47
|
-
private
|
|
48
|
-
private
|
|
49
|
-
private
|
|
50
|
-
private invalidateValidatedEntries;
|
|
47
|
+
private currentEntries;
|
|
48
|
+
private startListing;
|
|
49
|
+
private listSegments;
|
|
51
50
|
private parseIndexedEntries;
|
|
52
51
|
private decodeIndexedRecord;
|
|
53
52
|
private scanUncoalesced;
|
package/dist/src/node_modules/@atolis-hq/eventing-filesystem/dist/file-event-journal.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file-event-journal.d.ts","sourceRoot":"","sources":["../src/file-event-journal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,SAAS,EACT,aAAa,EACb,aAAa,EACb,YAAY,EACZ,mBAAmB,EACnB,
|
|
1
|
+
{"version":3,"file":"file-event-journal.d.ts","sourceRoot":"","sources":["../src/file-event-journal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,SAAS,EACT,aAAa,EACb,aAAa,EACb,YAAY,EACZ,mBAAmB,EACnB,SAAS,EACV,MAAM,qBAAqB,CAAC;AAU7B,MAAM,WAAW,uBAAuB;IACtC,KAAK,IAAI,IAAI,CAAC;IACd,KAAK,IAAI,IAAI,CAAC;IACd,IAAI,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC;CACrD;AAED,MAAM,MAAM,8BAA8B,GAAG,CAC3C,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,IAAI,KACf,OAAO,CAAC,uBAAuB,CAAC,CAAC;AAEtC,MAAM,WAAW,uBAAuB;IACtC,QAAQ,CAAC,cAAc,CAAC,EAAE,8BAA8B,CAAC;CAC1D;AAWD,qBAAa,gBAAiB,YAAW,YAAY;IAEjD,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,KAAK;IACtB,OAAO,CAAC,QAAQ,CAAC,OAAO;gBAFP,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,aAAa,EACpB,OAAO,GAAE,uBAA4B;IAGxD,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAsC;IACzE,OAAO,CAAC,aAAa,CAAsC;IAC3D,OAAO,CAAC,qBAAqB,CAA4B;IAEzD,IAAI,YAAY,IAAI,mBAAmB,CAEtC;IAKD,OAAO,CAAC,MAAM,CAA8B;IAW5C,OAAO,CAAC,YAAY,CAC4E;IAQhG,OAAO,CAAC,QAAQ,CAAC,aAAa,CAA+B;IAC7D,OAAO,CAAC,aAAa,CAA2B;IAChD,OAAO,CAAC,OAAO,CAA+E;IAE9F,OAAO,CAAC,cAAc,CAA2C;IACjE,OAAO,CAAC,aAAa,CAA2C;IAChE,OAAO,CAAC,oBAAoB,CAAS;IAE/B,cAAc,CAClB,MAAM,EAAE,SAAS,EACjB,gBAAgB,EAAE,MAAM,EACxB,MAAM,EAAE,SAAS,SAAS,EAAE,GAC3B,OAAO,CAAC,SAAS,aAAa,EAAE,CAAC;YA4CtB,eAAe;IAsBvB,UAAU,CAAC,MAAM,EAAE,SAAS;IA2BlC,qFAAqF;IAC9E,OAAO,CAAC,MAAM,CAAC,EAAE,WAAW,GAAG,aAAa,CAAC,aAAa,CAAC;YAcnD,WAAW;IAgC1B,OAAO,CAAC,gBAAgB;IAoBlB,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,SAA2B;IA0BvD,UAAU,CAAC,oBAAoB,CAAC,EAAE,MAAM,EAAE,KAAK,SAA2B;IAW1E,oBAAoB,IAAI,OAAO,CAAC,MAAM,CAAC;IAKvC,kBAAkB,CACtB,mBAAmB,EAAE,MAAM,EAC3B,MAAM,EAAE,WAAW,EACnB,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,IAAI,CAAC;IAWhB,OAAO,CAAC,mBAAmB;YAUb,kBAAkB;YAyBlB,WAAW;IAuDzB,OAAO,CAAC,KAAK;IAKb,OAAO,CAAC,YAAY;YAQN,eAAe;YAKf,YAAY;YAYZ,IAAI;IAelB,OAAO,CAAC,cAAc;IActB,OAAO,CAAC,YAAY;YAQN,YAAY;YA4DZ,mBAAmB;IA0BjC,OAAO,CAAC,mBAAmB;YAwBb,eAAe;CAuD9B"}
|