maka-agent 0.2.0-dev.53.20260927 → 0.2.0-dev.62.20260928
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/LICENSE +6 -5
- package/dist/workspace-root.js +2 -2
- package/native/runtime-host-windows-task-launcher/prebuilds/win32-x64/maka-runtime-host-task-launcher.exe +0 -0
- package/node_modules/@maka/acp-executor-plugin/dist/index.js +333 -28
- package/node_modules/@maka/acp-executor-plugin/dist/plugin.mjs +283 -27
- package/node_modules/@maka/core/dist/executor-catalog.js +10 -1
- package/node_modules/@maka/core/dist/message-queue-order.js +47 -0
- package/node_modules/@maka/core/dist/model-metadata.js +2 -1
- package/node_modules/@maka/core/dist/redaction.js +42 -3
- package/node_modules/@maka/core/dist/relative-time-policy.js +71 -0
- package/node_modules/@maka/core/dist/relative-time.js +3 -54
- package/node_modules/@maka/core/package.json +1 -0
- package/node_modules/@maka/eval/dist/egress-audit.js +127 -0
- package/node_modules/@maka/eval/dist/harness-executor.js +16 -96
- package/node_modules/@maka/eval/harbor/egress-proxy/entrypoint.sh +4 -4
- package/node_modules/@maka/eval/harbor/egress_filter.py +153 -104
- package/node_modules/@maka/eval/harbor/eval_framework.py +37 -14
- package/node_modules/@maka/eval/harbor/relay_agent.py +4 -6
- package/node_modules/@maka/eval/harbor/run_trial.py +11 -4
- package/node_modules/@maka/runtime/dist/agent-graph-supervisor-wake.js +33 -6
- package/node_modules/@maka/runtime/dist/ai-sdk-turn.js +1 -1
- package/node_modules/@maka/runtime/dist/plugin-executor-backend.js +26 -5
- package/node_modules/@maka/runtime/dist/plugin-executor-service.js +36 -0
- package/node_modules/@maka/runtime/dist/provider-error-classification.js +8 -73
- package/node_modules/@maka/runtime/dist/provider-error-signals.js +31 -0
- package/node_modules/@maka/runtime/dist/provider-retry-policy.js +79 -0
- package/node_modules/@maka/runtime/dist/session-manager.js +6 -4
- package/node_modules/@maka/runtime/dist/session-projection-helpers.js +2 -0
- package/node_modules/@maka/runtime/dist/shell-run-manager.js +8 -8
- package/node_modules/@maka/runtime/dist/terminal-run-commit.js +7 -1
- package/node_modules/@maka/runtime/dist/tool-runtime.js +5 -4
- package/node_modules/@maka/runtime-host/dist/adapter/provider-retry-projector.js +63 -0
- package/node_modules/@maka/runtime-host/dist/adapter/session-projector.js +7 -51
- package/node_modules/@maka/runtime-host/dist/protocol/index.js +9 -3
- package/node_modules/@maka/runtime-host/dist/protocol/message-queue-limits.js +21 -0
- package/node_modules/@maka/runtime-host/dist/protocol/message.js +6 -104
- package/node_modules/@maka/runtime-host/dist/protocol/queue-mutation.js +136 -0
- package/node_modules/@maka/runtime-host/dist/protocol/turn-provider-retry.js +69 -0
- package/node_modules/@maka/runtime-host/dist/protocol/turn.js +2 -43
- package/node_modules/@maka/runtime-host/dist/server/goal-coordinator.js +42 -5
- package/node_modules/@maka/runtime-host/dist/server/message-coordinator.js +105 -233
- package/node_modules/@maka/runtime-host/dist/server/message-queue-state.js +69 -0
- package/node_modules/@maka/runtime-host/dist/server/provider-retry-projection.js +71 -0
- package/node_modules/@maka/runtime-host/dist/server/queued-mutation-executor.js +94 -0
- package/node_modules/@maka/runtime-host/dist/server/root-turn-coordinator.js +1 -1
- package/node_modules/@maka/runtime-host/dist/server/session-continuity-coordinator.js +9 -58
- package/node_modules/@maka/storage/dist/agent-run-store-contract.js +0 -3
- package/node_modules/@maka/storage/dist/agent-run-store.js +15 -6
- package/node_modules/@maka/storage/dist/execution-persistence-provider.js +1 -0
- package/node_modules/@maka/storage/dist/execution-stores.js +1 -0
- package/node_modules/@maka/storage/dist/project-catalog.js +41 -42
- package/node_modules/@maka/storage/dist/sqlite-runtime-store.js +102 -31
- package/node_modules/@maka/storage/dist/sqlite-session-metadata-schema.js +52 -1
- package/node_modules/@maka/storage/dist/sqlite-session-metadata-store.js +34 -2
- package/package.json +1 -1
|
@@ -69,6 +69,12 @@ export class PluginExecutorService extends Service {
|
|
|
69
69
|
...(provider.inspectConversation
|
|
70
70
|
? { inspectConversation: provider.inspectConversation.bind(provider) }
|
|
71
71
|
: {}),
|
|
72
|
+
...(provider.acknowledgeExecution
|
|
73
|
+
? { acknowledgeExecution: provider.acknowledgeExecution.bind(provider) }
|
|
74
|
+
: {}),
|
|
75
|
+
...(provider.abandonExecution
|
|
76
|
+
? { abandonExecution: provider.abandonExecution.bind(provider) }
|
|
77
|
+
: {}),
|
|
72
78
|
});
|
|
73
79
|
const entry = {
|
|
74
80
|
...identity,
|
|
@@ -198,6 +204,29 @@ export class PluginExecutorService extends Service {
|
|
|
198
204
|
}
|
|
199
205
|
return this.executeEntry(entry, request, options);
|
|
200
206
|
},
|
|
207
|
+
...(entry.provider.acknowledgeExecution
|
|
208
|
+
? {
|
|
209
|
+
acknowledgeExecution: (conversationKey, turnId) => conversationKey !== sessionId
|
|
210
|
+
? Promise.reject(new Error('Executor binding cannot cross Session scope'))
|
|
211
|
+
: this.withActiveOperation(entry, { conversationKey }, async (signal) => {
|
|
212
|
+
signal.throwIfAborted();
|
|
213
|
+
if (entry.retired)
|
|
214
|
+
throw new ExecutorRetiredAbort(entry.provider.id);
|
|
215
|
+
await entry.provider.acknowledgeExecution(conversationKey, turnId);
|
|
216
|
+
}),
|
|
217
|
+
}
|
|
218
|
+
: {}),
|
|
219
|
+
...(entry.provider.abandonExecution
|
|
220
|
+
? {
|
|
221
|
+
abandonExecution: (conversationKey, turnId) => conversationKey !== sessionId
|
|
222
|
+
? Promise.reject(new Error('Executor binding cannot cross Session scope'))
|
|
223
|
+
: this.withActiveOperation(entry, { conversationKey }, async () => {
|
|
224
|
+
if (entry.retired)
|
|
225
|
+
throw new ExecutorRetiredAbort(entry.provider.id);
|
|
226
|
+
await entry.provider.abandonExecution(conversationKey, turnId);
|
|
227
|
+
}),
|
|
228
|
+
}
|
|
229
|
+
: {}),
|
|
201
230
|
});
|
|
202
231
|
}
|
|
203
232
|
async execute(executorId, request, options = {}) {
|
|
@@ -304,6 +333,13 @@ function validateProvider(provider) {
|
|
|
304
333
|
if (typeof provider.execute !== 'function') {
|
|
305
334
|
throw new TypeError(`Executor implementation is invalid: ${provider.id}`);
|
|
306
335
|
}
|
|
336
|
+
if (provider.acknowledgeExecution !== undefined &&
|
|
337
|
+
typeof provider.acknowledgeExecution !== 'function') {
|
|
338
|
+
throw new TypeError(`Executor acknowledgement is invalid: ${provider.id}`);
|
|
339
|
+
}
|
|
340
|
+
if (provider.abandonExecution !== undefined && typeof provider.abandonExecution !== 'function') {
|
|
341
|
+
throw new TypeError(`Executor abandonment is invalid: ${provider.id}`);
|
|
342
|
+
}
|
|
307
343
|
if (provider.displayName !== undefined &&
|
|
308
344
|
(typeof provider.displayName !== 'string' || !provider.displayName.trim())) {
|
|
309
345
|
throw new TypeError(`Executor display name is invalid: ${provider.id}`);
|
|
@@ -20,6 +20,8 @@ import { RetryError } from 'ai';
|
|
|
20
20
|
import { MODEL_FAILURE_MESSAGE_MAX_BYTES } from '@maka/core/model-failure';
|
|
21
21
|
import { truncateUtf8 } from '@maka/core/diagnostic-log';
|
|
22
22
|
import { isAuthenticationErrorText } from '@maka/core/redaction';
|
|
23
|
+
import { providerRetryDecision, responseHeadersFromError } from './provider-retry-policy.js';
|
|
24
|
+
import { OPENAI_RESPONSES_TRANSPORT_CODES, PROVIDER_BILLING_PROVIDER_CODES, } from './provider-error-signals.js';
|
|
23
25
|
/**
|
|
24
26
|
* Structured provider error identifiers that mean the INPUT exceeded the
|
|
25
27
|
* model's context window. These come from the provider's error JSON and are
|
|
@@ -64,20 +66,6 @@ const RESPONSE_TRANSPORT_FAILURE_CODES = new Set([
|
|
|
64
66
|
* represents quota exhaustion and needs different user guidance.
|
|
65
67
|
*/
|
|
66
68
|
const PROVIDER_CAPACITY_CODES = new Set(['resource-exhausted']);
|
|
67
|
-
/**
|
|
68
|
-
* Structured provider error identifiers that mean an ACCOUNT-level usage or
|
|
69
|
-
* billing condition — exhausted credits or a closed plan/quota window —
|
|
70
|
-
* rather than an invalid credential. Providers disagree on which HTTP status
|
|
71
|
-
* travels with them (402, 401/403, even 429); the structured code is the
|
|
72
|
-
* stable evidence, so it outranks every numeric fallback below.
|
|
73
|
-
*/
|
|
74
|
-
const PROVIDER_BILLING_PROVIDER_CODES = new Set([
|
|
75
|
-
'insufficient_quota', // OpenAI & OpenAI-compatible: error.code
|
|
76
|
-
'insufficient_balance', // DeepSeek: error.code
|
|
77
|
-
'quota_exceeded', // OpenAI-compatible variants: error.code
|
|
78
|
-
'freeusagelimiterror', // OpenCode Zen free tier exhausted (HTTP 429): error.type
|
|
79
|
-
'upgrade_required', // Command Code: the plan has no Provider API access (HTTP 403): error.code
|
|
80
|
-
]);
|
|
81
69
|
/**
|
|
82
70
|
* Free-text usage/billing wording that overrides a credential-shaped HTTP
|
|
83
71
|
* status (401/403): some providers report exhausted plan windows, credits,
|
|
@@ -95,30 +83,6 @@ const USAGE_LIMIT_TEXT_PATTERNS = [
|
|
|
95
83
|
/subscription/i,
|
|
96
84
|
];
|
|
97
85
|
const PROVIDER_FAILURE_FIELD_MAX_BYTES = 256;
|
|
98
|
-
const MAX_SAFE_TIMER_DELAY_MS = 2_147_483_647;
|
|
99
|
-
/** Codes the incremental Responses transport raises before any HTTP response. */
|
|
100
|
-
const OPENAI_RESPONSES_TRANSPORT_CODES = new Set([
|
|
101
|
-
'OPENAI_RESPONSES_WEBSOCKET_TRANSPORT_ERROR',
|
|
102
|
-
'OPENAI_RESPONSES_CONTINUATION_UNAVAILABLE',
|
|
103
|
-
]);
|
|
104
|
-
/** Retryability follows the kind alone; never re-derive it from a status or header. */
|
|
105
|
-
const MODEL_FAILURE_RETRY = {
|
|
106
|
-
abort: null,
|
|
107
|
-
auth: null,
|
|
108
|
-
context_overflow: null,
|
|
109
|
-
network: 'network',
|
|
110
|
-
provider_billing: null,
|
|
111
|
-
provider_capacity: 'provider_capacity',
|
|
112
|
-
provider_unavailable: 'provider_unavailable',
|
|
113
|
-
rate_limit: 'rate_limit',
|
|
114
|
-
request_rejected: null,
|
|
115
|
-
stream_truncated: 'stream_truncated',
|
|
116
|
-
timeout: 'timeout',
|
|
117
|
-
unknown: null,
|
|
118
|
-
};
|
|
119
|
-
export function providerRetryReason(kind) {
|
|
120
|
-
return MODEL_FAILURE_RETRY[kind];
|
|
121
|
-
}
|
|
122
86
|
function providerErrorTarget(error) {
|
|
123
87
|
return RetryError.isInstance(error) && error.lastError !== undefined && error.lastError !== error
|
|
124
88
|
? error.lastError
|
|
@@ -169,37 +133,6 @@ function isTransportFailure(target, statusCode) {
|
|
|
169
133
|
}
|
|
170
134
|
return false;
|
|
171
135
|
}
|
|
172
|
-
function responseHeadersFromError(error) {
|
|
173
|
-
if (typeof error !== 'object' || error === null)
|
|
174
|
-
return undefined;
|
|
175
|
-
const value = error.responseHeaders;
|
|
176
|
-
if (typeof value !== 'object' || value === null)
|
|
177
|
-
return undefined;
|
|
178
|
-
const headers = {};
|
|
179
|
-
for (const [key, header] of Object.entries(value)) {
|
|
180
|
-
if (typeof header === 'string')
|
|
181
|
-
headers[key.toLowerCase()] = header;
|
|
182
|
-
}
|
|
183
|
-
return headers;
|
|
184
|
-
}
|
|
185
|
-
function parseRetryAfterMs(headers) {
|
|
186
|
-
const rawMilliseconds = headers['retry-after-ms'];
|
|
187
|
-
const rawRetryAfter = headers['retry-after'];
|
|
188
|
-
if (rawMilliseconds === undefined && rawRetryAfter === undefined)
|
|
189
|
-
return undefined;
|
|
190
|
-
let delayMs;
|
|
191
|
-
if (rawMilliseconds !== undefined) {
|
|
192
|
-
delayMs = Number(rawMilliseconds);
|
|
193
|
-
}
|
|
194
|
-
else {
|
|
195
|
-
const seconds = Number(rawRetryAfter);
|
|
196
|
-
delayMs = Number.isFinite(seconds) ? seconds * 1_000 : Date.parse(rawRetryAfter) - Date.now();
|
|
197
|
-
}
|
|
198
|
-
if (!Number.isFinite(delayMs) || delayMs <= 0 || delayMs > MAX_SAFE_TIMER_DELAY_MS) {
|
|
199
|
-
return undefined;
|
|
200
|
-
}
|
|
201
|
-
return Math.ceil(delayMs);
|
|
202
|
-
}
|
|
203
136
|
function retryMetadataFromFacts(facts, errorClass = classifyProviderFacts(facts)) {
|
|
204
137
|
if (facts.aborted)
|
|
205
138
|
return { retryable: false };
|
|
@@ -207,10 +140,11 @@ function retryMetadataFromFacts(facts, errorClass = classifyProviderFacts(facts)
|
|
|
207
140
|
// Do not let the outer model loop restart that same transport budget.
|
|
208
141
|
if (isTrustedCodexEdgeRejection(facts))
|
|
209
142
|
return { retryable: false };
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
143
|
+
const decision = providerRetryDecision(errorClass, facts.responseHeaders ?? {});
|
|
144
|
+
return {
|
|
145
|
+
retryable: decision.reason !== null,
|
|
146
|
+
...(decision.retryAfterMs === undefined ? {} : { retryAfterMs: decision.retryAfterMs }),
|
|
147
|
+
};
|
|
214
148
|
}
|
|
215
149
|
/** Collects `code`/`type` strings from a payload and from its `error` wrapper. */
|
|
216
150
|
function collectStructuredCodes(payload, out) {
|
|
@@ -535,6 +469,7 @@ const CONTEXT_OVERFLOW_PATTERNS = [
|
|
|
535
469
|
/greater than the context length/i, // LM Studio
|
|
536
470
|
/context window exceeds limit/i, // MiniMax
|
|
537
471
|
/exceeded model token limit/i, // Kimi For Coding
|
|
472
|
+
/exceeded [\w.-]+ model token limit:\s*[\d,]+/i, // Kimi model-qualified limit
|
|
538
473
|
/too large for model with \d+ maximum context length/i, // Mistral
|
|
539
474
|
/prompt has [\d,]+ tokens?, but the configured context size is [\d,]+ tokens?/i, // DS4 server
|
|
540
475
|
/model_context_window_exceeded/i, // z.ai non-standard finish_reason surfaced as error text
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Licensed to the Apache Software Foundation (ASF) under one
|
|
3
|
+
* or more contributor license agreements. See the NOTICE file
|
|
4
|
+
* distributed with this work for additional information
|
|
5
|
+
* regarding copyright ownership. The ASF licenses this file
|
|
6
|
+
* to you under the Apache License, Version 2.0 (the
|
|
7
|
+
* "License"); you may not use this file except in compliance
|
|
8
|
+
* with the License. You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing,
|
|
13
|
+
* software distributed under the License is distributed on an
|
|
14
|
+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
15
|
+
* KIND, either express or implied. See the License for the
|
|
16
|
+
* specific language governing permissions and limitations
|
|
17
|
+
* under the License.
|
|
18
|
+
*/
|
|
19
|
+
/** Provider codes that identify an account-level usage or billing condition. */
|
|
20
|
+
export const PROVIDER_BILLING_PROVIDER_CODES = new Set([
|
|
21
|
+
'insufficient_quota',
|
|
22
|
+
'insufficient_balance',
|
|
23
|
+
'quota_exceeded',
|
|
24
|
+
'freeusagelimiterror',
|
|
25
|
+
'upgrade_required',
|
|
26
|
+
]);
|
|
27
|
+
/** Codes emitted by the incremental Responses transport before an HTTP response. */
|
|
28
|
+
export const OPENAI_RESPONSES_TRANSPORT_CODES = new Set([
|
|
29
|
+
'OPENAI_RESPONSES_WEBSOCKET_TRANSPORT_ERROR',
|
|
30
|
+
'OPENAI_RESPONSES_CONTINUATION_UNAVAILABLE',
|
|
31
|
+
]);
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Licensed to the Apache Software Foundation (ASF) under one
|
|
3
|
+
* or more contributor license agreements. See the NOTICE file
|
|
4
|
+
* distributed with this work for additional information
|
|
5
|
+
* regarding copyright ownership. The ASF licenses this file
|
|
6
|
+
* to you under the Apache License, Version 2.0 (the
|
|
7
|
+
* "License"); you may not use this file except in compliance
|
|
8
|
+
* with the License. You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing,
|
|
13
|
+
* software distributed under the License is distributed on an
|
|
14
|
+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
15
|
+
* KIND, either express or implied. See the License for the
|
|
16
|
+
* specific language governing permissions and limitations
|
|
17
|
+
* under the License.
|
|
18
|
+
*/
|
|
19
|
+
const MAX_TIMER_DELAY_MS = 2_147_483_647;
|
|
20
|
+
const RETRY_REASON = {
|
|
21
|
+
abort: null,
|
|
22
|
+
auth: null,
|
|
23
|
+
context_overflow: null,
|
|
24
|
+
network: 'network',
|
|
25
|
+
provider_billing: null,
|
|
26
|
+
provider_capacity: 'provider_capacity',
|
|
27
|
+
provider_unavailable: 'provider_unavailable',
|
|
28
|
+
rate_limit: 'rate_limit',
|
|
29
|
+
request_rejected: null,
|
|
30
|
+
stream_truncated: 'stream_truncated',
|
|
31
|
+
timeout: 'timeout',
|
|
32
|
+
unknown: null,
|
|
33
|
+
};
|
|
34
|
+
/** One pure policy decision consumed by both Runtime retrying and Host projection. */
|
|
35
|
+
export function providerRetryDecision(kind, headers = {}) {
|
|
36
|
+
const reason = RETRY_REASON[kind];
|
|
37
|
+
if (reason === null)
|
|
38
|
+
return { reason };
|
|
39
|
+
const delay = retryAfterMs(headers);
|
|
40
|
+
return delay === undefined ? { reason } : { reason, retryAfterMs: delay };
|
|
41
|
+
}
|
|
42
|
+
export function providerRetryReason(kind) {
|
|
43
|
+
return providerRetryDecision(kind).reason;
|
|
44
|
+
}
|
|
45
|
+
export function responseHeadersFromError(error) {
|
|
46
|
+
if (typeof error !== 'object' || error === null)
|
|
47
|
+
return undefined;
|
|
48
|
+
const value = error.responseHeaders;
|
|
49
|
+
if (typeof value !== 'object' || value === null)
|
|
50
|
+
return undefined;
|
|
51
|
+
const headers = {};
|
|
52
|
+
if (value instanceof Headers) {
|
|
53
|
+
value.forEach((header, key) => {
|
|
54
|
+
headers[key.toLowerCase()] = header;
|
|
55
|
+
});
|
|
56
|
+
return headers;
|
|
57
|
+
}
|
|
58
|
+
for (const [key, header] of Object.entries(value)) {
|
|
59
|
+
if (typeof header === 'string')
|
|
60
|
+
headers[key.toLowerCase()] = header;
|
|
61
|
+
}
|
|
62
|
+
return headers;
|
|
63
|
+
}
|
|
64
|
+
export function retryAfterMs(headers) {
|
|
65
|
+
const bounded = (delayMs) => Number.isFinite(delayMs) && delayMs > 0 && delayMs <= MAX_TIMER_DELAY_MS
|
|
66
|
+
? Math.ceil(delayMs)
|
|
67
|
+
: undefined;
|
|
68
|
+
const milliseconds = headers['retry-after-ms'];
|
|
69
|
+
if (milliseconds !== undefined) {
|
|
70
|
+
const parsed = bounded(Number(milliseconds));
|
|
71
|
+
if (parsed !== undefined)
|
|
72
|
+
return parsed;
|
|
73
|
+
}
|
|
74
|
+
const retryAfter = headers['retry-after'];
|
|
75
|
+
if (retryAfter === undefined)
|
|
76
|
+
return undefined;
|
|
77
|
+
const seconds = Number(retryAfter);
|
|
78
|
+
return bounded(Number.isFinite(seconds) ? seconds * 1_000 : Date.parse(retryAfter) - Date.now());
|
|
79
|
+
}
|
|
@@ -3224,8 +3224,9 @@ export class SessionManager {
|
|
|
3224
3224
|
const toolRecovery = resolveRuntimeRecovery(inspected.runtimeEvents);
|
|
3225
3225
|
const indeterminate = toolRecovery.decisions.filter((decision) => decision.status === 'indeterminate');
|
|
3226
3226
|
unknownDispatchedTools = indeterminate
|
|
3227
|
-
.filter((decision) => decision.reason === 'dispatch_without_response')
|
|
3228
|
-
.map(({ toolCallId, toolName }) => ({
|
|
3227
|
+
.filter((decision) => decision.reason === 'dispatch_without_response' && decision.operationId !== undefined)
|
|
3228
|
+
.map(({ operationId, toolCallId, toolName }) => ({
|
|
3229
|
+
operationId: operationId,
|
|
3229
3230
|
toolCallId,
|
|
3230
3231
|
...(toolName ? { toolName } : {}),
|
|
3231
3232
|
}));
|
|
@@ -3265,7 +3266,7 @@ export class SessionManager {
|
|
|
3265
3266
|
},
|
|
3266
3267
|
};
|
|
3267
3268
|
}
|
|
3268
|
-
if (await this.applyAgentRunRecovery(sessionId, decision, inspected, policy)) {
|
|
3269
|
+
if (await this.applyAgentRunRecovery(sessionId, decision, inspected, policy, unknownDispatchedTools.map(({ operationId }) => operationId))) {
|
|
3269
3270
|
recovered = true;
|
|
3270
3271
|
}
|
|
3271
3272
|
}
|
|
@@ -3276,7 +3277,7 @@ export class SessionManager {
|
|
|
3276
3277
|
return undefined;
|
|
3277
3278
|
return runtimeTerminalFactToRecoveryDecision(inspected.invocation, inspected.terminalRuntimeFact);
|
|
3278
3279
|
}
|
|
3279
|
-
async applyAgentRunRecovery(sessionId, decision, inspected, policy = { kind: 'best_effort' }) {
|
|
3280
|
+
async applyAgentRunRecovery(sessionId, decision, inspected, policy = { kind: 'best_effort' }, unsettledOperationIds = []) {
|
|
3280
3281
|
if (!this.deps.runStore || !this.deps.runtimeEventStore)
|
|
3281
3282
|
return false;
|
|
3282
3283
|
const ts = this.deps.now();
|
|
@@ -3312,6 +3313,7 @@ export class SessionManager {
|
|
|
3312
3313
|
terminalEvent,
|
|
3313
3314
|
...(failureClass ? { failureClass } : {}),
|
|
3314
3315
|
...(abortSource ? { abortSource } : {}),
|
|
3316
|
+
...(unsettledOperationIds.length > 0 ? { unsettledOperationIds } : {}),
|
|
3315
3317
|
});
|
|
3316
3318
|
}
|
|
3317
3319
|
catch (error) {
|
|
@@ -34,6 +34,8 @@ export function normalizeStopSessionSource(source, workHubActionId) {
|
|
|
34
34
|
return 'renderer.stop_button';
|
|
35
35
|
case 'graph_supervisor':
|
|
36
36
|
return 'graph.supervisor';
|
|
37
|
+
case 'host_shutdown':
|
|
38
|
+
return 'runtime_host.shutdown';
|
|
37
39
|
case 'workhub_direct_stop':
|
|
38
40
|
return workHubDirectStopAbortSource(workHubActionId);
|
|
39
41
|
case undefined:
|
|
@@ -353,16 +353,16 @@ export class ShellRunProcessManager {
|
|
|
353
353
|
failed: true,
|
|
354
354
|
}));
|
|
355
355
|
}
|
|
356
|
-
//
|
|
357
|
-
//
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
return shellRunContent(record, operation);
|
|
361
|
-
}
|
|
362
|
-
if (isTerminalShellRunStatus(record.status))
|
|
363
|
-
record = await this.markObserved(record);
|
|
356
|
+
// The snapshot was captured before persistence. Exit can begin during that
|
|
357
|
+
// await, so every control response goes through the same final-record
|
|
358
|
+
// reconciliation rather than returning a stale running snapshot.
|
|
359
|
+
record = await this.reconcilePtyControlRecord(live, record);
|
|
364
360
|
return clientControl ? compactShellRunContent(record) : shellRunContent(record, operation);
|
|
365
361
|
}
|
|
362
|
+
async reconcilePtyControlRecord(live, snapshot) {
|
|
363
|
+
const record = live.driverExit || live.finalizeOnce ? await live.finished.join() : snapshot;
|
|
364
|
+
return isTerminalShellRunStatus(record.status) ? this.markObserved(record) : record;
|
|
365
|
+
}
|
|
366
366
|
async readRuntimeResource(sessionId, ref, abortSignal) {
|
|
367
367
|
return this.resourceDetail(sessionId, ref, true, abortSignal, true);
|
|
368
368
|
}
|
|
@@ -45,7 +45,13 @@ export function classifyTerminalRuntimeLedger(run, events) {
|
|
|
45
45
|
*/
|
|
46
46
|
export async function commitTerminalRunWithRuntimeFact(input) {
|
|
47
47
|
assertCommittableTerminalEvent(input.terminalEvent, input, input.status);
|
|
48
|
-
|
|
48
|
+
if (input.unsettledOperationIds?.length &&
|
|
49
|
+
input.runtimeEventStore.ensureRecoveredTerminalRuntimeEventDurable) {
|
|
50
|
+
await input.runtimeEventStore.ensureRecoveredTerminalRuntimeEventDurable(input.sessionId, input.runId, input.terminalEvent, input.unsettledOperationIds);
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
await input.runtimeEventStore.ensureTerminalRuntimeEventDurable(input.sessionId, input.runId, input.terminalEvent);
|
|
54
|
+
}
|
|
49
55
|
}
|
|
50
56
|
export async function commitOrCreateTerminalRunFact(input) {
|
|
51
57
|
const createdTerminalEvent = !input.terminalEvent;
|
|
@@ -2417,10 +2417,11 @@ function coerceTerminalFailure(tool, cwd, args, err) {
|
|
|
2417
2417
|
}
|
|
2418
2418
|
: {}),
|
|
2419
2419
|
},
|
|
2420
|
-
//
|
|
2421
|
-
//
|
|
2422
|
-
//
|
|
2423
|
-
//
|
|
2420
|
+
// Short error for the direct caller, built from the tail because that is
|
|
2421
|
+
// where shell errors land; Code Mode's nested callTool throws it as an
|
|
2422
|
+
// Error. It is not the model-visible result: each step is rebuilt from
|
|
2423
|
+
// durable events, where `content` above is what the model reads. When that
|
|
2424
|
+
// result is pruned, failure details stay pageable content (#5247).
|
|
2424
2425
|
message: buildTerminalFailureMessage(error.code, stdout, stderr, sandboxDenied),
|
|
2425
2426
|
sandboxDenied,
|
|
2426
2427
|
};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Licensed to the Apache Software Foundation (ASF) under one
|
|
3
|
+
* or more contributor license agreements. See the NOTICE file
|
|
4
|
+
* distributed with this work for additional information
|
|
5
|
+
* regarding copyright ownership. The ASF licenses this file
|
|
6
|
+
* to you under the Apache License, Version 2.0 (the
|
|
7
|
+
* "License"); you may not use this file except in compliance
|
|
8
|
+
* with the License. You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing,
|
|
13
|
+
* software distributed under the License is distributed on an
|
|
14
|
+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
15
|
+
* KIND, either express or implied. See the License for the
|
|
16
|
+
* specific language governing permissions and limitations
|
|
17
|
+
* under the License.
|
|
18
|
+
*/
|
|
19
|
+
export function seedProviderRetry(turn, now) {
|
|
20
|
+
return turn.providerRetry ? retryEvent(turn, turn.providerRetry, now) : undefined;
|
|
21
|
+
}
|
|
22
|
+
export function projectProviderRetryChange(previous, next, now) {
|
|
23
|
+
if (!isLiveTurn(next) || !next.providerRetry)
|
|
24
|
+
return undefined;
|
|
25
|
+
const prior = isLiveTurn(previous) && previous.runId === next.runId ? previous.providerRetry : undefined;
|
|
26
|
+
return sameRetry(prior, next.providerRetry)
|
|
27
|
+
? undefined
|
|
28
|
+
: retryEvent(next, next.providerRetry, now);
|
|
29
|
+
}
|
|
30
|
+
function retryEvent(turn, retry, now) {
|
|
31
|
+
const base = {
|
|
32
|
+
type: 'provider_retry',
|
|
33
|
+
id: `host-retry:${turn.runId}:${retry.phase}:${retry.attempt}`,
|
|
34
|
+
turnId: turn.turnId,
|
|
35
|
+
ts: now,
|
|
36
|
+
attempt: retry.attempt,
|
|
37
|
+
maxAttempts: retry.maxAttempts,
|
|
38
|
+
reason: retry.reason,
|
|
39
|
+
};
|
|
40
|
+
if (retry.phase === 'started')
|
|
41
|
+
return { ...base, phase: 'started' };
|
|
42
|
+
const elapsed = retry.ts === undefined ? 0 : Math.max(0, now - retry.ts);
|
|
43
|
+
return {
|
|
44
|
+
...base,
|
|
45
|
+
phase: 'scheduled',
|
|
46
|
+
delayMs: retry.delayMs,
|
|
47
|
+
remainingMs: Math.max(0, retry.delayMs - elapsed),
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
function sameRetry(left, right) {
|
|
51
|
+
if (!left ||
|
|
52
|
+
left.phase !== right.phase ||
|
|
53
|
+
left.attempt !== right.attempt ||
|
|
54
|
+
left.maxAttempts !== right.maxAttempts ||
|
|
55
|
+
left.reason !== right.reason) {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
return (left.phase === 'started' ||
|
|
59
|
+
(right.phase === 'scheduled' && left.delayMs === right.delayMs && left.ts === right.ts));
|
|
60
|
+
}
|
|
61
|
+
function isLiveTurn(turn) {
|
|
62
|
+
return (!!turn && turn.status !== 'completed' && turn.status !== 'failed' && turn.status !== 'cancelled');
|
|
63
|
+
}
|
|
@@ -16,8 +16,8 @@
|
|
|
16
16
|
* specific language governing permissions and limitations
|
|
17
17
|
* under the License.
|
|
18
18
|
*/
|
|
19
|
-
import { isDeepStrictEqual } from 'node:util';
|
|
20
19
|
import { foldAssistantDelta, } from '@maka/core/events';
|
|
20
|
+
import { projectProviderRetryChange, seedProviderRetry } from './provider-retry-projector.js';
|
|
21
21
|
export function createRuntimeHostSessionProjectionSeed(transcript, snapshot) {
|
|
22
22
|
return {
|
|
23
23
|
durableUserMessages: transcript
|
|
@@ -126,12 +126,10 @@ export class RuntimeHostSessionProjector {
|
|
|
126
126
|
if (root.rootExecutionKind === 'context_compact') {
|
|
127
127
|
events.push(contextCompactionStartedEvent(root, this.#now()));
|
|
128
128
|
}
|
|
129
|
-
let seededAssistantText = false;
|
|
130
129
|
if (includeAssistantText) {
|
|
131
130
|
for (const accumulator of this.#accumulators.values()) {
|
|
132
131
|
if (accumulator.complete)
|
|
133
132
|
continue;
|
|
134
|
-
seededAssistantText = true;
|
|
135
133
|
events.push({
|
|
136
134
|
type: accumulator.kind === 'text' ? 'text_delta' : 'thinking_delta',
|
|
137
135
|
id: `host-seed:${root.runId}:${accumulator.kind}:${accumulator.messageId}`,
|
|
@@ -143,8 +141,11 @@ export class RuntimeHostSessionProjector {
|
|
|
143
141
|
});
|
|
144
142
|
}
|
|
145
143
|
}
|
|
146
|
-
|
|
147
|
-
|
|
144
|
+
const seededAssistantContent = events.some((event) => event.type === 'text_delta' || event.type === 'thinking_delta');
|
|
145
|
+
if (!seededAssistantContent) {
|
|
146
|
+
const retry = seedProviderRetry(root, this.#now());
|
|
147
|
+
if (retry)
|
|
148
|
+
events.push(retry);
|
|
148
149
|
}
|
|
149
150
|
for (const interaction of this.#snapshot.interactions.pending) {
|
|
150
151
|
events.push(...projectRuntimeHostInteractionRequest(interaction, this.#now()));
|
|
@@ -368,7 +369,7 @@ export class RuntimeHostSessionProjector {
|
|
|
368
369
|
if (root && rootIsCompaction && !previousWasCompaction) {
|
|
369
370
|
events.push(contextCompactionStartedEvent(root, this.#now()));
|
|
370
371
|
}
|
|
371
|
-
const retry =
|
|
372
|
+
const retry = projectProviderRetryChange(previousRoot, root, this.#now());
|
|
372
373
|
if (retry)
|
|
373
374
|
events.push(retry);
|
|
374
375
|
const terminalTurn = root && isRuntimeHostTerminalTurn(root) && !sameRuntimeHostTerminalTurn(previousRoot, root)
|
|
@@ -668,51 +669,6 @@ export function sameRuntimeHostTerminalTurn(previous, next) {
|
|
|
668
669
|
previous.runId === next.runId &&
|
|
669
670
|
previous.terminalEventId === next.terminalEventId);
|
|
670
671
|
}
|
|
671
|
-
function liveProviderRetryEvent(previous, next, ts) {
|
|
672
|
-
if (!next || isRuntimeHostTerminalTurn(next) || !next.providerRetry)
|
|
673
|
-
return undefined;
|
|
674
|
-
const previousRetry = previous && !isRuntimeHostTerminalTurn(previous) ? previous.providerRetry : undefined;
|
|
675
|
-
if (previous?.runId === next.runId && isDeepStrictEqual(previousRetry, next.providerRetry)) {
|
|
676
|
-
return undefined;
|
|
677
|
-
}
|
|
678
|
-
return providerRetryEvent(next, ts);
|
|
679
|
-
}
|
|
680
|
-
function providerRetryEvent(root, ts) {
|
|
681
|
-
const retry = root.providerRetry;
|
|
682
|
-
if (!retry) {
|
|
683
|
-
throw new Error('Non-terminal Turn snapshot has no provider retry');
|
|
684
|
-
}
|
|
685
|
-
if (retry.phase !== 'scheduled') {
|
|
686
|
-
return {
|
|
687
|
-
type: 'provider_retry',
|
|
688
|
-
id: `host-seed:${root.runId}:provider_retry`,
|
|
689
|
-
turnId: root.turnId,
|
|
690
|
-
ts,
|
|
691
|
-
phase: 'started',
|
|
692
|
-
attempt: retry.attempt,
|
|
693
|
-
maxAttempts: retry.maxAttempts,
|
|
694
|
-
reason: retry.reason,
|
|
695
|
-
};
|
|
696
|
-
}
|
|
697
|
-
// remainingMs is the skew-free countdown authority for clients on another
|
|
698
|
-
// machine: a duration, recomputed from the host-clock schedule time stored
|
|
699
|
-
// in the snapshot, so a mid-wait re-projection (reconnect) does not restart
|
|
700
|
-
// the countdown. Snapshots from older runtimes lack `ts` and degrade to the
|
|
701
|
-
// full delay.
|
|
702
|
-
const remainingMs = retry.ts === undefined ? retry.delayMs : Math.max(0, retry.delayMs - (ts - retry.ts));
|
|
703
|
-
return {
|
|
704
|
-
type: 'provider_retry',
|
|
705
|
-
id: `host-seed:${root.runId}:provider_retry`,
|
|
706
|
-
turnId: root.turnId,
|
|
707
|
-
ts,
|
|
708
|
-
phase: 'scheduled',
|
|
709
|
-
attempt: retry.attempt,
|
|
710
|
-
maxAttempts: retry.maxAttempts,
|
|
711
|
-
delayMs: retry.delayMs,
|
|
712
|
-
remainingMs,
|
|
713
|
-
reason: retry.reason,
|
|
714
|
-
};
|
|
715
|
-
}
|
|
716
672
|
function abortReason(source) {
|
|
717
673
|
if (source.includes('timeout'))
|
|
718
674
|
return 'timeout';
|
|
@@ -46,6 +46,7 @@ export * from './project-catalog-change.js';
|
|
|
46
46
|
export * from './execution-inspect.js';
|
|
47
47
|
export * from './external-session.js';
|
|
48
48
|
export * from './message.js';
|
|
49
|
+
export * from './queue-mutation.js';
|
|
49
50
|
export * from './operations.js';
|
|
50
51
|
export * from './runtime-resource.js';
|
|
51
52
|
export * from './session-continuity.js';
|
|
@@ -64,7 +65,10 @@ export const RUNTIME_HOST_REGISTRATION_SCHEMA_VERSION = 1;
|
|
|
64
65
|
export const RUNTIME_HOST_PROTOCOL_VERSION = 0;
|
|
65
66
|
// Increment when the same protocol version no longer guarantees safe Client-Host
|
|
66
67
|
// interoperability. Mismatches are rejected before domain commands are admitted.
|
|
67
|
-
export const RUNTIME_HOST_COMPATIBILITY_EPOCH =
|
|
68
|
+
export const RUNTIME_HOST_COMPATIBILITY_EPOCH = 198;
|
|
69
|
+
// 198: Executor readiness exposes explicit restore, restore-failed and history-gap states.
|
|
70
|
+
// 197: Queue reorder requests carry the expected queue revision. Epoch-196
|
|
71
|
+
// peers reject the required field or send an unfenced reorder request.
|
|
68
72
|
// 196: `turn.start` carries an optional durable external-message origin; older
|
|
69
73
|
// peers would drop activation provenance and misclassify automated turns.
|
|
70
74
|
// 195: Session catalog live run state may carry the host generation that
|
|
@@ -74,6 +78,8 @@ export const RUNTIME_HOST_COMPATIBILITY_EPOCH = 196;
|
|
|
74
78
|
// 194: Session catalog live run state may carry the runtime's run epoch, which
|
|
75
79
|
// lets clients order same-revision reads. Epoch-193 peers reject the unknown
|
|
76
80
|
// key, so a newer Desktop against an older Host loses session catalog reads.
|
|
81
|
+
// 193: Queue reorder requests require at least one entry identity. Epoch-192
|
|
82
|
+
// peers can send an empty reorder request that the current Host rejects.
|
|
77
83
|
// 192: Message quotes carry an optional annotation written by the user, which
|
|
78
84
|
// the model reads beside the excerpt. An epoch-191 peer rejects the field.
|
|
79
85
|
// 191: Session catalog change frames can carry attention events.
|
|
@@ -410,8 +416,8 @@ export const RUNTIME_HOST_COMPATIBILITY_EPOCH = 196;
|
|
|
410
416
|
// 41: Context compaction returns a typed terminal outcome on both Turn
|
|
411
417
|
// snapshots and context.compact results. Epoch-40 peers reject these closed
|
|
412
418
|
// shapes after admission, so mixed peers must fail during the handshake.
|
|
413
|
-
// 40:
|
|
414
|
-
//
|
|
419
|
+
// 40: Queue entries become independently addressable for promotion,
|
|
420
|
+
// retraction, and ordering. Epoch-39 peers do not recognize those commands.
|
|
415
421
|
// 39: Client Capability tool descriptors carry trusted activity semantics and
|
|
416
422
|
// invocations can stream bounded progress frames.
|
|
417
423
|
// 38: `execute` is no longer a permission mode. Frame decoders reject it, so a
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Licensed to the Apache Software Foundation (ASF) under one
|
|
3
|
+
* or more contributor license agreements. See the NOTICE file
|
|
4
|
+
* distributed with this work for additional information
|
|
5
|
+
* regarding copyright ownership. The ASF licenses this file
|
|
6
|
+
* to you under the Apache License, Version 2.0 (the
|
|
7
|
+
* "License"); you may not use this file except in compliance
|
|
8
|
+
* with the License. You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing,
|
|
13
|
+
* software distributed under the License is distributed on an
|
|
14
|
+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
15
|
+
* KIND, either express or implied. See the License for the
|
|
16
|
+
* specific language governing permissions and limitations
|
|
17
|
+
* under the License.
|
|
18
|
+
*/
|
|
19
|
+
export const MESSAGE_QUEUE_MAX_ENTRIES = 64;
|
|
20
|
+
export const MESSAGE_QUEUE_PROJECTION_MAX_BYTES = 52 * 1024;
|
|
21
|
+
export const MESSAGE_OPERATION_RESULT_MAX_BYTES = 56 * 1024;
|