gestalt-mobile 0.72.2 → 0.72.3
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.
|
@@ -9469,6 +9469,103 @@ describe('production composition', () => {
|
|
|
9469
9469
|
});
|
|
9470
9470
|
await third.close();
|
|
9471
9471
|
}, 20000);
|
|
9472
|
+
it.each(['initialize', 'thread/start'])('releases a failed %s start so a new session can use the same workspace', async (failedMethod) => {
|
|
9473
|
+
const root = await mkdtemp(join(tmpdir(), 'gestalt-mobile-root-'));
|
|
9474
|
+
const dataDir = await mkdtemp(join(tmpdir(), 'gestalt-mobile-state-'));
|
|
9475
|
+
ownTemporaryPaths(root, dataDir);
|
|
9476
|
+
await mkdir(join(root, 'workspace'));
|
|
9477
|
+
let fail = true;
|
|
9478
|
+
const released = vi.fn(async () => { });
|
|
9479
|
+
const app = await composeAuthorizedApp({
|
|
9480
|
+
root,
|
|
9481
|
+
dataDir,
|
|
9482
|
+
relyingParty,
|
|
9483
|
+
profiles: {
|
|
9484
|
+
list: async () => [],
|
|
9485
|
+
require: async () => ({ name: 'default', state: 'ok', status: 'ready' }),
|
|
9486
|
+
},
|
|
9487
|
+
installedCodexVersion: 'codex-cli 0.167.2',
|
|
9488
|
+
startAppServers: true,
|
|
9489
|
+
launchAppServer: (options) => {
|
|
9490
|
+
const process = fakeAppServer([]);
|
|
9491
|
+
return {
|
|
9492
|
+
...process,
|
|
9493
|
+
closeAndWait: released,
|
|
9494
|
+
rpc: {
|
|
9495
|
+
...process.rpc,
|
|
9496
|
+
request: async (method, params) => {
|
|
9497
|
+
if (options.environment && fail && method === failedMethod) {
|
|
9498
|
+
fail = false;
|
|
9499
|
+
throw new CodexJsonRpcError(-32600, 'Invalid startup settings');
|
|
9500
|
+
}
|
|
9501
|
+
return process.rpc.request(method, params);
|
|
9502
|
+
},
|
|
9503
|
+
},
|
|
9504
|
+
};
|
|
9505
|
+
},
|
|
9506
|
+
});
|
|
9507
|
+
try {
|
|
9508
|
+
const workspace = (await app.inject('/api/bootstrap')).json().workspaces[0].children[0];
|
|
9509
|
+
const payload = { workspaceId: workspace.id, profile: 'default', provider: 'codex' };
|
|
9510
|
+
const failed = await app.inject({ method: 'POST', url: '/api/sessions', payload });
|
|
9511
|
+
expect(failed.statusCode).toBe(500);
|
|
9512
|
+
const db = new DatabaseSync(join(dataDir, 'relay.sqlite'));
|
|
9513
|
+
try {
|
|
9514
|
+
expect(db.prepare('SELECT state,desired_state,thread_id FROM relay_sessions').all()).toEqual([{ state: 'stopped', desired_state: 'stopped', thread_id: null }]);
|
|
9515
|
+
}
|
|
9516
|
+
finally {
|
|
9517
|
+
db.close();
|
|
9518
|
+
}
|
|
9519
|
+
expect(released).toHaveBeenCalled();
|
|
9520
|
+
const retry = await app.inject({ method: 'POST', url: '/api/sessions', payload });
|
|
9521
|
+
expect(retry.statusCode).toBe(202);
|
|
9522
|
+
expect(retry.json()).toMatchObject({ state: 'ready', threadId: 'thread-1' });
|
|
9523
|
+
}
|
|
9524
|
+
finally {
|
|
9525
|
+
await app.close();
|
|
9526
|
+
}
|
|
9527
|
+
});
|
|
9528
|
+
it.each(['starting', 'recovering'])('clears a persisted %s session without a thread when the relay restarts', async (state) => {
|
|
9529
|
+
const root = await mkdtemp(join(tmpdir(), 'gestalt-mobile-root-'));
|
|
9530
|
+
const dataDir = await mkdtemp(join(tmpdir(), 'gestalt-mobile-state-'));
|
|
9531
|
+
ownTemporaryPaths(root, dataDir);
|
|
9532
|
+
await mkdir(join(root, 'workspace'));
|
|
9533
|
+
const options = {
|
|
9534
|
+
root,
|
|
9535
|
+
dataDir,
|
|
9536
|
+
relyingParty,
|
|
9537
|
+
profiles: {
|
|
9538
|
+
list: async () => [],
|
|
9539
|
+
require: async () => ({ name: 'default', state: 'ok', status: 'ready' }),
|
|
9540
|
+
},
|
|
9541
|
+
installedCodexVersion: 'codex-cli 0.167.2',
|
|
9542
|
+
startAppServers: false,
|
|
9543
|
+
launchAppServer: () => fakeAppServer([]),
|
|
9544
|
+
};
|
|
9545
|
+
const first = await composeAuthorizedApp(options);
|
|
9546
|
+
const workspace = (await first.inject('/api/bootstrap')).json().workspaces[0].children[0];
|
|
9547
|
+
const payload = { workspaceId: workspace.id, profile: 'default', provider: 'codex' };
|
|
9548
|
+
const created = await first.inject({ method: 'POST', url: '/api/sessions', payload });
|
|
9549
|
+
expect(created.statusCode).toBe(202);
|
|
9550
|
+
await first.close();
|
|
9551
|
+
const db = new DatabaseSync(join(dataDir, 'relay.sqlite'));
|
|
9552
|
+
try {
|
|
9553
|
+
db.prepare('UPDATE relay_sessions SET state=? WHERE id=?').run(state, created.json().id);
|
|
9554
|
+
}
|
|
9555
|
+
finally {
|
|
9556
|
+
db.close();
|
|
9557
|
+
}
|
|
9558
|
+
const restarted = await composeAuthorizedApp(options);
|
|
9559
|
+
try {
|
|
9560
|
+
await restarted.listen({ host: '127.0.0.1', port: 0 });
|
|
9561
|
+
expect((await restarted.inject(`/api/sessions/${created.json().id}`)).json()).toMatchObject({ state: 'stopped', desiredState: 'stopped', threadId: null });
|
|
9562
|
+
const retry = await restarted.inject({ method: 'POST', url: '/api/sessions', payload });
|
|
9563
|
+
expect(retry.statusCode).toBe(202);
|
|
9564
|
+
}
|
|
9565
|
+
finally {
|
|
9566
|
+
await restarted.close();
|
|
9567
|
+
}
|
|
9568
|
+
});
|
|
9472
9569
|
it('detaches active persisted threads when the relay restarts without resuming a writer', async () => {
|
|
9473
9570
|
const root = await mkdtemp(join(tmpdir(), 'gestalt-mobile-root-'));
|
|
9474
9571
|
const dataDir = await mkdtemp(join(tmpdir(), 'gestalt-mobile-state-'));
|
|
@@ -1786,9 +1786,22 @@ export async function composeRelayApp(options) {
|
|
|
1786
1786
|
const now = new Date().toISOString();
|
|
1787
1787
|
dismissPendingInteractions(session.id, now);
|
|
1788
1788
|
const owner = ownerRuntime(session);
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1789
|
+
return withWorkspaceAdmission(session.id, async () => {
|
|
1790
|
+
try {
|
|
1791
|
+
if (!owner)
|
|
1792
|
+
throw new Error('LLM_RUNTIME_UNAVAILABLE');
|
|
1793
|
+
return await owner.start(session, now);
|
|
1794
|
+
}
|
|
1795
|
+
catch (error) {
|
|
1796
|
+
// Publication and scratch admission precede provider startup.
|
|
1797
|
+
// Release its resources before allowing another workspace writer.
|
|
1798
|
+
await owner?.releaseForForget(session);
|
|
1799
|
+
const current = sessions.find(session.id);
|
|
1800
|
+
if (current && current.desiredState === 'active')
|
|
1801
|
+
saveSession(RelaySession.rehydrate(current).stop(new Date().toISOString()).snapshot);
|
|
1802
|
+
throw error;
|
|
1803
|
+
}
|
|
1804
|
+
});
|
|
1792
1805
|
}
|
|
1793
1806
|
: undefined,
|
|
1794
1807
|
};
|
|
@@ -2590,9 +2603,7 @@ export async function composeRelayApp(options) {
|
|
|
2590
2603
|
throw error;
|
|
2591
2604
|
}
|
|
2592
2605
|
const detachActiveSessions = async () => {
|
|
2593
|
-
await mapWithConcurrency(sessions
|
|
2594
|
-
.list()
|
|
2595
|
-
.filter((session) => persistedSessionIds.has(session.id) && session.threadId !== null), 2, async (session) => {
|
|
2606
|
+
await mapWithConcurrency(sessions.list().filter((session) => persistedSessionIds.has(session.id)), 2, async (session) => {
|
|
2596
2607
|
if (forgetOperations.find(session.id))
|
|
2597
2608
|
return;
|
|
2598
2609
|
// The status lease must repopulate the authoritative plan projection before
|
|
@@ -2602,6 +2613,10 @@ export async function composeRelayApp(options) {
|
|
|
2602
2613
|
saveSession(RelaySession.rehydrate(session).stop(new Date().toISOString()).snapshot);
|
|
2603
2614
|
await (session.provider === 'kimi' ? kimiRuntime : runtime)?.release(session.id);
|
|
2604
2615
|
}
|
|
2616
|
+
// An interrupted initial start has no thread to watch or resume, but
|
|
2617
|
+
// its durable active reservation must still be detached on restart.
|
|
2618
|
+
if (session.threadId === null)
|
|
2619
|
+
return;
|
|
2605
2620
|
await runtime?.watchPlanStatus(session);
|
|
2606
2621
|
autopilot.restore(session.id);
|
|
2607
2622
|
// A prior process cannot resolve its original JSON-RPC request. Turn
|