@myagentroam/agent 0.15.9 → 0.15.11
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/extensions/session-input.d.ts +2 -1
- package/dist/extensions/session-input.js +19 -8
- package/dist/runtime/execution.js +23 -9
- package/dist/runtime/model-generation-timing.d.ts +1 -1
- package/dist/runtime/model-generation-timing.js +2 -2
- package/dist/sdk/native-steer.d.ts +2 -3
- package/dist/sdk/native-steer.js +54 -21
- package/dist/sdk/session-execution-factory.js +4 -10
- package/dist/sdk/session-execution.d.ts +2 -0
- package/dist/sdk/session-execution.js +17 -4
- package/package.json +1 -1
|
@@ -114,7 +114,7 @@ export interface ExtensionSessionBackend {
|
|
|
114
114
|
export interface SessionInputEntry {
|
|
115
115
|
/** SDK-owned admission barrier, never accepted from Extension input. */
|
|
116
116
|
nativeSteer?: {
|
|
117
|
-
|
|
117
|
+
pending?: true;
|
|
118
118
|
recordId?: string;
|
|
119
119
|
restored?: true;
|
|
120
120
|
};
|
|
@@ -151,6 +151,7 @@ export declare class SessionInputCoordinator {
|
|
|
151
151
|
recordCompactCommit(outcome: ExtensionSessionActionResult): void;
|
|
152
152
|
performCompact(input: ExtensionCompactInput, call: ExtensionOperationContext, action: (commit: (outcome: ExtensionSessionActionResult) => void) => Promise<ExtensionSessionActionResult>): Promise<ExtensionSessionActionResult>;
|
|
153
153
|
accept(request: ExtensionSessionRequest, source: ExtensionOperationContext, action: ExtensionSessionAction, status: 'accepted' | 'queued'): SessionInputEntry;
|
|
154
|
+
cancelSteerReservation(entry: SessionInputEntry): void;
|
|
154
155
|
handled(input: ExtensionSubmitInput, call: ExtensionOperationContext, value?: unknown): ExtensionSessionReceipt;
|
|
155
156
|
drain(leaf: (entry: SessionInputEntry, request: ExtensionSessionRequest, call: ExtensionOperationContext) => Promise<ExtensionSessionActionResult>, execution?: {
|
|
156
157
|
readonly executionId: string;
|
|
@@ -57,7 +57,7 @@ export class SessionInputCoordinator {
|
|
|
57
57
|
!['cancelled', 'failed'].includes(previous.receipt.status))
|
|
58
58
|
return;
|
|
59
59
|
const entry = this.#record({ kind: 'submit', input: { text } }, source, (request, call, next) => next(request, call), 'accepted');
|
|
60
|
-
entry.nativeSteer = { recordId,
|
|
60
|
+
entry.nativeSteer = { recordId, restored: true };
|
|
61
61
|
if (index >= 0)
|
|
62
62
|
this.#pending[index] = entry;
|
|
63
63
|
else
|
|
@@ -65,7 +65,9 @@ export class SessionInputCoordinator {
|
|
|
65
65
|
}
|
|
66
66
|
get hasBoundaryPending() {
|
|
67
67
|
const head = this.#pending.find((entry) => entry.receipt.status !== 'cancelled' && !entry.source.signal.aborted);
|
|
68
|
-
return !!head &&
|
|
68
|
+
return (!!head &&
|
|
69
|
+
!head.nativeSteer?.pending &&
|
|
70
|
+
(head.request.kind !== 'submit' || head.request.input.delivery !== 'idle'));
|
|
69
71
|
}
|
|
70
72
|
get executing() {
|
|
71
73
|
return this.#current.getStore()?.receipt.status === 'in-progress';
|
|
@@ -74,6 +76,8 @@ export class SessionInputCoordinator {
|
|
|
74
76
|
for (const entry of this.#pending) {
|
|
75
77
|
if (entry.receipt.status === 'cancelled' || entry.source.signal.aborted)
|
|
76
78
|
continue;
|
|
79
|
+
if (entry.nativeSteer?.pending)
|
|
80
|
+
return false;
|
|
77
81
|
if (entry.request.kind === 'submit' && entry.request.input.delivery === 'idle')
|
|
78
82
|
return false;
|
|
79
83
|
if (entry.request.kind === 'compact')
|
|
@@ -145,6 +149,11 @@ export class SessionInputCoordinator {
|
|
|
145
149
|
this.#pending.push(entry);
|
|
146
150
|
return entry;
|
|
147
151
|
}
|
|
152
|
+
cancelSteerReservation(entry) {
|
|
153
|
+
// The admission owner calls this only when the writer cannot still commit.
|
|
154
|
+
if (entry.nativeSteer && !entry.nativeSteer.recordId && this.#active.has(entry))
|
|
155
|
+
this.#finish(entry, 'cancelled');
|
|
156
|
+
}
|
|
148
157
|
handled(input, call, value) {
|
|
149
158
|
const entry = this.#record({ kind: 'submit', input }, call, (request, effective, next) => next(request, effective), 'accepted');
|
|
150
159
|
this.#finish(entry, 'handled', { changed: false });
|
|
@@ -236,6 +245,11 @@ export class SessionInputCoordinator {
|
|
|
236
245
|
!head.source.signal.aborted &&
|
|
237
246
|
head.receipt.status !== 'cancelled')
|
|
238
247
|
break;
|
|
248
|
+
// Reservations preserve FIFO order but never block a model boundary on a Hook or writer.
|
|
249
|
+
if (head.nativeSteer?.pending &&
|
|
250
|
+
!head.source.signal.aborted &&
|
|
251
|
+
head.receipt.status !== 'cancelled')
|
|
252
|
+
break;
|
|
239
253
|
const entry = this.#pending.shift();
|
|
240
254
|
if (entry.receipt.status === 'cancelled' || entry.source.signal.aborted) {
|
|
241
255
|
this.#finish(entry, 'cancelled');
|
|
@@ -278,13 +292,10 @@ export class SessionInputCoordinator {
|
|
|
278
292
|
let effects = 0;
|
|
279
293
|
let committed;
|
|
280
294
|
try {
|
|
281
|
-
if (entry.nativeSteer) {
|
|
282
|
-
await entry.nativeSteer.ready;
|
|
295
|
+
if (entry.nativeSteer && !entry.nativeSteer.recordId) {
|
|
283
296
|
call.signal.throwIfAborted();
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
return false;
|
|
287
|
-
}
|
|
297
|
+
this.#finish(entry, 'handled', { changed: false });
|
|
298
|
+
return false;
|
|
288
299
|
}
|
|
289
300
|
const outcome = await this.#current.run(entry, () => entry.action(entry.request, call, async (request, effective) => {
|
|
290
301
|
validateCoreSessionRequest(request);
|
|
@@ -25,6 +25,7 @@ export class ExecutionLoop {
|
|
|
25
25
|
const { mode, messages } = input;
|
|
26
26
|
let recoveringFromContextOverflow = false;
|
|
27
27
|
const modelRetryState = { attempts: 0 };
|
|
28
|
+
let retryTpsStartedAt;
|
|
28
29
|
while (true) {
|
|
29
30
|
let stop;
|
|
30
31
|
let sawTool = false;
|
|
@@ -38,7 +39,6 @@ export class ExecutionLoop {
|
|
|
38
39
|
const startedMessages = new Set();
|
|
39
40
|
const leadingMessageWhitespace = new Map();
|
|
40
41
|
let sawModelSemanticEvent = false;
|
|
41
|
-
let requestStartedAt;
|
|
42
42
|
let firstModelResponseAt;
|
|
43
43
|
let generation = new ModelGenerationTiming();
|
|
44
44
|
let requestCompletedAt;
|
|
@@ -55,19 +55,24 @@ export class ExecutionLoop {
|
|
|
55
55
|
const emitFinalPerformance = async (completedAt) => {
|
|
56
56
|
if (mode === 'compact')
|
|
57
57
|
return;
|
|
58
|
-
|
|
59
|
-
const outputDuration = generation.durationMs;
|
|
58
|
+
const requestDurationMs = completedAt - tpsStartedAt;
|
|
60
59
|
const outputTokens = requestOutputTokens;
|
|
61
|
-
if (outputTokens === undefined ||
|
|
60
|
+
if (outputTokens === undefined ||
|
|
61
|
+
!Number.isFinite(requestDurationMs) ||
|
|
62
|
+
requestDurationMs <= 0)
|
|
62
63
|
return;
|
|
64
|
+
generation.finish(completedAt);
|
|
65
|
+
const outputDurationMs = Math.round(generation.durationMs ?? 0);
|
|
66
|
+
// Final output tokens can include reasoning that the provider did not stream.
|
|
67
|
+
const rateDurationMs = Math.max(requestDurationMs, 1_000);
|
|
63
68
|
await input.publish({
|
|
64
69
|
type: 'model.performance',
|
|
65
70
|
...(firstModelResponseAt === undefined
|
|
66
71
|
? {}
|
|
67
72
|
: { latencyMs: Math.max(0, Math.round(firstModelResponseAt - requestStartedAt)) }),
|
|
68
73
|
outputTokens,
|
|
69
|
-
outputDurationMs:
|
|
70
|
-
tokensPerSecond: Number(((outputTokens *
|
|
74
|
+
...(outputDurationMs === 0 ? {} : { outputDurationMs }),
|
|
75
|
+
tokensPerSecond: Number(((outputTokens * 1_000) / rateDurationMs).toFixed(2))
|
|
71
76
|
});
|
|
72
77
|
};
|
|
73
78
|
const persistToolCalls = async (calls) => {
|
|
@@ -84,8 +89,10 @@ export class ExecutionLoop {
|
|
|
84
89
|
await input.appendContext(message);
|
|
85
90
|
}
|
|
86
91
|
};
|
|
92
|
+
const requestStartedAt = performance.now();
|
|
93
|
+
const tpsStartedAt = retryTpsStartedAt ?? requestStartedAt;
|
|
94
|
+
retryTpsStartedAt = undefined;
|
|
87
95
|
try {
|
|
88
|
-
requestStartedAt = performance.now();
|
|
89
96
|
for await (const event of input.startModel({
|
|
90
97
|
...round.request,
|
|
91
98
|
retryState: modelRetryState
|
|
@@ -207,6 +214,9 @@ export class ExecutionLoop {
|
|
|
207
214
|
messages.push({ role: 'assistant', content: event.text });
|
|
208
215
|
}
|
|
209
216
|
else if (event.type === 'usage') {
|
|
217
|
+
// Adapters merge intermediate usage within the request before publishing final usage.
|
|
218
|
+
if (event.final === false)
|
|
219
|
+
continue;
|
|
210
220
|
latestUsage = event.usage;
|
|
211
221
|
if (event.final === true)
|
|
212
222
|
generation.finish(observedAt);
|
|
@@ -215,7 +225,7 @@ export class ExecutionLoop {
|
|
|
215
225
|
event.usage.outputTokens >= 0
|
|
216
226
|
? event.usage.outputTokens
|
|
217
227
|
: undefined;
|
|
218
|
-
if (
|
|
228
|
+
if (outputTokens !== undefined || event.final === true)
|
|
219
229
|
requestOutputTokens = outputTokens;
|
|
220
230
|
const reportedContext = event.usage.contextInputTokens ?? event.usage.inputTokens;
|
|
221
231
|
if (reportedContext !== undefined &&
|
|
@@ -293,8 +303,11 @@ export class ExecutionLoop {
|
|
|
293
303
|
pendingTools.splice(0, pendingTools.length);
|
|
294
304
|
else if (pendingTools.length > 0)
|
|
295
305
|
await persistToolCalls(pendingTools);
|
|
296
|
-
if (pendingTools.length === 0)
|
|
306
|
+
if (pendingTools.length === 0) {
|
|
307
|
+
// Runtime recovery continues the same logical request unless it runs a tool.
|
|
308
|
+
retryTpsStartedAt = tpsStartedAt;
|
|
297
309
|
continue;
|
|
310
|
+
}
|
|
298
311
|
}
|
|
299
312
|
else if (mode === 'compact' &&
|
|
300
313
|
!sawModelSemanticEvent &&
|
|
@@ -410,6 +423,7 @@ export class ExecutionLoop {
|
|
|
410
423
|
this.planOutputPrefixes.clear();
|
|
411
424
|
if (await recoverModelStream(error, modelRetryState, input.recoverySignal())) {
|
|
412
425
|
this.finalAnswer = '';
|
|
426
|
+
retryTpsStartedAt = tpsStartedAt;
|
|
413
427
|
continue;
|
|
414
428
|
}
|
|
415
429
|
throw error;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/** Diagnostic generation intervals within one model attempt, excluding explicit execution pauses. */
|
|
2
2
|
export declare class ModelGenerationTiming {
|
|
3
3
|
private startedAt;
|
|
4
4
|
private latestAt;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/** Diagnostic generation intervals within one model attempt, excluding explicit execution pauses. */
|
|
2
2
|
export class ModelGenerationTiming {
|
|
3
3
|
startedAt;
|
|
4
4
|
latestAt;
|
|
@@ -34,6 +34,6 @@ export class ModelGenerationTiming {
|
|
|
34
34
|
this.completed = true;
|
|
35
35
|
}
|
|
36
36
|
get durationMs() {
|
|
37
|
-
return this.completed && this.valid && this.duration
|
|
37
|
+
return this.completed && this.valid && this.duration > 0 ? this.duration : undefined;
|
|
38
38
|
}
|
|
39
39
|
}
|
|
@@ -7,9 +7,8 @@ import type { SteerInput, SteerResult } from './types.js';
|
|
|
7
7
|
export declare function createNativeSteer(input: {
|
|
8
8
|
readonly executionId: string;
|
|
9
9
|
readonly inputs: SessionInputCoordinator;
|
|
10
|
-
readonly
|
|
11
|
-
|
|
12
|
-
operation<T>(action: (call: ExtensionOperationContext) => T): T;
|
|
10
|
+
readonly admissionSignal: AbortSignal;
|
|
11
|
+
operation<T>(action: (call: ExtensionOperationContext) => T, signal?: AbortSignal): T;
|
|
13
12
|
admit(content: ExtensionPromptInput, call: ExtensionOperationContext, write: (content: ExtensionPromptInput, call: ExtensionOperationContext) => Promise<ExtensionPromptResult>): Promise<unknown>;
|
|
14
13
|
receive(content: ExtensionPromptInput, clientMessageId: string, call: ExtensionOperationContext, source?: import('../extensions/session-input.js').ExtensionInputSource): Promise<SessionRecord>;
|
|
15
14
|
notify(entry: Extract<SteerResult, {
|
package/dist/sdk/native-steer.js
CHANGED
|
@@ -11,7 +11,7 @@ export function createNativeSteer(input) {
|
|
|
11
11
|
const previous = retries.get(request.clientMessageId);
|
|
12
12
|
if (previous)
|
|
13
13
|
return previous;
|
|
14
|
-
if (
|
|
14
|
+
if (input.admissionSignal.aborted || input.inputs.hasIdleBarrier)
|
|
15
15
|
return Promise.resolve({ status: 'notAccepted' });
|
|
16
16
|
if (typeof request.clientMessageId !== 'string' ||
|
|
17
17
|
!request.clientMessageId.trim() ||
|
|
@@ -23,25 +23,54 @@ export function createNativeSteer(input) {
|
|
|
23
23
|
...(request.images === undefined ? {} : { images: request.images })
|
|
24
24
|
});
|
|
25
25
|
const result = Promise.withResolvers();
|
|
26
|
-
const ready = Promise.withResolvers();
|
|
27
26
|
const entry = input.operation((call) => input.inputs.accept({ kind: 'submit', input: content }, call, (request, effective, next) => next(request, effective), 'accepted'));
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
27
|
+
const reservation = { pending: true };
|
|
28
|
+
entry.nativeSteer = reservation;
|
|
29
|
+
const releaseAdmission = () => {
|
|
30
|
+
delete reservation.pending;
|
|
31
|
+
};
|
|
32
|
+
const admissionController = new AbortController();
|
|
33
|
+
let writing = false;
|
|
31
34
|
let committed = false;
|
|
32
|
-
const
|
|
33
|
-
.
|
|
34
|
-
|
|
35
|
+
const releaseReservation = () => {
|
|
36
|
+
input.inputs.cancelSteerReservation(entry);
|
|
37
|
+
releaseAdmission();
|
|
38
|
+
};
|
|
39
|
+
const aborted = () => {
|
|
40
|
+
admissionController.abort(input.admissionSignal.reason);
|
|
41
|
+
// A writer that has started owns the outcome until it reports whether it committed.
|
|
42
|
+
if (!writing) {
|
|
43
|
+
releaseReservation();
|
|
44
|
+
result.resolve({ status: 'notAccepted' });
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
input.admissionSignal.addEventListener('abort', aborted, { once: true });
|
|
48
|
+
const write = async (actual, effective) => {
|
|
35
49
|
if (committed)
|
|
36
50
|
return {};
|
|
37
51
|
effective.signal.throwIfAborted();
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
52
|
+
writing = true;
|
|
53
|
+
let record;
|
|
54
|
+
try {
|
|
55
|
+
record = await input.receive(actual, request.clientMessageId, effective, source);
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
if (admissionController.signal.aborted) {
|
|
59
|
+
releaseReservation();
|
|
60
|
+
// I/O errors can leave a durable record. Only the writer's cancellation proves non-admission.
|
|
61
|
+
if (error === admissionController.signal.reason)
|
|
62
|
+
result.resolve({ status: 'notAccepted' });
|
|
63
|
+
else
|
|
64
|
+
result.reject(error);
|
|
65
|
+
}
|
|
66
|
+
throw error;
|
|
67
|
+
}
|
|
68
|
+
finally {
|
|
69
|
+
writing = false;
|
|
41
70
|
}
|
|
42
|
-
const record = await input.receive(actual, request.clientMessageId, effective, source);
|
|
43
71
|
committed = true;
|
|
44
|
-
|
|
72
|
+
input.admissionSignal.removeEventListener('abort', aborted);
|
|
73
|
+
reservation.recordId = record.recordId;
|
|
45
74
|
const payload = record.payload;
|
|
46
75
|
const images = imageMetadata(payload.images);
|
|
47
76
|
const historyEntry = {
|
|
@@ -58,24 +87,28 @@ export function createNativeSteer(input) {
|
|
|
58
87
|
};
|
|
59
88
|
// Neither Hook post-processing nor a failed observer can revoke the writer's receipt.
|
|
60
89
|
void input.notify(historyEntry).catch(() => input.diagnose());
|
|
61
|
-
|
|
90
|
+
releaseAdmission();
|
|
62
91
|
result.resolve({ status: 'accepted', entry: historyEntry });
|
|
63
92
|
input.wake();
|
|
64
93
|
return {};
|
|
65
|
-
}
|
|
94
|
+
};
|
|
95
|
+
const admission = admissionTail
|
|
96
|
+
.catch(() => undefined)
|
|
97
|
+
.then(() => input.operation((call) => input.admit(content, call, write), admissionController.signal));
|
|
66
98
|
void admission
|
|
67
99
|
.then(() => {
|
|
68
|
-
|
|
100
|
+
releaseAdmission();
|
|
101
|
+
if (!committed && !admissionController.signal.aborted)
|
|
69
102
|
result.resolve({ status: 'handled' });
|
|
70
103
|
}, (error) => {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
else
|
|
104
|
+
releaseAdmission();
|
|
105
|
+
if (committed)
|
|
74
106
|
input.diagnose();
|
|
107
|
+
else if (!admissionController.signal.aborted)
|
|
108
|
+
result.reject(error);
|
|
75
109
|
})
|
|
76
110
|
.finally(() => {
|
|
77
|
-
|
|
78
|
-
input.signal.removeEventListener('abort', aborted);
|
|
111
|
+
input.admissionSignal.removeEventListener('abort', aborted);
|
|
79
112
|
});
|
|
80
113
|
admissionTail = result.promise;
|
|
81
114
|
retries.set(request.clientMessageId, result.promise);
|
|
@@ -83,7 +83,6 @@ export function createSessionExecutionFactory(ports) {
|
|
|
83
83
|
const manualCompactionId = mode === 'compact' ? randomUUID() : undefined;
|
|
84
84
|
sessionRuntime.registerExecution(executionOwner);
|
|
85
85
|
const inputs = sessionInputs();
|
|
86
|
-
let acceptsSteer = false;
|
|
87
86
|
let exhaustedModelAttempt;
|
|
88
87
|
const eventPorts = {
|
|
89
88
|
hasRetainedLease: () => store.hasRetainedSessionLease(sessionId, sessionWriterOwner),
|
|
@@ -300,14 +299,14 @@ export function createSessionExecutionFactory(ports) {
|
|
|
300
299
|
const selectedModelForTools = executionModels.get(input.modelId ?? executionDefaultModelId);
|
|
301
300
|
const coreExtensions = await extensionManager.prepare(sessionId, controller.signal, sourceBindings, sessionSource.type === 'user' && !internal.automaticInput);
|
|
302
301
|
executionOwner.bindViews({ toolSources: sources });
|
|
303
|
-
const operation = (run) => extensionManager.operations.run({
|
|
302
|
+
const operation = (run, signal) => extensionManager.operations.run({
|
|
304
303
|
sessionId,
|
|
305
304
|
sessionEpoch: coreExtensions.epoch,
|
|
306
305
|
executionId,
|
|
307
306
|
turnId,
|
|
308
307
|
actor: 'sdk',
|
|
309
308
|
entry: 'native-api',
|
|
310
|
-
signal: controller.signal
|
|
309
|
+
signal: signal ? AbortSignal.any([controller.signal, signal]) : controller.signal
|
|
311
310
|
}, run);
|
|
312
311
|
if (mode !== 'compact') {
|
|
313
312
|
// Missing entries prepend in reverse order; warm entries retain their FIFO position.
|
|
@@ -509,12 +508,10 @@ export function createSessionExecutionFactory(ports) {
|
|
|
509
508
|
});
|
|
510
509
|
if (!entered)
|
|
511
510
|
return { inputHandled: true };
|
|
512
|
-
acceptsSteer = true;
|
|
513
511
|
executionOwner.acceptSteer(createNativeSteer({
|
|
514
512
|
executionId,
|
|
515
513
|
inputs,
|
|
516
|
-
|
|
517
|
-
isOpen: () => acceptsSteer,
|
|
514
|
+
admissionSignal: executionOwner.steerAdmissionSignal,
|
|
518
515
|
operation,
|
|
519
516
|
admit: (content, call, write) => invokeCorePromptSubmission(coreExtensions.hooks, content, call, write),
|
|
520
517
|
receive: receiveSteer,
|
|
@@ -841,9 +838,7 @@ export function createSessionExecutionFactory(ports) {
|
|
|
841
838
|
mailbox: {
|
|
842
839
|
hasPending: () => inputs.hasBoundaryPending && !inputs.executing,
|
|
843
840
|
append: appendMailboxMessages,
|
|
844
|
-
close: () =>
|
|
845
|
-
acceptsSteer = false;
|
|
846
|
-
}
|
|
841
|
+
close: () => executionOwner.closeSteerAdmission()
|
|
847
842
|
}
|
|
848
843
|
});
|
|
849
844
|
compactRequests.seal();
|
|
@@ -868,7 +863,6 @@ export function createSessionExecutionFactory(ports) {
|
|
|
868
863
|
};
|
|
869
864
|
},
|
|
870
865
|
beforeFailure: async (error) => {
|
|
871
|
-
acceptsSteer = false;
|
|
872
866
|
executionOwner.stopSteer();
|
|
873
867
|
await sessionRuntime.joinRecordProjection();
|
|
874
868
|
await compactCoordinator.close(error).catch(() => undefined);
|
|
@@ -86,9 +86,11 @@ export declare class SessionExecution {
|
|
|
86
86
|
}) | (import("./types.js").AgentEventBase & {
|
|
87
87
|
type: "execution.cancelled";
|
|
88
88
|
}) | undefined;
|
|
89
|
+
get steerAdmissionSignal(): AbortSignal;
|
|
89
90
|
private readonly steer;
|
|
90
91
|
bindViews(views: Partial<Pick<SessionExecutionContext, 'requestMessages' | 'appendedMessages' | 'toolSources'>>): void;
|
|
91
92
|
acceptSteer(steer: NonNullable<SessionExecutionContext['steer']>): void;
|
|
93
|
+
closeSteerAdmission(): void;
|
|
92
94
|
stopSteer(): void;
|
|
93
95
|
retireCompactRequests(reason: unknown): void;
|
|
94
96
|
revokeViews(reason: unknown): void;
|
|
@@ -24,6 +24,10 @@ export class SessionExecution {
|
|
|
24
24
|
#bindings;
|
|
25
25
|
// The handle exists before its first input is committed. This only gates entry to the mailbox.
|
|
26
26
|
#steerReady = Promise.withResolvers();
|
|
27
|
+
#steerAdmission = new AbortController();
|
|
28
|
+
get steerAdmissionSignal() {
|
|
29
|
+
return this.#steerAdmission.signal;
|
|
30
|
+
}
|
|
27
31
|
steer = async (input, source) => {
|
|
28
32
|
if (input.expectedExecutionId !== this.executionId)
|
|
29
33
|
return { status: 'notAccepted' };
|
|
@@ -35,12 +39,21 @@ export class SessionExecution {
|
|
|
35
39
|
Object.assign(this.#bindings, views);
|
|
36
40
|
}
|
|
37
41
|
acceptSteer(steer) {
|
|
42
|
+
if (this.steerAdmissionSignal.aborted)
|
|
43
|
+
return;
|
|
38
44
|
this.#bindings = { ...this.#bindings, steer };
|
|
39
45
|
this.#steerReady.resolve();
|
|
40
46
|
}
|
|
47
|
+
closeSteerAdmission() {
|
|
48
|
+
if (this.steerAdmissionSignal.aborted)
|
|
49
|
+
return;
|
|
50
|
+
// Keep the binding for retries of already accepted IDs until the Execution tears down.
|
|
51
|
+
this.#steerReady.resolve();
|
|
52
|
+
this.#steerAdmission.abort(new AgentError('MAR_AGENT_CANCELLED', 'Steer admission closed.'));
|
|
53
|
+
}
|
|
41
54
|
stopSteer() {
|
|
42
55
|
delete this.#bindings.steer;
|
|
43
|
-
this
|
|
56
|
+
this.closeSteerAdmission();
|
|
44
57
|
}
|
|
45
58
|
retireCompactRequests(reason) {
|
|
46
59
|
this.compactRequests.close(reason);
|
|
@@ -225,8 +238,8 @@ export class SessionExecution {
|
|
|
225
238
|
if (full.type === 'execution.completed') {
|
|
226
239
|
this.controller.signal.throwIfAborted();
|
|
227
240
|
this.completionAdmitted = true;
|
|
228
|
-
// Handled input never binds steer;
|
|
229
|
-
this
|
|
241
|
+
// Handled first input never binds steer; release startup waiters before Host publication.
|
|
242
|
+
this.closeSteerAdmission();
|
|
230
243
|
}
|
|
231
244
|
if (full.type === 'execution.completed' ||
|
|
232
245
|
full.type === 'execution.failed' ||
|
|
@@ -440,7 +453,7 @@ export class SessionExecution {
|
|
|
440
453
|
cancel(reason) {
|
|
441
454
|
if (this.completionAdmitted)
|
|
442
455
|
return;
|
|
456
|
+
this.closeSteerAdmission();
|
|
443
457
|
this.controller.abort(reason);
|
|
444
|
-
this.#steerReady.resolve();
|
|
445
458
|
}
|
|
446
459
|
}
|