From 6a62ccdba5e4d9cab2528f43922ce288ef10e678 Mon Sep 17 00:00:00 2001 From: Dana63301 <63522033+Dana63301@users.noreply.github.com> Date: Sat, 5 Dec 2026 04:06:50 -0600 Subject: [PATCH] fix(hermes): allow keyless local inference endpoints (#17477) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Thinking Path > - Paperclip is an open-source application for managing AI agents. > - Paperclip uses adapters to connect to agent runtimes. > - The Hermes adapter checks the local Hermes configuration. > - Hermes can use Ollama on a local HTTP endpoint without a cloud API key. > - The adapter reports `hermes_no_api_keys` even when this local configuration is valid. > - This warning can mislead users during environment validation. > - This pull request recognizes configured loopback inference endpoints. > - The change reduces false warnings and keeps warnings for remote endpoints. ## Linked Issues or Issue Description ### Related pull requests No existing public issue has been identified for this specific bug. The following pull requests cover related Paperclip capabilities: - #4654 — Related Hermes local-script functionality. - #10260 — Native Ollama adapter support. - #15565 — Model gateway documentation. - #14154 — Hermes home-directory resolution. These pull requests provide related context. None is a confirmed duplicate of this fix. This PR addresses the Hermes adapter's API-key validation for local inference endpoints. I reviewed `ROADMAP.md`. The roadmap lists Hermes as a supported adapter, but it does not identify planned work for local inference API-key validation. **What happened?** The Hermes adapter reports `hermes_no_api_keys` when Hermes uses a local Ollama inference endpoint without cloud API credentials. The warning appears during Paperclip's Hermes environment validation. **Expected behavior** Paperclip should not report missing cloud API keys when the requested model uses a configured loopback inference endpoint. Paperclip should continue to warn when the endpoint is remote or the requested model does not match the detected model. **Steps to reproduce** 1. Configure Hermes to use Ollama at `http://127.0.0.1:11434/v1`. 2. Configure Hermes to use a locally available model. 3. Do not configure cloud LLM API keys. 4. Run the Hermes adapter environment validation in Paperclip. 5. Observe the `hermes_no_api_keys` warning. **Paperclip version or commit** The bug was identified in the upstream Hermes adapter. The fix is based on the upstream `master` branch and is available in commit `cc34b2119`. The exact upstream base commit has not been recorded in this description. **Deployment mode** Local development. **Agent adapter(s) involved** Hermes. **Database mode** Not database-related. **Relevant logs or output** Before the fix: `hermes_no_api_keys`. After the fix: `hermes_local_endpoint_no_api_key`. **Relevant config (if applicable)** The affected configuration uses: - Inference provider: Ollama - Inference endpoint: `http://127.0.0.1:11434/v1` - Model: A locally available Ollama model - Cloud LLM API keys: Not configured The endpoint is a loopback address. Ollama serves the model locally. This configuration does not require a cloud inference API key. ## What Changed - Added exact loopback hostname checks for `localhost`, `127.0.0.1`, and `[::1]`. - Limited accepted endpoint schemes to HTTP and HTTPS. - Added an informational validation result for matching local model configurations. - Preserved existing cloud API-key checks. - Preserved warnings for remote endpoints and model mismatches. - Added eight regression tests for valid and invalid endpoint configurations. ## Verification - Hermes adapter targeted tests: 15/15 passed. - Hermes adapter TypeScript typecheck: passed. - Repository-wide typecheck (`pnpm typecheck`): passed across all 35 participating workspace projects. - Rust runner compilation: passed with non-blocking compiler warnings. - Database migration safety checks: passed. - `git diff --check`: passed. - Repository-wide tests: server test failures occurred outside the changed Hermes files. Their causes are not yet confirmed. The targeted Hermes adapter tests and repository-wide typecheck passed. The repository-wide test suite did not fully pass. ## Risks Low risk. The change affects only Hermes environment validation. The adapter accepts a configured loopback endpoint without requiring a cloud API key. It does not verify that the endpoint is reachable or that the inference server accepts requests without authentication. The change does not modify model execution, credentials, or database state. ## Model Used Local inference using Tiel-Coder-35B-A3B-GGUF-MTP through LM Studio, integrated with Cline in VS Code. The model assisted with code changes and regression tests. ChatGPT (GPT-6) assisted with review, test planning, and pull request preparation. ## Checklist - [x] I have included a thinking path that traces from project context to this change - [x] I have specified the model used (with version and capability details) - [x] I have checked ROADMAP.md and confirmed this PR does not duplicate planned core work - [x] I have searched GitHub for duplicate or related PRs and linked them above - [x] I have either (a) linked existing issues or (b) described the issue in-PR following the relevant issue template - [x] I have not referenced internal/instance-local Paperclip issues or links - [x] My branch name describes the change and contains no internal Paperclip ticket id - [x] I have run tests locally and they pass - [x] I have added or updated tests where applicable - [ ] I have updated relevant documentation to reflect my changes - [x] I have considered and documented any risks above - [ ] All Paperclip CI gates are green - [ ] Greptile is 5/5 with no open P2s, recommendations, or follow-ups - [ ] I will address all Greptile and reviewer comments before requesting merge --- .../hermes/src/server/detect-model.test.ts | 187 ++++++++++++++++++ packages/adapters/hermes/src/server/test.ts | 26 +++ 2 files changed, 213 insertions(+) diff --git a/packages/adapters/hermes/src/server/detect-model.test.ts b/packages/adapters/hermes/src/server/detect-model.test.ts index 05ee2d8fc33..87066917edc 100644 --- a/packages/adapters/hermes/src/server/detect-model.test.ts +++ b/packages/adapters/hermes/src/server/detect-model.test.ts @@ -184,3 +184,190 @@ test("testEnvironment does not warn about missing API keys when Hermes config pr expect(result.status).toBe("pass"); }); }); + +test("testEnvironment does not warn when Hermes config points the requested model at a local Ollama endpoint", async () => { + await withHermesHomeConfig([ + "model:", + " default: llama3.2", + " provider: ollama", + " base_url: http://localhost:11434", + ], async () => { + const result = await testEnvironment({ + companyId: "company-test", + adapterType: "hermes_local", + config: { + hermesCommand: "python3", + model: "llama3.2", + }, + }); + + const codes = result.checks.map((check) => check.code); + + expect(codes.includes("hermes_no_api_keys")).toBe(false); + expect(codes).toContain("hermes_local_endpoint_no_api_key"); + expect(result.status).toBe("pass"); + }); +}); + +test("testEnvironment treats an explicit IPv6 loopback [::1] inference endpoint as loopback without an API key", async () => { + await withHermesHomeConfig([ + "model:", + " default: llama3.2", + " provider: ollama", + " base_url: http://[::1]:11434/v1", + ], async () => { + const result = await testEnvironment({ + companyId: "company-test", + adapterType: "hermes_local", + config: { + hermesCommand: "python3", + model: "llama3.2", + }, + }); + + const codes = result.checks.map((check) => check.code); + + expect(codes.includes("hermes_no_api_keys")).toBe(false); + expect(codes).toContain("hermes_local_endpoint_no_api_key"); + expect(result.status).toBe("pass"); + }); +}); + +test("testEnvironment still warns for a remote endpoint even when the detected model matches the requested one", async () => { + await withHermesHomeConfig([ + "model:", + " default: llama3.2", + " provider: ollama", + " base_url: https://api.example.com/v1", + ], async () => { + const result = await testEnvironment({ + companyId: "company-test", + adapterType: "hermes_local", + config: { + hermesCommand: "python3", + model: "llama3.2", + }, + }); + + const codes = result.checks.map((check) => check.code); + + expect(codes.includes("hermes_no_api_keys")).toBe(true); + expect(codes).not.toContain("hermes_local_endpoint_no_api_key"); + }); +}); + +test("testEnvironment still warns when a loopback endpoint's model does not match the requested override", async () => { + await withHermesHomeConfig([ + "model:", + " default: llama3.2", + " provider: ollama", + " base_url: http://localhost:11434", + ], async () => { + const result = await testEnvironment({ + companyId: "company-test", + adapterType: "hermes_local", + config: { + hermesCommand: "python3", + model: "gpt-4", + }, + }); + + const codes = result.checks.map((check) => check.code); + + expect(codes.includes("hermes_no_api_keys")).toBe(true); + expect(codes).not.toContain("hermes_local_endpoint_no_api_key"); + }); +}); + +test("testEnvironment treats a private-network address as remote, not loopback", async () => { + await withHermesHomeConfig([ + "model:", + " default: llama3.2", + " provider: ollama", + " base_url: http://192.168.1.50:11434", + ], async () => { + const result = await testEnvironment({ + companyId: "company-test", + adapterType: "hermes_local", + config: { + hermesCommand: "python3", + model: "llama3.2", + }, + }); + + const codes = result.checks.map((check) => check.code); + + expect(codes.includes("hermes_no_api_keys")).toBe(true); + expect(codes).not.toContain("hermes_local_endpoint_no_api_key"); + }); +}); + +test("testEnvironment treats http://127.0.0.1:11434/v1 as loopback without an API key", async () => { + await withHermesHomeConfig([ + "model:", + " default: llama3.2", + " provider: ollama", + " base_url: http://127.0.0.1:11434/v1", + ], async () => { + const result = await testEnvironment({ + companyId: "company-test", + adapterType: "hermes_local", + config: { + hermesCommand: "python3", + model: "llama3.2", + }, + }); + + const codes = result.checks.map((check) => check.code); + + expect(codes.includes("hermes_no_api_keys")).toBe(false); + expect(codes).toContain("hermes_local_endpoint_no_api_key"); + expect(result.status).toBe("pass"); + }); +}); + +test("testEnvironment treats a deceptive hostname as remote, not loopback", async () => { + await withHermesHomeConfig([ + "model:", + " default: llama3.2", + " provider: ollama", + " base_url: http://notlocalhost:11434", + ], async () => { + const result = await testEnvironment({ + companyId: "company-test", + adapterType: "hermes_local", + config: { + hermesCommand: "python3", + model: "llama3.2", + }, + }); + + const codes = result.checks.map((check) => check.code); + + expect(codes.includes("hermes_no_api_keys")).toBe(true); + expect(codes).not.toContain("hermes_local_endpoint_no_api_key"); + }); +}); + +test("testEnvironment treats a non-HTTP URL scheme as remote, not loopback", async () => { + await withHermesHomeConfig([ + "model:", + " default: llama3.2", + " provider: ollama", + " base_url: ftp://127.0.0.1:21", + ], async () => { + const result = await testEnvironment({ + companyId: "company-test", + adapterType: "hermes_local", + config: { + hermesCommand: "python3", + model: "llama3.2", + }, + }); + + const codes = result.checks.map((check) => check.code); + + expect(codes.includes("hermes_no_api_keys")).toBe(true); + expect(codes).not.toContain("hermes_local_endpoint_no_api_key"); + }); +}); diff --git a/packages/adapters/hermes/src/server/test.ts b/packages/adapters/hermes/src/server/test.ts index 3fd8402efd3..2d60f7d5d79 100644 --- a/packages/adapters/hermes/src/server/test.ts +++ b/packages/adapters/hermes/src/server/test.ts @@ -132,6 +132,23 @@ function checkModel( }; } +function isLoopbackBaseUrl(baseUrl: string): boolean { + if (!baseUrl) return false; + let parsed: URL; + try { + parsed = new URL(baseUrl); + } catch { + return false; + } + if (parsed.protocol !== "http:" && parsed.protocol !== "https:") return false; + const hostname = parsed.hostname; + return ( + hostname === "localhost" || + hostname === "127.0.0.1" || + hostname === "[::1]" + ); +} + async function checkApiKeys( config: Record, detectedConfig: Awaited> | null, @@ -234,6 +251,15 @@ async function checkApiKeys( }; } + if (modelMatchesRequested && detectedConfig?.baseUrl && isLoopbackBaseUrl(detectedConfig.baseUrl)) { + return { + level: "info", + message: `Hermes config points the requested model at a local inference endpoint (${detectedConfig.baseUrl})`, + hint: "Skipping the missing API-key warning for a configured loopback inference endpoint.", + code: "hermes_local_endpoint_no_api_key", + }; + } + return { level: "warn", message: "No LLM API keys found in environment",