From df677d665f270656c9236da00dc1d4232d09824d Mon Sep 17 00:00:00 2001 From: Brennan Benson <79079362+brennanb2025@users.noreply.github.com> Date: Mon, 5 Oct 2026 16:17:11 -0700 Subject: [PATCH] refactor(codex): keep the receipt-timed notification methods with the event they stamp --- src/main/codex/codex-structured-session-acquire.ts | 12 ++---------- src/main/codex/codex-structured-session-state.ts | 12 +++++++++++- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/main/codex/codex-structured-session-acquire.ts b/src/main/codex/codex-structured-session-acquire.ts index a878b9597b5..61856ef5f24 100644 --- a/src/main/codex/codex-structured-session-acquire.ts +++ b/src/main/codex/codex-structured-session-acquire.ts @@ -38,6 +38,7 @@ import { } from './codex-structured-fast-mode' import { assertCodexConnectionOpen, + CODEX_RECEIPT_TIMED_METHODS, codexSessionLifecycle, mintCodexAcquisitionGeneration, type CodexAcquisitionRegistry, @@ -49,15 +50,6 @@ import type { CodexStructuredSessionTeardown } from './codex-structured-session- import type { CodexStructuredNotificationRetry } from './codex-structured-notification-retry' import type { deliverCodexServerRequest } from './codex-structured-provider-events' -// Turn and item boundaries are timed by when the host received them, never by when a buffered or -// retried delivery got round to them. -const RECEIPT_TIMED_METHODS: ReadonlySet = new Set([ - 'turn/started', - 'turn/completed', - 'item/started', - 'item/completed' -]) - export async function acquireCodexStructuredSession(input: { input: StructuredAgentSessionAcquireInput deps: CodexStructuredSessionAdapterDeps @@ -151,7 +143,7 @@ export async function acquireCodexStructuredSession(input: { { onNotification: (method, params) => { // Stamped at receipt, ahead of any pre-publication buffering or retry. - const observedAt = RECEIPT_TIMED_METHODS.has(method) + const observedAt = CODEX_RECEIPT_TIMED_METHODS.has(method) ? (deps.now?.() ?? Date.now()) : undefined const dispatchSequenceAtReceipt = diff --git a/src/main/codex/codex-structured-session-state.ts b/src/main/codex/codex-structured-session-state.ts index f70517668b5..a96499846bb 100644 --- a/src/main/codex/codex-structured-session-state.ts +++ b/src/main/codex/codex-structured-session-state.ts @@ -44,6 +44,15 @@ export type CodexStructuredLaunch = { env?: Record } +/** Turn and item boundaries, timed by when the host received them, never by when a buffered or + * retried delivery got round to them. */ +export const CODEX_RECEIPT_TIMED_METHODS: ReadonlySet = new Set([ + 'turn/started', + 'turn/completed', + 'item/started', + 'item/completed' +]) + export type CodexStructuredSessionEvent = | { type: 'notification' @@ -51,7 +60,8 @@ export type CodexStructuredSessionEvent = threadId: string method: string params: unknown - /** Host receipt time of a turn boundary; survives retry and deferral so a replay is not re-stamped. */ + /** Host receipt time of a `CODEX_RECEIPT_TIMED_METHODS` boundary; survives retry and + * deferral so a replay is not re-stamped. */ observedAt?: number /** Highest dispatch sequence armed when this turn-start was first received. */ dispatchSequenceAtReceipt?: number