Repository navigation
Conversation
…ion/history_tail` AIR follows sessions that another Codex client writes, such as the Codex CLI. A `session/load` of such a thread fails: `thread/resume` takes the writer lock. The new request reads the thread with `thread/read`, `thread/items/list` and `thread/turns/list` only. It takes no lock and opens no session. - `CodexAcpClient.readSessionHistory` gives the stored history without `thread/resume`, close to the change of PR #815. A legacy thread uses one `thread/read`. - `streamThreadHistory` replays into a target: a state, a connection and a sink. A load uses the open session. The tail uses a detached state and its own delivery, so the `_meta` filter is the filter of a load. - The tail replays the whole history into a recorder and cuts it after the cursor item of each session, as the Claude adapter does. `unchanged` reads only the newest item and turn of the root thread and the newest item of each open subagent. `rewritten` comes when the cursor item is gone, as after `thread/revert`. `turnOpen` tells that the newest turn has no end. - A v1 client with `loadReplayEnd` gets one `session_info_update` after the load replay. With `historyTail` it carries `historyCursor`. - The `thread_active_writer` refusal carries an empty `data.held` object, the form of the Claude adapter. Codex does not name the holder, and the tail cannot tell a held thread without `thread/resume`, so its answer has no `held`. A live test with two app-servers on one temporary Codex home shows that the second one reads the held thread, and that it sees the running turn of the first one as interrupted with no `completedAt`. So `turnOpen` is true while that turn runs.
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved history-tail defects can leave child history stale, cause repeated full-history replays, and prevent clients from recognizing retryable read failures.
3 open issues
What changed in this PR
Adds read-only session history polling for AIR clients, reusing the adapter’s load replay logic without opening a session or taking its writer lock.
Changes:
- Adds
_session/history_tailwith opaque cursors, paging, cached replays, and change detection. - Adds load replay cursors and empty
heldmetadata to active-writer errors. - Documents the contract and updates integration tests and capability snapshots.
| File | Description |
|---|---|
src/HistoryTail.ts |
Implements cursors, replay recording, paging, and caching. |
src/CodexThreadErrors.ts |
Recognizes missing rollouts and adds holder metadata. |
src/CodexAppServerClient.ts |
Exports the history timeout helper. |
src/CodexAcpServer.ts |
Integrates detached replay and history-tail requests. |
src/CodexAcpClient.ts |
Adds read-only history, head, and model reads. |
src/AirExtension.ts |
Defines history-tail and replay-end metadata keys. |
src/AcpAgentRouter.ts |
Routes tail requests and disposes cached replays. |
src/__tests__/scenarios/scenario-harness.ts |
Adds the expected history-tail capability. |
src/__tests__/scenarios/data/air/web-search.jsonl |
Updates advertised capability snapshot. |
src/__tests__/scenarios/data/air/subagent-activity.jsonl |
Updates advertised capability snapshot. |
src/__tests__/scenarios/data/air/read-search-list.jsonl |
Updates advertised capability snapshot. |
src/__tests__/scenarios/data/air/plan-stream.jsonl |
Updates advertised capability snapshot. |
src/__tests__/scenarios/data/air/plan-review-permission.jsonl |
Updates advertised capability snapshot. |
src/__tests__/scenarios/data/air/plan-deltas-and-turn-plan.jsonl |
Updates advertised capability snapshot. |
src/__tests__/scenarios/data/air/network-and-sandbox-approval.jsonl |
Updates advertised capability snapshot. |
src/__tests__/scenarios/data/air/nested-subagent-session.jsonl |
Updates advertised capability snapshot. |
src/__tests__/scenarios/data/air/native-subagent-session.jsonl |
Updates advertised capability snapshot. |
src/__tests__/scenarios/data/air/mcp-url-elicitation.jsonl |
Updates advertised capability snapshot. |
src/__tests__/scenarios/data/air/mcp-tool.jsonl |
Updates advertised capability snapshot. |
src/__tests__/scenarios/data/air/mcp-tool-approval.jsonl |
Updates advertised capability snapshot. |
src/__tests__/scenarios/data/air/mcp-startup-failure.jsonl |
Updates advertised capability snapshot. |
src/__tests__/scenarios/data/air/mcp-elicitation.jsonl |
Updates advertised capability snapshot. |
src/__tests__/scenarios/data/air/late-subagent-update.jsonl |
Updates advertised capability snapshot. |
src/__tests__/scenarios/data/air/image-view.jsonl |
Updates advertised capability snapshot. |
src/__tests__/scenarios/data/air/image-generation.jsonl |
Updates advertised capability snapshot. |
src/__tests__/scenarios/data/air/history-replay.jsonl |
Updates advertised capability snapshot. |
src/__tests__/scenarios/data/air/guardian-review.jsonl |
Updates advertised capability snapshot. |
src/__tests__/scenarios/data/air/goal-update.jsonl |
Updates advertised capability snapshot. |
src/__tests__/scenarios/data/air/fuzzy-file-search.jsonl |
Updates advertised capability snapshot. |
src/__tests__/scenarios/data/air/file-changes.jsonl |
Updates advertised capability snapshot. |
src/__tests__/scenarios/data/air/file-change-approval.jsonl |
Updates advertised capability snapshot. |
src/__tests__/scenarios/data/air/dynamic-tool.jsonl |
Updates advertised capability snapshot. |
src/__tests__/scenarios/data/air/context-compaction.jsonl |
Updates advertised capability snapshot. |
src/__tests__/scenarios/data/air/command-without-streamed-output.jsonl |
Updates advertised capability snapshot. |
src/__tests__/scenarios/data/air/command-output-stdin.jsonl |
Updates advertised capability snapshot. |
src/__tests__/scenarios/data/air/command-failed.jsonl |
Updates advertised capability snapshot. |
src/__tests__/scenarios/data/air/command-approval.jsonl |
Updates advertised capability snapshot. |
src/__tests__/scenarios/data/air/collab-controls.jsonl |
Updates advertised capability snapshot. |
src/__tests__/scenarios/data/air/collab-agent.jsonl |
Updates advertised capability snapshot. |
src/__tests__/scenarios/data/air/background-terminal.jsonl |
Updates advertised capability snapshot. |
src/__tests__/scenarios/data/air/agent-message-and-reasoning.jsonl |
Updates advertised capability snapshot. |
src/__tests__/integration/history-tail.test.ts |
Tests following a session held by another process. |
src/__tests__/CodexACPAgent/thread-active-writer.test.ts |
Expects empty holder metadata in refusal errors. |
src/__tests__/CodexACPAgent/initialize.test.ts |
Expects history-tail capability advertisement. |
src/__tests__/CodexACPAgent/data/session-index-capabilities.json |
Updates capability expectations. |
README.md |
Links to the read-only history-tail feature. |
docs/air-extensions.md |
Documents requests, responses, cursors, and limitations. |
Review effort: Balanced
| const last = turn?.items.at(-1); | ||
| item = last ? itemIdentity(last, true) : ""; |
There was a problem hiding this comment.
Fixed in b3b2c9a. When the newest turn of a legacy thread has no item yet, the head now pages back through earlier turns to the newest item. turn and turnOpen still come from the newest turn. A new test checks that such a thread answers unchanged. It fails without the fix.
| } catch (error) { | ||
| const refused = storedSessionError(sessionId, error, this.sessionIndex.enabled); | ||
| // A thread that Codex does not have is -32002. Each other failed read can pass on a later try. | ||
| if (refused instanceof RequestError) throw refused; |
There was a problem hiding this comment.
Fixed in b3b2c9a. The tail wrapper now turns the process-exit error (code 1001) into the retryable history_read_failed error. Not-found (-32002), cancellation and tail errors that are already normalized pass through unchanged. A new test covers an exit during a root read. It fails without the fix.
| for (const [threadId, item] of Object.entries(signature.children)) { | ||
| if ((await head(threadId)).item !== item) return false; |
There was a problem hiding this comment.
Fixed in b3b2c9a. For a legacy subagent, c now names the last item plus a rolling hash of all the items of its newest turn. The head computes the same value from that turn. The subagent session is exactly that turn. So a rollback and a new run that end with the same item no longer match, and the tail answers rewritten. A new test covers this case. It fails without the fix.
…cess exits - A legacy thread whose newest turn has no item yet now takes the newest item of an earlier turn for its signature. Before, the signature never matched, and each tail replayed the whole history. - The signature of a legacy subagent now names its last item and a rolling hash of all the items of its newest turn. A rollback and a new run that end with the same item now answer `rewritten`, not `unchanged`. - An exit of the Codex process during a read now fails the tail with the retryable `history_read_failed` error, as other failed reads do.
…use of a process exit The paging back to the newest item of a legacy thread had no guard for a repeated cursor, so a bad cursor from Codex made the read loop forever. It now fails the read, which gives the retryable history error. When an exit of the Codex process fails a history tail read, the history_read_failed error now keeps the code, the message and the data of the exit error in data.cause. The client can see restartable and retryAfterMs and stop when a later try does not help.

Summary
This change adds the
_session/history_tailrequest. A client can read the history of a stored session after a cursor. The read takes no writer lock and opens no session.Why
An AIR client shows sessions that another Codex process writes, such as the Codex CLI in a terminal. A
session/loadof such a thread fails, becausethread/resumetakes the writer lock. The client must follow that session read only. The new request reads the thread withthread/read,thread/items/listandthread/turns/list. It never callsthread/resume.What it adds
_session/history_tailwith an opaque cursor. The client sends back the cursor as it is.ok: the updates after the cursor, in the order of a load replay, and a new cursor.unchanged: no updates. This read costs only a few small reads of the newest item and turn.rewritten: the cursor names an item that the history no longer holds, for example afterthread/revert. The client reads the whole history again.turnOpentells the client that the newest turn of the root thread can still run.limit, an answer can havemore: true. The client asks again with the new cursor. The pages together give the same updates as one answer.historyCursoron the load replay end update, for a client that declareshistoryTail. The first tail after a load starts from it.thread_active_writerrefusal ofsession/loadnow carriesdata.heldas an empty object. Codex does not name the holder, so the object has no fields.Failure rule
A failed read of the root thread, of a subagent thread, or of
model/listfails the whole tail. The error is-32603withdata.reasonhistory_read_failedandretryable: true. The error has no updates and no cursor. The client keeps its cursor and asks again later. A root thread that Codex does not have answers-32002.Known limits
invalid_requesterror, so the agent matches these error texts.rewritten, and the client reads the whole history again.interruptedwith no end time. SoturnOpenstaystruewhile that turn runs.Contract
See
docs/air-extensions.md, sections "History tail" and "Load replay end".Tests
npm run typecheck: passes.npm test: 171 files passed, 7 skipped. 2851 tests passed, 39 skipped.npm run test:integration: 12 files and 29 tests passed.