Skip to content

fix(agents): identify changed facts behind prompt-cache drops - #186095

Merged
steipete merged 3 commits into
mainfrom
steipete/fix-prompt-cache-drop-attribution-20261027
Oct 27, 2026
Merged

steipete merged 3 commits into
mainfrom
steipete/fix-prompt-cache-drop-attribution-20261027

Conversation

@steipete

@steipete steipete commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Prompt-cache drop warnings identify a changed suffix section or tool description but do not explain which fact changed. Operators cannot distinguish a model-field change, tool-list reorder, routing policy change, or computer capability clause from unexplained churn.

User Impact

Warnings now include bounded, content-free fact names such as Runtime.model, Session routing.hidden delegation, Tooling.tool list order, and computer.description.window observation. Arbitrary context uses line positions. Unknown headings and custom tool names use positions rather than printing their text. Prompts, tool definitions, provider payloads, and cache behavior are unchanged.

Why This Change Was Made

Fact parsing and hashing happen only after a reportable cache drop. Exact before/after attribution therefore needs a before-image: private tracker data retains at most 32,768 UTF-16 code units of suffix text and 16,384 of tool descriptions per request snapshot. Oversized sources explicitly report unavailable fact detail. Suffixes are detached from large stable prefixes and reused when unchanged. Before-images follow the existing bounded snapshot/session lifecycle and never appear in exported trace snapshots.

The existing section/tool attribution code moves into the fact owner; there is no second prompt builder or provider path. Runtime production code grows by 263 net lines because this adds requested diagnostic functionality. The standalone owner benchmark adds 115 lines. This is an observability improvement, not a performance speedup.

Evidence

Six new fact-attribution regressions failed on the unchanged base for the intended missing detail. The final owner file passes all 33 tests, including content exclusion, deferred fact hashing, large-prefix/suffix bounds, computer clauses, and snapshot reuse. Focused observation/history/request-observer and prompt-prefix tests passed 114 tests before the tool-capture simplification; the final owner rerun covers that simplification. Export collision guard and both import/source closure files passed (32 tests). Scoped oxfmt, typed lint, and git diff --check pass. When rebasing exposed an inherited test-line ceiling overage, consolidating this owner file preserved all 33 cases and made this PR net -2 test lines. The existing non-growth ratchet passes; the ceiling was not edited. Owner file: 11.96 seconds total including transformation, under one second of test execution.

Review: independent subagent review (autoreview route unavailable), scoped-clean through P2. Codex autoreview refused before inference because the selected provider did not match operator configuration; no configuration was changed. The fresh-context reviewer inspected the final production diff, direct caller, warning consumer, renderer grammar, docs, and benchmark. No accepted findings remain. The subsequent test-only consolidation received an additional independent review.

Synthetic owner benchmark: 64 rotating active observations, 40 tools, a roughly 100 KB stable prefix, and a multi-section suffix. Five counterbalanced base/candidate pairs, 5,000 requests per arm per pair (25,000 per side per mode). CPU is untraced; allocation uses separate inspector sampling passes including collected objects. Acceptance was unchanged prompt bytes, drop-only fact hashing, bounded content-free output, and explicit attribution cost. Mean values:

Workload CPU µs/request, base → candidate Sampled bytes/request, base → candidate
Stable 105.61 → 108.13 (+2.39%) 105,712 → 109,507 (+3.59%)
Changed, no drop 116.53 → 119.43 (+2.49%) 109,356 → 116,846 (+6.85%)
Alternating drops 110.88 → 122.84 (+10.79%) 109,422 → 121,412 (+10.96%)

The drop workload includes alternating cache-hit and cache-drop requests. The additional work buys fact attribution; normal-path overhead is approximately 2.5 µs/request. Host one-minute load ranged from 28.1 to 33.8. Usage and baseline-owner selection are documented in scripts/perf/prompt-cache-facts-measure.ts.

No live server was accessed. No Gateway stress/load result is claimed: this attribution-only change used the requested focused fast path, so Gateway CPU, GC, event-loop/RPC percentiles, and RSS/heap impact remain unmeasured. PR CI is the broad validation gate.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-27T16:06:34.857936Z 83eb1ea New commits
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation scripts Repository scripts agents Agent runtime and tooling size: L labels Oct 27, 2026
@steipete
steipete force-pushed the steipete/fix-prompt-cache-drop-attribution-20261027 branch from 5f49445 to 3a7fb06 Compare October 27, 2026 15:52
Name bounded runtime, routing, tooling, context-line, and computer-description changes only when reporting a cache drop. Keep private before-images bounded and exclude prompt values and arbitrary headings/tool names from warning details. Prompt and provider payload bytes remain unchanged.
@steipete
steipete force-pushed the steipete/fix-prompt-cache-drop-attribution-20261027 branch from 3a7fb06 to 83eb1ea Compare October 27, 2026 16:04
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 27, 2026
@clawsweeper

clawsweeper Bot commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge.

What this changes

This PR identifies changed prompt and tool-description facts in cache-drop diagnostics without printing their contents.

Example: The Runtime suffix changes from model=fixture-a to model=fixture-b and cache reads fall from 8,000 to 2,000 tokens.

  • Before: The warning identifies only the Runtime section.
  • After: The warning also reports Runtime.model changed without printing either model value.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Useful, focused attribution with owner-level evidence, but an existing integration assertion remains incompatible with the changed formatter.
Proof confidence 🦐 gold shrimp (3/6) This maintainer-authored diagnostic PR is outside the ordinary contributor proof gate; supplied evidence exercises the observation owner with synthetic inputs and explicitly claims no live Gateway verification.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Product

Kind: Feature · Worth it: Yes · Fix scope: Complete
User problem: Operators can identify a changed prompt section but cannot tell which runtime field, routing clause, or tool-description fact moved.
Reason: The maintainer-authored direction adds useful bounded diagnostics through the established observation path without a new setting or provider behavior.

Merge readiness

⛔ Needs changes before merge - 1 item remains

Keep this PR open: it adds useful maintainer-directed diagnostics absent from current main, but leaves an existing integration-test expectation incompatible with the new output.

Priority: P2
Reviewed head: 83eb1eaca6a70bb8361198847fb14c067b692ff6

Before merge

  • Update the request-submit test for positional tool diagnostics (P2) - The existing integration test at src/agents/embedded-agent-runner/run/attempt-prompt-submit.cache-observation.test.ts:62 still expects 1 -> 1 tools; description: "read". Its third request changes the read description and reaches this formatter through the real request observer, which now returns 1 -> 1 tools; description: tool[1]. Cache reads increase from zero in that case, so there is no fact suffix to account for. The assertion at line 82 consequently mismatches on this head. Update the expected positional label while retaining the managed-cache and compaction coverage.

Findings

  • [P2] Update the request-submit test for positional tool diagnostics — src/agents/embedded-agent-runner/prompt-cache-facts.ts:274-277

Tests

  • Missing end-to-end proof: The supplied owner tests and synthetic benchmark do not demonstrate the new warning through a running Gateway; base-red/head-green results are author-reported.
Agent review details

How this fits together

The embedded runner observes model-request prompts and tools, pairs snapshots with provider usage, and sends cache-drop explanations to logs and cache traces.

flowchart LR
  A[Model request] --> B[Request observer]
  B --> C[Bounded diagnostic tracker]
  D[Provider usage] --> C
  C --> E[Fact comparison on drop]
  E --> F[Warnings and cache traces]
Loading

Technical review

Best possible solution:

Retain the bounded attribution implementation and update the existing request-submit integration assertion to the positional diagnostic contract.

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

Source confirms current main stops at section/tool attribution and deterministically shows the stale integration assertion; no tests or product commands were executed during this read-only review.

Is this the best way to solve the issue?

The existing tracker supplies the appropriate lifetime and comparison baseline, while one fact owner replaces the previous attribution helpers without changing provider requests.

Full review comments:

  • [P2] Update the request-submit test for positional tool diagnostics — src/agents/embedded-agent-runner/prompt-cache-facts.ts:274-277
    The existing integration test at src/agents/embedded-agent-runner/run/attempt-prompt-submit.cache-observation.test.ts:62 still expects 1 -> 1 tools; description: "read". Its third request changes the read description and reaches this formatter through the real request observer, which now returns 1 -> 1 tools; description: tool[1]. Cache reads increase from zero in that case, so there is no fact suffix to account for. The assertion at line 82 consequently mismatches on this head. Update the expected positional label while retaining the managed-cache and compaction coverage.
    Confidence: 0.99

Overall correctness: patch is incorrect
Overall confidence: 0.96

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 65f07e3fbf1e.

Provenance checked

  • Section labels and retained diagnostic source changes intended behavior with a stated reason (53fa49b: Name previously anonymous changed sections while retaining only hashes; this PR explicitly documents positional labels and bounded private before-images for deferred fact comparison.)
  • Tool-definition attribution keeps the original intent (1d03e5d: Distinguish tool membership, description, and schema changes during prompt-cache diagnosis; the same comparisons remain with positional labels and additional description facts.)
  • Request baselines and history reuse keeps the original intent (3a3246e: Reuse unchanged observation histories without weakening per-request history checks; this PR preserves that machinery and enriches only reported drops.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

Acceptance criteria:

  • pnpm test src/agents/embedded-agent-runner/run/attempt-prompt-submit.cache-observation.test.ts src/agents/embedded-agent-runner/prompt-cache-observability.test.ts src/agents/embedded-agent-runner/prompt-cache-request-observer.test.ts --maxWorkers=1
  • pnpm exec oxfmt --check src/agents/embedded-agent-runner/run/attempt-prompt-submit.cache-observation.test.ts
  • node scripts/run-oxlint.mjs --tsconfig tsconfig.json src/agents/embedded-agent-runner/run/attempt-prompt-submit.cache-observation.test.ts
  • git diff --check

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 2b78763 adds src/agents/embedded-agent-runner/prompt-cache-observability.ts:273 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 2b787637a639; files: src/agents/embedded-agent-runner/prompt-cache-observability.ts)
  • Vincent Koc: Raw commit c76646a adds src/agents/pi-embedded-runner/prompt-cache-observability.ts:51 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: c76646adb135; files: src/agents/pi-embedded-runner/prompt-cache-observability.ts)
  • Ayaan Zaidi: Raw commit 1f7b2f1 adds src/agents/embedded-agent-runner/prompt-cache-observability.ts:582 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 1f7b2f1c6f00; files: src/agents/embedded-agent-runner/prompt-cache-observability.ts)

PR surface

Source +263, Tests -2, Docs 0, Other +115. Total +376 across 5 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 2 388 125 +263
Tests 1 118 120 -2
Docs 1 1 1 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 115 0 +115
Total 5 622 246 +376

Review metrics

Metric Value Why it matters
Production versus test growth Runtime production +263 net lines; tests -2 net lines Growth implements bounded fact attribution and relocates the existing section/tool attribution into one owner; the test consolidation retains distinct behavior coverage.

Labels

Label changes:

  • add P2: Useful operator diagnostics with limited runtime impact and a focused integration-test repair.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🦐 gold shrimp.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Label justifications:

  • P2: Useful operator diagnostics with limited runtime impact and a focused integration-test repair.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed October 27, 2026, 12:20 PM ET / 16:20 UTC.

@steipete
steipete merged commit fe8f3f3 into main Oct 27, 2026
138 checks passed
@steipete
steipete deleted the steipete/fix-prompt-cache-drop-attribution-20261027 branch October 27, 2026 16:30
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 28, 2026
…aw#186095)

* fix(agents): identify changed facts behind prompt-cache drops

Name bounded runtime, routing, tooling, context-line, and computer-description changes only when reporting a cache drop. Keep private before-images bounded and exclude prompt values and arbitrary headings/tool names from warning details. Prompt and provider payload bytes remain unchanged.

* test(agents): consolidate cache diagnostic regression coverage

* test(agents): remove unused cache observation import
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. scripts Repository scripts size: L status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant