gestalt-mobile 0.69.0 → 0.69.1

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.
@@ -2619,9 +2619,14 @@ export async function composeRelayApp(options) {
2619
2619
  }
2620
2620
  await detachActiveSessions();
2621
2621
  });
2622
- app.addHook('onClose', async () => {
2622
+ // HTTP close waits for accepted requests. A provider that never answers a
2623
+ // history RPC must not keep us from reaching the normal runtime cleanup.
2624
+ app.addHook('preClose', async () => {
2623
2625
  closing = true;
2624
2626
  providerRecovery.dispose();
2627
+ runtime?.cancelHistoryReads();
2628
+ });
2629
+ app.addHook('onClose', async () => {
2625
2630
  await hostTests?.close();
2626
2631
  await forgetSessions.drain();
2627
2632
  await retrievalCapability.close?.();
@@ -167,6 +167,7 @@ export class CodexSessionRuntime {
167
167
  void _legacyRequestTimeoutMs;
168
168
  }
169
169
  sessions = new Map();
170
+ historyShutdown = new AbortController();
170
171
  historyReads = new Map();
171
172
  childTopologyReads = new Map();
172
173
  writerAcquisitions = new Map();
@@ -345,6 +346,7 @@ export class CodexSessionRuntime {
345
346
  }
346
347
  /** Releases all relay-owned app-server children during graceful shutdown. */
347
348
  stopAll() {
349
+ this.cancelHistoryReads();
348
350
  // Exit delivery can already be queued when shutdown begins. Declare the
349
351
  // shared intent for every owner before closing any process.
350
352
  const resources = [...this.sessions.values()];
@@ -358,6 +360,8 @@ export class CodexSessionRuntime {
358
360
  this.retrieval?.release?.(resource.sessionId);
359
361
  }
360
362
  async drainReleases() {
363
+ if (this.historyShutdown.signal.aborted)
364
+ await Promise.allSettled([...this.historyReads.values()]);
361
365
  await Promise.allSettled([...this.liveResources.values()].flatMap((resources) => [...resources].map((resource) => {
362
366
  resource.beginExplicitShutdown();
363
367
  resource.dispose();
@@ -826,12 +830,32 @@ export class CodexSessionRuntime {
826
830
  process.close();
827
831
  }
828
832
  }
833
+ /** Unblock HTTP history requests before the server waits for them to drain. */
834
+ cancelHistoryReads() {
835
+ this.historyShutdown.abort(new Error('CODEX_APP_SERVER_CLOSED'));
836
+ }
837
+ async historyUntilShutdown(read) {
838
+ const signal = this.historyShutdown.signal;
839
+ signal.throwIfAborted();
840
+ let cancel;
841
+ const cancelled = new Promise((_, reject) => {
842
+ cancel = () => reject(signal.reason);
843
+ signal.addEventListener('abort', cancel, { once: true });
844
+ });
845
+ try {
846
+ return await Promise.race([read(), cancelled]);
847
+ }
848
+ finally {
849
+ signal.removeEventListener('abort', cancel);
850
+ }
851
+ }
829
852
  async readHistory(session) {
830
853
  if (!session.threadId)
831
854
  throw new Error('CODEX_THREAD_ID_MISSING');
855
+ this.historyShutdown.signal.throwIfAborted();
832
856
  const owned = this.sessions.get(session.id);
833
857
  if (owned)
834
- return this.decodeHistory(owned.process, session.threadId, owned);
858
+ return this.historyUntilShutdown(() => this.decodeHistory(owned.process, session.threadId, owned));
835
859
  const existing = this.historyReads.get(session.id);
836
860
  if (existing)
837
861
  return existing;
@@ -1255,14 +1279,19 @@ export class CodexSessionRuntime {
1255
1279
  cwd: this.readerCwd ?? session.workspacePath,
1256
1280
  });
1257
1281
  try {
1258
- await process.rpc.request('initialize', {
1259
- clientInfo: { name: 'gestalt-mobile', version: '0.1.0' },
1260
- capabilities: { experimentalApi: true },
1282
+ return await this.historyUntilShutdown(async () => {
1283
+ await process.rpc.request('initialize', {
1284
+ clientInfo: { name: 'gestalt-mobile', version: '0.1.0' },
1285
+ capabilities: { experimentalApi: true },
1286
+ });
1287
+ return this.decodeHistory(process, session.threadId);
1261
1288
  });
1262
- return await this.decodeHistory(process, session.threadId);
1263
1289
  }
1264
1290
  finally {
1265
- process.close();
1291
+ if (this.historyShutdown.signal.aborted && process.closeAndWait)
1292
+ await process.closeAndWait();
1293
+ else
1294
+ process.close();
1266
1295
  }
1267
1296
  }
1268
1297
  async decodeHistory(process, threadId, resource) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gestalt-mobile",
3
- "version": "0.69.0",
3
+ "version": "0.69.1",
4
4
  "description": "Mobile-first web relay for durable Codex development sessions",
5
5
  "keywords": [
6
6
  "codex",