gestalt-mobile 0.45.1 → 0.45.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.
|
@@ -830,6 +830,124 @@ describe('production composition', () => {
|
|
|
830
830
|
expect(accepted.handles.flatMap((handle) => handle.calls)).not.toContain('turn/start');
|
|
831
831
|
await accepted.app.close();
|
|
832
832
|
});
|
|
833
|
+
it('resumes the same executor after a checkpoint while activity is refreshed', async () => {
|
|
834
|
+
const timers = [];
|
|
835
|
+
const fixture = await createProductionAutopilotFixture({
|
|
836
|
+
activitySchedule: () => () => { },
|
|
837
|
+
autopilotSchedule: (callback) => {
|
|
838
|
+
const timer = { callback, cancelled: false, fired: false };
|
|
839
|
+
timers.push(timer);
|
|
840
|
+
return () => {
|
|
841
|
+
timer.cancelled = true;
|
|
842
|
+
};
|
|
843
|
+
},
|
|
844
|
+
});
|
|
845
|
+
onTestFinished(() => fixture.app.close());
|
|
846
|
+
const checkpoint = await holdCheckpointRequest(fixture, timers, 8901);
|
|
847
|
+
checkpoint.handle.responseSettled({ id: 8901, outcome: 'resultWritten' });
|
|
848
|
+
await expect(checkpoint.response).resolves.toEqual(toOrgPlanCheckpointToolResponse('recorded'));
|
|
849
|
+
let rootActive = true;
|
|
850
|
+
let holdRoster = false;
|
|
851
|
+
const releaseRoster = [];
|
|
852
|
+
for (const handle of fixture.handles)
|
|
853
|
+
handle.respond = (method, params) => {
|
|
854
|
+
if (method === 'thread/read')
|
|
855
|
+
return {
|
|
856
|
+
thread: {
|
|
857
|
+
id: params.threadId,
|
|
858
|
+
status: { type: rootActive ? 'active' : 'idle' },
|
|
859
|
+
turns: [],
|
|
860
|
+
},
|
|
861
|
+
};
|
|
862
|
+
if (method === 'thread/list') {
|
|
863
|
+
const result = {
|
|
864
|
+
data: [
|
|
865
|
+
{
|
|
866
|
+
id: 'checkpoint-executor',
|
|
867
|
+
status: { type: 'idle' },
|
|
868
|
+
source: { subAgent: { thread_spawn: { agent_path: '/root/l1' } } },
|
|
869
|
+
},
|
|
870
|
+
],
|
|
871
|
+
};
|
|
872
|
+
if (holdRoster)
|
|
873
|
+
return new Promise((resolve) => {
|
|
874
|
+
releaseRoster.push(() => resolve(result));
|
|
875
|
+
});
|
|
876
|
+
return result;
|
|
877
|
+
}
|
|
878
|
+
return undefined;
|
|
879
|
+
};
|
|
880
|
+
await fixture.app.inject({
|
|
881
|
+
method: 'POST',
|
|
882
|
+
url: `/api/sessions/${fixture.sessionId}/activity/refresh`,
|
|
883
|
+
});
|
|
884
|
+
rootActive = false;
|
|
885
|
+
checkpoint.handle.notify({
|
|
886
|
+
method: 'turn/completed',
|
|
887
|
+
params: {
|
|
888
|
+
threadId: checkpoint.threadId,
|
|
889
|
+
turn: { id: checkpoint.turnId, status: 'completed' },
|
|
890
|
+
},
|
|
891
|
+
});
|
|
892
|
+
await vi.waitFor(async () => expect((await fixture.app.inject(`/api/sessions/${fixture.sessionId}`)).json().agentActivity.root
|
|
893
|
+
.state).toBe('idle'));
|
|
894
|
+
const settled = (await fixture.app.inject(`/api/sessions/${fixture.sessionId}`)).json()
|
|
895
|
+
.agentActivity;
|
|
896
|
+
vi.useFakeTimers({ toFake: ['Date'] });
|
|
897
|
+
onTestFinished(() => {
|
|
898
|
+
vi.useRealTimers();
|
|
899
|
+
});
|
|
900
|
+
const refreshedAt = new Date(Date.parse(settled.root.observedAt) + 60_000).toISOString();
|
|
901
|
+
vi.setSystemTime(new Date(refreshedAt));
|
|
902
|
+
await fixture.app.inject({
|
|
903
|
+
method: 'POST',
|
|
904
|
+
url: `/api/sessions/${fixture.sessionId}/activity/refresh`,
|
|
905
|
+
});
|
|
906
|
+
holdRoster = true;
|
|
907
|
+
const refreshing = fixture.app.inject({
|
|
908
|
+
method: 'POST',
|
|
909
|
+
url: `/api/sessions/${fixture.sessionId}/activity/refresh`,
|
|
910
|
+
});
|
|
911
|
+
void refreshing.then(() => { });
|
|
912
|
+
await vi.waitFor(() => expect(releaseRoster.length).toBeGreaterThan(0));
|
|
913
|
+
for (const timer of timers.filter((candidate) => !candidate.cancelled && !candidate.fired)) {
|
|
914
|
+
timer.fired = true;
|
|
915
|
+
timer.callback();
|
|
916
|
+
}
|
|
917
|
+
await new Promise((resolve) => setImmediate(resolve));
|
|
918
|
+
holdRoster = false;
|
|
919
|
+
expect(releaseRoster).toHaveLength(1);
|
|
920
|
+
for (const release of releaseRoster)
|
|
921
|
+
release();
|
|
922
|
+
await refreshing;
|
|
923
|
+
const starts = () => fixture.handles
|
|
924
|
+
.flatMap((handle) => handle.requests)
|
|
925
|
+
.filter((request) => request.method === 'turn/start' &&
|
|
926
|
+
request.params.threadId === 'checkpoint-executor');
|
|
927
|
+
for (let attempt = 0; attempt < 8 && starts().length === 0; attempt += 1) {
|
|
928
|
+
await vi.waitFor(() => expect(starts().length > 0 || timers.some((timer) => !timer.cancelled && !timer.fired)).toBe(true));
|
|
929
|
+
if (starts().length > 0)
|
|
930
|
+
break;
|
|
931
|
+
const timer = timers.find((candidate) => !candidate.cancelled && !candidate.fired);
|
|
932
|
+
timer.fired = true;
|
|
933
|
+
timer.callback();
|
|
934
|
+
await fixture.app.inject({
|
|
935
|
+
method: 'POST',
|
|
936
|
+
url: `/api/sessions/${fixture.sessionId}/activity/refresh`,
|
|
937
|
+
});
|
|
938
|
+
await new Promise((resolve) => setImmediate(resolve));
|
|
939
|
+
}
|
|
940
|
+
await vi.waitFor(() => expect(starts()).toHaveLength(1));
|
|
941
|
+
const database = new DatabaseSync(join(fixture.dataDir, 'relay.sqlite'));
|
|
942
|
+
const events = database
|
|
943
|
+
.prepare("SELECT type FROM session_events WHERE session_id = ? AND type IN ('org-plan.step-reported', 'autopilot.executor-resumed') ORDER BY sequence")
|
|
944
|
+
.all(fixture.sessionId);
|
|
945
|
+
database.close();
|
|
946
|
+
expect(events).toEqual([
|
|
947
|
+
{ type: 'org-plan.step-reported' },
|
|
948
|
+
{ type: 'autopilot.executor-resumed' },
|
|
949
|
+
]);
|
|
950
|
+
});
|
|
833
951
|
it('acknowledges a checkpoint before scheduling and drops an obsolete executor wait lease', async () => {
|
|
834
952
|
const timers = [];
|
|
835
953
|
let coordinator;
|
|
@@ -2184,6 +2302,66 @@ describe('production composition', () => {
|
|
|
2184
2302
|
await Promise.resolve();
|
|
2185
2303
|
expect(starts()).toHaveLength(1);
|
|
2186
2304
|
});
|
|
2305
|
+
it('refreshes unchanged idle evidence so a stale handoff can continue', async () => {
|
|
2306
|
+
const timers = [];
|
|
2307
|
+
const fixture = await createProductionAutopilotFixture({
|
|
2308
|
+
activitySchedule: () => () => { },
|
|
2309
|
+
autopilotSchedule: (callback) => {
|
|
2310
|
+
const timer = { callback, cancelled: false, fired: false };
|
|
2311
|
+
timers.push(timer);
|
|
2312
|
+
return () => {
|
|
2313
|
+
timer.cancelled = true;
|
|
2314
|
+
};
|
|
2315
|
+
},
|
|
2316
|
+
});
|
|
2317
|
+
onTestFinished(() => fixture.app.close());
|
|
2318
|
+
await fixture.app.inject({
|
|
2319
|
+
method: 'PUT',
|
|
2320
|
+
url: `/api/sessions/${fixture.sessionId}/autopilot`,
|
|
2321
|
+
payload: { enabled: false },
|
|
2322
|
+
});
|
|
2323
|
+
await fixture.app.inject({
|
|
2324
|
+
method: 'POST',
|
|
2325
|
+
url: `/api/sessions/${fixture.sessionId}/activity/refresh`,
|
|
2326
|
+
});
|
|
2327
|
+
const before = (await fixture.app.inject(`/api/sessions/${fixture.sessionId}`)).json()
|
|
2328
|
+
.agentActivity;
|
|
2329
|
+
vi.useFakeTimers({ toFake: ['Date'] });
|
|
2330
|
+
onTestFinished(() => {
|
|
2331
|
+
vi.useRealTimers();
|
|
2332
|
+
});
|
|
2333
|
+
const refreshedAt = new Date(Date.parse(before.root.observedAt) + 60_000).toISOString();
|
|
2334
|
+
vi.setSystemTime(new Date(refreshedAt));
|
|
2335
|
+
await fixture.app.inject({
|
|
2336
|
+
method: 'POST',
|
|
2337
|
+
url: `/api/sessions/${fixture.sessionId}/activity/refresh`,
|
|
2338
|
+
});
|
|
2339
|
+
const after = (await fixture.app.inject(`/api/sessions/${fixture.sessionId}`)).json()
|
|
2340
|
+
.agentActivity;
|
|
2341
|
+
expect(after).toMatchObject({
|
|
2342
|
+
confidence: 'fresh',
|
|
2343
|
+
root: {
|
|
2344
|
+
state: 'idle',
|
|
2345
|
+
observedAt: refreshedAt,
|
|
2346
|
+
lastActivityAt: before.root.lastActivityAt,
|
|
2347
|
+
},
|
|
2348
|
+
});
|
|
2349
|
+
await fixture.app.inject({
|
|
2350
|
+
method: 'PUT',
|
|
2351
|
+
url: `/api/sessions/${fixture.sessionId}/autopilot`,
|
|
2352
|
+
payload: { enabled: true },
|
|
2353
|
+
});
|
|
2354
|
+
const starts = () => fixture.handles.flatMap((handle) => handle.calls).filter((call) => call === 'turn/start');
|
|
2355
|
+
for (let attempt = 0; attempt < 8 && starts().length === 0; attempt += 1) {
|
|
2356
|
+
const timer = timers.find((candidate) => !candidate.cancelled && !candidate.fired);
|
|
2357
|
+
expect(timer).toBeDefined();
|
|
2358
|
+
timer.fired = true;
|
|
2359
|
+
timer.callback();
|
|
2360
|
+
await vi.waitFor(() => expect(starts().length > 0 ||
|
|
2361
|
+
timers.some((candidate) => !candidate.cancelled && !candidate.fired)).toBe(true));
|
|
2362
|
+
}
|
|
2363
|
+
expect(starts()).toHaveLength(1);
|
|
2364
|
+
});
|
|
2187
2365
|
it('production incompatible reconcile remains supervised and schedules reinspection', async () => {
|
|
2188
2366
|
let reconciliations = 0;
|
|
2189
2367
|
const timers = [];
|
|
@@ -67,11 +67,17 @@ export class AgentActivityRegistry {
|
|
|
67
67
|
return existing;
|
|
68
68
|
const generation = (this.#generation.get(sessionId) ?? 0) + 1;
|
|
69
69
|
this.#generation.set(sessionId, generation);
|
|
70
|
-
const
|
|
70
|
+
const completion = Promise.withResolvers();
|
|
71
|
+
const running = completion.promise.finally(() => {
|
|
71
72
|
if (this.#inFlight.get(sessionId) === running)
|
|
72
73
|
this.#inFlight.delete(sessionId);
|
|
73
74
|
});
|
|
75
|
+
// Publishing "reconciling" synchronously notifies Autopilot, which can
|
|
76
|
+
// request this refresh again. Install the shared promise before publishing
|
|
77
|
+
// so that reentrant observers cannot launch a second authoritative read
|
|
78
|
+
// and supersede the generation of the first one.
|
|
74
79
|
this.#inFlight.set(sessionId, running);
|
|
80
|
+
void this.#attempt(sessionId, generation, 1).then(completion.resolve, completion.reject);
|
|
75
81
|
return running;
|
|
76
82
|
}
|
|
77
83
|
/** Replaces the observed direct-child set; absent children are disconnected. */
|
|
@@ -111,6 +117,16 @@ export class AgentActivityRegistry {
|
|
|
111
117
|
// healthy. Preserve it as disconnected but keep the aggregate qualified
|
|
112
118
|
// only as stale until a later authoritative read succeeds.
|
|
113
119
|
next = withActivityConfidence(next, children.some((child) => child.qualified === false) ? 'stale' : 'fresh');
|
|
120
|
+
// The complete authoritative read is new observation evidence even when
|
|
121
|
+
// the semantic projector deduplicates an unchanged idle root and roster.
|
|
122
|
+
// Keep liveness separate from activity: a read must not manufacture work
|
|
123
|
+
// progress, but its old timestamp must not force Autopilot to reconcile
|
|
124
|
+
// the same successfully refreshed snapshot forever.
|
|
125
|
+
if (Date.parse(occurredAt) > Date.parse(next.root.observedAt))
|
|
126
|
+
next = Object.freeze({
|
|
127
|
+
...next,
|
|
128
|
+
root: Object.freeze({ ...next.root, observedAt: occurredAt }),
|
|
129
|
+
});
|
|
114
130
|
const current = this.snapshot(sessionId, occurredAt);
|
|
115
131
|
if (next !== current) {
|
|
116
132
|
this.#snapshots.set(sessionId, next);
|