@atolis-hq/wake 0.4.110 → 0.4.111
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/board-projection.d.ts +4 -0
- package/dist/src/bootstrap/board-projection.js +33 -19
- package/dist/src/bootstrap/composition-root.d.ts +3 -1
- package/dist/src/bootstrap/composition-root.js +21 -6
- package/dist/src/bootstrap/delegated-artifact-context.d.ts +15 -0
- package/dist/src/bootstrap/delegated-artifact-context.js +17 -0
- package/dist/src/bootstrap/initialise.js +20 -2
- package/dist/src/bootstrap/integration-runtime.js +1 -0
- package/dist/src/bootstrap/objective-title-context.d.ts +7 -0
- package/dist/src/bootstrap/objective-title-context.js +15 -0
- package/dist/src/bootstrap/surface-api-delivery.js +6 -1
- package/dist/src/bootstrap/surface-api-work-applications.js +39 -5
- package/dist/src/bootstrap/surface-api-workflow-diagrams.js +8 -4
- package/dist/src/bootstrap/version.js +1 -1
- package/dist/src/conversations/application/control-plane-entry.d.ts +14 -0
- package/dist/src/conversations/application/control-plane-entry.js +16 -0
- package/dist/src/conversations/index.d.ts +1 -0
- package/dist/src/conversations/index.js +1 -0
- package/dist/src/integrations/application/agent-run-publication-reactor.d.ts +2 -1
- package/dist/src/integrations/application/agent-run-publication-reactor.js +6 -17
- package/dist/src/integrations/application/agent-run-publication-target.d.ts +12 -0
- package/dist/src/integrations/application/agent-run-publication-target.js +31 -0
- package/dist/src/integrations/application/artifact-registration-reactor.js +4 -2
- package/dist/src/integrations/contracts/provider.d.ts +5 -0
- package/dist/src/integrations/github/application/inbound-translator.d.ts +7 -0
- package/dist/src/integrations/github/application/inbound-translator.js +46 -0
- package/dist/src/integrations/github/provider.js +1 -0
- package/dist/src/orchestration/application/conversation-command-reactor.js +6 -25
- package/dist/src/orchestration/application/delegated-work.d.ts +12 -2
- package/dist/src/orchestration/application/delegated-work.js +30 -3
- package/dist/src/orchestration/application/delegation-attention-state.d.ts +2 -0
- package/dist/src/orchestration/application/delegation-attention-state.js +11 -1
- package/dist/src/orchestration/application/delegation-attention.d.ts +9 -11
- package/dist/src/orchestration/application/delegation-attention.js +42 -23
- package/dist/src/orchestration/application/orchestration-service.d.ts +11 -4
- package/dist/src/orchestration/application/orchestration-service.js +22 -16
- package/dist/src/orchestration/application/prerequisite-readiness.d.ts +8 -0
- package/dist/src/orchestration/application/prerequisite-readiness.js +35 -0
- package/dist/src/orchestration/contracts/delegation-ports.d.ts +16 -0
- package/dist/src/orchestration/contracts/delegation.d.ts +6 -4
- package/dist/src/orchestration/contracts/delegation.js +13 -3
- package/dist/src/orchestration/contracts/vocabulary.d.ts +1 -0
- package/dist/src/orchestration/contracts/vocabulary.js +1 -0
- package/dist/src/orchestration/domain/delegated-brief.d.ts +8 -0
- package/dist/src/orchestration/domain/delegated-brief.js +35 -0
- package/dist/src/orchestration/index.d.ts +1 -1
- package/dist/src/resources/contracts/events.js +1 -0
- package/dist/src/resources/contracts/vocabulary.d.ts +2 -0
- package/dist/src/resources/contracts/vocabulary.js +2 -0
- package/dist/src/surfaces/api/contracts/board.d.ts +4 -0
- package/dist/src/surfaces/api/contracts/work.d.ts +9 -0
- package/dist/src/surfaces/mcp/delegation.js +2 -2
- package/dist/src/surfaces/web-assets/assets/index-CHhBIiQQ.js +1192 -0
- package/dist/src/surfaces/web-assets/assets/index-DKNzCDQl.css +1 -0
- package/dist/src/surfaces/web-assets/index.html +2 -2
- package/docker/Dockerfile.runtime +10 -1
- package/docker/Dockerfile.runtime.packaged +10 -1
- package/package.json +1 -1
- package/dist/src/orchestration/application/delegation-attention-escalations.d.ts +0 -11
- package/dist/src/orchestration/application/delegation-attention-escalations.js +0 -36
- package/dist/src/surfaces/web-assets/assets/index-CJVgp3N-.js +0 -1192
- package/dist/src/surfaces/web-assets/assets/index-EVgZ9q9N.css +0 -1
|
@@ -89,9 +89,9 @@ export class ArtifactRegistrationReactor {
|
|
|
89
89
|
await this.recordUnresolved(provider, record, verified, attempt);
|
|
90
90
|
return;
|
|
91
91
|
}
|
|
92
|
-
await this.registerVerified(record, verified, workItemId);
|
|
92
|
+
await this.registerVerified(record, verified, workItemId, provider);
|
|
93
93
|
}
|
|
94
|
-
async registerVerified(record, verified, workItemId) {
|
|
94
|
+
async registerVerified(record, verified, workItemId, provider) {
|
|
95
95
|
const existing = await this.dependencies.resources.findByExternalKey(verified.externalKey);
|
|
96
96
|
// Re-discover an existing resource so a re-report records its newly verified head.
|
|
97
97
|
const resource = await this.dependencies.resources.discover({
|
|
@@ -107,7 +107,9 @@ export class ArtifactRegistrationReactor {
|
|
|
107
107
|
}
|
|
108
108
|
catch {
|
|
109
109
|
// Resources records primary conflicts durably; this flow never guesses a secondary relation.
|
|
110
|
+
return;
|
|
110
111
|
}
|
|
112
|
+
await provider.reobserve?.(verified.externalKey);
|
|
111
113
|
}
|
|
112
114
|
async recordUnresolved(provider, record, result, attempt) {
|
|
113
115
|
const stream = integrationStream(provider.adapter);
|
|
@@ -80,6 +80,11 @@ export interface ProviderInstance {
|
|
|
80
80
|
readonly workspaceRevision?: string;
|
|
81
81
|
readonly pullRequestBase?: string;
|
|
82
82
|
}): Promise<VerifiedArtifact | ArtifactVerificationResult>;
|
|
83
|
+
/**
|
|
84
|
+
* Re-applies the latest journaled observation of a resource Wake has just begun tracking,
|
|
85
|
+
* for observations that arrived before the resource had a WorkItem.
|
|
86
|
+
*/
|
|
87
|
+
readonly reobserve?: (externalKey: ExternalResourceKey) => Promise<void>;
|
|
83
88
|
readonly checkConnectivity?: () => Promise<void>;
|
|
84
89
|
readonly health?: () => readonly AdapterHealthCheck[];
|
|
85
90
|
/** Lets the poll runner report whole-poll failures (lock contention, timeouts) as health. */
|
|
@@ -67,6 +67,13 @@ export declare class InboundTranslator {
|
|
|
67
67
|
private readonly conversations;
|
|
68
68
|
private readonly conversationCapabilities;
|
|
69
69
|
private conversationRecordRecoveryPending;
|
|
70
|
+
/**
|
|
71
|
+
* Applies the newest journaled observation of a pull request Wake has just correlated to
|
|
72
|
+
* a WorkItem. A poll that saw the PR earlier was skipped as unowned, and unchanged evidence
|
|
73
|
+
* is not re-emitted, so without this the PR would never gain its WorkItem observation.
|
|
74
|
+
*/
|
|
75
|
+
reapplyObservation(externalKey: string): Promise<void>;
|
|
76
|
+
private latestPullRequestObservation;
|
|
70
77
|
private reconcileOnce;
|
|
71
78
|
private selectInboundEvent;
|
|
72
79
|
private isTranslatable;
|
|
@@ -88,6 +88,52 @@ export class InboundTranslator {
|
|
|
88
88
|
conversations;
|
|
89
89
|
conversationCapabilities;
|
|
90
90
|
conversationRecordRecoveryPending;
|
|
91
|
+
/**
|
|
92
|
+
* Applies the newest journaled observation of a pull request Wake has just correlated to
|
|
93
|
+
* a WorkItem. A poll that saw the PR earlier was skipped as unowned, and unchanged evidence
|
|
94
|
+
* is not re-emitted, so without this the PR would never gain its WorkItem observation.
|
|
95
|
+
*/
|
|
96
|
+
async reapplyObservation(externalKey) {
|
|
97
|
+
if (this.journal === undefined || this.resources === undefined)
|
|
98
|
+
return;
|
|
99
|
+
const pullRequests = this.pullRequests;
|
|
100
|
+
if (pullRequests === undefined)
|
|
101
|
+
return;
|
|
102
|
+
const latest = await this.latestPullRequestObservation(externalKey);
|
|
103
|
+
if (latest === undefined)
|
|
104
|
+
return;
|
|
105
|
+
const resourceIdValue = await this.lookup?.resourceIdForExternalKey({
|
|
106
|
+
adapter: this.adapter,
|
|
107
|
+
key: externalKey,
|
|
108
|
+
});
|
|
109
|
+
if (resourceIdValue === null || resourceIdValue === undefined)
|
|
110
|
+
return;
|
|
111
|
+
const primary = (await this.resources.correlations(resourceIdValue)).find((correlation) => correlation.role === ResourceCorrelationRole.Primary);
|
|
112
|
+
if (primary === undefined)
|
|
113
|
+
return;
|
|
114
|
+
await this.applyReobservation({
|
|
115
|
+
payload: latest.event.payload,
|
|
116
|
+
context: {
|
|
117
|
+
...commandContext(latest),
|
|
118
|
+
commandId: `${latest.event.eventId}:reobserve:${resourceIdValue}`,
|
|
119
|
+
},
|
|
120
|
+
pullRequests,
|
|
121
|
+
resourceId: resourceIdValue,
|
|
122
|
+
workItemId: primary.workItemId,
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
async latestPullRequestObservation(externalKey) {
|
|
126
|
+
let latest;
|
|
127
|
+
for (const envelope of await this.journal.readStream(integrationStream(this.adapter))) {
|
|
128
|
+
const owned = selectGitHubAdapterEvent(envelope);
|
|
129
|
+
if (owned !== null &&
|
|
130
|
+
isGitHubAdapterEventType(owned, GitHubEventType.WorkObserved) &&
|
|
131
|
+
owned.event.payload.kind === 'pull-request' &&
|
|
132
|
+
owned.event.payload.externalKey === externalKey)
|
|
133
|
+
latest = owned;
|
|
134
|
+
}
|
|
135
|
+
return latest;
|
|
136
|
+
}
|
|
91
137
|
async reconcileOnce() {
|
|
92
138
|
if (this.journal === undefined || this.work === undefined || this.resources === undefined) {
|
|
93
139
|
throw new Error('InboundTranslator services are required to run evidence translation');
|
|
@@ -208,6 +208,7 @@ export const gitHubProviderDefinition = {
|
|
|
208
208
|
},
|
|
209
209
|
inbound,
|
|
210
210
|
reconciler: inbound.reconciler,
|
|
211
|
+
reobserve: (externalKey) => inbound.reapplyObservation(externalKey.key),
|
|
211
212
|
checkConnectivity: async () => {
|
|
212
213
|
await client.authenticatedLogin();
|
|
213
214
|
},
|
|
@@ -49,7 +49,12 @@ export function createConversationCommandReactor(orchestration, feedback) {
|
|
|
49
49
|
}
|
|
50
50
|
if (entry.origin.canClarify === false)
|
|
51
51
|
return;
|
|
52
|
-
await
|
|
52
|
+
await orchestration.requestReplyAssessment(workItemId, event.eventId, {
|
|
53
|
+
commandId: `${event.eventId}:reply-assessment`,
|
|
54
|
+
correlationId: correlationId(event.correlationId),
|
|
55
|
+
occurredAt: event.occurredAt,
|
|
56
|
+
actor: { kind: EventActorKind.Integration, id: entry.origin.adapter },
|
|
57
|
+
});
|
|
53
58
|
for (const workflow of await orchestration.listAll()) {
|
|
54
59
|
if (workflow.workItemId !== workItemId)
|
|
55
60
|
continue;
|
|
@@ -67,30 +72,6 @@ export function createConversationCommandReactor(orchestration, feedback) {
|
|
|
67
72
|
}),
|
|
68
73
|
};
|
|
69
74
|
}
|
|
70
|
-
/**
|
|
71
|
-
* A parent that escalated a delegated child's question to a human has no stage to resume. The
|
|
72
|
-
* human's reply is recorded on each asking child's own conversation, where the ordinary reply path
|
|
73
|
-
* resumes it; the cohort stays tracked and nothing is settled or joined.
|
|
74
|
-
*/
|
|
75
|
-
async function routeEscalatedReply(orchestration, feedback, event, workItemId, adapter) {
|
|
76
|
-
if (feedback === undefined)
|
|
77
|
-
return;
|
|
78
|
-
const context = {
|
|
79
|
-
commandId: `${event.eventId}:escalated-reply`,
|
|
80
|
-
correlationId: correlationId(event.correlationId),
|
|
81
|
-
occurredAt: event.occurredAt,
|
|
82
|
-
actor: { kind: EventActorKind.Integration, id: adapter },
|
|
83
|
-
};
|
|
84
|
-
for (const childWorkItemId of await orchestration.escalatedReplyTargets(workItemId)) {
|
|
85
|
-
const conversation = await feedback.conversations.createForWorkItem(childWorkItemId, context);
|
|
86
|
-
await feedback.conversations.record({
|
|
87
|
-
conversationId: conversation.conversationId,
|
|
88
|
-
entryId: `${event.eventId}:routed:${childWorkItemId}`,
|
|
89
|
-
body: event.entry.body,
|
|
90
|
-
origin: event.entry.origin,
|
|
91
|
-
}, context);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
75
|
async function applyExternalCommand(orchestration, feedback, event, input, context) {
|
|
95
76
|
const entryId = context.commandId + ':feedback';
|
|
96
77
|
const canPublish = input.authorized || input.reviewAuthorized === true;
|
|
@@ -3,7 +3,7 @@ import type { DelegationAuthority } from '../contracts/delegation-ports.js';
|
|
|
3
3
|
import { type CommandContext } from '@atolis-hq/eventing';
|
|
4
4
|
import type { ActivityName } from '../../activities/index.js';
|
|
5
5
|
import { type WorkService } from '../../work/index.js';
|
|
6
|
-
import type { DelegationArtifacts, DelegationRepositories } from '../contracts/delegation-ports.js';
|
|
6
|
+
import type { DelegationArtifacts, DelegationMessages, DelegationRepositories, DelegationResources } from '../contracts/delegation-ports.js';
|
|
7
7
|
import type { DelegatedAssignment, DelegationCaller, DelegationLimits, DelegationReservation, DelegationResult } from '../contracts/delegation.js';
|
|
8
8
|
import { type WorkflowInstanceId } from '../contracts/identifiers.js';
|
|
9
9
|
import type { WorkflowInstanceView } from '../contracts/views.js';
|
|
@@ -37,8 +37,16 @@ export declare class DelegatedWork {
|
|
|
37
37
|
readonly authority?: DelegationAuthority | undefined;
|
|
38
38
|
readonly supportsAttention?: ((activity: ActivityName) => boolean) | undefined;
|
|
39
39
|
readonly resumeChild?: DelegationAttentionDependencies['resumeChild'] | undefined;
|
|
40
|
+
readonly messages?: DelegationMessages | undefined;
|
|
41
|
+
readonly resources?: DelegationResources | undefined;
|
|
40
42
|
});
|
|
41
|
-
|
|
43
|
+
/**
|
|
44
|
+
* `verify` re-checks upstream outputs with the provider. Reads default to recorded facts
|
|
45
|
+
* because that check costs provider round trips on every call.
|
|
46
|
+
*/
|
|
47
|
+
inspect(id: WorkItemId, options?: {
|
|
48
|
+
readonly verify?: boolean;
|
|
49
|
+
}): Promise<{
|
|
42
50
|
settled: boolean;
|
|
43
51
|
failureReason: string | undefined;
|
|
44
52
|
children: {
|
|
@@ -164,6 +172,8 @@ export declare class DelegatedWork {
|
|
|
164
172
|
/** Appends the reservation only if the root stream is unchanged since `events` was read. */
|
|
165
173
|
private commit;
|
|
166
174
|
private reconcileReservation;
|
|
175
|
+
/** A human reply on a parent: wake it to pass the answer to the children still waiting. */
|
|
176
|
+
assessReply(parent: WorkflowInstanceView, replyEntryId: string, context: CommandContext): Promise<void>;
|
|
167
177
|
/** Independent members keep advancing; a blocked member is skipped, never retried blindly. */
|
|
168
178
|
private advanceMembers;
|
|
169
179
|
private settleUnusable;
|
|
@@ -9,6 +9,7 @@ import { OrchestrationEventType } from '../contracts/events.js';
|
|
|
9
9
|
import { orchestrationGroupId, workflowInstanceId, } from '../contracts/identifiers.js';
|
|
10
10
|
import { DelegationConflictCode, DelegationPrerequisiteCondition, WorkflowStatus, } from '../contracts/vocabulary.js';
|
|
11
11
|
import { nextOrdinal } from '../domain/decision-events.js';
|
|
12
|
+
import { renderDelegatedBrief } from '../domain/delegated-brief.js';
|
|
12
13
|
import { assertCriteriaPreserving, originalOf } from '../domain/delivery-replacement.js';
|
|
13
14
|
import { isSuccessfulWorkflowCompletion } from '../domain/workflow-completion.js';
|
|
14
15
|
import { DelegationAttention, } from './delegation-attention.js';
|
|
@@ -18,6 +19,8 @@ import { assertWithinRootLimits, buildReservation, matchesAssignments, } from '.
|
|
|
18
19
|
import { resolvePrerequisites } from './delegation-wait-graph.js';
|
|
19
20
|
import { readDeliveryFacts } from './delivery-facts-reader.js';
|
|
20
21
|
const defaultLimits = { maxDepth: 1, maxDescendants: 8 };
|
|
22
|
+
/** How long completed-child outputs may stay invisible before the child is blocked. */
|
|
23
|
+
const OUTPUT_VISIBILITY_GRACE_MS = 120_000;
|
|
21
24
|
/**
|
|
22
25
|
* Durable delegation of independent child WorkItems. Reservation is the single commit point;
|
|
23
26
|
* every later boundary is reconciled idempotently from it, and the parent stays fenced until join.
|
|
@@ -50,12 +53,17 @@ export class DelegatedWork {
|
|
|
50
53
|
resumeChild: (id, context) => dependencies.resumeChild?.(id, context) ?? Promise.resolve(null),
|
|
51
54
|
contextWorkItems: (parent) => this.contextWorkItems(parent),
|
|
52
55
|
canContinue: (reservation) => this.canJoin(reservation),
|
|
56
|
+
messages: dependencies.messages,
|
|
53
57
|
});
|
|
54
58
|
this.prerequisites = new DelegationPrerequisites(repository, this.ledger, dependencies.artifacts, dependencies.repositories, work);
|
|
55
59
|
this.repositories = dependencies.repositories;
|
|
56
60
|
this.runHasEnded = dependencies.runHasEnded;
|
|
57
61
|
}
|
|
58
|
-
|
|
62
|
+
/**
|
|
63
|
+
* `verify` re-checks upstream outputs with the provider. Reads default to recorded facts
|
|
64
|
+
* because that check costs provider round trips on every call.
|
|
65
|
+
*/
|
|
66
|
+
async inspect(id, options = {}) {
|
|
59
67
|
const item = await this.work.get(id);
|
|
60
68
|
const root = item?.delegation?.rootWorkItemId ?? id;
|
|
61
69
|
const events = await this.ledger.events();
|
|
@@ -72,7 +80,9 @@ export class DelegatedWork {
|
|
|
72
80
|
children: await Promise.all(reservation.children.map(async (child) => ({
|
|
73
81
|
...child,
|
|
74
82
|
work: await this.work.get(child.workItemId),
|
|
75
|
-
prerequisiteBlocker: (
|
|
83
|
+
prerequisiteBlocker: (options.verify === true
|
|
84
|
+
? await read.reason(child.workItemId)
|
|
85
|
+
: read.recordedReason(child.workItemId)) ?? childBlocker(events, child.workItemId),
|
|
76
86
|
consumedInputs: read.inputs(child.workItemId),
|
|
77
87
|
workflow: read.workflow(child.workflowInstanceId) ?? null,
|
|
78
88
|
}))),
|
|
@@ -364,6 +374,13 @@ export class DelegatedWork {
|
|
|
364
374
|
if (await this.childrenQualified(reservation, results, context))
|
|
365
375
|
await this.join(reservation, results, context);
|
|
366
376
|
}
|
|
377
|
+
/** A human reply on a parent: wake it to pass the answer to the children still waiting. */
|
|
378
|
+
async assessReply(parent, replyEntryId, context) {
|
|
379
|
+
const reservation = (await this.ledger.reservations()).find((entry) => entry.parentWorkflowInstanceId === parent.workflowInstanceId &&
|
|
380
|
+
entry.cohortId === parent.delegationWait?.cohortId);
|
|
381
|
+
if (reservation !== undefined)
|
|
382
|
+
await this.attention.raiseForReply(reservation, replyEntryId, context);
|
|
383
|
+
}
|
|
367
384
|
/** Independent members keep advancing; a blocked member is skipped, never retried blindly. */
|
|
368
385
|
async advanceMembers(artifacts, root, reservation, context) {
|
|
369
386
|
const read = await this.prerequisites.read();
|
|
@@ -510,6 +527,13 @@ export class DelegatedWork {
|
|
|
510
527
|
ancestors: reservation.ancestors,
|
|
511
528
|
},
|
|
512
529
|
}, childContext);
|
|
530
|
+
await this.dependencies.resources?.relateChild({ childWorkItemId: child.workItemId, parentWorkItemId: reservation.parentWorkItemId }, childContext);
|
|
531
|
+
await this.dependencies.messages?.post({
|
|
532
|
+
workItemId: child.workItemId,
|
|
533
|
+
entryId: `delegation:${child.grantId}`,
|
|
534
|
+
authorId: `delegation:${reservation.parentWorkItemId}`,
|
|
535
|
+
body: renderDelegatedBrief(child),
|
|
536
|
+
}, childContext);
|
|
513
537
|
await this.claims.claimPrimary(child.workItemId, child.workflowInstanceId, childContext);
|
|
514
538
|
await artifacts.registerChild({
|
|
515
539
|
delegationId: child.grantId,
|
|
@@ -598,7 +622,10 @@ export class DelegatedWork {
|
|
|
598
622
|
});
|
|
599
623
|
return;
|
|
600
624
|
}
|
|
601
|
-
|
|
625
|
+
// Provider evidence (e.g. a PR observation) lags the child's completion, so a later
|
|
626
|
+
// pass alone does not prove the output is missing; only a bounded wait does.
|
|
627
|
+
const waitedMs = Date.parse(context.occurredAt) - Date.parse(observed.event.occurredAt);
|
|
628
|
+
if (observed.event.causationId !== context.commandId && waitedMs >= OUTPUT_VISIBILITY_GRACE_MS)
|
|
602
629
|
await this.failChild(reservation, child, `Child ${child.workItemId} completed without required outputs`, context);
|
|
603
630
|
}
|
|
604
631
|
endedRun(id) {
|
|
@@ -50,4 +50,6 @@ export declare function reject(code: DelegationAttentionRejection, message: stri
|
|
|
50
50
|
* blocker and its kind, and the assignment revision. Returns the earlier identical reply, if any.
|
|
51
51
|
*/
|
|
52
52
|
export declare function assertReplyAllowed(parent: WorkflowInstanceView, attention: OpenAttention | null, caller: DelegationCaller, reply: DelegationAttentionReply): DelegationAttentionResponse | undefined;
|
|
53
|
+
/** Only the parked cohort wait may start an assessment; a running one coalesces new reasons. */
|
|
54
|
+
export declare function canRequestAssessment(view: WorkflowInstanceView, reservation: DelegationReservation): boolean;
|
|
53
55
|
export {};
|
|
@@ -188,7 +188,17 @@ export function assertReplyAllowed(parent, attention, caller, reply) {
|
|
|
188
188
|
if (reply.expectedRevision !== attention.revision)
|
|
189
189
|
throw reject(DelegationAttentionRejection.StaleRevision, 'The assignment revision changed; inspect before replying');
|
|
190
190
|
const prior = attention.responses.find((entry) => entry.blockerId === reply.blockerId);
|
|
191
|
-
if (prior !== undefined &&
|
|
191
|
+
if (prior !== undefined &&
|
|
192
|
+
(JSON.stringify(prior.references) !== JSON.stringify(reply.references) ||
|
|
193
|
+
prior.message !== reply.message))
|
|
192
194
|
throw reject(DelegationAttentionRejection.Duplicate, 'This blocker already has a different accepted reply');
|
|
195
|
+
if (reply.references.length === 0 && reply.message === undefined)
|
|
196
|
+
throw reject(DelegationAttentionRejection.EmptyReply, 'A reply needs a message, accepted artifact references, or both');
|
|
193
197
|
return prior;
|
|
194
198
|
}
|
|
199
|
+
/** Only the parked cohort wait may start an assessment; a running one coalesces new reasons. */
|
|
200
|
+
export function canRequestAssessment(view, reservation) {
|
|
201
|
+
return (view.status === WorkflowStatus.Waiting &&
|
|
202
|
+
view.delegationWait?.cohortId === reservation.cohortId &&
|
|
203
|
+
view.delegationAttention === undefined);
|
|
204
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type CommandContext } from '@atolis-hq/eventing';
|
|
2
2
|
import { type ActivityName } from '../../activities/index.js';
|
|
3
|
-
import type { DelegationArtifacts } from '../contracts/delegation-ports.js';
|
|
3
|
+
import type { DelegationArtifacts, DelegationMessages } from '../contracts/delegation-ports.js';
|
|
4
4
|
import type { DelegationAttentionBlocker, DelegationAttentionReply, DelegationCaller, DelegationReservation } from '../contracts/delegation.js';
|
|
5
5
|
import { type WorkflowOrchestrationEvent } from '../contracts/events.js';
|
|
6
6
|
import type { WorkflowInstanceId } from '../contracts/identifiers.js';
|
|
@@ -16,6 +16,8 @@ export interface DelegationAttentionDependencies {
|
|
|
16
16
|
readonly resumeChild: (id: WorkflowInstanceId, context: CommandContext) => Promise<WorkflowInstanceView | null>;
|
|
17
17
|
/** Work items whose artifacts the parent may reference (its own hierarchy). */
|
|
18
18
|
readonly contextWorkItems: (parent: WorkflowInstanceView) => Promise<ReadonlySet<string>>;
|
|
19
|
+
/** Where a parent's free-text answer is posted: the child's own conversation. */
|
|
20
|
+
readonly messages?: DelegationMessages | undefined;
|
|
19
21
|
/** Run end and delivery availability gate every attention continuation, like the join. */
|
|
20
22
|
readonly canContinue: (reservation: DelegationReservation) => Promise<boolean>;
|
|
21
23
|
}
|
|
@@ -33,8 +35,12 @@ export declare class DelegationAttention {
|
|
|
33
35
|
* Callers settle fully terminal batches through the ordinary unsuccessful continuation instead.
|
|
34
36
|
*/
|
|
35
37
|
raise(reservation: DelegationReservation, context: CommandContext): Promise<void>;
|
|
36
|
-
/**
|
|
37
|
-
|
|
38
|
+
/**
|
|
39
|
+
* A human replied on the parent while children wait on a clarification. The reply is new
|
|
40
|
+
* information on blockers already assessed, so wake the parent once per reply to decide how
|
|
41
|
+
* to pass it on; replaying the same reply never wakes it twice.
|
|
42
|
+
*/
|
|
43
|
+
raiseForReply(reservation: DelegationReservation, replyEntryId: string, context: CommandContext): Promise<void>;
|
|
38
44
|
/** Returns false when a concurrent append won and the caller must re-read. */
|
|
39
45
|
private request;
|
|
40
46
|
/** The open attention request for a parent, with the replies already accepted. */
|
|
@@ -47,12 +53,4 @@ export declare class DelegationAttention {
|
|
|
47
53
|
/** Ends the assessment and restores the unresolved wait; a pending join then proceeds. */
|
|
48
54
|
resolve(parentId: WorkflowInstanceId, attentionActivation: string, context: CommandContext, verdict?: AttentionVerdict): Promise<WorkflowInstanceView>;
|
|
49
55
|
private priorFailures;
|
|
50
|
-
/**
|
|
51
|
-
* Children whose assignment-context blocker the parent escalated to a human and which are still
|
|
52
|
-
* blocked on it. A human reply on the parent is routed to exactly these, so a published question
|
|
53
|
-
* always has an answer path that moves the delivery without settling or joining the cohort.
|
|
54
|
-
*/
|
|
55
|
-
escalatedTargets(parent: WorkflowInstanceView): Promise<readonly {
|
|
56
|
-
readonly childWorkItemId: string;
|
|
57
|
-
}[]>;
|
|
58
56
|
}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { WrongExpectedSequenceError } from '@atolis-hq/eventing';
|
|
2
2
|
import { activationId } from '../../activities/index.js';
|
|
3
3
|
import { OrchestrationEventType } from '../contracts/events.js';
|
|
4
|
-
import { DelegationAttentionRejection,
|
|
4
|
+
import { DelegationAttentionRejection, DelegationBlockerKind } from '../contracts/vocabulary.js';
|
|
5
5
|
import { nextOrdinal } from '../domain/decision-events.js';
|
|
6
|
-
import {
|
|
7
|
-
import { assertReplyAllowed, assessedBlockers, attentionKeyOf, blockerOf, contextBlockerId, digest, MaxAssessmentAttempts, reject, resolutionDrafts, } from './delegation-attention-state.js';
|
|
6
|
+
import { assertReplyAllowed, assessedBlockers, attentionKeyOf, blockerOf, canRequestAssessment, contextBlockerId, digest, MaxAssessmentAttempts, reject, resolutionDrafts, } from './delegation-attention-state.js';
|
|
8
7
|
import { delegationDraft, isSettled } from './delegation-ledger.js';
|
|
9
8
|
/** Durable cohort/blocker state for the parent attention protocol. */
|
|
10
9
|
export class DelegationAttention {
|
|
@@ -49,17 +48,36 @@ export class DelegationAttention {
|
|
|
49
48
|
const attentionKey = attentionKeyOf(reservation, blockers.map((blocker) => blocker.blockerId));
|
|
50
49
|
for (;;) {
|
|
51
50
|
const loaded = await this.repository.loadRequired(reservation.parentWorkflowInstanceId);
|
|
52
|
-
if (!
|
|
51
|
+
if (!canRequestAssessment(loaded.view, reservation))
|
|
53
52
|
return;
|
|
54
53
|
if (await this.request(reservation, loaded, { attentionKey, blockers }, context))
|
|
55
54
|
return;
|
|
56
55
|
}
|
|
57
56
|
}
|
|
58
|
-
/**
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
57
|
+
/**
|
|
58
|
+
* A human replied on the parent while children wait on a clarification. The reply is new
|
|
59
|
+
* information on blockers already assessed, so wake the parent once per reply to decide how
|
|
60
|
+
* to pass it on; replaying the same reply never wakes it twice.
|
|
61
|
+
*/
|
|
62
|
+
async raiseForReply(reservation, replyEntryId, context) {
|
|
63
|
+
const events = await this.ledger.events();
|
|
64
|
+
if (isSettled(events, reservation))
|
|
65
|
+
return;
|
|
66
|
+
const blockers = (await this.blockers(reservation, events)).filter((blocker) => blocker.kind === DelegationBlockerKind.Context);
|
|
67
|
+
if (blockers.length === 0 || !(await this.dependencies.canContinue(reservation)))
|
|
68
|
+
return;
|
|
69
|
+
const attentionKey = `${attentionKeyOf(reservation, blockers.map((blocker) => blocker.blockerId))}:reply:${digest(replyEntryId)}`;
|
|
70
|
+
const asked = events.some(({ event }) => event.eventType === OrchestrationEventType.DelegationAttentionRequested &&
|
|
71
|
+
event.payload.attentionKey === attentionKey);
|
|
72
|
+
if (asked)
|
|
73
|
+
return;
|
|
74
|
+
for (;;) {
|
|
75
|
+
const loaded = await this.repository.loadRequired(reservation.parentWorkflowInstanceId);
|
|
76
|
+
if (!canRequestAssessment(loaded.view, reservation))
|
|
77
|
+
return;
|
|
78
|
+
if (await this.request(reservation, loaded, { attentionKey, blockers }, context))
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
63
81
|
}
|
|
64
82
|
/** Returns false when a concurrent append won and the caller must re-read. */
|
|
65
83
|
async request(reservation, loaded, input, context) {
|
|
@@ -158,12 +176,21 @@ export class DelegationAttention {
|
|
|
158
176
|
eventType: OrchestrationEventType.DelegationAttentionResponded,
|
|
159
177
|
payload: { cohortId: attention.cohortId, attentionKey: attention.attentionKey, ...reply },
|
|
160
178
|
});
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
179
|
+
if (reply.references.length > 0)
|
|
180
|
+
await this.dependencies.artifacts.registerChild({
|
|
181
|
+
delegationId: `${child.grantId}:response:${key}`,
|
|
182
|
+
parentWorkItemId: reservation.parentWorkItemId,
|
|
183
|
+
childWorkItemId: child.workItemId,
|
|
184
|
+
childReferences: reply.references,
|
|
185
|
+
}, context);
|
|
186
|
+
// Posted before the child resumes, so its next turn reads the answer.
|
|
187
|
+
if (reply.message !== undefined)
|
|
188
|
+
await this.dependencies.messages?.post({
|
|
189
|
+
workItemId: child.workItemId,
|
|
190
|
+
entryId: `delegation-reply:${key}`,
|
|
191
|
+
authorId: `delegation:${reservation.parentWorkItemId}`,
|
|
192
|
+
body: reply.message,
|
|
193
|
+
}, context);
|
|
167
194
|
if (stillBlocked)
|
|
168
195
|
await this.dependencies.resumeChild(child.workflowInstanceId, {
|
|
169
196
|
...context,
|
|
@@ -195,12 +222,4 @@ export class DelegationAttention {
|
|
|
195
222
|
event.payload.attentionKey === attentionKey &&
|
|
196
223
|
event.payload.assessmentFailure !== undefined).length;
|
|
197
224
|
}
|
|
198
|
-
/**
|
|
199
|
-
* Children whose assignment-context blocker the parent escalated to a human and which are still
|
|
200
|
-
* blocked on it. A human reply on the parent is routed to exactly these, so a published question
|
|
201
|
-
* always has an answer path that moves the delivery without settling or joining the cohort.
|
|
202
|
-
*/
|
|
203
|
-
escalatedTargets(parent) {
|
|
204
|
-
return escalatedTargets(this.repository, this.ledger, parent);
|
|
205
|
-
}
|
|
206
225
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { DelegationArtifacts, DelegationAuthority, DelegationRepositories } from '../contracts/delegation-ports.js';
|
|
1
|
+
import type { DelegationArtifacts, DelegationAuthority, DelegationMessages, DelegationRepositories, DelegationResources } from '../contracts/delegation-ports.js';
|
|
2
2
|
import type { DelegationAttentionReply, DelegationCaller, DelegationSubmission } from '../contracts/delegation.js';
|
|
3
3
|
import type { DeliveryIntegration } from '../contracts/delivery-ports.js';
|
|
4
4
|
import type { DeliveryCandidateCommand, DeliveryMaintenanceCommand, DeliveryQaCommand, DeliverySelectionCommand } from '../contracts/delivery.js';
|
|
@@ -547,7 +547,9 @@ export declare class OrchestrationService {
|
|
|
547
547
|
maxConcurrentRuns?: number | undefined;
|
|
548
548
|
}[];
|
|
549
549
|
}>;
|
|
550
|
-
deliveryTree(id: WorkItemId
|
|
550
|
+
deliveryTree(id: WorkItemId, options?: {
|
|
551
|
+
readonly verify?: boolean;
|
|
552
|
+
}): Promise<{
|
|
551
553
|
settled: boolean;
|
|
552
554
|
failureReason: string | undefined;
|
|
553
555
|
children: {
|
|
@@ -682,8 +684,11 @@ export declare class OrchestrationService {
|
|
|
682
684
|
* number of times. The cohort is never settled or cancelled by the assessment itself.
|
|
683
685
|
*/
|
|
684
686
|
private endAttention;
|
|
685
|
-
/**
|
|
686
|
-
|
|
687
|
+
/**
|
|
688
|
+
* A human replied on this work item while delegated children wait on a clarification: wake
|
|
689
|
+
* the delegating stage once, so the parent decides how to pass the reply to each child.
|
|
690
|
+
*/
|
|
691
|
+
requestReplyAssessment(workItemId: WorkItemId, replyEntryId: string, context: CommandContext): Promise<void>;
|
|
687
692
|
/** The open attention request when `activationId` is the attention activation, else null. */
|
|
688
693
|
openDelegationAttention(id: WorkflowInstanceId, activationId: ActivationId): Promise<import("./delegation-attention-state.js").OpenAttention | null>;
|
|
689
694
|
respondToDelegationAttention(caller: DelegationCaller, reply: DelegationAttentionReply, context: CommandContext): Promise<import("./delegation-attention-state.js").OpenAttention | null>;
|
|
@@ -761,6 +766,8 @@ type DelegationDependenciesFactory = (queries: {
|
|
|
761
766
|
artifacts: DelegationArtifacts;
|
|
762
767
|
authority?: DelegationAuthority;
|
|
763
768
|
repositories?: DelegationRepositories;
|
|
769
|
+
messages?: DelegationMessages;
|
|
770
|
+
resources?: DelegationResources;
|
|
764
771
|
integration?: DeliveryIntegration;
|
|
765
772
|
runHasEnded: (runId: string) => Promise<boolean>;
|
|
766
773
|
};
|
|
@@ -62,14 +62,7 @@ export class OrchestrationService {
|
|
|
62
62
|
this.claims = new CoordinationClaims(journal);
|
|
63
63
|
this.definitions = new WorkflowDefinitionRegistry(journal, projections, definitions);
|
|
64
64
|
this.startWorkflow = new StartWorkflow(repository, this.claims, work, this.definitions);
|
|
65
|
-
this.delegatedWork = new DelegatedWork(repository, work, this.claims, this.definitions, this.startWorkflow,
|
|
66
|
-
authority: dependencies?.authority,
|
|
67
|
-
artifacts: dependencies?.artifacts ?? unavailableArtifacts,
|
|
68
|
-
repositories: dependencies?.repositories,
|
|
69
|
-
runHasEnded: dependencies?.runHasEnded ?? unavailableRunCompletion,
|
|
70
|
-
supportsAttention: isAgentActivity,
|
|
71
|
-
resumeChild: this.resumeClarification,
|
|
72
|
-
});
|
|
65
|
+
this.delegatedWork = new DelegatedWork(repository, work, this.claims, this.definitions, this.startWorkflow, delegatedWorkDependencies(dependencies, isAgentActivity, this.resumeClarification));
|
|
73
66
|
this.delegationCommands = new DelegationCommands(repository, work, this.startWorkflow, this.definitions, this.delegatedWork, dependencies?.authority ?? unavailableDelegationAuthority);
|
|
74
67
|
this.delivery = new DeliveryCoordinator(repository, deliveryDependencies(dependencies, async (parent) => this.startWorkflow.definitionFor(parent), work));
|
|
75
68
|
this.advanceWorkflow = new AdvanceWorkflow(repository, this.startWorkflow, (command, context) => this.acceptOutcome(command, context), isAgentActivity);
|
|
@@ -155,8 +148,8 @@ export class OrchestrationService {
|
|
|
155
148
|
delivery: await this.delivery.inspectFor(caller),
|
|
156
149
|
};
|
|
157
150
|
}
|
|
158
|
-
deliveryTree(id) {
|
|
159
|
-
return this.delegatedWork.inspect(id);
|
|
151
|
+
deliveryTree(id, options) {
|
|
152
|
+
return this.delegatedWork.inspect(id, options);
|
|
160
153
|
}
|
|
161
154
|
deliveryRunLimit(id) {
|
|
162
155
|
return this.delegatedWork.runLimit(id);
|
|
@@ -204,14 +197,14 @@ export class OrchestrationService {
|
|
|
204
197
|
await this.delegatedWork.reconcile(context);
|
|
205
198
|
return (await this.repository.loadRequired(command.workflowInstanceId)).view;
|
|
206
199
|
}
|
|
207
|
-
/**
|
|
208
|
-
|
|
209
|
-
|
|
200
|
+
/**
|
|
201
|
+
* A human replied on this work item while delegated children wait on a clarification: wake
|
|
202
|
+
* the delegating stage once, so the parent decides how to pass the reply to each child.
|
|
203
|
+
*/
|
|
204
|
+
async requestReplyAssessment(workItemId, replyEntryId, context) {
|
|
210
205
|
for (const parent of await this.advanceWorkflow.listAll())
|
|
211
206
|
if (parent.workItemId === workItemId)
|
|
212
|
-
|
|
213
|
-
targets.push(target.childWorkItemId);
|
|
214
|
-
return targets;
|
|
207
|
+
await this.delegatedWork.assessReply(parent, replyEntryId, context);
|
|
215
208
|
}
|
|
216
209
|
/** The open attention request when `activationId` is the attention activation, else null. */
|
|
217
210
|
async openDelegationAttention(id, activationId) {
|
|
@@ -500,6 +493,19 @@ function isReviewConversationCommand(command) {
|
|
|
500
493
|
command === ConversationBuiltInCommand.Accepted ||
|
|
501
494
|
command === ConversationBuiltInCommand.Changes);
|
|
502
495
|
}
|
|
496
|
+
/** The delegation dependencies Orchestration hands to DelegatedWork, with safe unavailable stubs. */
|
|
497
|
+
function delegatedWorkDependencies(dependencies, supportsAttention, resumeChild) {
|
|
498
|
+
return {
|
|
499
|
+
authority: dependencies?.authority,
|
|
500
|
+
artifacts: dependencies?.artifacts ?? unavailableArtifacts,
|
|
501
|
+
repositories: dependencies?.repositories,
|
|
502
|
+
runHasEnded: dependencies?.runHasEnded ?? unavailableRunCompletion,
|
|
503
|
+
supportsAttention,
|
|
504
|
+
resumeChild,
|
|
505
|
+
messages: dependencies?.messages,
|
|
506
|
+
resources: dependencies?.resources,
|
|
507
|
+
};
|
|
508
|
+
}
|
|
503
509
|
async function unavailableRunCompletion() {
|
|
504
510
|
throw new Error('Delegation adapters unavailable');
|
|
505
511
|
}
|
|
@@ -56,6 +56,14 @@ export declare class PrerequisiteReadiness {
|
|
|
56
56
|
} | undefined;
|
|
57
57
|
} | undefined;
|
|
58
58
|
workflow(id: string): WorkflowInstanceView | undefined;
|
|
59
|
+
/**
|
|
60
|
+
* Why a child is held back, from recorded facts only. Read paths use this because the full
|
|
61
|
+
* evaluation asks the provider to re-verify upstream outputs; drift is detected by
|
|
62
|
+
* reconciliation, which records a block this method then reports.
|
|
63
|
+
*/
|
|
64
|
+
recordedReason(id: string, seen?: Set<string>): string | undefined;
|
|
65
|
+
private upstreamOf;
|
|
66
|
+
private recordedUpstreamReason;
|
|
59
67
|
reason(id: string): Promise<string | undefined>;
|
|
60
68
|
block(id: string, seen?: Set<string>): Promise<PrerequisiteBlock | undefined>;
|
|
61
69
|
private evaluate;
|
|
@@ -55,6 +55,41 @@ export class PrerequisiteReadiness {
|
|
|
55
55
|
workflow(id) {
|
|
56
56
|
return this.workflows.get(id);
|
|
57
57
|
}
|
|
58
|
+
/**
|
|
59
|
+
* Why a child is held back, from recorded facts only. Read paths use this because the full
|
|
60
|
+
* evaluation asks the provider to re-verify upstream outputs; drift is detected by
|
|
61
|
+
* reconciliation, which records a block this method then reports.
|
|
62
|
+
*/
|
|
63
|
+
recordedReason(id, seen = new Set()) {
|
|
64
|
+
const blocked = this.blockers.get(id);
|
|
65
|
+
if (blocked !== undefined)
|
|
66
|
+
return blocked.reason;
|
|
67
|
+
const child = this.children.get(id);
|
|
68
|
+
// Pinned inputs mean every prerequisite was met when the child was started.
|
|
69
|
+
if (child === undefined || this.receipts.has(id) || seen.has(id))
|
|
70
|
+
return undefined;
|
|
71
|
+
for (const edge of child.prerequisites ?? []) {
|
|
72
|
+
const upstream = this.upstreamOf(child, edge);
|
|
73
|
+
if (upstream === undefined)
|
|
74
|
+
continue;
|
|
75
|
+
return this.recordedUpstreamReason(upstream, edge, new Set([...seen, id]));
|
|
76
|
+
}
|
|
77
|
+
return undefined;
|
|
78
|
+
}
|
|
79
|
+
upstreamOf(child, edge) {
|
|
80
|
+
const owner = this.owners.get(child.workItemId);
|
|
81
|
+
return [...this.children.values()].find((entry) => this.owners.get(entry.workItemId) === owner && entry.assignmentId === edge.assignmentId);
|
|
82
|
+
}
|
|
83
|
+
recordedUpstreamReason(upstream, edge, seen) {
|
|
84
|
+
const inherited = this.recordedReason(upstream.workItemId, seen);
|
|
85
|
+
if (inherited !== undefined)
|
|
86
|
+
return inherited;
|
|
87
|
+
const workflow = this.workflows.get(upstream.workflowInstanceId);
|
|
88
|
+
if (workflow === undefined)
|
|
89
|
+
return `Waiting for upstream ${upstream.assignmentId}`;
|
|
90
|
+
return (workflowReason(workflow, edge) ??
|
|
91
|
+
`Waiting for ${edge.condition} output ${upstream.assignmentId}/${edge.output}`);
|
|
92
|
+
}
|
|
58
93
|
async reason(id) {
|
|
59
94
|
return (await this.block(id))?.reason;
|
|
60
95
|
}
|
|
@@ -14,6 +14,22 @@ export interface DelegationArtifacts {
|
|
|
14
14
|
}, context: CommandContext): Promise<void>;
|
|
15
15
|
qualifyingOutputs(child: WorkflowInstanceView, outputs: DelegatedAssignment['outputs']): Promise<DelegationResult['outputs'] | null>;
|
|
16
16
|
}
|
|
17
|
+
/** Posts Wake-authored messages, on a parent's behalf, to a delegated child's conversation. */
|
|
18
|
+
export interface DelegationMessages {
|
|
19
|
+
post(input: {
|
|
20
|
+
readonly workItemId: DelegationReservation['parentWorkItemId'];
|
|
21
|
+
readonly entryId: string;
|
|
22
|
+
readonly authorId: string;
|
|
23
|
+
readonly body: string;
|
|
24
|
+
}, context: CommandContext): Promise<void>;
|
|
25
|
+
}
|
|
26
|
+
/** Relates a delegated child to its parent's primary resource, e.g. so its runs publish there. */
|
|
27
|
+
export interface DelegationResources {
|
|
28
|
+
relateChild(input: {
|
|
29
|
+
readonly childWorkItemId: DelegationReservation['parentWorkItemId'];
|
|
30
|
+
readonly parentWorkItemId: DelegationReservation['parentWorkItemId'];
|
|
31
|
+
}, context: CommandContext): Promise<void>;
|
|
32
|
+
}
|
|
17
33
|
export interface DelegationAuthority {
|
|
18
34
|
assertQaCaller?(caller: DelegationCaller, candidateId: string, selectionRevision: number, revisions: readonly {
|
|
19
35
|
resourceId: string;
|