Skip to content

fix(bff): mark API responses no-store - #138

Open
Gkrumbach07 wants to merge 1 commit into
ai-openshell:mainfrom
Gkrumbach07:claude/fix-129-api-no-store-f2d976
Open

Gkrumbach07 wants to merge 1 commit into
ai-openshell:mainfrom
Gkrumbach07:claude/fix-129-api-no-store-f2d976

Conversation

@Gkrumbach07

@Gkrumbach07 Gkrumbach07 commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #129

What

Every /api/v1 response now carries Cache-Control: no-store. A small middleware (noStore in backend/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.

  • Static frontend assets are served outside /api/v1 and get no header from this change.
  • Logs stream (.../logs/stream) still sets its own Cache-Control: no-cache, no-transform, which replaces the middleware's value. no-cache already forbids reuse without revalidation, and no-transform keeps proxies from buffering the event stream, so it stays as it is.
  • Terminal WebSocket: the header goes on the 101 handshake response, where it has no effect.
  • File downloads: no-store is 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'].

  • Hooks: useCreateWorkspace invalidates workspaceKeys.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).
  • Gateway: handle_create_workspace writes the workspace synchronously, and handle_list_workspaces returns every workspace to platform admins. So a list read after the create sees the new workspace.
  • No change since v0.1.2: none of this code has changed since the reporter's version.

That leaves the refetch getting a stale HTTP answer. apiutils.WriteJSON set no Cache-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 a GET /api/v1/workspaces answer.

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-store on public, authenticated, error and unknown /api/v1 routes; no header on static files or the SPA fallback; a handler's own Cache-Control wins.
  • frontend/src/api/__tests__/workspace-create.spec.tsx: creating a workspace refetches the unfiltered ['workspaces'] list, and the data follows.
  • Local: make typecheck and make test pass (Go plus 2177 frontend tests). make lint passes 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

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

No deployments
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.

Workspace count remains stale after creating a workspace until page refresh

1 participant