Skip to content

fix(llama-cpp): make endpoint auth transitions reproducible - #126498

Merged
steipete merged 1 commit into
mainfrom
steipete/llama-cpp-ownership-cleanup
Aug 20, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/llama-cpp-ownership-cleanup

Conversation

@steipete

Copy link
Copy Markdown
Contributor

Related: #126434
Related: #125781
Related: #116765

What Problem This Solves

The single-provider llama.cpp architecture still carried endpoint-auth state from the implementation path that created it. Existing-server setup mixed three different facts—the credential used to probe an endpoint, the operator's intended saved auth state, and the profile action—and that made several normal transitions non-reproducible:

  • an explicitly authored replacement SecretRef could be discarded because its resolved source was env rather than flag;
  • an unchanged endpoint's existing profile could be converted and rewritten unnecessarily;
  • selecting no API key could probe successfully with a stored profile and then remove the profile that made the probe succeed.

The plugin also retained beta-only doctor compatibility and a manual live-catalog projection after core already owned those responsibilities.

Why This Change Was Made

This change gives existing-server setup one closed auth-persistence decision while carrying probe access separately. Explicitness comes from the authored setup option, replacement endpoints never receive prior endpoint credentials, unchanged configured Authorization remains authoritative, and saved profile actions now match the credentials used for validation.

The same focused cleanup removes the unshipped local://llama-cpp doctor migration, redundant unified-catalog projection, diagnostic-only discovery fields, dead managed result fields, and obsolete implementation-coupled tests. It does not add a generic provider framework or modify LM Studio, Ollama, the Plugin SDK, or system-agent persistence.

The retired local URL existed only in beta tags; no stable v* tag contains that provider implementation, so repository compatibility policy requires no retained migration.

Production LOC: +162/-300 (net -138) | Tests: +290/-296 (net -6) | Docs: +4/-2 (net +2)

AI-assisted. I reviewed the implementation and proof directly.

User Impact

Switching an existing llama-server endpoint or its authentication mode now produces a configuration that can reproduce the successful setup probe. Endpoint replacement remains fail-closed: old environment, profile, inline, and Authorization credentials never cross to the new endpoint.

Managed llama.cpp setup, downloads, local embeddings, localService ownership, router discovery, dynamic models, structured output, and custom OpenAI-compatible llama-server routes are unchanged.

Evidence

Regression and focused plugin proof:

node scripts/run-vitest.mjs extensions/llama-cpp src/plugins/doctor-contract-declarations.test.ts src/plugins/doctor-contract-closure-guard.test.ts
14 files passed; 97 tests passed

The auth-transition matrix covers changed/unchanged endpoint, explicit Authorization, plaintext key, SecretRef/ref key, stored profile, ambient environment key, and no-auth behavior.

Real llama-server proof:

Runtime: LM Studio llama.cpp backend 2.27.1
Model: Gemma 4 E4B GGUF
Endpoint: isolated llama-server with 32,768-token context

OPENCLAW_LIVE_TEST=1 LLAMA_SERVER_LIVE_TEST=1 \
LLAMA_SERVER_LIVE_URL=<isolated-test-endpoint> \
LLAMA_SERVER_LIVE_MODEL_ID=<test-model-id> \
pnpm test:live -- extensions/llama-cpp/src/external-server/llama-server.live.test.ts

3 passed: discovery/concurrent generation, schema-constrained JSON, cancellation
1 skipped: the selected model template did not advertise tool calling

Architecture and review:

node scripts/check-changed.mjs
passed on the exact rebased head with a fresh lockfile install

pnpm test:contracts:plugins
42 files passed; 1,033 tests passed

pnpm check:docs
passed formatting, Markdown lint, MDX, glossary, links, and config-example checks

Codex autoreview
clean; no accepted/actionable findings

@clawsweeper

clawsweeper Bot commented Aug 20, 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 docs Improvements or additions to documentation extensions: llama-cpp labels Aug 20, 2026
@steipete
steipete marked this pull request as ready for review August 20, 2026 01:08
@openclaw-barnacle openclaw-barnacle Bot added size: XL maintainer Maintainer-authored PR labels Aug 20, 2026
@clawsweeper clawsweeper Bot added 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. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. labels Aug 20, 2026
@clawsweeper

clawsweeper Bot commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 19, 2026, 9:12 PM ET / August 20, 2026, 01:12 UTC.

ClawSweeper review

What this changes

The PR separates llama.cpp existing-server probe access from saved authentication persistence, removes obsolete migration and catalog code, and updates tests and docs.

Regression provenance

Possible regression — suspected (reviewed change). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

Keep open for normal maintainer review. The branch fixes a concrete current-main auth-persistence defect in the llama.cpp provider; no blocking patch defect was found, but exact-head CI is still pending and the maintainer label prevents automated cleanup closure.

Priority: P2
Reviewed head: d37e50030e09c079d70837c4ba9ab93c8555c0f8

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The focused owner-boundary repair and regression matrix are sound in source review; exact-head CI remains the merge gate.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-authored/labeled PR is exempt from the external-contributor proof gate; its body nevertheless includes a redacted live llama-server run and focused transition tests.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-authored/labeled PR is exempt from the external-contributor proof gate; its body nevertheless includes a redacted live llama-server run and focused transition tests.
Evidence reviewed 6 items Current-main defect: Current main accepts a replacement key only when its resolved source is flag, so an explicitly authored SecretRef that resolves through env is discarded; the PR instead keys persistence on whether an option was authored.
Provider-owned repair: The branch makes setup compute one closed persistence state and uses it for both interactive and non-interactive config/profile writes.
Regression coverage: The focused table covers authored keys, SecretRefs, unchanged profiles, explicit Authorization, ambient keys, no-auth, and replacement endpoints.
Findings None None.
Security None None.

How this fits together

The llama.cpp plugin configures managed or existing llama-server endpoints. Its setup flow validates access, saves provider configuration and auth profiles, then feeds model discovery and routing.

flowchart LR
A[Setup input] --> B[Endpoint comparison]
B --> C[Probe credential selection]
B --> D[Persistence decision]
C --> E[Server discovery]
D --> F[Provider config and auth profile]
E --> G[Model routing]
F --> G
Loading

Before merge

  • Resolve merge risk (P1) - Exact-head CI was still in progress in the supplied context; it should complete successfully before merge because this changes persisted provider authentication behavior.
  • Complete next step (P2) - This protected maintainer PR has no mechanical repair finding; normal exact-head CI and maintainer handling remain.
Agent review details

Security

None.

PR surface

Source -138, Tests -6, Docs +2. Total -142 across 18 files.

View PR surface stats
Area Files Added Removed Net
Source 9 162 300 -138
Tests 8 290 296 -6
Docs 1 4 2 +2
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 18 456 598 -142

Review metrics

Metric Value Why it matters
Production versus test delta production net -138; tests net -6; docs net +2 The PR reduces provider and compatibility code while adding focused auth-transition coverage rather than expanding the runtime surface.

Stored data model

Persistent data-model change detected: migration/backfill/repair: extensions/llama-cpp/doctor-contract-api.test.ts, migration/backfill/repair: extensions/llama-cpp/doctor-contract-api.ts, serialized state: extensions/llama-cpp/provider-policy-api.test.ts, unknown-data-model-change: extensions/llama-cpp/doctor-contract-api.test.ts, unknown-data-model-change: extensions/llama-cpp/doctor-contract-api.ts, vector/embedding metadata: extensions/llama-cpp/provider-policy-api.test.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Verify the final upgrade matrix (recommended)
    Merge after exact-head CI confirms the unchanged-endpoint preservation and replacement-endpoint credential-clearing paths.
Copy recommended automerge instruction
@clawsweeper automerge

Special instructions:
Require exact-head CI and retain the focused auth-transition matrix.

Technical review

Best possible solution:

Retain the provider-owned closed persistence decision, preserve credentials only for an unchanged endpoint, and clear inherited credentials before probing a replacement endpoint.

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

Yes, at source level: current main's source-based key selection and profile removal are directly replaced by a closed persistence decision, with focused transition coverage. This read-only review did not execute the suite.

Is this the best way to solve the issue?

Yes: provider setup owns both validation access and durable authentication, while core already synthesizes provider catalog rows, so retaining separate transition and catalog paths would duplicate ownership.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P2: This repairs a bounded optional-provider setup and credential-persistence path.
  • add merge-risk: 🚨 compatibility: The PR changes persisted provider configuration, setup behavior, and a doctor compatibility path.
  • add merge-risk: 🚨 auth-provider: The changed flow selects, preserves, removes, and writes llama.cpp authentication profiles and Authorization headers.
  • 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: This maintainer-authored/labeled PR is exempt from the external-contributor proof gate; its body nevertheless includes a redacted live llama-server run and focused transition tests.

Label justifications:

  • P2: This repairs a bounded optional-provider setup and credential-persistence path.
  • merge-risk: 🚨 compatibility: The PR changes persisted provider configuration, setup behavior, and a doctor compatibility path.
  • merge-risk: 🚨 auth-provider: The changed flow selects, preserves, removes, and writes llama.cpp authentication profiles and Authorization headers.
  • 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: This maintainer-authored/labeled PR is exempt from the external-contributor proof gate; its body nevertheless includes a redacted live llama-server run and focused transition tests.

Evidence

What I checked:

Likely related people:

  • steipete: Authored the preceding llama.cpp single-provider refactor and this focused repair. (role: recent area contributor; confidence: high; commits: 0135046830ae, d37e50030e09; files: extensions/llama-cpp/src/external-server/setup.ts, extensions/llama-cpp/src/managed-provider.ts)
  • osolmaz: Authored the merged external llama-server feature that established this provider surface. (role: feature introducer; confidence: medium; commits: c2de3206d43a; files: extensions/llama-cpp/src/external-server/setup.ts, extensions/llama-cpp/src/external-server/provider.ts)

Rank-up moves

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

  • Wait for exact-head CI to complete successfully.

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

Land-ready proof for d37e50030e09c079d70837c4ba9ab93c8555c0f8:

  • Root cause and owner: llama.cpp existing-server setup conflated probe access with durable auth persistence. The owning provider now computes one closed preserve / upsert / remove decision and applies it consistently to the provider config and auth profile.
  • Canonical cleanup: endpoint replacement clears inherited endpoint credentials; unchanged explicit Authorization remains authoritative unless setup receives a newly authored key. The beta-only doctor migration, duplicate live-catalog projection, diagnostic/dead fields, and obsolete tests are removed.
  • Sibling/shared coverage: managed llama.cpp setup, discovery, dynamic models, structured output, local embeddings, custom OpenAI-compatible routes, LM Studio, Ollama, the Plugin SDK, and system-agent persistence are unchanged. Shared plugin doctor-contract closure and plugin contract suites passed.

Exact final commands:

node scripts/run-vitest.mjs extensions/llama-cpp src/plugins/doctor-contract-declarations.test.ts src/plugins/doctor-contract-closure-guard.test.ts
# 14 files passed; 97 tests passed

node scripts/check-changed.mjs
# passed on the exact rebased head with a fresh lockfile install

pnpm test:contracts:plugins
# 42 files passed; 1,033 tests passed

git diff --check origin/main...HEAD
# passed

pnpm check:docs
# passed formatting, Markdown lint, MDX, glossary, links, and config-example checks

No separate build was required: the final diff does not change SDK, loader, build, dynamic-import, package-manifest, or other published-package boundary surfaces.

Exact-head CI is green: run 32319913314 is attached to d37e50030e09c079d70837c4ba9ab93c8555c0f8.

ClawSweeper review: #126498 (comment). It found no actionable patch defect. Its only Rank-up move—wait for exact-head CI—has been completed; normal maintainer handling is satisfied by the authorized repo-native prepare/merge flow.

Production LOC: +162/-300 (net -138) | Tests: +290/-296 (net -6) | Docs: +4/-2 (net +2)

Real isolated llama-server proof passed discovery/concurrent generation, schema-constrained JSON, and cancellation. The tool-call case remains an explicit gap: the selected Gemma template did not advertise tool calling, so that case skipped rather than claiming unsupported proof.

@steipete
steipete merged commit 4118f31 into main Aug 20, 2026
224 checks passed
@steipete
steipete deleted the steipete/llama-cpp-ownership-cleanup branch August 20, 2026 01:37
@steipete

steipete commented Aug 20, 2026 •

Copy link
Copy Markdown
Contributor Author

Merged via squash.

Follow-up: #126574 landed in 01e888795978ede45f9cbeaf6d8bfc4bbbb9987d, eliminating the request-bridging dynamic model caches for llama.cpp, LM Studio, and local Ollama. The request lifecycle now owns the exact prepared model directly, while existing void-returning provider hooks remain compatible.

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

Labels

docs Improvements or additions to documentation extensions: llama-cpp maintainer Maintainer-authored PR merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XL 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