Skip to content

Add experimental turn additional context#24154

Open
pakrym-oai wants to merge 18 commits into
mainfrom
pakrym/additional-context
Open

Add experimental turn additional context#24154
pakrym-oai wants to merge 18 commits into
mainfrom
pakrym/additional-context

Conversation

@pakrym-oai
Copy link
Copy Markdown
Collaborator

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

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 shape for the parameter is:

additionalContext?: Record<string, {
  value: string
  isUntrusted?: boolean
}> | null

Example:

{
  "additionalContext": {
    "browser_info": {
      "value": "Active tab is CI failures.",
      "isUntrusted": true
    },
    "automation_info": {
      "value": "CI rerun is in progress."
    }
  }
}

The keys are opaque and caller-defined. isUntrusted defaults to false.

Context Injection

When the parameter is provided, each accepted entry is inserted into model context as a hidden contextual message item, not as a visible thread user-message item.

Untrusted entries are inserted with role user:

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

Trusted 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 the 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 isUntrusted. 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 trusted developer-role context.
  • Switches task input plumbing to carry TurnInput directly 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, and truncation.

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

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

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
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.

2 participants