fix(codex): fork archived sessions without reopening the source (#2231)

* fix(codex): fork archived sessions without reopening the source

* fix(codex): reconcile interrupted archived fork recovery

* fix(codex): release rejected forks and serialize source startup

* fix(codex): fence unconfirmed resume startup across retries

* test(codex): validate durable resume recovery and serialize archive

* fix(codex): block local resume of pending archived fork sources

* fix(hub): coalesce concurrent resume requests to preserve idempotent startup

* fix(hub): bypass startup coalescing for PTY sessions
This commit is contained in:
Ananovo
2026-11-01 09:55:01 +08:00
committed by GitHub
parent 639f71b6a6
commit 46bae9b0f1
30 changed files with 1377 additions and 34 deletions
+26 -2
View File
@@ -67,6 +67,7 @@ async function fixture(opts?: { hubArchived?: boolean; end?: RootHost['end']; cr
const send = vi.fn();
const consumed = vi.fn();
const uncertain = vi.fn();
const sessionReady = vi.fn();
const hubArchivedListeners: Array<() => void> = [];
const session = {
sessionId: 'sid', getMetadata: () => metadata,
@@ -79,7 +80,7 @@ async function fixture(opts?: { hubArchived?: boolean; end?: RootHost['end']; cr
if (event === 'hub-archived') hubArchivedListeners.push(listener);
},
rpcHandlerManager: { registerHandler: (name: string, handler: (raw: unknown) => Promise<unknown>) => rpc.set(name, handler) },
sendSessionEvent() {}, sendAgentMessage: send, emitSessionReady() {},
sendSessionEvent() {}, sendAgentMessage: send, emitSessionReady: sessionReady,
sendUserMessage() {}, emitMessagesConsumed: consumed, emitSteerIndeterminate: uncertain, syncNativeQueuedMessage() {},
sendSessionDeath() {}, async flush() {}, close() {}
} as unknown as ApiSessionClient;
@@ -102,7 +103,7 @@ async function fixture(opts?: { hubArchived?: boolean; end?: RootHost['end']; cr
responses: Array<{ id: string | number; result: unknown }>;
};
return {
root, native, rpc, send, consumed, uncertain, metadata: () => metadata, state: () => state, updateState,
root, native, rpc, send, consumed, uncertain, sessionReady, metadata: () => metadata, state: () => state, updateState,
drain: () => (root as unknown as { notifications: Promise<void> }).notifications,
reconnect: () => reconnect?.(),
emitHubArchived: () => { for (const listener of hubArchivedListeners) listener(); },
@@ -111,6 +112,29 @@ async function fixture(opts?: { hubArchived?: boolean; end?: RootHost['end']; cr
};
}
describe('native readiness after Hub reconnect', () => {
it('replays readiness only after an activated root revalidates native history', async () => {
const f = await fixture()
f.reconnect()
await vi.waitFor(() => expect(f.state().steeringActive).toBe(false))
expect(f.sessionReady).not.toHaveBeenCalled()
await f.root.activate()
expect(f.sessionReady).toHaveBeenCalledTimes(1)
f.reconnect()
await vi.waitFor(() => expect(f.sessionReady).toHaveBeenCalledTimes(2))
})
it('does not replay readiness if native revalidation fails', async () => {
const f = await fixture()
await f.root.activate()
const read = vi.spyOn(f.root.client, 'request').mockRejectedValue(new Error('native unavailable'))
f.reconnect()
await vi.waitFor(() => expect(read).toHaveBeenCalledWith('thread/read', expect.anything()))
await new Promise(resolve => setTimeout(resolve, 10))
expect(f.sessionReady).toHaveBeenCalledTimes(1)
})
})
async function startCompaction(f: Awaited<ReturnType<typeof fixture>>, id = 'input', turnId = 'compacting-turn') {
f.native.queue = [{ id: `native-${id}`, clientUserMessageId: id, input: [{ type: 'text', text: id }] }];
await f.root.refresh();