Skip to content

fix(codex): preserve native mixed history and tool records - #905

Merged
leeroybrun merged 3 commits into
happier-dev:devfrom
kairan0:fix/codex-native-history-import
Nov 12, 2026
Merged

leeroybrun merged 3 commits into
happier-dev:devfrom
kairan0:fix/codex-native-history-import

Conversation

@kairan0

@kairan0 kairan0 commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Project native Codex subagent activity, collaboration calls and dynamic tools through the existing stream bridge. Preserve mixed user content in message metadata, and return an oversized indivisible transcript record alone instead of aborting pagination.

Why

Direct history viewing and import can fail on otherwise valid native histories containing these records. Related to #904. This does not address the separate transient duplicate-rendering report (#903).

How to test

  1. Run the CLI tests streamEventBridge.test.ts, pageCodexTranscript.nativeHistory.test.ts and readCodexUserMessageContent.test.ts: 33 passed.
  2. Run adjacent runtime.test.ts, rolloutMapper.test.ts and pageCodexTranscript.test.ts: 279 passed; the missing-CLI error-class assertion failed identically with unmodified base production sources. CLI typecheck and build passed.
  3. Read-only native paging completed for six affected local histories with unique message IDs. After switching the local daemon to the build, the actual encrypted cloud RPC returned all 1,984 projected records across 26 pages for one affected conversation, including a record larger than 1 MB. No conversation contents or credentials are included in this PR.

Notes

  • Draft: end-to-end cloud import/takeover has not been rerun; browser confirmation is pending. Successful history reads are not claimed as a completed import.
  • Mixed user content is preserved in meta.codexNativeContent. Images show an explicit unavailable-preview placeholder; original URL/data or local path is retained. Local image files are not copied.
  • Activity completion does not imply that a child agent has finished. Live completion fields are retained even when absent from the started event.
  • Unknown user-content types still fail explicitly. The larger-record behavior matches existing rollout paging.
  • No server/authentication changes. Existing native histories remain unchanged. The 0.3 port has not been performed; this draft covers the current 0.2 CLI line.
  • AI-assisted implementation and verification. The automated checks and read-only live verification above were performed by the assistant; no personal human UI acceptance is claimed.

Checklist

  • PR targets dev
  • Linked related issue
  • Added regression tests
  • Updated behavior documentation
  • Disclosed AI assistance and validation limits

Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

Note

Preserve native Codex mixed user content and tool records in history

  • Adds readCodexUserMessageContent in readCodexUserMessageContent.ts, which builds display text from text, mention, skill, image, audio, and local-media parts and keeps the original native parts alongside it. Inline media bytes are excluded from display text.
  • The stream bridge now recognizes native subagent, collaboration, and dynamic-tool records as tool contexts, and forwards mixed user content through the history projector instead of rejecting non-text user messages.
  • Provider-originated user messages and direct transcript messages carry the native Codex content in their metadata.
  • Unsupported or malformed native content throws a sanitized projection error that reports only a validated type identifier, not payload text. See codexNativeProjectionError.
  • Risk: pageCodexNativeTranscript now returns an oversized single record as its own page instead of erroring; mixed user media that was previously rejected is now imported with native metadata — check pageCodexTranscript.nativeHistory.test.ts and the feature matrix in codex-feature-matrix.md.

Macroscope summarized d36f5e8.

Summary by CodeRabbit

  • New Features
    • User messages can retain supported native content, including skill references, mentions, and media references, alongside readable text. Images and audio show a preview-unavailable notice while their original references are preserved.
    • Conversation history now displays subagent activity, collaboration tools, and dynamic tool calls with their results.
  • Bug Fixes
    • Oversized transcript records are returned on their own instead of being skipped.
    • Unsupported content is reported clearly, without exposing private payload details.

@coderabbitai

coderabbitai Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

Explain Change →

Walkthrough

The changes project mixed Codex user content and native activity records into app-server and direct transcript paths. They retain supported native content in message metadata, add sanitized projection errors, and allow an oversized first transcript record to be returned alone.

Changes

Codex Native History

Layer / File(s) Summary
Project native user content
apps/cli/src/backends/codex/utils/readCodexUserMessageContent.ts, apps/cli/src/backends/codex/utils/codexNativeProjectionError.ts, apps/cli/src/backends/codex/utils/readCodexUserMessageContent.test.ts
The new projection helper formats supported text, skill, mention, image, and audio content. It retains original content for supported non-text parts and text annotations. Projection errors use a sanitized wire-type identifier.
Bridge native records into history
apps/cli/src/backends/codex/appServer/streamEventBridge.ts, apps/cli/src/backends/codex/appServer/session/projectCodexNativeHistoryItem.ts, apps/cli/src/backends/codex/appServer/runtime.ts, apps/cli/src/backends/codex/localControl/rolloutMapper.ts, apps/cli/src/backends/codex/rollout/projectCodexRolloutActions.ts, apps/cli/src/backends/codex/appServer/streamEventBridge.test.ts
The stream bridge recognizes subagent activity, collaboration tool calls, and dynamic tool calls. User-text updates and projected actions can carry native content, which imported messages store as codexNativeContent. Tests cover native tool inputs and results in history and live projections.
Map and page direct transcripts
apps/cli/src/backends/codex/directSessions/mapCodexRolloutLineToDirectMessages.ts, apps/cli/src/backends/codex/directSessions/pageCodexNativeTranscript.ts, apps/cli/src/backends/codex/directSessions/pageCodexTranscript.nativeHistory.test.ts, docs/codex-feature-matrix.md
Direct transcript mapping adds native content to message metadata. Paging returns an oversized first record alone. Tests cover mixed content, import behavior, and call/result rows for native tool records. The feature matrix describes these projection and paging behaviors.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant Codex as Codex user message
  participant Bridge as streamEventBridge
  participant Projector as readCodexUserMessageContent
  participant History as projectCodexNativeHistoryItem
  participant Runtime as runtime
  Codex->>Bridge: user message content
  Bridge->>Projector: content parts
  Projector-->>Bridge: text and optional nativeContent
  Bridge-->>History: provider-user-text update
  History-->>Runtime: projected user-text action
  Runtime->>Runtime: attach codexNativeContent when present
Loading

Possibly related issues

Possibly related PRs

  • happier-dev/happier#740: This PR extends the shared native-record projection path used by PR #740 to additional collaboration and dynamic-tool records.

Suggested labels: needs:maintainer

Suggested reviewers: leeroybrun

Merge Risk: Minimal · up to d36f5

The change projects native Codex subagent, collaboration and dynamic-tool history, preserves mixed user content, and returns an oversized record alone when paging. No concrete merge-blocking risk was established. The one open question is whether an in-progress tool could be shown with a premature result. Evidence suggests this is unlikely, but it is unconfirmed.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title clearly and concisely describes the main changes: preserving native mixed history and tool records for Codex.
Description check Passed The description follows the required template. It explains the changes, motivation, testing, risks, validation limits, and checklist status. The screenshots section is not needed because this is not a…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description follows the required template. It explains the changes, motivation, testing, risks, validation limits, and checklist status. The screenshots section is not needed because this is not a UI change.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

…lures

Accept Codex 0.167 audio and file-id media inputs at the shared native user
content boundary. Preserve text annotations using either supported spelling.
Report the projection phase and sanitized unsupported type without including
native content bodies or paths in errors.
Preserve client message correlation alongside retained native content when
combining the two projection changes. Validate the real native provider
catalog, paging, media adoption, encrypted importer and HTTP commit boundary,
including no partial writes when a later history page is unsupported.

Refs happier-dev#904

Co-authored-by: kairan <kairan0@qq.com>
@happier-bot
happier-bot marked this pull request as ready for review November 11, 2026 20:18
@greptile-apps

greptile-apps Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The reviewed changes appear safe to merge; no actionable defect was established.

Summary

The PR extends the shared Codex stream bridge to preserve native activity, collaboration, dynamic tool records, and mixed user content.

  • Codex activity and dynamic tool records appear as tool rows.
  • Codex user messages show mixed content and retain its original parts.
  • Native transcript paging returns oversized records one at a time.

Review used source inspection; no tests or live UI checks were run during this review.

Acknowledged limits from kairan0: the 0.3 port is not performed; end-to-end cloud import/takeover and browser confirmation remain pending; local media files are not copied and previews remain unavailable; unknown content types fail explicitly; the separate transient duplicate-rendering report is outside scope.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[Native history] --> B[Shared stream bridge]
  C[Live notifications] --> B
  B --> D[Tool calls and results]
  B --> E[User text and original content]
  D --> F[Direct paging or stored messages]
  E --> F
Loading

Reviews (1) · Last reviewed commit: "chore(codex): integrate native history f..." · Reviewed by Greptile

@happier-bot

Copy link
Copy Markdown
Contributor

Thanks @kairan0 for the investigation and fix. Keeping native history and live events on the shared Codex bridge is the right approach, and preserving mixed user content addresses a real gap behind #904.

I added support for the current native media shapes, payload-free projection diagnostics, and a test that imports a complete encrypted transcript and verifies that unsupported content on a later page causes no partial writes. I also integrated the current dev changes while preserving both client-message correlation and native content. Focused coverage and the CLI typecheck pass on d36f5e8.

The source change is recommended to merge. I marked the PR ready for review and approved its fork CI run; required CI and approving review still need to finish before merging. The 0.3 adaptation is applied locally, with focused tests passing, but its wider validation remains blocked by existing destination errors. Reporter-cloud takeover and browser confirmation have not been reproduced here.

Posted on behalf of @leeroybrun.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additional comments: 1

apps/cli/src/backends/codex/appServer/session/projectCodexNativeHistoryItem.ts-9-9: 1

9-9: Major · Data Integrity & Integration · Heavy lift

Unverified finding
Verification ran but could not confirm this finding. It is shown for review, not as a verified issue.

Do not project an active native tool as completed.

If thread/items/list returns a dynamicToolCall or collabAgentToolCall with status: 'inProgress', this line sends it as item/completed. The new bridge branch then emits a tool-result row. Direct history shows a result before completion, and a one-shot import can persist that premature result. Route nonterminal history items through the started path; emit a result only for terminal status. Codex 0.167 defines inProgress for both tool types. (github.com)

Review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between d1f2674 and d36f5e8.

Files selected for processing: 13

  • apps/cli/src/backends/codex/appServer/runtime.ts
  • apps/cli/src/backends/codex/appServer/session/projectCodexNativeHistoryItem.ts
  • apps/cli/src/backends/codex/appServer/streamEventBridge.test.ts
  • apps/cli/src/backends/codex/appServer/streamEventBridge.ts
  • apps/cli/src/backends/codex/directSessions/mapCodexRolloutLineToDirectMessages.ts
  • apps/cli/src/backends/codex/directSessions/pageCodexNativeTranscript.ts
  • apps/cli/src/backends/codex/directSessions/pageCodexTranscript.nativeHistory.test.ts
  • apps/cli/src/backends/codex/localControl/rolloutMapper.ts
  • apps/cli/src/backends/codex/rollout/projectCodexRolloutActions.ts
  • apps/cli/src/backends/codex/utils/codexNativeProjectionError.ts
  • apps/cli/src/backends/codex/utils/readCodexUserMessageContent.test.ts
  • apps/cli/src/backends/codex/utils/readCodexUserMessageContent.ts
  • docs/codex-feature-matrix.md

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

@happier-bot

Copy link
Copy Markdown
Contributor

Follow-up on d36f5e893116aec91a2301b9d4b1c67ab64773fd: the required review is now approved, and no actionable code finding remains from the final review.

I checked CodeRabbit's unverified in-progress-tool concern against Codex 0.167. The history reader rejects legacy history and admits only paginated history. Its materializer projects completed items, and migration converts legacy completion events, rather than the legacy builder's unfinished snapshots. That does not establish a reachable defect requiring a phase change here. No speculative lifecycle patch was added; the same disposition applies to the 0.3 adaptation.

Merge is currently blocked by CI run 43094858253. After fork-run approval and one native rerun, GitHub still reports startup_failure, zero jobs, and an internal-error annotation. None of the required test/build checks executed. Auto-merge is disabled for the repository, so I cannot queue the merge. No further author changes are requested on the evidence available; the next action is to recover CI and obtain successful required checks on this head, then merge. The local 0.3 adaptation remains uncommitted, with broader validation blocked as noted above.

Posted on behalf of @leeroybrun.

@leeroybrun
leeroybrun merged commit 407d782 into happier-dev:dev Nov 12, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants