Repository navigation
fix(bff): mark API responses no-store - #138
Open
Gkrumbach07 wants to merge 1 commit into
Open
Gkrumbach07 wants to merge 1 commit into
Gkrumbach07 wants to merge 1 commit into
Conversation
Every /api/v1 response now carries Cache-Control: no-store, set by a middleware on the API router before the handler runs. A cache in the deployment path could otherwise replay a list read after a write, which is how the workspace count stayed stale after a create (ai-openshell#129): the hooks invalidate and refetch the unfiltered list, and the gateway writes the workspace synchronously. The logs stream keeps its own "no-cache, no-transform"; static frontend assets are not affected. Fixes ai-openshell#129 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Gage Krumbach <gkrumbac@redhat.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #129
What
Every
/api/v1response now carriesCache-Control: no-store. A small middleware (noStoreinbackend/pkg/server/app.go) on the API router sets it before the handler runs, so it covers public routes, authenticated routes, error envelopes and unknown API routes alike./api/v1and get no header from this change..../logs/stream) still sets its ownCache-Control: no-cache, no-transform, which replaces the middleware's value.no-cachealready forbids reuse without revalidation, andno-transformkeeps proxies from buffering the event stream, so it stays as it is.no-storeis right for a file read out of a sandbox.Why (the investigation)
The workspace count in the navigation is
useWorkspaces(undefined, …)(frontend/src/app/AppLayout.tsx), whose query key is['workspaces'].useCreateWorkspaceinvalidatesworkspaceKeys.all=['workspaces']. A test of the real hooks with the HTTP client stubbed shows the nav query refetching and the count following. That test is added here as a regression test (frontend/src/api/__tests__/workspace-create.spec.tsx).handle_create_workspacewrites the workspace synchronously, andhandle_list_workspacesreturns every workspace to platform admins. So a list read after the create sees the new workspace.That leaves the refetch getting a stale HTTP answer.
apiutils.WriteJSONset noCache-Control, so any cache between the browser and the BFF (a proxy or gateway in front of the chart, or the browser's heuristic cache) was free to reuse aGET /api/v1/workspacesanswer.Not reproduced against the reporter's environment (console 0.1.2, gateway 0.1.7, Kubernetes behind an HTTPS Gateway). This is the cause the code points to, and the fix is correct either way: API answers depend on the bearer and change with every write. A network trace of the refetch from the reporter would confirm it.
Tests
backend/pkg/server/cache_control_test.go:no-storeon public, authenticated, error and unknown/api/v1routes; no header on static files or the SPA fallback; a handler's ownCache-Controlwins.frontend/src/api/__tests__/workspace-create.spec.tsx: creating a workspace refetches the unfiltered['workspaces']list, and the data follows.make typecheckandmake testpass (Go plus 2177 frontend tests).make lintpasses eslint and prettier. golangci-lint v2 (latest, built with Go 1.26) reports 0 issues; the locally installed binary was built with Go 1.25 and can't load a 1.26 module.🤖 Generated with Claude Code