gestalt-mobile 0.68.0 → 0.68.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.
@@ -591,6 +591,143 @@ async function orgPlanActivationFixture() {
591
591
  }
592
592
  describe('production composition', () => {
593
593
  describeCompositionConcern('autopilot', () => {
594
+ it('starts one root recovery after an executor wake encounters a superseded issued command', async () => {
595
+ const timers = [];
596
+ let coordinator;
597
+ let childWorking = true;
598
+ let rootThreadId = 'thread-1';
599
+ const fixture = await createProductionAutopilotFixture({
600
+ activitySchedule: () => () => { },
601
+ autopilotActivity: (sessionId) => {
602
+ const observedAt = new Date().toISOString();
603
+ return {
604
+ sessionId,
605
+ rootThreadId,
606
+ root: {
607
+ state: 'idle',
608
+ reason: 'turnCompleted',
609
+ observedAt,
610
+ lastActivityAt: observedAt,
611
+ },
612
+ subagents: [
613
+ {
614
+ id: 'child-1',
615
+ threadId: 'child-1',
616
+ taskPath: '/root/l1',
617
+ canonicalTaskName: 'l1',
618
+ canonicalPosition: 'L1',
619
+ continuationGeneration: 1,
620
+ outcome: 'partial',
621
+ ownedProcesses: [],
622
+ state: childWorking ? 'working' : 'idle',
623
+ reason: childWorking ? 'turnActive' : 'turnCompleted',
624
+ observedAt,
625
+ lastActivityAt: observedAt,
626
+ },
627
+ ],
628
+ aggregateSubagents: childWorking ? 'working' : 'idle',
629
+ confidence: 'fresh',
630
+ };
631
+ },
632
+ onAutopilotCoordinator: (value) => {
633
+ coordinator = value;
634
+ },
635
+ autopilotSchedule: (callback) => {
636
+ const timer = { callback, cancelled: false, fired: false };
637
+ timers.push(timer);
638
+ return () => {
639
+ timer.cancelled = true;
640
+ };
641
+ },
642
+ });
643
+ onTestFinished(() => fixture.app.close());
644
+ rootThreadId = (await fixture.app.inject(`/api/sessions/${fixture.sessionId}`)).json()
645
+ .threadId;
646
+ expect(coordinator.reconcileExecutorBinding(fixture.sessionId).status).toBe('ready');
647
+ const database = new DatabaseSync(join(fixture.dataDir, 'relay.sqlite'));
648
+ onTestFinished(() => database.close());
649
+ const store = new SqliteAutopilotStore(database);
650
+ const state = store.find(fixture.sessionId);
651
+ const executor = state.executor;
652
+ const commandId = createHash('sha256')
653
+ .update(JSON.stringify([
654
+ state.planIdentity,
655
+ state.planFingerprint,
656
+ executor.canonicalPosition,
657
+ executor.canonicalTaskName,
658
+ executor.taskPath,
659
+ executor.threadId,
660
+ 2,
661
+ 'partial',
662
+ ]))
663
+ .digest('hex');
664
+ store.save({
665
+ ...state,
666
+ executor: {
667
+ ...executor,
668
+ commands: [
669
+ {
670
+ commandId,
671
+ status: 'superseded',
672
+ planIdentity: state.planIdentity,
673
+ planFingerprint: state.planFingerprint,
674
+ canonicalPosition: executor.canonicalPosition,
675
+ canonicalTaskName: executor.canonicalTaskName,
676
+ taskPath: executor.taskPath,
677
+ threadId: executor.threadId,
678
+ generation: 2,
679
+ trigger: 'partial',
680
+ createdAt: state.updatedAt,
681
+ updatedAt: state.updatedAt,
682
+ },
683
+ ],
684
+ },
685
+ });
686
+ expect(coordinator.registerProactiveWait(fixture.sessionId, {
687
+ id: 'executor-report',
688
+ leaseId: 'executor-lease',
689
+ maxWaitMs: 60_000,
690
+ wakeConditions: ['executorChanged'],
691
+ })).toBe(true);
692
+ childWorking = false;
693
+ coordinator.activityChanged(fixture.sessionId);
694
+ const starts = () => fixture.handles
695
+ .flatMap((handle) => handle.requests)
696
+ .filter((request) => request.method === 'turn/start');
697
+ for (let attempt = 0; attempt < 8 && starts().length === 0; attempt++) {
698
+ const timer = timers.find((candidate) => !candidate.cancelled && !candidate.fired);
699
+ expect(timer).toBeDefined();
700
+ timer.fired = true;
701
+ timer.callback();
702
+ await new Promise((resolve) => setImmediate(resolve));
703
+ }
704
+ await vi.waitFor(() => expect(starts()).toHaveLength(1));
705
+ expect(starts()[0].params.threadId).toBe(rootThreadId);
706
+ expect(store.find(fixture.sessionId).executor.commands[0]).toMatchObject({
707
+ commandId,
708
+ status: 'superseded',
709
+ });
710
+ for (const timer of timers.filter((candidate) => candidate.fired))
711
+ timer.callback();
712
+ await new Promise((resolve) => setImmediate(resolve));
713
+ expect(starts()).toHaveLength(1);
714
+ const trace = exportControlPlaneTrace(join(fixture.dataDir, 'relay.sqlite'), fixture.sessionId);
715
+ const wake = trace.events.find((event) => event.type === 'autopilot.wait-woken');
716
+ expect(wake.payload.leaseId).toBe('executor-lease');
717
+ const transitions = trace.events
718
+ .filter((event) => event.sequence > wake.sequence &&
719
+ [
720
+ 'autopilot.continuation-scheduled',
721
+ 'autopilot.control-issued',
722
+ 'autopilot.turn-started',
723
+ ].includes(event.type))
724
+ .map((event) => event.type);
725
+ expect(transitions).toEqual([
726
+ 'autopilot.continuation-scheduled',
727
+ 'autopilot.control-issued',
728
+ 'autopilot.turn-started',
729
+ ]);
730
+ });
594
731
  it('persists a bounded executor after 64 exited results and new active work, including a plan watcher update', async () => {
595
732
  const handles = [];
596
733
  const launch = liveAppServer(handles);
@@ -3122,11 +3122,14 @@ export class AutopilotCoordinator {
3122
3122
  if (this.authoritativeExecutorActive(state, retained.plan, this.deps.activity(state.sessionId)))
3123
3123
  return false;
3124
3124
  const planFingerprint = fingerprint(retained.plan);
3125
- // Issued is not accepted. A later wait can replace the transient probe
3126
- // state, but cannot erase this durable ambiguity. Resume protection must
3127
- // hand diagnosis back to root rather than silently selecting a command
3128
- // which replay protection will refuse to issue again.
3129
- return Boolean(executor.commands?.some((command) => command.status === 'issued' &&
3125
+ // Issued is not accepted. A plan change can supersede that command, then
3126
+ // return to the same fingerprint after dependency repair. Neither that
3127
+ // transition nor a later wait resolves the original dispatch ambiguity.
3128
+ // Hand diagnosis back to root instead of selecting a command that replay
3129
+ // protection will refuse to issue again. Proven unissued commands remain
3130
+ // eligible for a new fenced attempt.
3131
+ return Boolean(executor.commands?.some((command) => (command.status === 'issued' ||
3132
+ (command.status === 'superseded' && !command.supersededBeforeIssue)) &&
3130
3133
  !command.processAction &&
3131
3134
  command.planIdentity === retained.identity &&
3132
3135
  command.planFingerprint === planFingerprint &&
@@ -4,7 +4,7 @@
4
4
  * SPDX-License-Identifier: AGPL-3.0-or-later
5
5
  */
6
6
  import { randomUUID } from 'node:crypto';
7
- import { lstat, mkdir, opendir, readdir, realpath, rename, rm, rmdir } from 'node:fs/promises';
7
+ import { lstat, mkdir, readdir, realpath, rename, rm, rmdir } from 'node:fs/promises';
8
8
  import { basename, dirname, isAbsolute, join, relative, resolve, sep } from 'node:path';
9
9
  import { emptyScratchCounts, } from '../../features/sessions/clean-tmp/use-case.js';
10
10
  import { mobileScratchOwnerId, privateDirectory, scratchMarkerName } from './scratch-filesystem.js';
@@ -15,6 +15,10 @@ import { claimScratchContainment, containmentFenceName } from './containment-fen
15
15
  function reject(reason) {
16
16
  throw new Error(`SCRATCH_CLEANUP_${reason}`);
17
17
  }
18
+ /** POSIX payload names need not be UTF-8. Keep their bytes for filesystem calls. */
19
+ function payloadPath(directory, name) {
20
+ return Buffer.concat([Buffer.from(directory), Buffer.from(sep), name]);
21
+ }
18
22
  /** Only the managed namespace is traversed. There are no prefix/age/PID legacy recognizers. */
19
23
  export class FilesystemScratchCleanup {
20
24
  async cleanSession(session, authorized, protectedSessions) {
@@ -121,10 +125,10 @@ export class FilesystemScratchCleanup {
121
125
  await this.assertProtection(directory, join(container, ownerId), marker, protectedSessions, authorized);
122
126
  // Keep authority metadata until disposable payload has been removed. A failed
123
127
  // payload deletion is retryable; an interrupted metadata retirement is unknown.
124
- for (const child of await readdir(directory)) {
125
- if ([scratchMarkerName, 'leases', '.controller-lock', containmentFenceName].includes(child))
128
+ for (const child of await readdir(directory, { encoding: 'buffer' })) {
129
+ if ([scratchMarkerName, 'leases', '.controller-lock', containmentFenceName].includes(child.toString()))
126
130
  continue;
127
- await rm(join(directory, child), { recursive: true });
131
+ await rm(payloadPath(directory, child), { recursive: true });
128
132
  }
129
133
  if ((await readdir(directory)).includes('leases'))
130
134
  await rm(join(directory, 'leases'), { recursive: true });
@@ -234,17 +238,17 @@ export class FilesystemScratchCleanup {
234
238
  // Even an empty nested namespace is not authority to retire a workspace's
235
239
  // contents recursively as another owner's payload.
236
240
  if (directory !== root &&
237
- basename(directory) === 'sessions' &&
238
- basename(dirname(directory)) === 'tmp')
241
+ basename(directory.toString()) === 'sessions' &&
242
+ basename(dirname(directory.toString())) === 'tmp')
239
243
  reject('unrecognized');
240
- for await (const entry of await opendir(directory)) {
244
+ for (const entry of await readdir(directory, { encoding: 'buffer', withFileTypes: true })) {
241
245
  const child = entry.name;
242
246
  if (++budget.entries > 100_000)
243
247
  reject('unrecognized');
244
248
  if (directory !== root &&
245
- [scratchMarkerName, '.controller-lock', '.association-lock', containmentFenceName].includes(child))
249
+ [scratchMarkerName, '.controller-lock', '.association-lock', containmentFenceName].includes(child.toString()))
246
250
  reject('unrecognized');
247
- const path = join(directory, child);
251
+ const path = payloadPath(directory, child);
248
252
  const info = await lstat(path);
249
253
  if ((process.getuid && info.uid !== process.getuid()) ||
250
254
  (!info.isDirectory() && !info.isFile() && !info.isSymbolicLink()) ||
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gestalt-mobile",
3
- "version": "0.68.0",
3
+ "version": "0.68.2",
4
4
  "description": "Mobile-first web relay for durable Codex development sessions",
5
5
  "keywords": [
6
6
  "codex",