gestalt-mobile 0.66.3 → 0.67.0
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.
- package/dist/server/server/composition.contracts.js +450 -61
- package/dist/server/server/composition.js +1 -0
- package/dist/server/server/features/autopilot/application/service.js +67 -5
- package/dist/server/server/features/autopilot/domain/supervision-protocol.js +32 -0
- package/dist/server/server/features/control-plane-trace/export-trace.js +110 -10
- package/dist/server/server/platform/codex/codex-capabilities.js +65 -7
- package/dist/server/server/platform/codex/codex-playwright.js +20 -3
- package/dist/server/server/platform/codex/codex-serena.js +14 -4
- package/dist/server/server/platform/codex/instruction-blocks.js +17 -0
- package/dist/server/server/platform/codex/session-runtime.js +7 -0
- package/dist/server/server/platform/codex/startup-guidance.fixture.js +38 -0
- package/dist/server/server/platform/codex/startup-guidance.js +94 -0
- package/dist/server/server/platform/retrieval/codex-xerj.js +14 -4
- package/package.json +1 -1
|
@@ -148,8 +148,16 @@ async function createComposedSession(app) {
|
|
|
148
148
|
url: '/api/sessions',
|
|
149
149
|
payload: { workspaceId: workspace.id, profile: 'default', provider: 'codex' },
|
|
150
150
|
});
|
|
151
|
-
|
|
152
|
-
|
|
151
|
+
const response = created.json();
|
|
152
|
+
const diagnostic = {
|
|
153
|
+
status: created.statusCode,
|
|
154
|
+
code: typeof response.code === 'string' && /^[A-Z0-9_]{1,80}$/.test(response.code)
|
|
155
|
+
? response.code
|
|
156
|
+
: null,
|
|
157
|
+
retryable: typeof response.retryable === 'boolean' ? response.retryable : null,
|
|
158
|
+
};
|
|
159
|
+
expect(created.statusCode, JSON.stringify(diagnostic)).toBe(202);
|
|
160
|
+
return response.id;
|
|
153
161
|
}
|
|
154
162
|
const autopilotPlanText = (childState = 'TODO') => `#+TITLE: Autopilot fixture
|
|
155
163
|
* WIP [#A] Parent
|
|
@@ -210,6 +218,59 @@ async function installAutopilotPlan(app, sessionId, workspacePath, name, childSt
|
|
|
210
218
|
expect((await app.inject({ method: 'POST', url: `/api/sessions/${sessionId}/restore` })).statusCode).toBe(200);
|
|
211
219
|
return planPath;
|
|
212
220
|
}
|
|
221
|
+
function ownRuntimeRecycles(sessionId, app) {
|
|
222
|
+
const owned = [];
|
|
223
|
+
const pending = new Set();
|
|
224
|
+
const owners = new Set();
|
|
225
|
+
const recycle = CodexSessionRuntime.prototype.recycle;
|
|
226
|
+
const observer = vi.spyOn(CodexSessionRuntime.prototype, 'recycle').mockImplementation(function (session, now) {
|
|
227
|
+
const result = recycle.call(this, session, now);
|
|
228
|
+
if (session.id === sessionId && (owners.size === 0 || owners.has(this))) {
|
|
229
|
+
owners.add(this);
|
|
230
|
+
owned.push(result);
|
|
231
|
+
pending.add(result);
|
|
232
|
+
void result.finally(() => pending.delete(result)).catch(() => { });
|
|
233
|
+
}
|
|
234
|
+
return result;
|
|
235
|
+
});
|
|
236
|
+
const drain = async () => {
|
|
237
|
+
const results = [];
|
|
238
|
+
while (results.length < owned.length)
|
|
239
|
+
results.push(...(await Promise.allSettled(owned.slice(results.length))));
|
|
240
|
+
return results;
|
|
241
|
+
};
|
|
242
|
+
let closing;
|
|
243
|
+
function close() {
|
|
244
|
+
return (closing ??= (async () => {
|
|
245
|
+
try {
|
|
246
|
+
const results = [];
|
|
247
|
+
let joined;
|
|
248
|
+
try {
|
|
249
|
+
results.push(...(await drain()));
|
|
250
|
+
joined = owned.length;
|
|
251
|
+
}
|
|
252
|
+
finally {
|
|
253
|
+
try {
|
|
254
|
+
await app.close();
|
|
255
|
+
}
|
|
256
|
+
finally {
|
|
257
|
+
await drain();
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
expect(pending.size).toBe(0);
|
|
261
|
+
expect(owned.length).toBe(joined);
|
|
262
|
+
return results;
|
|
263
|
+
}
|
|
264
|
+
finally {
|
|
265
|
+
observer.mockRestore();
|
|
266
|
+
}
|
|
267
|
+
})());
|
|
268
|
+
}
|
|
269
|
+
onTestFinished(async () => {
|
|
270
|
+
await close();
|
|
271
|
+
});
|
|
272
|
+
return { owned, pending, close };
|
|
273
|
+
}
|
|
213
274
|
async function createProductionAutopilotFixture(overrides = {}, source) {
|
|
214
275
|
const root = await mkdtemp(join(tmpdir(), 'gestalt-mobile-root-'));
|
|
215
276
|
const dataDir = await mkdtemp(join(tmpdir(), 'gestalt-mobile-state-'));
|
|
@@ -1648,7 +1709,9 @@ describe('production composition', () => {
|
|
|
1648
1709
|
}),
|
|
1649
1710
|
},
|
|
1650
1711
|
});
|
|
1651
|
-
|
|
1712
|
+
onTestFinished(() => app.close());
|
|
1713
|
+
// Managed TMPDIR fixtures share an ancestor publication fence during session creation.
|
|
1714
|
+
const sessions = [await createComposedSession(app), await createComposedSession(app)];
|
|
1652
1715
|
await vi.waitFor(async () => expect(await Promise.all(sessions.map(async (sessionId) => (await app.inject(`/api/sessions/${sessionId}`)).json().state))).toEqual(['ready', 'ready']));
|
|
1653
1716
|
const planText = `#+TITLE: Autopilot fixture
|
|
1654
1717
|
* WIP [#A] Parent
|
|
@@ -3307,48 +3370,59 @@ describe('production composition', () => {
|
|
|
3307
3370
|
};
|
|
3308
3371
|
},
|
|
3309
3372
|
});
|
|
3310
|
-
const
|
|
3311
|
-
|
|
3312
|
-
|
|
3313
|
-
|
|
3314
|
-
|
|
3315
|
-
|
|
3316
|
-
const
|
|
3317
|
-
|
|
3318
|
-
|
|
3319
|
-
|
|
3320
|
-
|
|
3321
|
-
|
|
3322
|
-
|
|
3323
|
-
|
|
3324
|
-
|
|
3325
|
-
|
|
3326
|
-
|
|
3327
|
-
|
|
3328
|
-
|
|
3329
|
-
|
|
3330
|
-
|
|
3331
|
-
|
|
3332
|
-
|
|
3333
|
-
|
|
3334
|
-
|
|
3335
|
-
|
|
3373
|
+
const recovery = ownRuntimeRecycles(fixture.sessionId, fixture.app);
|
|
3374
|
+
try {
|
|
3375
|
+
const { handle, response, startsBefore, writersBefore } = await holdCheckpointRequest(fixture, timers, 992);
|
|
3376
|
+
const starts = () => fixture.handles
|
|
3377
|
+
.flatMap((candidate) => candidate.requests)
|
|
3378
|
+
.filter((request) => request.method === 'turn/start').length;
|
|
3379
|
+
const failures = () => {
|
|
3380
|
+
const database = new DatabaseSync(join(fixture.dataDir, 'relay.sqlite'));
|
|
3381
|
+
const count = database
|
|
3382
|
+
.prepare("SELECT count(*) AS count FROM session_events WHERE type = 'org-plan.checkpoint-handoff-failed'")
|
|
3383
|
+
.get();
|
|
3384
|
+
database.close();
|
|
3385
|
+
return count.count;
|
|
3386
|
+
};
|
|
3387
|
+
if (scenario === 'resultWritten-before-timeout') {
|
|
3388
|
+
handle.responseSettled({ id: 992, outcome: 'resultWritten' });
|
|
3389
|
+
await expect(response).resolves.toEqual(toOrgPlanCheckpointToolResponse('recorded'));
|
|
3390
|
+
await new Promise((resolve) => setTimeout(resolve, 30));
|
|
3391
|
+
expect(fixture.handles).toHaveLength(writersBefore);
|
|
3392
|
+
expect(failures()).toBe(0);
|
|
3393
|
+
}
|
|
3394
|
+
else if (scenario === 'duplicate-settlement') {
|
|
3395
|
+
handle.responseSettled({ id: 992, outcome: 'resultWritten' });
|
|
3396
|
+
handle.responseSettled({ id: 992, outcome: 'resultWritten' });
|
|
3397
|
+
await expect(response).resolves.toEqual(toOrgPlanCheckpointToolResponse('recorded'));
|
|
3398
|
+
await new Promise((resolve) => setTimeout(resolve, 30));
|
|
3399
|
+
expect(fixture.handles).toHaveLength(writersBefore);
|
|
3400
|
+
expect(failures()).toBe(0);
|
|
3401
|
+
}
|
|
3402
|
+
else {
|
|
3403
|
+
if (scenario === 'writeFailed')
|
|
3404
|
+
handle.responseSettled({ id: 992, outcome: 'writeFailed' });
|
|
3405
|
+
const lateSettlement = handle.responseSettled;
|
|
3406
|
+
await expect(response).rejects.toThrow('CODEX_SERVER_REQUEST_CANCELLED');
|
|
3407
|
+
await vi.waitFor(() => expect(fixture.handles.length).toBeGreaterThan(writersBefore), {
|
|
3408
|
+
timeout: 1_000,
|
|
3409
|
+
});
|
|
3410
|
+
expect(recovery.owned).toHaveLength(1);
|
|
3411
|
+
await expect(recovery.owned[0]).resolves.toMatchObject({
|
|
3412
|
+
id: fixture.sessionId,
|
|
3413
|
+
state: 'ready',
|
|
3414
|
+
});
|
|
3415
|
+
if (scenario === 'timeout-before-late-resultWritten')
|
|
3416
|
+
lateSettlement({ id: 992, outcome: 'resultWritten' });
|
|
3417
|
+
await new Promise((resolve) => setTimeout(resolve, 30));
|
|
3418
|
+
expect(failures()).toBe(1);
|
|
3419
|
+
}
|
|
3420
|
+
expect(recovery.owned).toHaveLength(scenario === 'writeFailed' || scenario === 'timeout-before-late-resultWritten' ? 1 : 0);
|
|
3421
|
+
expect(starts()).toBe(startsBefore);
|
|
3336
3422
|
}
|
|
3337
|
-
|
|
3338
|
-
|
|
3339
|
-
handle.responseSettled({ id: 992, outcome: 'writeFailed' });
|
|
3340
|
-
const lateSettlement = handle.responseSettled;
|
|
3341
|
-
await expect(response).rejects.toThrow('CODEX_SERVER_REQUEST_CANCELLED');
|
|
3342
|
-
await vi.waitFor(() => expect(fixture.handles.length).toBeGreaterThan(writersBefore), {
|
|
3343
|
-
timeout: 1_000,
|
|
3344
|
-
});
|
|
3345
|
-
if (scenario === 'timeout-before-late-resultWritten')
|
|
3346
|
-
lateSettlement({ id: 992, outcome: 'resultWritten' });
|
|
3347
|
-
await new Promise((resolve) => setTimeout(resolve, 30));
|
|
3348
|
-
expect(failures()).toBe(1);
|
|
3423
|
+
finally {
|
|
3424
|
+
await recovery.close();
|
|
3349
3425
|
}
|
|
3350
|
-
expect(starts()).toBe(startsBefore);
|
|
3351
|
-
await fixture.app.close();
|
|
3352
3426
|
});
|
|
3353
3427
|
it('does not apply checkpoint deadlines to quiz or approval requests', async () => {
|
|
3354
3428
|
const checkpointFailures = (dataDir) => {
|
|
@@ -4340,9 +4414,112 @@ describe('production composition', () => {
|
|
|
4340
4414
|
expect(replacements.count).toBe(1);
|
|
4341
4415
|
await fixture.app.close();
|
|
4342
4416
|
});
|
|
4417
|
+
it.each([false, true, 'otherTurn', 'expired', 'missingOwner'])('production trace distinguishes an incomplete final from accepted wait yield (wait: %s)', async (wait) => {
|
|
4418
|
+
const timers = [];
|
|
4419
|
+
let coordinator;
|
|
4420
|
+
const fixture = await createProductionAutopilotFixture({
|
|
4421
|
+
onAutopilotCoordinator: (value) => {
|
|
4422
|
+
coordinator = value;
|
|
4423
|
+
},
|
|
4424
|
+
autopilotSchedule: (callback) => {
|
|
4425
|
+
const timer = { callback, cancelled: false };
|
|
4426
|
+
timers.push(timer);
|
|
4427
|
+
return () => {
|
|
4428
|
+
timer.cancelled = true;
|
|
4429
|
+
};
|
|
4430
|
+
},
|
|
4431
|
+
});
|
|
4432
|
+
onTestFinished(() => fixture.app.close());
|
|
4433
|
+
timers.find((timer) => !timer.cancelled).callback();
|
|
4434
|
+
await vi.waitFor(async () => expect((await fixture.app.inject(`/api/sessions/${fixture.sessionId}`)).json().activeTurnId).toEqual(expect.any(String)));
|
|
4435
|
+
const session = (await fixture.app.inject(`/api/sessions/${fixture.sessionId}`)).json();
|
|
4436
|
+
const handle = fixture.handles.find((candidate) => candidate.requests.some((request) => request.method === 'turn/start'));
|
|
4437
|
+
if (wait) {
|
|
4438
|
+
const result = (await handle.request({
|
|
4439
|
+
id: 9180,
|
|
4440
|
+
method: 'item/tool/call',
|
|
4441
|
+
params: {
|
|
4442
|
+
threadId: session.threadId,
|
|
4443
|
+
turnId: session.activeTurnId,
|
|
4444
|
+
tool: 'gestalt_autopilot_wait_lease',
|
|
4445
|
+
arguments: {
|
|
4446
|
+
version: 2,
|
|
4447
|
+
reportId: 'trace-wait-report',
|
|
4448
|
+
leaseId: 'trace-wait-lease',
|
|
4449
|
+
wakeConditions: ['processExited'],
|
|
4450
|
+
maxWaitMs: 60_000,
|
|
4451
|
+
},
|
|
4452
|
+
},
|
|
4453
|
+
}));
|
|
4454
|
+
expect(JSON.parse(result.contentItems[0].text)).toMatchObject({ accepted: true });
|
|
4455
|
+
}
|
|
4456
|
+
if (typeof wait === 'string') {
|
|
4457
|
+
const database = new DatabaseSync(join(fixture.dataDir, 'relay.sqlite'));
|
|
4458
|
+
try {
|
|
4459
|
+
const row = database
|
|
4460
|
+
.prepare('SELECT lifecycle_json FROM autopilot_sessions WHERE session_id = ?')
|
|
4461
|
+
.get(fixture.sessionId);
|
|
4462
|
+
const lifecycle = JSON.parse(row.lifecycle_json);
|
|
4463
|
+
if (wait === 'otherTurn')
|
|
4464
|
+
lifecycle.supervision.waitLease.turnId = 'unrelated-root-turn';
|
|
4465
|
+
if (wait === 'expired')
|
|
4466
|
+
lifecycle.supervision.waitLease.resumeAt = '2000-01-01T00:00:00Z';
|
|
4467
|
+
if (wait === 'missingOwner')
|
|
4468
|
+
delete lifecycle.supervision.waitLease.turnId;
|
|
4469
|
+
database
|
|
4470
|
+
.prepare('UPDATE autopilot_sessions SET lifecycle_json = ? WHERE session_id = ?')
|
|
4471
|
+
.run(JSON.stringify(lifecycle), fixture.sessionId);
|
|
4472
|
+
}
|
|
4473
|
+
finally {
|
|
4474
|
+
database.close();
|
|
4475
|
+
}
|
|
4476
|
+
}
|
|
4477
|
+
expect(coordinator.turnCompleted(fixture.sessionId, session.activeTurnId)).toBe(false);
|
|
4478
|
+
const path = join(fixture.dataDir, 'relay.sqlite');
|
|
4479
|
+
const trace = exportControlPlaneTrace(path, fixture.sessionId);
|
|
4480
|
+
const final = trace.events.findLast((event) => event.type === 'autopilot.final-rejected');
|
|
4481
|
+
expect(final.payload).toMatchObject({
|
|
4482
|
+
reason: 'incompletePlan',
|
|
4483
|
+
disposition: wait === true
|
|
4484
|
+
? 'acceptedWait'
|
|
4485
|
+
: wait === 'missingOwner'
|
|
4486
|
+
? 'unknownWait'
|
|
4487
|
+
: 'rejectedFinal',
|
|
4488
|
+
turnId: session.activeTurnId,
|
|
4489
|
+
});
|
|
4490
|
+
if (wait === true) {
|
|
4491
|
+
expect(final.payload.leaseId).toBe('trace-wait-lease');
|
|
4492
|
+
expect(trace.events.some((event) => event.type === 'autopilot.wait-registered')).toBe(true);
|
|
4493
|
+
}
|
|
4494
|
+
else
|
|
4495
|
+
expect(final.payload).not.toHaveProperty('leaseId');
|
|
4496
|
+
expect(trace.diagnoses).not.toContain('continuation scheduled, but no control or executor dispatch was observed');
|
|
4497
|
+
expect(trace.diagnoses).not.toContain('control issued, but no turn acceptance or failure was observed');
|
|
4498
|
+
});
|
|
4499
|
+
it('production trace treats a cancelled scheduled root control as settled', async () => {
|
|
4500
|
+
const fixture = await createProductionAutopilotFixture({ autopilotSchedule: () => () => { } });
|
|
4501
|
+
onTestFinished(() => fixture.app.close());
|
|
4502
|
+
expect((await fixture.app.inject({
|
|
4503
|
+
method: 'PUT',
|
|
4504
|
+
url: `/api/sessions/${fixture.sessionId}/autopilot`,
|
|
4505
|
+
payload: { enabled: false },
|
|
4506
|
+
})).statusCode).toBe(200);
|
|
4507
|
+
const trace = exportControlPlaneTrace(join(fixture.dataDir, 'relay.sqlite'), fixture.sessionId);
|
|
4508
|
+
const cancellation = trace.events.find((event) => event.type === 'autopilot.control-cancelled');
|
|
4509
|
+
expect(cancellation.payload).toMatchObject({
|
|
4510
|
+
controlId: expect.any(String),
|
|
4511
|
+
reason: 'manualDisabled',
|
|
4512
|
+
});
|
|
4513
|
+
expect(trace.events.some((event) => event.type === 'autopilot.continuation-scheduled' &&
|
|
4514
|
+
event.payload.controlId === cancellation.payload.controlId)).toBe(true);
|
|
4515
|
+
expect(trace.diagnoses).not.toContain('continuation scheduled, but no control or executor dispatch was observed');
|
|
4516
|
+
expect(trace.diagnoses).not.toContain('control issued, but no turn acceptance or failure was observed');
|
|
4517
|
+
});
|
|
4343
4518
|
it.each([
|
|
4344
4519
|
['transport-lost', new Error('CODEX_CONNECTION_LOST'), false],
|
|
4345
4520
|
['ambiguous RPC failure', new CodexJsonRpcError(-32603, 'internal error'), false],
|
|
4521
|
+
['invalid request', new CodexJsonRpcError(-32600, 'private provider request detail'), false],
|
|
4522
|
+
['unknown error', new Error('private provider request detail'), false],
|
|
4346
4523
|
['manual Off after RPC failure', new CodexJsonRpcError(-32603, 'internal error'), true],
|
|
4347
4524
|
])('production recovers through the root after %s without replaying or replacing the executor', async (_scenario, failure, disableBeforeRecovery) => {
|
|
4348
4525
|
const timers = [];
|
|
@@ -4420,7 +4597,7 @@ describe('production composition', () => {
|
|
|
4420
4597
|
if (failure instanceof CodexJsonRpcError)
|
|
4421
4598
|
expect(JSON.parse(operation.payload_json)).toMatchObject({
|
|
4422
4599
|
kind: 'executorResume',
|
|
4423
|
-
rpcCode:
|
|
4600
|
+
rpcCode: failure.code,
|
|
4424
4601
|
});
|
|
4425
4602
|
else
|
|
4426
4603
|
expect(JSON.parse(operation.payload_json)).not.toHaveProperty('rpcCode');
|
|
@@ -4464,6 +4641,30 @@ describe('production composition', () => {
|
|
|
4464
4641
|
await new Promise((resolve) => setImmediate(resolve));
|
|
4465
4642
|
expect(starts().filter((request) => request.params.threadId === 'child-1')).toHaveLength(1);
|
|
4466
4643
|
expect(rootStarts()).toHaveLength(disableBeforeRecovery ? 0 : 1);
|
|
4644
|
+
const trace = exportControlPlaneTrace(join(fixture.dataDir, 'relay.sqlite'), fixture.sessionId);
|
|
4645
|
+
const exportedFailure = trace.events.find((event) => event.type === 'autopilot.operation-failed');
|
|
4646
|
+
expect(exportedFailure.payload).toMatchObject({
|
|
4647
|
+
kind: 'executorResume',
|
|
4648
|
+
reason: failure instanceof CodexJsonRpcError ? 'CODEX_JSON_RPC_ERROR' : 'UNKNOWN',
|
|
4649
|
+
requestId: expect.any(String),
|
|
4650
|
+
threadId: 'child-1',
|
|
4651
|
+
generation: expect.any(Number),
|
|
4652
|
+
});
|
|
4653
|
+
expect(exportedFailure.payload.requestId).not.toBe('');
|
|
4654
|
+
expect(JSON.stringify(trace)).not.toContain('private provider request detail');
|
|
4655
|
+
expect(trace.diagnoses).toContain(disableBeforeRecovery
|
|
4656
|
+
? 'executor resume failed; no matching root recovery continuation was observed; executor outcome remains unconfirmed'
|
|
4657
|
+
: 'root continuation observed after executor resume failure; executor outcome remains unconfirmed');
|
|
4658
|
+
const settledDatabase = new DatabaseSync(join(fixture.dataDir, 'relay.sqlite'));
|
|
4659
|
+
try {
|
|
4660
|
+
const row = settledDatabase
|
|
4661
|
+
.prepare('SELECT lifecycle_json FROM autopilot_sessions WHERE session_id = ?')
|
|
4662
|
+
.get(fixture.sessionId);
|
|
4663
|
+
expect(JSON.parse(row.lifecycle_json).supervision.diagnosticRecovery).toBeNull();
|
|
4664
|
+
}
|
|
4665
|
+
finally {
|
|
4666
|
+
settledDatabase.close();
|
|
4667
|
+
}
|
|
4467
4668
|
await fixture.app.close();
|
|
4468
4669
|
});
|
|
4469
4670
|
it.each([
|
|
@@ -5108,18 +5309,48 @@ describe('production composition', () => {
|
|
|
5108
5309
|
]));
|
|
5109
5310
|
await fixture.app.close();
|
|
5110
5311
|
});
|
|
5111
|
-
|
|
5312
|
+
async function exerciseWedgedAttention(failAfterRejection = false, cleanup = { owned: -1, pending: -1, ready: false, closed: false, restored: false }) {
|
|
5112
5313
|
const fixture = await createProductionAutopilotFixture({
|
|
5113
5314
|
attentionAcknowledgementDeadlineMs: 100,
|
|
5114
5315
|
});
|
|
5115
|
-
const
|
|
5116
|
-
|
|
5117
|
-
|
|
5118
|
-
|
|
5119
|
-
|
|
5120
|
-
|
|
5121
|
-
|
|
5122
|
-
|
|
5316
|
+
const recovery = ownRuntimeRecycles(fixture.sessionId, fixture.app);
|
|
5317
|
+
const { owned, pending } = recovery;
|
|
5318
|
+
try {
|
|
5319
|
+
const handle = fixture.handles.find((candidate) => candidate.request);
|
|
5320
|
+
handle.deferResponseSettlement = true;
|
|
5321
|
+
const response = handle.request(attentionCall(699));
|
|
5322
|
+
const rejected = expect(response).rejects.toThrow('CODEX_SERVER_REQUEST_CANCELLED');
|
|
5323
|
+
await vi.waitFor(() => expect(handle.pendingResponses.has(699)).toBe(true));
|
|
5324
|
+
await rejected;
|
|
5325
|
+
expect(owned).toHaveLength(1);
|
|
5326
|
+
if (failAfterRejection) {
|
|
5327
|
+
expect(pending.size).toBe(1);
|
|
5328
|
+
throw new Error('injected assertion-path failure');
|
|
5329
|
+
}
|
|
5330
|
+
await expect(owned[0]).resolves.toMatchObject({ id: fixture.sessionId, state: 'ready' });
|
|
5331
|
+
expect((await fixture.app.inject(`/api/sessions/${fixture.sessionId}/attention`)).json()).toMatchObject({ requestId: '699', attention: { reason: 'hardBlock' } });
|
|
5332
|
+
}
|
|
5333
|
+
finally {
|
|
5334
|
+
const settled = await recovery.close();
|
|
5335
|
+
const result = settled[0];
|
|
5336
|
+
cleanup.owned = owned.length;
|
|
5337
|
+
cleanup.pending = pending.size;
|
|
5338
|
+
cleanup.ready =
|
|
5339
|
+
settled.length === 1 &&
|
|
5340
|
+
result?.status === 'fulfilled' &&
|
|
5341
|
+
result.value.id === fixture.sessionId &&
|
|
5342
|
+
result.value.state === 'ready';
|
|
5343
|
+
cleanup.closed = true;
|
|
5344
|
+
cleanup.restored = true;
|
|
5345
|
+
}
|
|
5346
|
+
}
|
|
5347
|
+
it('bounds a wedged attention acknowledgement writer without losing durable attention', async () => {
|
|
5348
|
+
await exerciseWedgedAttention();
|
|
5349
|
+
});
|
|
5350
|
+
it('drains owned acknowledgement recovery after an assertion-path failure before closing its app', async () => {
|
|
5351
|
+
const cleanup = { owned: -1, pending: -1, ready: false, closed: false, restored: false };
|
|
5352
|
+
await expect(exerciseWedgedAttention(true, cleanup)).rejects.toThrow('injected assertion-path failure');
|
|
5353
|
+
expect(cleanup).toEqual({ owned: 1, pending: 0, ready: true, closed: true, restored: true });
|
|
5123
5354
|
});
|
|
5124
5355
|
it('returns a bounded failure when durable attention persistence fails', async () => {
|
|
5125
5356
|
const root = await mkdtemp(join(tmpdir(), 'gestalt-mobile-root-'));
|
|
@@ -5143,6 +5374,7 @@ describe('production composition', () => {
|
|
|
5143
5374
|
}),
|
|
5144
5375
|
},
|
|
5145
5376
|
});
|
|
5377
|
+
onTestFinished(() => app.close());
|
|
5146
5378
|
await createComposedSession(app);
|
|
5147
5379
|
const handle = await vi.waitFor(() => {
|
|
5148
5380
|
const candidate = handles.find((item) => item.request);
|
|
@@ -6546,7 +6778,40 @@ describe('production composition', () => {
|
|
|
6546
6778
|
const analytics = replay.events.filter((event) => event.type === 'tool.efficiency.updated');
|
|
6547
6779
|
expect(analytics).toHaveLength(6);
|
|
6548
6780
|
expect(analytics.at(-1)?.payload).toEqual(snapshot);
|
|
6549
|
-
|
|
6781
|
+
const assertPayloadPrivacy = (value) => {
|
|
6782
|
+
if (typeof value === 'number')
|
|
6783
|
+
expect([500, 1000]).not.toContain(value);
|
|
6784
|
+
else if (value && typeof value === 'object') {
|
|
6785
|
+
for (const [key, child] of Object.entries(value)) {
|
|
6786
|
+
expect(key).not.toMatch(/token|usage|^(arguments|command|aggregatedOutput|contentItems|text|prompt|output|code)$/i);
|
|
6787
|
+
assertPayloadPrivacy(child);
|
|
6788
|
+
}
|
|
6789
|
+
}
|
|
6790
|
+
};
|
|
6791
|
+
const assertAnalyticsPrivacy = (events) => {
|
|
6792
|
+
expect(JSON.stringify(events)).not.toMatch(/secret|synthetic command|nested/);
|
|
6793
|
+
for (const event of events)
|
|
6794
|
+
assertPayloadPrivacy(event.payload);
|
|
6795
|
+
};
|
|
6796
|
+
assertAnalyticsPrivacy(analytics);
|
|
6797
|
+
// Milliseconds are valid observation metadata, not numeric provider usage.
|
|
6798
|
+
assertAnalyticsPrivacy([
|
|
6799
|
+
{
|
|
6800
|
+
...analytics[0],
|
|
6801
|
+
occurredAt: '2026-11-06T19:32:00.500Z',
|
|
6802
|
+
payload: { ...snapshot, observedAt: '2026-11-06T19:32:00.500Z' },
|
|
6803
|
+
},
|
|
6804
|
+
]);
|
|
6805
|
+
// Keep the privacy guard sensitive to usage fields and values at any depth.
|
|
6806
|
+
for (const payload of [
|
|
6807
|
+
{ groups: [{ totalTokens: 1 }] },
|
|
6808
|
+
{ tokenUsage: { last: { value: 1 } } },
|
|
6809
|
+
{ groups: [{ durationMs: { value: 500 } }] },
|
|
6810
|
+
{ groups: [{ durationMs: { value: 1000 } }] },
|
|
6811
|
+
{ groups: [{ command: 'otherwise innocuous' }] },
|
|
6812
|
+
{ groups: [{ description: 'secret synthetic command nested' }] },
|
|
6813
|
+
])
|
|
6814
|
+
expect(() => assertAnalyticsPrivacy([{ ...analytics[0], payload }])).toThrow();
|
|
6550
6815
|
const sameEvents = journal.currentSequence(sessionId);
|
|
6551
6816
|
notify(wrapper);
|
|
6552
6817
|
expect((await app.inject(`/api/sessions/${sessionId}`)).json().toolEfficiency).toEqual(snapshot);
|
|
@@ -6660,20 +6925,82 @@ describe('production composition', () => {
|
|
|
6660
6925
|
message.event.payload?.status === 'ready')).toBe(true));
|
|
6661
6926
|
expect(JSON.stringify(messages)).not.toMatch(/TOKEN|secret|stderr/);
|
|
6662
6927
|
});
|
|
6663
|
-
it('hydrates chat and resyncs a large replay without materializing the journal', async () => {
|
|
6928
|
+
it('hydrates chat and resyncs a large replay without materializing the journal', async (context) => {
|
|
6929
|
+
const diagnostic = {
|
|
6930
|
+
stage: 'fixture',
|
|
6931
|
+
elapsedMs: { fixture: 0 },
|
|
6932
|
+
upgradeSeen: false,
|
|
6933
|
+
teardownStarted: false,
|
|
6934
|
+
closeBeforeTeardown: false,
|
|
6935
|
+
errorBeforeTeardown: false,
|
|
6936
|
+
opened: false,
|
|
6937
|
+
message: false,
|
|
6938
|
+
closed: false,
|
|
6939
|
+
error: false,
|
|
6940
|
+
};
|
|
6941
|
+
const began = performance.now();
|
|
6942
|
+
const stamp = (stage) => {
|
|
6943
|
+
diagnostic.elapsedMs[stage] = Math.round(performance.now() - began);
|
|
6944
|
+
};
|
|
6945
|
+
const stage = (value) => {
|
|
6946
|
+
diagnostic.stage = value;
|
|
6947
|
+
stamp(value);
|
|
6948
|
+
};
|
|
6949
|
+
onTestFinished(() => {
|
|
6950
|
+
if (context.task.result?.state === 'fail')
|
|
6951
|
+
console.info('large-replay-diagnostic', JSON.stringify(diagnostic));
|
|
6952
|
+
});
|
|
6664
6953
|
const fixture = await createProductionAutopilotFixture();
|
|
6665
6954
|
const { app, sessionId } = fixture;
|
|
6666
6955
|
onTestFinished(() => app.close());
|
|
6956
|
+
stage('journal');
|
|
6667
6957
|
const database = new DatabaseSync(join(fixture.dataDir, 'relay.sqlite'));
|
|
6668
6958
|
const journal = new SqliteEventJournal(database);
|
|
6669
|
-
|
|
6670
|
-
|
|
6671
|
-
|
|
6672
|
-
|
|
6959
|
+
let activity;
|
|
6960
|
+
try {
|
|
6961
|
+
// Replay size is the precondition; per-append transaction throughput is not under test.
|
|
6962
|
+
database.exec('BEGIN IMMEDIATE');
|
|
6963
|
+
let firstSequence;
|
|
6964
|
+
try {
|
|
6965
|
+
const row = database
|
|
6966
|
+
.prepare('SELECT next_sequence AS sequence FROM relay_sessions WHERE id = ?')
|
|
6967
|
+
.get(sessionId);
|
|
6968
|
+
firstSequence = row.sequence;
|
|
6969
|
+
expect(firstSequence).toBe(journal.currentSequence(sessionId) + 1);
|
|
6970
|
+
const insert = database.prepare('INSERT INTO session_events (session_id,sequence,occurred_at,type,payload_json) VALUES (?,?,?,?,?)');
|
|
6971
|
+
const payload = JSON.stringify({ synthetic: 'x'.repeat(4096) });
|
|
6972
|
+
for (let index = 0; index < 250; index++)
|
|
6973
|
+
insert.run(sessionId, firstSequence + index, new Date().toISOString(), 'agent.activity.updated', payload);
|
|
6974
|
+
expect(database
|
|
6975
|
+
.prepare('UPDATE relay_sessions SET next_sequence = ? WHERE id = ?')
|
|
6976
|
+
.run(firstSequence + 250, sessionId).changes).toBe(1);
|
|
6977
|
+
expect(database
|
|
6978
|
+
.prepare("SELECT COUNT(*) AS count, SUM(length(CAST(payload_json AS BLOB))) AS bytes, MIN(sequence) AS first, MAX(sequence) AS last FROM session_events WHERE session_id = ? AND type = 'agent.activity.updated' AND sequence >= ? AND sequence < ?")
|
|
6979
|
+
.get(sessionId, firstSequence, firstSequence + 250)).toMatchObject({
|
|
6980
|
+
count: 250,
|
|
6981
|
+
bytes: Buffer.byteLength(payload) * 250,
|
|
6982
|
+
first: firstSequence,
|
|
6983
|
+
last: firstSequence + 249,
|
|
6984
|
+
});
|
|
6985
|
+
expect(Buffer.byteLength(payload) * 250).toBeGreaterThan(1_000_000);
|
|
6986
|
+
database.exec('COMMIT');
|
|
6987
|
+
}
|
|
6988
|
+
catch (error) {
|
|
6989
|
+
database.exec('ROLLBACK');
|
|
6990
|
+
throw error;
|
|
6991
|
+
}
|
|
6992
|
+
activity = journal.append(sessionId, 'activity.updated', { id: 'command', label: 'Command', detail: 'completed' }, new Date().toISOString());
|
|
6993
|
+
expect(activity.sequence).toBe(firstSequence + 250);
|
|
6994
|
+
expect(journal.currentSequence(sessionId)).toBe(activity.sequence);
|
|
6995
|
+
}
|
|
6996
|
+
finally {
|
|
6997
|
+
database.close();
|
|
6998
|
+
}
|
|
6673
6999
|
const fullRead = vi.spyOn(SqliteEventJournal.prototype, 'since').mockImplementation(() => {
|
|
6674
7000
|
throw new Error('Unbounded journal reads must not be used by Chat');
|
|
6675
7001
|
});
|
|
6676
7002
|
onTestFinished(() => fullRead.mockRestore());
|
|
7003
|
+
stage('history');
|
|
6677
7004
|
const history = await app.inject(`/api/sessions/${sessionId}/history`);
|
|
6678
7005
|
expect(history.statusCode).toBe(200);
|
|
6679
7006
|
expect(history.json()).toMatchObject({
|
|
@@ -6683,26 +7010,88 @@ describe('production composition', () => {
|
|
|
6683
7010
|
]),
|
|
6684
7011
|
});
|
|
6685
7012
|
expect(history.json().baseSequence).toBeGreaterThanOrEqual(activity.sequence);
|
|
7013
|
+
stage('listen');
|
|
6686
7014
|
await app.listen({ host: '127.0.0.1', port: 0 });
|
|
6687
7015
|
const address = app.server.address();
|
|
6688
7016
|
if (!address || typeof address === 'string')
|
|
6689
7017
|
throw new Error('Expected TCP listener');
|
|
7018
|
+
const upgradeMarker = `large-replay-${sessionId}`;
|
|
7019
|
+
const observeUpgrade = (request) => {
|
|
7020
|
+
if (request.url === `/api/sessions/${sessionId}/events?after=0` &&
|
|
7021
|
+
request.headers['x-test-replay-id'] === upgradeMarker) {
|
|
7022
|
+
diagnostic.upgradeSeen = true;
|
|
7023
|
+
stamp('upgrade');
|
|
7024
|
+
}
|
|
7025
|
+
};
|
|
7026
|
+
app.server.on('upgrade', observeUpgrade);
|
|
7027
|
+
onTestFinished(() => {
|
|
7028
|
+
app.server.off('upgrade', observeUpgrade);
|
|
7029
|
+
});
|
|
6690
7030
|
const socket = new WebSocket(`ws://127.0.0.1:${address.port}/api/sessions/${sessionId}/events?after=0`, {
|
|
6691
7031
|
headers: {
|
|
6692
7032
|
origin: relyingParty.publicOrigin,
|
|
6693
7033
|
cookie: 'gestalt_mobile_session=test-session',
|
|
7034
|
+
'x-test-replay-id': upgradeMarker,
|
|
6694
7035
|
},
|
|
6695
7036
|
});
|
|
7037
|
+
stage('socket');
|
|
7038
|
+
const closeSocket = () => {
|
|
7039
|
+
if (!diagnostic.teardownStarted) {
|
|
7040
|
+
diagnostic.teardownStarted = true;
|
|
7041
|
+
stamp('teardown');
|
|
7042
|
+
}
|
|
7043
|
+
socket.close();
|
|
7044
|
+
};
|
|
7045
|
+
onTestFinished(closeSocket);
|
|
7046
|
+
socket.on('open', () => {
|
|
7047
|
+
diagnostic.opened = true;
|
|
7048
|
+
stamp('socketOpen');
|
|
7049
|
+
});
|
|
7050
|
+
socket.on('close', () => {
|
|
7051
|
+
diagnostic.closed = true;
|
|
7052
|
+
diagnostic.closeBeforeTeardown ||= !diagnostic.teardownStarted;
|
|
7053
|
+
stamp('socketClose');
|
|
7054
|
+
});
|
|
7055
|
+
socket.on('error', () => {
|
|
7056
|
+
diagnostic.error = true;
|
|
7057
|
+
diagnostic.errorBeforeTeardown ||= !diagnostic.teardownStarted;
|
|
7058
|
+
stamp('socketError');
|
|
7059
|
+
});
|
|
6696
7060
|
try {
|
|
6697
|
-
const
|
|
7061
|
+
const data = await new Promise((resolve, reject) => {
|
|
7062
|
+
const cleanup = () => {
|
|
7063
|
+
socket.off('message', message);
|
|
7064
|
+
socket.off('close', closed);
|
|
7065
|
+
socket.off('error', failed);
|
|
7066
|
+
};
|
|
7067
|
+
const message = (data) => {
|
|
7068
|
+
stage('message');
|
|
7069
|
+
diagnostic.message = true;
|
|
7070
|
+
cleanup();
|
|
7071
|
+
resolve(data);
|
|
7072
|
+
};
|
|
7073
|
+
const closed = () => {
|
|
7074
|
+
cleanup();
|
|
7075
|
+
reject(new Error(`REPLAY_SOCKET_CLOSED_BEFORE_MESSAGE ${JSON.stringify(diagnostic)}`));
|
|
7076
|
+
};
|
|
7077
|
+
const failed = () => {
|
|
7078
|
+
cleanup();
|
|
7079
|
+
reject(new Error(`REPLAY_SOCKET_ERROR_BEFORE_MESSAGE ${JSON.stringify(diagnostic)}`));
|
|
7080
|
+
};
|
|
7081
|
+
socket.once('message', message);
|
|
7082
|
+
socket.once('close', closed);
|
|
7083
|
+
socket.once('error', failed);
|
|
7084
|
+
});
|
|
6698
7085
|
expect(JSON.parse(String(data))).toMatchObject({
|
|
6699
7086
|
type: 'relay.resyncRequired',
|
|
6700
7087
|
currentSequence: expect.any(Number),
|
|
6701
7088
|
});
|
|
6702
7089
|
expect(fullRead).not.toHaveBeenCalled();
|
|
7090
|
+
stage('asserted');
|
|
6703
7091
|
}
|
|
6704
7092
|
finally {
|
|
6705
|
-
|
|
7093
|
+
app.server.off('upgrade', observeUpgrade);
|
|
7094
|
+
closeSocket();
|
|
6706
7095
|
}
|
|
6707
7096
|
});
|
|
6708
7097
|
it('starts Self DEBUG with the configured executor model and exact source skill profile', async () => {
|
|
@@ -1324,6 +1324,7 @@ export async function composeRelayApp(options) {
|
|
|
1324
1324
|
skills: catalog.skills,
|
|
1325
1325
|
skillsConfig: selected.skillsConfig,
|
|
1326
1326
|
start: true,
|
|
1327
|
+
startup: !session.threadId,
|
|
1327
1328
|
});
|
|
1328
1329
|
return playwright.prepare(state, playwrightAuthority(session), {
|
|
1329
1330
|
rpc,
|