Repository navigation
fix/llm-models-runner-down - #760
Conversation
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
There was a problem hiding this comment.
ℹ️ 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).
GetLLMModelsdegrades to an empty catalog — a transport error from agent-runner now returns200with{}and aslog.Warninstead 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
httptestserver covers the unreachable path, a pre-cancelled request context covers the cancel path. - Docs record the contract —
docs/ai-agent/api-design.mdstates 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.
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) | ||
| } | ||
| } |
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
LGTM! Thank you for the contribution! 🚀

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
GetLLMModelsreturns 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.failed to reach agent-runner serviceinservices/api: one other hit,proxyACPBridgeStatus(same 500, left unchanged).Testing
Added
TestGetLLMModels_RunnerUnreachableReturnsEmptyListandTestGetLLMModels_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-modelsnow 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 toorigin/master: exit 1, failing: TestGetLLMModels_RunnerUnreachableReturnsEmptyList; TestGetLLMModels_ClientCancelWritesNothing.