Skip to content

core: make AGENTS.md react to environment changes - #29977

Closed
sayan-oai wants to merge 2 commits into
mainfrom
codex/reactive-agents-md-world-state
Closed

core: make AGENTS.md react to environment changes#29977
sayan-oai wants to merge 2 commits into
mainfrom
codex/reactive-agents-md-world-state

Conversation

@sayan-oai

@sayan-oai sayan-oai commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Why

With deferred executors, a turn can begin before a remote environment attaches. AGENTS.md discovery previously ran only during session setup, so instructions from a later environment never reached the model or the session's instruction sources.

WorldState persistence has now landed, so this can use the durable model-visible baseline directly instead of carrying the temporary resume/fork compatibility path from #29810.

What

  • Add an AgentsMdManager in SessionServices to own host instructions, loaded state, and refresh caching.
  • When DeferredExecutor is enabled, refresh AGENTS.md when attached environment selections change and freeze the result in that request's StepContext.
  • Represent AGENTS.md as a persisted WorldState section for every session, with bounded initial, replacement, and removal updates.
  • Remove duplicate AGENTS.md state and rendering from SessionConfiguration and TurnContext.
  • Build initial context, per-request updates, and compaction context from the same step-scoped value.
  • On resume and fork, compare current instructions with the restored WorldState baseline and inject a replacement exactly once when they differ.

Supersedes #29810 and builds on #29833, #29835, and #29837.

Tests

  • Covers a remote environment becoming ready mid-turn, with AGENTS.md appearing on the next request exactly once and updating canonical instruction sources.
  • Covers full, unchanged, replaced, and removed AGENTS.md WorldState rendering.
  • Covers changed instructions across cold resume and fork without duplicate reinjection.
  • Covers remote-v2 compaction retaining creation-time instructions in the live session and cold resume appending one replacement when the source changed.
  • Ran focused codex-core AGENTS.md, WorldState, and context-update test suites.

@sayan-oai
sayan-oai requested a review from a team as a code owner June 25, 2026 04:05

@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: 3bfe2a3af2

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

directory: instructions.directory.clone(),
text: format!("{REPLACEMENT_NOTICE}\n\n{}", instructions.text),
},
(Some(instructions), None) => instructions.clone(),

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.

P1 Badge Seed AGENTS.md baselines when resuming legacy rollouts

When resuming a rollout written before this change, the prompt history already contains the old AGENTS.md contextual user message, but the persisted WorldState has no agents_md section. On the first resumed turn previous is therefore None for this section, so this branch emits another full AGENTS.md item instead of treating the legacy history as the baseline, duplicating instructions for existing saved threads. Please migrate/seed the agents_md snapshot during reconstruction or suppress this first diff for legacy rollouts.

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.

coming in stacked pr

Comment thread codex-rs/core/src/context/world_state/agents_md.rs
Comment thread codex-rs/core/src/session/mod.rs
Comment thread codex-rs/core/src/agents_md_manager.rs
@sayan-oai

Copy link
Copy Markdown
Contributor Author

Moved this exact implementation onto the already-reviewed #29810 branch. Continuing there; #29997 is now stacked on #29810.

@sayan-oai sayan-oai closed this Jun 25, 2026
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.

1 participant