Skip to content

fix(codex): report native project docs truthfully - #126010

Merged
steipete merged 1 commit into
mainfrom
steipete/codex-native-project-doc-accounting
Aug 18, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/codex-native-project-doc-accounting

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Follow-up to #125966. Native Codex turns load project AGENTS.md files under one aggregate root-to-working-directory byte budget, so a later file can be partially retained. OpenClaw's context accounting instead treated every native AGENTS.md as fully injected whenever OpenClaw had not injected it itself.

That made /context, context maps, and Usage details report a precise value that the Codex app-server cannot actually provide.

Why This Change Was Made

Codex 0.147 exposes the loaded instruction source paths on thread start, resume, and fork, but it does not expose per-file retained byte counts or completeness. A listed source can still have been truncated by the aggregate budget.

This change gives native project documents an explicit native_unverified accounting state with unknown injected/truncated values. OpenClaw-injected workspace files remain precisely measured. /context explains the distinction and keeps native files out of the separate OpenClaw character-budget analysis; context maps and the Control UI omit unknown bytes rather than inventing a value.

The 128 KiB normal-thread default landed by #125966 is unchanged. Lightweight and restricted zero-document behavior is unchanged. Normal runs emit no new messages; the warning is visible only when an operator explicitly opens /context reporting or Usage details.

User Impact

Operators inspecting context diagnostics now see native AGENTS.md files as NATIVE/UNVERIFIED / unknown instead of a false full-injection count. The report explains that earlier/root project documents consume the shared byte budget and recommends reading the relevant scoped file directly when guidance appears missing.

Measured OpenClaw workspace files, memory routing, normal Codex execution, and restricted/lightweight turn behavior are unchanged.

Evidence

  • Pinned Codex rust-v0.147.0 (3ed6f04f6bf8b7c46299d1cb1ff99c74ce21a51d) inspected directly:
    • codex-rs/core/src/agents_md.rs:94-143 applies one byte budget across root-to-CWD project documents and truncates a later file to the remaining bytes.
    • codex-rs/core/src/agents_md.rs:403-412 retains source paths, not retained-byte counts.
    • codex-rs/app-server-protocol/src/protocol/v2/thread.rs:175-208,408-459,600-633 exposes instructionSources on start/resume/fork without completeness metadata.
  • Regression coverage: native AGENTS.md reports native_unverified with null retained counts; an agent-workspace AGENTS.md injected by OpenClaw remains exactly measured.
  • /context boundary coverage verifies NATIVE/UNVERIFIED, actionable aggregate-budget guidance, and no incorrect OpenClaw bootstrap-limit advice.
  • Control UI coverage verifies measured files remain sorted by size while native AGENTS.md renders as unknown and contributes no invented token count.
  • Focused exact-head Vitest: 173/173 passed.
  • Changed-file checks passed formatting, lint, typechecks, plugin boundaries, dead exports, import cycles, and Control UI i18n verification.
  • pnpm docs:check-mdx: 777 files passed.
  • git diff --check origin/main...HEAD: clean.
  • Fresh exact-head Codex autoreview: clean, no accepted/actionable findings.
  • Production LOC: +85/-25; tests: +85/-15; docs: +4/-0.

Visual proof:

Control UI Usage details showing native AGENTS.md accounting as unknown

Known proof boundary: current app-server responses do not expose the exact retained bytes, which is the reason this report is intentionally unverified rather than reconstructed from local file contents.

AI-assisted; implementation and final diff were reviewed and verified by Peter Steinberger.

@clawsweeper

clawsweeper Bot commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@steipete steipete self-assigned this Aug 18, 2026
@steipete
steipete marked this pull request as ready for review August 18, 2026 20:58
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation app: web-ui App: web-ui extensions: codex size: M maintainer Maintainer-authored PR labels Aug 18, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 18, 2026
@clawsweeper

clawsweeper Bot commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 18, 2026, 5:05 PM ET / 21:05 UTC.

ClawSweeper review

What this changes

The PR marks native Codex project documents as having unknown injected size when app-server exposes only their source paths, and updates /context, maps, and Control UI details accordingly.

Regression provenance

Possible regression — suspected (reviewed change). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

Keep open for maintainer handling: the local accounting repair is coherent, but the required direct Codex-source contract check is unavailable in this review environment.

Priority: P2
Reviewed head: 260ee5f4b66aa5539a6c152dbc9fb22739d9b638

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The local patch and focused coverage are coherent, but this review cannot independently verify the upstream Codex contract it relies on.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-authored PR is exempt from the external-contributor real-behavior-proof gate.
Patch quality 🦐 gold shrimp (3/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-authored PR is exempt from the external-contributor real-behavior-proof gate.
Evidence reviewed 6 items Current-main accounting behavior: Current main marks an uninjected native AGENTS.md as fully injected and not truncated, which is the inaccurate fallback addressed here.
Producer and consumer coverage: The branch adds a closed unknown state at the Codex report producer and consistently excludes it from computed totals while retaining an unknown UI entry.
Checked-in protocol artifact: The generated ThreadStart response defines instructionSources as an array of source paths and has no retained-byte or completeness field.
Findings None None.
Security None None.

Live Verification

Command: node scripts/run-vitest.mjs src/auto-reply/reply/commands-context-report.test.ts

Result: FAIL (partial) — step 2 expect_output reports native Codex project docs as unverified without OpenClaw limit advice: expected terminal output was not visible within 30 seconds: "reports native Codex project docs as unverified without OpenClaw limit advice"

node scripts/run-vitest.mjs src/auto-reply/reply/commands-context-report.test.ts
runner@runnervmzvulz:/tmp/clawsweeper-live-proof-126010-QKFt5J/target$ node scripts/run-vitest.mjs src/auto-reply/reply/commands-context-report.test.ts
node scripts/run-vitest.mjs src/auto-reply/reply/commands-context-report.test.ts
[test] starting test/vitest/vitest.auto-reply.config.ts

 RUN  v4.1.10 /tmp/clawsweeper-live-proof-126010-QKFt5J/target

 ✓  auto-reply  src/auto-reply/reply/commands-context-report.test.ts (20 tests) 756ms
     ✓ explains when cached prompt usage has no compactable conversation messages  318ms

 Test Files  1 passed (1)
      Tests  20 passed (20)
   Start at  21:06:42
   Duration  10.05s (transform 7.19s, setup 1.05s, import 7.87s, tests 756ms, environment 0ms)

[test] passed 1 Vitest shard in 15.90s
runner@runnervmzvulz:/tmp/clawsweeper-live-proof-126010-QKFt5J/target$ node scripts/run-vitest.mjs src/auto-reply/reply/commands-context-report.test.ts
[test] starting test/vitest/vitest.auto-reply.config.ts

 RUN  v4.1.10 /tmp/clawsweeper-live-proof-126010-QKFt5J/target

 ✓  auto-reply  src/auto-reply/reply/commands-context-report.test.ts (20 tests) 735ms
     ✓ explains when cached prompt usage has no compactable conversation messages  309ms

 Test Files  1 passed (1)
      Tests  20 passed (20)
   Start at  21:06:58
   Duration  5.02s (transform 2.30s, setup 481ms, import 3.56s, tests 735ms, environment 0ms)

[test] passed 1 Vitest shard in 10.90s
runner@runnervmzvulz:/tmp/clawsweeper-live-proof-126010-QKFt5J/target$




















Assertions:

  • FAIL expect_output: reports native Codex project docs as unverified without OpenClaw limit advice

How this fits together

Codex-backed runs assemble a session context report that feeds /context, context maps, and Control UI Usage details. OpenClaw can measure files it injects itself, while Codex-native project files arrive through app-server metadata.

flowchart LR
  A[Project AGENTS files] --> B[Codex app server]
  B --> C[Instruction source paths]
  D[OpenClaw-injected files] --> E[Session context report]
  C --> E
  E --> F[/context]
  E --> G[Context map]
  E --> H[Control UI Usage details]
Loading

Before merge

  • Resolve merge risk (P1) - The aggregate-budget and per-file-completeness behavior cannot be confirmed without the required pinned Codex source, so the central dependency claim remains unverified by this review.
  • Complete next step (P2) - The protected PR needs a maintainer-side direct Codex source check before landing.
Agent review details

Security

None.

PR surface

Source +60, Tests +70, Docs +4. Total +134 across 9 files.

View PR surface stats
Area Files Added Removed Net
Source 5 85 25 +60
Tests 3 85 15 +70
Docs 1 4 0 +4
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 9 174 40 +134

Review metrics

Metric Value Why it matters
Production vs test LOC production +85/-25; tests +85/-15; docs +4/-0 The diagnostic-state change spans the report producer and three presentation consumers; its production growth depends on the upstream contract being correct.

Stored data model

Persistent data-model change detected: serialized state: src/config/sessions/session-system-prompt-report.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Verify the pinned Codex runtime contract directly, then retain this producer-owned unknown state and its existing consumer treatment if that contract confirms per-file retained bytes are unavailable.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Verify the pinned Codex runtime contract directly, then retain this producer-owned unknown state and its existing consumer treatment if that contract confirms per-file retained bytes are unavailable.

Do we have a high-confidence way to reproduce the issue?

Yes for the local defect: current main reports an uninjected native AGENTS.md as fully injected at extensions/codex/src/app-server/attempt-context.ts:464-466; upstream-runtime confirmation is unavailable here.

Is this the best way to solve the issue?

Unclear: the closed unknown state is the correct local owner boundary, but the mandatory direct Codex source check could not be completed.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 8032e6c75e01.

Labels

Label changes:

  • add P2: This corrects operator-facing Codex context diagnostics without changing ordinary run execution.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🌊 off-meta tidepool and patch quality is 🦐 gold shrimp.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This maintainer-authored PR is exempt from the external-contributor real-behavior-proof gate.

Label justifications:

  • P2: This corrects operator-facing Codex context diagnostics without changing ordinary run execution.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🌊 off-meta tidepool and patch quality is 🦐 gold shrimp.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This maintainer-authored PR is exempt from the external-contributor real-behavior-proof gate.

Evidence

What I checked:

Likely related people:

  • steipete: Authored the present fallback and the proposed Codex context-accounting repair. (role: recent area contributor; confidence: high; commits: d204ebe6a4df, 260ee5f4b66a; files: extensions/codex/src/app-server/attempt-context.ts, src/config/sessions/session-system-prompt-report.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Verify the pinned Codex source’s aggregate document-budget and thread-response metadata behavior before landing.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@steipete

Copy link
Copy Markdown
Contributor Author

Land-ready verification for exact head 260ee5f4b66aa5539a6c152dbc9fb22739d9b638:

  • Applied ClawSweeper's rank-up move with direct inspection of pinned Codex rust-v0.147.0 (3ed6f04f6bf8b7c46299d1cb1ff99c74ce21a51d):
    • codex-rs/core/src/agents_md.rs:94-143 owns the aggregate root-to-CWD byte budget and truncates a later project document to the remaining bytes.
    • codex-rs/core/src/agents_md.rs:403-412 retains contributing source paths only.
    • codex-rs/app-server-protocol/src/protocol/v2/thread.rs:175-208,408-459,600-633 exposes instructionSources for start/resume/fork without retained-byte or completeness metadata.
  • ClawSweeper reported no code or security findings. Its expect_output live-proof assertion looked for the individual test title, which Vitest's successful summary did not print; the captured command itself passed all 20/20 tests twice.
  • Focused exact-head local proof: 173/173 tests passed across Codex attempt context, /context reporting, and Control UI Usage details.
  • Changed-file checks passed formatting, lint, typechecks, plugin boundaries, dead exports, import cycles, and Control UI i18n verification.
  • pnpm docs:check-mdx: 777 files passed.
  • git diff --check origin/main...HEAD: clean.
  • Fresh exact-head Codex autoreview: clean, no accepted/actionable findings.
  • Exact-head CI: https://github.com/openclaw/openclaw/actions/runs/32185246158 — green.
  • Mocked real-browser proof was inspected: measured files retain estimates while native AGENTS.md renders as unknown: https://github.com/user-attachments/assets/5cb859fd-a221-4bf0-ad73-b677344d9b10
  • Production LOC: +85/-25; tests: +85/-15; docs: +4/-0. The production growth is the closed unknown-accounting state plus the three operator-facing consumers that must stop inventing native byte counts.

Known proof boundary: app-server does not expose exact retained bytes, so the repaired output intentionally remains native_unverified; normal runs produce no additional messages, and #125966's 128 KiB default plus restricted/lightweight zero-doc behavior are unchanged.

@steipete
steipete merged commit 491dc7f into main Aug 18, 2026
304 checks passed
@steipete
steipete deleted the steipete/codex-native-project-doc-accounting branch August 18, 2026 21:43
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app: web-ui App: web-ui docs Improvements or additions to documentation extensions: codex maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant