@atolis-hq/wake 0.4.70 → 0.4.72
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/bootstrap/surface-api-trigger-applications.js +22 -0
- package/dist/src/bootstrap/version.js +1 -1
- package/dist/src/control-plane/application/trigger-diagnostics.d.ts +4 -0
- package/dist/src/control-plane/application/trigger-facts.d.ts +7 -1
- package/dist/src/control-plane/application/trigger-facts.js +19 -2
- package/dist/src/control-plane/application/trigger-manual-request.d.ts +19 -0
- package/dist/src/control-plane/application/trigger-manual-request.js +95 -0
- package/dist/src/control-plane/application/trigger-service.d.ts +5 -4
- package/dist/src/control-plane/application/trigger-service.js +31 -33
- package/dist/src/control-plane/contracts/events.d.ts +30 -0
- package/dist/src/control-plane/contracts/events.js +26 -1
- package/dist/src/control-plane/contracts/trigger-diagnostics.d.ts +9 -10
- package/dist/src/control-plane/contracts/trigger-diagnostics.js +2 -8
- package/dist/src/control-plane/contracts/trigger-skip-reason.d.ts +10 -0
- package/dist/src/control-plane/contracts/trigger-skip-reason.js +8 -0
- package/dist/src/execution/infrastructure/runners/codex.js +7 -8
- package/dist/src/surfaces/api/contracts/control-plane.d.ts +2 -0
- package/dist/src/surfaces/api/contracts/transport-values.d.ts +4 -1
- package/dist/src/surfaces/api/contracts/transport-values.js +14 -0
- package/dist/src/surfaces/api/contracts/triggers.d.ts +6 -0
- package/dist/src/surfaces/api/contracts/triggers.js +7 -0
- package/dist/src/surfaces/api/routes/applications.d.ts +1 -0
- package/dist/src/surfaces/api/routes/commands.js +9 -2
- package/dist/src/surfaces/web-assets/assets/index-KgkqaRO6.js +1192 -0
- package/dist/src/surfaces/web-assets/index.html +1 -1
- package/package.json +1 -1
- package/dist/src/surfaces/web-assets/assets/index-DVapiQjj.js +0 -1192
|
@@ -146,6 +146,28 @@ export function createTriggerApplications(root, now) {
|
|
|
146
146
|
status: ApiCommandStatus.Completed,
|
|
147
147
|
};
|
|
148
148
|
},
|
|
149
|
+
async run(id, request) {
|
|
150
|
+
if (!root.config.controlPlane.triggers.some((trigger) => trigger.id === id))
|
|
151
|
+
return {
|
|
152
|
+
conflict: true,
|
|
153
|
+
code: 'trigger-not-found',
|
|
154
|
+
detail: 'Trigger definition is unavailable',
|
|
155
|
+
};
|
|
156
|
+
const context = {
|
|
157
|
+
commandId: 'trigger:' + request.idempotencyKey,
|
|
158
|
+
correlationId: correlationId('trigger:' + request.idempotencyKey),
|
|
159
|
+
occurredAt: now(),
|
|
160
|
+
actor: { kind: EventActorKind.Operator, id: 'web' },
|
|
161
|
+
};
|
|
162
|
+
const triggerOutcome = await root.triggers.requestManual(id, context);
|
|
163
|
+
return {
|
|
164
|
+
commandId: context.commandId,
|
|
165
|
+
idempotencyKey: request.idempotencyKey,
|
|
166
|
+
acceptedAt: now(),
|
|
167
|
+
status: ApiCommandStatus.Completed,
|
|
168
|
+
triggerOutcome,
|
|
169
|
+
};
|
|
170
|
+
},
|
|
149
171
|
pause: (id, request) => command(id, request, true),
|
|
150
172
|
resume: (id, request) => command(id, request, false),
|
|
151
173
|
};
|
|
@@ -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.72";
|
|
128
128
|
/** The registry-installable version used by packaged sandbox images. */
|
|
129
129
|
export const wakePackageVersion = packageVersion(defaultRepoRoot) ?? wakeVersion;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type CommandContext, type EventJournal } from '@atolis-hq/eventing';
|
|
2
|
-
import { type ControlEventPayloads, type TriggerSource } from '../contracts/events.js';
|
|
2
|
+
import { ControlEventType, type ControlEventPayloads, type TriggerSource } from '../contracts/events.js';
|
|
3
|
+
import type { TriggerSkipReason } from '../contracts/trigger-diagnostics.js';
|
|
3
4
|
export type TriggerFactInput = {
|
|
4
5
|
[Type in keyof ControlEventPayloads]: {
|
|
5
6
|
readonly eventType: Type;
|
|
@@ -9,3 +10,8 @@ export type TriggerFactInput = {
|
|
|
9
10
|
export declare function sourceIdentity(source: TriggerSource): string;
|
|
10
11
|
/** Invocation/command appends check event IDs; source appends use the caught-up scope sequence. */
|
|
11
12
|
export declare function appendTriggerFact(journal: EventJournal, occurredAt: string, input: TriggerFactInput, context: CommandContext, eventId: string, sequence?: number): Promise<void>;
|
|
13
|
+
export declare function hasTriggerRequest(requests: readonly {
|
|
14
|
+
readonly triggerId: string;
|
|
15
|
+
readonly source: TriggerSource;
|
|
16
|
+
}[], triggerId: string, source: TriggerSource): boolean;
|
|
17
|
+
export declare function consumedTriggerRequest(request: ControlEventPayloads[typeof ControlEventType.TriggerRequestRecorded], reason: TriggerSkipReason): TriggerFactInput;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { EventSourceKind, WrongExpectedSequenceError, } from '@atolis-hq/eventing';
|
|
2
2
|
import { createControlPlaneEventData } from '../contracts/event-factory.js';
|
|
3
|
-
import { TriggerSourceKind, } from '../contracts/events.js';
|
|
3
|
+
import { ControlEventType, ManualTriggerDisposition, TriggerRequestDisposition, TriggerSourceKind, } from '../contracts/events.js';
|
|
4
4
|
import { triggerControlStream, triggerInvocationStream } from '../contracts/streams.js';
|
|
5
5
|
export function sourceIdentity(source) {
|
|
6
|
-
return `${source.kind}:${source.kind === TriggerSourceKind.Cron ? source.slot : source.eventId}`;
|
|
6
|
+
return `${source.kind}:${source.kind === TriggerSourceKind.Cron ? source.slot : source.kind === TriggerSourceKind.Manual ? source.commandId : source.eventId}`;
|
|
7
7
|
}
|
|
8
8
|
/** Invocation/command appends check event IDs; source appends use the caught-up scope sequence. */
|
|
9
9
|
export async function appendTriggerFact(journal, occurredAt, input, context, eventId, sequence) {
|
|
@@ -36,3 +36,20 @@ export async function appendTriggerFact(journal, occurredAt, input, context, eve
|
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
|
+
export function hasTriggerRequest(requests, triggerId, source) {
|
|
40
|
+
return requests.some((request) => request.triggerId === triggerId && sourceIdentity(request.source) === sourceIdentity(source));
|
|
41
|
+
}
|
|
42
|
+
export function consumedTriggerRequest(request, reason) {
|
|
43
|
+
return {
|
|
44
|
+
eventType: ControlEventType.TriggerRequestRecorded,
|
|
45
|
+
payload: {
|
|
46
|
+
triggerId: request.triggerId,
|
|
47
|
+
coordinationKey: request.coordinationKey,
|
|
48
|
+
source: request.source,
|
|
49
|
+
disposition: TriggerRequestDisposition.Skipped,
|
|
50
|
+
manualOutcome: request.manualOutcome?.disposition === ManualTriggerDisposition.Started
|
|
51
|
+
? { disposition: ManualTriggerDisposition.Skipped, reason }
|
|
52
|
+
: request.manualOutcome,
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { CommandContext } from '@atolis-hq/eventing';
|
|
2
|
+
import type { TriggerConfig } from '../contracts/config.js';
|
|
3
|
+
import { type ManualTriggerOutcome } from '../contracts/events.js';
|
|
4
|
+
import type { TriggerDiagnostics } from './trigger-diagnostics.js';
|
|
5
|
+
import { type TriggerFactInput } from './trigger-facts.js';
|
|
6
|
+
import { type TriggerView } from './trigger-projection.js';
|
|
7
|
+
import type { TriggerServiceDependencies } from './trigger-service-ports.js';
|
|
8
|
+
interface ManualRequestPorts {
|
|
9
|
+
readonly dependencies: TriggerServiceDependencies;
|
|
10
|
+
readonly diagnostics: TriggerDiagnostics;
|
|
11
|
+
readonly config: TriggerConfig | undefined;
|
|
12
|
+
readonly coordinationKey: () => string;
|
|
13
|
+
readonly view: () => Promise<TriggerView>;
|
|
14
|
+
readonly recover: (context: CommandContext) => Promise<void>;
|
|
15
|
+
readonly advance: (context: CommandContext) => Promise<void>;
|
|
16
|
+
readonly emit: (input: TriggerFactInput, context: CommandContext, eventId: string) => Promise<void>;
|
|
17
|
+
}
|
|
18
|
+
export declare function requestManualTrigger(ports: ManualRequestPorts, triggerId: string, context: CommandContext): Promise<ManualTriggerOutcome>;
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { ControlEventType, ManualTriggerDisposition, selectControlEvent, TriggerRequestDisposition, TriggerSourceKind, } from '../contracts/events.js';
|
|
2
|
+
import { TriggerSkipReason } from '../contracts/trigger-diagnostics.js';
|
|
3
|
+
import { consumedTriggerRequest, sourceIdentity } from './trigger-facts.js';
|
|
4
|
+
import { maximumTriggerSources } from './trigger-projection.js';
|
|
5
|
+
import { hasActiveInvocation } from './trigger-rules.js';
|
|
6
|
+
export async function requestManualTrigger(ports, triggerId, context) {
|
|
7
|
+
await ports.view();
|
|
8
|
+
const coordinationKey = ports.coordinationKey();
|
|
9
|
+
const eventId = `trigger:request:${triggerId}:manual:${context.commandId}`;
|
|
10
|
+
const previous = await recoverManualOutcome(ports, triggerId, context);
|
|
11
|
+
if (previous !== undefined) {
|
|
12
|
+
await ports.recover(context);
|
|
13
|
+
await ports.advance(context);
|
|
14
|
+
return (await recoverManualOutcome(ports, triggerId, context)) ?? previous;
|
|
15
|
+
}
|
|
16
|
+
await ports.recover(context);
|
|
17
|
+
const view = await ports.view();
|
|
18
|
+
const config = ports.config;
|
|
19
|
+
const active = hasActiveInvocation(view, coordinationKey);
|
|
20
|
+
const reason = (await ports.diagnostics.ineligibleReason(view, triggerId, config, config !== undefined, active)) ??
|
|
21
|
+
((view.coalesced[coordinationKey]?.sources.length ?? 0) >= maximumTriggerSources
|
|
22
|
+
? TriggerSkipReason.PendingLimit
|
|
23
|
+
: undefined);
|
|
24
|
+
const outcome = reason === undefined
|
|
25
|
+
? {
|
|
26
|
+
disposition: active
|
|
27
|
+
? ManualTriggerDisposition.Coalesced
|
|
28
|
+
: ManualTriggerDisposition.Started,
|
|
29
|
+
}
|
|
30
|
+
: { disposition: ManualTriggerDisposition.Skipped, reason };
|
|
31
|
+
const source = {
|
|
32
|
+
kind: TriggerSourceKind.Manual,
|
|
33
|
+
commandId: context.commandId,
|
|
34
|
+
operator: context.actor.id,
|
|
35
|
+
};
|
|
36
|
+
await ports.emit({
|
|
37
|
+
eventType: ControlEventType.TriggerRequestRecorded,
|
|
38
|
+
payload: {
|
|
39
|
+
triggerId,
|
|
40
|
+
coordinationKey,
|
|
41
|
+
source,
|
|
42
|
+
manualOutcome: outcome,
|
|
43
|
+
disposition: reason === undefined
|
|
44
|
+
? TriggerRequestDisposition.Coalesced
|
|
45
|
+
: TriggerRequestDisposition.Skipped,
|
|
46
|
+
},
|
|
47
|
+
}, context, eventId);
|
|
48
|
+
if (reason !== undefined)
|
|
49
|
+
await ports.diagnostics.record(triggerId, source, reason);
|
|
50
|
+
await ports.advance(context);
|
|
51
|
+
return (await recoverManualOutcome(ports, triggerId, context)) ?? outcome;
|
|
52
|
+
}
|
|
53
|
+
async function recoverManualOutcome(ports, triggerId, context) {
|
|
54
|
+
// Command identity survives changes to the configured coordination scope.
|
|
55
|
+
let position = 0;
|
|
56
|
+
let request;
|
|
57
|
+
let pauseCleared = false;
|
|
58
|
+
const latest = await ports.dependencies.journal.latestGlobalPosition();
|
|
59
|
+
while (position < latest) {
|
|
60
|
+
const batch = await ports.dependencies.journal.readAll(position, 256);
|
|
61
|
+
if (batch.length === 0)
|
|
62
|
+
throw new Error('Manual command journal cursor did not advance');
|
|
63
|
+
for (const envelope of batch) {
|
|
64
|
+
const event = selectControlEvent(envelope);
|
|
65
|
+
request = matchingManualRequest(event, triggerId, context.commandId) ?? request;
|
|
66
|
+
if (event?.event.eventType === ControlEventType.TriggerPaused &&
|
|
67
|
+
event.event.payload.coordinationKey === request?.coordinationKey)
|
|
68
|
+
pauseCleared = true;
|
|
69
|
+
position = envelope.globalPosition;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return resolvePausedRequest(ports, request, pauseCleared, context);
|
|
73
|
+
}
|
|
74
|
+
async function resolvePausedRequest(ports, request, pauseCleared, context) {
|
|
75
|
+
if (request?.manualOutcome?.disposition !== ManualTriggerDisposition.Started || !pauseCleared)
|
|
76
|
+
return request?.manualOutcome;
|
|
77
|
+
const history = await ports.dependencies.history();
|
|
78
|
+
if (history.some((invocation) => invocation.claim.triggerId === request.triggerId &&
|
|
79
|
+
invocation.claim.sources.some((source) => sourceIdentity(source) === sourceIdentity(request.source))))
|
|
80
|
+
return request.manualOutcome;
|
|
81
|
+
// Pause clears unclaimed requests, but a committed claim still recovers normally.
|
|
82
|
+
const fact = consumedTriggerRequest(request, TriggerSkipReason.Paused);
|
|
83
|
+
await ports.emit(fact, context, 'trigger:consume:' + request.triggerId + ':' + sourceIdentity(request.source));
|
|
84
|
+
await ports.diagnostics.record(request.triggerId, request.source, TriggerSkipReason.Paused);
|
|
85
|
+
return { disposition: ManualTriggerDisposition.Skipped, reason: TriggerSkipReason.Paused };
|
|
86
|
+
}
|
|
87
|
+
function matchingManualRequest(event, triggerId, commandId) {
|
|
88
|
+
if (event?.event.eventType === ControlEventType.TriggerRequestRecorded &&
|
|
89
|
+
event.event.payload.triggerId === triggerId &&
|
|
90
|
+
event.event.payload.source.kind === TriggerSourceKind.Manual &&
|
|
91
|
+
event.event.payload.source.commandId === commandId &&
|
|
92
|
+
event.event.payload.manualOutcome !== undefined)
|
|
93
|
+
return event.event.payload;
|
|
94
|
+
return undefined;
|
|
95
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { CommandContext, EventEnvelope } from '@atolis-hq/eventing';
|
|
2
2
|
import type { TriggerConfig } from '../contracts/config.js';
|
|
3
|
-
import { type TriggerSource } from '../contracts/events.js';
|
|
3
|
+
import { TriggerSourceKind, type ManualTriggerOutcome, type TriggerSource } from '../contracts/events.js';
|
|
4
4
|
import { type TriggerSkipDiagnostic } from '../contracts/trigger-diagnostics.js';
|
|
5
5
|
import { type TriggerView } from './trigger-projection.js';
|
|
6
6
|
import type { TriggerServiceDependencies } from './trigger-service-ports.js';
|
|
@@ -22,16 +22,17 @@ export declare class TriggerService {
|
|
|
22
22
|
reconcile(context: CommandContext): Promise<void>;
|
|
23
23
|
pause(triggerId: string, reason: string, context: CommandContext): Promise<void>;
|
|
24
24
|
resume(triggerId: string, context: CommandContext): Promise<void>;
|
|
25
|
+
requestManual(triggerId: string, context: CommandContext): Promise<ManualTriggerOutcome>;
|
|
25
26
|
run(config: TriggerConfig, context: CommandContext): Promise<readonly string[]>;
|
|
26
|
-
start(config: TriggerConfig, source: TriggerSource,
|
|
27
|
+
start(config: TriggerConfig, source: Exclude<TriggerSource, {
|
|
28
|
+
kind: typeof TriggerSourceKind.Manual;
|
|
29
|
+
}>, context: CommandContext, event?: EventEnvelope): Promise<boolean>;
|
|
27
30
|
private serialise;
|
|
28
31
|
private key;
|
|
29
32
|
private commandKey;
|
|
30
|
-
private view;
|
|
31
33
|
private configured;
|
|
32
34
|
private emit;
|
|
33
35
|
private request;
|
|
34
|
-
private suppressed;
|
|
35
36
|
private advanceCoalesced;
|
|
36
37
|
private recover;
|
|
37
38
|
}
|
|
@@ -3,7 +3,8 @@ import { ControlEventType, TriggerRequestDisposition, TriggerSourceKind, } from
|
|
|
3
3
|
import { TriggerSkipReason } from '../contracts/trigger-diagnostics.js';
|
|
4
4
|
import { CronTriggerPolicy } from '../domain/cron-trigger-policy.js';
|
|
5
5
|
import { TriggerDiagnostics } from './trigger-diagnostics.js';
|
|
6
|
-
import { appendTriggerFact, sourceIdentity } from './trigger-facts.js';
|
|
6
|
+
import { appendTriggerFact, consumedTriggerRequest, hasTriggerRequest, sourceIdentity, } from './trigger-facts.js';
|
|
7
|
+
import { requestManualTrigger } from './trigger-manual-request.js';
|
|
7
8
|
import { maximumTriggerSources } from './trigger-projection.js';
|
|
8
9
|
import { recoverTriggerInvocation } from './trigger-recovery.js';
|
|
9
10
|
import { hasActiveInvocation, isOwnScopeSource } from './trigger-rules.js';
|
|
@@ -25,7 +26,7 @@ export class TriggerService {
|
|
|
25
26
|
}
|
|
26
27
|
async get() {
|
|
27
28
|
return this.serialise(async () => ({
|
|
28
|
-
...(await this.
|
|
29
|
+
...(await this.reader.get()),
|
|
29
30
|
invocations: await this.dependencies.history(),
|
|
30
31
|
diagnostics: await this.diagnostics.get(),
|
|
31
32
|
}));
|
|
@@ -38,7 +39,7 @@ export class TriggerService {
|
|
|
38
39
|
}
|
|
39
40
|
async pause(triggerId, reason, context) {
|
|
40
41
|
await this.serialise(async () => {
|
|
41
|
-
await this.
|
|
42
|
+
await this.reader.get();
|
|
42
43
|
await this.emit({
|
|
43
44
|
eventType: ControlEventType.TriggerPaused,
|
|
44
45
|
payload: { triggerId, reason, coordinationKey: this.commandKey(triggerId) },
|
|
@@ -47,13 +48,25 @@ export class TriggerService {
|
|
|
47
48
|
}
|
|
48
49
|
async resume(triggerId, context) {
|
|
49
50
|
await this.serialise(async () => {
|
|
50
|
-
await this.
|
|
51
|
+
await this.reader.get();
|
|
51
52
|
await this.emit({
|
|
52
53
|
eventType: ControlEventType.TriggerResumed,
|
|
53
54
|
payload: { triggerId, coordinationKey: this.commandKey(triggerId) },
|
|
54
55
|
}, context, `trigger:resume:${triggerId}:${context.commandId}`);
|
|
55
56
|
});
|
|
56
57
|
}
|
|
58
|
+
async requestManual(triggerId, context) {
|
|
59
|
+
return this.serialise(() => requestManualTrigger({
|
|
60
|
+
dependencies: this.dependencies,
|
|
61
|
+
diagnostics: this.diagnostics,
|
|
62
|
+
config: this.configured(triggerId),
|
|
63
|
+
coordinationKey: () => this.commandKey(triggerId),
|
|
64
|
+
view: () => this.reader.get(),
|
|
65
|
+
recover: (command) => this.recover(command),
|
|
66
|
+
advance: (command) => this.advanceCoalesced(command),
|
|
67
|
+
emit: (input, command, id) => this.emit(input, command, id),
|
|
68
|
+
}, triggerId, context));
|
|
69
|
+
}
|
|
57
70
|
async run(config, context) {
|
|
58
71
|
return this.serialise(async () => {
|
|
59
72
|
const accepted = [];
|
|
@@ -99,24 +112,20 @@ export class TriggerService {
|
|
|
99
112
|
?.coordinationKey ?? triggerId)
|
|
100
113
|
: this.key(config);
|
|
101
114
|
}
|
|
102
|
-
view() {
|
|
103
|
-
return this.reader.get();
|
|
104
|
-
}
|
|
105
115
|
configured(id) {
|
|
106
116
|
return this.dependencies.configurations().find((config) => config.id === id);
|
|
107
117
|
}
|
|
108
118
|
async emit(input, context, eventId) {
|
|
109
|
-
await this.
|
|
119
|
+
await this.reader.get();
|
|
110
120
|
await appendTriggerFact(this.dependencies.journal, this.dependencies.now(), input, context, eventId, input.eventType === ControlEventType.TriggerRequestRecorded
|
|
111
121
|
? this.reader.sequence(input.payload.coordinationKey)
|
|
112
122
|
: undefined);
|
|
113
123
|
}
|
|
114
124
|
async request(config, source, context, event) {
|
|
115
|
-
const view = await this.
|
|
125
|
+
const view = await this.reader.get();
|
|
116
126
|
if (await this.sourceCursor.isConsumed(config.id, source, event))
|
|
117
127
|
return false;
|
|
118
|
-
const duplicate = view.requests
|
|
119
|
-
sourceIdentity(request.source) === sourceIdentity(source));
|
|
128
|
+
const duplicate = hasTriggerRequest(view.requests, config.id, source);
|
|
120
129
|
const coordinationKey = this.key(config);
|
|
121
130
|
// The reactor checkpoint consumes suppressed sources. Emitting another trigger request
|
|
122
131
|
// here could itself become a source when subscribed to Control Plane events.
|
|
@@ -124,7 +133,14 @@ export class TriggerService {
|
|
|
124
133
|
await this.sourceCursor.consume(config.id, source, event);
|
|
125
134
|
return false;
|
|
126
135
|
}
|
|
127
|
-
if (await
|
|
136
|
+
if (await isOwnScopeSource(view, { triggerId: config.id, coordinationKey }, event, {
|
|
137
|
+
keyOf: (id) => {
|
|
138
|
+
const other = this.configured(id);
|
|
139
|
+
return other === undefined ? undefined : this.key(other);
|
|
140
|
+
},
|
|
141
|
+
sourceWorkItem: this.dependencies.sourceWorkItem,
|
|
142
|
+
invocationScope: this.dependencies.invocationScope,
|
|
143
|
+
})) {
|
|
128
144
|
await this.diagnostics.record(config.id, source, TriggerSkipReason.OwnScope);
|
|
129
145
|
await this.sourceCursor.consume(config.id, source, event);
|
|
130
146
|
return false;
|
|
@@ -148,18 +164,8 @@ export class TriggerService {
|
|
|
148
164
|
await this.sourceCursor.consume(config.id, source, event);
|
|
149
165
|
return eligible;
|
|
150
166
|
}
|
|
151
|
-
suppressed(view, config, coordinationKey, event) {
|
|
152
|
-
return isOwnScopeSource(view, { triggerId: config.id, coordinationKey }, event, {
|
|
153
|
-
keyOf: (id) => {
|
|
154
|
-
const other = this.configured(id);
|
|
155
|
-
return other === undefined ? undefined : this.key(other);
|
|
156
|
-
},
|
|
157
|
-
sourceWorkItem: this.dependencies.sourceWorkItem,
|
|
158
|
-
invocationScope: this.dependencies.invocationScope,
|
|
159
|
-
});
|
|
160
|
-
}
|
|
161
167
|
async advanceCoalesced(context) {
|
|
162
|
-
const view = await this.
|
|
168
|
+
const view = await this.reader.get();
|
|
163
169
|
for (const request of Object.values(view.coalesced)) {
|
|
164
170
|
if (hasActiveInvocation(view, request.coordinationKey))
|
|
165
171
|
continue;
|
|
@@ -169,15 +175,7 @@ export class TriggerService {
|
|
|
169
175
|
if (reason !== undefined || config === undefined) {
|
|
170
176
|
await this.diagnostics.record(request.triggerId, request.source, reason ?? TriggerSkipReason.Removed);
|
|
171
177
|
// This recorded request was reconsidered and consumed; later eligibility is not a source.
|
|
172
|
-
await this.emit({
|
|
173
|
-
eventType: ControlEventType.TriggerRequestRecorded,
|
|
174
|
-
payload: {
|
|
175
|
-
triggerId: request.triggerId,
|
|
176
|
-
coordinationKey: request.coordinationKey,
|
|
177
|
-
source: request.source,
|
|
178
|
-
disposition: TriggerRequestDisposition.Skipped,
|
|
179
|
-
},
|
|
180
|
-
}, context, `trigger:consume:${request.triggerId}:${sourceIdentity(request.source)}`);
|
|
178
|
+
await this.emit(consumedTriggerRequest(request, reason ?? TriggerSkipReason.Removed), context, `trigger:consume:${request.triggerId}:${sourceIdentity(request.source)}`);
|
|
181
179
|
continue;
|
|
182
180
|
}
|
|
183
181
|
await this.emit({
|
|
@@ -196,7 +194,7 @@ export class TriggerService {
|
|
|
196
194
|
}
|
|
197
195
|
}
|
|
198
196
|
async recover(context) {
|
|
199
|
-
for (const invocation of (await this.
|
|
197
|
+
for (const invocation of (await this.reader.get()).invocations) {
|
|
200
198
|
if (invocation.result === undefined)
|
|
201
199
|
await recoverTriggerInvocation({
|
|
202
200
|
work: this.dependencies.work,
|
|
@@ -26,8 +26,37 @@ export declare const TriggerRequestDisposition: {
|
|
|
26
26
|
export declare const TriggerSourceKind: {
|
|
27
27
|
readonly Event: "event";
|
|
28
28
|
readonly Cron: "cron";
|
|
29
|
+
readonly Manual: "manual";
|
|
30
|
+
};
|
|
31
|
+
declare const manualStartedShape: {
|
|
32
|
+
started: boolean;
|
|
33
|
+
};
|
|
34
|
+
export declare const ManualTriggerDisposition: {
|
|
35
|
+
readonly Started: keyof typeof manualStartedShape;
|
|
36
|
+
readonly Coalesced: "coalesced";
|
|
37
|
+
readonly Skipped: "skipped";
|
|
29
38
|
};
|
|
39
|
+
export declare const manualTriggerOutcomeSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
40
|
+
disposition: z.ZodLiteral<"started">;
|
|
41
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
42
|
+
disposition: z.ZodLiteral<"coalesced">;
|
|
43
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
44
|
+
disposition: z.ZodLiteral<"skipped">;
|
|
45
|
+
reason: z.ZodEnum<{
|
|
46
|
+
readonly OwnScope: "own-scope";
|
|
47
|
+
readonly Paused: "paused";
|
|
48
|
+
readonly Removed: "removed";
|
|
49
|
+
readonly DispatchPaused: "dispatch-paused";
|
|
50
|
+
readonly Capacity: "capacity-unavailable";
|
|
51
|
+
readonly PendingLimit: "pending-source-limit";
|
|
52
|
+
}>;
|
|
53
|
+
}, z.core.$strict>], "disposition">;
|
|
54
|
+
export type ManualTriggerOutcome = z.infer<typeof manualTriggerOutcomeSchema>;
|
|
30
55
|
export declare const triggerSourceSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
56
|
+
kind: z.ZodLiteral<"manual">;
|
|
57
|
+
commandId: z.ZodString;
|
|
58
|
+
operator: z.ZodString;
|
|
59
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
31
60
|
kind: z.ZodLiteral<"event">;
|
|
32
61
|
eventId: z.ZodString;
|
|
33
62
|
eventType: z.ZodString;
|
|
@@ -41,6 +70,7 @@ export interface ControlEventPayloads {
|
|
|
41
70
|
readonly triggerId: string;
|
|
42
71
|
readonly coordinationKey: string;
|
|
43
72
|
readonly source: TriggerSource;
|
|
73
|
+
readonly manualOutcome?: ManualTriggerOutcome | undefined;
|
|
44
74
|
readonly disposition: (typeof TriggerRequestDisposition)[keyof typeof TriggerRequestDisposition];
|
|
45
75
|
};
|
|
46
76
|
readonly [ControlEventType.TriggerInvocationClaimed]: {
|
|
@@ -2,6 +2,7 @@ import { eventDataSchema, eventEnvelopeSchema, } from '@atolis-hq/eventing';
|
|
|
2
2
|
import { z } from 'zod';
|
|
3
3
|
import { WorkflowStatus } from '../../orchestration/index.js';
|
|
4
4
|
import { ControlStreamKind, } from './streams.js';
|
|
5
|
+
import { TriggerSkipReason } from './trigger-skip-reason.js';
|
|
5
6
|
export const ControlEventType = {
|
|
6
7
|
TriggerRequestRecorded: 'control-plane.trigger-request-recorded',
|
|
7
8
|
TriggerInvocationClaimed: 'control-plane.trigger-invocation-claimed',
|
|
@@ -17,8 +18,31 @@ export const ControlEventType = {
|
|
|
17
18
|
export const RunnerPauseCause = { Manual: 'manual', Quota: 'quota' };
|
|
18
19
|
export const ControlEventNamespace = 'control-plane.';
|
|
19
20
|
export const TriggerRequestDisposition = { Coalesced: 'coalesced', Skipped: 'skipped' };
|
|
20
|
-
export const TriggerSourceKind = { Event: 'event', Cron: 'cron' };
|
|
21
|
+
export const TriggerSourceKind = { Event: 'event', Cron: 'cron', Manual: 'manual' };
|
|
22
|
+
const manualStartedShape = { started: true };
|
|
23
|
+
export const ManualTriggerDisposition = {
|
|
24
|
+
Started: Object.keys(manualStartedShape)[0],
|
|
25
|
+
Coalesced: TriggerRequestDisposition.Coalesced,
|
|
26
|
+
Skipped: TriggerRequestDisposition.Skipped,
|
|
27
|
+
};
|
|
28
|
+
export const manualTriggerOutcomeSchema = z.discriminatedUnion('disposition', [
|
|
29
|
+
z.object({ disposition: z.literal(ManualTriggerDisposition.Started) }).strict(),
|
|
30
|
+
z.object({ disposition: z.literal(ManualTriggerDisposition.Coalesced) }).strict(),
|
|
31
|
+
z
|
|
32
|
+
.object({
|
|
33
|
+
disposition: z.literal(ManualTriggerDisposition.Skipped),
|
|
34
|
+
reason: z.enum(TriggerSkipReason),
|
|
35
|
+
})
|
|
36
|
+
.strict(),
|
|
37
|
+
]);
|
|
21
38
|
export const triggerSourceSchema = z.discriminatedUnion('kind', [
|
|
39
|
+
z
|
|
40
|
+
.object({
|
|
41
|
+
kind: z.literal(TriggerSourceKind.Manual),
|
|
42
|
+
commandId: z.string().min(1),
|
|
43
|
+
operator: z.string().min(1),
|
|
44
|
+
})
|
|
45
|
+
.strict(),
|
|
22
46
|
z
|
|
23
47
|
.object({
|
|
24
48
|
kind: z.literal(TriggerSourceKind.Event),
|
|
@@ -52,6 +76,7 @@ const eventSchema = z.union([
|
|
|
52
76
|
coordinationKey: z.string().min(1),
|
|
53
77
|
source: triggerSourceSchema,
|
|
54
78
|
disposition: z.enum(TriggerRequestDisposition),
|
|
79
|
+
manualOutcome: manualTriggerOutcomeSchema.optional(),
|
|
55
80
|
})
|
|
56
81
|
.strict(),
|
|
57
82
|
}),
|
|
@@ -1,17 +1,12 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
|
|
3
|
-
export declare const TriggerSkipReason: {
|
|
4
|
-
readonly OwnScope: "own-scope";
|
|
5
|
-
readonly Paused: "paused";
|
|
6
|
-
readonly Removed: "removed";
|
|
7
|
-
readonly DispatchPaused: "dispatch-paused";
|
|
8
|
-
readonly Capacity: "capacity-unavailable";
|
|
9
|
-
readonly PendingLimit: "pending-source-limit";
|
|
10
|
-
};
|
|
11
|
-
export type TriggerSkipReason = ValueOf<typeof TriggerSkipReason>;
|
|
2
|
+
export { TriggerSkipReason } from './trigger-skip-reason.js';
|
|
12
3
|
export declare const triggerSkipDiagnosticSchema: z.ZodObject<{
|
|
13
4
|
triggerId: z.ZodString;
|
|
14
5
|
source: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
6
|
+
kind: z.ZodLiteral<"manual">;
|
|
7
|
+
commandId: z.ZodString;
|
|
8
|
+
operator: z.ZodString;
|
|
9
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
15
10
|
kind: z.ZodLiteral<"event">;
|
|
16
11
|
eventId: z.ZodString;
|
|
17
12
|
eventType: z.ZodString;
|
|
@@ -34,6 +29,10 @@ export declare const maximumTriggerDiagnostics = 256;
|
|
|
34
29
|
export declare const triggerDiagnosticsSchema: z.ZodArray<z.ZodObject<{
|
|
35
30
|
triggerId: z.ZodString;
|
|
36
31
|
source: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
32
|
+
kind: z.ZodLiteral<"manual">;
|
|
33
|
+
commandId: z.ZodString;
|
|
34
|
+
operator: z.ZodString;
|
|
35
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
37
36
|
kind: z.ZodLiteral<"event">;
|
|
38
37
|
eventId: z.ZodString;
|
|
39
38
|
eventType: z.ZodString;
|
|
@@ -1,13 +1,7 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { triggerSourceSchema } from './events.js';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Paused: 'paused',
|
|
6
|
-
Removed: 'removed',
|
|
7
|
-
DispatchPaused: 'dispatch-paused',
|
|
8
|
-
Capacity: 'capacity-unavailable',
|
|
9
|
-
PendingLimit: 'pending-source-limit',
|
|
10
|
-
};
|
|
3
|
+
import { TriggerSkipReason } from './trigger-skip-reason.js';
|
|
4
|
+
export { TriggerSkipReason } from './trigger-skip-reason.js';
|
|
11
5
|
export const triggerSkipDiagnosticSchema = z
|
|
12
6
|
.object({
|
|
13
7
|
triggerId: z.string().min(1),
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ValueOf } from '../../kernel/index.js';
|
|
2
|
+
export declare const TriggerSkipReason: {
|
|
3
|
+
readonly OwnScope: "own-scope";
|
|
4
|
+
readonly Paused: "paused";
|
|
5
|
+
readonly Removed: "removed";
|
|
6
|
+
readonly DispatchPaused: "dispatch-paused";
|
|
7
|
+
readonly Capacity: "capacity-unavailable";
|
|
8
|
+
readonly PendingLimit: "pending-source-limit";
|
|
9
|
+
};
|
|
10
|
+
export type TriggerSkipReason = ValueOf<typeof TriggerSkipReason>;
|
|
@@ -52,9 +52,8 @@ export function codexCommandArgs(request, passthroughArgs = [], defaults = {}) {
|
|
|
52
52
|
'exec',
|
|
53
53
|
'--json',
|
|
54
54
|
'--skip-git-repo-check',
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
: ['--sandbox', codexSandboxMode(request.workspaceMode)]),
|
|
55
|
+
'--sandbox',
|
|
56
|
+
CODEX_SANDBOX_MODE,
|
|
58
57
|
...(request.workspacePath === undefined ? [] : ['--cd', request.workspacePath]),
|
|
59
58
|
...(model === undefined ? [] : ['--model', model]),
|
|
60
59
|
...((request.effort ?? defaults.effort) === undefined
|
|
@@ -78,11 +77,11 @@ function codexMcpConfigArgs(request) {
|
|
|
78
77
|
}
|
|
79
78
|
// Work around Codex's missing background-command lifecycle contract (https://github.com/openai/codex/issues/32505, https://github.com/openai/codex/issues/34866).
|
|
80
79
|
const waitBackgroundInstruction = `When a command you started is still running or lacks a terminal result, do not report a normal Wake outcome. Make your entire final response exactly WAIT_BACKGROUND. Wake will reject that stop attempt and ask you to continue. After that hook prompt, poll the still-running command and report a normal terminal status only after it has settled. Do not use WAIT_BACKGROUND for a human-input or implementation blocker.`;
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
80
|
+
// Wake executes runners inside its Docker sandbox. Avoid asking Codex to
|
|
81
|
+
// create a second Linux namespace sandbox, which container runtimes may deny.
|
|
82
|
+
// Applies to stages without a workspace too: Codex's default sandbox cannot
|
|
83
|
+
// start here and denies MCP tool approvals under non-interactive exec.
|
|
84
|
+
const CODEX_SANDBOX_MODE = 'danger-full-access';
|
|
86
85
|
export function parseCodexOutput(stdout, request) {
|
|
87
86
|
let state = {};
|
|
88
87
|
for (const line of stdout.split(/\r?\n/)) {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ManualTriggerOutcome } from '../../../control-plane/index.js';
|
|
1
2
|
import { type ValueOf } from '../../../kernel/index.js';
|
|
2
3
|
export interface ControlPlaneStatusResponse {
|
|
3
4
|
readonly dispatchPaused: boolean;
|
|
@@ -18,6 +19,7 @@ export interface ControlPlaneStatusResponse {
|
|
|
18
19
|
};
|
|
19
20
|
}
|
|
20
21
|
export interface AcceptedCommandResponse {
|
|
22
|
+
readonly triggerOutcome?: ManualTriggerOutcome;
|
|
21
23
|
readonly commandId: string;
|
|
22
24
|
readonly idempotencyKey: string;
|
|
23
25
|
readonly acceptedAt: string;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { ActivityOutcomeKind } from '../../../activities/index.js';
|
|
2
|
-
import type { TriggerRequestDisposition, TriggerSkipReason, TriggerSourceKind } from '../../../control-plane/index.js';
|
|
2
|
+
import type { ManualTriggerDisposition, TriggerRequestDisposition, TriggerSkipReason, TriggerSourceKind } from '../../../control-plane/index.js';
|
|
3
3
|
import type { RunStatus } from '../../../execution/index.js';
|
|
4
4
|
import type { ApiCommandStatus } from './control-plane.js';
|
|
5
|
+
import type { TriggerCommandName } from './triggers.js';
|
|
5
6
|
export declare const AcceptedCommandStatusValue: {
|
|
6
7
|
readonly Accepted: ApiCommandStatus;
|
|
7
8
|
readonly Completed: ApiCommandStatus;
|
|
@@ -50,4 +51,6 @@ export declare const TriggerFinishedStatusValue: {
|
|
|
50
51
|
readonly Completed: "completed" | "superseded";
|
|
51
52
|
readonly Superseded: "completed" | "superseded";
|
|
52
53
|
};
|
|
54
|
+
export declare const ManualTriggerDispositionValue: typeof ManualTriggerDisposition;
|
|
55
|
+
export declare const TriggerCommandNameValue: typeof TriggerCommandName;
|
|
53
56
|
export {};
|
|
@@ -62,6 +62,7 @@ export const TranscriptGroupKindValue = {
|
|
|
62
62
|
export const TriggerSourceKindValue = {
|
|
63
63
|
Event: 'event',
|
|
64
64
|
Cron: 'cron',
|
|
65
|
+
Manual: 'manual',
|
|
65
66
|
};
|
|
66
67
|
export const TriggerRequestDispositionValue = {
|
|
67
68
|
Coalesced: 'coalesced',
|
|
@@ -81,3 +82,16 @@ export const TriggerFinishedStatusValue = {
|
|
|
81
82
|
Completed: triggerFinishedStatuses[0],
|
|
82
83
|
Superseded: triggerFinishedStatuses[1],
|
|
83
84
|
};
|
|
85
|
+
const manualStartedShape = { started: true };
|
|
86
|
+
export const ManualTriggerDispositionValue = {
|
|
87
|
+
Started: Object.keys(manualStartedShape)[0],
|
|
88
|
+
Coalesced: TriggerRequestDispositionValue.Coalesced,
|
|
89
|
+
Skipped: TriggerRequestDispositionValue.Skipped,
|
|
90
|
+
};
|
|
91
|
+
const triggerCommandShape = { pause: true, resume: true, run: true };
|
|
92
|
+
const triggerCommands = Object.keys(triggerCommandShape);
|
|
93
|
+
export const TriggerCommandNameValue = {
|
|
94
|
+
Pause: triggerCommands[0],
|
|
95
|
+
Resume: triggerCommands[1],
|
|
96
|
+
Run: triggerCommands[2],
|
|
97
|
+
};
|