/status keeps showing Agents.md: <none> after /init creates AGENTS.md

Open 💬 2 comments Opened Aug 9, 2026 by DioNanos

Summary

/status keeps reporting Agents.md: <none> for the rest of a session after /init creates an AGENTS.md, on any platform.

Reproduction

  1. Start a session in a directory with no AGENTS.md.
  2. Run /init and let it write AGENTS.md.
  3. Run /status.

Expected: the new file is discovered. Actual: Agents.md: <none>, and it stays that way until a new session is started.

Reported downstream with a full codex doctor --json on 0.146.0 (DioNanos/codex-termux#14) and still present on current main.

Root cause

AgentsMdManager::refresh in codex-rs/core/src/agents_md_manager.rs returns early whenever the environment selection is unchanged:

let selections = environments.to_selections();
if self.cache.lock().await.selections.as_ref() == Some(&selections) {
    return;
}

The environment selection is not the only input to discovery — the files on disk are one too. /init changes the filesystem without changing the environment, so the early return fires and discovery never re-runs.

This looks like a gap left by #29977, which made discovery react to environment changes; the other input it can react to is not covered.

Outline of a fix

Require that discovery has actually found something before skipping the work:

if cache.selections.as_ref() == Some(&selections) && cache.loaded.is_some() {
    return;
}

Re-running while nothing has been located costs a bounded set of path probes, and stops costing anything as soon as instructions exist — once an AGENTS.md is in place the early return fires on every refresh as before.

Evidence

This change has been running in a downstream Android build since 0.147.2 with no regressions observed. Verified against current main with cargo check -p codex-core and cargo fmt --all --check.

Not opening a PR, per the invitation-only policy. Happy to prepare one if the team wants it, and equally happy for someone on the team to take the one-line version directly.

View original on GitHub ↗

2 Comments

jdcodes1 · 9 days ago

Verified on main (1f41cc5d92): the early return is unchanged — refresh skips purely on environment-selection equality (https://github.com/openai/codex/blob/1f41cc5d92/codex-rs/core/src/agents_md_manager.rs#L33-L36), so a filesystem-only change like /init can never invalidate the cache, exactly as analyzed. The proposed && cache.loaded.is_some() guard is the right minimal shape: bounded re-probing only while discovery has found nothing, returning to today's single-probe behavior the moment instructions exist.

One asymmetry worth acknowledging in the fix commit (fine to leave unfixed): the negative case gets repaired, but a stale positive — editing or deleting an existing AGENTS.md mid-session — still serves the cached copy until a new session or environment change. That's consistent with instructions being loaded per-turn-prefix anyway, but a one-line comment on the cache stating "positive results are session-sticky by design" would stop the next person from reading the is_some() check as full filesystem freshness. /status could also honestly label it ("as of session start / last discovery").

daichunghy · 5 days ago

Still true on current main.

AgentsMdManager::refresh in codex-rs/core/src/agents_md_manager.rs returns early when environment selections are unchanged. Creating AGENTS.md via /init does not change that selection, so the cache keeps Agents.md: <none> for the rest of the session.