Skip to content

fix(registry): propagate registry errors from ListAvailableSkills - #6753

Merged
ChrisJBurns merged 7 commits into
stacklok:mainfrom
feiiiiii5:fix/skills-error-semantics
Nov 26, 2026
Merged

ChrisJBurns merged 7 commits into
stacklok:mainfrom
feiiiiii5:fix/skills-error-semantics

Conversation

@feiiiiii5

Copy link
Copy Markdown
Contributor

Summary

  • ListAvailableSkills returned (nil, nil) when the registry fetch failed with no warm cache, and served stale skills on a 401/403. The v0.1 registry route turns that into HTTP 200 with an empty skills array, so an unreachable registry or a revoked token reads as "this registry has no skills".
  • This makes the skills path match ListAvailablePlugins, which already implements the intended contract 30 lines below and documents it in its doc comment: auth failures always propagate, transient failures degrade to stale cache when one exists, and with no stale cache the error is returned.
  • The skills doc comment now states the same contract.

Fixes #6752

Type of change

  • Bug fix
  • New feature
  • Refactoring (no behavior change)
  • Dependency update
  • Documentation
  • Other (describe):

Test plan

  • Unit tests (task test)
  • E2E tests (task test-e2e)
  • Linting (task lint-fix)
  • Manual testing (describe below)

The two task targets could not run in my environment, for a reason unrelated to this change, so I am not claiming them:

  • task test runs task gen first, which shells out to mockgen. mockgen@latest is built with go1.24 and refuses packages that declare go1.27, so it exits 1 for pkg/vmcp/* and pkg/workloads/*. Those packages are untouched here.
  • task lint fails before linting: golangci-lint's newest release (v2.14.0, the version pinned in .github/workflows/lint.yml) is built with go1.26 and reports "the Go language version used to build golangci-lint is lower than the targeted Go version (1.27.0)".
What I did run

What I did run:

go test ./pkg/registry/...
  ok  github.com/stacklok/toolhive/pkg/registry
  ok  github.com/stacklok/toolhive/pkg/registry/api
  ok  github.com/stacklok/toolhive/pkg/registry/auth
  ok  github.com/stacklok/toolhive/pkg/registry/legacyhint

go vet ./pkg/registry/...        # clean
gofmt -l <both changed files>    # clean

Red/green, reverting only provider_cached.go to origin/main and keeping the new test file:

--- FAIL: TestCachedProvider_SkillsTransient500WithColdCache
        An error is expected but got nil.
        transient 500 with cold cache must return the error, not nil,nil
--- FAIL: TestCachedProvider_SkillsAuthErrorWithWarmCache
        An error is expected but got nil.
        401 must propagate, not be masked by stale cache

With the change, all three skills tests pass. TestCachedProvider_SkillsTransient500WithWarmCache is the control and passes on both sides, pinning the part of the behaviour that should not change.

API Compatibility

  • This PR does not break the v1beta1 API, OR the api-break-allowed label is applied and the migration guidance is described above.

No operator API surface is touched.

Does this introduce a user-facing change?

Yes, and it is the fix: the skills registry route can now return a non-200 instead of an empty list when the upstream registry fails or the token is revoked. Clients that currently treat an empty skills array as "registry has no skills" will start seeing an error in those cases, which is the intended signal.

Special notes for reviewers

  • The tests mirror provider_cached_plugins_errors_test.go deliberately, including the newSkillsStatusServer helper shape and the cache-expiry idiom. I did not add a ForceRefresh case for skills because provider_cached.go:169-171 invalidates skillsCacheSet on the same path the plugins test already covers, and a second copy would be redundant.
  • I did not touch the route handler. registry_v01_skills.go declares @Failure 503 ... "Registry authentication required or upstream registry unavailable" but never calls writeRegistryUnavailableError, so that documented 503 is unreachable from this handler today. Making the error propagate is the prerequisite; wiring the handler to map it is a separate change and I would rather not bundle it. Happy to follow up if you want the 503 in this PR instead.
  • provider_cached_plugins_test.go:109-112 still has a comment saying plugins returns nil "mirroring the skills behavior". That was accurate when written and is now stale in both directions: plugins returns the error, and after this PR skills does too. I left it alone since it is in a file this PR does not otherwise touch.
  • No CLA in this repo; the commit carries a DCO Signed-off-by trailer.
  • No recording: no user-visible UI changes.

Implementation plan

Approved implementation plan

Not AI-planned in the sense this section expects: this came out of reading provider_cached.go and noticing that ListAvailableSkills and ListAvailablePlugins disagree about what to do with an error. The plan was to make the smaller one match the larger one rather than invent a third behaviour, which is why the doc comment on the plugins path is quoted in the issue and the tests mirror that file.

ListAvailableSkills returned (nil, nil) when the registry fetch failed and
no cache was warm, and served stale skills on a 401/403. The v0.1 registry
route turns that into HTTP 200 with an empty skills list, so an unreachable
registry or a revoked token reads as "this registry has no skills", and a
revoked token hides the need to re-auth.

ListAvailablePlugins, 30 lines below, already documents the intended
contract and implements it: auth failures always propagate, transient
failures degrade to stale cache when one exists, and with no stale cache
the error is returned so the route surfaces a real failure. This change
makes skills match, and states the same contract in its doc comment.

Signed-off-by: fei <[email protected]>
@codecov

codecov Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.60%. Comparing base (37c96de) to head (b6b4118).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6753      +/-   ##
==========================================
+ Coverage   79.57%   79.60%   +0.03%     
==========================================
  Files         814      814              
  Lines       82515    82528      +13     
==========================================
+ Hits        65660    65696      +36     
+ Misses      16850    16827      -23     
  Partials        5        5              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Sanskarzz Sanskarzz left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The reported cold-cache failure and upstream 401/403 behavior are confirmed, and the regression tests pass with this fix. Before merging, please preserve the behavior for a valid servers-only registry: when the optional skills endpoint is absent (404), the unconditional error return in provider_cached.go:470 turns the previous empty list into an HTTP 500 response. Please distinguish this unsupported-endpoint case from actual outage/auth failures and add regression coverage. A targeted diagnostic passes against the base implementation and fails against this PR.

Separately, token-acquisition failures still return stale skills because they carry auth.ErrRegistryAuthRequired rather than RegistryHTTPError. This predates the PR, so it is non-blocking feedback: please consider the existing server-cache sentinel check and a regression test here or in a follow-up. The handler's 503 mapping can remain separate as proposed.
The failing GitHub Actions Static Analysis check concerns action-version comments in workflow files unchanged by this PR.

@feiiiiii5

Copy link
Copy Markdown
Contributor Author

Thanks @Sanskarzz — addressed in 32e41e41:

  • A 404 from the skills list endpoint is now treated as "this registry predates skills" and returns an empty list again, so a valid servers-only registry no longer turns into a route-level HTTP 500. 401/403 and other real failures still propagate, and transient failures still degrade to stale cache first.
  • Token-acquisition failures are also propagated now: the skills path only inspected api.RegistryHTTPError, so an error carrying auth.ErrRegistryAuthRequired from the transport fell into the transient branch and could be masked by stale skills. The check mirrors what refreshCache() already does for the servers cache. The handler's 503 mapping is unchanged.

Both behaviors are pinned by new tests in pkg/registry/provider_cached_skills_errors_test.go: TestCachedProvider_SkillsEndpointAbsent and TestCachedProvider_SkillsTokenFailurePropagates. On the merge-base each fails for the reason above (missing 404 handling; token failure returns stale cache with nil error); with the fix, go test ./pkg/registry/ -run 'TestCachedProvider_Skills' passes 5/5. go vet and gofmt are clean. The Static Analysis finding is from workflow action-version comments this PR does not touch.

@Sanskarzz

Copy link
Copy Markdown
Collaborator

@feiiiiii5 Thanks for addressing the earlier cases. One remaining issue: a 404 on a later pagination page still becomes an empty successful response, even after page one returned skills. Please limit the unsupported-endpoint fallback to the initial request and add regression coverage for cold and expired warm caches. Once that’s addressed, we can finish the review.

ListSkills auto-paginates, so a 404 on a later page reached the same handler
that reads 404 as "this registry has no skills endpoint" and returned an
empty list with no error, dropping the pages that were already fetched. The
client now marks only a first-page 404 as a missing endpoint and returns the
plain HTTP error for any later one, and the provider matches on that.

Signed-off-by: Chen Yufeiyang <[email protected]>
@feiiiiii5

Copy link
Copy Markdown
Contributor Author

Done in 85f906d0, and you were right about the shape of the bug: the 404 check sat after the whole auto-paginated list, so it could not tell a missing endpoint from a page that failed.

The distinction is now made where the requests are made. ListSkills knows which request failed, so a 404 on the first page is wrapped as api.ErrSkillsEndpointNotServed ("the registry does not serve the skills endpoint"), and a 404 on any later page is returned as the plain RegistryHTTPError. ListAvailableSkills matches on that sentinel instead of inspecting the status code, so:

  • first page 404, cold cache → nil, nil (unchanged, the pre-skills case your existing tests pinned);
  • later page 404, cold cache → the error, not an empty list, so the pages already fetched are not silently dropped;
  • later page 404, expired warm cache → the stale skills, like any other non-auth failure.

Regression coverage for the two cache states you asked for: TestCachedProvider_SkillsLaterPage404WithColdCache and TestCachedProvider_SkillsLaterPage404WithWarmCache in pkg/registry/provider_cached_skills_errors_test.go, both of which fail on e7170864 with the empty list, plus TestSkillsClient_ListSkillsNotFoundPagination in pkg/registry/api/skills_client_test.go for the first-page/later-page split itself.

go test ./pkg/registry/... passes; go vet and gofmt are clean. I still cannot run task lint or task test here (golangci-lint is built with go1.24 and the module targets go1.27).

@feiiiiii5

Copy link
Copy Markdown
Contributor Author

The single red check here is failing on main too, so it is not from this change.

Operator CI / Operator Tests Integration fails on both runs at the same place — cmd/thv-operator/test-integration/mcp-oidc-config/mcpoidcconfig_mcpserver_integration_test.go:281, [FAILED] Timed out after 30.000s — on this branch (3e9a052, job https://github.com/stacklok/toolhive/actions/runs/37950948596/job/113982978765) and on main at 2c69e1f, about an hour and a half earlier (job https://github.com/stacklok/toolhive/actions/runs/37968068354/job/113950374126). It passes on the commit this branch was cut from (c23718d), so the regression came in from main rather than from these files, which are all under pkg/registry.

The other 41 checks on this head are green, including Tests / Test Go Code and Linting, so I am not pushing anything for this.

@feiiiiii5

Copy link
Copy Markdown
Contributor Author

Operator CI / Operator Tests Integration is the only red check on this branch (42 checks, 1 failing, 0 pending). It is red on main at 2c69e1f as well, with the same failure:

[FAIL] MCPOIDCConfig and MCPServer Cross-Resource Integration Tests When deleting MCPOIDCConfig with active references [It] should be deleted after references are removed
[FAILED] Timed out after 30.001s.

Base job: https://github.com/stacklok/toolhive/actions/runs/37968068354/job/113950374126
This PR's job: https://github.com/stacklok/toolhive/actions/runs/37950948596/job/113982978765

Same spec, same 30 s timeout, and 23 other cases in that suite pass on both runs. The diff here only touches pkg/registry, so recording it for whoever reads the red check.

@feiiiiii5

Copy link
Copy Markdown
Contributor Author

Operator CI / Operator Tests Integration fails on main itself, independent of this branch: the push run of 2c69e1f failed the same job with the same spec — MCPOIDCConfig and MCPServer Cross-Resource Integration Tests When deleting MCPOIDCConfig with active references [It] should be deleted after references are removed (run 37968068354, job log).

Here it is the identical spec, Timed out after 30.000s, 23 Passed | 1 Failed (job log). This diff only touches pkg/registry/, and nothing in it reaches that OIDC suite, so I am not changing code for it — let me know if you would like a re-run or a rebase onto current main.

@feiiiiii5

Copy link
Copy Markdown
Contributor Author

Both points from your 10-07 review are addressed on the current head (b6b4118e), and the branch now includes main through 10-13.

  • Servers-only registry (404). A 404 on the first skills page is now tagged api.ErrSkillsEndpointNotServed in skills_client.go and turned into nil, nil by ListAvailableSkills, preserving the previous empty list instead of a route-level 500. A 404 on a later page is not tagged and is returned as a real failure. TestCachedProvider_SkillsMissingEndpoint... and TestCachedProvider_SkillsLaterPage404WithColdCache/WithWarmCache pin both sides.
  • Token acquisition. auth.ErrRegistryAuthRequired now propagates before the stale-cache branch, the same way refreshCache() treats it. TestCachedProvider_SkillsAuthRequired... covers the wrapped error.

Transient failures still fall back to stale cache when present, and return the error when there is none, so the route can no longer answer 200 [] for an outage.

go test ./pkg/registry/... is green locally just now (registry, api, auth, legacyhint). The earlier Operator CI / Operator Tests Integration red was reproduced on main with the same timeout, and the current rollup on this head is green except for that known job.

Could you take a fresh look when you have a moment? I am happy to adjust the 404 distinction if you would rather treat a missing endpoint differently.

@Sanskarzz Sanskarzz left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM. The first-page versus later-page 404 handling and token-acquisition fixes address our feedback, with regression coverage for both cache states. Local registry tests and CI pass. Thanks for following through!

@ChrisJBurns
ChrisJBurns merged commit 2fc044d into stacklok:main Nov 26, 2026
43 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.

GET .../skills answers 200 [] when the registry is unreachable or the token is revoked

3 participants