koala73 / koala73/worldmonitor
Lazy RPC client: first-call request timeout now includes chunk-load latency
- Dominant language
- TypeScript
- Stars
- 86.6k
- Forks
- 13.1k
- Avg merge
- 8h 4m
- Merged PRs (30d)
- 825
Description
_Follow-up from the adversarial review of #4542 (lazy-loaded generated RPC clients)._
## What
In `src/services/generated-rpc-clients.ts`, a method call resolves the lazy `import()` of the generated client chunk **before** the real method runs `fetch(url, { signal })`. Callers create the abort signal with `AbortSignal.timeout(N)` at call time, so the timer starts before the chunk load. On the **first** call per client instance, the `rpc-client-*` chunk-load latency is charged against the caller's request-timeout budget.
## Impact
Low. Only the first call per service client per page load is affected (subsequent calls reuse the memoized instance). The minimum timeout actually passed to a lazy RPC method is **12s** (most are 15–20s), e.g.:
- `src/services/economic/index.ts:738` — `getNationalDebt({}, { signal: AbortSignal.timeout(12_000) })`
- `src/services/cross-source-signals.ts:18` — `listCrossSourceSignals({}, { signal: AbortSignal.timeout(15_000) })`
All such calls are circuit-breaker-wrapped with cached fallbacks, so a spurious first-call abort degrades gracefully rather than breaking. (Note: the 5s timeouts elsewhere in these files are on plain `fetch(toApiUrl(...))` calls, not lazy methods, so they are unaffected.)
## Possible fix
If we want strict timeout semantics, resolve the client constructor first and only then apply/start the per-call timeout (so the budget covers the network call, not the chunk load). Otherwise, document that first-call timeouts should allow for chunk-load time.
Contributor guide
Research direction
Start in src/services/generated-rpc-clients.ts and trace the lazy import path before the generated RPC method receives fetch(url, { signal }). Compare the first call with subsequent memoized calls, then inspect the examples at src/services/economic/index.ts:738 and src/services/cross-source-signals.ts:18. Done means the chosen timeout behavior is consistent and covered for first-call chunk loading without changing unaffected plain fetch calls.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 66/100