/status keeps showing Agents.md: <none> after /init creates AGENTS.md
Summary
/status keeps reporting Agents.md: <none> for the rest of a session after /init creates an AGENTS.md, on any platform.
Reproduction
- Start a session in a directory with no
AGENTS.md. - Run
/initand let it writeAGENTS.md. - 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.
2 Comments
Verified on
main(1f41cc5d92): the early return is unchanged —refreshskips 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/initcan 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.mdmid-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 theis_some()check as full filesystem freshness./statuscould also honestly label it ("as of session start / last discovery").Still true on current main.
AgentsMdManager::refreshincodex-rs/core/src/agents_md_manager.rsreturns early when environment selections are unchanged. CreatingAGENTS.mdvia/initdoes not change that selection, so the cache keepsAgents.md: <none>for the rest of the session.