gestalt-mobile 0.68.5 → 0.68.6
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.contracts.js +129 -3
- package/dist/server/server/composition.js +92 -22
- package/dist/server/server/features/plans/application/prepare-org-plan-supervision.js +18 -10
- package/dist/server/server/features/plans/application/start-org-plan-supervision.js +13 -4
- package/dist/server/server/features/sessions/application/writer-acquisition.js +7 -0
- package/dist/server/server/features/sessions/start-session/endpoint.js +8 -0
- package/dist/server/server/platform/codex/error-code.js +2 -2
- package/dist/server/server/platform/codex/protocol-compatibility.js +7 -24
- package/dist/server/server/platform/persistence/sqlite-org-plan-launch-store.js +43 -16
- package/package.json +1 -1
|
@@ -460,7 +460,7 @@ async function createUnauthorizedProductionApp(root, dataDir) {
|
|
|
460
460
|
installedCodexVersion: null,
|
|
461
461
|
});
|
|
462
462
|
}
|
|
463
|
-
async function orgPlanActivationFixture() {
|
|
463
|
+
async function orgPlanActivationFixture(installedCodexVersion = 'codex-cli 0.144.3') {
|
|
464
464
|
const root = await mkdtemp(join(tmpdir(), 'gestalt-plan-activation-root-'));
|
|
465
465
|
const dataDir = await mkdtemp(join(tmpdir(), 'gestalt-plan-activation-state-'));
|
|
466
466
|
ownTemporaryPaths(root, dataDir);
|
|
@@ -487,7 +487,7 @@ async function orgPlanActivationFixture() {
|
|
|
487
487
|
root,
|
|
488
488
|
dataDir,
|
|
489
489
|
relyingParty,
|
|
490
|
-
installedCodexVersion
|
|
490
|
+
installedCodexVersion,
|
|
491
491
|
startAppServers: true,
|
|
492
492
|
sessionModelCatalog: { list: async () => ['gpt-6.1-sol', 'gpt-5.6-terra'] },
|
|
493
493
|
profiles: {
|
|
@@ -6005,6 +6005,127 @@ describe('production composition', () => {
|
|
|
6005
6005
|
});
|
|
6006
6006
|
});
|
|
6007
6007
|
describeCompositionConcern('lifecycle', () => {
|
|
6008
|
+
it('requires the prior session to stop, then fences it while a supervisor owns its workspace', async () => {
|
|
6009
|
+
const f = await orgPlanActivationFixture('codex-cli 0.167.0');
|
|
6010
|
+
const app = await f.open();
|
|
6011
|
+
try {
|
|
6012
|
+
const idleId = await createComposedSession(app);
|
|
6013
|
+
const payload = await f.prepare(app);
|
|
6014
|
+
const busy = (await app.inject({ method: 'POST', url: '/api/plans/execute', payload })).json();
|
|
6015
|
+
expect(busy).toMatchObject({
|
|
6016
|
+
kind: 'blocked',
|
|
6017
|
+
code: 'WORKSPACE_BUSY',
|
|
6018
|
+
existingSessionId: idleId,
|
|
6019
|
+
});
|
|
6020
|
+
expect((await app.inject({ method: 'POST', url: `/api/sessions/${idleId}/stop` })).statusCode).toBe(202);
|
|
6021
|
+
const launched = (await app.inject({ method: 'POST', url: '/api/plans/execute', payload })).json();
|
|
6022
|
+
expect(launched).toMatchObject({ kind: 'started' });
|
|
6023
|
+
expect(launched.session.id).not.toBe(idleId);
|
|
6024
|
+
const otherTurn = await app.inject({
|
|
6025
|
+
method: 'POST',
|
|
6026
|
+
url: `/api/sessions/${idleId}/turns`,
|
|
6027
|
+
payload: { text: 'Continue work' },
|
|
6028
|
+
});
|
|
6029
|
+
expect(otherTurn.statusCode).toBe(409);
|
|
6030
|
+
expect(otherTurn.json()).toMatchObject({ code: 'SESSION_WORKSPACE_LOCKED' });
|
|
6031
|
+
expect(f.requests('turn/start')).toHaveLength(1);
|
|
6032
|
+
expect((await app.inject({ method: 'DELETE', url: `/api/sessions/${launched.session.id}` }))
|
|
6033
|
+
.statusCode).toBe(204);
|
|
6034
|
+
expect(await createComposedSession(app)).toEqual(expect.any(String));
|
|
6035
|
+
}
|
|
6036
|
+
finally {
|
|
6037
|
+
await app.close();
|
|
6038
|
+
}
|
|
6039
|
+
});
|
|
6040
|
+
it('blocks Execute while another session has accepted work in the workspace', async () => {
|
|
6041
|
+
const f = await orgPlanActivationFixture('codex-cli 0.167.0');
|
|
6042
|
+
const app = await f.open();
|
|
6043
|
+
try {
|
|
6044
|
+
const id = await createComposedSession(app);
|
|
6045
|
+
const payload = await f.prepare(app);
|
|
6046
|
+
expect((await app.inject({
|
|
6047
|
+
method: 'POST',
|
|
6048
|
+
url: `/api/sessions/${id}/turns`,
|
|
6049
|
+
payload: { text: 'Work' },
|
|
6050
|
+
})).statusCode).toBe(202);
|
|
6051
|
+
const launch = (await app.inject({ method: 'POST', url: '/api/plans/execute', payload })).json();
|
|
6052
|
+
expect(launch).toMatchObject({
|
|
6053
|
+
kind: 'blocked',
|
|
6054
|
+
code: 'ACTIVE_SUPERVISION',
|
|
6055
|
+
existingSessionId: id,
|
|
6056
|
+
});
|
|
6057
|
+
expect(launch.reason).toContain('Stop its work');
|
|
6058
|
+
expect((await app.inject('/api/sessions')).json()).toHaveLength(1);
|
|
6059
|
+
}
|
|
6060
|
+
finally {
|
|
6061
|
+
await app.close();
|
|
6062
|
+
}
|
|
6063
|
+
});
|
|
6064
|
+
it('executes a validated plan on Codex 0.167.0 with supervision instructions and exclusive workspace ownership', async () => {
|
|
6065
|
+
const f = await orgPlanActivationFixture('codex-cli 0.167.0');
|
|
6066
|
+
const app = await f.open();
|
|
6067
|
+
try {
|
|
6068
|
+
const payload = await f.prepare(app);
|
|
6069
|
+
const launched = (await app.inject({ method: 'POST', url: '/api/plans/execute', payload })).json();
|
|
6070
|
+
expect(launched).toMatchObject({ kind: 'started', bootstrap: { kind: 'accepted' } });
|
|
6071
|
+
const turns = f.requests('turn/start');
|
|
6072
|
+
expect(turns).toHaveLength(1);
|
|
6073
|
+
expect(JSON.stringify(turns[0].params)).toContain('Use $gestalt:org-plan');
|
|
6074
|
+
expect(JSON.stringify(turns[0].params)).toContain('.gestalt/activation.org');
|
|
6075
|
+
const prepare = (await app.inject({
|
|
6076
|
+
method: 'POST',
|
|
6077
|
+
url: '/api/plans/prepare',
|
|
6078
|
+
payload: payload.reference,
|
|
6079
|
+
})).json();
|
|
6080
|
+
expect(prepare).toMatchObject({
|
|
6081
|
+
kind: 'blocked',
|
|
6082
|
+
code: 'ACTIVE_SUPERVISION',
|
|
6083
|
+
existingSessionId: launched.session.id,
|
|
6084
|
+
});
|
|
6085
|
+
const other = await app.inject({
|
|
6086
|
+
method: 'POST',
|
|
6087
|
+
url: '/api/sessions',
|
|
6088
|
+
payload: {
|
|
6089
|
+
workspaceId: payload.reference.workspaceId,
|
|
6090
|
+
profile: 'default',
|
|
6091
|
+
provider: 'codex',
|
|
6092
|
+
model: 'gpt-6.1-sol',
|
|
6093
|
+
},
|
|
6094
|
+
});
|
|
6095
|
+
expect(other.statusCode).toBe(409);
|
|
6096
|
+
expect(other.json()).toMatchObject({ code: 'SESSION_WORKSPACE_LOCKED' });
|
|
6097
|
+
expect((await app.inject('/api/sessions')).json()).toHaveLength(1);
|
|
6098
|
+
expect(f.requests('thread/start')).toHaveLength(1);
|
|
6099
|
+
}
|
|
6100
|
+
finally {
|
|
6101
|
+
await app.close();
|
|
6102
|
+
}
|
|
6103
|
+
});
|
|
6104
|
+
it.each(['codex-cli 0.166.0', 'codex-cli 1.0.0', 'custom development build', null])('explains the exact Codex admission blocker for %s', async (version) => {
|
|
6105
|
+
const f = await orgPlanActivationFixture(version);
|
|
6106
|
+
const app = await f.open();
|
|
6107
|
+
try {
|
|
6108
|
+
const workspace = (await app.inject('/api/bootstrap'))
|
|
6109
|
+
.json()
|
|
6110
|
+
.workspaces[0].children.find((item) => item.name === 'workspace');
|
|
6111
|
+
const result = (await app.inject({
|
|
6112
|
+
method: 'POST',
|
|
6113
|
+
url: '/api/plans/prepare',
|
|
6114
|
+
payload: {
|
|
6115
|
+
kind: 'workspace',
|
|
6116
|
+
workspaceId: workspace.id,
|
|
6117
|
+
planName: '.gestalt/activation.org',
|
|
6118
|
+
},
|
|
6119
|
+
})).json();
|
|
6120
|
+
expect(result).toMatchObject(version ? { kind: 'eligible' } : { kind: 'blocked', code: 'CODEX_NOT_FOUND' });
|
|
6121
|
+
if (!version)
|
|
6122
|
+
expect(result.reason).toContain('not found');
|
|
6123
|
+
expect(f.requests('thread/start')).toHaveLength(0);
|
|
6124
|
+
}
|
|
6125
|
+
finally {
|
|
6126
|
+
await app.close();
|
|
6127
|
+
}
|
|
6128
|
+
});
|
|
6008
6129
|
it('recovers a published Org-plan supervisor after initial runtime failure without replacing its session', async () => {
|
|
6009
6130
|
const f = await orgPlanActivationFixture();
|
|
6010
6131
|
const app = await f.open();
|
|
@@ -6709,7 +6830,12 @@ describe('production composition', () => {
|
|
|
6709
6830
|
launchId: 'after-forget',
|
|
6710
6831
|
},
|
|
6711
6832
|
})).json();
|
|
6712
|
-
expect(nextLaunch
|
|
6833
|
+
expect(nextLaunch, JSON.stringify({
|
|
6834
|
+
kind: nextLaunch.kind,
|
|
6835
|
+
stage: nextLaunch.stage,
|
|
6836
|
+
reason: nextLaunch.reason,
|
|
6837
|
+
state: nextLaunch.session?.state,
|
|
6838
|
+
})).toMatchObject(recoveryScenario === 'uncertain-manual'
|
|
6713
6839
|
? { kind: 'partial', stage: 'bootstrap', bootstrap: { kind: 'pending' } }
|
|
6714
6840
|
: { kind: 'started', bootstrap: { kind: 'accepted' } });
|
|
6715
6841
|
expect(nextLaunch.session.id).not.toBe(id);
|
|
@@ -130,7 +130,6 @@ import { currentExecutableL1Index } from './features/plans/domain/supervised-pla
|
|
|
130
130
|
import { AttentionResolution } from './features/org-plan-attention/application/resolve.js';
|
|
131
131
|
import { AttentionAcknowledgement } from './features/org-plan-attention/application/acknowledgement.js';
|
|
132
132
|
import { pwaIconUrl } from './features/pwa/register-routes.js';
|
|
133
|
-
const generatedProtocolVersion = 'codex-cli 0.144.3';
|
|
134
133
|
const checkpointDiagnostic = debuglog('gestalt-mobile:checkpoint');
|
|
135
134
|
const attentionDiagnostic = debuglog('gestalt-mobile:attention');
|
|
136
135
|
export async function composeRelayApp(options) {
|
|
@@ -169,6 +168,36 @@ export async function composeRelayApp(options) {
|
|
|
169
168
|
const interactions = new SqlitePendingInteractionStore(database);
|
|
170
169
|
const idempotency = new SqliteIdempotencyStore(database);
|
|
171
170
|
const orgPlanLaunches = new SqliteOrgPlanLaunchStore(database);
|
|
171
|
+
// Admission spans asynchronous provider calls so Execute cannot reserve a workspace mid-start.
|
|
172
|
+
const workspaceAdmissions = new Map();
|
|
173
|
+
const assertWorkspaceOwner = (session) => {
|
|
174
|
+
let owner = orgPlanLaunches.workspaceOwner(session.workspacePath);
|
|
175
|
+
while (owner &&
|
|
176
|
+
forgetOperations.find(owner.sessionId)?.phase === 'completed' &&
|
|
177
|
+
!sessions.find(owner.sessionId) &&
|
|
178
|
+
!runtime?.ownsWriter(owner.sessionId)) {
|
|
179
|
+
orgPlanLaunches.releaseOwner(owner);
|
|
180
|
+
owner = orgPlanLaunches.workspaceOwner(session.workspacePath);
|
|
181
|
+
}
|
|
182
|
+
if (owner && owner.sessionId !== session.id)
|
|
183
|
+
throw new WriterAcquisitionError('workspaceLocked');
|
|
184
|
+
};
|
|
185
|
+
const withWorkspaceAdmission = async (sessionId, operation) => {
|
|
186
|
+
const session = sessions.find(sessionId);
|
|
187
|
+
if (session)
|
|
188
|
+
assertWorkspaceOwner(session);
|
|
189
|
+
workspaceAdmissions.set(sessionId, (workspaceAdmissions.get(sessionId) ?? 0) + 1);
|
|
190
|
+
try {
|
|
191
|
+
return await operation();
|
|
192
|
+
}
|
|
193
|
+
finally {
|
|
194
|
+
const count = (workspaceAdmissions.get(sessionId) ?? 1) - 1;
|
|
195
|
+
if (count)
|
|
196
|
+
workspaceAdmissions.set(sessionId, count);
|
|
197
|
+
else
|
|
198
|
+
workspaceAdmissions.delete(sessionId);
|
|
199
|
+
}
|
|
200
|
+
};
|
|
172
201
|
const reconcileOrgPlanReceipt = (sessionId) => {
|
|
173
202
|
const record = orgPlanLaunches.forSession(sessionId);
|
|
174
203
|
if (record?.phase !== 'submitting' || !record.bootstrapFingerprint)
|
|
@@ -374,7 +403,7 @@ export async function composeRelayApp(options) {
|
|
|
374
403
|
}),
|
|
375
404
|
nextControlId: (sessionId, generation) => `autopilot-${generation}-${createHash('sha256').update(`${sessionId}:${randomUUID()}`).digest('hex').slice(0, 16)}`,
|
|
376
405
|
turnStarter: {
|
|
377
|
-
start: async (sessionId, controlId, generation, launchIdentity) => {
|
|
406
|
+
start: async (sessionId, controlId, generation, launchIdentity) => withWorkspaceAdmission(sessionId, async () => {
|
|
378
407
|
if (supervisorOwnership(sessionId) !== 'owned')
|
|
379
408
|
throw new Error('AUTOPILOT_START_UNAVAILABLE');
|
|
380
409
|
const current = () => {
|
|
@@ -388,7 +417,10 @@ export async function composeRelayApp(options) {
|
|
|
388
417
|
if (!current())
|
|
389
418
|
throw new Error('AUTOPILOT_START_UNAVAILABLE');
|
|
390
419
|
const session = sessions.find(sessionId);
|
|
391
|
-
if (!session ||
|
|
420
|
+
if (!session ||
|
|
421
|
+
!runtime ||
|
|
422
|
+
session.activeTurnId ||
|
|
423
|
+
blockingInteractions(sessionId).length)
|
|
392
424
|
throw new Error('AUTOPILOT_START_UNAVAILABLE');
|
|
393
425
|
requireOrgExecutionAdmission(sessionId);
|
|
394
426
|
if (!current() ||
|
|
@@ -442,10 +474,10 @@ export async function composeRelayApp(options) {
|
|
|
442
474
|
...(started.threadId ? { threadId: started.threadId } : {}),
|
|
443
475
|
...(started.activeTurnId ? { turnId: started.activeTurnId } : {}),
|
|
444
476
|
});
|
|
445
|
-
},
|
|
477
|
+
}),
|
|
446
478
|
},
|
|
447
479
|
executorController: {
|
|
448
|
-
resume: async (sessionId, threadId, generation, trigger) => {
|
|
480
|
+
resume: async (sessionId, threadId, generation, trigger) => withWorkspaceAdmission(sessionId, async () => {
|
|
449
481
|
if (supervisorOwnership(sessionId) !== 'owned')
|
|
450
482
|
throw new Error('AUTOPILOT_EXECUTOR_UNAVAILABLE');
|
|
451
483
|
const session = sessions.find(sessionId);
|
|
@@ -482,7 +514,7 @@ export async function composeRelayApp(options) {
|
|
|
482
514
|
threadId,
|
|
483
515
|
turnId,
|
|
484
516
|
});
|
|
485
|
-
},
|
|
517
|
+
}),
|
|
486
518
|
refresh: (sessionId) => activity.refresh(sessionId),
|
|
487
519
|
interrupt: async (sessionId, threadId) => {
|
|
488
520
|
const session = sessions.find(sessionId);
|
|
@@ -651,7 +683,7 @@ export async function composeRelayApp(options) {
|
|
|
651
683
|
? { ...session, executionPolicy, updatedAt: new Date().toISOString() }
|
|
652
684
|
: session;
|
|
653
685
|
};
|
|
654
|
-
const protocol = protocolCompatibility(options.installedCodexVersion
|
|
686
|
+
const protocol = protocolCompatibility(options.installedCodexVersion);
|
|
655
687
|
const providerAvailability = {
|
|
656
688
|
codex: {
|
|
657
689
|
available: options.installedCodexVersion !== null && protocol.compatible,
|
|
@@ -867,7 +899,7 @@ export async function composeRelayApp(options) {
|
|
|
867
899
|
const timer = setTimeout(callback, delay);
|
|
868
900
|
return () => clearTimeout(timer);
|
|
869
901
|
}),
|
|
870
|
-
start: async (session, current) => {
|
|
902
|
+
start: async (session, current) => withWorkspaceAdmission(session.id, async () => {
|
|
871
903
|
if (!runtime || !current())
|
|
872
904
|
throw new Error('PROVIDER_RETRY_CANCELLED');
|
|
873
905
|
const started = await runtime.startTurn(session, providerContinuationPrompt, `provider-retry-${randomUUID()}`, new Date().toISOString(), current);
|
|
@@ -879,7 +911,7 @@ export async function composeRelayApp(options) {
|
|
|
879
911
|
threadId: started.threadId,
|
|
880
912
|
turnId: started.activeTurnId,
|
|
881
913
|
});
|
|
882
|
-
},
|
|
914
|
+
}),
|
|
883
915
|
publish: (id, type, payload) => {
|
|
884
916
|
events.publish(journal.append(id, type, payload, new Date().toISOString()));
|
|
885
917
|
},
|
|
@@ -1546,6 +1578,7 @@ export async function composeRelayApp(options) {
|
|
|
1546
1578
|
return current;
|
|
1547
1579
|
};
|
|
1548
1580
|
const publishSession = (session, beforeCommit, commit) => withScratchContainment(session.workspacePath, () => {
|
|
1581
|
+
assertWorkspaceOwner(session);
|
|
1549
1582
|
beforeCommit?.();
|
|
1550
1583
|
if (commit)
|
|
1551
1584
|
commit();
|
|
@@ -1684,7 +1717,7 @@ export async function composeRelayApp(options) {
|
|
|
1684
1717
|
const session = sessions.find(sessionId);
|
|
1685
1718
|
if (!runtime || !session)
|
|
1686
1719
|
return null;
|
|
1687
|
-
return async (text, operationKey) => {
|
|
1720
|
+
return async (text, operationKey) => withWorkspaceAdmission(sessionId, async () => {
|
|
1688
1721
|
const writer = await runtime.ensureWriter(session, new Date().toISOString());
|
|
1689
1722
|
if (writer.session.activeTurnId)
|
|
1690
1723
|
await runtime.queueTurnInput(writer.session, writer.session.activeTurnId, text, operationKey);
|
|
@@ -1699,7 +1732,7 @@ export async function composeRelayApp(options) {
|
|
|
1699
1732
|
turnId: started.activeTurnId,
|
|
1700
1733
|
});
|
|
1701
1734
|
}
|
|
1702
|
-
};
|
|
1735
|
+
});
|
|
1703
1736
|
},
|
|
1704
1737
|
},
|
|
1705
1738
|
policy: {
|
|
@@ -1736,12 +1769,13 @@ export async function composeRelayApp(options) {
|
|
|
1736
1769
|
defaultSkillProfile: options.explicitSkillProfile,
|
|
1737
1770
|
activate: runtime || kimiRuntime
|
|
1738
1771
|
? async (session) => {
|
|
1772
|
+
assertWorkspaceOwner(session);
|
|
1739
1773
|
const now = new Date().toISOString();
|
|
1740
1774
|
dismissPendingInteractions(session.id, now);
|
|
1741
1775
|
const owner = ownerRuntime(session);
|
|
1742
1776
|
if (!owner)
|
|
1743
1777
|
throw new Error('LLM_RUNTIME_UNAVAILABLE');
|
|
1744
|
-
return owner.start(session, now);
|
|
1778
|
+
return withWorkspaceAdmission(session.id, () => owner.start(session, now));
|
|
1745
1779
|
}
|
|
1746
1780
|
: undefined,
|
|
1747
1781
|
};
|
|
@@ -1758,7 +1792,7 @@ export async function composeRelayApp(options) {
|
|
|
1758
1792
|
session.activeTurnId)
|
|
1759
1793
|
orgPlanLaunches.save({ ...record, phase: 'submitting', manualRecoveryTurnId: session.activeTurnId }, record.phase);
|
|
1760
1794
|
},
|
|
1761
|
-
start: async (session, text, clientUserMessageId) => {
|
|
1795
|
+
start: async (session, text, clientUserMessageId) => withWorkspaceAdmission(session.id, async () => {
|
|
1762
1796
|
providerRecovery.cancel(session.id);
|
|
1763
1797
|
autopilot.manualSend(session.id);
|
|
1764
1798
|
const owner = ownerRuntime(session);
|
|
@@ -1772,9 +1806,9 @@ export async function composeRelayApp(options) {
|
|
|
1772
1806
|
!forgetOperations.find(session.id));
|
|
1773
1807
|
});
|
|
1774
1808
|
return owner.startTurn(session, text, clientUserMessageId, new Date().toISOString());
|
|
1775
|
-
},
|
|
1809
|
+
}),
|
|
1776
1810
|
ensureWriter: runtime || kimiRuntime
|
|
1777
|
-
? async (session) => {
|
|
1811
|
+
? async (session) => withWorkspaceAdmission(session.id, async () => {
|
|
1778
1812
|
if (supervisorOwnership(session.id) === 'replaced')
|
|
1779
1813
|
throw new WriterAcquisitionError('supervisorReplaced');
|
|
1780
1814
|
dismissPendingInteractions(session.id, new Date().toISOString());
|
|
@@ -1788,7 +1822,7 @@ export async function composeRelayApp(options) {
|
|
|
1788
1822
|
persisted: true,
|
|
1789
1823
|
};
|
|
1790
1824
|
return owner.ensureWriter(await recoverExecutionPolicy(session), new Date().toISOString());
|
|
1791
|
-
}
|
|
1825
|
+
})
|
|
1792
1826
|
: undefined,
|
|
1793
1827
|
releaseWriter: runtime || kimiRuntime
|
|
1794
1828
|
? async (id) => {
|
|
@@ -1855,11 +1889,37 @@ export async function composeRelayApp(options) {
|
|
|
1855
1889
|
const reclaimableLaunchOwner = (record) => forgetOperations.find(record.sessionId)?.phase === 'completed' &&
|
|
1856
1890
|
!sessions.find(record.sessionId) &&
|
|
1857
1891
|
!runtime?.ownsWriter(record.sessionId);
|
|
1892
|
+
const workspaceBusy = (workspacePath) => {
|
|
1893
|
+
const session = sessions.list().find((session) => {
|
|
1894
|
+
if (!within(workspacePath, session.workspacePath) &&
|
|
1895
|
+
!within(session.workspacePath, workspacePath))
|
|
1896
|
+
return false;
|
|
1897
|
+
const snapshot = activity.snapshot(session.id, new Date().toISOString());
|
|
1898
|
+
return Boolean(session.activeTurnId ||
|
|
1899
|
+
pendingRootTurn(session.id) ||
|
|
1900
|
+
workspaceAdmissions.has(session.id) ||
|
|
1901
|
+
orgPlanStarting.has(session.id) ||
|
|
1902
|
+
snapshot.subagents.some((agent) => ['working', 'awaitingAgent'].includes(agent.state) ||
|
|
1903
|
+
agent.ownedProcesses?.some((process) => ['running', 'detached-active'].includes(process.state))));
|
|
1904
|
+
});
|
|
1905
|
+
return session
|
|
1906
|
+
? {
|
|
1907
|
+
sessionId: session.id,
|
|
1908
|
+
reason: 'Another session is working in this workspace. Stop its work before starting a supervisor.',
|
|
1909
|
+
}
|
|
1910
|
+
: null;
|
|
1911
|
+
};
|
|
1858
1912
|
const prepareOrgPlan = (reference, expectedRevision, skillProfile, ownUnpublishedLaunchId) => prepareOrgPlanSupervision(reference, {
|
|
1859
1913
|
resolveReference: (ref) => orgPlanContext.resolveReference(ref),
|
|
1860
1914
|
workspace: (path, revision) => orgPlanContext.workspace(path, revision),
|
|
1861
1915
|
read: (workspacePath, planName) => workspacePlanCatalog.readExecution(workspacePath, planName),
|
|
1862
|
-
runtimeAvailable: async () =>
|
|
1916
|
+
runtimeAvailable: async () => protocol.compatible
|
|
1917
|
+
? { available: true }
|
|
1918
|
+
: {
|
|
1919
|
+
available: false,
|
|
1920
|
+
code: protocol.code,
|
|
1921
|
+
reason: 'Codex CLI was not found when Mobile started. Install Codex and restart Mobile.',
|
|
1922
|
+
},
|
|
1863
1923
|
policy: assessModelPolicyAdmission,
|
|
1864
1924
|
settings: (workspacePath, selectedProfile) => prepareOrgPlanSettings(workspacePath, {
|
|
1865
1925
|
defaults: sessionDefaults,
|
|
@@ -1869,8 +1929,8 @@ export async function composeRelayApp(options) {
|
|
|
1869
1929
|
skillCatalog,
|
|
1870
1930
|
defaultSkillProfile: options.explicitSkillProfile,
|
|
1871
1931
|
}, selectedProfile),
|
|
1872
|
-
owner: async (canonicalPath) => {
|
|
1873
|
-
const pending = orgPlanLaunches.owner(canonicalPath);
|
|
1932
|
+
owner: async (canonicalPath, workspacePath) => {
|
|
1933
|
+
const pending = orgPlanLaunches.owner(canonicalPath) ?? orgPlanLaunches.workspaceOwner(workspacePath);
|
|
1874
1934
|
const ownUnpublished = pending &&
|
|
1875
1935
|
ownUnpublishedLaunchId &&
|
|
1876
1936
|
pending.launchId === ownUnpublishedLaunchId &&
|
|
@@ -1878,7 +1938,13 @@ export async function composeRelayApp(options) {
|
|
|
1878
1938
|
!runtime?.ownsWriter(pending.sessionId) &&
|
|
1879
1939
|
['reserved', 'creating'].includes(pending.phase);
|
|
1880
1940
|
if (pending && !reclaimableLaunchOwner(pending) && !ownUnpublished)
|
|
1881
|
-
return
|
|
1941
|
+
return {
|
|
1942
|
+
...(sessions.find(pending.sessionId) ? { sessionId: pending.sessionId } : {}),
|
|
1943
|
+
reason: 'This plan or an overlapping workspace is reserved by another supervisor. Open its session to continue, or forget it to release the reservation.',
|
|
1944
|
+
};
|
|
1945
|
+
const busy = workspaceBusy(workspacePath);
|
|
1946
|
+
if (busy && busy.sessionId !== pending?.sessionId)
|
|
1947
|
+
return busy;
|
|
1882
1948
|
const identity = createHash('sha256').update(canonicalPath).digest('hex');
|
|
1883
1949
|
const owner = sessions.list().find((session) => {
|
|
1884
1950
|
if (!session.lastOrgPlan?.attached || session.lastOrgPlan.path !== canonicalPath)
|
|
@@ -1895,10 +1961,14 @@ export async function composeRelayApp(options) {
|
|
|
1895
1961
|
prepare: prepareOrgPlan,
|
|
1896
1962
|
createId: randomUUID,
|
|
1897
1963
|
launches: orgPlanLaunches,
|
|
1898
|
-
|
|
1964
|
+
workspaceBusy,
|
|
1965
|
+
reclaimForgottenOwner: (path, workspacePath) => {
|
|
1899
1966
|
const record = orgPlanLaunches.owner(path);
|
|
1900
1967
|
if (record && reclaimableLaunchOwner(record))
|
|
1901
1968
|
orgPlanLaunches.releaseOwner(record);
|
|
1969
|
+
const workspaceOwner = orgPlanLaunches.workspaceOwner(workspacePath);
|
|
1970
|
+
if (workspaceOwner && reclaimableLaunchOwner(workspaceOwner))
|
|
1971
|
+
orgPlanLaunches.releaseOwner(workspaceOwner);
|
|
1902
1972
|
},
|
|
1903
1973
|
authorizeReplay: async (record) => {
|
|
1904
1974
|
try {
|
|
@@ -2045,7 +2115,7 @@ export async function composeRelayApp(options) {
|
|
|
2045
2115
|
version: '0.1.0',
|
|
2046
2116
|
codex: {
|
|
2047
2117
|
installedVersion: options.installedCodexVersion,
|
|
2048
|
-
protocolVersion:
|
|
2118
|
+
protocolVersion: null,
|
|
2049
2119
|
compatible: protocol.compatible,
|
|
2050
2120
|
},
|
|
2051
2121
|
providers: providerAvailability,
|
|
@@ -54,17 +54,25 @@ export async function prepareOrgPlanSupervision(reference, deps, expectedRevisio
|
|
|
54
54
|
const policy = deps.policy(file.plan);
|
|
55
55
|
if (!policy.allowed)
|
|
56
56
|
return blocked('MODEL_POLICY_UNAVAILABLE', policy.action);
|
|
57
|
+
let owner;
|
|
57
58
|
try {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
59
|
+
owner = await deps.owner(file.canonicalPath, context.workspace.path);
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
return blocked('WORKSPACE_UNAVAILABLE', 'Plan and workspace ownership could not be verified. Refresh and retry.');
|
|
63
|
+
}
|
|
64
|
+
if (owner)
|
|
65
|
+
return {
|
|
66
|
+
kind: 'blocked',
|
|
67
|
+
code: 'ACTIVE_SUPERVISION',
|
|
68
|
+
reason: owner.reason ??
|
|
69
|
+
'This plan already has a supervisor. Open its session to continue or recover it.',
|
|
70
|
+
...(owner.sessionId ? { existingSessionId: owner.sessionId } : {}),
|
|
71
|
+
};
|
|
72
|
+
try {
|
|
73
|
+
const runtime = await deps.runtimeAvailable();
|
|
74
|
+
if (!runtime.available)
|
|
75
|
+
return blocked(runtime.code, runtime.reason);
|
|
68
76
|
}
|
|
69
77
|
catch {
|
|
70
78
|
return blocked('CODEX_UNAVAILABLE', 'Supervision availability could not be verified. Retry after refreshing.');
|
|
@@ -59,7 +59,15 @@ export async function startOrgPlanSupervision(request, deps) {
|
|
|
59
59
|
code: 'GESTALT_CAPABILITIES_UNAVAILABLE',
|
|
60
60
|
reason: 'The Org-plan skill changed before launch. Refresh and confirm again.',
|
|
61
61
|
};
|
|
62
|
-
deps.reclaimForgottenOwner?.(context.sourcePath);
|
|
62
|
+
deps.reclaimForgottenOwner?.(context.sourcePath, context.workspace.path);
|
|
63
|
+
const busy = deps.workspaceBusy?.(context.workspace.path);
|
|
64
|
+
if (busy)
|
|
65
|
+
return {
|
|
66
|
+
kind: 'blocked',
|
|
67
|
+
code: 'ACTIVE_SUPERVISION',
|
|
68
|
+
reason: busy.reason,
|
|
69
|
+
existingSessionId: busy.sessionId,
|
|
70
|
+
};
|
|
63
71
|
const reservation = deps.launches.reserve({
|
|
64
72
|
launchId: input.launchId,
|
|
65
73
|
requestFingerprint: fingerprint,
|
|
@@ -76,7 +84,7 @@ export async function startOrgPlanSupervision(request, deps) {
|
|
|
76
84
|
return {
|
|
77
85
|
kind: 'blocked',
|
|
78
86
|
code: 'ACTIVE_SUPERVISION',
|
|
79
|
-
reason: 'This plan already has a supervisor launch. Open its session to continue or recover it.',
|
|
87
|
+
reason: 'This plan or an overlapping workspace already has a supervisor launch. Open its session to continue or recover it.',
|
|
80
88
|
...(deps.sessions.find(record.sessionId) ? { existingSessionId: record.sessionId } : {}),
|
|
81
89
|
};
|
|
82
90
|
if (record.requestFingerprint !== fingerprint)
|
|
@@ -131,11 +139,12 @@ async function continueLaunch(record, deps) {
|
|
|
131
139
|
}
|
|
132
140
|
if ((record.phase === 'reserved' || record.phase === 'creating') && !session) {
|
|
133
141
|
if (record.notPersisted && !deps.launches.acquireOwner(record)) {
|
|
134
|
-
const owner = deps.launches.owner(record.canonicalPath)
|
|
142
|
+
const owner = deps.launches.owner(record.canonicalPath) ??
|
|
143
|
+
deps.launches.workspaceOwner(record.context.workspace.path);
|
|
135
144
|
return {
|
|
136
145
|
kind: 'blocked',
|
|
137
146
|
code: 'ACTIVE_SUPERVISION',
|
|
138
|
-
reason: 'Another launch now owns this plan.',
|
|
147
|
+
reason: 'Another supervisor launch now owns this plan or an overlapping workspace.',
|
|
139
148
|
...(owner && deps.sessions.find(owner.sessionId)
|
|
140
149
|
? { existingSessionId: owner.sessionId }
|
|
141
150
|
: {}),
|
|
@@ -13,6 +13,13 @@ export class WriterAcquisitionError extends Error {
|
|
|
13
13
|
}
|
|
14
14
|
export function writerAcquisitionProblem(kind) {
|
|
15
15
|
switch (kind) {
|
|
16
|
+
case 'workspaceLocked':
|
|
17
|
+
return {
|
|
18
|
+
status: 409,
|
|
19
|
+
code: 'SESSION_WORKSPACE_LOCKED',
|
|
20
|
+
retryable: false,
|
|
21
|
+
detail: 'An Org-plan supervisor owns this workspace. Continue in its session, or forget that session to release the reservation.',
|
|
22
|
+
};
|
|
16
23
|
case 'supervisorReplaced':
|
|
17
24
|
return {
|
|
18
25
|
status: 409,
|
|
@@ -8,6 +8,7 @@ import { parseStartSessionRequest } from './request.js';
|
|
|
8
8
|
import { startSession } from './use-case.js';
|
|
9
9
|
import { SkillProfileError } from '../../skills/model/errors.js';
|
|
10
10
|
import { problem } from '../../../platform/http/problem.js';
|
|
11
|
+
import { WriterAcquisitionError, writerAcquisitionProblem, } from '../application/writer-acquisition.js';
|
|
11
12
|
export function registerStartSession(app, deps) {
|
|
12
13
|
app.post('/api/sessions', { bodyLimit: 4 * 1024 }, async (request, reply) => {
|
|
13
14
|
const key = idempotencyKey(request.headers);
|
|
@@ -30,6 +31,13 @@ export function registerStartSession(app, deps) {
|
|
|
30
31
|
}
|
|
31
32
|
catch (error) {
|
|
32
33
|
deps.reportFailure?.('start-session', error);
|
|
34
|
+
if (error instanceof WriterAcquisitionError) {
|
|
35
|
+
const failure = writerAcquisitionProblem(error.kind);
|
|
36
|
+
return reply
|
|
37
|
+
.code(failure.status)
|
|
38
|
+
.type('application/problem+json')
|
|
39
|
+
.send(problem(failure.code, failure.status, failure.detail, failure.retryable));
|
|
40
|
+
}
|
|
33
41
|
if (error instanceof Error && error.message === 'CODEX_EXECUTOR_MODEL_UNAVAILABLE')
|
|
34
42
|
return reply
|
|
35
43
|
.code(400)
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
* Designed by Denis Roio <jaromil@dyne.org>
|
|
4
4
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
5
5
|
*/
|
|
6
|
-
export function protocolErrorCode(installed
|
|
6
|
+
export function protocolErrorCode(installed) {
|
|
7
7
|
if (!installed)
|
|
8
8
|
return 'CODEX_NOT_FOUND';
|
|
9
|
-
return
|
|
9
|
+
return null;
|
|
10
10
|
}
|
|
@@ -3,28 +3,11 @@
|
|
|
3
3
|
* Designed by Denis Roio <jaromil@dyne.org>
|
|
4
4
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
5
5
|
*/
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
// optional APIs are negotiated independently at runtime.
|
|
14
|
-
if (!installed || !expected || !coreCompatible(installed, expected))
|
|
15
|
-
return { compatible: false, code: 'CODEX_PROTOCOL_MISMATCH' };
|
|
16
|
-
return { compatible: true };
|
|
17
|
-
}
|
|
18
|
-
function parseCoreVersion(value) {
|
|
19
|
-
const match = /\b(\d+)\.(\d+)(?:\.(\d+))?\b/.exec(value);
|
|
20
|
-
if (!match)
|
|
21
|
-
return undefined;
|
|
22
|
-
return { major: Number(match[1]), minor: Number(match[2]) };
|
|
23
|
-
}
|
|
24
|
-
function coreCompatible(installed, expected) {
|
|
25
|
-
if (installed.major !== expected.major)
|
|
26
|
-
return false;
|
|
27
|
-
if (installed.major !== 0)
|
|
28
|
-
return installed.minor === expected.minor;
|
|
29
|
-
return installed.minor >= expected.minor && installed.minor <= expected.minor + 4;
|
|
6
|
+
import { protocolErrorCode } from './error-code.js';
|
|
7
|
+
/** Retain the public health flag without using version text as admission policy.
|
|
8
|
+
* Runtime operations and capability checks establish actual protocol support.
|
|
9
|
+
*/
|
|
10
|
+
export function protocolCompatibility(installedVersion) {
|
|
11
|
+
const code = protocolErrorCode(installedVersion);
|
|
12
|
+
return code ? { compatible: false, code } : { compatible: true };
|
|
30
13
|
}
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* Designed by Denis Roio <jaromil@dyne.org>
|
|
4
4
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
5
5
|
*/
|
|
6
|
+
import { relative, isAbsolute } from 'node:path';
|
|
6
7
|
export class SqliteOrgPlanLaunchStore {
|
|
7
8
|
db;
|
|
8
9
|
#operations = new Map();
|
|
@@ -22,19 +23,40 @@ export class SqliteOrgPlanLaunchStore {
|
|
|
22
23
|
.prepare('SELECT record_json FROM org_plan_launches WHERE session_id=?')
|
|
23
24
|
.get(sessionId));
|
|
24
25
|
}
|
|
26
|
+
workspaceOwner(workspacePath) {
|
|
27
|
+
const records = this.db
|
|
28
|
+
.prepare('SELECT record_json FROM org_plan_launches WHERE canonical_path IS NOT NULL')
|
|
29
|
+
.all();
|
|
30
|
+
for (const row of records) {
|
|
31
|
+
const record = decode(row);
|
|
32
|
+
const overlaps = (parent, child) => {
|
|
33
|
+
const path = relative(parent, child);
|
|
34
|
+
return path === '' || (path !== '..' && !path.startsWith('../') && !isAbsolute(path));
|
|
35
|
+
};
|
|
36
|
+
if (overlaps(record.context.workspace.path, workspacePath) ||
|
|
37
|
+
overlaps(workspacePath, record.context.workspace.path))
|
|
38
|
+
return record;
|
|
39
|
+
}
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
25
42
|
reserve(record) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
43
|
+
return this.activationTransaction(() => {
|
|
44
|
+
const existing = this.find(record.launchId);
|
|
45
|
+
if (existing)
|
|
46
|
+
return { kind: 'existing', record: existing };
|
|
47
|
+
const workspaceOwner = this.workspaceOwner(record.context.workspace.path);
|
|
48
|
+
if (workspaceOwner)
|
|
49
|
+
return { kind: 'owned', record: workspaceOwner };
|
|
50
|
+
const inserted = this.db
|
|
51
|
+
.prepare('INSERT OR IGNORE INTO org_plan_launches (launch_id,canonical_path,session_id,phase,record_json) VALUES (?,?,?,?,?)')
|
|
52
|
+
.run(record.launchId, record.canonicalPath, record.sessionId, record.phase, JSON.stringify(record));
|
|
53
|
+
if (inserted.changes === 1)
|
|
54
|
+
return { kind: 'reserved', record };
|
|
55
|
+
const owner = this.owner(record.canonicalPath);
|
|
56
|
+
if (!owner)
|
|
57
|
+
throw new Error('ORG_PLAN_RESERVATION_CONFLICT');
|
|
58
|
+
return { kind: 'owned', record: owner };
|
|
59
|
+
});
|
|
38
60
|
}
|
|
39
61
|
save(record, expected) {
|
|
40
62
|
return (this.db
|
|
@@ -47,10 +69,15 @@ export class SqliteOrgPlanLaunchStore {
|
|
|
47
69
|
.run(record.launchId, record.sessionId, record.canonicalPath);
|
|
48
70
|
}
|
|
49
71
|
acquireOwner(record) {
|
|
50
|
-
this.
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
72
|
+
return this.activationTransaction(() => {
|
|
73
|
+
const owner = this.workspaceOwner(record.context.workspace.path);
|
|
74
|
+
if (owner && owner.launchId !== record.launchId)
|
|
75
|
+
return false;
|
|
76
|
+
this.db
|
|
77
|
+
.prepare('UPDATE OR IGNORE org_plan_launches SET canonical_path=? WHERE launch_id=? AND session_id=? AND canonical_path IS NULL')
|
|
78
|
+
.run(record.canonicalPath, record.launchId, record.sessionId);
|
|
79
|
+
return this.owner(record.canonicalPath)?.launchId === record.launchId;
|
|
80
|
+
});
|
|
54
81
|
}
|
|
55
82
|
publishSession(record, candidate, sessions) {
|
|
56
83
|
this.db.exec('BEGIN IMMEDIATE');
|