Skip to content

core: support extension-owned turn items - #31283

Merged
owenlin0 merged 6 commits into
mainfrom
owen/dynamic_image_gen_item
Jul 8, 2026
Merged

core: support extension-owned turn items#31283
owenlin0 merged 6 commits into
mainfrom
owen/dynamic_image_gen_item

Conversation

@owenlin0

@owenlin0 owenlin0 commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Description

This PR adds a codex-extension-items crate for extension-owned TurnItem schemas, and updates standalone image generation to start using it via TurnItem::Extension.

This gives us a way to prevent Core from having to be aware of all extension items. App-server still exposes the existing public ThreadItem::ImageGeneration shape, now by wrapping the same shared image_generation::ImageGenerationItem type.

The new codex-extension-items crate is necessary because the image gen extension item is used by:

  • codex-image-generation-extension, which produces it.
  • codex-tools / core, which carry it generically.
  • codex-protocol, which serializes it into lifecycle events and rollouts.
  • app-server protocol, which wraps it in public ThreadItem::ImageGeneration
extension implementation
        ↓
codex-extension-items
        ↓
protocol / tools / app-server

We keep the hosted Responses API image generation as TurnItem::ImageGeneration because core still owns its persistence and legacy fanout.

Before

Standalone image generation is implemented as an extension, but its item representation previously lived in the core protocol. This sets the precedent that core is aware of all extension items, which would be good to avoid.

image-gen extension
→ constructs codex_protocol::ImageGenerationItem
→ emits ExtensionTurnItem::ImageGeneration
→ core matches ImageGeneration specially
→ protocol stores TurnItem::ImageGeneration

After

image-gen extension
→ constructs extension-owned ImageGenerationItem
→ emits generic ExtensionItem
→ core transports/persists it generically
→ app-server wraps ImageGenerationItem as ThreadItem::ImageGeneration

Future extension items can have typed app-server APIs without adding a new TurnItem variant, ExtensionTurnItem variant, or core emitter match arm.

What changed

  • Added codex-extension-items with the closed ExtensionItem enum and shared image_generation::ImageGenerationItem schema.
  • Added generic TurnItem::Extension(ExtensionItem) and ExtensionTurnItem::Extension { item, legacy_events } paths.
  • Updated standalone image generation to emit a typed extension item and provide its existing legacy ImageGenerationBegin / ImageGenerationEnd events explicitly.
  • Kept canonical lifecycle ordering: core emits ItemStarted / ItemCompleted before extension-provided legacy events.

Follow-up

Standalone web search still uses its typed special-case path. Migrating it later would let ExtensionTurnItem collapse into a single extension-item struct.

@owenlin0
owenlin0 force-pushed the owen/dynamic_image_gen_item branch from b6e8ca7 to f15b9a9 Compare July 6, 2026 20:21
@owenlin0 owenlin0 changed the title wip core agnostic turn items core: support typed extension-owned turn items Jul 6, 2026
@owenlin0 owenlin0 changed the title core: support typed extension-owned turn items core: support extension-owned turn items Jul 6, 2026
@owenlin0
owenlin0 marked this pull request as ready for review July 6, 2026 20:55
@owenlin0
owenlin0 requested a review from a team as a code owner July 6, 2026 20:55
owenlin0 added a commit that referenced this pull request Jul 6, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3f8b56118f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread codex-rs/Cargo.toml
(item, Vec::new())
}
};
session.emit_turn_item_completed(turn.as_ref(), item).await;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Badge Persist completed extension items for replay

When an extension emits a canonical item with no legacy fallback (the API allows legacy_events to be empty), this ItemCompleted(TurnItem::Extension) is delivered live but is dropped from rollout storage because rollout/src/policy.rs only keeps completed Plan/Sleep items. After resuming from that rollout, the extension-owned item is gone, so the new canonical extension item path is not durable unless every extension also invents a legacy event; include TurnItem::Extension(_) in the persisted completion policy.

AGENTS.md reference: AGENTS.md:L102-L110

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

no, we are purposely not doing this in this PR and deferring it for #30188 - we'll be switching to ItemCompleted(<turn_item>) for paginated threads generally then

@owenlin0
owenlin0 requested a review from pakrym-oai July 6, 2026 21:17
@owenlin0 owenlin0 changed the title core: support extension-owned turn items core: support typed extension-owned turn items Jul 6, 2026
@owenlin0 owenlin0 changed the title core: support typed extension-owned turn items core: support extension-owned turn items Jul 6, 2026
owenlin0 added a commit that referenced this pull request Jul 6, 2026
@owenlin0
owenlin0 force-pushed the owen/dynamic_image_gen_item branch from 6466cfa to 022f3c0 Compare July 6, 2026 23:10
num_last_images_to_include: Option<usize>,
}

fn legacy_end_event(item: &ImageGenerationItem) -> EventMsg {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

should this persist TurnItem::Extension and drop legacy events?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

will be doing as part of this PR! #30188

@owenlin0
owenlin0 force-pushed the owen/dynamic_image_gen_item branch from 022f3c0 to ca76515 Compare July 8, 2026 03:40
@owenlin0
owenlin0 enabled auto-merge (squash) July 8, 2026 03:49
@owenlin0
owenlin0 merged commit f1affba into main Jul 8, 2026
75 of 77 checks passed
@owenlin0
owenlin0 deleted the owen/dynamic_image_gen_item branch July 8, 2026 03:55
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 8, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants