Repository navigation
fix(agent): emit model.usage diagnostic for HTTP ingress traffic - #96152
Conversation
|
Codex review: needs maintainer review before merge. Reviewed June 24, 2026, 4:15 AM ET / 08:15 UTC. Summary PR surface: Source +88, Tests +301. Total +389 across 2 files. Reproducibility: yes. at source level. Current main routes both OpenAI-compatible HTTP handlers through Review metrics: 1 noteworthy metric.
Root-cause cluster Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Next step before merge
Security Review detailsBest possible solution: Land the shared ingress diagnostic emission after maintainer review, then close the canonical HTTP-ingress diagnostics issue when the fix merges. Do we have a high-confidence way to reproduce the issue? Yes at source level. Current main routes both OpenAI-compatible HTTP handlers through Is this the best way to solve the issue? Yes. Emitting once from the shared ingress finalization boundary is the narrow maintainable fix compared with endpoint-local emission, and the sibling endpoint-local PR remains weaker for the same canonical issue. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 599294b9af1f. Label changesLabel changes:
Label justifications:
Evidence reviewedPR surface: Source +88, Tests +301. Total +389 across 2 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
|
3b3bd87 to
f2853ec
Compare
f2853ec to
ad0fa63
Compare
|
Merge-ready from my review. Local maintainer review and clean local autoreview found no accepted/actionable findings. ClawSweeper review is also clean, CI is green, and the live proof in the PR body is sufficient for the affected HTTP ingress diagnostics path. This is the best narrow fix: instrumenting |
|
@sallyom a huge thanks for the thorough reviews on my PRs — really appreciate you taking the time to go through them. Sorry for the ping, but I couldn't let it pass without saying thank you. Much appreciated! |
…nclaw#96152) * fix(agents): emit model.usage diagnostic for HTTP ingress traffic * fix(agents): emit model.usage diagnostic for HTTP ingress traffic * fix(agent): add regression tests and refactor ingress model.usage diagnostic emission * fix(agent): resolve oxlint curly and no-useless-fallback-in-spread violations
Root Cause
agentCommandFromIngress, the shared entry point for all HTTP ingress paths (POST /v1/responses, POST /v1/chat/completions, node-event dispatch), did not emitmodel.usagediagnostic events. This diagnostic event, which carries token and cost data, was only emitted inrunReplyAgent(channel message loop) andfinalizeCronRun(cron). Every diagnostics consumer (Langfuse bridge,@openclaw/diagnostics-otel,diagnostics-prometheus) was blind to HTTP API traffic.Summary
POST /v1/responses,POST /v1/chat/completions) received responses with usage data but never emittedmodel.usagediagnostics, leaving exporters blind to API traffic.model.usageemission inagentCommandFromIngress, the shared HTTP ingress finalization point, by reading usage data already present inresult.meta.agentMeta.usage— the same data that was already being returned in API responses but not surfaced as a diagnostic event.runContext.messageChannel/messageChannel/channel) instead of hardcoding"http", so non-HTTP ingress callers (e.g. TUI) are not misattributed.emitIngressModelUsageDiagnostic+ingressDiagnosticChannelhelpers, exposed via thetestingnamespace for focused regression coverage.Verification
pnpm build— build succeedspnpm test src/agents/agent-command.ingress-diagnostics.test.ts— 13 passedpnpm test src/agents/agent-command.compaction-rotation.test.ts— 3 passed (no regression)pnpm check:test-types— cleanpnpm check:import-cycles— 0 cyclespnpm openclaw doctor— runtime validation passesReal behavior proof
Behavior addressed: HTTP API endpoints (POST /v1/responses, POST /v1/chat/completions) now emit
model.usagediagnostic events through the sharedagentCommandFromIngress→emitIngressModelUsageDiagnosticpath, usingemitTrustedDiagnosticEventpipeline consumed by Langfuse, OpenTelemetry, and Prometheus exporters.Real environment tested: Linux x86_64, Node v24.13.1, OpenClaw 2026.6.9, branch
fix/issue-96093-model-usage-ingress, commitc225222c31Exact steps or command run after this patch:
Evidence after fix:
Observed result after fix: HTTP POST to
/v1/chat/completionsis routed throughagentCommandFromIngress→agentCommandInternal→ real agent runner (zte-maas/Qwen3-235B-A22B). After the agent completes, a realmodel.usagediagnostic event is dispatched throughemitTrustedDiagnosticEventand delivered to anonInternalDiagnosticEventsubscriber — the same pipeline consumed by Langfuse bridge,@openclaw/diagnostics-otel, anddiagnostics-prometheus. The subscriber received a complete event with provider, model, usage (input/output/cacheRead/cacheWrite/promptTokens/total), lastCallUsage, context (limit/used), costUsd, durationMs, and trusted+internal metadata proving core-owned instrumentation provenance. TheemitIngressModelUsageDiagnosticandingressDiagnosticChannelfunctions are present in the compiled dist binary. 13 focused regression tests cover diagnostics-enabled emission, diagnostics-disabled skip, zero-usage skip, missing agentMeta, channel resolution, cost computation, and optional field handling. Test types and import cycles are clean.