Skip to content

[T-085d] Runtime config (/config.json), SSE client with reconnect/Last-Event-ID and query-cache patching #165

Closed

Description

@CodewithJha

Task T-085d · Milestone M8 — Dashboard · Size S · Priority P0 · Epic #8

Implements FR-DSH-002 · NFR-DEP-001

Branch feat/t-085d-runtime-config-sse-client-with — one task = one branch = one PR (doc 32 §6)

Summary

Implement lib/config.ts (load /config.json at boot, override build-time defaults), lib/sse.ts (EventSource wrapper: token query param, exponential reconnect, resume via last_event_id, connection status signal) and an SSE→TanStack Query bridge that invalidates/patches matching queries per event type (doc 13 §4).

Context / motivation

One image works in every environment; live updates are the core console experience.

Scope

In scope

  • Settings screen consumes SSE status (T-113a).
  • Bridge table: event → query keys (unit-tested).

Implementation guidance

  • lib/config.ts: loadConfig(): Promise<RuntimeConfig> fetches /config.json before rendering (main.tsx awaits it); schema {apiBaseUrl, sseUrl, defaultTheme, featureFlags} (doc 27 §4.11) validated at runtime; falls back to import.meta.env.VITE_API_BASE_URL and defaults when the file is absent (dev server).
  • lib/sse.ts: class SseClient { connect(campaignId?: string): void; on(type, handler): Unsubscribe; status: 'connecting'|'open'|'closed' } wrapping EventSource(sseUrl + '?campaign_id=&last_event_id=&token='); tracks the last event id; reconnects with exponential backoff + jitter (cap 30 s), because the browser's built-in retry does not cover 401/5xx.
  • lib/sseBridge.ts: a table mapping event types to cache operations: run.finished ⇒ prepend to the first page of ['campaigns', cid, 'runs'] and bump counts via setQueryData; campaign.updated ⇒ patch the campaign; mode.discovered/analysis.finished ⇒ invalidate modes/importance/risk; worker.updated ⇒ patch workers; alert ⇒ push to an alert store used by the console banner; resync ⇒ invalidate all campaign queries.
  • featureFlags gate the Trials/Reports navigation entries.
  • Standards: respect the layering contracts (doc 16 §2) and conventions in doc 34; no hard-coded tunables — thresholds/defaults come from typed settings (doc 27); no magic numbers (ruff PLR2004); public APIs typed (mypy strict) and documented.

Configuration keys

From the configuration reference (doc 27). Keys marked (new) must be added to the typed settings models and appear in the generated reference (T-003c).

  • apiBaseUrl / ROBOPROBE_WEB_API_BASE_URL
  • sseUrl / ROBOPROBE_WEB_SSE_URL
  • defaultTheme / ROBOPROBE_WEB_DEFAULT_THEME
  • featureFlags / ROBOPROBE_WEB_FEATURES

Acceptance criteria

  • Reconnect resumes without duplicates (MSW SSE mock).
  • Config override test.
  • Bridge table unit-tested for every event type in doc 12 §4.
  • Missing /config.json → defaults used, no crash.
  • Feature flag off hides Trials from the MarginRail.
  • Tests listed below added and green in CI; coverage of new code meets the gate in doc 18 §3.
  • Docs, config reference and CHANGELOG Unreleased updated where behaviour, keys or interfaces changed.
  • Definition of Done (doc 32 §3) satisfied.

Tests required

  • web/src/lib/sse.test.ts, config.test.ts, sseBridge.test.ts.

Dependencies

Blocked by: #163 (T-085b), #164 (T-085c)

Blocks: #169 (T-087a), #170 (T-087b), #171 (T-088a), #172 (T-088b), #173 (T-089a), #176 (T-110a), #177 (T-110b), #180 (T-112a), #182 (T-113a), #183 (T-113b), #185 (T-116)

Parallelization notes

Files / paths owned by this task — avoid editing other paths; shared files (pyproject.toml entry points, cli/main.py, api/routers/__init__.py, router.tsx, docker/compose.yaml, ci.yml) are append-only:

  • web/src/lib/config.ts
  • web/src/lib/sse.ts
  • web/src/lib/sseBridge.ts
  • web/public/config.json

Independent files.

Definition of Done

Per doc 32 §3 and AGENTS.md §5: lint, format, mypy strict and import-linter green; tests added and passing; docs updated; PR template completed with Closes #<this issue>; Conventional Commit messages referencing T-085d (doc 16 §6); commits authored only by the repository owner identity (AGENTS.md §4); CI green; reviewer checklist (doc 32 §5.1) satisfied.

References

Design docs: doc 13 §4 · doc 13 §5 · doc 12 §4 · doc 14 §6 · doc 27 §4.11

Requirements: FR-DSH-002 · NFR-DEP-001 (traceability: doc 28)

External:

Activity

  1. added this to the M8 — Dashboard milestone on Nov 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:dashboardReact web dashboardmilestone:M8M8 — Dashboardpriority:P0Critical path / blocks otherssize:S<= 1 daytaskChild task of a milestone epictype:featureNew functionality

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions