Skip to content

Add experimental turn additional context#24154

Merged
pakrym-oai merged 20 commits into
mainfrom
pakrym/additional-context
May 26, 2026
Merged

Add experimental turn additional context#24154
pakrym-oai merged 20 commits into
mainfrom
pakrym/additional-context

Conversation

@pakrym-oai

@pakrym-oai pakrym-oai commented May 22, 2026

Copy link
Copy Markdown
Collaborator

Summary

Adds experimental additionalContext support to turn/start and turn/steer so clients can provide ephemeral external context, such as browser or automation state, without turning that plumbing into a visible user prompt or triggering user-prompt lifecycle behavior.

API Shape

The parameter shape is:

additionalContext?: Record<string, {
  value: string
  kind: "untrusted" | "application"
}> | null

Example:

{
  "additionalContext": {
    "browser_info": {
      "value": "Active tab is CI failures.",
      "kind": "untrusted"
    },
    "automation_info": {
      "value": "CI rerun is in progress.",
      "kind": "application"
    }
  }
}

The keys are opaque and caller-defined.

Context Injection

When provided, accepted entries are inserted into model context as hidden contextual message items, not as visible thread user-message items.

kind: "untrusted" entries are inserted with role user:

<external_${key}>${value}</external_${key}>

kind: "application" entries are inserted with role developer:

<${key}>${value}</${key}>

Values are not escaped. Each value is truncated to 1k approximate tokens before wrapping.

For turn/start, accepted additional context is inserted before normal user input. For turn/steer, additional context is merged only when the steer includes non-empty user input; context-only steers still reject as empty input.

Dedupe Strategy

AdditionalContextStore lives on session state and stores the latest complete additional-context map.

Each turn/start or non-empty turn/steer treats its additionalContext as the current complete set of values. Entries are injected only when the key is new or the exact entry for that key changed, including value or kind. After merging, the store is replaced with the provided map, so omitted keys are removed from the retained set and can be injected again later if reintroduced.

Omitting additionalContext, passing null, or passing an empty object resets the store to empty and injects nothing.

What Changed

  • Threads experimental v2 additionalContext through app-server into core turn start and steer handling.
  • Adds separate contextual fragment types for untrusted user-role context and application developer-role context.
  • Uses pending response input items so additional context can be combined with normal user input without treating it as prompt text.
  • Adds integration coverage for start/steer flow, role routing, dedupe/reset behavior, deletion/re-add behavior, hook-blocked input behavior, empty context-only steer rejection, external-fragment marker matching, and truncation.

@pakrym-oai pakrym-oai requested a review from a team as a code owner May 22, 2026 22:09

@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: 5bc43bd551

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread codex-rs/core/src/context/fragments.rs
Comment thread codex-rs/core/src/session/handlers.rs
Comment thread codex-rs/app-server/src/request_processors/turn_processor.rs
Base automatically changed from pakrym/session-task-turn-input to main May 22, 2026 22:21
Comment thread codex-rs/protocol/src/protocol.rs Outdated
@pakrym-oai pakrym-oai merged commit 768848a into main May 26, 2026
31 checks passed
@pakrym-oai pakrym-oai deleted the pakrym/additional-context branch May 26, 2026 20:02
@github-actions github-actions Bot locked and limited conversation to collaborators May 26, 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