Skip to content

fix(client): keep streams out of REST clients, and add refetchInterval - #121

Merged
juicycleff merged 2 commits into
mainfrom
fix/client-streams-and-polling
Nov 16, 2026
Merged

juicycleff merged 2 commits into
mainfrom
fix/client-streams-and-polling

Conversation

@juicycleff

Copy link
Copy Markdown
Contributor

This clears the three open issues. Two needed code, one commit each. The third was already done by other work.

#106: stream endpoints generated as queries

The empty streams manifest half was fixed by #109, which carries x-forge-stream bindings from AsyncAPI into stream-bindings.ts. To get rows in that table you declare a binding (WithStreamBinding, or messages through WithSSEMessages / WithWebSocketMessages) and pass the AsyncAPI document to forge client generate alongside the OpenAPI one.

The other half was still there. SSE, EventStream, WebSocket and WebTransport all register a plain GET, and the OpenAPI generator never looked at route.Kind, so every stream showed up in openapi.json as GET -> 200 Success. You can't tell that apart from a REST read, so the TypeScript generator emitted query(...) for it, and the Go and Dart REST clients got a method that fetches a body that never ends.

What changed

  • In the router, streaming operations now carry x-forge-protocol: sse | websocket | webtransport, the same marker AsyncAPI channels already use for WebTransport. An SSE route's 200 is declared as text/event-stream, keeping any schema the route declared. A WebSocket route whose only response is the generated default gets 101 Switching Protocols in its place. The golden specs change for exactly the three streaming routes in them.
  • In the IR, Endpoint.Stream comes from that marker. Failing that, it comes from the responses: every 2xx is text/event-stream, or the only success is 101. That second rule is what catches a gateway document like the one in the issue. A malformed marker warns and falls back to the responses.
  • At generation, Generator.Generate takes streams out of Endpoints after merge and path filtering, before any language generator runs. So it covers introspection, --from-spec, merged sources, watch and check in one place.
    • AsyncAPI already describes it: the OpenAPI operation is dropped, and the channel is the stream's only description.
    • Only OpenAPI describes it and the path has no parameters: it becomes a stream endpoint of its kind with untyped events.
    • Only OpenAPI describes it and the path has parameters: it's left out with a warning naming it.

That last case is deliberate. The TypeScript and Go stream clients concatenate a channel path onto the base URL as written, so a client for /instances/{instanceId}/logs/stream would connect to a literal {instanceId}. That's true today for AsyncAPI channels with parameters too, so it isn't new, but we didn't want this change emitting more of it. Substituting path params in the stream clients is a good follow-up. Dart's streaming already has a pathParams helper to copy from.

For the six portal endpoints in the issue, that means after a regen they disappear from ops.ts, hooks.ts and rest.ts, and forge client generate prints one warning each. Declaring their messages on the services and passing asyncapi.json too gives them proper stream clients and stream bindings.

#100: polling from useQuery

useQuery (React, Vue) and injectQuery (Angular) take refetchInterval?: number | false and refetchIntervalInBackground?: boolean, spelled and behaving the way TanStack does, so refetchInterval: isExecuting ? 3000 : false moves over unchanged. The timer is keyed on the query and the two options, never on the result, which is the bug every hand-written hook in the issue had. Vue takes refs or getters and Angular signals or functions, same as live and staleTime.

All three run on the core's poll, which needed a fix of its own. It slept the full interval after each response settled, so its period was interval plus latency, the same drift the issue describes, just in a different place. It now waits the interval less however long the request took. A response slower than the interval is followed straight away by the next request, and two never overlap. An interval of 0, a negative number, NaN or Infinity polls nothing. Before, 0 would loop with no delay at all.

#98: pin a dashboard shell release

Nothing left to do. b550666 (Sep 29) removed the embedded shell at {BasePath}/ui, the two pin files, scripts/fetch-dashboard-shell.sh and the GoReleaser hook, so there's no placeholder to ship and nothing to pin. The other blocker in the issue is gone too: forge-dashboard has tagged v0.1.0 through v0.3.0, and all six @forge-go/dashboard-* packages forge dashboard new scaffolds are on npm at 0.3.0, so the scaffold installs.

How we checked it

  • go test ./... on the root module with typescript@5.8.2 and esbuild on PATH, as CI installs them, so none of the tsc gates skipped. cmd/forge/plugins (through a local go.work) and extensions/streaming pass too. golangci-lint is clean on the changed packages.
  • Router tests for each route kind, plus a declared-schema and a declared-WebSocket-response case. Unit tests for classification and separation, including the :id versus {id} path match, the warning and idempotence.
  • Two end-to-end tests through client.Generator.Generate: a gateway-style OpenAPI document with no AsyncAPI, and a real router's two documents merged. Both fail with the separation pass removed. The gateway one type-checks the synthesized SSE client.
  • For the client packages, build, typecheck, test, smoke and size for core, react, vue and angular, all passing. freshness goes from 378 B to 451 B against its 500 B budget. The new cadence tests fail against the old poll.

Closes #100
Closes #106
Closes #98

SSE, EventStream, WebSocket and WebTransport routes are registered as plain
GETs, so they landed in openapi.json as `GET -> 200 Success`, which nothing can
tell apart from a REST read. The TypeScript generator bound every one of them
as `query(...)`, and calling that fetches an endpoint whose body never ends.
The Go and Dart REST clients had the same trap.

The router now marks those operations with x-forge-protocol (the marker
AsyncAPI channels already carry for WebTransport), answers an SSE route's 200
as text/event-stream, and gives a WebSocket route a 101 when its only response
is the generated default.

On the client side the IR records Endpoint.Stream from that marker, or from
responses that are only text/event-stream or only 101, so a document from a
gateway is caught too. Generator.Generate then takes streams out of Endpoints
after merge and filtering. A stream AsyncAPI already describes is dropped, a
stream only OpenAPI knows about becomes a stream endpoint of its kind, and one
whose path has parameters is left out with a warning, because the generated
stream clients don't substitute path parameters yet.

Refs #106
Polling had to be written by hand at every call site, and the easy way to
write it keys the timer on the result object, so it restarts on every
response and a three second poll on a slow endpoint quietly becomes five.

useQuery in React and Vue and injectQuery in Angular now take
refetchInterval (number or false, as in TanStack Query) and
refetchIntervalInBackground. The timer is keyed on the query and the two
options, never on the result. Vue takes refs or getters and Angular signals or
functions, the same way they take live and staleTime.

All three run on the core's poll, which now holds its cadence too. It used to
sleep the whole interval after each response, so the period was interval plus
latency. It now waits the interval less the time the request took, starts the
next request straight away when a response is slower than the interval, and
never overlaps two. An interval that isn't a positive finite number polls
nothing, where 0 used to spin. The freshness entry goes from 378 B to 451 B
against its 500 B budget.

Closes #100
@vercel

vercel Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
forge Ready Ready Preview Nov 16, 2026 4:16am UTC

Request Review

@github-actions

Copy link
Copy Markdown
Contributor

Conventional Commits Validation

PR Title: valid
Commits: all 2 follow conventional format

@codecov

codecov Bot commented Nov 16, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.39073% with 13 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
internal/client/stream_endpoints.go 91.52% 5 Missing and 5 partials ⚠️
internal/router/openapi_generator.go 89.28% 2 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@juicycleff
juicycleff merged commit 0c56e66 into main Nov 16, 2026
51 checks passed
@juicycleff
juicycleff deleted the fix/client-streams-and-polling branch November 16, 2026 04:31

This branch was successfully deployed

1 active deployment
Preview — 2f41beef Deployed Nov 16, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

1 participant