Skip to content

fix(advisor): log review cache writes - #196704

Merged
obviyus merged 2 commits into
mainfrom
fix/advisor-log-cache-writes
Nov 10, 2026
Merged

obviyus merged 2 commits into
mainfrom
fix/advisor-log-cache-writes

Conversation

@obviyus

@obviyus obviyus commented Nov 10, 2026

Copy link
Copy Markdown
Collaborator

What Problem This Solves

Advisor's review usage log omits cache writes. On the team Gateway (OpenAI gpt-6.1-sol route), 46 of 205 reviews since this morning logged:

advisor: review usage for session …: input=75 cacheRead=0 output=6

That reads like a review that saw no conversation. The same sessions' normal turns show about 200k cached prompt tokens, and the review prompt alone is about 1,400 characters.

Why

mapResponsesTerminalUsage subtracts both cached_tokens and cache_write_tokens from OpenAI's input_tokens. A review that misses the provider cache therefore reports its forked context as cacheWrite. The plugin already receives cacheWriteTokens (LlmCompleteUsage) but didn't log it.

Misses happen because reviews omit the conversation's prompt-cache key by design since #182844 (forks rebuild context independently). On OpenAI that makes cache affinity best-effort:

Gateway / route Reviews Cache misses (cacheRead=0)
Team, openai/gpt-6.1-sol 205 46 (22%)
Peanutto, Anthropic Opus (since Oct 24) 166 2 (1%)

Change

  • Log cacheWrite with the other review usage fields.
  • Docs: the advisor section names the logged fields and says misses report context as cache writes.

No behavior change. Whether to restore cache affinity for forks is left as a separate decision.

Evidence

  • Usage mapping read from packages/ai/src/providers/openai-responses-terminal-usage.ts and src/gateway/server-plugin-subagent-runtime.ts (cacheWriteTokens: value.cacheWrite).
  • Team and Peanutto counts come from Gateway logs (read-only).
  • Not yet observed directly: a logged cacheWrite value on a miss. This change is what makes that visible. I'll confirm on the next team release.
  • extensions/advisor tests (10) pass; oxlint and oxfmt clean.

Review usage logged input, cache reads and output but not cache writes.
On OpenAI routes a review that misses the prompt cache reports its whole
forked context as cache writes, so the log showed input=75 cacheRead=0 and
looked like a review that saw no conversation.

Co-authored-by: obviyus <[email protected]>
@clawsweeper

clawsweeper Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation extensions: advisor size: XS labels Nov 10, 2026
@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. P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. 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 Nov 10, 2026
@clawsweeper

clawsweeper Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR adds cache-write token counts to Advisor review logs and documents provider-dependent cache-write reporting.

Example: A review returns inputTokens=75, cacheReadTokens=0, cacheWriteTokens=200000, and outputTokens=6.

  • Before: input=75 cacheRead=0 output=6
  • After: input=75 cacheRead=0 cacheWrite=200000 output=6

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The patch is minimal and source-supported, and the prior finding is fixed; after-change runtime evidence remains limited.
Proof confidence 🦐 gold shrimp (3/6) This collaborator-authored PR is outside the ordinary contributor proof gate; reported unit checks support the change, but the inspected historical settings screenshot does not exercise the added log field.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Operators cannot account for review context tokens when the provider reports them as cache writes.
Reason: The feature-history owner proposes a narrow diagnostic correction using usage data already supplied to Advisor.

Merge readiness

✅ Ready for maintainer review

Keep open: this collaborator-authored PR provides useful diagnostic visibility, resolves the prior documentation finding, and has no remaining actionable findings.

Priority: P3
Reviewed head: 9236119323dd7fa904d93c706afb5238ce3dea73

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: No supplied artifact shows an after-change Gateway review log with a provider-reported nonzero cacheWrite value.
Agent review details

How this fits together

Advisor requests a conversation review through the session-fork runtime, receives normalized provider usage, and writes token counts to Gateway logs.

flowchart LR
 A[Advisor review trigger] --> B[Session fork runtime]
 B --> C[Model provider]
 C --> D[Normalized usage]
 D --> E[Advisor Gateway log]
Loading

Technical review

Best possible solution:

Retain the existing logging-field addition and the qualified explanation without changing fork cache identity.

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

Source confirms that session forks return cacheWriteTokens while current-main Advisor logging omits it; no target code was executed.

Is this the best way to solve the issue?

Adding the available field at the existing logging owner is the smallest complete fix, and the revised documentation correctly conditions cache-write reporting on provider usage.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 920338823f7b.

Provenance checked

Testing

Proof path: unit tests only.

Security

None.

Evidence

What I checked:

PR surface

Source 0, Docs +3. Total +3 across 2 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 1 1 0
Tests 0 0 0 0
Docs 1 5 2 +3
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 6 3 +3

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Labels

Label changes:

  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P3: This improves diagnostic visibility without changing model requests, delivery, configuration, or persisted state.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Rank-up moves

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

  • Optionally confirm a real Gateway review emits the provider-reported cacheWrite count, sharing only redacted output.

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.

History

Review history (1 earlier review cycle)
  • reviewed 2026-11-10T14:46:33.219Z sha 7f2cde9 :: needs changes before merge. :: [P3] Qualify the cache-miss explanation by provider-reported usage

Reviewed November 10, 2026, 10:05 AM ET / 15:05 UTC (Revision 2).

@obviyus

obviyus commented Nov 10, 2026

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@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. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. 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 Nov 10, 2026
@obviyus
obviyus merged commit b4bd83e into main Nov 10, 2026
110 checks passed
@obviyus
obviyus deleted the fix/advisor-log-cache-writes branch November 10, 2026 15:16
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 11, 2026
* fix(advisor): log review cache writes

Review usage logged input, cache reads and output but not cache writes.
On OpenAI routes a review that misses the prompt cache reports its whole
forked context as cache writes, so the log showed input=75 cacheRead=0 and
looked like a review that saw no conversation.

Co-authored-by: obviyus <[email protected]>

* docs(advisor): qualify cache-write reporting by provider usage

Co-authored-by: obviyus <[email protected]>

---------

Co-authored-by: obviyus <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation extensions: advisor P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: XS 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