Repository navigation
Description
Summary
The frontend has no single source of truth for talking to the backend, in two dimensions:
- Transport: 8 independent HTTP-client classes (two of them generic), none extending a shared base, plus 22 files calling
window.fetchdirectly and 3 importingaxiosdirectly. - Types: a 172,402-line generated contract (
src/types/generated/api.ts) that only 4 files import, while 74 files hand-type their own*Responseinterfaces. The generated file is also stale — it declares 2,424 paths against the live backend's 2,152.
This is the root cause under several already-filed issues (#12313 port/CSP, #12317 /api prefix, #12326 dead buttons): when every caller builds its own URL and declares its own response shape, nothing enforces that a path exists or that a response matches — and a config error like :8443 lands in some clients but not others, which is exactly why features break inconsistently.
1. HTTP-client sprawl
Eight distinct client classes, none of which extend the others — each reimplements request/error/auth/URL handling:
utils/ApiClient.ts class ApiClient (generic)
services/api.ts class ApiService (generic — second one)
utils/AdvancedControlApiClient.ts class AdvancedControlApiClient
utils/SecretsApiClient(.d).ts class SecretsApiClient
utils/VisionMultimodalApiClient.ts class VisionMultimodalApiClient
utils/FeatureFlagsApiClient.ts class FeatureFlagsApiClient
services/BatchApiService.ts class BatchApiService
composables/useWorkflowBuilder.ts class WorkflowBuilderApiClient
Plus 22 files using window.fetch directly and 3 importing axios directly, bypassing all of the above.
Two generic clients (ApiClient and ApiService) is itself an unresolved fork — there should be exactly one.
This is the mechanism behind the :8443 breakage (#12313)
Base-URL construction is not centralised, so it drifts per client:
54x getApiBase() # the common idiom
4x window.location... # a different idiom
1x VITE_BACKEND_PORT # raw — the :8443 defect lives here
Because there is no single place that builds the backend origin, the broken :8443 construction exists in some code paths and not others. That is precisely why chat/voice/onboarding break while other calls succeed on the same page — they are built by different clients. A single client would have made #12313 a one-line, one-place fix instead of a scattered symptom.
2. Types: the generated contract is bypassed and stale
src/types/generated/api.ts 172,402 lines, 2,424 path entries
files importing it: 4
files hand-typing *Response: 74
live backend (openapi.json): 2,152 paths
- Bypassed: 74 hand-written response interfaces vs 4 files deriving from the contract. Example —
models/repositories/KnowledgeRepository.ts:69hand-declaresRagSearchResponserather than importing the generated shape. - Stale: the generated file has 272 more paths than the live backend serves, so even the 4 files that do use it may be typing against endpoints that no longer exist (or in shapes that have since changed). Regeneration is clearly not part of the backend-change workflow.
Per the canonical rule (#4): types come from the generated contract; a hand-typed response that duplicates a backend shape is a contract-check bypass. With 74 of them, TypeScript cannot catch a frontend/backend shape mismatch anywhere — which is why the 77 dead calls in #12326 compiled cleanly.
Why these two are one problem
Both are "the frontend invents its own version of the backend." Transport and types are the two halves of the contract, and both are currently reinvented per-file instead of derived once. Fixing them together is what makes the mechanical audit (audit_api_wiring.py) meaningful: a single client that only accepts paths present in the generated types would make an unwired call a compile error rather than a runtime 404.
Recommendation (architecture decision — needs owner sign-off)
Per the canonical rule for "two implementations already exist": pick one, migrate, shim/delete the rest — do not add a ninth.
- Declare one canonical client (likely
utils/ApiClient.ts) that owns URL construction (onegetApiBase, correct origin — fixes frontend: .env.production hardcodes VITE_BACKEND_PORT=8443 but nothing listens there — onboarding/metrics calls fail with 'Failed to fetch' #12313 at the source), auth, and error handling. FoldApiServiceand the domain clients into thin typed wrappers over it, or delete them. - Regenerate
api.tsfrom the live backend and make regeneration a required step on any backend route change (npm run gen:types), enforced in CI so it cannot drift to 2,424-vs-2,152 again. - Migrate the 74 hand-typed responses to the generated types, incrementally, starting with the repositories.
- Add a lint rule forbidding
window.fetch/axiosoutside the canonical client, and forbidding hand-typed*Responseinterfaces where a generated equivalent exists. - Record as an ADR — this is a module-boundary/authority decision.
Discovery issue — filed per the marketing-session rule (expose, do not fix). The migration is an implementation task for a later session and should not begin without the canonical-client decision in step 1.
Environment
autobot-frontend/src at origin/Dev_new_gui; counts from the deployed frontend source; live path count from the running backend's openapi.json.
Activity
mrveiss commentedon Jul 25, 2026
Correction — the recommendation above under-scoped the canonical target
The original recommendation framed this as "8 HTTP client classes → 1." That is necessary but not sufficient: it points at the wrong consolidation surface and omits the type-level half. Two dimensions were missing.
1. Composables are the real data-access layer, not the client classes
API access is spread across the composables, not centralised in the 8 client classes:
So consolidating the 8 client classes leaves 125 composables each still building their own calls, their own URL construction, and their own error handling. The canonical layering has to be explicit:
:8443origin, frontend: .env.production hardcodes VITE_BACKEND_PORT=8443 but nothing listens there — onboarding/metrics calls fail with 'Failed to fetch' #12313) fixes it for all 125 consumers, instead of in whichever composables happen to use the shared client.2. Enums — 51 hand-typed string-unions that should derive from the contract
The type half of the contract is reinvented the same way the transport half is. There are 51 hand-declared string-union types for status/type/mode/severity/level concepts, e.g.:
These are the frontend parallel of the backend
PerformanceIssuestr-vs-enum divergence called out in #12362: the same concept (e.g. an agent's status) exists as a backend enum, a generated-type enum, and a hand-typed frontend string union — three definitions, free to drift. A component checkingstatus === 'terminated'silently breaks when the backend renames a variant, because nothing ties the string union to the source enum.Canonical fix: status/type/mode unions come from the generated types' enums, the same way response shapes should (original step 3). Hand-typed string-unions that duplicate a generated enum are the enum-level version of the hand-typed
*Responsebypass.Revised canonical target
Not "one client," but the full contract derived once:
src/types/generated/api.ts— the 74 hand-typed*Responseinterfaces and the 51 hand-typed status/mode/type string-unions both migrate to the generated contract.window.fetch/axiosoutside the client, hand-typed*Responsewhere a generated shape exists, and hand-typed string-unions where a generated enum exists.The through-line with #12362 is exact: both are "one concept, defined multiple times, free to diverge (incl. str-vs-enum)." The fix is the same on both sides — derive from one source. Thanks for the catch; the original three-step version would have consolidated transport while leaving the composable sprawl and the enum divergence in place.
mrveiss commentedon Jul 26, 2026
Phased plan (from a read-only audit) — issue is ~75% already done
Key finding: a prior effort (#12152) already routed 6 of 8 clients through the canonical
utils/ApiClient.ts. The 'no single contract' framing is now stale. Canonical =utils/ApiClient.ts(owns base-URL resolution, auth+expiry, X-Organization-Id, 401 handling, retry/backoff, timeout/abort, FormData, rawRequest) —ApiServicealready delegates to it.Remaining, phased:
AdvancedControlApiClient(still onfetchWithAuth) →apiClient.rawRequest(behavior-neutral), andSecretsApiClient.js→.ts. Completes the single-transport half.fetch(29 files) + axios (4 importers) in feature-batched PRs viafetchWithAuth/domain clients; add a lint rule forbidding raw fetch/axios. (SSE/streaming sites must userawRequest, not.get().)src/types/generated/api.tsfor the ~74 hand-typed*Responseinterfaces; gategen:types/verify:typesin CI. Fold in the oxlint glob fix (_generatedvsgeneratedmismatch makes oxlint walk a 5MB file every run).Owner decisions: whether AdvancedControl/Secrets should inherit ApiClient's retry + 401-auto-logout (behavior change — Phase 1 deliberately avoids it); whether to extract a shared
@autobot/http-core(do NOT put transport in @autobot/ui #10860 — violates its presentational charter); making gen:types a CI gate.refactor(frontend): route last 2 clients through canonical ApiClient …
mrveiss commentedon Jul 26, 2026
Phase 1 complete (#12583 merged, discrete #12582 closed): the last 2 transport outliers now go through canonical
ApiClient— the single-transport half of #12363 is done. Phases 2 (retire 29 raw-fetch + 4 axios) and 3 (adopt generated types + oxlint glob fix) remain per the roadmap above.refactor(frontend): migrate axios importers onto canonical ApiClient (#…
refactor(frontend): migrate feature composables off raw fetch onto Ap…
refactor(frontend): migrate monitoring/health composables off raw fet…
refactor(frontend): migrate getBackendUrl fetch callers onto ApiClient (
refactor(frontend): migrate 6 getBackendUrl callers onto ApiClient (#…
98 remaining items
fix(frontend): the export download throws the response's HttpError, n…
fix(ui): fillPathParams placeholder regex excludes '{' so it stays li…
chore(guard): drop the VisionMultimodalApiClient size ceiling mrveiss…
chore(types): regenerate api.ts on the merged train tree (#12363)
chore(types): regenerate api.ts on the merged train tree (mrveiss#12363)
chore(types): regenerate api.ts on the merged train tree (#12363)
chore(types): regenerate api.ts on the merged train tree (#12363)
github-actions commentedon Nov 12, 2026
Landed via the merge train (#21335, merge
f87e78874a)test(ci): compare bridge importers and hand-built URLs by identity; s…
mrveiss commentedon Nov 12, 2026
Slice merged via #21057 in train #21398, main merge commit 650d062 (2026-11-12 ~21:30 Riga). Evidence read from origin/main. The issue stays open; its body has no checkboxes, so nothing was ticked. The table below uses the numbered Recommendation items.
repo_tests/frontend_api_contract_ratchet_test.py: dimensionsfetch_with_auth_importers(by file path) andhand_built_urls(by file path plus stripped line text with multiplicity) at lines 238-291;test_no_new_bridge_importer_or_hand_built_url_even_at_equal_count(:371); control tests for equal-count swaps and line shifts (:536, :548). Compared against the merge base, no baseline file.fetchWithAuthimporters and 571 hand-built URL lines on its head.api.ts, enforce in CIPossible wrong link: the PR names #21050 as the migration follow-up, but #21050 is "tech-debt(ci): switch the three inline x-websocket-paths strips to the dumpers' --no-websocket-paths flag". No open migration issue was found by search, so the migration has no tracked home yet.
github-actions commentedon Nov 12, 2026
Landed via the merge train (#21398, merge
650d06217f) via #21057mrveiss commentedon Nov 12, 2026
Correction to the closure note: the follow-up for migrating the remaining bridge importers and hand-built URLs is #21405 (PR #21057 cited #21050, which tracks a different change).
mrveiss commentedon Nov 20, 2026
Branch
issue-12363-slice1-models(PR #21232, head 08c6334) was deleted as a zero-change branch: its content is already on main. This issue has no acceptance-criteria checkboxes (its recommendation steps 1-5 are prose), so nothing can be ticked or closed. It needs ACs written, for example: one canonical client, regeneratedapi.tsenforced in CI, the 74 hand-typed responses migrated, and the lint rule from step 4.mrveiss commentedon Nov 22, 2026
Branch audit (2026-11-22): the unmerged branch
issue-12363-slice4-domain-wrappersis landed except one item. Commit f525895's polynomial-regex fix infillPathParamsis on main (libs/autobot-ui/src/utils/ApiClientBase.ts:186), but its two regression tests are not: inlibs/autobot-ui/src/utils/__tests__/ApiClientBase.test.ts, "fillPathParams is linear on a run of unbalanced opening braces" (5000{, under 500 ms) and "still fills a plain placeholder". They belong to this issue. The branch is kept until they land. Note: the linear-time test as written is a wall-clock assertion; a call-count or step-bound form would be load-safe.