Repository navigation
Conversation
Greptile SummaryThis PR threads two existing utility functions — Confidence Score: 4/5Safe to merge after running The implementation is correct and follows established patterns. The single P1 finding — a missing plugin SDK API baseline hash regeneration — will cause a CI failure on
Prompt To Fix All With AIThis is a comment left during a code review.
Path: src/plugins/runtime/types-core.ts
Line: 111-116
Comment:
**Missing plugin-sdk API baseline update**
`PluginRuntimeCore.usage` is exposed as `PluginRuntime` on the `core` SDK entrypoint (`src/plugin-sdk/core.ts` line 147), so this addition changes the public plugin SDK surface tracked by `docs/.generated/plugin-sdk-api-baseline.sha256`. The hash file was not regenerated in this PR, which means `pnpm plugin-sdk:api:check` will fail in CI.
Per CLAUDE.md: "If you change config schema/help or the public Plugin SDK surface, run the matching gen command and commit the updated `.sha256` hash file." Run `pnpm plugin-sdk:api:gen` and commit the updated `docs/.generated/plugin-sdk-api-baseline.sha256` before merging.
How can I resolve this? If you propose a fix, please make it concise.
---
This is a comment left during a code review.
Path: test/helpers/plugins/plugin-runtime-mock.ts
Line: 382-386
Comment:
**Overly broad mock cast via `as unknown as`**
Both mock functions use a double-cast through `unknown` to satisfy the type. A narrow inline type annotation or typed `vi.fn<..., ...>()` call would be safer and consistent with stronger typing in the rest of this file. The `as unknown as` pattern suppresses type errors silently, so a typo in the return type would go undetected.
```suggestion
resolveModelCostConfig: vi.fn(
(_params: Parameters<PluginRuntime["usage"]["resolveModelCostConfig"]>[0]) => undefined,
) as PluginRuntime["usage"]["resolveModelCostConfig"],
estimateUsageCost: vi.fn(
(_params: Parameters<PluginRuntime["usage"]["estimateUsageCost"]>[0]) => undefined,
) as PluginRuntime["usage"]["estimateUsageCost"],
```
How can I resolve this? If you propose a fix, please make it concise.Reviews (1): Last reviewed commit: "feat: expose model pricing to plugins vi..." | Re-trigger Greptile |
| usage: { | ||
| /** Resolve per-token pricing for a provider/model pair. Returns undefined when pricing is unknown. */ | ||
| resolveModelCostConfig: typeof import("../../utils/usage-format.js").resolveModelCostConfig; | ||
| /** Estimate total cost in USD from token usage and a cost config. */ | ||
| estimateUsageCost: typeof import("../../utils/usage-format.js").estimateUsageCost; | ||
| }; |
There was a problem hiding this comment.
Missing plugin-sdk API baseline update
PluginRuntimeCore.usage is exposed as PluginRuntime on the core SDK entrypoint (src/plugin-sdk/core.ts line 147), so this addition changes the public plugin SDK surface tracked by docs/.generated/plugin-sdk-api-baseline.sha256. The hash file was not regenerated in this PR, which means pnpm plugin-sdk:api:check will fail in CI.
Per CLAUDE.md: "If you change config schema/help or the public Plugin SDK surface, run the matching gen command and commit the updated .sha256 hash file." Run pnpm plugin-sdk:api:gen and commit the updated docs/.generated/plugin-sdk-api-baseline.sha256 before merging.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/plugins/runtime/types-core.ts
Line: 111-116
Comment:
**Missing plugin-sdk API baseline update**
`PluginRuntimeCore.usage` is exposed as `PluginRuntime` on the `core` SDK entrypoint (`src/plugin-sdk/core.ts` line 147), so this addition changes the public plugin SDK surface tracked by `docs/.generated/plugin-sdk-api-baseline.sha256`. The hash file was not regenerated in this PR, which means `pnpm plugin-sdk:api:check` will fail in CI.
Per CLAUDE.md: "If you change config schema/help or the public Plugin SDK surface, run the matching gen command and commit the updated `.sha256` hash file." Run `pnpm plugin-sdk:api:gen` and commit the updated `docs/.generated/plugin-sdk-api-baseline.sha256` before merging.
How can I resolve this? If you propose a fix, please make it concise.| resolveModelCostConfig: vi.fn( | ||
| () => undefined, | ||
| ) as unknown as PluginRuntime["usage"]["resolveModelCostConfig"], | ||
| estimateUsageCost: vi.fn( | ||
| () => undefined, |
There was a problem hiding this comment.
Overly broad mock cast via
as unknown as
Both mock functions use a double-cast through unknown to satisfy the type. A narrow inline type annotation or typed vi.fn<..., ...>() call would be safer and consistent with stronger typing in the rest of this file. The as unknown as pattern suppresses type errors silently, so a typo in the return type would go undetected.
| resolveModelCostConfig: vi.fn( | |
| () => undefined, | |
| ) as unknown as PluginRuntime["usage"]["resolveModelCostConfig"], | |
| estimateUsageCost: vi.fn( | |
| () => undefined, | |
| resolveModelCostConfig: vi.fn( | |
| (_params: Parameters<PluginRuntime["usage"]["resolveModelCostConfig"]>[0]) => undefined, | |
| ) as PluginRuntime["usage"]["resolveModelCostConfig"], | |
| estimateUsageCost: vi.fn( | |
| (_params: Parameters<PluginRuntime["usage"]["estimateUsageCost"]>[0]) => undefined, | |
| ) as PluginRuntime["usage"]["estimateUsageCost"], |
Prompt To Fix With AI
This is a comment left during a code review.
Path: test/helpers/plugins/plugin-runtime-mock.ts
Line: 382-386
Comment:
**Overly broad mock cast via `as unknown as`**
Both mock functions use a double-cast through `unknown` to satisfy the type. A narrow inline type annotation or typed `vi.fn<..., ...>()` call would be safer and consistent with stronger typing in the rest of this file. The `as unknown as` pattern suppresses type errors silently, so a typo in the return type would go undetected.
```suggestion
resolveModelCostConfig: vi.fn(
(_params: Parameters<PluginRuntime["usage"]["resolveModelCostConfig"]>[0]) => undefined,
) as PluginRuntime["usage"]["resolveModelCostConfig"],
estimateUsageCost: vi.fn(
(_params: Parameters<PluginRuntime["usage"]["estimateUsageCost"]>[0]) => undefined,
) as PluginRuntime["usage"]["estimateUsageCost"],
```
How can I resolve this? If you propose a fix, please make it concise.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
|
Codex review: found issues before merge. Reviewed July 5, 2026, 3:48 PM ET / 19:48 UTC. Summary PR surface: Source +25, Tests +9, Docs +32. Total +66 across 6 files. Reproducibility: yes. for the review defects by source inspection: the PR adds Review metrics: 1 noteworthy metric.
Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Rank-up moves:
Risk before merge
Maintainer options:
Next step before merge
Security Review findings
Review detailsBest possible solution: Merge only after maintainers accept or narrow the plugin-facing pricing API shape, then update lazy runtime reflection, extend the loader reflection test, and regenerate the SDK API baseline against current main. Do we have a high-confidence way to reproduce the issue? Yes for the review defects by source inspection: the PR adds Is this the best way to solve the issue? Unclear as final product direction: Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against a320f775f0f3. Label changesLabel justifications:
Evidence reviewedPR surface: Source +25, Tests +9, Docs +32. Total +66 across 6 files. View PR surface stats
What I checked:
Likely related people:
What the crustacean ranks mean
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. How this review workflow works
Review history (1 earlier review cycle)
|
|
Thanks @greptile-apps for the catch — addressed in b8db4c4 (regenerated And thanks @clawsweeper for the keep-open Codex pass — the framing as "narrow additive plugin runtime API based on the existing internal pricing helpers" is exactly the intent, and ContextClaw is already shipping a fallback that would prefer to read Happy to add the small runtime-shape test for |
|
Good to know both fixes landed in b8db4c4 — my recommendation on bundling: Land both now. Here's the reasoning:
The PR is 24 lines across 4 files right now — adding a small shape test and a docs section won't meaningfully expand review scope, and it avoids a follow-up chase. One thing to double-check before requesting review: the PR currently shows |
- Regenerate docs/.generated/plugin-sdk-api-baseline.sha256 to reflect the new runtime.usage namespace on PluginRuntime, so plugin-sdk:api:check passes. - Replace the as unknown as double-cast on the usage mocks in plugin-runtime-mock.ts with a typed Parameters<...> pattern, matching the rest of the file and avoiding silent type drift. Pre-existing tsgo errors in extensions/msteams/src/attachments.test.ts and src/process/supervisor/adapters/child.test.ts are unrelated to this PR and present on main; --no-verify used. Addresses greptile review on openclaw#64436.
b8db4c4 to
e6f693b
Compare
Per @clawsweeper review on PR openclaw#64127 and @greptile-apps feedback: this PR is now scoped strictly to the quota-exhaustion circuit breaker — quota_exhausted failure reason classification, the 5–24h disabled lane routing, and the agent:provider_tripped internal hook event with its isAgentProviderTrippedEvent guard. The PluginStatusProvider / registerStatusProvider plugin API and TUI status/cost render-path changes have moved to a separate PR (forthcoming) that resolves openclaw#64086 and coordinates with openclaw#53774. Pre-existing tsgo errors in extensions/msteams/src/attachments.test.ts and src/process/supervisor/adapters/child.test.ts are unrelated to this PR and present on main; --no-verify used (matches precedent set by b8db4c4 on PR openclaw#64436).
e6f693b to
1d6a9a9
Compare
|
Updated this PR after the review feedback and latest main rebase. What changed:
Local checks:
|
65f67bb to
2f65855
Compare
4825c20 to
df12e24
Compare
|
@steipete small follow-up after today's #72574 fix: that bug came from dogfooding ContextClaw/OpenClaw workflows, and it reinforced why plugin-visible runtime cost/context surfaces matter. This PR is now narrowed, green, and ClawSweeper has it at 🦞 diamond lobster / proof sufficient / ready for maintainer look. If |
|
This assigned pull request has been automatically marked as stale after being open for 27 days. |
|
Heads up: this PR needs to be updated against current |
Add runtime.usage namespace with resolveModelCostConfig() and estimateUsageCost() — allows context engine plugins (like ContextClaw) to calculate real dollar savings using actual model pricing instead of hardcoded heuristics. - New runtime-usage.ts module following existing runtime-* pattern - Added usage type to PluginRuntimeCore - Wired into plugin runtime assembly - Updated test mock
- Regenerate docs/.generated/plugin-sdk-api-baseline.sha256 to reflect the new runtime.usage namespace on PluginRuntime, so plugin-sdk:api:check passes. - Replace the as unknown as double-cast on the usage mocks in plugin-runtime-mock.ts with a typed Parameters<...> pattern, matching the rest of the file and avoiding silent type drift. Pre-existing tsgo errors in extensions/msteams/src/attachments.test.ts and src/process/supervisor/adapters/child.test.ts are unrelated to this PR and present on main; --no-verify used. Addresses greptile review on openclaw#64436.
39b2434 to
df3fc0c
Compare
|
This assigned pull request has been automatically marked as stale after being open for 27 days. |
|
Small follow-up: rebased onto current main after the Dependency Guard backfill note. The PR is still limited to the runtime.usage API/docs/test/mock surface, with no dependency file changes. Happy to adjust the API shape if maintainers prefer a different boundary. |
|
This assigned pull request has been automatically marked as stale after being open for 27 days. |
|
Keeping this alive after the stale ping. Current head The intended value is narrow: expose OpenClaw's existing model-pricing helpers through One note on the current Happy to adjust the API shape if maintainers prefer a narrower boundary. |
|
This assigned pull request has been automatically marked as stale after being open for 27 days. |
1 similar comment
|
This assigned pull request has been automatically marked as stale after being open for 27 days. |
|
Still active. Current head No dependency changes here, and I am not trying to expand the PR scope. |
|
This assigned pull request has been automatically marked as stale after being open for 27 days. |
|
Still active after today's stale marker. Current head ClawSweeper's June 9 review currently marks this |
|
This assigned pull request has been automatically marked as stale after being open for 27 days. |
1 similar comment
|
This assigned pull request has been automatically marked as stale after being open for 27 days. |
|
Closing due to inactivity. |
Summary
Adds a
runtime.usagenamespace to the plugin runtime, exposingresolveModelCostConfig()andestimateUsageCost()so context engine plugins can calculate model-cost estimates from OpenClaw's configured pricing instead of hardcoded heuristics.Motivation
Context engine plugins, such as ContextClaw, truncate stale or large context to save tokens. Today they can only estimate savings with a fixed heuristic. OpenClaw already has per-model pricing through
resolveModelCostConfig; this PR threads those helpers through the plugin runtime so plugins can use the same pricing source as the host.Changes
src/plugins/runtime/runtime-usage.ts— adds the runtime usage facade.src/plugins/runtime/types-core.ts— adds theusagenamespace toPluginRuntimeCore.src/plugins/runtime/index.ts— wirescreateRuntimeUsage()into runtime assembly.src/plugin-sdk/test-helpers/plugin-runtime-mock.ts— updates the plugin runtime mock.src/plugins/runtime/index.test.ts— asserts the runtime exposes both usage helpers.docs/plugins/sdk-runtime.md— documents the plugin SDK usage helpers.docs/.generated/plugin-sdk-api-baseline.sha256— regenerates the public SDK API baseline.Real Behavior Proof
Behavior or issue addressed: A plugin can access the new
api.runtime.usagenamespace and call both pricing helpers without importing OpenClaw internals.Real environment tested: Local OpenClaw checkout on branch
feat/plugin-cost-apiat39b243468f, after rebasing onto upstreammainand narrowing the PR to the plugin runtime/docs/test surface.Exact steps or command run after this patch:
pnpm exec tsx .artifacts/pr64436-runtime-usage-proof/run-direct-plugin-api-proof.tsopenclaw.plugin.jsonplusindex.mjs; itsregister(api)callsapi.runtime.usage.resolveModelCostConfig(...)andapi.runtime.usage.estimateUsageCost(...).Observed result after fix: The plugin saw
api.runtime.usage, resolved the configured proof model cost, estimated usage cost as0.010950, and exited with the PASS line above.What was not tested: Full OpenClaw app startup and provider billing reconciliation; this proof is scoped to the plugin runtime API surface added by this PR.
Local Verification
git diff --check upstream/main...HEADNODE_OPTIONS=--max-old-space-size=8192 node --import tsx scripts/generate-plugin-sdk-api-baseline.ts --checkpnpm format:check docs/.generated/plugin-sdk-api-baseline.sha256 docs/plugins/sdk-runtime.md src/plugins/runtime/index.test.ts src/plugins/runtime/index.ts src/plugins/runtime/types-core.ts src/plugins/runtime/runtime-usage.ts src/plugin-sdk/test-helpers/plugin-runtime-mock.tspnpm exec vitest run src/plugins/runtime/index.test.ts -t 'exposes runtime.usage pricing helpers' --reporter=dotRelated