maka-agent 0.2.0-dev.47.20260922 → 0.2.0-dev.48.20260923
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/runtime-host-capability-provider-command.js +25 -6
- package/dist/tui-mcp-control.js +37 -24
- 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/acp-errors.js +26 -0
- package/node_modules/@maka/acp-executor-plugin/dist/acp-filesystem.js +103 -0
- package/node_modules/@maka/acp-executor-plugin/dist/acp-process.js +119 -0
- package/node_modules/@maka/acp-executor-plugin/dist/acp-projection.js +146 -0
- package/node_modules/@maka/acp-executor-plugin/dist/index.js +653 -0
- package/node_modules/@maka/acp-executor-plugin/dist/plugin.mjs +24446 -0
- package/node_modules/@maka/acp-executor-plugin/package.json +15 -0
- package/node_modules/@maka/antigravity-acp-plugin/dist/index.js +88 -0
- package/node_modules/@maka/antigravity-acp-plugin/dist/model-presentation.js +53 -0
- package/node_modules/@maka/antigravity-acp-plugin/dist/plugin.mjs +115 -0
- package/node_modules/@maka/antigravity-acp-plugin/package.json +15 -0
- package/node_modules/@maka/core/dist/executor-catalog.js +106 -0
- package/node_modules/@maka/core/dist/mcp.js +4 -1
- package/node_modules/@maka/core/dist/model-metadata.js +28 -1
- package/node_modules/@maka/core/dist/runtime-event-store.js +25 -0
- package/node_modules/@maka/core/dist/runtime-invocation.js +5 -0
- package/node_modules/@maka/core/dist/runtime-policy/credential-vault-codec.js +6 -0
- package/node_modules/@maka/core/dist/runtime-policy/policy-codec.js +21 -0
- package/node_modules/@maka/core/dist/session.js +2 -0
- package/node_modules/@maka/core/dist/settings.js +1 -0
- package/node_modules/@maka/core/dist/tool-ledger-scanner.js +365 -104
- package/node_modules/@maka/core/dist/turn-origin.js +14 -0
- package/node_modules/@maka/core/package.json +2 -0
- package/node_modules/@maka/mcp/dist/credential-coordinator.js +6 -1
- package/node_modules/@maka/mcp/dist/index.js +31 -5
- package/node_modules/@maka/mcp/dist/oauth.js +54 -6
- package/node_modules/@maka/runtime/dist/agent-run-inspect.js +1 -1
- package/node_modules/@maka/runtime/dist/conversation-copy.js +56 -1
- package/node_modules/@maka/runtime/dist/mcp-tools.js +9 -2
- package/node_modules/@maka/runtime/dist/plugin-executor-backend.js +116 -3
- package/node_modules/@maka/runtime/dist/plugin-executor-service.js +212 -16
- package/node_modules/@maka/runtime/dist/runtime-ledger-repair.js +2 -2
- package/node_modules/@maka/runtime/dist/session-event-runtime-mapper.js +3 -0
- package/node_modules/@maka/runtime/dist/session-manager.js +170 -125
- package/node_modules/@maka/runtime/dist/shell-run-manager.js +3 -0
- package/node_modules/@maka/runtime/dist/stream-graph-coordinator.js +29 -4
- package/node_modules/@maka/runtime-host/dist/candidate-entry.js +8 -5
- package/node_modules/@maka/runtime-host/dist/client/index.js +1 -1
- package/node_modules/@maka/runtime-host/dist/client/reconnect-lifecycle.js +8 -1
- package/node_modules/@maka/runtime-host/dist/client/session-catalog-summary.js +6 -1
- package/node_modules/@maka/runtime-host/dist/composition-identity.js +19 -0
- package/node_modules/@maka/runtime-host/dist/protocol/index.js +10 -2
- package/node_modules/@maka/runtime-host/dist/protocol/plugin-platform.js +34 -0
- package/node_modules/@maka/runtime-host/dist/protocol/session-catalog.js +40 -2
- package/node_modules/@maka/runtime-host/dist/server/builtin-external-agent-plugins.js +188 -0
- package/node_modules/@maka/runtime-host/dist/server/candidate.js +12 -7
- package/node_modules/@maka/runtime-host/dist/server/client-capability-recovery.js +44 -46
- package/node_modules/@maka/runtime-host/dist/server/context-coordinator.js +2 -0
- package/node_modules/@maka/runtime-host/dist/server/execution-composition-factory.js +1 -1
- package/node_modules/@maka/runtime-host/dist/server/execution-composition.js +159 -19
- package/node_modules/@maka/runtime-host/dist/server/execution-model-authority.js +3 -0
- package/node_modules/@maka/runtime-host/dist/server/extension-bundle.js +4 -0
- package/node_modules/@maka/runtime-host/dist/server/host-composition-source.js +47 -0
- package/node_modules/@maka/runtime-host/dist/server/host-composition.js +1 -29
- package/node_modules/@maka/runtime-host/dist/server/host-kernel.js +2 -9
- package/node_modules/@maka/runtime-host/dist/server/hosted-execution-recovery.js +75 -9
- package/node_modules/@maka/runtime-host/dist/server/hosted-execution-tool-profile.js +4 -0
- package/node_modules/@maka/runtime-host/dist/server/interaction-coordinator.js +45 -0
- package/node_modules/@maka/runtime-host/dist/server/jev-routing-model.js +157 -0
- package/node_modules/@maka/runtime-host/dist/server/listener-set.js +2 -2
- package/node_modules/@maka/runtime-host/dist/server/message-coordinator.js +4 -0
- package/node_modules/@maka/runtime-host/dist/server/plugin-platform-coordinator.js +11 -1
- package/node_modules/@maka/runtime-host/dist/server/process-lifecycle.js +1 -1
- package/node_modules/@maka/runtime-host/dist/server/process-termination-error.js +27 -0
- package/node_modules/@maka/runtime-host/dist/server/root-turn-coordinator.js +91 -12
- package/node_modules/@maka/runtime-host/dist/server/runtime-policy-coordinator.js +2 -0
- package/node_modules/@maka/runtime-host/dist/server/session-catalog-coordinator.js +99 -12
- package/node_modules/@maka/runtime-host/dist/server/session-effect-coordinator.js +12 -6
- package/node_modules/@maka/runtime-host/dist/server/session-transcript-reader.js +33 -0
- package/node_modules/@maka/runtime-host/dist/server/workhub-coordination-coordinator.js +4 -0
- package/node_modules/@maka/runtime-host/dist/server/workhub-result-coordinator.js +173 -0
- package/node_modules/@maka/runtime-host/dist/server/workhub-result-runtime.js +293 -0
- package/node_modules/@maka/runtime-host/package.json +2 -0
- package/node_modules/@maka/storage/dist/agent-run-store-contract.js +8 -0
- package/node_modules/@maka/storage/dist/execution-stores.js +15 -3
- package/node_modules/@maka/storage/dist/mcp-config-store.js +91 -2
- package/node_modules/@maka/storage/dist/operational-state-store.js +15 -1
- package/node_modules/@maka/storage/dist/plan-authority.js +2 -0
- package/node_modules/@maka/storage/dist/plan-store.js +30 -0
- package/node_modules/@maka/storage/dist/runtime-event-persistence.js +1 -0
- package/node_modules/@maka/storage/dist/runtime-policy/credential-vault-document.js +4 -1
- package/node_modules/@maka/storage/dist/runtime-policy/policy-document.js +2 -0
- package/node_modules/@maka/storage/dist/session-store-values.js +16 -4
- package/node_modules/@maka/storage/dist/shell-run-authority.js +1 -0
- package/node_modules/@maka/storage/dist/shell-run-store.js +15 -0
- package/node_modules/@maka/storage/dist/sqlite-runtime-schema.js +74 -1
- package/node_modules/@maka/storage/dist/sqlite-runtime-store.js +724 -84
- package/node_modules/@maka/storage/dist/sqlite-session-metadata-store.js +16 -0
- package/package.json +1 -1
|
@@ -16,6 +16,8 @@
|
|
|
16
16
|
* specific language governing permissions and limitations
|
|
17
17
|
* under the License.
|
|
18
18
|
*/
|
|
19
|
+
import { createWorkHubResultRuntime } from './workhub-result-runtime.js';
|
|
20
|
+
import { createJevRoutingModel } from './jev-routing-model.js';
|
|
19
21
|
import { copyWorkHubAttachmentsToTarget } from './workhub-message-attachments.js';
|
|
20
22
|
import { createHash, randomUUID } from 'node:crypto';
|
|
21
23
|
import { attachmentKindFromMimeType, MAX_READ_IMAGE_BYTES } from '@maka/core/attachments';
|
|
@@ -99,7 +101,7 @@ import { HostClientCapabilityCoordinator } from './client-capability-coordinator
|
|
|
99
101
|
import { HostDailyReviewCoordinator } from './daily-review-coordinator.js';
|
|
100
102
|
import { prepareHostAiSdkBackend } from './execution-model-composition.js';
|
|
101
103
|
import { createInteractiveRunComposer, createInteractiveRunComposerFactory, routeInteractiveRunToolSurface, } from './interactive-run-composer.js';
|
|
102
|
-
import { createHostGoalEvaluator, createHostDailyReviewModel, createHostMemoryExtractionModel, createHostPluginModel, createHostSessionEffectModel, } from './execution-model-authority.js';
|
|
104
|
+
import { readDuringBackendCreation, createHostGoalEvaluator, createHostDailyReviewModel, createHostMemoryExtractionModel, createHostPluginModel, createHostSessionEffectModel, } from './execution-model-authority.js';
|
|
103
105
|
import { HostExecutionInspectCoordinator } from './execution-inspect-coordinator.js';
|
|
104
106
|
import { HostExternalSessionCoordinator } from './external-session-coordinator.js';
|
|
105
107
|
import { boundedFailureDiagnostic } from './failure-diagnostic.js';
|
|
@@ -133,6 +135,7 @@ import { HostPlanCoordinator } from './plan-coordinator.js';
|
|
|
133
135
|
import { HostProjectDirectoryAuthority, } from './project-directory-authority.js';
|
|
134
136
|
import { HostProjectCatalogCoordinator } from './project-catalog-coordinator.js';
|
|
135
137
|
import { HostProjectMembershipGate } from './project-membership-gate.js';
|
|
138
|
+
import { HostBuiltinExternalAgentPluginCoordinator, withBuiltinExternalAgentCatalog, } from './builtin-external-agent-plugins.js';
|
|
136
139
|
import { HostPluginPlatformCoordinator } from './plugin-platform-coordinator.js';
|
|
137
140
|
import { HostPluginPlatform } from './plugin-platform.js';
|
|
138
141
|
import { RootAdmissionOwner } from './root-admission-owner.js';
|
|
@@ -150,7 +153,7 @@ import { HostStorageMaintenance } from './storage-maintenance.js';
|
|
|
150
153
|
import { HostSessionRevisionCoordinator } from './session-revision-coordinator.js';
|
|
151
154
|
import { HostSessionEffectCoordinator } from './session-effect-coordinator.js';
|
|
152
155
|
import { SessionContinuityCoordinator } from './session-continuity-coordinator.js';
|
|
153
|
-
import { createSessionTranscriptReader, } from './session-transcript-reader.js';
|
|
156
|
+
import { createSessionTranscriptReader, createTurnResultReader, } from './session-transcript-reader.js';
|
|
154
157
|
import { HostSkillCatalogCoordinator, SkillCatalogInvocableContextError, } from './skill-catalog-coordinator.js';
|
|
155
158
|
import { SkillCatalogRepository } from './skill-catalog-repository.js';
|
|
156
159
|
import { HostSessionTodoCoordinator } from './session-todo-coordinator.js';
|
|
@@ -253,9 +256,28 @@ export async function createExecutionRuntimeHostComposition(context, options = {
|
|
|
253
256
|
executors: pluginExecutors,
|
|
254
257
|
clientBridge: pluginClientBridge,
|
|
255
258
|
});
|
|
256
|
-
const pluginPlatformCoordinator = new HostPluginPlatformCoordinator(pluginPlatform)
|
|
259
|
+
const pluginPlatformCoordinator = new HostPluginPlatformCoordinator(pluginPlatform, async (input) => {
|
|
260
|
+
if (input.kind === 'conversation') {
|
|
261
|
+
const header = await stores.sessionStore.readHeaderSnapshot(input.sessionId);
|
|
262
|
+
if (!header.executorId)
|
|
263
|
+
return [];
|
|
264
|
+
return pluginExecutors.catalog({
|
|
265
|
+
sessionId: input.sessionId,
|
|
266
|
+
executorId: header.executorId,
|
|
267
|
+
cwd: header.cwd,
|
|
268
|
+
...(header.executorConfig ? { configuration: header.executorConfig } : {}),
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
const catalog = await pluginExecutors.catalog({ cwd: input.cwd });
|
|
272
|
+
return withBuiltinExternalAgentCatalog(catalog);
|
|
273
|
+
});
|
|
257
274
|
const openedProjectCatalog = storage.projectCatalog;
|
|
258
275
|
const runtimePolicyStores = storage.runtimePolicy;
|
|
276
|
+
const builtinExternalAgentPlugins = new HostBuiltinExternalAgentPluginCoordinator({
|
|
277
|
+
platform: pluginPlatform,
|
|
278
|
+
controlDirectory: context.owner.controlDirectory,
|
|
279
|
+
readPolicy: () => runtimePolicyStores.runtimePolicy.getSnapshot(),
|
|
280
|
+
});
|
|
259
281
|
const oauthCredentials = new HostOAuthExecutionAuthority(runtimePolicyStores);
|
|
260
282
|
const openedScheduledTaskStore = storage.scheduledTasks;
|
|
261
283
|
const openedPlanStore = storage.plan;
|
|
@@ -623,6 +645,7 @@ export async function createExecutionRuntimeHostComposition(context, options = {
|
|
|
623
645
|
}, projectMembership, context.requestDrain, new HostProjectDirectoryAuthority(options.projectDirectoryRoots));
|
|
624
646
|
let rootCoordinator;
|
|
625
647
|
let workHubCoordination;
|
|
648
|
+
let workHubResults;
|
|
626
649
|
let canonicalProjection;
|
|
627
650
|
let memory;
|
|
628
651
|
let clientCapabilities;
|
|
@@ -634,7 +657,32 @@ export async function createExecutionRuntimeHostComposition(context, options = {
|
|
|
634
657
|
let dailyReview;
|
|
635
658
|
const rootPort = {
|
|
636
659
|
readLatestRootTurnLineage: (identity) => requireRootCoordinator(rootCoordinator).readLatestRootTurnLineage(identity),
|
|
637
|
-
readSessionHeader: (sessionId) =>
|
|
660
|
+
readSessionHeader: async (sessionId) => {
|
|
661
|
+
const projected = await requireRootCoordinator(rootCoordinator).readSessionHeader(sessionId);
|
|
662
|
+
if (!projected || projected.unavailableReason)
|
|
663
|
+
return projected;
|
|
664
|
+
const header = await stores.sessionStore.readHeaderSnapshot(sessionId);
|
|
665
|
+
if (!header.executorId)
|
|
666
|
+
return projected;
|
|
667
|
+
const [entry] = await pluginExecutors.catalog({
|
|
668
|
+
sessionId,
|
|
669
|
+
executorId: header.executorId,
|
|
670
|
+
cwd: header.cwd,
|
|
671
|
+
...(header.executorConfig ? { configuration: header.executorConfig } : {}),
|
|
672
|
+
});
|
|
673
|
+
return {
|
|
674
|
+
...projected,
|
|
675
|
+
idleOnly: true,
|
|
676
|
+
supportsAttachments: entry?.supportsAttachments ?? false,
|
|
677
|
+
...(entry?.readiness === 'ready'
|
|
678
|
+
? {}
|
|
679
|
+
: {
|
|
680
|
+
unavailableReason: entry?.readiness === 'history_only'
|
|
681
|
+
? 'External conversation is history-only. Start a new task.'
|
|
682
|
+
: 'Executor is unavailable. Check External Agents settings.',
|
|
683
|
+
}),
|
|
684
|
+
};
|
|
685
|
+
},
|
|
638
686
|
readRootState: (sessionId) => requireRootCoordinator(rootCoordinator).readRootState(sessionId),
|
|
639
687
|
claimStopFence: (input, commitQueueFence, admission) => requireRootCoordinator(rootCoordinator).claimStopFence(input, commitQueueFence, admission),
|
|
640
688
|
startFromMessage: (input, admission, commitAdmission) => requireRootCoordinator(rootCoordinator).startFromMessage(input, admission, commitAdmission),
|
|
@@ -676,8 +724,14 @@ export async function createExecutionRuntimeHostComposition(context, options = {
|
|
|
676
724
|
continuity = new SessionContinuityCoordinator(context.hostEpoch, (sessionId) => canonicalProjectionReader.read(sessionId), sessionAdmission, context.requestDrain, transcriptReader, (sessionId) => hostChanges.publishSessionCatalog(sessionId), context.sessionAccessAuthority);
|
|
677
725
|
const continuityCoordinator = continuity;
|
|
678
726
|
const planStore = observeInteractivePlanStoreWriter(openedPlanStore, (sessionId) => continuityCoordinator.enqueueSessionDomainChanged(sessionId, 'plan'), context.requestDrain);
|
|
679
|
-
unsubscribeTranscriptChanges = stores.sessionStore.subscribeTranscriptChanges((sessionId) =>
|
|
680
|
-
|
|
727
|
+
unsubscribeTranscriptChanges = stores.sessionStore.subscribeTranscriptChanges((sessionId) => {
|
|
728
|
+
continuityCoordinator.enqueueCanonicalRefresh(sessionId);
|
|
729
|
+
sessionAdmission.detach(() => workHubResults?.notify(sessionId));
|
|
730
|
+
});
|
|
731
|
+
unsubscribeRuntimeEventCommits = stores.runtimeEventStore.subscribeRuntimeEventCommits((sessionId) => {
|
|
732
|
+
continuityCoordinator.enqueueTranscriptAdvanced(sessionId);
|
|
733
|
+
sessionAdmission.detach(() => workHubResults?.notify(sessionId));
|
|
734
|
+
});
|
|
681
735
|
unsubscribeUsageChanges = openedUsageStores.subscribeSessionUsageChanges((sessionId) => continuityCoordinator.enqueueSessionDomainChanged(sessionId, 'usage'));
|
|
682
736
|
dailyReview = new HostDailyReviewCoordinator({
|
|
683
737
|
store: openedDailyReviewStore,
|
|
@@ -717,7 +771,10 @@ export async function createExecutionRuntimeHostComposition(context, options = {
|
|
|
717
771
|
preflightSessionSnapshot: (sessionId, interactionProjection) => canonicalProjectionReader.fitsCandidate(sessionId, {
|
|
718
772
|
interactions: interactionProjection,
|
|
719
773
|
}),
|
|
720
|
-
refreshCanonicalContinuity: (sessionId, admission) =>
|
|
774
|
+
refreshCanonicalContinuity: async (sessionId, admission) => {
|
|
775
|
+
await continuityCoordinator.refreshCanonical(sessionId, admission);
|
|
776
|
+
sessionAdmission.detach(() => workHubResults?.notify(sessionId));
|
|
777
|
+
},
|
|
721
778
|
onPoison: (error) => {
|
|
722
779
|
if (poisonFailure)
|
|
723
780
|
return;
|
|
@@ -784,7 +841,9 @@ export async function createExecutionRuntimeHostComposition(context, options = {
|
|
|
784
841
|
goalTools: requireGoal(goal).tools,
|
|
785
842
|
builtinTools,
|
|
786
843
|
hostTools,
|
|
787
|
-
resolveRootTools: (sessionId) =>
|
|
844
|
+
resolveRootTools: (sessionId) => sessionId === WORKHUB_COORDINATION_SESSION_ID && workHubResults
|
|
845
|
+
? Promise.resolve([workHubResults.tool])
|
|
846
|
+
: requireGraphCoordinator(graphCoordinator).toolsForSession(sessionId),
|
|
788
847
|
resolvePluginTools: (sessionId, coreTools) => pluginTools.resolveContributions(sessionId, coreTools),
|
|
789
848
|
resolvePluginSystemPrompt: async (sessionId, promptContext, baseText) => {
|
|
790
849
|
const assembly = await pluginSystemPrompt.assemble({
|
|
@@ -842,6 +901,9 @@ export async function createExecutionRuntimeHostComposition(context, options = {
|
|
|
842
901
|
...(factoryContext.header.thinkingLevel
|
|
843
902
|
? { thinkingLevel: factoryContext.header.thinkingLevel }
|
|
844
903
|
: {}),
|
|
904
|
+
...(factoryContext.header.executorConfig
|
|
905
|
+
? { configuration: factoryContext.header.executorConfig }
|
|
906
|
+
: {}),
|
|
845
907
|
...(factoryContext.systemPrompt ? { instructions: factoryContext.systemPrompt } : {}),
|
|
846
908
|
binding,
|
|
847
909
|
}),
|
|
@@ -918,7 +980,9 @@ export async function createExecutionRuntimeHostComposition(context, options = {
|
|
|
918
980
|
const capabilitySnapshot = requireClientCapabilities(clientCapabilities).snapshotForSession(sessionId);
|
|
919
981
|
try {
|
|
920
982
|
const [graphTools, planState] = await Promise.all([
|
|
921
|
-
|
|
983
|
+
sessionId === WORKHUB_COORDINATION_SESSION_ID && workHubResults
|
|
984
|
+
? Promise.resolve([workHubResults.tool])
|
|
985
|
+
: requireGraphCoordinator(graphCoordinator).toolsForSession(sessionId),
|
|
922
986
|
planStore.readState(sessionId),
|
|
923
987
|
]);
|
|
924
988
|
const { runtimePolicy, surface } = await resolveInteractiveToolSurface({
|
|
@@ -1246,9 +1310,32 @@ export async function createExecutionRuntimeHostComposition(context, options = {
|
|
|
1246
1310
|
}, {
|
|
1247
1311
|
currentGraphId: (rootSessionId) => requireGraphCoordinator(graphCoordinator).currentGraphId(rootSessionId),
|
|
1248
1312
|
beginNextGraphEpoch: async (rootSessionId) => (await requireGraphCoordinator(graphCoordinator).beginNextGraphEpoch(rootSessionId, (operation) => requireGraphSupervisorWake(graphSupervisorWake).runWithSessionWakesSuppressed(rootSessionId, operation, 'agent_graph_epoch_advanced'))).graphId,
|
|
1249
|
-
}, (input) => sessionEffectCoordinator.nameSessionFromRootMessage(input), context.owner.capability.rootId,
|
|
1250
|
-
|
|
1251
|
-
|
|
1313
|
+
}, (input) => sessionEffectCoordinator.nameSessionFromRootMessage(input), context.owner.capability.rootId, async (input) => {
|
|
1314
|
+
// Explicit injection remains an experiment seam. Injected models own
|
|
1315
|
+
// policy/egress checks and cancellation; this bypasses the production
|
|
1316
|
+
// Jev preparation deadline (including its transcript-read protection).
|
|
1317
|
+
if (dependencies.workHubRoutingModel)
|
|
1318
|
+
return workHubCoordination.prepareRoutingDecision(input);
|
|
1319
|
+
// One admission budget covers policy/transcript reads, both Jev asks,
|
|
1320
|
+
// candidate resolution and transport cleanup; it is not per request.
|
|
1321
|
+
const signal = AbortSignal.any([
|
|
1322
|
+
...(input.inputClosedSignal ? [input.inputClosedSignal] : []),
|
|
1323
|
+
AbortSignal.timeout(8_000),
|
|
1324
|
+
]);
|
|
1325
|
+
try {
|
|
1326
|
+
const { policy } = await readDuringBackendCreation(() => runtimePolicyStores.runtimePolicy.getSnapshot(), signal);
|
|
1327
|
+
if (!policy.jev?.enabled || policy.privacy.incognitoActive)
|
|
1328
|
+
return undefined;
|
|
1329
|
+
return await readDuringBackendCreation(() => workHubCoordination.prepareRoutingDecision({ ...input, inputClosedSignal: signal }), signal);
|
|
1330
|
+
}
|
|
1331
|
+
catch {
|
|
1332
|
+
if (!input.inputClosedSignal?.aborted) {
|
|
1333
|
+
const failure = signal.aborted ? 'timeout' : 'preparation_unavailable';
|
|
1334
|
+
console.warn(`[runtime-host] Jev routing fallback: ${failure}`);
|
|
1335
|
+
}
|
|
1336
|
+
return undefined;
|
|
1337
|
+
}
|
|
1338
|
+
});
|
|
1252
1339
|
const coordinator = rootCoordinator;
|
|
1253
1340
|
const pluginModel = createHostPluginModel({
|
|
1254
1341
|
runtimePolicy: runtimePolicyStores,
|
|
@@ -1601,6 +1688,7 @@ export async function createExecutionRuntimeHostComposition(context, options = {
|
|
|
1601
1688
|
});
|
|
1602
1689
|
async function applyRuntimePolicyMutationEffects() {
|
|
1603
1690
|
try {
|
|
1691
|
+
await builtinExternalAgentPlugins.reconcile();
|
|
1604
1692
|
await requireMemory(memory).refreshAfterPolicyMutation();
|
|
1605
1693
|
}
|
|
1606
1694
|
catch (error) {
|
|
@@ -1624,8 +1712,33 @@ export async function createExecutionRuntimeHostComposition(context, options = {
|
|
|
1624
1712
|
continuity: continuityCoordinator,
|
|
1625
1713
|
workspaceResolver,
|
|
1626
1714
|
requestDrain: context.requestDrain,
|
|
1627
|
-
|
|
1715
|
+
configureExecutor: async (header, configuration) => {
|
|
1716
|
+
if (!header.executorId)
|
|
1717
|
+
throw new Error('Session has no executor');
|
|
1718
|
+
await pluginExecutors.configureConversation(header.id, header.executorId, {
|
|
1719
|
+
conversationKey: header.id,
|
|
1720
|
+
cwd: header.cwd,
|
|
1721
|
+
configuration,
|
|
1722
|
+
});
|
|
1723
|
+
},
|
|
1724
|
+
retireExecutor: (sessionId) => pluginExecutors.retireConversation(sessionId),
|
|
1725
|
+
assertExecutorAvailable: async (sessionId, executorId, configuration, cwd) => {
|
|
1628
1726
|
pluginExecutors.identity(sessionId, executorId);
|
|
1727
|
+
const [entry] = await pluginExecutors.catalog({
|
|
1728
|
+
cwd,
|
|
1729
|
+
executorId,
|
|
1730
|
+
discoverySessionId: sessionId,
|
|
1731
|
+
});
|
|
1732
|
+
if (!entry || entry.readiness !== 'ready')
|
|
1733
|
+
throw new Error('Executor is not ready');
|
|
1734
|
+
// Catalog-managed executors pin their confirmed configuration on every create path.
|
|
1735
|
+
// Providers without model discovery retain main's executor-specific model contract.
|
|
1736
|
+
if (entry.supportsModelChange || entry.models.length > 0) {
|
|
1737
|
+
if (configuration?.model &&
|
|
1738
|
+
!entry.models.some((model) => model.id === configuration.model))
|
|
1739
|
+
throw new Error('Executor model is unavailable');
|
|
1740
|
+
return configuration ?? {};
|
|
1741
|
+
}
|
|
1629
1742
|
},
|
|
1630
1743
|
...(context.sessionAccessAuthority
|
|
1631
1744
|
? { sessionAccessAuthority: context.sessionAccessAuthority }
|
|
@@ -1651,7 +1764,7 @@ export async function createExecutionRuntimeHostComposition(context, options = {
|
|
|
1651
1764
|
},
|
|
1652
1765
|
});
|
|
1653
1766
|
workHubCoordination = new HostWorkHubCoordinationCoordinator({
|
|
1654
|
-
routingModel: dependencies.workHubRoutingModel,
|
|
1767
|
+
routingModel: dependencies.workHubRoutingModel ?? createJevRoutingModel({ stores: runtimePolicyStores }),
|
|
1655
1768
|
requestForm: (input) => interactions.requestForm(input),
|
|
1656
1769
|
targetExecution: workHubTargetExecution,
|
|
1657
1770
|
configureModel: (input) => sessionCatalog.configureWorkHubModel(input),
|
|
@@ -1881,6 +1994,7 @@ export async function createExecutionRuntimeHostComposition(context, options = {
|
|
|
1881
1994
|
? WORKHUB_COORDINATION_REPLACEMENT_SCHEMA_VERSION
|
|
1882
1995
|
: 1,
|
|
1883
1996
|
kind: 'delegation_assigned',
|
|
1997
|
+
returnResults: true,
|
|
1884
1998
|
actionId: input.actionId,
|
|
1885
1999
|
actionFingerprint: input.actionFingerprint,
|
|
1886
2000
|
coordinationTurnId: input.coordinationTurnId ?? input.actionId,
|
|
@@ -1947,6 +2061,20 @@ export async function createExecutionRuntimeHostComposition(context, options = {
|
|
|
1947
2061
|
},
|
|
1948
2062
|
requestDrain: context.requestDrain,
|
|
1949
2063
|
});
|
|
2064
|
+
workHubResults = createWorkHubResultRuntime({
|
|
2065
|
+
stores,
|
|
2066
|
+
executions: coordinator,
|
|
2067
|
+
messages,
|
|
2068
|
+
interactions,
|
|
2069
|
+
admission: sessionAdmission,
|
|
2070
|
+
readTurnResult: createTurnResultReader({
|
|
2071
|
+
stores,
|
|
2072
|
+
canonicalPermissionOutcomes,
|
|
2073
|
+
ensureTranscriptLedger: (sessionId) => requireSessionManager(manager).ensureTranscriptLedgerForRead(sessionId),
|
|
2074
|
+
}),
|
|
2075
|
+
acquireResidency: () => context.acquireResidency('hosted-execution'),
|
|
2076
|
+
onError: (error) => console.error(`[runtime-host] WorkHub result reconciliation failed: ${boundedFailureDiagnostic(error)}`),
|
|
2077
|
+
});
|
|
1950
2078
|
scheduledTasks = new HostScheduledTaskCoordinator({
|
|
1951
2079
|
store: openedScheduledTaskStore,
|
|
1952
2080
|
sessions: stores.sessionStore,
|
|
@@ -2029,7 +2157,13 @@ export async function createExecutionRuntimeHostComposition(context, options = {
|
|
|
2029
2157
|
sessionEffects: sessionEffectCoordinator,
|
|
2030
2158
|
graph: requireGraphCoordinator(graphCoordinator),
|
|
2031
2159
|
graphWake: requireGraphSupervisorWake(graphSupervisorWake),
|
|
2032
|
-
manager
|
|
2160
|
+
manager: {
|
|
2161
|
+
finalizeChildWorkspacePatches: (sessionId) => requireSessionManager(manager).finalizeChildWorkspacePatches(sessionId),
|
|
2162
|
+
disposeSessionBackend: async (sessionId) => {
|
|
2163
|
+
await requireSessionManager(manager).disposeSessionBackend(sessionId);
|
|
2164
|
+
await pluginExecutors.retireConversation(sessionId);
|
|
2165
|
+
},
|
|
2166
|
+
},
|
|
2033
2167
|
capabilities: clientCapabilities,
|
|
2034
2168
|
continuity: continuityCoordinator,
|
|
2035
2169
|
artifacts: openedArtifactStore,
|
|
@@ -2103,6 +2237,10 @@ export async function createExecutionRuntimeHostComposition(context, options = {
|
|
|
2103
2237
|
(connectionId) => pluginPlatformCoordinator.releaseConnection(connectionId),
|
|
2104
2238
|
],
|
|
2105
2239
|
}),
|
|
2240
|
+
createRuntimeHostDomainModule({
|
|
2241
|
+
id: 'builtin-external-agent-plugins',
|
|
2242
|
+
recovery: { state: () => builtinExternalAgentPlugins.recover() },
|
|
2243
|
+
}),
|
|
2106
2244
|
createRuntimeHostDomainModule({
|
|
2107
2245
|
id: 'memory',
|
|
2108
2246
|
handlers: [requireMemory(memory).handlers],
|
|
@@ -2137,9 +2275,6 @@ export async function createExecutionRuntimeHostComposition(context, options = {
|
|
|
2137
2275
|
recoverySessions = await stores.sessionStore.listForRecovery();
|
|
2138
2276
|
await worktreeChildExecutor.recover(recoverySessions.flatMap((session) => session.subagentWorkspace ? [session.subagentWorkspace] : []));
|
|
2139
2277
|
await sessionRevisions.recover();
|
|
2140
|
-
for (const session of recoverySessions) {
|
|
2141
|
-
await stores.runtimeEventStore.repairImmutableSteeringMessageProofsForRecovery(session.id);
|
|
2142
|
-
}
|
|
2143
2278
|
},
|
|
2144
2279
|
},
|
|
2145
2280
|
}),
|
|
@@ -2285,6 +2420,7 @@ export async function createExecutionRuntimeHostComposition(context, options = {
|
|
|
2285
2420
|
},
|
|
2286
2421
|
},
|
|
2287
2422
|
drain: [
|
|
2423
|
+
() => workHubResults?.coordinator.beginDrain(),
|
|
2288
2424
|
() => turnAccessRequests?.beginDrain(),
|
|
2289
2425
|
() => rootCoordinator?.beginDrain(),
|
|
2290
2426
|
() => workspaceExecution?.beginDrain(),
|
|
@@ -2301,6 +2437,7 @@ export async function createExecutionRuntimeHostComposition(context, options = {
|
|
|
2301
2437
|
rootCloseTask ??= coordinator.close();
|
|
2302
2438
|
await rootCloseTask;
|
|
2303
2439
|
},
|
|
2440
|
+
() => workHubResults?.coordinator.close(),
|
|
2304
2441
|
() => runtimeResources?.close(),
|
|
2305
2442
|
() => workspaceExecution?.close(),
|
|
2306
2443
|
() => sessionEffects?.close(),
|
|
@@ -2357,7 +2494,10 @@ export async function createExecutionRuntimeHostComposition(context, options = {
|
|
|
2357
2494
|
beginDrain();
|
|
2358
2495
|
const handlers = composeRuntimeHostDomainHandlers(domainModules);
|
|
2359
2496
|
const recover = () => {
|
|
2360
|
-
recoveryTask ??= recoverRuntimeHostDomainModules(domainModules)
|
|
2497
|
+
recoveryTask ??= recoverRuntimeHostDomainModules(domainModules).then(() => {
|
|
2498
|
+
if (!draining)
|
|
2499
|
+
workHubResults?.coordinator.start();
|
|
2500
|
+
});
|
|
2361
2501
|
return recoveryTask;
|
|
2362
2502
|
};
|
|
2363
2503
|
const close = () => {
|
|
@@ -305,6 +305,9 @@ function createAuxiliaryModelCallAuthority(input) {
|
|
|
305
305
|
};
|
|
306
306
|
}
|
|
307
307
|
async function runHostAuxiliaryModelCall(authority, input) {
|
|
308
|
+
if (input.header.backend === 'plugin-executor') {
|
|
309
|
+
throw new AuxiliaryModelCallConfigurationError('Plugin executor Sessions do not provide a native auxiliary model');
|
|
310
|
+
}
|
|
308
311
|
const target = await readAuxiliaryPreflight(authority, input.abortSignal, () => readDuringBackendCreation(() => resolveExecutionTarget(input.header, authority.runtimePolicy, authority.oauthCredentials, authority.createFetchTransport), input.abortSignal));
|
|
309
312
|
const pricingSnapshot = await readAuxiliaryPreflight(authority, input.abortSignal, () => readDuringBackendCreation(() => authority.usage.pricing.snapshot(), input.abortSignal));
|
|
310
313
|
const request = input.buildRequest(target);
|
|
@@ -233,6 +233,10 @@ export function extensionPackageContentDigest(files) {
|
|
|
233
233
|
}
|
|
234
234
|
return `sha256-${hash.digest('hex')}`;
|
|
235
235
|
}
|
|
236
|
+
/** Computes the canonical digest used by PluginPackageStore without installing the package. */
|
|
237
|
+
export async function extensionPackageDirectoryContentDigest(root) {
|
|
238
|
+
return extensionPackageContentDigest(await readDirectory(root));
|
|
239
|
+
}
|
|
236
240
|
function safePath(value) {
|
|
237
241
|
if (!value ||
|
|
238
242
|
value.length > 512 ||
|
|
@@ -0,0 +1,47 @@
|
|
|
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
|
+
import { INTERACTIVE_RUNTIME_HOST_COMPOSITION_ID } from '../composition-identity.js';
|
|
20
|
+
const COMPOSITION_ID_PATTERN = /^[a-z][a-z0-9]*(?:[.-][a-z0-9]+)*$/;
|
|
21
|
+
export function defineRuntimeHostComposition(descriptor, create) {
|
|
22
|
+
return Object.freeze({
|
|
23
|
+
descriptor: normalizeHostCompositionDescriptor(descriptor),
|
|
24
|
+
create,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
export function defineInteractiveRuntimeHostComposition(create) {
|
|
28
|
+
return defineRuntimeHostComposition(INTERACTIVE_HOST_COMPOSITION_DESCRIPTOR, create);
|
|
29
|
+
}
|
|
30
|
+
export function normalizeHostCompositionDescriptor(descriptor) {
|
|
31
|
+
if (!COMPOSITION_ID_PATTERN.test(descriptor.id) || descriptor.id.length > 128) {
|
|
32
|
+
throw new TypeError('Runtime Host composition id is invalid');
|
|
33
|
+
}
|
|
34
|
+
if (descriptor.revision.length === 0 ||
|
|
35
|
+
descriptor.revision.length > 128 ||
|
|
36
|
+
/[\u0000-\u001f\u007f]/u.test(descriptor.revision)) {
|
|
37
|
+
throw new TypeError('Runtime Host composition revision is invalid');
|
|
38
|
+
}
|
|
39
|
+
return Object.freeze({
|
|
40
|
+
id: descriptor.id,
|
|
41
|
+
revision: descriptor.revision,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
export const INTERACTIVE_HOST_COMPOSITION_DESCRIPTOR = normalizeHostCompositionDescriptor({
|
|
45
|
+
id: INTERACTIVE_RUNTIME_HOST_COMPOSITION_ID,
|
|
46
|
+
revision: '3',
|
|
47
|
+
});
|
|
@@ -16,9 +16,8 @@
|
|
|
16
16
|
* specific language governing permissions and limitations
|
|
17
17
|
* under the License.
|
|
18
18
|
*/
|
|
19
|
-
import { INTERACTIVE_RUNTIME_HOST_COMPOSITION_ID } from '../protocol/index.js';
|
|
20
19
|
import { createUnavailableDomainOperationHandlers, } from './operation-dispatcher.js';
|
|
21
|
-
|
|
20
|
+
export * from './host-composition-source.js';
|
|
22
21
|
const MODULE_ID_PATTERN = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;
|
|
23
22
|
const moduleDrainFailures = new WeakMap();
|
|
24
23
|
export const HOST_RECOVERY_PHASES = [
|
|
@@ -166,30 +165,3 @@ async function closeModuleResources(moduleId, resources, priorFailures) {
|
|
|
166
165
|
throw new AggregateError(errors, `Unable to close Runtime Host ${moduleId} module`);
|
|
167
166
|
}
|
|
168
167
|
}
|
|
169
|
-
export function defineRuntimeHostComposition(descriptor, create) {
|
|
170
|
-
return Object.freeze({
|
|
171
|
-
descriptor: normalizeHostCompositionDescriptor(descriptor),
|
|
172
|
-
create,
|
|
173
|
-
});
|
|
174
|
-
}
|
|
175
|
-
export function defineInteractiveRuntimeHostComposition(create) {
|
|
176
|
-
return defineRuntimeHostComposition(INTERACTIVE_HOST_COMPOSITION_DESCRIPTOR, create);
|
|
177
|
-
}
|
|
178
|
-
export function normalizeHostCompositionDescriptor(descriptor) {
|
|
179
|
-
if (!COMPOSITION_ID_PATTERN.test(descriptor.id) || descriptor.id.length > 128) {
|
|
180
|
-
throw new TypeError('Runtime Host composition id is invalid');
|
|
181
|
-
}
|
|
182
|
-
if (descriptor.revision.length === 0 ||
|
|
183
|
-
descriptor.revision.length > 128 ||
|
|
184
|
-
/[\u0000-\u001f\u007f]/u.test(descriptor.revision)) {
|
|
185
|
-
throw new TypeError('Runtime Host composition revision is invalid');
|
|
186
|
-
}
|
|
187
|
-
return Object.freeze({
|
|
188
|
-
id: descriptor.id,
|
|
189
|
-
revision: descriptor.revision,
|
|
190
|
-
});
|
|
191
|
-
}
|
|
192
|
-
export const INTERACTIVE_HOST_COMPOSITION_DESCRIPTOR = normalizeHostCompositionDescriptor({
|
|
193
|
-
id: INTERACTIVE_RUNTIME_HOST_COMPOSITION_ID,
|
|
194
|
-
revision: '3',
|
|
195
|
-
});
|
|
@@ -31,6 +31,8 @@ import { startLocalRuntimeHostListenerSet, } from './listener-set.js';
|
|
|
31
31
|
import { HostResidencyRegistry } from './host-residency-registry.js';
|
|
32
32
|
import { createPeerMeshOperationHandlers } from './peer-mesh-authority.js';
|
|
33
33
|
import { createHostResourceCollector } from './host-resource-collector.js';
|
|
34
|
+
import { RuntimeHostProcessTerminationRequiredError } from './process-termination-error.js';
|
|
35
|
+
export { RuntimeHostProcessTerminationRequiredError } from './process-termination-error.js';
|
|
34
36
|
const DEFAULT_IDLE_GRACE_MS = 30_000;
|
|
35
37
|
const DEFAULT_HANDSHAKE_TIMEOUT_MS = 5_000;
|
|
36
38
|
const DEFAULT_SHUTDOWN_GRACE_MS = 10_000;
|
|
@@ -41,15 +43,6 @@ const HOST_PROTOCOL = {
|
|
|
41
43
|
min: RUNTIME_HOST_PROTOCOL_VERSION,
|
|
42
44
|
max: RUNTIME_HOST_PROTOCOL_VERSION,
|
|
43
45
|
};
|
|
44
|
-
export class RuntimeHostProcessTerminationRequiredError extends Error {
|
|
45
|
-
shutdownGraceMs;
|
|
46
|
-
code = 'process_termination_required';
|
|
47
|
-
constructor(shutdownGraceMs) {
|
|
48
|
-
super(`Runtime Host did not shut down within ${shutdownGraceMs} ms`);
|
|
49
|
-
this.shutdownGraceMs = shutdownGraceMs;
|
|
50
|
-
this.name = 'RuntimeHostProcessTerminationRequiredError';
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
46
|
export class RuntimeHostKernel {
|
|
54
47
|
hostEpoch = randomUUID();
|
|
55
48
|
closed;
|
|
@@ -17,11 +17,29 @@
|
|
|
17
17
|
* under the License.
|
|
18
18
|
*/
|
|
19
19
|
import { isDeepStrictEqual } from 'node:util';
|
|
20
|
+
import { DURABLE_TOOL_RESULT_PROJECTION_MAX_BYTES } from '@maka/core/durable-tool-result-projection';
|
|
20
21
|
import { readLogicalRuntimeExecution } from '@maka/core/runtime-logical-execution';
|
|
22
|
+
import { runtimeHandoffPause } from '@maka/core/runtime-handoff';
|
|
21
23
|
import { runtimeInvocationOutcome, } from '@maka/core/runtime-invocation';
|
|
22
24
|
import { messageContentsEqual, normalizeMessageContent, } from '@maka/core/events';
|
|
23
25
|
import { projectRuntimeEventUserMessage } from '@maka/runtime/runtime-event-read-model';
|
|
24
26
|
import { admittedPromptEventId, RuntimeMessageAuthorityInvariantError, } from '@maka/runtime/message-authority';
|
|
27
|
+
import { ROOT_TURN_ADMISSION_MAX_RECORD_BYTES, ROOT_TURN_ADMISSION_MAX_SOURCE_MESSAGES, } from '@maka/storage/execution-stores';
|
|
28
|
+
const RECOVERY_MESSAGE_EVIDENCE_MIN_RECORDS = 16;
|
|
29
|
+
const RECOVERY_MESSAGE_EVIDENCE_MAX_RECORDS = 65_536;
|
|
30
|
+
// One admission is capped at 1 MiB including the normalized prompt and every
|
|
31
|
+
// folded source. A second admission-sized allowance covers RuntimeEvent
|
|
32
|
+
// envelopes and the separately stored canonical prompt without inventing a
|
|
33
|
+
// smaller read ceiling than the write contract permits.
|
|
34
|
+
const RECOVERY_MESSAGE_EVIDENCE_BYTES_PER_ADMISSION = ROOT_TURN_ADMISSION_MAX_RECORD_BYTES * 2;
|
|
35
|
+
const RECOVERY_MESSAGE_EVIDENCE_MIN_BYTES = 2 * 1024 * 1024;
|
|
36
|
+
const RECOVERY_MESSAGE_EVIDENCE_MAX_BYTES = 256 * 1024 * 1024;
|
|
37
|
+
const RECOVERY_HANDOFF_PREFIX_PROOF_BUDGET = Object.freeze({
|
|
38
|
+
maxEvents: 65_536,
|
|
39
|
+
maxBytes: 256 * 1024 * 1024,
|
|
40
|
+
// A RuntimeEvent can carry both a raw Tool Result and its durable model projection.
|
|
41
|
+
maxRecordBytes: DURABLE_TOOL_RESULT_PROJECTION_MAX_BYTES * 2 + 256 * 1024,
|
|
42
|
+
});
|
|
25
43
|
/** Validates and repairs durable admission/message relationships before execution replay. */
|
|
26
44
|
export async function prepareHostedExecutionRecovery(input) {
|
|
27
45
|
// listHeaders() avoids listForRecovery()'s discarded per-Session message
|
|
@@ -29,25 +47,48 @@ export async function prepareHostedExecutionRecovery(input) {
|
|
|
29
47
|
// own RuntimeEvents: the ledger is where a Turn's user message is committed,
|
|
30
48
|
// so it is also the only place a missing one can be detected.
|
|
31
49
|
const sessions = await input.stores.sessionStore.listHeaders();
|
|
50
|
+
const logicalMembershipStore = {
|
|
51
|
+
listSessionInvocations: input.stores.runtimeEventStore.listSessionInvocations,
|
|
52
|
+
readRunInvocation: input.stores.runtimeEventStore.readRunInvocation,
|
|
53
|
+
readContinuationClaimStateByBoundary: input.stores.runtimeEventStore.readContinuationClaimStateByBoundary,
|
|
54
|
+
readImmutableRuntimePrefixProof: (proofInput) => input.stores.runtimeEventStore.readImmutableRuntimePrefixProof(proofInput, RECOVERY_HANDOFF_PREFIX_PROOF_BUDGET),
|
|
55
|
+
};
|
|
32
56
|
const prepared = [];
|
|
33
57
|
for (const session of sessions) {
|
|
34
58
|
const admissions = await input.rootAdmissions.recoverSession(session.id);
|
|
59
|
+
if (admissions.length === 0)
|
|
60
|
+
continue;
|
|
61
|
+
const pendingMessageIds = new Set((await input.stores.sessionStore.listMessageAdmissions(session.id)).map((admission) => admission.messageId));
|
|
35
62
|
const runs = await input.stores.runtimeEventStore.listSessionInvocations(session.id);
|
|
36
63
|
const runsById = new Map(runs.map((run) => [run.runId, run]));
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
64
|
+
const recoveryMessageEvidence = await input.stores.runtimeEventStore.readRecoveryMessageEvents({
|
|
65
|
+
sessionId: session.id,
|
|
66
|
+
turnIds: admissions.map((admission) => admission.turnId),
|
|
67
|
+
eventIds: admissions.flatMap((admission) => [
|
|
68
|
+
admittedPromptEventId(admission.runId, admission.userMessageId),
|
|
69
|
+
...admission.sourceMessages.map((source) => source.messageId),
|
|
70
|
+
]),
|
|
71
|
+
budget: recoveryMessageEvidenceBudget(admissions),
|
|
72
|
+
});
|
|
73
|
+
if (recoveryMessageEvidence.status === 'limit_exceeded') {
|
|
74
|
+
throw new RuntimeMessageAuthorityInvariantError(`Recovery message evidence exceeds the bounded read budget for Session ${session.id}`);
|
|
40
75
|
}
|
|
41
|
-
const messageIndex = indexRecoveryMessages(recoveryUserMessagesFromLedger(
|
|
76
|
+
const messageIndex = indexRecoveryMessages(recoveryUserMessagesFromLedger(recoveryMessageEvidence.records));
|
|
42
77
|
const replayAdmissions = [];
|
|
43
78
|
const rootReplayAdmissions = [];
|
|
44
79
|
const pendingRecoveryClosures = [];
|
|
80
|
+
const pendingHandoffRunIds = new Set();
|
|
45
81
|
for (const admission of admissions) {
|
|
46
82
|
const run = runsById.get(admission.runId);
|
|
47
|
-
const logical = run && (
|
|
83
|
+
const logical = run?.terminalEvent && runtimeHandoffPause(run.terminalEvent)
|
|
84
|
+
? await readLogicalRuntimeExecution(logicalMembershipStore, admission, run, {
|
|
85
|
+
mode: 'membership',
|
|
86
|
+
})
|
|
87
|
+
: undefined;
|
|
48
88
|
if (logical?.pendingHandoff) {
|
|
49
89
|
replayAdmissions.push(admission);
|
|
50
90
|
rootReplayAdmissions.push(admission);
|
|
91
|
+
pendingHandoffRunIds.add(admission.runId);
|
|
51
92
|
}
|
|
52
93
|
const admittedMessageId = admittedPromptEventId(admission.runId, admission.userMessageId);
|
|
53
94
|
// Whether the prompt is on the ledger is a question about the Turn, not
|
|
@@ -62,7 +103,7 @@ export async function prepareHostedExecutionRecovery(input) {
|
|
|
62
103
|
const messageIdOwner = messageIdOwners[0];
|
|
63
104
|
const executionContract = recoveryExecutionContract(admission.execution);
|
|
64
105
|
if (admission.execution.kind === 'scheduled_task' &&
|
|
65
|
-
(!
|
|
106
|
+
(!run || runtimeInvocationOutcome(logical?.tip ?? run) === undefined)) {
|
|
66
107
|
if (!input.assertScheduledTaskAdmission) {
|
|
67
108
|
throw new RuntimeMessageAuthorityInvariantError('ScheduledTask recovery admission has no canonical authority validator');
|
|
68
109
|
}
|
|
@@ -134,9 +175,21 @@ export async function prepareHostedExecutionRecovery(input) {
|
|
|
134
175
|
if (replayAdmissions[0] && session.isArchived) {
|
|
135
176
|
throw new Error(`Archived Session ${session.id} has an admitted Turn without a Run`);
|
|
136
177
|
}
|
|
178
|
+
const pendingRecoveryClosureTurnIds = new Set(pendingRecoveryClosures.map(({ admission }) => admission.turnId));
|
|
179
|
+
const rootRecoveryAdmissions = admissions.filter((admission) => {
|
|
180
|
+
const run = runsById.get(admission.runId);
|
|
181
|
+
if (!run) {
|
|
182
|
+
return (rootReplayAdmissions[0] === admission ||
|
|
183
|
+
pendingRecoveryClosureTurnIds.has(admission.turnId));
|
|
184
|
+
}
|
|
185
|
+
return (!run.terminalEvent ||
|
|
186
|
+
admission.sourceMessages.some((source) => pendingMessageIds.has(source.messageId)) ||
|
|
187
|
+
pendingHandoffRunIds.has(run.runId));
|
|
188
|
+
});
|
|
137
189
|
prepared.push({
|
|
138
190
|
sessionId: session.id,
|
|
139
191
|
admissions,
|
|
192
|
+
rootRecoveryAdmissions,
|
|
140
193
|
...(rootReplayAdmissions[0] ? { rootReplayAdmission: rootReplayAdmissions[0] } : {}),
|
|
141
194
|
pendingRecoveryClosures,
|
|
142
195
|
});
|
|
@@ -165,11 +218,13 @@ export async function prepareHostedExecutionRecovery(input) {
|
|
|
165
218
|
});
|
|
166
219
|
}
|
|
167
220
|
}
|
|
168
|
-
return prepared
|
|
221
|
+
return prepared
|
|
222
|
+
.map(({ sessionId, rootRecoveryAdmissions, rootReplayAdmission }) => ({
|
|
169
223
|
sessionId,
|
|
170
|
-
admissions,
|
|
224
|
+
admissions: rootRecoveryAdmissions,
|
|
171
225
|
...(rootReplayAdmission ? { rootReplayAdmission } : {}),
|
|
172
|
-
}))
|
|
226
|
+
}))
|
|
227
|
+
.filter((plan) => plan.admissions.length > 0 || plan.rootReplayAdmission !== undefined);
|
|
173
228
|
}
|
|
174
229
|
/**
|
|
175
230
|
* The message a crashed Turn was admitted with, written into the Run that had
|
|
@@ -221,6 +276,8 @@ export function requireHostedExecutionMessageContent(admission) {
|
|
|
221
276
|
}
|
|
222
277
|
export function hostedExecutionMessageOrigin(execution) {
|
|
223
278
|
switch (execution.kind) {
|
|
279
|
+
case 'workhub_coordination':
|
|
280
|
+
return execution.feedback;
|
|
224
281
|
case 'scheduled_task':
|
|
225
282
|
return {
|
|
226
283
|
kind: 'scheduled_task',
|
|
@@ -376,6 +433,15 @@ function appendIndexed(index, key, value) {
|
|
|
376
433
|
else
|
|
377
434
|
index.set(key, [value]);
|
|
378
435
|
}
|
|
436
|
+
function recoveryMessageEvidenceBudget(admissions) {
|
|
437
|
+
const citedEventIds = admissions.reduce((count, admission) => count +
|
|
438
|
+
1 +
|
|
439
|
+
Math.min(admission.sourceMessages.length, ROOT_TURN_ADMISSION_MAX_SOURCE_MESSAGES), 0);
|
|
440
|
+
return {
|
|
441
|
+
maxRecords: Math.min(RECOVERY_MESSAGE_EVIDENCE_MAX_RECORDS, Math.max(RECOVERY_MESSAGE_EVIDENCE_MIN_RECORDS, admissions.length * 2 + citedEventIds)),
|
|
442
|
+
maxBytes: Math.min(RECOVERY_MESSAGE_EVIDENCE_MAX_BYTES, Math.max(RECOVERY_MESSAGE_EVIDENCE_MIN_BYTES, admissions.length * RECOVERY_MESSAGE_EVIDENCE_BYTES_PER_ADMISSION)),
|
|
443
|
+
};
|
|
444
|
+
}
|
|
379
445
|
function assertNever(value) {
|
|
380
446
|
throw new Error(`Unsupported root execution descriptor: ${JSON.stringify(value)}`);
|
|
381
447
|
}
|