maka-agent 0.2.0-dev.76.20261009 → 0.2.0-dev.77.20261009
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/README.md +1 -1
- package/README.zh-CN.md +1 -1
- package/native/runtime-host-windows-task-launcher/prebuilds/win32-x64/maka-runtime-host-task-launcher.exe +0 -0
- package/node_modules/@maka/runtime/dist/agent-graph-supervisor-wake.js +115 -17
- package/node_modules/@maka/runtime/dist/agent-run.js +11 -0
- package/node_modules/@maka/runtime/dist/computer-use-observation-text.js +22 -0
- package/node_modules/@maka/runtime/dist/conversation-copy-agent-output.js +227 -0
- package/node_modules/@maka/runtime/dist/conversation-copy.js +176 -46
- package/node_modules/@maka/runtime/dist/filesystem-worker/resource-resolver.js +3 -1
- package/node_modules/@maka/runtime/dist/owned-child-process.js +209 -0
- package/node_modules/@maka/runtime/dist/owned-process-main.js +183 -0
- package/node_modules/@maka/runtime/dist/pipe-process-driver.js +19 -25
- package/node_modules/@maka/runtime/dist/runtime-kernel.js +124 -3
- package/node_modules/@maka/runtime/dist/session-manager.js +125 -12
- package/node_modules/@maka/runtime/dist/shell-exec.js +18 -20
- package/node_modules/@maka/runtime/dist/shell-run-manager.js +2 -1
- package/node_modules/@maka/runtime/dist/stream-graph-coordinator.js +279 -8
- package/node_modules/@maka/runtime/dist/stream-graph-schedule-reconcile.js +209 -37
- package/node_modules/@maka/runtime/dist/tool-availability.js +37 -6
- package/node_modules/@maka/runtime/dist/tool-runtime.js +2 -1
- package/node_modules/@maka/runtime-host/dist/client/reconnect-lifecycle.js +44 -13
- package/node_modules/@maka/runtime-host/dist/client/session-catalog-summary.js +6 -0
- package/node_modules/@maka/runtime-host/dist/client/wsl-environment.js +4 -0
- package/node_modules/@maka/runtime-host/dist/protocol/index.js +4 -1
- package/node_modules/@maka/runtime-host/dist/protocol/session-catalog.js +46 -9
- package/node_modules/@maka/runtime-host/dist/server/candidate.js +47 -40
- package/node_modules/@maka/runtime-host/dist/server/execution-composition.js +70 -24
- package/node_modules/@maka/runtime-host/dist/server/execution-service.js +5 -1
- package/node_modules/@maka/runtime-host/dist/server/root-turn-coordinator.js +41 -5
- package/node_modules/@maka/runtime-host/dist/server/scheduled-task-coordinator.js +20 -3
- package/node_modules/@maka/runtime-host/dist/server/session-background-activity.js +71 -0
- package/node_modules/@maka/runtime-host/dist/server/session-catalog-coordinator.js +8 -4
- package/node_modules/@maka/runtime-host/dist/server/session-interaction-activity.js +78 -0
- package/node_modules/@maka/runtime-host/dist/server/session-retirement-coordinator.js +56 -0
- package/node_modules/@maka/runtime-host/dist/server/session-revision-graph-references.js +16 -2
- package/node_modules/@maka/runtime-host/dist/server/workhub-result-runtime.js +3 -1
- package/node_modules/@maka/storage/dist/context-offload-store.js +8 -3
- package/node_modules/@maka/storage/dist/session-bundle-policy.js +54 -19
- package/package.json +2 -2
- /package/node_modules/@maka/runtime/dist/workers/{filesystem-worker.js → filesystem-worker.mjs} +0 -0
|
@@ -148,6 +148,7 @@ export class HostSessionCatalogCoordinator {
|
|
|
148
148
|
#runtimePolicy;
|
|
149
149
|
#manager;
|
|
150
150
|
#isTurnBusy;
|
|
151
|
+
#readBackgroundActivity;
|
|
151
152
|
#admission;
|
|
152
153
|
#continuity;
|
|
153
154
|
#workspaceResolver;
|
|
@@ -162,6 +163,7 @@ export class HostSessionCatalogCoordinator {
|
|
|
162
163
|
this.#runtimePolicy = options.runtimePolicy;
|
|
163
164
|
this.#manager = options.manager;
|
|
164
165
|
this.#isTurnBusy = options.isTurnBusy;
|
|
166
|
+
this.#readBackgroundActivity = options.readBackgroundActivity;
|
|
165
167
|
this.#admission = options.admission;
|
|
166
168
|
this.#continuity = options.continuity;
|
|
167
169
|
this.#workspaceResolver = options.workspaceResolver;
|
|
@@ -305,7 +307,7 @@ export class HostSessionCatalogCoordinator {
|
|
|
305
307
|
ok: true,
|
|
306
308
|
result: {
|
|
307
309
|
session: record
|
|
308
|
-
? projectSharedSessionCatalogRecord(record, projectCatalogLiveRunState(this.#manager.runningTurnIds(record.header.id), this.#manager.sessionRunEpoch(record.header.id), this.#manager.sessionHostGeneration()))
|
|
310
|
+
? projectSharedSessionCatalogRecord(record, projectCatalogLiveRunState(this.#manager.runningTurnIds(record.header.id), this.#manager.sessionRunEpoch(record.header.id), this.#manager.sessionHostGeneration()), this.#readBackgroundActivity?.(record.header.id))
|
|
309
311
|
: null,
|
|
310
312
|
},
|
|
311
313
|
};
|
|
@@ -318,7 +320,7 @@ export class HostSessionCatalogCoordinator {
|
|
|
318
320
|
}
|
|
319
321
|
}
|
|
320
322
|
#projectCatalogQueryRecord(record) {
|
|
321
|
-
return projectSessionCatalogRecord(record, projectCatalogLiveRunState(this.#manager.runningTurnIds(record.header.id), this.#manager.sessionRunEpoch(record.header.id), this.#manager.sessionHostGeneration()));
|
|
323
|
+
return projectSessionCatalogRecord(record, projectCatalogLiveRunState(this.#manager.runningTurnIds(record.header.id), this.#manager.sessionRunEpoch(record.header.id), this.#manager.sessionHostGeneration()), this.#readBackgroundActivity?.(record.header.id));
|
|
322
324
|
}
|
|
323
325
|
async #queryExecutionBoundary(input) {
|
|
324
326
|
try {
|
|
@@ -1121,7 +1123,7 @@ function createRequestFingerprint(input, prepared) {
|
|
|
1121
1123
|
];
|
|
1122
1124
|
return `sha256:${createHash('sha256').update(JSON.stringify(identity)).digest('hex')}`;
|
|
1123
1125
|
}
|
|
1124
|
-
export function projectSessionCatalogRecord(record, liveRunState) {
|
|
1126
|
+
export function projectSessionCatalogRecord(record, liveRunState, backgroundActivity) {
|
|
1125
1127
|
const { header, summary } = record;
|
|
1126
1128
|
const projectedLabels = projectCatalogLabels(header.labels);
|
|
1127
1129
|
const projection = {
|
|
@@ -1156,6 +1158,7 @@ export function projectSessionCatalogRecord(record, liveRunState) {
|
|
|
1156
1158
|
: { lastMessagePreview: summary.lastMessagePreview }),
|
|
1157
1159
|
status: header.status,
|
|
1158
1160
|
...(liveRunState === undefined ? {} : { liveRunState }),
|
|
1161
|
+
...(backgroundActivity === undefined ? {} : backgroundActivity),
|
|
1159
1162
|
...(header.blockedReason === undefined ? {} : { blockedReason: header.blockedReason }),
|
|
1160
1163
|
...(header.statusUpdatedAt === undefined ? {} : { statusUpdatedAt: header.statusUpdatedAt }),
|
|
1161
1164
|
...(header.parentSessionId === undefined ? {} : { parentSessionId: header.parentSessionId }),
|
|
@@ -1215,7 +1218,7 @@ export function projectSessionCatalogRecord(record, liveRunState) {
|
|
|
1215
1218
|
};
|
|
1216
1219
|
}
|
|
1217
1220
|
}
|
|
1218
|
-
function projectSharedSessionCatalogRecord(record, liveRunState) {
|
|
1221
|
+
function projectSharedSessionCatalogRecord(record, liveRunState, backgroundActivity) {
|
|
1219
1222
|
const { header, summary } = record;
|
|
1220
1223
|
const shared = {
|
|
1221
1224
|
kind: 'shared_session',
|
|
@@ -1230,6 +1233,7 @@ function projectSharedSessionCatalogRecord(record, liveRunState) {
|
|
|
1230
1233
|
: { lastMessagePreview: summary.lastMessagePreview }),
|
|
1231
1234
|
status: header.status,
|
|
1232
1235
|
...(liveRunState === undefined ? {} : { liveRunState }),
|
|
1236
|
+
...(backgroundActivity === undefined ? {} : backgroundActivity),
|
|
1233
1237
|
...(header.blockedReason === undefined ? {} : { blockedReason: header.blockedReason }),
|
|
1234
1238
|
...(header.statusUpdatedAt === undefined ? {} : { statusUpdatedAt: header.statusUpdatedAt }),
|
|
1235
1239
|
};
|
|
@@ -0,0 +1,78 @@
|
|
|
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
|
+
/**
|
|
20
|
+
* Process-local read projection of the canonical pending requests. Refreshes run
|
|
21
|
+
* under the Interaction coordinator's Session admission, including withdrawals
|
|
22
|
+
* that have no Runtime answer event. Catalog reads never query these stores.
|
|
23
|
+
*/
|
|
24
|
+
export class SessionInteractionActivityProjection {
|
|
25
|
+
sources;
|
|
26
|
+
#counts = new Map();
|
|
27
|
+
constructor(sources) {
|
|
28
|
+
this.sources = sources;
|
|
29
|
+
}
|
|
30
|
+
readTurnPendingInteractionCount(sessionId, turnId) {
|
|
31
|
+
const counts = this.#counts.get(sessionId);
|
|
32
|
+
return counts ? (counts.get(turnId) ?? 0) : undefined;
|
|
33
|
+
}
|
|
34
|
+
async refresh(sessionId) {
|
|
35
|
+
try {
|
|
36
|
+
await this.#refresh(sessionId);
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
// This is presentation state, not canonical authority. Failed reads must
|
|
40
|
+
// neither retain authoritative counts nor prevent an answer from applying.
|
|
41
|
+
const invalidated = this.#counts.delete(sessionId);
|
|
42
|
+
try {
|
|
43
|
+
if (invalidated)
|
|
44
|
+
this.sources.onChanged(sessionId);
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
// A catalog observer cannot gate canonical continuity either.
|
|
48
|
+
}
|
|
49
|
+
try {
|
|
50
|
+
this.sources.onError(sessionId, error);
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
// Diagnostics must not turn a presentation failure into an authority failure.
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
async #refresh(sessionId) {
|
|
58
|
+
const [interactions, boundaries] = await Promise.all([
|
|
59
|
+
this.sources.interactions.listSessionPending(sessionId),
|
|
60
|
+
this.sources.sandboxBoundaries.listPendingSandboxBoundaryRequests(sessionId),
|
|
61
|
+
]);
|
|
62
|
+
const counts = new Map();
|
|
63
|
+
for (const request of [...interactions, ...boundaries]) {
|
|
64
|
+
// Handoffs replace the physical run id while retaining this logical Turn.
|
|
65
|
+
// A new graph activation has a different Turn and cannot inherit its wait.
|
|
66
|
+
if (request.turnId === undefined)
|
|
67
|
+
continue;
|
|
68
|
+
counts.set(request.turnId, (counts.get(request.turnId) ?? 0) + 1);
|
|
69
|
+
}
|
|
70
|
+
const previous = this.#counts.get(sessionId);
|
|
71
|
+
if (previous?.size === counts.size &&
|
|
72
|
+
[...counts].every(([turnId, count]) => previous.get(turnId) === count)) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
this.#counts.set(sessionId, counts);
|
|
76
|
+
this.sources.onChanged(sessionId);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
@@ -23,6 +23,8 @@ import { HostScheduledTaskSessionBusyError, } from './scheduled-task-coordinator
|
|
|
23
23
|
import { projectSessionCatalogRecord } from './session-catalog-coordinator.js';
|
|
24
24
|
import { purgeSessionSidecars } from './session-sidecar-purge.js';
|
|
25
25
|
const FAMILY_STABILIZATION_ATTEMPTS = 4;
|
|
26
|
+
/** The store rejects a WorkHub target batch above its own bound; page below it. */
|
|
27
|
+
const WORKHUB_ASSIGNMENT_TARGET_PAGE = 256;
|
|
26
28
|
class RetryFamilyResolution extends Error {
|
|
27
29
|
sessionIds;
|
|
28
30
|
name = 'RetryFamilyResolution';
|
|
@@ -66,6 +68,7 @@ export class HostSessionRetirementCoordinator {
|
|
|
66
68
|
#root;
|
|
67
69
|
#messages;
|
|
68
70
|
#interactions;
|
|
71
|
+
#workHub;
|
|
69
72
|
#goals;
|
|
70
73
|
#scheduledTasks;
|
|
71
74
|
#resources;
|
|
@@ -95,6 +98,7 @@ export class HostSessionRetirementCoordinator {
|
|
|
95
98
|
this.#root = options.root;
|
|
96
99
|
this.#messages = options.messages;
|
|
97
100
|
this.#interactions = options.interactions;
|
|
101
|
+
this.#workHub = options.workHub;
|
|
98
102
|
this.#goals = options.goals;
|
|
99
103
|
this.#scheduledTasks = options.scheduledTasks;
|
|
100
104
|
this.#resources = options.resources;
|
|
@@ -150,6 +154,7 @@ export class HostSessionRetirementCoordinator {
|
|
|
150
154
|
let handles;
|
|
151
155
|
let committed = false;
|
|
152
156
|
try {
|
|
157
|
+
await this.#assertNoLiveRelationships(family);
|
|
153
158
|
handles = await this.#prepareRetirement(family, 'archive');
|
|
154
159
|
await this.#finalizeWorkspacePatches(family.sessionIds);
|
|
155
160
|
await this.#disposeBackends(family.sessionIds);
|
|
@@ -563,6 +568,57 @@ export class HostSessionRetirementCoordinator {
|
|
|
563
568
|
expectedVersion: record.revision,
|
|
564
569
|
})), true);
|
|
565
570
|
}
|
|
571
|
+
/**
|
|
572
|
+
* A manual archive must not hide a Session that a WorkHub delegation or a
|
|
573
|
+
* linked child still points at: WorkHub candidate and result views exclude
|
|
574
|
+
* archived Sessions, so either relationship would lose its visible target.
|
|
575
|
+
* "Live" means the relationship is still in flight — the delegation's
|
|
576
|
+
* execution has not retired (or its result has not been delivered), or the
|
|
577
|
+
* child still carries active work. A finished delegation and a finished
|
|
578
|
+
* subtask hold nothing visible hostage, so they no longer block the archive.
|
|
579
|
+
* This guards the manual archive path only — a removal retires or archives
|
|
580
|
+
* the whole relationship set under its own confirm.
|
|
581
|
+
*/
|
|
582
|
+
async #assertNoLiveRelationships(family) {
|
|
583
|
+
const familyIds = new Set(family.sessionIds);
|
|
584
|
+
for (let offset = 0; offset < family.sessionIds.length; offset += WORKHUB_ASSIGNMENT_TARGET_PAGE) {
|
|
585
|
+
const page = family.sessionIds.slice(offset, offset + WORKHUB_ASSIGNMENT_TARGET_PAGE);
|
|
586
|
+
// The ledger keeps every live delegation of a target, newest first, so a
|
|
587
|
+
// finished newest delegation must not hide an older one that is still in
|
|
588
|
+
// flight or still owes WorkHub its result.
|
|
589
|
+
const assignments = await this.#stores.readActiveWorkHubAssignmentsByTarget(page);
|
|
590
|
+
for (const assignment of assignments) {
|
|
591
|
+
// The Coordination ledger keeps a delegation row until it is superseded
|
|
592
|
+
// or stopped, so the row alone says nothing about the work: read the
|
|
593
|
+
// delegation's execution state the same way WorkHub actions do.
|
|
594
|
+
const retirement = await this.#workHub.readDelegationRetirement(assignment, family.admission);
|
|
595
|
+
if (retirement !== 'retired') {
|
|
596
|
+
throw new SessionRetirementBusyError(`Session ${assignment.targetSessionId} has an active WorkHub delegation`);
|
|
597
|
+
}
|
|
598
|
+
if (await this.#workHub.hasUndeliveredResult(assignment, family.admission)) {
|
|
599
|
+
throw new SessionRetirementBusyError(`Session ${assignment.targetSessionId} has an undelivered WorkHub result`);
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
for (const header of await this.#stores.listHeaders()) {
|
|
604
|
+
const parent = header.subagentParent;
|
|
605
|
+
if (parent === undefined || parent.graph !== undefined)
|
|
606
|
+
continue;
|
|
607
|
+
if (!familyIds.has(parent.parentSessionId))
|
|
608
|
+
continue;
|
|
609
|
+
if (header.conversationCopy?.state === 'preparing' || header.isArchived)
|
|
610
|
+
continue;
|
|
611
|
+
if (await this.#hasLiveChildWork(header.id)) {
|
|
612
|
+
throw new SessionRetirementBusyError(`Session ${parent.parentSessionId} has a live linked child Session`);
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
/** The in-flight signals that make a linked child worth keeping visible. */
|
|
617
|
+
async #hasLiveChildWork(sessionId) {
|
|
618
|
+
return (this.#root.readRootState(sessionId).kind !== 'idle' ||
|
|
619
|
+
this.#messages.hasLiveSessionState(sessionId) ||
|
|
620
|
+
(await this.#interactions.hasPendingSession(sessionId)));
|
|
621
|
+
}
|
|
566
622
|
async #prepareRetirement(family, kind) {
|
|
567
623
|
for (const sessionId of family.sessionIds) {
|
|
568
624
|
if (this.#root.readRootState(sessionId).kind !== 'idle') {
|
|
@@ -88,6 +88,7 @@ export async function prepareLinkedChildCopyReferences(input, dependencies) {
|
|
|
88
88
|
const shared = new Map();
|
|
89
89
|
const snapshots = new Map();
|
|
90
90
|
const runsByChildSession = new Map();
|
|
91
|
+
const terminalResults = new Set(requests.filter((request) => isTerminalRunStatus(request.status)).map(linkedRunKey));
|
|
91
92
|
for (const request of requests) {
|
|
92
93
|
const childSessionId = request.childSessionId;
|
|
93
94
|
const child = headersById.get(childSessionId);
|
|
@@ -95,13 +96,21 @@ export async function prepareLinkedChildCopyReferences(input, dependencies) {
|
|
|
95
96
|
if (!child ||
|
|
96
97
|
!parent ||
|
|
97
98
|
!familySessionIds.has(parent.parentSessionId) ||
|
|
99
|
+
(request.graph !== undefined &&
|
|
100
|
+
(request.graph.graphId !== parent.graph?.graphId ||
|
|
101
|
+
request.graph.workId !== parent.graph?.workId ||
|
|
102
|
+
request.graph.operatorId !== parent.graph?.operatorId)) ||
|
|
98
103
|
!retainedTurnIds.has(parent.spawnedBy.parentTurnId)) {
|
|
99
104
|
return failure('operation_unavailable', 'Linked child reference does not belong to the source revision family');
|
|
100
105
|
}
|
|
101
106
|
if (dependencies.isSessionActive(childSessionId)) {
|
|
102
107
|
return failure('session_busy', 'A retained linked child is still active');
|
|
103
108
|
}
|
|
104
|
-
|
|
109
|
+
// A poll describes the run at read time. It may precede a retained terminal
|
|
110
|
+
// result for that exact run, but cannot borrow one from another execution.
|
|
111
|
+
// Keep validating every observation, including its Artifact references.
|
|
112
|
+
const terminalResult = isTerminalRunStatus(request.status);
|
|
113
|
+
if (!terminalResult && !terminalResults.has(linkedRunKey(request))) {
|
|
105
114
|
return failure('session_busy', 'A retained linked child result is not terminal');
|
|
106
115
|
}
|
|
107
116
|
let runsById = runsByChildSession.get(childSessionId);
|
|
@@ -126,7 +135,9 @@ export async function prepareLinkedChildCopyReferences(input, dependencies) {
|
|
|
126
135
|
if (!currentRun ||
|
|
127
136
|
currentRun.sessionId !== childSessionId ||
|
|
128
137
|
currentRun.turnId !== request.turnId ||
|
|
129
|
-
|
|
138
|
+
(request.terminalEventId !== undefined &&
|
|
139
|
+
request.terminalEventId !== currentRun.terminalEvent?.id) ||
|
|
140
|
+
(terminalResult && !linkedResultStatusMatchesRun(request, currentRun))) {
|
|
130
141
|
return failure('operation_unavailable', 'Retained linked child run reference is unavailable');
|
|
131
142
|
}
|
|
132
143
|
const lineage = traceChildRunLineage(currentRun, runsById, childSessionId);
|
|
@@ -166,6 +177,9 @@ export async function prepareLinkedChildCopyReferences(input, dependencies) {
|
|
|
166
177
|
}
|
|
167
178
|
return { ok: true, shared, snapshots };
|
|
168
179
|
}
|
|
180
|
+
function linkedRunKey(reference) {
|
|
181
|
+
return JSON.stringify([reference.childSessionId, reference.runId, reference.turnId]);
|
|
182
|
+
}
|
|
169
183
|
export function linkedChildCopyAdmissionSessionIds(input) {
|
|
170
184
|
const retainedTurnIds = new Set(input.copyTurnIds);
|
|
171
185
|
const sessionIds = new Set(input.requests.map((request) => request.childSessionId));
|
|
@@ -289,5 +289,7 @@ export function createWorkHubResultRuntime(options) {
|
|
|
289
289
|
return { status: outcome.result.status, targetSessionId: assignment.targetSessionId };
|
|
290
290
|
},
|
|
291
291
|
};
|
|
292
|
-
|
|
292
|
+
// Exposed for the archive guard: the receipt read needs the same observation
|
|
293
|
+
// (and therefore the same event identity) delivery itself is keyed on.
|
|
294
|
+
return { coordinator, tool, notify, inspect };
|
|
293
295
|
}
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
* under the License.
|
|
18
18
|
*/
|
|
19
19
|
import { join } from 'node:path';
|
|
20
|
-
import { assertStorageRootLease, runWithStorageRootLease, StorageRootAuthorityError, } from './root-authority.js';
|
|
20
|
+
import { assertStorageRootLease, assertStorageRootLeaseActive, runWithStorageRootLease, StorageRootAuthorityError, } from './root-authority.js';
|
|
21
21
|
import { CONTEXT_OFFLOAD_DATABASE_NAME, SqliteContextOffloadStore, } from './sqlite-context-offload-store.js';
|
|
22
22
|
const writerBrand = Symbol('InteractiveContextOffloadWriter');
|
|
23
23
|
const readerBrand = Symbol('InteractiveContextOffloadReader');
|
|
@@ -63,11 +63,16 @@ export function createInteractiveContextOffloadReader(writer) {
|
|
|
63
63
|
export async function openInteractiveContextOffloadStoreForWrite(lease, options) {
|
|
64
64
|
const limits = snapshotLimits(options.limits);
|
|
65
65
|
const limitsKey = serializeLimits(limits);
|
|
66
|
-
|
|
66
|
+
// Claim or join the per-lease slot before the first await so the earliest caller binds
|
|
67
|
+
// the limits; the on-disk root identity checks of concurrent callers finish in no fixed order.
|
|
68
|
+
assertStorageRootLeaseActive(lease, 'interactive', 'write');
|
|
67
69
|
const existing = writerByLease.get(lease);
|
|
68
70
|
if (existing) {
|
|
69
71
|
assertSameLimits(existing.limitsKey, limitsKey);
|
|
70
|
-
|
|
72
|
+
await assertStorageRootLease(lease, 'interactive', 'write');
|
|
73
|
+
if (writerByLease.get(lease) === existing)
|
|
74
|
+
return existing.writer;
|
|
75
|
+
return openInteractiveContextOffloadStoreForWrite(lease, { limits });
|
|
71
76
|
}
|
|
72
77
|
const opening = writerOpeningByLease.get(lease);
|
|
73
78
|
if (opening) {
|
|
@@ -490,6 +490,15 @@ const SESSION_LINK_COLUMNS = [
|
|
|
490
490
|
* derivation changes.
|
|
491
491
|
*/
|
|
492
492
|
const TRIGGER_MAINTAINED_TABLES = new Set(['session_catalog_projection']);
|
|
493
|
+
// These are database-local ordering keys, not portable identities or references.
|
|
494
|
+
// Keep this semantic policy explicit: other sequence columns belong to Sessions,
|
|
495
|
+
// invocations or streams and must retain their values. A schema-derived test in
|
|
496
|
+
// session-bundle-policy.test.ts fails when a copied table keyed by a single
|
|
497
|
+
// INTEGER column is neither listed here nor allow-listed there.
|
|
498
|
+
const LOCAL_SEQUENCE_COLUMNS = new Map([
|
|
499
|
+
['tool_journal_events', 'journal_seq'],
|
|
500
|
+
['message_admissions', 'sequence'],
|
|
501
|
+
]);
|
|
493
502
|
const PORTABLE_GLOBAL_TABLES = new Set([
|
|
494
503
|
'operational_schema_migrations',
|
|
495
504
|
'session_metadata_schema',
|
|
@@ -974,29 +983,55 @@ function mergeBundleDatabase(lease, bundleDatabasePath) {
|
|
|
974
983
|
target.exec('DETACH DATABASE bundle');
|
|
975
984
|
}
|
|
976
985
|
}
|
|
986
|
+
/**
|
|
987
|
+
* The tables an import copies from the database attached as `bundle`, in the
|
|
988
|
+
* order it copies them.
|
|
989
|
+
*
|
|
990
|
+
* The merge writes exactly these, and a schema-derived test reads the same
|
|
991
|
+
* list, so the two cannot disagree about which tables are copied.
|
|
992
|
+
*/
|
|
993
|
+
export function listSessionBundleMergeTables(target) {
|
|
994
|
+
const tables = target
|
|
995
|
+
.prepare("SELECT name FROM bundle.sqlite_master WHERE type = 'table' AND name NOT LIKE 'sqlite_%' ORDER BY name")
|
|
996
|
+
.all();
|
|
997
|
+
const merged = [];
|
|
998
|
+
for (const row of tables) {
|
|
999
|
+
const name = row.name;
|
|
1000
|
+
if (typeof name !== 'string' ||
|
|
1001
|
+
PORTABLE_GLOBAL_TABLES.has(name) ||
|
|
1002
|
+
TRIGGER_MAINTAINED_TABLES.has(name)) {
|
|
1003
|
+
continue;
|
|
1004
|
+
}
|
|
1005
|
+
// Mirror the export's own classification instead of trusting that it
|
|
1006
|
+
// ran: a table with no Session column and no referential rule describes
|
|
1007
|
+
// the WORKSPACE, and the target has its own. The export empties those,
|
|
1008
|
+
// so in practice this inserts nothing -- but an import that depends on
|
|
1009
|
+
// the other side having tidied up is one bundle away from writing a
|
|
1010
|
+
// workspace singleton into somebody else's workspace.
|
|
1011
|
+
if (!describesASession(target, name))
|
|
1012
|
+
continue;
|
|
1013
|
+
const localSequenceColumn = LOCAL_SEQUENCE_COLUMNS.get(name);
|
|
1014
|
+
merged.push(localSequenceColumn === undefined ? { name } : { name, localSequenceColumn });
|
|
1015
|
+
}
|
|
1016
|
+
return merged;
|
|
1017
|
+
}
|
|
977
1018
|
function mergeAttachedBundle(target) {
|
|
978
1019
|
{
|
|
979
1020
|
{
|
|
980
|
-
const
|
|
981
|
-
|
|
982
|
-
.
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
1021
|
+
for (const table of listSessionBundleMergeTables(target)) {
|
|
1022
|
+
const quoted = quoteIdentifier(table.name);
|
|
1023
|
+
const localSequence = table.localSequenceColumn;
|
|
1024
|
+
if (localSequence) {
|
|
1025
|
+
const columns = target.prepare(`PRAGMA bundle.table_info(${quoted})`).all()
|
|
1026
|
+
.filter((column) => column.name !== localSequence)
|
|
1027
|
+
.map((column) => quoteIdentifier(column.name))
|
|
1028
|
+
.join(', ');
|
|
1029
|
+
// Let SQLite allocate target-local values while retaining source order.
|
|
1030
|
+
target.exec(`INSERT INTO main.${quoted} (${columns}) SELECT ${columns} FROM bundle.${quoted} ORDER BY ${quoteIdentifier(localSequence)}`);
|
|
1031
|
+
}
|
|
1032
|
+
else {
|
|
1033
|
+
target.exec(`INSERT INTO main.${quoted} SELECT * FROM bundle.${quoted}`);
|
|
989
1034
|
}
|
|
990
|
-
// Mirror the export's own classification instead of trusting that it
|
|
991
|
-
// ran: a table with no Session column and no referential rule describes
|
|
992
|
-
// the WORKSPACE, and the target has its own. The export empties those,
|
|
993
|
-
// so in practice this inserts nothing -- but an import that depends on
|
|
994
|
-
// the other side having tidied up is one bundle away from writing a
|
|
995
|
-
// workspace singleton into somebody else's workspace.
|
|
996
|
-
if (!describesASession(target, name))
|
|
997
|
-
continue;
|
|
998
|
-
const quoted = quoteIdentifier(name);
|
|
999
|
-
target.exec(`INSERT INTO main.${quoted} SELECT * FROM bundle.${quoted}`);
|
|
1000
1035
|
}
|
|
1001
1036
|
// An archived Session arrives with the archive time (or no time) of the
|
|
1002
1037
|
// machine it left. Archive retention counts from that time, so an import
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "maka-agent",
|
|
3
|
-
"version": "0.2.0-dev.
|
|
3
|
+
"version": "0.2.0-dev.77.20261009",
|
|
4
4
|
"description": "Apache Maka (Incubating) developer snapshot; not an Apache release.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"managedRuntimeHostUpdateCompatibility": 1
|
|
13
13
|
},
|
|
14
14
|
"engines": {
|
|
15
|
-
"node": "
|
|
15
|
+
"node": "^22.19.0 || >=24.0.0"
|
|
16
16
|
},
|
|
17
17
|
"repository": {
|
|
18
18
|
"type": "git",
|
/package/node_modules/@maka/runtime/dist/workers/{filesystem-worker.js → filesystem-worker.mjs}
RENAMED
|
File without changes
|