gestalt-mobile 0.35.2 → 0.35.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.
@@ -2242,6 +2242,65 @@ describe('production composition', () => {
2242
2242
  });
2243
2243
  });
2244
2244
  describeCompositionConcern('lifecycle', () => {
2245
+ it('rejects a wait lease when automatic continuation is unavailable', async () => {
2246
+ const root = await mkdtemp(join(tmpdir(), 'gestalt-mobile-root-'));
2247
+ const dataDir = await mkdtemp(join(tmpdir(), 'gestalt-mobile-state-'));
2248
+ ownTemporaryPaths(root, dataDir);
2249
+ await mkdir(join(root, 'workspace'));
2250
+ const handles = [];
2251
+ const app = await composeAuthorizedApp({
2252
+ root,
2253
+ dataDir,
2254
+ relyingParty,
2255
+ installedCodexVersion: 'codex-cli 0.144.3',
2256
+ startAppServers: true,
2257
+ launchAppServer: liveAppServer(handles),
2258
+ profiles: {
2259
+ list: async () => [],
2260
+ require: async () => ({
2261
+ name: 'default',
2262
+ state: 'ok',
2263
+ status: 'ready',
2264
+ }),
2265
+ },
2266
+ });
2267
+ const sessionId = await createComposedSession(app);
2268
+ const handle = handles.find((candidate) => candidate.calls.includes('thread/start'));
2269
+ const started = await app.inject({
2270
+ method: 'POST',
2271
+ url: `/api/sessions/${sessionId}/turns`,
2272
+ payload: { text: 'continue supervised work' },
2273
+ });
2274
+ const turnId = started.json().activeTurnId;
2275
+ const threadId = (await app.inject(`/api/sessions/${sessionId}`)).json().threadId;
2276
+ handle.notify?.({ method: 'turn/started', params: { threadId, turn: { id: turnId } } });
2277
+ await expect(handle.request({
2278
+ id: 89,
2279
+ method: 'item/tool/call',
2280
+ params: {
2281
+ threadId,
2282
+ turnId,
2283
+ tool: 'gestalt_autopilot_wait_lease',
2284
+ arguments: {
2285
+ version: 2,
2286
+ reportId: 'unavailable-report',
2287
+ leaseId: 'unavailable-lease',
2288
+ wakeConditions: ['executorChanged'],
2289
+ maxWaitMs: 60_000,
2290
+ },
2291
+ },
2292
+ })).resolves.toEqual({
2293
+ success: true,
2294
+ contentItems: [
2295
+ {
2296
+ type: 'inputText',
2297
+ text: '{"accepted":false,"reason":"automaticContinuationUnavailable","next":"continueSameTurn"}',
2298
+ },
2299
+ ],
2300
+ });
2301
+ expect((await app.inject(`/api/sessions/${sessionId}`)).json().activeTurnId).toBe(turnId);
2302
+ await app.close();
2303
+ });
2245
2304
  it('acknowledges root-owned capacity recovery before recycling only its app-server', async () => {
2246
2305
  const root = await mkdtemp(join(tmpdir(), 'gestalt-mobile-root-'));
2247
2306
  const dataDir = await mkdtemp(join(tmpdir(), 'gestalt-mobile-state-'));
@@ -581,14 +581,14 @@ export async function composeRelayApp(options) {
581
581
  const rootOwned = origin.kind === 'root' && origin.physicalTurnId === session.activeTurnId;
582
582
  if (rootOwned)
583
583
  autopilot.rejectProbe(sessionId);
584
- return (runtime?.resolveServerRequest(sessionId, String(request.id), autopilotWaitLeaseToolResponse()) === true);
584
+ return (runtime?.resolveServerRequest(sessionId, String(request.id), autopilotWaitLeaseToolResponse(false)) === true);
585
585
  }
586
586
  if (!rawInteraction)
587
587
  return false;
588
588
  if (rawInteraction.kind === 'autopilotWaitLease') {
589
589
  const lease = rawInteraction.payload;
590
590
  const rootOwned = origin.kind === 'root' && origin.physicalTurnId === session.activeTurnId;
591
- const accepted = rootOwned &&
591
+ const registration = rootOwned &&
592
592
  (lease.version === 2
593
593
  ? autopilot.registerProactiveWait(sessionId, {
594
594
  id: lease.reportId,
@@ -602,10 +602,12 @@ export async function composeRelayApp(options) {
602
602
  leaseId: lease.leaseId,
603
603
  wakeConditions: lease.wakeConditions,
604
604
  }));
605
- if (!accepted) {
606
- if (rootOwned)
605
+ if (registration !== true) {
606
+ if (rootOwned && registration === false)
607
607
  autopilot.rejectProbe(sessionId);
608
- return (runtime?.resolveServerRequest(sessionId, rawInteraction.requestId, autopilotWaitLeaseToolResponse()) === true);
608
+ return (runtime?.resolveServerRequest(sessionId, rawInteraction.requestId, autopilotWaitLeaseToolResponse(false, registration === 'wakeAlreadySatisfied'
609
+ ? 'wakeAlreadySatisfied'
610
+ : 'automaticContinuationUnavailable')) === true);
609
611
  }
610
612
  return (runtime?.resolveServerRequest(sessionId, rawInteraction.requestId, autopilotWaitLeaseToolResponse()) === true);
611
613
  }
@@ -162,6 +162,24 @@ export class AutopilotCoordinator {
162
162
  report.maxWaitMs > AUTOPILOT_WAIT_MAX_MS)
163
163
  return false;
164
164
  const now = this.deps.now();
165
+ if (this.executorWakeAlreadySatisfied(sessionId, state, report.wakeConditions)) {
166
+ // The executor edge is already visible. Fence every pending automatic
167
+ // callback before returning control to the still-active root; otherwise
168
+ // a scheduled executor resume could race same-turn supervision.
169
+ const cancelled = this.cancelScheduledControl(state, now);
170
+ this.persist({
171
+ ...state,
172
+ generation: state.generation + 1,
173
+ ...(cancelled ? { lastControlId: null } : {}),
174
+ nextEvaluationAt: null,
175
+ updatedAt: now,
176
+ }, cancelled);
177
+ this.timers.get(sessionId)?.();
178
+ this.timers.delete(sessionId);
179
+ this.completionTimers.get(sessionId)?.();
180
+ this.completionTimers.delete(sessionId);
181
+ return 'wakeAlreadySatisfied';
182
+ }
165
183
  const resumeAt = new Date(Date.parse(now) + report.maxWaitMs).toISOString();
166
184
  const protocol = state.supervision ?? startSupervisionProtocol(this.progressKey(sessionId));
167
185
  const nextProtocol = registerProtocolWait(protocol, { ...report, resumeAt });
@@ -185,6 +203,19 @@ export class AutopilotCoordinator {
185
203
  this.armWaitDeadline(sessionId, report.leaseId, resumeAt);
186
204
  return true;
187
205
  }
206
+ /** Prevents an edge-triggered executor lease from parking after its edge. */
207
+ executorWakeAlreadySatisfied(sessionId, state, wakeConditions) {
208
+ if (!wakeConditions.includes('executorChanged'))
209
+ return false;
210
+ if (this.completionTimers.has(sessionId))
211
+ return true;
212
+ const retained = this.deps.plan(sessionId);
213
+ const activity = this.deps.activity(sessionId);
214
+ if (!retained || activity?.confidence !== 'fresh')
215
+ return false;
216
+ const executor = this.currentExecutor(sessionId, retained.plan, state.consecutiveNoProgress, state.executor);
217
+ return Boolean(executor && !this.authoritativeExecutorActive(state, retained.plan, activity));
218
+ }
188
219
  /** Fails closed only for the currently active bounded probe. */
189
220
  rejectProbe(sessionId) {
190
221
  const state = this.deps.store.find(sessionId);
@@ -1074,6 +1105,10 @@ export class AutopilotCoordinator {
1074
1105
  this.completionTimers.delete(sessionId);
1075
1106
  this.executorTimers.get(sessionId)?.();
1076
1107
  this.executorTimers.delete(sessionId);
1108
+ this.cancelScheduledExecutorCommands(sessionId);
1109
+ }
1110
+ /** Cancels executor authority while allowing a delivered stale callback to audit itself. */
1111
+ cancelScheduledExecutorCommands(sessionId) {
1077
1112
  const state = this.deps.store.find(sessionId);
1078
1113
  const executor = state?.executor;
1079
1114
  if (state && executor?.commands?.some((command) => command.status === 'scheduled'))
@@ -20,7 +20,7 @@ export const AUTOPILOT_WAIT_MAX_MS = 86_400_000;
20
20
  export const gestaltAutopilotWaitLeaseDynamicTool = {
21
21
  type: 'function',
22
22
  name: GESTALT_AUTOPILOT_WAIT_LEASE_TOOL_NAME,
23
- description: 'Register one non-persistent Autopilot wait episode for the current supervised session. Version 2 may be called proactively for known long work and resumes on the first requested event or bounded maxWaitMs deadline; call it again in a later turn only if another long wait is justified. This cannot request human authority and never accepts transcript prose.',
23
+ description: 'Register one non-persistent Autopilot wait episode for the current supervised session. Version 2 may be called proactively for known long work and resumes on the first requested event or bounded maxWaitMs deadline; call it again in a later turn only if another long wait is justified. Yield only when the response has accepted:true; accepted:false requires same-turn supervision. This cannot request human authority and never accepts transcript prose.',
24
24
  inputSchema: {
25
25
  type: 'object',
26
26
  additionalProperties: false,
@@ -74,8 +74,18 @@ export function parseAutopilotWaitLease(value) {
74
74
  maxWaitMs: value.maxWaitMs,
75
75
  };
76
76
  }
77
- export function autopilotWaitLeaseToolResponse() {
78
- return { success: true, contentItems: [{ type: 'inputText', text: '{"accepted":true}' }] };
77
+ export function autopilotWaitLeaseToolResponse(accepted = true, reason = 'automaticContinuationUnavailable') {
78
+ return {
79
+ success: true,
80
+ contentItems: [
81
+ {
82
+ type: 'inputText',
83
+ text: accepted
84
+ ? '{"accepted":true}'
85
+ : JSON.stringify({ accepted: false, reason, next: 'continueSameTurn' }),
86
+ },
87
+ ],
88
+ };
79
89
  }
80
90
  function record(value) {
81
91
  return typeof value === 'object' && value !== null && !Array.isArray(value);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gestalt-mobile",
3
- "version": "0.35.2",
3
+ "version": "0.35.4",
4
4
  "description": "Mobile-first web relay for durable Codex development sessions",
5
5
  "keywords": [
6
6
  "codex",