gestalt-mobile 0.65.3 → 0.65.4

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.
@@ -388,6 +388,116 @@ async function createUnauthorizedProductionApp(root, dataDir) {
388
388
  }
389
389
  describe('production composition', () => {
390
390
  describeCompositionConcern('autopilot', () => {
391
+ it('persists a bounded executor after 64 exited results and new active work, including a plan watcher update', async () => {
392
+ const handles = [];
393
+ const launch = liveAppServer(handles);
394
+ const diagnostic = vi.fn();
395
+ let coordinator;
396
+ const old = Array.from({ length: 64 }, (_, n) => ({
397
+ itemId: `old-item-${n}`,
398
+ processId: `old-${n}`,
399
+ }));
400
+ let active = old;
401
+ const fixture = await createProductionAutopilotFixture({
402
+ activitySchedule: () => () => { },
403
+ autopilotSchedule: () => () => { },
404
+ activityDiagnostic: diagnostic,
405
+ onAutopilotCoordinator: (value) => {
406
+ coordinator = value;
407
+ },
408
+ launchAppServer: () => {
409
+ const server = launch();
410
+ handles.at(-1).respond = (method, params) => {
411
+ if (method === 'thread/list')
412
+ return {
413
+ data: [
414
+ {
415
+ id: 'child-1',
416
+ status: { type: 'idle' },
417
+ source: { subAgent: { thread_spawn: { agent_path: '/root/l1' } } },
418
+ },
419
+ ],
420
+ };
421
+ if (method === 'thread/backgroundTerminals/list')
422
+ return { data: active, nextCursor: null };
423
+ if (method === 'thread/read' && params.threadId === 'child-1')
424
+ return {
425
+ thread: {
426
+ id: 'child-1',
427
+ turns: [
428
+ {
429
+ items: old.map((item) => ({
430
+ id: item.itemId,
431
+ type: 'commandExecution',
432
+ status: 'completed',
433
+ exitCode: 0,
434
+ })),
435
+ },
436
+ ],
437
+ },
438
+ };
439
+ return undefined;
440
+ };
441
+ return server;
442
+ },
443
+ });
444
+ onTestFinished(() => fixture.app.close());
445
+ const rootThreadId = (await fixture.app.inject(`/api/sessions/${fixture.sessionId}`)).json()
446
+ .threadId;
447
+ handles.find((handle) => handle.calls.includes('thread/start')).notify({
448
+ method: 'thread/started',
449
+ params: { thread: { id: rootThreadId, status: { type: 'idle' } } },
450
+ });
451
+ const database = new DatabaseSync(join(fixture.dataDir, 'relay.sqlite'));
452
+ onTestFinished(() => database.close());
453
+ const executor = () => {
454
+ const row = database
455
+ .prepare('SELECT lifecycle_json FROM autopilot_sessions WHERE session_id = ?')
456
+ .get(fixture.sessionId);
457
+ return JSON.parse(row.lifecycle_json).executor;
458
+ };
459
+ const refresh = async () => {
460
+ const response = await fixture.app.inject({
461
+ method: 'POST',
462
+ url: `/api/sessions/${fixture.sessionId}/activity/refresh`,
463
+ });
464
+ expect(response.statusCode).toBe(202);
465
+ await vi.waitFor(async () => expect((await fixture.app.inject(`/api/sessions/${fixture.sessionId}`)).json()).toMatchObject({
466
+ agentActivity: { confidence: 'fresh' },
467
+ autopilot: { enabled: true },
468
+ }));
469
+ };
470
+ await refresh();
471
+ expect(executor().ownedProcesses).toHaveLength(64);
472
+ active = [];
473
+ await refresh();
474
+ await vi.waitFor(() => {
475
+ expect(coordinator.reconcileExecutorBinding(fixture.sessionId)).toMatchObject({
476
+ status: 'ready',
477
+ });
478
+ expect(executor().ownedProcesses.some((process) => process.state === 'running')).toBe(false);
479
+ expect(executor().ownedProcesses.some((process) => process.state === 'exited-awaiting-result')).toBe(true);
480
+ });
481
+ active = Array.from({ length: 64 }, (_, n) => ({
482
+ itemId: `new-item-${n}`,
483
+ processId: `new-active-${n}`,
484
+ }));
485
+ await refresh();
486
+ await vi.waitFor(() => expect(executor().ownedProcesses[0]).toMatchObject({
487
+ processId: 'new-active-0',
488
+ state: expect.stringMatching(/^(running|detached-active)$/),
489
+ }));
490
+ expect(executor().ownedProcesses).toHaveLength(64);
491
+ await writeFile(join(fixture.workspacePath, 'autopilot.org'), autopilotPlanText('TODO').replace('Parent', 'Updated parent'));
492
+ await vi.waitFor(async () => {
493
+ expect((await fixture.app.inject(`/api/sessions/${fixture.sessionId}/plan`)).json()).toMatchObject({ steps: [{ title: 'Updated parent' }] });
494
+ });
495
+ expect(executor().ownedProcesses).toHaveLength(64);
496
+ expect(diagnostic).not.toHaveBeenCalled();
497
+ expect(database
498
+ .prepare("SELECT count(*) AS count FROM session_events WHERE session_id = ? AND type = 'autopilot.operation-failed'")
499
+ .get(fixture.sessionId)).toMatchObject({ count: 0 });
500
+ });
391
501
  it('serves compact supervision deltas and wakes only for the selected host run', async () => {
392
502
  let coordinator;
393
503
  const f = await createProductionAutopilotFixture({
@@ -61,7 +61,7 @@ import { GitSummaryCache } from './platform/git/git-summary-cache.js';
61
61
  import { SessionSupervisor } from './platform/runtime/session-supervisor.js';
62
62
  import { mapWithConcurrency } from './platform/runtime/concurrency.js';
63
63
  import { RelaySession, } from './features/sessions/model/relay-session.js';
64
- import { AgentActivityRegistry } from './features/agent-activity/registry.js';
64
+ import { AgentActivityRegistry, } from './features/agent-activity/registry.js';
65
65
  import { SupervisionTakeover } from './features/autopilot/application/takeover-supervision.js';
66
66
  import { SqliteSupervisionTakeoverStore } from './platform/persistence/sqlite-supervision-takeover-store.js';
67
67
  import { isOrgPlanTakeoverCall } from '../shared/contracts/org-plan-takeover.js';
@@ -237,7 +237,7 @@ export async function composeRelayApp(options) {
237
237
  }),
238
238
  now: () => new Date().toISOString(),
239
239
  diagnostic: options.activityDiagnostic ??
240
- ((sessionId, code, detail) => console.warn(`agent activity ${code} session=${sessionId} attempt=${detail?.attempt ?? 0} rpcCode=${detail?.rpcCode ?? 'none'}`)),
240
+ ((sessionId, code, detail) => console.warn(`agent activity ${code} session=${sessionId} attempt=${detail?.attempt ?? 0} rpcCode=${detail?.rpcCode ?? 'none'} errorCode=${detail?.errorCode ?? 'none'}`)),
241
241
  reconcile: async (sessionId) => {
242
242
  const session = sessions.find(sessionId);
243
243
  if (!session)
@@ -209,6 +209,13 @@ export class AgentActivityRegistry {
209
209
  this.options.diagnostic?.(sessionId, 'reconcileExhausted', {
210
210
  attempt,
211
211
  ...(rpcCode !== undefined ? { rpcCode } : {}),
212
+ // Fixed controller code only; arbitrary exception text stays private.
213
+ ...(error &&
214
+ typeof error === 'object' &&
215
+ 'code' in error &&
216
+ error.code === 'AUTOPILOT_STATE_INVALID'
217
+ ? { errorCode: 'AUTOPILOT_STATE_INVALID' }
218
+ : {}),
212
219
  });
213
220
  this.disconnected(sessionId, this.options.now?.() ?? now);
214
221
  return;
@@ -1281,6 +1281,16 @@ export class AutopilotCoordinator {
1281
1281
  }
1282
1282
  /** Handles only plan lifecycle safety; ordinary plan mutations are ignored. */
1283
1283
  planStatusChanged(sessionId) {
1284
+ try {
1285
+ this.applyPlanStatusChanged(sessionId);
1286
+ }
1287
+ catch (error) {
1288
+ // Filesystem watchers invoke this synchronous boundary without a caller
1289
+ // that can handle rejection. Use the same durable recovery as queued work.
1290
+ this.containOperationFailure(sessionId, error);
1291
+ }
1292
+ }
1293
+ applyPlanStatusChanged(sessionId) {
1284
1294
  this.reconcileExecutorBinding(sessionId);
1285
1295
  const prior = this.deps.store.find(sessionId);
1286
1296
  if (!prior)
@@ -3526,6 +3536,8 @@ function startFailureCode(error) {
3526
3536
  }
3527
3537
  /** Keep failure telemetry bounded and free of prompts, paths, and error prose. */
3528
3538
  function operationFailureCode(error) {
3539
+ if (error instanceof AutopilotStateError)
3540
+ return 'PERSISTENCE';
3529
3541
  const code = error && typeof error === 'object' && 'code' in error && typeof error.code === 'string'
3530
3542
  ? error.code
3531
3543
  : error instanceof Error
@@ -3548,6 +3560,8 @@ function operationRpcCode(error) {
3548
3560
  return undefined;
3549
3561
  }
3550
3562
  function operationErrorKind(error) {
3563
+ if (error instanceof AutopilotStateError)
3564
+ return 'AUTOPILOT_STATE_INVALID';
3551
3565
  if (error &&
3552
3566
  typeof error === 'object' &&
3553
3567
  'kind' in error &&
@@ -961,9 +961,7 @@ export class CodexSessionRuntime {
961
961
  error.code !== -32600 ||
962
962
  error.message !== `thread not found: ${child.id}`)
963
963
  throw error;
964
- return [...owned.ownedChildProcesses.values()].filter((process) => process.ownerThreadId === child.id &&
965
- process.state !== 'result-consumed' &&
966
- process.state !== 'terminated-for-budget');
964
+ return this.childProcessBatch(owned, child.id);
967
965
  }
968
966
  const activeIds = new Set(active.map((process) => process.processId));
969
967
  for (const process of active)
@@ -985,9 +983,19 @@ export class CodexSessionRuntime {
985
983
  });
986
984
  }
987
985
  }
988
- return [...owned.ownedChildProcesses.values()].filter((process) => process.ownerThreadId === child.id &&
986
+ return this.childProcessBatch(owned, child.id);
987
+ }
988
+ childProcessBatch(owned, childThreadId) {
989
+ // The active RPC is bounded, but exited results accumulate across reads.
990
+ // Keep that backlog until explicit consumption; only the lifecycle batch is
991
+ // bounded. Active work must remain visible even when older results fill it.
992
+ return [...owned.ownedChildProcesses.values()]
993
+ .filter((process) => process.ownerThreadId === childThreadId &&
989
994
  process.state !== 'result-consumed' &&
990
- process.state !== 'terminated-for-budget');
995
+ process.state !== 'terminated-for-budget')
996
+ .sort((left, right) => Number(right.state === 'running' || right.state === 'detached-active') -
997
+ Number(left.state === 'running' || left.state === 'detached-active'))
998
+ .slice(0, 64);
991
999
  }
992
1000
  consumeChildProcessResult(sessionId, childThreadId, processId, actionId) {
993
1001
  const owned = this.sessions.get(sessionId);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gestalt-mobile",
3
- "version": "0.65.3",
3
+ "version": "0.65.4",
4
4
  "description": "Mobile-first web relay for durable Codex development sessions",
5
5
  "keywords": [
6
6
  "codex",