Skip to content

Preserve applicable AGENTS instructions in Background Review context #787

Description

@shiny-code-bot

Finish Line

Background Review receives every applicable repository instruction needed to judge its target, without silently dropping later AGENTS.md rules because a single world-state section exceeded its byte budget.

Current Status

State: not ready to merge at PR #788 head 0fb2a4635dbffb5b73c558c581b2d7c90c13051f after terminal installed lifecycle reconstruction, green CI/inspection, and independent final review on August 24, 2026.

Verified successful evidence:

  • The task branch is clean and synchronized with origin at the exact PR head above. The prior issue update incorrectly recorded a different full SHA with the same prefix; this status corrects it.
  • Final diff against origin/main: 706 additions and 92 deletions, 798 changed lines across seven files.
  • just test -p codex-core world_state: 104 passed, 0 failed.
  • just test -p codex-core agents_md: 66 passed, 0 failed.
  • just fix -p codex-core, just fmt, and git diff --check: passed in the required order.
  • Required GitHub CI, Rust workspace compile, repository checks, SDK checks, and the macOS ARM64 Codex Lab app build are green on the exact head. The PR is mergeable with a clean merge state.
  • Fresh externally orchestrated IntelliJ changed-files closeout is GREEN with zero actionable findings and successful cleanup.
  • Change-size review found the current 798-line feature slice coherent and reviewable as one stage. However, required fixes below cannot simply be added without reconsidering the 800-line ceiling.

Installed lifecycle outcomes:

  • Automatic Validation selected the package-scoped codex-core Cargo provider and timed out after 30.016 seconds with exit code 124. It emitted dependency artifacts but no compiler diagnostic. This is Enable automatic functional validation in installed Codex Lab defaults #785 evidence, not a compile failure.
  • Late Background Review completed in thread 01a03195-b55a-7160-a42f-e6999ad9c964 at 02:27:54 UTC. It reported one finding, marked the patch incorrect, and assigned confidence 0.95.

Blocking implementation and compatibility findings:

  1. Malformed continuation envelopes: parts 2–4 open <INSTRUCTIONS> in the body but close with </INSTRUCTIONS_PART_N>. Every multi-shard document therefore emits structurally mismatched standalone instruction tags. Use matching part-specific opening/closing tags or the common matching close tag. codex-rs/core/src/context/world_state/agents_md.rs:270
  2. Continuation messages are not classified as contextual user content: central contextual-message/event mapping recognizes only the legacy UserInstructions wrapper. Parts 2–4 can surface as ordinary user messages and perturb turn-boundary, rollback, trimming, and visible transcript behavior. codex-rs/core/src/context/contextual_user_message.rs:20
  3. Frozen rollout-migration compatibility is missing: the thread-store rollback adapter also recognizes only the legacy wrapper, so continuation shards can be counted as real user-turn boundaries during retained-history migration. codex-rs/thread-store/src/local/rollout_migration/rollback.rs:127
  4. Deletion can leave stale continuations: continuation sections are registered only when currently present. If retained history loses/mangles shard 1 but keeps shards 2–4, deleting AGENTS.md can classify shard 1 as absent, emit no removal notice, and never visit the stale continuation sections. codex-rs/core/src/context/world_state/agents_md.rs:49
  5. Retained matching does not prove shard content: matches_retained_fragment accepts any same-marker user message without validating persisted content/document identity. Corrupt or stale shard text can suppress rehydration. codex-rs/core/src/context/world_state/agents_md.rs:172
  6. Reachable UTF-8/newline split panic: after a newline-preferred early split, a later shard can compute minimum_split > maximum_split when a four-byte character straddles the boundary, producing an invalid byte slice. The current multibyte test does not exercise aggregate truncation or newline preference. codex-rs/core/src/context/world_state/agents_md.rs:121

Blocking or material test findings:

  1. The legacy migration unit test renders only shard 1; its assertions for shards 2–4 inspect raw payload text and cannot detect duplicate replacement notices. codex-rs/core/src/context/world_state/agents_md_tests.rs:196
  2. Cold-resume migration uses only a 4-KiB single-shard replacement, so unsharded-to-multi-shard migration is not tested end to end. The prior AGENTS deletion integration scenario was also removed; both replacement and removal require suite coverage. codex-rs/core/tests/suite/agents_md.rs:999
  3. The old insta snapshot remains tracked after the snapshot test was removed and now asserts obsolete notice wording. Restore/update the snapshot test or remove the orphan through the intended snapshot workflow. codex-rs/core/src/context/world_state/snapshots/codex_core__context__world_state__agents_md__tests__snapshots.snap:1
  4. Atomic document-change coverage does not assert per-shard rendered bounds or absence of world-state truncation on the replacement path, where shard 1 sits exactly at the 8-KiB cap. codex-rs/core/src/context/world_state/agents_md_tests.rs:132
  5. The 128-section starvation test gives every fragment an 8-KiB body, making the AGENTS cap non-discriminating; it passes even if the special cap is removed. codex-rs/core/src/context/world_state/world_state_tests.rs:208
  6. The generic-cap pressure assertion never reaches its upper bound and also passes without the AGENTS cap, so it does not prove the behavior named by the test. codex-rs/core/src/context/world_state/world_state_tests.rs:281
  7. No integration test changes a multi-shard AGENTS document between turns and proves four separate incremental response items, one replacement notice, and no truncation. codex-rs/core/tests/suite/agents_md.rs:397
  8. Initial-context ordering changed by moving standalone AGENTS shards after the merged contextual-user message, but no test pins their ordering relative to environment context. codex-rs/core/src/session/mod.rs:3697

Next action:

  • Do not merge the current head.
  • Correct the malformed envelopes, central and frozen contextual classifiers, stale-removal/retained identity behavior, and the UTF-8 splitter panic before another push.
  • Repair the vacuous/missing integration tests and snapshot coverage. Since the branch is already 798 changed lines, consolidate or replace existing tests/implementation rather than layering additions. If the complete safe fix cannot remain below 800 changed lines, stop and define the smallest coherent staged review plan before committing.
  • After amendment: focused tests, fix/format, fresh JetBrains inspection, installed lifecycle dogfood, independent context/testing/breaking review, and exact-head CI.

Preserved exclusions: no #784 or #785 implementation, TUI changes, Cargo Validation changes, global-loader redesign, CI harness work, or unrelated convergence.

Last verified: August 24, 2026.

Acceptance Criteria

  • Every file in a review target is checked against all applicable root and nested AGENTS.md instructions.
  • No individual contextual fragment exceeds the repository's hard model-context cap.
  • Truncation is not silent: review lifecycle evidence identifies omitted instruction scopes and prevents a clean verdict when required instructions are unavailable.
  • Root and nested instruction precedence remains deterministic.
  • Integration coverage proves a review target governed by a rule after the former 9,216-byte boundary still observes that rule.
  • Installed-artifact dogfood produces a Background Review verdict without instruction-context truncation or with an explicit non-clean outcome.

Relationships

Metadata

Metadata

Assignees

No one assigned

    Labels

    planDurable planning issueplan:activePlan is actionable now

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions