Skip to content

Config-apply returns 500 for an invalid value; malformed log line; stale nested upstream_stats in /api/v1/status #1084

Closed

Description

@Dumbris

Three defects observed during a live verification session against a running core. All are pre-existing and independent of the feature being verified; grouped because they were all found in the same PATCH /api/v1/config / GET /api/v1/status session.

1. Invalid config value returns HTTP 500, not 400

PATCH /api/v1/config with {"direct_tool_response_mode":"bogus"}:

HTTP/1.1 500 Internal Server Error
{"success":false,"error":"Failed to apply configuration: configuration validation failed: direct_tool_response_mode: invalid direct tool response mode: bogus (must be \"full\" or \"deferred\")"}

The behaviour is safe — validation caught it and the config file was left untouched — and the message is genuinely good. Only the status code is wrong: a client-supplied invalid value is a 400, not a server fault. This matters for clients that retry on 5xx.

Suggested fix: classify the ApplyConfig error in the handler — when the result carries ValidationErrors (or the error is a config-validation error), return http.StatusBadRequest with the ValidationErrors payload, reserving 500 for marshal/persist failures. The sibling call sites in internal/httpapi/ need the same treatment.

Around internal/httpapi/server.go:4665.

2. Malformed structured log line on config-apply failure

The same rejected PATCH produced:

ERROR httpapi/server.go:651 Failed to apply configuration patcherrorconfiguration validation failed: direct_tool_response_mode: ...

Note patcherrorconfiguration — the message, the error key and its value are concatenated with no separators. The call is s.logger.Error("Failed to apply configuration patch", "error", err), i.e. sugared-style key/value pairs passed to a non-sugared Error. The reported server.go:651 is also not the real call site, so the logging shim needs AddCallerSkip.

3. /api/v1/status embeds a permanently stale copy of upstream stats

For an entire ~5-minute session — long after the upstream was Ready and the log confirmed Successfully indexed tools for server {server: everything, count: 13} — every poll returned:

data.status.tools_indexed                           = 0
data.status.upstream_stats.servers.everything.state = "Connecting"
data.status.upstream_stats.total_tools              = 0

while the sibling top-level data.upstream_stats was correct throughout. Two fields describing the same thing disagree, and the nested one never converges.

Suggested fix: either refresh the embedded snapshot from the same source as the top-level upstream_stats before serving, or drop the duplicated data.status.upstream_stats / data.status.tools_indexed so there is a single authority. If it is deliberately a last-published-event snapshot, that should be documented in the OpenAPI description, because it currently reads as live data.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions