Skip to content

Standardize context fragment handling#13465

Open
charley-oai wants to merge 3 commits intomainfrom
ccunningham/standardize-context-fragments
Open

Standardize context fragment handling#13465
charley-oai wants to merge 3 commits intomainfrom
ccunningham/standardize-context-fragments

Conversation

@charley-oai
Copy link
Collaborator

@charley-oai charley-oai commented Mar 4, 2026

Summary

  • Standardizes model-visible context injection around shared typed fragments and two envelopes:
    • ModelVisibleContextFragment
    • ModelVisibleContextRole (DeveloperContextRole / ContextualUserContextRole)
    • DeveloperEnvelopeBuilder / ContextualUserEnvelopeBuilder
  • Unifies turn-state context assembly for both build_initial_context and build_settings_update_items under a single ordered registry in core/src/context_manager/updates.rs (REGISTERED_TURN_STATE_FRAGMENT_BUILDERS).
  • Simplifies TurnContextDiffFragment to one entrypoint:
    • build(turn_context, reference_context_item, params)
      This removes pass-based boilerplate and keeps fragment extraction/diff/render logic together on each fragment type.
  • Removes old dual-registry scaffolding (contextual_user_update_fragments.rs, pass enums/adapter plumbing) and keeps one obvious place to register new turn-state fragments.
  • Preserves explicit text boundaries between content items (\n\n) because adjacent text content items are concatenated model-side.

Standardized Rules

  • All model-visible injected context is represented as a typed fragment.
  • There are exactly two model-visible envelopes: one developer message and one contextual-user message.
  • Contextual-user fragments use stable markers so history parsing/diffing can recognize them as contextual state.
  • Fragments derived from turn-state that need reinjection/diff behavior implement TurnContextDiffFragment.
  • New model-visible context should not hand-build raw ResponseItem::Message payloads outside envelope builders.

Additional Fixes Included

  • Split custom override semantics from system developer context via CustomDeveloperInstructions (with compatibility aliasing retained where needed).
  • Kept developerInstructions API docs aligned in app-server protocol schema/readme.
  • Fixed permission-policy edge cases:
    • prompt on unmatched with_additional_permissions requests in restricted/on-request flows
    • include request_permissions in reject-policy instructions
  • Aligned naming/docs for contextual-user fragments (AgentsMdInstructions, plugin-instructions naming, model-visible docs).

Docs

  • docs/model-visible-context.md now documents the single registry + one-method diff trait path.
  • AGENTS.md now points contributors to the same blessed registration path.
  • App-server docs/schema text was updated to match current developerInstructions behavior.

Validation

  • just fmt
  • Attempted targeted codex-core tests after rebase; current branch state still has compile errors in codex-core tests (for example missing DeveloperInstructions import in core/src/codex_tests.rs and RejectConfig field update in core/src/exec_policy.rs) that need follow-up in this PR series.

@charley-oai
Copy link
Collaborator Author

@codex review this

@chatgpt-codex-connector
Copy link
Contributor

Codex Review: Didn't find any major issues. Keep them coming!

ℹ️ 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".

@charley-oai
Copy link
Collaborator Author

@codex review this

Copy link
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: 38fdc27d8d

ℹ️ 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".

@charley-oai charley-oai force-pushed the ccunningham/standardize-context-fragments branch from 38fdc27 to 98c0e56 Compare March 5, 2026 04:19
@charley-oai
Copy link
Collaborator Author

@codex review this

Copy link
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: 5ff0745346

ℹ️ 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".

@charley-oai
Copy link
Collaborator Author

@codex review this

Copy link
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: c7d81f7dca

ℹ️ 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".

return false;
};
if role != "user" {
if role != "developer" {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

changing subagent message to dev

"expected path {expected_path_str} in instructions"
);
assert!(
instructions_text.find("## Plugins") < instructions_text.find("## Skills"),
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

after the refactor, ## Plugins is no longer in instructions_text at all.

That assertion used to check ordering within one string. Now we intentionally split into two user fragments:

  • AGENTS fragment (instructions_text)
  • plugins fragment (plugin_text)

So we replaced it with stronger checks in plugins.rs:

  • instructions_text does not contain ## Plugins
  • plugin_text does contain ## Plugins
  • plugin fragment appears after AGENTS fragment in request input order

@charley-oai charley-oai force-pushed the ccunningham/standardize-context-fragments branch from 419ee40 to 51c06c6 Compare March 7, 2026 21:48
@charley-oai
Copy link
Collaborator Author

@codex review this

Copy link
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

let user_instructions = get_user_instructions(
&config,
Some(&allowed_skills_for_implicit_invocation),
Some(loaded_plugins.capability_summaries()),
)

P0 Badge Update get_user_instructions call to new signature

get_user_instructions now accepts only (config, skills) in project_doc.rs, but this call still passes a third plugins argument. This causes a compile-time E0061 (wrong number of arguments), so codex-core cannot build from this commit.

ℹ️ 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".

@charley-oai
Copy link
Collaborator Author

@codex review this

Copy link
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: d8cdaaf67c

ℹ️ 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".

@charley-oai charley-oai force-pushed the ccunningham/standardize-context-fragments branch from d8cdaaf to c8b22a3 Compare March 8, 2026 00:15
@charley-oai charley-oai force-pushed the ccunningham/standardize-context-fragments branch from 636a666 to e58874d Compare March 9, 2026 17:37
@charley-oai
Copy link
Collaborator Author

@codex review this

Copy link
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: e58874d0ac

ℹ️ 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".

@charley-oai
Copy link
Collaborator Author

@codex review this

@charley-oai charley-oai force-pushed the ccunningham/standardize-context-fragments branch from 6dd1b70 to 18dfa72 Compare March 10, 2026 22:10
Copy link
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: 6dd1b70c77

ℹ️ 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".

Copy link
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: 18dfa72614

ℹ️ 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".

Copy link
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

if let Some(cwd) = updates.cwd.clone() {
next_configuration.cwd = cwd;
cwd_changed = true;

P1 Badge Refresh AGENTS text when applying a cwd override

SessionConfiguration::apply updates only cwd on turn overrides, but leaves project_doc_instructions unchanged. The AGENTS fragment now re-emits whenever cwd differs (AgentsMdInstructions::build, lines 546-553), so a cwd change can inject stale AGENTS content under the new directory label. This misguides the model with incorrect directory-specific instructions.

ℹ️ 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".

@charley-oai
Copy link
Collaborator Author

@codex review this

Copy link
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: 2a5415d226

ℹ️ 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".

@charley-oai
Copy link
Collaborator Author

@codex review this

Copy link
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: addc82f6ea

ℹ️ 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".

@charley-oai charley-oai force-pushed the ccunningham/standardize-context-fragments branch from 3cd6baf to 34e7077 Compare March 13, 2026 18:02
@charley-oai
Copy link
Collaborator Author

@codex review this

Copy link
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: 34e707738f

ℹ️ 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".

@charley-oai
Copy link
Collaborator Author

@codex review this

Copy link
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: 4bcfdafd01

ℹ️ 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".

@charley-oai charley-oai force-pushed the ccunningham/standardize-context-fragments branch 3 times, most recently from 9b202fb to 7b7ad57 Compare March 13, 2026 23:54
@charley-oai
Copy link
Collaborator Author

@codex review this

Copy link
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: 7b7ad57fe7

ℹ️ 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 on lines 3528 to +3531
if separate_guardian_developer_message
&& let Some(developer_instructions) = turn_context.developer_instructions.as_deref()
&& let Some(guardian_developer_message) =
crate::context_manager::updates::build_developer_update_item(vec![
developer_instructions.to_string(),
])
{
items.push(guardian_developer_message);
items.push(DeveloperTextFragment::new(developer_instructions).into_message());
Copy link
Contributor

Choose a reason for hiding this comment

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

P2 Badge Avoid duplicating guardian developer instructions

For guardian subagent sessions, turn_context.developer_instructions is emitted twice: once in the main developer envelope via build_turn_state_fragments(None, ...) (which includes CustomDeveloperInstructionsUpdateFragment), and again in this explicit guardian-only branch. Previously guardian mode kept this text separate (not duplicated). This duplicates policy text, inflates tokens, and can overweight the same instruction.

Useful? React with 👍 / 👎.

@charley-oai
Copy link
Collaborator Author

@codex review this

@charley-oai charley-oai changed the base branch from main to dev/sayan/plugin-instr-reorder March 14, 2026 03:02
Copy link
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: 6f96c5d63f

ℹ️ 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".

@charley-oai charley-oai force-pushed the ccunningham/standardize-context-fragments branch from d69af5b to 04561f0 Compare March 14, 2026 03:34
Base automatically changed from dev/sayan/plugin-instr-reorder to main March 14, 2026 03:51
@charley-oai charley-oai force-pushed the ccunningham/standardize-context-fragments branch from 04561f0 to 1568ec0 Compare March 14, 2026 03:52
@charley-oai
Copy link
Collaborator Author

@codex review this

Copy link
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: 3d15bfde03

ℹ️ 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".

charley-oai and others added 3 commits March 21, 2026 15:09
Fold Apps, Skills, and Plugins into the model-visible fragment registry as ordered developer-envelope fragments, keep the turn-state/contextual-user framework intact, and refresh prompt layout snapshots/docs around the new shape.

Co-authored-by: Codex <noreply@openai.com>
Co-authored-by: Codex <noreply@openai.com>
Co-authored-by: Codex <noreply@openai.com>
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