Repository navigation
fix(agents): resolve pdf tool models through the canonical resolver - #127952
Conversation
Inside gateway runs the prepared model runtime is a static snapshot whose ModelRegistry is empty on a fresh state dir; configured models are served through the snapshot's prepared facts. The pdf tool resolved candidates via the registry-only resolveModelFromRegistry helper, so every fallback candidate failed with `Unknown model` while the main turn and image tool (already on resolveModelAsync) worked. Resolve each pdf candidate through resolveModelAsync with the prepared stores, matching the image sibling, and delete the registry-only helper. Adds a regression test that acquires a real static prepared runtime on a fresh state dir with a config-inline model. Observed live: Mantis run 32574012855 (both lanes died in the pdf bridge).
|
🦞👀 Pull request received. I will update this pull request when review starts. |
Mantis Telegram Desktop ProofSummary: Native Telegram Desktop proof for PDF tool model resolution: baseline reproduces Code Mode pdf(...) Unknown model failure; candidate dispatches the PDF model call with extracted PDF text and completes without Unknown model.
Motion-trimmed clips: |
|
Codex review: needs maintainer review before merge. Reviewed August 22, 2026, 10:20 AM ET / 14:20 UTC. ClawSweeper reviewWhat this changesThe PR makes the PDF tool resolve configured models through the prepared-runtime canonical resolver instead of a registry-only lookup, with static-runtime regression coverage. Regression provenancePossible regression — probable (reviewed change; failure trace). No predecessor PR is attributed. Merge readinessKeep open. The patch is a focused root-cause repair with no blocking source finding; a live exact-head read is still needed to confirm the active proof, remaining checks, and latest ClawSweeper rank-up guidance before landing. Priority: P1 Review scores
Verification
Live VerificationCommand: Result: PASS (completed) Assertions:
How this fits togetherGateway and embedded agent runs prepare model facts for tools. The PDF tool uses those facts to choose a model before sending extracted document content to the provider. flowchart LR
A[Gateway agent run] --> B[Static prepared runtime]
B --> C[PDF tool]
C --> D[Canonical model resolver]
D --> E[Provider request]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +3, Tests +64, Other 0. Total +67 across 8 files. View PR surface stats
Review metrics
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: Keep the single canonical resolver path, retain the fresh static-runtime regression, and land only after exact-head proof confirms both static configured and ordinary catalog-backed PDF resolution. Do we have a high-confidence way to reproduce the issue? Yes, by source: a static prepared runtime can contain configured model facts while its registry is empty, and the added regression test constructs that exact path; it was not executed in this read-only review. Is this the best way to solve the issue? Yes. Reusing the existing prepared-runtime resolver removes the lone registry-only PDF path rather than adding a PDF-specific fallback. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against ea1cd39d6c9a. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
… head The Telegram Desktop proof previously built the candidate from the raw PR head, so a head behind main failed for reasons main already fixed (observed on #127770: 59 commits behind, hitting the Unknown-model defect fixed by #127952). GitHub's cached PR test merge cannot be the candidate either: it was observed 50 commits / 12 hours stale and never refreshed. The workflow now resolves the live refs/heads/main tip and merge base at dispatch, requires a main-targeting PR, and builds a deterministic local merge (merge-tree --merge-base + commit-tree with pinned identity/date) as the candidate; conflicts fail with a direct rebase message and there is no fallback to the raw head. Lane labels and docs now say the candidate is the PR merged onto main.
… head (#127961) The Telegram Desktop proof previously built the candidate from the raw PR head, so a head behind main failed for reasons main already fixed (observed on #127770: 59 commits behind, hitting the Unknown-model defect fixed by #127952). GitHub's cached PR test merge cannot be the candidate either: it was observed 50 commits / 12 hours stale and never refreshed. The workflow now resolves the live refs/heads/main tip and merge base at dispatch, requires a main-targeting PR, and builds a deterministic local merge (merge-tree --merge-base + commit-tree with pinned identity/date) as the candidate; conflicts fail with a direct rebase message and there is no fallback to the raw head. Lane labels and docs now say the candidate is the PR merged onto main.
…penclaw#127952) Inside gateway runs the prepared model runtime is a static snapshot whose ModelRegistry is empty on a fresh state dir; configured models are served through the snapshot's prepared facts. The pdf tool resolved candidates via the registry-only resolveModelFromRegistry helper, so every fallback candidate failed with `Unknown model` while the main turn and image tool (already on resolveModelAsync) worked. Resolve each pdf candidate through resolveModelAsync with the prepared stores, matching the image sibling, and delete the registry-only helper. Adds a regression test that acquires a real static prepared runtime on a fresh state dir with a config-inline model. Observed live: Mantis run 32574012855 (both lanes died in the pdf bridge).
… head (openclaw#127961) The Telegram Desktop proof previously built the candidate from the raw PR head, so a head behind main failed for reasons main already fixed (observed on openclaw#127770: 59 commits behind, hitting the Unknown-model defect fixed by openclaw#127952). GitHub's cached PR test merge cannot be the candidate either: it was observed 50 commits / 12 hours stale and never refreshed. The workflow now resolves the live refs/heads/main tip and merge base at dispatch, requires a main-targeting PR, and builds a deterministic local merge (merge-tree --merge-base + commit-tree with pinned identity/date) as the candidate; conflicts fail with a direct rebase message and there is no fallback to the raw head. Lane labels and docs now say the candidate is the PR merged onto main.




What Problem This Solves
Inside a Gateway agent run, the
pdftool fails withUnknown model: <provider>/<model>for every candidate — including an explicitly configuredagents.defaults.pdfModel— whenever the agent state dir has never had its model catalog materialized (fresh Docker-style deployments, hand-writtenopenclaw.json, CI harnesses). The main turn and theimagetool resolve the same model fine.Observed live in Mantis run 32574012855: both lanes died in the pdf tool bridge with
Unknown model: openai/gpt-5.6-luna(then sol / gpt-5.5 fallback candidates) while the same turn's main dispatch usedopenai/gpt-5.6-lunasuccessfully.Why This Change Was Made
Gateway/embedded runs publish prepared model runtimes with
catalogMode: "static"(src/gateway/server-startup-post-attach.ts,src/agents/embedded-agent-runner/run-orchestrator.ts). By design, static snapshots build theirModelRegistryonly from on-disk captured catalog bytes and serve configured models through the snapshot'sconfiguredRuntimeModelsprepared facts instead (src/agents/prepared-model-runtime.startup-static.test.tspins thatplanOpenClawModelsJsonSourceis never called on that path). On a fresh state dir that registry is empty.The canonical resolver
resolveModelAsync(src/agents/embedded-agent-runner/model.ts) consults the registry,configuredRuntimeModels, inline provider models, and the bundled static catalog in order — and the image media path already uses it with the prepared stores (src/media-understanding/image-model-runtime.ts). The pdf tool was the lone sibling resolving throughresolveModelFromRegistry, a rawregistry.find-only helper inmedia-tool-shared.tswith the pdf tool as its only consumer.Fix: the pdf tool resolves each fallback candidate through
resolveModelAsyncwith the prepared runtime's stores (same shape as the image sibling);resolveModelFromRegistryand its tests are deleted. Resolution errors still throw so the fallback loop's per-candidateattemptsare preserved. Production LOC: net −14 (pdf-tool.ts+16/−8,media-tool-shared.ts−25 after dropping an unneeded cast).Also corrects the harness comment from #127882: the
pdfModelpin inscripts/e2e/telegram-mantis-sut.tsstays (it keeps the pdf tool on the one catalog model instead of walking fallback candidates), but its stated reason ("auto-resolution picks gpt-5.5") was this bug's symptom, not its cause.User Impact
Operators running a gateway on a state dir that never went through a catalog-materializing flow (onboarding,
openclaw models, any live-mode CLI path) get a workingpdftool instead ofUnknown modelfor every ref. No config, protocol, or schema change.Evidence
src/agents/tools/pdf-tool.static-runtime.test.ts: realacquireAgentRunPreparedModelRuntime(..., { catalogMode: "static" })on a fresh state dir with a config-inlineopenai/gpt-5.6-luna; asserts the static registry is empty, the configured facts carry the model, and the pdf tool resolves and dispatches it. Pre-fix (production files fromorigin/main):FailoverError: Unknown model: openai/gpt-5.6-luna. Post-fix: passes.node scripts/run-vitest.mjs src/agents/tools/pdf-tool.test.ts src/agents/tools/pdf-tool.model-catalog.test.ts src/agents/tools/pdf-tool.runtime-abort.test.ts src/agents/tools/pdf-tool.helpers.test.ts src/agents/tools/media-tool-shared.test.ts src/agents/tools/pdf-tool.static-runtime.test.ts— 2 shards, 6 files / 83 tests passed (exit 0)node scripts/check-changed.mjs -- <changed files>— all lanes ok (oxfmt, oxlint, SAFETY ratchet shrink-only prune, dead-export scan, typecheck core + core tests + scripts)node scripts/run-tsgo.mjs -p tsconfig.core.json— pass.patch is correct(0.96), no findingspassatea1cd39d(reproduces Code Modepdf(...)Unknown modelafter a staged Telegram PDF), candidatepassat2ca1a9d5(pdf call completes; provider request carries the extracted PDF text), overallpass. CI run 32578075001 green on the exact head; ClawSweeper local reviewpatch is correct, 0 findings.