refactor(codex): keep the receipt-timed notification methods with the event they stamp

This commit is contained in:
Brennan Benson
2026-10-05 16:17:11 -07:00
parent 616255036b
commit df677d665f
2 changed files with 13 additions and 11 deletions
@@ -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<string> = 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 =
@@ -44,6 +44,15 @@ export type CodexStructuredLaunch = {
env?: Record<string, string>
}
/** 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<string> = 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