fix(codex): persist Round duration across session reloads (#2025)

* fix(codex): persist Round duration across session reloads

* fix(codex): preserve completed plan summaries between turns

* test(ios): make plan transcript recycling deterministic

* fix(ios): preserve reading anchors with stale sizing attributes
This commit is contained in:
SSU-WEI HUANG
2026-10-26 10:26:55 +08:00
committed by GitHub
parent 713b2d1a7f
commit c64051eba6
24 changed files with 828 additions and 78 deletions
+1 -1
View File
@@ -386,7 +386,7 @@ export function createCodexEventConverter(): CodexEventConverter {
currentTurnId = extractEventTurnId(parsed.data) ?? currentTurnId;
const projection = extractAssistantMessageProjection(parsed.data, currentTurnId);
const converted = convertCodexEvent(parsed.data);
const convertedActions = convertProjectionToActions(converted, projection?.turnId ?? null);
const convertedActions = convertProjectionToActions(converted, projection?.turnId ?? extractEventTurnId(parsed.data));
const payload = asRecord(parsed.data.payload);
if (parsed.data.type === 'compacted') {
+27
View File
@@ -0,0 +1,27 @@
import { describe, expect, it } from 'vitest';
import { CodexRoundDuration } from './roundDuration';
describe('Codex live round duration', () => {
it('keeps the original start, ignores stale completions and persists once', () => {
const clock = new CodexRoundDuration();
clock.start('turn', 1000);
clock.start('turn', 2000);
expect(clock.finish('old', 3000, true)).toBeUndefined();
expect(clock.finish('turn', 4000, true)).toEqual({ type: 'turn_duration', flavor: 'codex', turn_id: 'turn', durationMs: 3000 });
expect(clock.finish('turn', 5000, true)).toBeUndefined();
clock.start('instant', 0);
expect(clock.finish('instant', 0, true)?.durationMs).toBe(0);
});
it('does not invent a start for completion-only history or interrupted turns', () => {
const clock = new CodexRoundDuration();
expect(clock.finish('imported', 4000, true)).toBeUndefined();
clock.start('failed', 1000);
expect(clock.finish('failed', 4000, false)).toBeUndefined();
expect(clock.finish('failed', 5000, true)).toBeUndefined();
});
it.each([NaN, Infinity, -1])('rejects invalid or reversed time %s', time => {
const clock = new CodexRoundDuration();
clock.start('turn', 1000);
expect(clock.finish('turn', time, true)).toBeUndefined();
});
});
+19
View File
@@ -0,0 +1,19 @@
/** Tracks only observed live starts; replay callers must never seed this clock. */
export class CodexRoundDuration {
private active: { turnId: string; startedAt: number } | undefined;
get turnId(): string | undefined { return this.active?.turnId; }
start(turnId: string | null | undefined, startedAt: number): void {
if (!turnId || !Number.isFinite(startedAt) || this.active?.turnId === turnId) return;
this.active = { turnId, startedAt };
}
finish(turnId: string | null | undefined, completedAt: number, completed: boolean) {
if (!turnId || this.active?.turnId !== turnId) return;
const { startedAt } = this.active;
this.active = undefined;
if (!completed || !Number.isFinite(completedAt) || completedAt < startedAt) return;
return { type: 'turn_duration' as const, flavor: 'codex' as const, turn_id: turnId, durationMs: completedAt - startedAt };
}
}