Skip to content

refactor(media): consolidate automatic provider selection - #131534

Merged
steipete merged 1 commit into
mainfrom
codex/cleanup20k-media-selection-owner-20260828
Aug 28, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/cleanup20k-media-selection-owner-20260828

Conversation

@steipete

@steipete steipete commented Aug 28, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Media auto-selection duplicated its provider priority/default-model policy between the configuration defaults and the runtime runner. Active-model selection and API-key selection also repeated the same eligibility, authentication, and model-resolution flow. Those copies made behavior-preserving maintenance unnecessarily error-prone.

Why This Change Was Made

The existing provider registry becomes the single owner of registry-only priority and default-model lookup. The runner shares its provider eligibility/authentication/model-selection flow; configuration and manifest caching remain in the defaults owner. No new abstraction layer, dependency, configuration key, protocol, schema version, or public SDK export is introduced.

The two callers deliberately retain different timing and identity contracts: active selection normalizes its execution provider and reads the model after authentication; key selection retains its trimmed provider identity and captures its model before authentication. Audio still uses its provider default rather than the chat model, and the final key-provider pass after unavailable local audio remains intact.

Production LOC: +80/-149 (net -69). Preservation tests: +250/-0. Pure moves cancel in that count.

User Impact

No intended user-visible change. Existing media selection, configured-image insertion, regional provider aliases, priority ordering, native-vision bypass, authentication, and operator output are preserved. This is an internal cleanup; no changelog entry is needed.

Evidence

  • Fresh Linux Node 24.19.0 / pinned pnpm 11.22.0, with independent frozen dependency installs for the original production code and the candidate. The same preservation tests passed 88/88 on each side, including active/key model-read timing and audio's final key pass.
  • Complete candidate 28-stage changed-file gate, SDK exports/surface checks, and both normal 15-stage builds passed. No checks were disabled. All 34,436 source entries were checked before and after each command.
  • Actual built audio/video CLI and public image SDK calls exercised automatic model selection, real WAV/MP4/PNG transport, streamed responses, and operator-visible output against owned loopback HTTP endpoints. Parsed requests and results matched between baseline and candidate. This is not external-provider availability or semantic speech/vision-recognition proof.
  • An independently authored source-blind validator passed all 12 contract outcomes across both builds, including fresh response markers and invalid-model rejection before any HTTP request.
  • Both public runtime export lists matched. All 69 reachable emitted declaration files were byte-identical; a separate TypeScript AST walk verified the complete local import closure.
  • Clean-machine proof run. The owned proof trees and process groups were removed, the lease reports completed, and its local connection/key/claim files are absent. Full logs and the hash-bound 172-file evidence collection are retained locally.
  • Exact-head CI completed successfully for 9aeedbac84660851602d233b7af1a0233603957f: 161 passed jobs, 18 intentional skips, required openclaw/ci-gate passed. All three pre-commit Codex review passes and all three separate published-head passes finished with no actionable findings. Source, index, patch and review-runtime cleanup were independently checked.

The first environment attempt lacked FFmpeg; installation and a separately recorded rerun resolved it without changing product source. The first independent validator misparsed ordinary SDK diagnostic stdout; only its own result framing was corrected before the successful run. Both failed attempts remain recorded as failures. Existing dependency build warnings were not suppressed.

Current-main composition through 7573b91727c8f9acb0c1ee611749698b92181436 is conflict-free and retains the exact five-file patch and afterimages. Native preparation, merge and actual-squash/ancestry verification remain separate steps; this text does not claim the PR is merged.

Named Follow-ups

The existing auto-audio test titled “prefers provider keys over auto-detected local whisper” sets its mock-binary PATH outside a fixture that clears PATH. It does not actually prove a competing local binary is available; fixing that fixture and asserting discoverability is separate follow-up work. The new final-key-pass case tests unavailable local audio and makes no competing-binary claim. A private single-caller forwarding helper in runner.entries.ts can also be removed separately. Neither is included in this change's line count.

@clawsweeper

clawsweeper Bot commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@openclaw-barnacle openclaw-barnacle Bot added size: M maintainer Maintainer-authored PR labels Aug 28, 2026
@steipete
steipete marked this pull request as ready for review August 28, 2026 04:40
@clawsweeper clawsweeper Bot added P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 28, 2026
@clawsweeper

clawsweeper Bot commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 28, 2026, 12:48 AM ET / 04:48 UTC.

ClawSweeper review

What this changes

The PR moves automatic media-provider default-model and priority lookup into the provider registry and shares the runner’s provider-selection path while adding preservation coverage.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

Keep open. This member-authored, maintainer-labeled PR is a focused, net-negative refactor; no introduced correctness or security defect was found, and the exact-head check rollup is still incomplete.

Priority: P3
Reviewed head: 9aeedbac84660851602d233b7af1a0233603957f

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) PR readiness rating was derived from proof quality, review findings, security review, and reviewer confidence.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): ClawSweeper live verification passed on the reviewed terminal surface.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): ClawSweeper live verification passed on the reviewed terminal surface.
Evidence reviewed 6 items Registry-only policy is centralized: The introduced helpers retain normalized default-model lookup and capability/finite-priority ordering in the registry owner.
Runner retains distinct active and key selection contracts: Key selection captures its supplied model before authentication, while active selection supplies a deferred model read; the shared helper preserves audio’s provider-default behavior.
Production entry point and sibling caller inspected: The attachment pipeline builds one provider registry and supplies it to every capability run; the audio-preflight caller reaches the same runner through the transcription wrapper.
Findings None None.
Security None None.

Live Verification

Command: pnpm openclaw --help

Result: PASS (completed)

  security *           Audit local config and state for common security foot-guns
  sessions *           List stored conversation sessions
  setup                Chat with OpenClaw; onboard when setup is incomplete
  skills *             List and inspect available skills
  status               Show channel health and recent session recipients
  system *             System tools (events, heartbeat, presence)
  tasks *              Inspect durable background tasks and TaskFlow state
  telemetry *          Inspect and manage anonymous usage telemetry
  terminal             Open a local terminal UI (alias for tui --local)
  transcripts *        Inspect stored transcripts
  triage               Collect sanitized diagnostics and prepare an agent debugging handoff
  tui                  Open a terminal UI connected to the Gateway
  uninstall            Uninstall the gateway service + local data (CLI remains)
  update *             Update OpenClaw and inspect update channel status
  users *              Manage durable user profiles and email aliases
  webhooks *           Webhook helpers and integrations
  worker               Run the restricted cloud worker runtime
  worktrees *          Create, inspect, restore, and clean up managed worktrees

Examples:
  openclaw onboard
    Run guided setup for a local Gateway, workspace, auth, and channels.
  openclaw setup
    Create the baseline config, workspace, and session folders.
  openclaw configure
    Change models, Gateway, channels, plugins, skills, and health checks.
  openclaw status
    Check Gateway, channel, model, and recent-session status.
  openclaw doctor --fix
    Repair common config, service, plugin, and channel problems.
  openclaw channels add
    Add or update a chat channel account with guided prompts.
  openclaw channels status
    See connected messaging accounts and login state.
  openclaw --dev gateway
    Run a dev Gateway (isolated state/config) on ws://127.0.0.1:19001.
  openclaw gateway run --force
    Start the Gateway and replace anything bound to its port.
  openclaw models status
    Show model/provider auth health before running agents.
  openclaw plugins list
    Inspect enabled, disabled, and installed plugins.
  openclaw agent --to +15555550123 --message "Run summary" --deliver
    Run one agent turn through the Gateway and optionally deliver the reply.
  openclaw message send --channel telegram --target @mychat --message "Hi"
    Send via your Telegram bot.

Docs: docs.openclaw.ai/cli


Assertions:

  • PASS expect_output: Usage: openclaw [options] [command]

How this fits together

Media understanding selects an authenticated provider and model for image, audio, and video attachments before dispatching to the provider runtime and returning structured output to the agent. The registry supplies provider capabilities, default models, and automatic-selection priority.

flowchart LR
  A[Media attachments] --> B[Automatic media selection]
  C[Active model or configured keys] --> B
  D[Provider registry metadata] --> B
  B --> E[Provider authentication]
  E --> F[Media provider runtime]
  F --> G[Structured media output]
Loading

Before merge

  • Resolve merge risk (P1) - Exact-head GitHub checks are still in progress, so merge readiness cannot yet be established.
  • Complete next step (P2) - No repair lane is needed: no actionable finding was identified, and normal maintainer handling should await exact-head checks.
Agent review details

Security

None.

PR surface

Source -69, Tests +250. Total +181 across 5 files.

View PR surface stats
Area Files Added Removed Net
Source 3 80 149 -69
Tests 2 250 0 +250
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 330 149 +181

Review metrics

Metric Value Why it matters
Production versus test LOC production -69, tests +250 The refactor removes duplicated production selection logic while adding focused preservation coverage.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Retain the single registry-owned lookup policy and land only after the exact PR-head checks complete successfully.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Retain the single registry-owned lookup policy and land only after the exact PR-head checks complete successfully.

Do we have a high-confidence way to reproduce the issue?

Not applicable: this PR refactors existing selection behavior rather than reporting a user-facing failure.

Is this the best way to solve the issue?

Yes. The registry already owns provider metadata, so moving pure default and priority lookup there removes duplicate policy without changing configuration or plugin contracts.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against cd7b282ed8c5.

Labels

Label changes:

  • add P3: This is a behavior-preserving internal cleanup with no reported user-facing regression.
  • add proof: sufficient: Contributor real behavior proof is sufficient. ClawSweeper live verification passed on the reviewed terminal surface.
  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): ClawSweeper live verification passed on the reviewed terminal surface.

Label justifications:

  • P3: This is a behavior-preserving internal cleanup with no reported user-facing regression.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): ClawSweeper live verification passed on the reviewed terminal surface.
  • proof: sufficient: Contributor real behavior proof is sufficient. ClawSweeper live verification passed on the reviewed terminal surface.

Evidence

What I checked:

  • Registry-only policy is centralized: The introduced helpers retain normalized default-model lookup and capability/finite-priority ordering in the registry owner. (src/media-understanding/provider-registry.ts:10, 9aeedbac8466)
  • Runner retains distinct active and key selection contracts: Key selection captures its supplied model before authentication, while active selection supplies a deferred model read; the shared helper preserves audio’s provider-default behavior. (src/media-understanding/runner.ts:338, 9aeedbac8466)
  • Production entry point and sibling caller inspected: The attachment pipeline builds one provider registry and supplies it to every capability run; the audio-preflight caller reaches the same runner through the transcription wrapper. (src/media-understanding/apply.ts:465, 9aeedbac8466)
  • Focused preservation coverage: New tests cover image/video timing, provider identity, audio’s default model, and the final post-local-audio key pass; existing tests cover provider-key precedence over local Whisper discovery. (src/media-understanding/runner.auto-selection.test.ts:47, 9aeedbac8466)
  • Current-main comparison: The fetched current-main revision does not contain this refactor; the verified comparison identifies these five media-understanding files as the branch delta, so the PR remains necessary rather than implemented elsewhere. (cd7b282ed8c5)
  • Feature-history provenance: The pre-refactor selection path is attributed to Paul Campbell in the available base history; the introduced shared selection helper is attributed to the current PR commit. (src/media-understanding/runner.ts:576, 4b6ee77b3b2f)

Likely related people:

  • Paul Campbell: Available blame attributes the existing runner selection path to this contributor before the PR’s consolidation. (role: recent area contributor; confidence: medium; commits: 4b6ee77b3b2f; files: src/media-understanding/runner.ts, src/media-understanding/provider-registry.ts)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
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.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@steipete

Copy link
Copy Markdown
Contributor Author

The cleanup is ready for native preparation at 9aeedbac84660851602d233b7af1a0233603957f: the separate published-head Codex review completed with no actionable findings, and exact-head CI finished successfully (161 passed jobs, 18 intentional skips; required openclaw/ci-gate passed).

The latest ClawSweeper review found no defect and left two pre-merge items: finish exact-head checks and complete maintainer handling. The checks are now green and the independent maintainer review is complete. One evidence qualification: the older Whisper test does not establish executable competition because its fixture clears PATH; the PR body already records that gap. Our proof does not rely on that stronger interpretation.

The registry owns priority/default lookup; the runner shares eligibility/authentication/model selection without changing active/key provider identity, model-read timing, configured image precedence, audio defaults, or local-audio fallback ordering. Production is +80/-149, net 69 lines removed; preservation tests are +250/-0. No public SDK, configuration, protocol, storage or dependency contract changes.

Verification used fresh independent baseline/candidate installs on Linux Node24.19.0 and pnpm11.22.0 in clean-machine run33138443444. Actual source commands included:

node scripts/run-vitest.mjs src/media-understanding/defaults.test.ts src/media-understanding/runner.auto-selection.test.ts src/media-understanding/provider-registry.test.ts src/media-understanding/runner.auto-audio.test.ts src/media-understanding/runner.vision-skip.test.ts src/media-understanding/runner.video.test.ts --maxWorkers=2 --reporter=default --reporter=json --outputFile=<owned-evidence>/vitest.json
node scripts/check-changed.mjs --timed --base origin/main --staged
pnpm plugin-sdk:check-exports
pnpm plugin-sdk:surface:check
pnpm build

Both sides passed88/88 preservation tests and all15 normal build stages; candidate passed all28 changed-file stages and both SDK guards. Real built audio/video CLI and public image SDK calls preserved parsed requests and fresh outputs. An independent source-blind validator passed12 outcomes, and all69 reachable emitted declarations were byte-identical with separately checked AST import closure. Owned processes, proof trees and lease were cleaned up. The five-file patch also composes unchanged with current main through7573b91727c8f9acb0c1ee611749698b92181436.

Proof limits remain explicit: owned loopback endpoints prove routing/transport/output, not external-provider availability or recognition quality. The initial missing-FFmpeg attempt and initial validator-stdout framing failure are retained as failed attempts; their separate corrections did not alter product source. The older competing-Whisper PATH fixture weakness and single-caller private forwarder remain named follow-ups in the PR body. No merge is claimed yet.

@steipete
steipete merged commit 68574fe into main Aug 28, 2026
313 checks passed
@steipete
steipete deleted the codex/cleanup20k-media-selection-owner-20260828 branch August 28, 2026 05:11
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer Maintainer-authored PR P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant