Repository navigation
fix: include plugin LLM calls in usage diagnostics - #107937
vincentkoc merged 1 commit into
Conversation
|
Land-ready proof for
Known proof gap: no live provider/OTLP call was made; the source-level completion path and both exporter outputs are covered by focused deterministic tests. |
ed089fc to
a023985
Compare
a023985 to
f528160
Compare
|
Codex review: needs maintainer review before merge. Reviewed August 6, 2026, 4:36 AM ET / 08:36 UTC. ClawSweeper reviewWhat this changesRecords successful direct and isolated plugin LLM completion usage in diagnostics and adds host-derived plugin identity only to the corresponding OpenTelemetry span. Merge readinessNo blocking findings. This PR remains necessary because current main still omits plugin LLM usage diagnostics; the exact head implements the approved host-owned path with sufficient real Gateway-to-OTLP proof. Priority: P2 Review scores
Verification
How this fits togetherPlugin runtime LLM calls produce normalized token and cost data, which diagnostics exporters consume. This PR routes valid completion usage through the shared host finalizer to OpenTelemetry and Prometheus while keeping plugin attribution private to OpenTelemetry spans. flowchart LR
A[Plugin LLM call] --> B[Direct or isolated completion]
B --> C[Shared usage finalizer]
C --> D[Trusted diagnostics dispatcher]
D --> E[OpenTelemetry usage span]
D --> F[Prometheus aggregate metrics]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +188, Tests +917, Docs +5. Total +1110 across 20 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge-risk optionsMaintainer options:
Copy recommended automerge instructionTechnical reviewBest possible solution: Validate the clean merge result against current main, then land the shared host-finalizer repair without adding plugin labels to aggregate metrics or public SDK listener types. Do we have a high-confidence way to reproduce the issue? Yes, from source: current main returns plugin completion usage without emitting model.usage, while the exact-head Gateway-to-OTLP scenario exercises the repaired production boundary. Is this the best way to solve the issue? Yes. A single host-owned finalizer covers direct and isolated completions, while the dispatcher carries attribution privately to the OTel exporter instead of expanding public event or SDK contracts. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 245dbacbe091. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (10 earlier review cycles; latest 8 shown)
|
|
Maintainer decision: preserve every existing OpenTelemetry metric and Prometheus label contract. The approved repair is:
This resolves the additive-versus-breaking telemetry decision. The existing contributor PR should be repaired in place and preserve contributor credit. |
f528160 to
12acb69
Compare
12acb69 to
4b236be
Compare
|
@clawsweeper re-review Please review exact published head |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
4b236be to
921524f
Compare
|
🦞👀 Command router queued. I will update this comment with the next step. |
1c7c3d0 to
e8a28f4
Compare
|
@clawsweeper re-review Please review exact published head Both rank-up moves from the This head is the test-only lint successor to |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
e8a28f4 to
ae21df4
Compare
|
@clawsweeper re-review Please review the exact published head Exact-head CI is green in run |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
Emit usage once at the shared plugin completion boundary and expose host-derived plugin identity only on OTel usage spans. Preserve aggregate metric labels and cover the redacted Gateway path end to end. Refs openclaw#98968 Co-authored-by: Last-emo-boy <[email protected]> Co-authored-by: ZengWen-DT <[email protected]>
ae21df4 to
8d55032
Compare
|
@clawsweeper re-review Please review exact published head The remaining same-invariant fixes are complete:
Exact-head proof is in the PR body: 385 focused tests, clean P0-P2 autoreview, and redacted AWS Gateway-to-OTLP output showing one attributed span and no request content. |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
Exact-head ClawSweeper review disposition for
Exact-head CI remains green: https://github.com/openclaw/openclaw/actions/runs/31082140776 |
|
Merged via squash.
|
Emit usage once at the shared plugin completion boundary and expose host-derived plugin identity only on OTel usage spans. Preserve aggregate metric labels and cover the redacted Gateway path end to end. Refs openclaw#98968 Co-authored-by: Vincent Koc <[email protected]> Co-authored-by: ZengWen-DT <[email protected]>
What Problem This Solves
Plugin calls through
runtime.llm.completenow contribute trusted token and cost diagnostics at the host-owned completion boundary.Root Cause
Direct and isolated plugin LLM completions returned normalized usage, but the shared completion owner did not emit that usage to diagnostics.
Three sibling defects remained:
runCliAgentexposed CLI-isolated usage inmeta.agentMeta.usage, butrunCliIsolatedCompletiondropped it before the shared finalizer.stopReasonand output validity, so resolved errors, aborts, and reasoning-only messages could emit usage.Fix
model.usageevent only for a successful visible completion with positive token or cost usage.OpenClawPluginServiceContext.internalDiagnostics.onEvent,DiagnosticEventPrivateData, public metadata, and SDK export counts unchanged.hostPluginIdin the public type.openclaw.pluginonly to the trusted OTel usage span. Existing OTel metric labels and Prometheus labels remain unchanged.User Impact
Operators can attribute plugin-initiated LLM spend in traces without changing existing metric series, dashboards, or recording rules. Non-exporter plugins cannot observe or claim another plugin's trace identity.
Evidence
8d55032feba093179c690cab4080c40ea9d59bbb, one contributor-preserving commit.llm-tasksuites.0.90.oxfmt --check, focusedoxlint,git diff --check, max-lines, extension boundary, deprecated-API, dead-export, Plugin SDK API/export, and Plugin SDK surface checks passed.4831public exports,2908callable exports,0forbidden package subpaths.Exporter capability boundary
src/plugins/registry-registrars-operations.ts:300capturespluginId,origin, andtrustedOfficialInstallfrom the host-owned plugin record when a service is registered; the plugin supplies only the service implementation.src/plugins/services.ts:38grantsinternalDiagnosticsonly when the host record owner matches the exactdiagnostics-otelordiagnostics-prometheusservice id and the record is bundled or a verified official install.src/plugins/manifest-registry.ts:835derives official-install trust from a matching install path, install record, official catalog package/id, and registry or trusted official ClawHub source. Workspace/path/npm-pack/custom-source/unrecorded lookalikes cannot obtain the capability from manifest claims.src/infra/diagnostic-events.ts:1093gives the one-shot host identity only to the listener wrapper marked by the OTel service context. Public listeners, generic trusted listeners, and Prometheus receive cloned private data withouthostPluginId;src/plugins/services.test.ts:781covers the grant and spoof-denial matrix.hostPluginIdis absent from the public listener declaration, and the internal test-runtime listener API is not shipped as a package export. OpenClaw native plugins are trusted in-process code; the supported plugin model does not claim process isolation from deliberate runtime tampering.Exact-head real Gateway + OTLP proof
awscbx_4b929dbe9648run_2758a6c4fd2ellm-task+ OTLP receiver E2E passed, exit0,runStatus=succeeded; lease released.Redacted receiver/span output:
{"spanName":"openclaw.model.usage","pluginId":"llm-task","inputTokens":64,"outputTokens":24,"totalTokens":88,"attributedUsageSpanCount":1,"requestContentPresent":false}The E2E fails if the completion emits a second matching usage span, if attribution is missing or forged, or if request content reaches OTLP.
Production runtime delta is
+217/-83(net+134), justified by the shared completion owner, CLI adapter propagation, and exporter-private security/version-skew boundary. Tests and QA are net+971; docs are net+5.No changelog entry is included for this contributor repair.
Fixes #98968