Skip to content

fix(agents): resolve pdf tool models through the canonical resolver - #127952

Merged
obviyus merged 1 commit into
mainfrom
t3code/pdf-tool-canonical-resolver
Aug 22, 2026
Merged

obviyus merged 1 commit into
mainfrom
t3code/pdf-tool-canonical-resolver

Conversation

@obviyus

@obviyus obviyus commented Aug 22, 2026 •

Copy link
Copy Markdown
Collaborator

What Problem This Solves

Inside a Gateway agent run, the pdf tool fails with Unknown model: <provider>/<model> for every candidate — including an explicitly configured agents.defaults.pdfModel — whenever the agent state dir has never had its model catalog materialized (fresh Docker-style deployments, hand-written openclaw.json, CI harnesses). The main turn and the image tool 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 used openai/gpt-5.6-luna successfully.

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 their ModelRegistry only from on-disk captured catalog bytes and serve configured models through the snapshot's configuredRuntimeModels prepared facts instead (src/agents/prepared-model-runtime.startup-static.test.ts pins that planOpenClawModelsJsonSource is 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 through resolveModelFromRegistry, a raw registry.find-only helper in media-tool-shared.ts with the pdf tool as its only consumer.

Fix: the pdf tool resolves each fallback candidate through resolveModelAsync with the prepared runtime's stores (same shape as the image sibling); resolveModelFromRegistry and its tests are deleted. Resolution errors still throw so the fallback loop's per-candidate attempts are 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 pdfModel pin in scripts/e2e/telegram-mantis-sut.ts stays (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 working pdf tool instead of Unknown model for every ref. No config, protocol, or schema change.

Evidence

  • Regression test src/agents/tools/pdf-tool.static-runtime.test.ts: real acquireAgentRunPreparedModelRuntime(..., { catalogMode: "static" }) on a fresh state dir with a config-inline openai/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 from origin/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.
  • Autoreview: Codex gpt-5.6-sol high, patch is correct (0.96), no findings
  • Live proof: Mantis dispatch on this PR — run 32578074819 — baseline pass at ea1cd39d (reproduces Code Mode pdf(...) Unknown model after a staged Telegram PDF), candidate pass at 2ca1a9d5 (pdf call completes; provider request carries the extracted PDF text), overall pass. CI run 32578075001 green on the exact head; ClawSweeper local review patch is correct, 0 findings.

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).
@clawsweeper

clawsweeper Bot commented Aug 22, 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 scripts Repository scripts agents Agent runtime and tooling size: M maintainer Maintainer-authored PR labels Aug 22, 2026
@obviyus
obviyus marked this pull request as ready for review August 22, 2026 14:13
@openclaw-mantis

openclaw-mantis Bot commented Aug 22, 2026 •

Copy link
Copy Markdown
Contributor

Mantis Telegram Desktop Proof

Summary: 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.

Main screenshot This PR screenshot
Baseline native Telegram Desktop screenshot Candidate native Telegram Desktop screenshot
Main This PR
Baseline native Telegram Desktop proof GIF Candidate native Telegram Desktop proof GIF

Motion-trimmed clips:

Raw QA files: https://artifacts.openclaw.ai/mantis/telegram-desktop/pr-127952/run-32578074819-1/index.json

@clawsweeper clawsweeper Bot added merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 22, 2026
@clawsweeper

clawsweeper Bot commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 22, 2026, 10:20 AM ET / 14:20 UTC.

ClawSweeper review

What this changes

The 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 provenance

Possible regression — probable (reviewed change; failure trace). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

Keep 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
Reviewed head: 2ca1a9d556731f8338f6f381cf955a132edbfd23

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The patch is a clean, net-negative production repair with a realistic static-runtime regression test; exact-head proof status remains to be checked live.
Proof confidence 🌊 off-meta tidepool Not applicable: Repository state identifies the author as a member; the supplied active Mantis job is useful supplemental evidence, but its final after-fix verdict was not available.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: Repository state identifies the author as a member; the supplied active Mantis job is useful supplemental evidence, but its final after-fix verdict was not available.
Evidence reviewed 6 items Current-main failure path: Current main passes every PDF fallback candidate to a registry-only resolver; an empty static registry therefore throws before provider dispatch.
Registry-only helper: The removed helper only normalizes the reference and calls modelRegistry.find, then throws on a miss; it has no prepared configured-model fallback.
Canonical resolver contract: The resolver first consults prepared configured runtime models and can normalize configured inline provider models before falling through to registry and static-catalog paths.
Findings None None.
Security None None.

Live Verification

Command: node scripts/run-vitest.mjs src/agents/tools/pdf-tool.static-runtime.test.ts

Result: PASS (completed)

node scripts/run-vitest.mjs src/agents/tools/pdf-tool.static-runtime.test.ts
runner@runnervm76f27:/tmp/clawsweeper-live-proof-127952-y4rrsE/target$ node scripts/run-vitest.mjs src/agents/tools/pdf-tool.static-runtime.test.ts
node scripts/run-vitest.mjs src/agents/tools/pdf-tool.static-runtime.test.ts
[test] starting test/vitest/vitest.agents-tools.config.ts

 RUN  v4.1.10 /tmp/clawsweeper-live-proof-127952-y4rrsE/target

 ✓  agents-tools  src/agents/tools/pdf-tool.static-runtime.test.ts (1 test) 4393ms
     ✓ resolves a config-inline model when the static registry is empty  4389ms

 Test Files  1 passed (1)
      Tests  1 passed (1)
   Start at  14:21:33
   Duration  18.05s (transform 11.93s, setup 1.08s, import 12.19s, tests 4.39s, environment 0ms)

[test] passed 1 Vitest shard in 24.19s
runner@runnervm76f27:/tmp/clawsweeper-live-proof-127952-y4rrsE/target$ node scripts/run-vitest.mjs src/agents/tools/pdf-tool.static-runtime.test.ts


































Assertions:

  • PASS expect_output: resolves a config-inline model when the static registry is empty

How this fits together

Gateway 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]
Loading

Before merge

  • Resolve merge risk (P1) - GitHub and Gitcrawl were unreachable during review, so maintainers should re-read the latest ClawSweeper comment and confirm the active Mantis proof plus exact-head checks before landing.
  • Resolve merge risk (P1) - Model resolution now follows the shared provider-routing path; verify both configured static facts and ordinary registry-backed candidates on the exact head.
  • Complete next step (P2) - No repair job is needed: there is no actionable patch defect, while protected maintainer handling requires live exact-head validation.
Agent review details

Security

None.

PR surface

Source +3, Tests +64, Other 0. Total +67 across 8 files.

View PR surface stats
Area Files Added Removed Net
Source 3 38 35 +3
Tests 3 134 70 +64
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 2 3 3 0
Total 8 175 108 +67

Review metrics

Metric Value Why it matters
Production vs test LOC production +16/-33 (net -17); tests and test support +156/-72 (net +84) The bug fix removes the registry-only production path while adding focused owner-boundary coverage.

Root-cause cluster

Relationship: canonical
Canonical: #127952
Summary: This PR addresses the product resolver defect; the earlier merged harness pin only overlaps by preventing the same symptom in Mantis fixtures.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge-risk options

Maintainer options:

  1. Verify both resolver sources before merge (recommended)
    Confirm the active proof and exact-head checks cover a fresh static configured model as well as the established registry-backed PDF path.
Copy recommended automerge instruction
@clawsweeper automerge

Special instructions:
Confirm the active Mantis proof and exact-head checks cover static configured and registry-backed PDF model resolution before merge.

Technical review

Best 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.

Labels

Label changes:

  • add P1: A fresh gateway can fail every PDF model candidate despite a configured working model, breaking an agent tool workflow.
  • add merge-risk: 🚨 auth-provider: The patch changes the PDF tool's provider/model routing and runtime auth-store source from a registry-only lookup to canonical resolution.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: Repository state identifies the author as a member; the supplied active Mantis job is useful supplemental evidence, but its final after-fix verdict was not available.

Label justifications:

  • P1: A fresh gateway can fail every PDF model candidate despite a configured working model, breaking an agent tool workflow.
  • merge-risk: 🚨 auth-provider: The patch changes the PDF tool's provider/model routing and runtime auth-store source from a registry-only lookup to canonical resolution.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: Repository state identifies the author as a member; the supplied active Mantis job is useful supplemental evidence, but its final after-fix verdict was not available.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Git blame attributes the registry-only PDF resolution and helper to this current-main commit. (role: current-source author; confidence: high; commits: 1bd5f22b1341; files: src/agents/tools/pdf-tool.ts, src/agents/tools/media-tool-shared.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Attach or confirm the final redacted Mantis verdict for the exact PR head before merge.

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.

@obviyus
obviyus merged commit 71b5de4 into main Aug 22, 2026
310 checks passed
@obviyus
obviyus deleted the t3code/pdf-tool-canonical-resolver branch August 22, 2026 14:32
obviyus added a commit that referenced this pull request Aug 22, 2026
… 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.
obviyus added a commit that referenced this pull request Aug 22, 2026
… 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.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 23, 2026
…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).
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 23, 2026
… 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling maintainer Maintainer-authored PR merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. scripts Repository scripts 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