gestalt-mobile 0.70.0 → 0.70.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.
@@ -16,7 +16,7 @@ SPDX-License-Identifier: AGPL-3.0-or-later
16
16
  <link rel="icon" href="/icons/gestalt-mobile-192.png" />
17
17
  <link rel="apple-touch-icon" href="/icons/gestalt-mobile-180.png" />
18
18
  <title>Gestalt Mobile</title>
19
- <script type="module" crossorigin src="/assets/index-B0BsvTqL.js"></script>
19
+ <script type="module" crossorigin src="/assets/index-Cd7KiknR.js"></script>
20
20
  <link rel="stylesheet" crossorigin href="/assets/index-Bzd358yL.css">
21
21
  </head>
22
22
  <body>
@@ -23,10 +23,12 @@ import { SqliteAuthorizationStore } from './platform/auth/sqlite-authorization-s
23
23
  import { SqliteEventJournal } from './platform/persistence/sqlite-event-journal.js';
24
24
  import { SqliteIdempotencyStore } from './platform/persistence/sqlite-idempotency-store.js';
25
25
  import { SqliteOrgPlanLaunchStore } from './platform/persistence/sqlite-org-plan-launch-store.js';
26
+ import { SqliteSupervisionTakeoverStore } from './platform/persistence/sqlite-supervision-takeover-store.js';
26
27
  import { SqliteSessionRepository } from './platform/persistence/sqlite-session-repository.js';
27
28
  import { RelaySession } from './features/sessions/model/relay-session.js';
28
29
  import { SqliteAutopilotStore } from './platform/persistence/sqlite-autopilot-store.js';
29
30
  import { startSupervisionProtocol } from './features/autopilot/domain/supervision-protocol.js';
31
+ import { disabledAutopilot } from './features/autopilot/domain/autopilot-session.js';
30
32
  import { exportControlPlaneTrace } from './features/control-plane-trace/export-trace.js';
31
33
  import { authorizationSessionId, authorizedDeviceId, localOwnerId, webAuthnCredentialId, } from './features/auth/domain/identifiers.js';
32
34
  import { deviceNickname } from './features/auth/domain/device-nickname.js';
@@ -6005,6 +6007,155 @@ describe('production composition', () => {
6005
6007
  });
6006
6008
  });
6007
6009
  describeCompositionConcern('lifecycle', () => {
6010
+ it.each(['stop', 'release'])('releases supervisor reservations after %s while retaining history and scratch across restart', async (operation) => {
6011
+ const f = await orgPlanActivationFixture('codex-cli 0.167.0');
6012
+ let app = await f.open();
6013
+ try {
6014
+ const payload = await f.prepare(app);
6015
+ const launched = (await app.inject({ method: 'POST', url: '/api/plans/execute', payload })).json();
6016
+ expect(launched).toMatchObject({ kind: 'started' });
6017
+ const id = launched.session.id;
6018
+ const identity = f.database((db) => {
6019
+ const record = new SqliteOrgPlanLaunchStore(db).forSession(id);
6020
+ const identity = createHash('sha256').update(record.canonicalPath).digest('hex');
6021
+ new SqliteSupervisionTakeoverStore(db, new SqliteAutopilotStore(db)).claim(identity, id);
6022
+ return identity;
6023
+ });
6024
+ const marker = join(f.workspacePath, 'tmp', 'retained-on-close.txt');
6025
+ await writeFile(marker, 'keep');
6026
+ expect(f.database((db) => new SqliteOrgPlanLaunchStore(db).workspaceOwner(f.workspacePath)?.sessionId)).toBe(id);
6027
+ expect((await app.inject({ method: 'POST', url: `/api/sessions/${id}/${operation}` }))
6028
+ .statusCode).toBe(202);
6029
+ expect(f.database((db) => new SqliteOrgPlanLaunchStore(db).workspaceOwner(f.workspacePath))).toBeNull();
6030
+ expect(f.database((db) => new SqliteSupervisionTakeoverStore(db, new SqliteAutopilotStore(db)).owner(identity))).toBeNull();
6031
+ expect((await app.inject(`/api/sessions/${id}`)).statusCode).toBe(200);
6032
+ expect(await readFile(marker, 'utf8')).toBe('keep');
6033
+ await app.close();
6034
+ app = await f.open();
6035
+ const next = await createComposedSession(app);
6036
+ expect(next).not.toBe(id);
6037
+ expect((await app.inject({ method: 'POST', url: `/api/sessions/${next}/stop` })).statusCode).toBe(202);
6038
+ const prepared = (await app.inject({
6039
+ method: 'POST',
6040
+ url: '/api/plans/prepare',
6041
+ payload: payload.reference,
6042
+ })).json();
6043
+ expect(prepared).toMatchObject({ kind: 'eligible' });
6044
+ const restarted = (await app.inject({
6045
+ method: 'POST',
6046
+ url: '/api/plans/execute',
6047
+ payload: {
6048
+ ...payload,
6049
+ expectedRevision: prepared.revision,
6050
+ launchId: `next-${operation}`,
6051
+ },
6052
+ })).json();
6053
+ expect(restarted).toMatchObject({ kind: 'started' });
6054
+ expect(restarted.session.id).not.toBe(id);
6055
+ }
6056
+ finally {
6057
+ await app.close();
6058
+ }
6059
+ });
6060
+ it('keeps the reservation until Close has confirmed runtime shutdown', async () => {
6061
+ const f = await orgPlanActivationFixture('codex-cli 0.167.0');
6062
+ const app = await f.open();
6063
+ const gate = Promise.withResolvers();
6064
+ const original = CodexSessionRuntime.prototype.releaseForForget;
6065
+ let pending;
6066
+ let held = false;
6067
+ const spy = vi
6068
+ .spyOn(CodexSessionRuntime.prototype, 'releaseForForget')
6069
+ .mockImplementationOnce(async function (session) {
6070
+ held = true;
6071
+ await gate.promise;
6072
+ return original.call(this, session);
6073
+ });
6074
+ try {
6075
+ const payload = await f.prepare(app);
6076
+ const launched = (await app.inject({ method: 'POST', url: '/api/plans/execute', payload })).json();
6077
+ expect(launched).toMatchObject({ kind: 'started' });
6078
+ const id = launched.session.id;
6079
+ pending = Promise.resolve(app.inject({ method: 'POST', url: `/api/sessions/${id}/release` }));
6080
+ await expect.poll(() => held, { timeout: 2_000 }).toBe(true);
6081
+ expect(f.database((db) => new SqliteOrgPlanLaunchStore(db).workspaceOwner(f.workspacePath)?.sessionId)).toBe(id);
6082
+ const blocked = await app.inject({
6083
+ method: 'POST',
6084
+ url: '/api/sessions',
6085
+ payload: {
6086
+ workspaceId: payload.reference.workspaceId,
6087
+ profile: 'default',
6088
+ provider: 'codex',
6089
+ },
6090
+ });
6091
+ expect(blocked.statusCode).toBe(409);
6092
+ expect(blocked.json()).toMatchObject({ code: 'SESSION_WORKSPACE_LOCKED' });
6093
+ gate.resolve();
6094
+ expect((await pending).statusCode).toBe(202);
6095
+ expect(await createComposedSession(app)).not.toBe(id);
6096
+ }
6097
+ finally {
6098
+ gate.resolve();
6099
+ await pending?.catch(() => undefined);
6100
+ spy.mockRestore();
6101
+ await app.close();
6102
+ }
6103
+ });
6104
+ it('retains reservations when Close cannot confirm runtime shutdown and releases them on retry', async () => {
6105
+ const f = await orgPlanActivationFixture('codex-cli 0.167.0');
6106
+ const app = await f.open();
6107
+ const spy = vi.spyOn(CodexSessionRuntime.prototype, 'releaseForForget');
6108
+ try {
6109
+ const payload = await f.prepare(app);
6110
+ const launched = (await app.inject({ method: 'POST', url: '/api/plans/execute', payload })).json();
6111
+ expect(launched).toMatchObject({ kind: 'started' });
6112
+ const id = launched.session.id;
6113
+ spy.mockRejectedValueOnce(new Error('SESSION_RELEASE_UNCONFIRMED'));
6114
+ expect((await app.inject({ method: 'POST', url: `/api/sessions/${id}/release` })).statusCode).toBe(500);
6115
+ expect(f.database((db) => new SqliteOrgPlanLaunchStore(db).workspaceOwner(f.workspacePath)?.sessionId)).toBe(id);
6116
+ expect((await app.inject({ method: 'POST', url: `/api/sessions/${id}/release` })).statusCode).toBe(202);
6117
+ expect(f.database((db) => new SqliteOrgPlanLaunchStore(db).workspaceOwner(f.workspacePath))).toBeNull();
6118
+ expect(await createComposedSession(app)).not.toBe(id);
6119
+ }
6120
+ finally {
6121
+ spy.mockRestore();
6122
+ await app.close();
6123
+ }
6124
+ });
6125
+ it('keeps a retired supervisor fenced after its successor releases the reservation', async () => {
6126
+ const f = await orgPlanActivationFixture('codex-cli 0.167.0');
6127
+ const app = await f.open();
6128
+ try {
6129
+ const payload = await f.prepare(app);
6130
+ const launched = (await app.inject({ method: 'POST', url: '/api/plans/execute', payload })).json();
6131
+ expect(launched).toMatchObject({ kind: 'started' });
6132
+ const id = launched.session.id;
6133
+ expect((await app.inject({ method: 'POST', url: `/api/sessions/${id}/release` })).statusCode).toBe(202);
6134
+ f.database((db) => {
6135
+ const launch = new SqliteOrgPlanLaunchStore(db).forSession(id);
6136
+ const identity = createHash('sha256').update(launch.canonicalPath).digest('hex');
6137
+ const autopilot = new SqliteAutopilotStore(db);
6138
+ const state = autopilot.find(id) ?? disabledAutopilot(id, new Date().toISOString());
6139
+ autopilot.save({ ...state, planIdentity: identity });
6140
+ const takeover = new SqliteSupervisionTakeoverStore(db, autopilot);
6141
+ const successor = takeover.claim(identity, 'successor');
6142
+ expect(takeover.retire(successor, [id])).toBe(true);
6143
+ takeover.releaseSession('successor');
6144
+ });
6145
+ const turnsBefore = f.requests('turn/start').length;
6146
+ const resumed = await app.inject({
6147
+ method: 'POST',
6148
+ url: `/api/sessions/${id}/turns`,
6149
+ payload: { text: 'Continue work' },
6150
+ });
6151
+ expect(resumed.statusCode).toBe(409);
6152
+ expect(resumed.json()).toMatchObject({ code: 'SESSION_SUPERVISOR_REPLACED' });
6153
+ expect(f.requests('turn/start')).toHaveLength(turnsBefore);
6154
+ }
6155
+ finally {
6156
+ await app.close();
6157
+ }
6158
+ });
6008
6159
  it('requires the prior session to stop, then fences it while a supervisor owns its workspace', async () => {
6009
6160
  const f = await orgPlanActivationFixture('codex-cli 0.167.0');
6010
6161
  const app = await f.open();
@@ -220,6 +220,8 @@ export async function composeRelayApp(options) {
220
220
  const supervisorOwnership = (sessionId) => {
221
221
  const identity = supervisedPlans.identity(sessionId) ?? autopilotStore.find(sessionId)?.planIdentity;
222
222
  const owner = identity ? takeoverStore.owner(identity) : null;
223
+ if (identity && owner?.sessionId !== sessionId && takeoverStore.retired(identity, sessionId))
224
+ return 'replaced';
223
225
  const path = sessions.find(sessionId)?.lastOrgPlan?.path;
224
226
  const launchOwner = path ? orgPlanLaunches.owner(path) : null;
225
227
  if (!owner && launchOwner && launchOwner.sessionId !== sessionId)
@@ -1001,9 +1003,10 @@ export async function composeRelayApp(options) {
1001
1003
  title: update.plan.title,
1002
1004
  path: update.planPath,
1003
1005
  attached: true,
1004
- supervision: (takeoverOwner
1005
- ? takeoverOwner.sessionId === sessionId
1006
- : !launchOwner || launchOwner.sessionId === sessionId) &&
1006
+ supervision: session.desiredState !== 'stopped' &&
1007
+ (takeoverOwner
1008
+ ? takeoverOwner.sessionId === sessionId
1009
+ : !launchOwner || launchOwner.sessionId === sessionId) &&
1007
1010
  planAttachmentSupervision(session.lastOrgPlan, update, execution?.planIdentity === update.identity && !!execution.supervision),
1008
1011
  },
1009
1012
  updatedAt: occurredAt,
@@ -1940,13 +1943,16 @@ export async function composeRelayApp(options) {
1940
1943
  if (pending && !reclaimableLaunchOwner(pending) && !ownUnpublished)
1941
1944
  return {
1942
1945
  ...(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.',
1946
+ reason: 'This plan or an overlapping workspace is reserved by another supervisor. Open its session to continue, or close it to release the reservation.',
1944
1947
  };
1945
1948
  const busy = workspaceBusy(workspacePath);
1946
1949
  if (busy && busy.sessionId !== pending?.sessionId)
1947
1950
  return busy;
1948
1951
  const identity = createHash('sha256').update(canonicalPath).digest('hex');
1949
1952
  const owner = sessions.list().find((session) => {
1953
+ if (session.desiredState === 'stopped' &&
1954
+ ['stopped', 'released'].includes(session.state))
1955
+ return false;
1950
1956
  if (!session.lastOrgPlan?.attached || session.lastOrgPlan.path !== canonicalPath)
1951
1957
  return false;
1952
1958
  const execution = autopilotStore.find(session.id);
@@ -2376,6 +2382,12 @@ export async function composeRelayApp(options) {
2376
2382
  if (session && owner)
2377
2383
  await owner.releaseForForget(session);
2378
2384
  await playwright.waitForRelease(id);
2385
+ const current = sessions.find(id);
2386
+ if (current?.desiredState === 'stopped' &&
2387
+ ['stopped', 'released'].includes(current.state)) {
2388
+ orgPlanLaunches.releaseSession(id);
2389
+ takeoverStore.releaseSession(id);
2390
+ }
2379
2391
  }
2380
2392
  : undefined,
2381
2393
  replyInteraction: runtime || kimiRuntime
@@ -18,7 +18,7 @@ export function writerAcquisitionProblem(kind) {
18
18
  status: 409,
19
19
  code: 'SESSION_WORKSPACE_LOCKED',
20
20
  retryable: false,
21
- detail: 'An Org-plan supervisor owns this workspace. Continue in its session, or forget that session to release the reservation.',
21
+ detail: 'An Org-plan supervisor owns this workspace. Continue in its session, or close that session to release the reservation.',
22
22
  };
23
23
  case 'supervisorReplaced':
24
24
  return {
@@ -25,6 +25,7 @@ import { registerStopSession } from './stop-session/endpoint.js';
25
25
  import { registerRefreshActivity } from './refresh-activity/endpoint.js';
26
26
  import { registerGetRetrievalReadiness } from './get-retrieval-readiness/endpoint.js';
27
27
  import { registerCleanTmp } from './clean-tmp/endpoint.js';
28
+ import { WriterAcquisitionError, writerAcquisitionProblem, } from './application/writer-acquisition.js';
28
29
  export function registerSessionRoutes(app, deps) {
29
30
  const sessions = deps.sessionRoutes;
30
31
  registerCleanTmp(app, deps.tmpCleanup);
@@ -191,6 +192,8 @@ export function registerSessionRoutes(app, deps) {
191
192
  });
192
193
  }
193
194
  function safeErrorLabel(error) {
195
+ if (error instanceof WriterAcquisitionError)
196
+ return writerAcquisitionProblem(error.kind).code;
194
197
  if (typeof error === 'object' && error !== null && 'code' in error) {
195
198
  const code = error.code;
196
199
  if (typeof code === 'string' && /^[A-Z0-9_]+$/.test(code))
@@ -38,6 +38,9 @@ export function registerStartSession(app, deps) {
38
38
  .type('application/problem+json')
39
39
  .send(problem(failure.code, failure.status, failure.detail, failure.retryable));
40
40
  }
41
+ const knownFailure = error instanceof Error ? sessionStartProblem(error.message) : null;
42
+ if (knownFailure)
43
+ return reply.code(knownFailure.status).type('application/problem+json').send(knownFailure);
41
44
  if (error instanceof Error && error.message === 'CODEX_EXECUTOR_MODEL_UNAVAILABLE')
42
45
  return reply
43
46
  .code(400)
@@ -70,3 +73,19 @@ export function registerStartSession(app, deps) {
70
73
  return reply.code(202).send(started);
71
74
  });
72
75
  }
76
+ /** Public guidance is allowlisted; runtime messages can contain private paths or credentials. */
77
+ function sessionStartProblem(code) {
78
+ switch (code) {
79
+ case 'CODEX_MODEL_UNAVAILABLE':
80
+ case 'KIMI_MODEL_UNAVAILABLE':
81
+ return problem(code, 400, 'The selected model is unavailable. Choose an available model in New session settings and retry.', true);
82
+ case 'WORKSPACE_NOT_FOUND':
83
+ return problem(code, 404, 'The selected workspace is no longer available. Select an existing workspace and retry.', true);
84
+ case 'PROFILE_NOT_FOUND':
85
+ return problem(code, 400, 'The selected launcher profile is unavailable. Refresh New session settings and retry.', true);
86
+ case 'LLM_RUNTIME_UNAVAILABLE':
87
+ return problem(code, 503, 'The selected provider runtime is unavailable. Check the provider installation and authentication, then retry.', true);
88
+ default:
89
+ return null;
90
+ }
91
+ }
@@ -68,6 +68,11 @@ export class SqliteOrgPlanLaunchStore {
68
68
  .prepare('UPDATE org_plan_launches SET canonical_path=NULL WHERE launch_id=? AND session_id=? AND canonical_path=?')
69
69
  .run(record.launchId, record.sessionId, record.canonicalPath);
70
70
  }
71
+ releaseSession(sessionId) {
72
+ this.db
73
+ .prepare('UPDATE org_plan_launches SET canonical_path=NULL WHERE session_id=?')
74
+ .run(sessionId);
75
+ }
71
76
  acquireOwner(record) {
72
77
  return this.activationTransaction(() => {
73
78
  const owner = this.workspaceOwner(record.context.workspace.path);
@@ -13,12 +13,18 @@ export class SqliteSupervisionTakeoverStore {
13
13
  }
14
14
  owner(planIdentity) {
15
15
  const row = this.db
16
- .prepare('SELECT session_id,epoch,phase FROM org_plan_takeovers WHERE plan_identity=?')
16
+ .prepare("SELECT session_id,epoch,phase FROM org_plan_takeovers WHERE plan_identity=? AND phase!='released'")
17
17
  .get(planIdentity);
18
18
  return row
19
19
  ? { planIdentity, sessionId: row.session_id, epoch: row.epoch, phase: row.phase }
20
20
  : null;
21
21
  }
22
+ /** Keep the epoch tombstone and retired-writer fences after confirmed runtime release. */
23
+ releaseSession(sessionId) {
24
+ this.db
25
+ .prepare("UPDATE org_plan_takeovers SET phase='released',epoch=epoch+1 WHERE session_id=? AND phase!='released'")
26
+ .run(sessionId);
27
+ }
22
28
  retired(planIdentity, sessionId) {
23
29
  return Boolean(this.db
24
30
  .prepare('SELECT 1 FROM org_plan_retired_supervisors WHERE plan_identity=? AND session_id=?')
@@ -71,7 +77,10 @@ export class SqliteSupervisionTakeoverStore {
71
77
  return null;
72
78
  }
73
79
  }
74
- const epoch = previous?.sessionId === sessionId ? previous.epoch : (previous?.epoch ?? 0) + 1;
80
+ const retained = this.db
81
+ .prepare('SELECT epoch FROM org_plan_takeovers WHERE plan_identity=?')
82
+ .get(planIdentity);
83
+ const epoch = previous?.sessionId === sessionId ? previous.epoch : (retained?.epoch ?? 0) + 1;
75
84
  const phase = previous?.sessionId === sessionId ? previous.phase : 'stopping';
76
85
  this.db
77
86
  .prepare('INSERT INTO org_plan_takeovers (plan_identity,session_id,epoch,phase) VALUES (?,?,?,?) ON CONFLICT(plan_identity) DO UPDATE SET session_id=excluded.session_id,epoch=excluded.epoch,phase=excluded.phase')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gestalt-mobile",
3
- "version": "0.70.0",
3
+ "version": "0.70.2",
4
4
  "description": "Mobile-first web relay for durable Codex development sessions",
5
5
  "keywords": [
6
6
  "codex",