Repository navigation
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. What this changesThis PR forwards provider-reported embedding token counts to the Gateway through an optional callback while preserving vector returns. Example: POST /v1/embeddings with input ["alpha", "beta"] using native Ollama bge-m3.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep this PR open for landing: current main still reports zero embedding usage, and this approved, proven repair has no actionable review findings. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherThe authenticated Gateway embeddings endpoint selects the configured provider, sends text through its existing transport and lifecycle owners, and returns vectors plus reported usage. flowchart LR
A[HTTP client] --> B[Gateway authentication and routing]
B --> C[Existing embedding provider call]
C --> D[Provider HTTP transport]
D --> E[Vector and usage parsing]
E --> F[Gateway usage aggregation]
F --> G[Embedding response]
Technical reviewBest possible solution: Land the approved optional observer repair through the existing provider contract, retaining zero when usage is unavailable. Do we have a high-confidence way to reproduce the issue? Current-main source discards provider usage and emits 0/0; supplied baseline Gateway results and the failing HTTP usage assertion independently establish the failure. Is this the best way to solve the issue? The optional observer fixes the shared parsing and call contract without a competing embedding path, while preserving cancellation, deadlines, service leases, and existing callers. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against fdb73933b276. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +11, Tests +93, Docs +9, Other -1. Total +112 across 19 files. Added test files: 0. View PR surface stats
Review metrics
LabelsLabel changes: No label changes. Label justifications:
Rating scale6/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. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (14 earlier review cycles; latest 8 shown)
Reviewed October 10, 2026, 12:57 AM ET / 04:57 UTC (Revision 15). |
fda52d5 to
24e758d
Compare
24e758d to
0660e48
Compare
0660e48 to
f2ccc7f
Compare
The caller-deadline change in openclaw#167891 moved availability probes from embedBatch to embed. Move the existing fixture gate and call-count assertions to the current entry point so late-probe exercises retained ownership instead of waiting forever for an unused batch stub.
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review Maintainer direction: the additive, optional |
|
🦞👀 Re-review progress:
|
Resolve the shared HTTP fixture by preserving slash-model override forwarding and upstream token usage assertions.
|
Merged via squash.
|
…ddings endpoint (openclaw#154721) * fix(gateway): report real token usage from the OpenAI-compatible embeddings endpoint The /v1/embeddings bridge hardcoded usage to zero and dropped upstream usage during response parsing, so token tracking and billing middleware always saw $0 while the sibling chat completions surface reports real usage. - Parse OpenAI-style usage in the openai-compatible provider and the shared memory-host-sdk remote fetch path (covers openai, voyage, lmstudio, mistral, deepinfra) - Add an additive optional EmbeddingProvider.embedBatchDetailed that returns vectors plus provider-reported usage; embedBatch stays the canonical vector-only contract for existing plugin implementations - Prefer detailed usage in the embeddings handler and fall back to a char-based estimate so both usage fields are always present - Forward the detailed path through the lmstudio lease wrapper and the llama-cpp facts wrapper without bypassing their lifecycle semantics * fix(memory-host-sdk): keep embeddings-remote-fetch within the allowed core bridge files The package boundary contract allows only the embeddings.types.ts alias to reference the canonical embedding provider contract. Route the EmbeddingUsage type import through that alias so the memory-host-sdk core bridge list stays unchanged. * fix(memory-host-sdk): omit batch usage when any query response lacks usage A detailed query batch fans out to one upstream request per input. When any constituent response omits usage, the aggregated batch usage used to silently undercount by reporting only the sum of the responses that did report. Return undefined instead so callers fall back to estimation, pin the semantics on the embedBatchDetailed contract, and add a mixed-response regression case. Addresses ClawSweeper review finding on PR openclaw#154721. * chore(embeddings): prune removed assertion allowance * test(memory): gate reload probes through embed The caller-deadline change in openclaw#167891 moved availability probes from embedBatch to embed. Move the existing fixture gate and call-count assertions to the current entry point so late-probe exercises retained ownership instead of waiting forever for an unused batch stub. --------- Co-authored-by: Peter Steinberger <[email protected]> Co-authored-by: xialonglee <[email protected]>
What Problem This Solves
Fixes:
/v1/embeddingsreports zero token usage even when the embedding provider returns actual token counts.User Impact
Clients receive provider-reported counts through native Ollama and OpenAI-compatible embedding transports. Providers that report zero keep zero; missing or incomplete counts remain zero without estimates. Existing embedding plugins retain their vector-only return values. No configuration, stored data, or migration changes are required.
Why This Change Was Made
Usage was discarded by response parsers, and the Gateway hard-coded both usage fields. The existing embedding call options now carry an optional
onUsageobserver. Parsers validate external counts, providers report each successful upstream response, and the Gateway sums complete reports. The same call path preserves model preload, service leases, cancellation, and deadlines; separate detailed-batch methods and their duplicate lifecycle wrappers are removed.This preserves @xialonglee's original commits and contribution while merging current main and simplifying the implementation. Production: +95/−84 (net +11, reduced from the original net +178); tests/support: +123/−30; docs: +9/−0; assertion baseline: −1 for the removed Ollama cast. The remaining production growth supplies the optional typed observer and validates provider counts.
Evidence
Baseline captured before repair:
ea6022cae60c509d8c0e8029ad8030557a917617, real isolated Gateway on loopback port 19232. With["alpha","beta"], direct Ollama reports 7 tokens forbge-m3and 6 fornomic-embed-text; both the native and/v1Gateway paths returned 0/0. LM Studiotext-embedding-nomic-embed-text-v1.5reports upstream 0/0.The existing Gateway regression failed on main production at its usage assertion (upstream 777/778, Gateway 0/0; wall 264.23s), then passed after the repair. All 116 tests across five files passed, combined wrapper wall 226.87s:
The Gateway tests reuse the existing suite server. The changed HTTP usage assertion took 59ms; the new split-usage cases exercise complete totals and missing reports without additional Gateway boots. Provider tests cover singleton/batch reporting, zero, missing counts, and invalid counts.
Core and Ollama package typechecks, Gateway/plugins/packages test type graphs, scoped core/Ollama lint, SDK export checks, and all required baseline ratchets passed. Broad extension typechecking could not resolve QA Lab's
crabbox-providerunder the gateway-only dependency profile; the affected Ollama package was checked separately. An initial regression attempt overlapped setup and failed before test discovery on a generated-assetENOENT; the settled run supplied the actual failing-before proof.Live after proof on
b645ca800f3f17035796406f5f73cf9f14b5480e, through the real isolated Gateway HTTP endpoint:Every successful response contained two vectors. Example request (the
nativeagent selects Ollama's native transport;compatselects its/v1transport):The isolated Gateway was stopped after proof. Shared Ollama and LM Studio services were left running. Slash-containing overrides are handled separately in #161170.
Full
pnpm buildpassed on the live-tested headb645ca800f3f17035796406f5f73cf9f14b5480e(wall 1694.45s). The first full build reached final stamping but detected input changes while checks and maintenance were running; the successful retry was serialized with no concurrent writers. The earlier review preparation also refused changing artifacts, so the final independent review runs only after build and live proof settle.Independent Codex branch autoreview was scoped-clean through P2 on the live-tested head, with final source verification passed.
Final merge resolution
Main advanced while verification ran and introduced caller-owned HTTP deadlines in the generic embedding transport. Merged main
9c241fea9080083518a64a2b3278d3e7f391167ewithout rewriting contributor history. The only conflict resolution preserves itsfetchWithCallerDeadlinedispatcher and reads the signal fromcallOptions?.signalinstead of the removedparams.signal. Merge-resolution head:5c34c17e9d316bcb20981019ef5d5f5586f5eb18.On the resolved head, all 11 generic-provider tests passed, including both new deadline cases (wall 287.61s); core typechecking (41.23s), scoped type-aware core lint, and affected line-cap, max-lines, and assertion ratchets passed. The earlier lint invocation unnecessarily entered plugin declaration preparation and hit its timeout; the canonical core config completed without that unrelated preparation.
The real Gateway matrix and full build above belong to
b645ca8; they were reused for unchanged usage mapping, and no live run is claimed for the mechanical merge resolution. ClawSweeper's first exact-head review found no code issues, accepted the live proof, and requested only this main-conflict repair.Fresh independent Codex branch autoreview on
5c34c17e9d316bcb20981019ef5d5f5586f5eb18: scoped-clean, no actionable P0–P2 findings; final source verification passed. The review explicitly checked the merged signal/deadline integration.Repair inherited CI fixture
CI run 38009841853 on
5c34c17exposed a deterministic 120 s timeout inmemory-runtime.owners.test.ts'slate-probecase. Main commit603f60a38cfe(#167891) switched availability probes fromembedBatchtoembed, but the fixture still signaled its entry gate only fromembedBatch. The real probe returned while the test waited forever for an unused stub. The exact new-main control also failed; older main passed.Fixture-repair head
eb710ad903121ff3f0cea0b8406e4cb5a91b9d48moves the existing gate and probe-call assertions to anembedmock returning a flat vector, while retaining a batch-shapedembedBatchfallback. This is a six-line test-only correction with no budget increase, retry, production seam, or weakened assertion. The ownership file passes 17/17 (wall 150.81s), and the original seven-file/two-worker CI selection passes 101/101 (wall 195.43s). Scoped test types, type-aware lint, and affected line-cap, timeout-race, and mock-export ratchets pass.Fresh independent Codex branch autoreview on
eb710ad903121ff3f0cea0b8406e4cb5a91b9d48: scoped-clean through P2; final source verification passed. The reviewer also checked the ownership-fixture correction.Preserve current response diagnostics
Main subsequently added contextual embedding errors in #168035. Final head
4f5fece0f60e1c1441bf80b0f0bbac5485d194b7merges maina0197f4921be56a09126b9b96f583c84423de342, retaining its unknown-payload parsing, vector diagnostics, request/response logs, error mapping, and caller-abort behavior. Each adapter validates vectors before reporting usage. Usage assertions now use main's real HTTP Response fixture, including a valid JSON number that parses to infinity.Both affected suites pass 43/43 (32 remote-response cases and 11 generic-provider cases), combined wall 266.85s. Core typechecking (56.15s), canonical type-aware scoped lint, and affected line-cap/max-lines/assertion/mock-export ratchets pass. The proven ownership fixture remains intact. These integrations use focused proof; the full build and real local-model matrix remain explicitly attributed to
b645ca8.Fresh independent Codex branch autoreview on
4f5fece0f60e1c1441bf80b0f0bbac5485d194b7: scoped-clean through P2; final source verification passed. Immediately before publication, a read-only merge against live maine09f3ecd491db23f4fdc6e79b4349808d010f394was clean.Final-head
openclaw/ci-gatepassed in run 38018085761. ClawSweeper’s exact-head review found no code issues and accepted the live proof and focused integration checks. Its requested maintainer direction is recorded below. No merge has been requested.Maintainer direction
Use the additive, optional
EmbeddingProviderCallOptions.onUsagecallback as the supported public SDK contract for this repair. This is the requested design for propagating upstream embedding usage through the existing call contract. Preserve the vector return values ofembedandembedBatch, compatibility with existing providers/callers, and zero usage when counts are unavailable. The callback adds no configuration, persistence, retention, or authority.Main conflict repair (current head)
Current head
d98e79d71fb13f7dbe0e0d4c6ca9c215034e5d22merges main2d6f7a3052a03867896f10d521969c78c4555d9ainto the contributor branch without rewriting history. The only manual conflict resolution combines the HTTP helper's optional model-override header with its upstream usage assertion. Both slash-containing model coverage and usage coverage remain; production code merged automatically.Focused embeddings validation passed 123/123 tests across five files, wall 590.51s. After reconciling the worktree's stale dependencies with the merged frozen lockfile, core types passed (160.66s), Gateway test types passed (55.32s), and scoped type-aware lint passed (84.11s). Line-cap, max-lines, assertion-safety, database-worker, test-timeout-race, test-mock-exports, config-docs, and plugin-inventory checks all passed. Independent Codex review of the frozen merge candidate was scoped-clean through P2.
A supplemental HTTP rerun after dependency reconciliation failed during the existing
beforeAllGateway startup hook at its 180-second deadline; all 34 cases were skipped, and teardown then encountered the uncreated server. Its wall time was 766.67s, including a cold compiled-worker rebuild. The setup/teardown path is unchanged by this PR and the conflict repair, but the local startup timeout remains unresolved; it is not represented as passing proof. No timeout increase or retry was used. Earlier live/build proof remains attached to its stated prior head. Current-headopenclaw/ci-gatepassed in run 38024880303; all 86 jobs completed successfully.