gestalt-mobile 0.71.1 → 0.71.2
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/server/server/composition.js +6 -1
- package/dist/server/server/features/autopilot/application/takeover-supervision.js +18 -5
- package/dist/server/server/features/sessions/application/runtime-release-store.js +6 -0
- package/dist/server/server/platform/codex/session-runtime.js +53 -11
- package/dist/server/server/platform/persistence/migrate.js +1 -0
- package/dist/server/server/platform/persistence/sqlite-runtime-release-store.js +27 -0
- package/package.json +1 -1
|
@@ -73,6 +73,7 @@ import { RelaySession, } from './features/sessions/model/relay-session.js';
|
|
|
73
73
|
import { AgentActivityRegistry, } from './features/agent-activity/registry.js';
|
|
74
74
|
import { SupervisionTakeover } from './features/autopilot/application/takeover-supervision.js';
|
|
75
75
|
import { SqliteSupervisionTakeoverStore } from './platform/persistence/sqlite-supervision-takeover-store.js';
|
|
76
|
+
import { SqliteRuntimeReleaseStore } from './platform/persistence/sqlite-runtime-release-store.js';
|
|
76
77
|
import { isOrgPlanTakeoverCall } from '../shared/contracts/org-plan-takeover.js';
|
|
77
78
|
import { WriterAcquisitionError } from './features/sessions/application/writer-acquisition.js';
|
|
78
79
|
import { toAgentActivityDto } from './features/agent-activity/activity-dto.js';
|
|
@@ -876,6 +877,10 @@ export async function composeRelayApp(options) {
|
|
|
876
877
|
autopilot.planStatusChanged(id);
|
|
877
878
|
autopilot.restore(id);
|
|
878
879
|
},
|
|
880
|
+
failed: (sessionId, boundary) => {
|
|
881
|
+
const now = new Date().toISOString();
|
|
882
|
+
events.publish(journal.append(sessionId, 'autopilot.takeover-failed', { kind: boundary }, now));
|
|
883
|
+
},
|
|
879
884
|
});
|
|
880
885
|
const providerRecovery = new SessionProviderRecovery({
|
|
881
886
|
find: (id) => sessions.find(id),
|
|
@@ -1473,7 +1478,7 @@ export async function composeRelayApp(options) {
|
|
|
1473
1478
|
await runtime.validateExecutorPolicy(sessionId, report.requested);
|
|
1474
1479
|
assertCurrent();
|
|
1475
1480
|
return { ...report.requested, assertCurrent };
|
|
1476
|
-
}, sessionScratch)
|
|
1481
|
+
}, sessionScratch, new SqliteRuntimeReleaseStore(database))
|
|
1477
1482
|
: null;
|
|
1478
1483
|
const handleKimiNotification = (sessionId, event) => {
|
|
1479
1484
|
const occurredAt = new Date().toISOString();
|
|
@@ -19,10 +19,18 @@ export class SupervisionTakeover {
|
|
|
19
19
|
const prior = this.running.get(sessionId);
|
|
20
20
|
if (prior)
|
|
21
21
|
return prior;
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}))
|
|
22
|
+
let boundary = 'context';
|
|
23
|
+
const run = this.run(sessionId, threadId, turnId, (value) => {
|
|
24
|
+
boundary = value;
|
|
25
|
+
}).catch(() => {
|
|
26
|
+
try {
|
|
27
|
+
this.deps.failed?.(sessionId, boundary);
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
/* diagnostics must not change the takeover result */
|
|
31
|
+
}
|
|
32
|
+
return { accepted: false, code: 'TAKEOVER_RUNTIME_UNAVAILABLE', boundary };
|
|
33
|
+
});
|
|
26
34
|
this.running.set(sessionId, run);
|
|
27
35
|
void run.finally(() => {
|
|
28
36
|
if (this.running.get(sessionId) === run)
|
|
@@ -30,7 +38,7 @@ export class SupervisionTakeover {
|
|
|
30
38
|
});
|
|
31
39
|
return run;
|
|
32
40
|
}
|
|
33
|
-
async run(sessionId, threadId, turnId) {
|
|
41
|
+
async run(sessionId, threadId, turnId, boundary) {
|
|
34
42
|
const before = this.deps.context(sessionId);
|
|
35
43
|
if (!before ||
|
|
36
44
|
before.session.provider !== 'codex' ||
|
|
@@ -81,23 +89,27 @@ export class SupervisionTakeover {
|
|
|
81
89
|
return { accepted: false, code: 'PREVIOUS_SUPERVISOR_NOT_FOUND' };
|
|
82
90
|
const fingerprint = planFingerprint(before.plan);
|
|
83
91
|
const generation = before.state?.generation ?? 0;
|
|
92
|
+
boundary('ownershipReservation');
|
|
84
93
|
const claim = this.deps.store.claim(before.identity, sessionId);
|
|
85
94
|
if (!claim)
|
|
86
95
|
return { accepted: false, code: 'TAKEOVER_IN_PROGRESS' };
|
|
87
96
|
if (!this.deps.store.retire(claim, previous.map((p) => p.session.id)))
|
|
88
97
|
return { accepted: false, code: 'TAKEOVER_CONTEXT_CHANGED' };
|
|
89
98
|
// Fence every predecessor before the first asynchronous process operation.
|
|
99
|
+
boundary('fencePreviousSupervisor');
|
|
90
100
|
for (const p of previous)
|
|
91
101
|
if (!this.deps.store.stopped(before.identity, p.session.id))
|
|
92
102
|
this.deps.fence(p.session.id);
|
|
93
103
|
for (const p of previous) {
|
|
94
104
|
if (this.deps.store.stopped(before.identity, p.session.id))
|
|
95
105
|
continue;
|
|
106
|
+
boundary('quiescePreviousWriter');
|
|
96
107
|
if (!(await this.deps.stop(p)))
|
|
97
108
|
return { accepted: false, code: 'PREVIOUS_WRITER_NOT_STOPPED' };
|
|
98
109
|
if (!this.deps.store.markStopped(claim, p.session.id))
|
|
99
110
|
return { accepted: false, code: 'TAKEOVER_CONTEXT_CHANGED' };
|
|
100
111
|
}
|
|
112
|
+
boundary('revalidateContext');
|
|
101
113
|
const current = this.deps.context(sessionId);
|
|
102
114
|
if (!current ||
|
|
103
115
|
current.session.threadId !== threadId ||
|
|
@@ -172,6 +184,7 @@ export class SupervisionTakeover {
|
|
|
172
184
|
updatedAt: now,
|
|
173
185
|
};
|
|
174
186
|
const previousSessionIds = previous.map((p) => p.session.id);
|
|
187
|
+
boundary('commitOwnership');
|
|
175
188
|
if (!this.deps.store.complete(claim, state, [
|
|
176
189
|
{
|
|
177
190
|
sessionId,
|
|
@@ -128,6 +128,7 @@ export class CodexSessionRuntime {
|
|
|
128
128
|
retrieval;
|
|
129
129
|
requireExecutorAdmission;
|
|
130
130
|
scratch;
|
|
131
|
+
runtimeReleases;
|
|
131
132
|
/** Trusted read-only port for the current controller-bound child on its owning process. */
|
|
132
133
|
async readExecutorConfiguration(input) {
|
|
133
134
|
const resource = this.sessions.get(input.sessionId);
|
|
@@ -150,7 +151,7 @@ export class CodexSessionRuntime {
|
|
|
150
151
|
// correlated-map constructor shape. Live ownership is `sessions` only.
|
|
151
152
|
_legacyProcesses = undefined, onNotification, onServerRequest, onProcessExit, resolveSkills, planStatusSource, onPlanStatus, planMeasurementBaseUrl,
|
|
152
153
|
// Compatibility slot: blocking app-server requests wait for explicit input.
|
|
153
|
-
_legacyRequestTimeoutMs = undefined, maxPendingRequests = 64, readerCwd, resolveModelConfig, retrieval, requireExecutorAdmission, scratch) {
|
|
154
|
+
_legacyRequestTimeoutMs = undefined, maxPendingRequests = 64, readerCwd, resolveModelConfig, retrieval, requireExecutorAdmission, scratch, runtimeReleases) {
|
|
154
155
|
this.launch = launch;
|
|
155
156
|
this.onNotification = onNotification;
|
|
156
157
|
this.onServerRequest = onServerRequest;
|
|
@@ -165,6 +166,7 @@ export class CodexSessionRuntime {
|
|
|
165
166
|
this.retrieval = retrieval;
|
|
166
167
|
this.requireExecutorAdmission = requireExecutorAdmission;
|
|
167
168
|
this.scratch = scratch;
|
|
169
|
+
this.runtimeReleases = runtimeReleases;
|
|
168
170
|
void _legacyProcesses;
|
|
169
171
|
void _legacyRequestTimeoutMs;
|
|
170
172
|
}
|
|
@@ -296,8 +298,10 @@ export class CodexSessionRuntime {
|
|
|
296
298
|
await this.confirmResourceRelease(resource, true);
|
|
297
299
|
}
|
|
298
300
|
this.retrieval?.release?.(session.id);
|
|
299
|
-
if (observedResource && !this.liveResources.get(session.id)?.size)
|
|
301
|
+
if (observedResource && !this.liveResources.get(session.id)?.size) {
|
|
302
|
+
this.runtimeReleases?.confirm(session);
|
|
300
303
|
this.confirmedWorkspaceReleases.add(session.id);
|
|
304
|
+
}
|
|
301
305
|
}
|
|
302
306
|
confirmResourceRelease(resource, strict = false) {
|
|
303
307
|
const prior = this.resourceReleases.get(resource);
|
|
@@ -608,7 +612,8 @@ export class CodexSessionRuntime {
|
|
|
608
612
|
// A user-confirmed Close already quiesced this root. Reopening it solely
|
|
609
613
|
// for takeover would conflict with the incoming workspace's running slot.
|
|
610
614
|
if (session.desiredState === 'stopped' &&
|
|
611
|
-
this.confirmedWorkspaceReleases.has(session.id)
|
|
615
|
+
(this.confirmedWorkspaceReleases.has(session.id) ||
|
|
616
|
+
this.runtimeReleases?.confirmed(session)) &&
|
|
612
617
|
!this.liveResources.get(session.id)?.size &&
|
|
613
618
|
!recordedProcesses.some((claim) => ['running', 'detached-active'].includes(claim.state)))
|
|
614
619
|
return true;
|
|
@@ -632,7 +637,7 @@ export class CodexSessionRuntime {
|
|
|
632
637
|
}
|
|
633
638
|
}
|
|
634
639
|
async quiesceTakeoverActors(session, recordedProcesses, executor, allowed) {
|
|
635
|
-
const writer = await this.
|
|
640
|
+
const writer = await this.acquireTakeoverControl(session, allowed);
|
|
636
641
|
if (!allowed()) {
|
|
637
642
|
await this.release(session.id);
|
|
638
643
|
return false;
|
|
@@ -773,6 +778,41 @@ export class CodexSessionRuntime {
|
|
|
773
778
|
resource.dispose();
|
|
774
779
|
return true;
|
|
775
780
|
}
|
|
781
|
+
/** A fenced predecessor needs a stop-only connection, never execution admission.
|
|
782
|
+
* thread/resume loads its existing identity without starting a model turn.
|
|
783
|
+
* No missing-rollout replacement, capability preparation or plan watcher is allowed here.
|
|
784
|
+
*/
|
|
785
|
+
async acquireTakeoverControl(session, allowed) {
|
|
786
|
+
if (this.ownsWriter(session.id))
|
|
787
|
+
return { session, replacementCreated: false };
|
|
788
|
+
if (!session.threadId)
|
|
789
|
+
throw new Error('CODEX_THREAD_ID_MISSING');
|
|
790
|
+
const resource = await this.createResource(session, 'takeover');
|
|
791
|
+
try {
|
|
792
|
+
if (!allowed())
|
|
793
|
+
throw new Error('TAKEOVER_CANCELLED');
|
|
794
|
+
await resource.process.rpc.request('initialize', {
|
|
795
|
+
clientInfo: { name: 'gestalt-mobile', version: '0.1.0' },
|
|
796
|
+
capabilities: { experimentalApi: true },
|
|
797
|
+
});
|
|
798
|
+
if (!allowed())
|
|
799
|
+
throw new Error('TAKEOVER_CANCELLED');
|
|
800
|
+
await resource.process.rpc.request('thread/resume', {
|
|
801
|
+
threadId: session.threadId,
|
|
802
|
+
cwd: session.workspacePath,
|
|
803
|
+
...this.permissionParams(session),
|
|
804
|
+
});
|
|
805
|
+
if (!allowed())
|
|
806
|
+
throw new Error('TAKEOVER_CANCELLED');
|
|
807
|
+
resource.threadId = session.threadId;
|
|
808
|
+
this.sessions.set(session.id, resource);
|
|
809
|
+
return { session, replacementCreated: false };
|
|
810
|
+
}
|
|
811
|
+
catch (error) {
|
|
812
|
+
resource.dispose();
|
|
813
|
+
throw error;
|
|
814
|
+
}
|
|
815
|
+
}
|
|
776
816
|
async queueTurnInput(session, turnId, text, clientUserMessageId) {
|
|
777
817
|
this.scratch?.assertAvailable?.(session.id);
|
|
778
818
|
const resource = this.sessions.get(session.id);
|
|
@@ -1507,9 +1547,9 @@ export class CodexSessionRuntime {
|
|
|
1507
1547
|
? { permissions: 'workspace-git' }
|
|
1508
1548
|
: { sandbox: selection };
|
|
1509
1549
|
}
|
|
1510
|
-
createResource(session) {
|
|
1550
|
+
createResource(session, purpose = 'execution') {
|
|
1511
1551
|
this.scratch?.assertAvailable?.(session.id);
|
|
1512
|
-
const task = this.createResourceInner(session);
|
|
1552
|
+
const task = this.createResourceInner(session, purpose);
|
|
1513
1553
|
const pending = this.resourceCreations.get(session.id) ?? new Set();
|
|
1514
1554
|
pending.add(task);
|
|
1515
1555
|
this.resourceCreations.set(session.id, pending);
|
|
@@ -1522,19 +1562,21 @@ export class CodexSessionRuntime {
|
|
|
1522
1562
|
.catch(() => undefined);
|
|
1523
1563
|
return task;
|
|
1524
1564
|
}
|
|
1525
|
-
async createResourceInner(session) {
|
|
1526
|
-
this.
|
|
1565
|
+
async createResourceInner(session, purpose) {
|
|
1566
|
+
this.runtimeReleases?.invalidate(session.id);
|
|
1567
|
+
if (purpose === 'execution')
|
|
1568
|
+
this.scratch?.reserveRuntime?.(session);
|
|
1527
1569
|
this.confirmedWorkspaceReleases.delete(session.id);
|
|
1528
1570
|
const deadline = xerjDeadline();
|
|
1529
|
-
const lease = this.planStatusSource
|
|
1571
|
+
const lease = purpose === 'execution' && this.planStatusSource
|
|
1530
1572
|
? await this.planStatusSource.open({ id: session.id, workspacePath: session.workspacePath }, (update) => this.onPlanStatus?.(session.id, update))
|
|
1531
1573
|
: undefined;
|
|
1532
1574
|
let borrowed;
|
|
1533
1575
|
let launched = false;
|
|
1534
1576
|
try {
|
|
1535
1577
|
const token = randomUUID();
|
|
1536
|
-
const skillsConfig = await this.resolveSkills?.(session);
|
|
1537
|
-
const modelConfig = (await this.resolveModelConfig?.(session)) ?? {};
|
|
1578
|
+
const skillsConfig = purpose === 'execution' ? await this.resolveSkills?.(session) : undefined;
|
|
1579
|
+
const modelConfig = purpose === 'execution' ? ((await this.resolveModelConfig?.(session)) ?? {}) : {};
|
|
1538
1580
|
const scratch = await this.scratch?.allocate(session);
|
|
1539
1581
|
const scratchLease = (borrowed = await this.scratch?.borrow?.(session));
|
|
1540
1582
|
this.scratch?.assertAvailable?.(session.id);
|
|
@@ -28,6 +28,7 @@ function migrateWorkspaceGitDefaults(database) {
|
|
|
28
28
|
}
|
|
29
29
|
export function migrate(database) {
|
|
30
30
|
database.exec(schema);
|
|
31
|
+
database.exec('CREATE TABLE IF NOT EXISTS session_runtime_releases (session_id TEXT PRIMARY KEY REFERENCES relay_sessions(id) ON DELETE CASCADE, workspace_path TEXT NOT NULL, thread_id TEXT NOT NULL)');
|
|
31
32
|
database.exec(`CREATE TABLE IF NOT EXISTS org_plan_launches (
|
|
32
33
|
launch_id TEXT PRIMARY KEY,
|
|
33
34
|
canonical_path TEXT UNIQUE,
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (C) 2026 Dyne.org foundation
|
|
3
|
+
* Designed by Denis Roio <jaromil@dyne.org>
|
|
4
|
+
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
5
|
+
*/
|
|
6
|
+
export class SqliteRuntimeReleaseStore {
|
|
7
|
+
db;
|
|
8
|
+
constructor(db) {
|
|
9
|
+
this.db = db;
|
|
10
|
+
}
|
|
11
|
+
confirmed(session) {
|
|
12
|
+
return Boolean(session.threadId &&
|
|
13
|
+
this.db
|
|
14
|
+
.prepare('SELECT 1 FROM session_runtime_releases WHERE session_id=? AND workspace_path=? AND thread_id=?')
|
|
15
|
+
.get(session.id, session.workspacePath, session.threadId));
|
|
16
|
+
}
|
|
17
|
+
confirm(session) {
|
|
18
|
+
if (!session.threadId)
|
|
19
|
+
return;
|
|
20
|
+
this.db
|
|
21
|
+
.prepare('INSERT INTO session_runtime_releases (session_id,workspace_path,thread_id) VALUES (?,?,?) ON CONFLICT(session_id) DO UPDATE SET workspace_path=excluded.workspace_path,thread_id=excluded.thread_id')
|
|
22
|
+
.run(session.id, session.workspacePath, session.threadId);
|
|
23
|
+
}
|
|
24
|
+
invalidate(sessionId) {
|
|
25
|
+
this.db.prepare('DELETE FROM session_runtime_releases WHERE session_id=?').run(sessionId);
|
|
26
|
+
}
|
|
27
|
+
}
|