Repository navigation
refactor(ai): share Chat Completions request assembly - #140604
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. Reviewed September 7, 2026, 2:49 AM ET / 06:49 UTC. ClawSweeper reviewWhat this changesShares Chat Completions request assembly between direct provider calls and managed transports while preserving their existing request policies. Merge readiness✅ Ready for maintainer review This remains a useful maintainer-requested consolidation: current main still has separate request builders, and the reviewed patch preserves their distinct policies. No actionable correctness or security defect was found. Priority: P3 Review scores
Verification
How this fits togetherOpenClaw’s AI package converts conversation history, tools, model capabilities, and generation options into provider requests. Direct provider calls and managed transports send those requests through their existing clients and return streamed assistant output. flowchart TD
A[Conversation and tools] --> D[Shared request assembly]
B[Model and generation options] --> D
C[Direct or managed policy] --> D
D --> E[Existing provider client]
E --> F[Chat Completions endpoint]
F --> G[Streamed assistant output]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource -108, Other 0. Total -108 across 4 files. View PR surface stats
Review metricsNone. Technical reviewBest possible solution: Keep one request-assembly owner with explicit direct and managed policies, preserving payload hooks and client lifecycle boundaries. Do we have a high-confidence way to reproduce the issue? Not applicable: this PR consolidates existing code rather than reporting a failing behavior; current-main source confirms the duplicated assembly. Is this the best way to solve the issue? Yes: sharing assembly while retaining explicit policy differences removes duplication without imposing managed defaults on direct calls. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 72913f02470d. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (3 earlier review cycles) |
f8e6795 to
760b7f0
Compare
Preserve direct reasoning and managed replay, strict tools, proxy omission, and output budgeting. Integrate shared cache policies from #140781 and #140853. Apply maintainer-approved shrink-only assertion baseline maintenance: provider 9 to 6 (main already reduced 10 to 9), params 9 to 7. Proof: focused provider, transport, cache and wrapper suites pass (30 files, 575 tests), and core typecheck passes; Codex autoreview found no actionable P0-P2 issues.
760b7f0 to
4e351e7
Compare
Preserve the same empty-tool history fallback while satisfying no-lonely-if. The focused compat/tool-choice suite passes all 9 tests; Codex autoreview reports no actionable P0-P2 findings.
|
Merged via squash.
|
* refactor(ai): share Chat Completions request assembly Preserve direct reasoning and managed replay, strict tools, proxy omission, and output budgeting. Integrate shared cache policies from openclaw#140781 and openclaw#140853. Apply maintainer-approved shrink-only assertion baseline maintenance: provider 9 to 6 (main already reduced 10 to 9), params 9 to 7. Proof: focused provider, transport, cache and wrapper suites pass (30 files, 575 tests), and core typecheck passes; Codex autoreview found no actionable P0-P2 issues. * style(ai): flatten completions tool-history condition Preserve the same empty-tool history fallback while satisfying no-lonely-if. The focused compat/tool-choice suite passes all 9 tests; Codex autoreview reports no actionable P0-P2 findings.
What Problem This Solves
Chat Completions request assembly had two implementations, so fixes to shared message, response-format, tool and generation fields could drift between direct provider calls and managed transports. This is a maintainer-requested consolidation from the provider/runner de-duplication campaign.
Why This Change Was Made
Both entrypoints now use one request builder in
packages/ai/src/transports/openai-completions-params.ts, with explicit direct and managed policies. Direct reasoning/routing remains a policy helper; managed replay, strict tool shaping, proxy tool omission and context-aware output budgeting retain their existing rules. Client creation, payload hooks and stream terminal handling remain with their lifecycle owners.This incorporates the shared cache-marker owner from #140781 and the native prompt-cache capability/lifetime policy from #140853. Cache opt-outs, stable-prefix and history anchors, Model Studio tool-marker omission, string-only endpoints, and payload identity remain intact. All existing exported signatures remain available. The nearby #138329 was inspected and does not overlap this package-level change.
User Impact
No intended behavior change. Direct and managed requests retain their reasoning defaults, cache policy, tool behavior and output caps. Production code decreases by 108 lines; no tests are removed. Maintainer-approved assertion baseline maintenance only shrinks the provider count from 9 to 6 (main had already reduced 10 to 9) and params from 9 to 7.
Evidence
node scripts/run-vitest.mjs packages/ai/src/providers/openai-completions{.,-}*.test.ts packages/ai/src/transports/openai-completions-*.test.ts src/llm/providers/stream-wrappers/proxy.test.ts extensions/deepinfra/cache-wrapper.test.ts src/agents/embedded-agent-runner/extra-params.openrouter-cache-control.test.ts.pnpm buildpassed on Blacksmith Testbox in 3m24.2s. The earlier local full build also passed.tbx_01m1x95npamnzvcdhaew94ahra, Actions run, wrapper exit 0. Both OpenAI suites made real provider round-trips: direct completion with nonempty output/positive usage (571ms), plus the profile suite's prompt, file-read and image probes foropenai/gpt-5.6-luna(5.564s). Two files, 38 tests passed; two unrelated OpenRouter/Z.AI tests were deliberately excluded. No OpenAI test skipped or passed vacuously. The lease stopped successfully. A subsequent runner-portal sync warning did not affect command success.4e351e779a43e183cd037c90b5ea153b6d30137d; the only subsequent source change flattens an equivalent nestedelse/ifto satisfy lint. The initial CI lint stripe reported that one error and zero warnings; exact-head CI passed after its correction: run 34092022603, headb2d28d06ffa4a39c41efc05a5ebc153fea697755.node scripts/check-changed.mjspassed completely after the lint correction, including core/core-test typechecks, all three dead-export scans, core/script lint and every remaining guard. A direct lint-wrapper attempt hit the documented nested-worktreeDeclaration input escapes checkoutboundary. No boundary or ancestor installation was modified.The profile allowlist alone defaults to Responses, so the command uses a temporary secret-free config selecting Chat Completions at both provider and model levels. Credentials come only from the remote hydration helper. The command below is the argument to
node scripts/crabbox-wrapper.mjs run --timing-json -- bash -lc(quoted to expand$HOMEremotely):