Skip to content

fix/llm-models-runner-down - #760

Merged
pikann merged 2 commits into
Paca-AI:masterfrom
tlq5l:fix/llm-models-runner-down
Nov 15, 2026
Merged

pikann merged 2 commits into
Paca-AI:masterfrom
tlq5l:fix/llm-models-runner-down

Conversation

@tlq5l

@tlq5l tlq5l commented Nov 15, 2026

Copy link
Copy Markdown
Contributor

Summary

With agent-runner unreachable, the agents page now loads with an empty model list instead of an error screen. Its route loader calls GET /api/v1/agents/llm-models, which returns 500 in that case. Boot-key rule unchanged. Refs #739.

Changes

  • GetLLMModels returns 200 with {} and a warning when agent-runner is unreachable; other runner failures still return 500, and a request the client cancelled writes nothing. Docs: api-design.md.
  • Swept: the removed text failed to reach agent-runner service in services/api: one other hit, proxyACPBridgeStatus (same 500, left unchanged).
  • Tradeoff (suspected): an outage may show an empty list, which the web app treats as fresh for up to 10 minutes.

Testing

Added TestGetLLMModels_RunnerUnreachableReturnsEmptyList and TestGetLLMModels_ClientCancelWritesNothing; each fails without the fix and passes with it (cd services/api && go test -count=1 -race -run TestGetLLMModels -v ./internal/transport/http/handler/). Also run with agent-runner stopped: GET /api/v1/agents/llm-models now returns 200 with {} (500 before). The web page and other failure paths were read from the code, not run.

AI-assisted; I take responsibility for it.

Tests (agent-run) at 67b8420, clean setup (empty HOME, no git config): cd services/api && go test -count=1 -race -run TestGetLLMModels -v ./internal/transport/http/handler/, exit 0. Last output line: ok github.com/Paca-AI/api/internal/transport/http/handler 1.790s.

Fails without fix: cd services/api && go test -count=1 -race -run TestGetLLMModels -v ./internal/transport/http/handler/ on 67b8420, with the fix's code reverted to origin/master: exit 1, failing: TestGetLLMModels_RunnerUnreachableReturnsEmptyList; TestGetLLMModels_ClientCancelWritesNothing.

The agents pages request /agents/llm-models when they open
(apps/web/src/routes/_authenticated/projects/$projectId/agents/index.tsx:44-45).
With agent-runner unreachable (as when scaled to 0, PACA_AGENT_RUNNER=no,
scripts/install.sh:776-778), a live run got 500 INTERNAL_ERROR. An unreachable
runner now gives 200 with an empty object. A runner that answers with an error
still returns 500.

Refs Paca-AI#739

Agent: claude
A cancelled request also fails httpClient.Do, so it was logged as
"agent-runner unreachable" and answered with {}. Return without writing
when r.Context() is done.

Refs Paca-AI#739

Agent: claude

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ Minor suggestions only — the degrade itself checks out; one untested branch worth a small test.

Reviewed changes

Read the full diff, the agent-runner /llm/models source, every web consumer of the endpoint, both deploy paths that disable agent-runner, and ran the new tests locally (go test -run TestGetLLMModels, plus gofmt/go vet on the handler package — all clean).

  • GetLLMModels degrades to an empty catalog — a transport error from agent-runner now returns 200 with {} and a slog.Warn instead of the 500 that broke four route loaders, while a request whose own context is already cancelled returns without writing anything.
  • Two regression tests — a closed httptest server covers the unreachable path, a pre-cancelled request context covers the cancel path.
  • Docs record the contract — docs/ai-agent/api-design.md states the 200-with-{} behavior and that a runner which answers with an error still yields 500.

Verification worth recording: both deploy paths that turn agent-runner off reach the transport-error branch rather than the aiAgentURL == "" 500 — docker compose still sets AI_AGENT_URL: http://agent-runner:8080 while scaling to 0, and Helm omits AI_AGENT_URL so config/load.go's default http://ai-agent:8080 fails to resolve. {} is also shape-safe for every consumer: listLLMModels returns the bare provider-keyed map and the dialogs/detail views default to {} and only do Object.keys / optional-chained lookups, so the worst case is an empty provider list, not a crash or a rewrite of an agent's provider/model.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏

if got := rec.Body.String(); got != "" {
t.Fatalf("body = %q, want nothing written after the client cancelled", got)
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The third branch here is the one that keeps this fix narrow: a reachable runner answering non-200 still returns 500, which the docs now promise. It is the branch most likely to be silently widened later, and a companion test alongside these two costs about eight lines (a fake server returning http.StatusInternalServerError, asserting rec.Code is 500).

@pikann pikann left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thank you for the contribution! 🚀

@pikann
pikann merged commit 558763e into Paca-AI:master Nov 15, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] api breaks without agent-runner (missing AI_AGENT_INTERNAL_KEY + agents page 500)

2 participants