Scaffolding: Federation sync app creation#298
Conversation
|
I'll add more comments after those are addressed to reduce the noise |
7bcbcba to
b4788db
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 3 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit a973a15. Configure here.
| def _resolve_gateway_api_key(peer: PeerInfo) -> str: | ||
| if peer.gateway_export_api_key: | ||
| return peer.gateway_export_api_key | ||
| return os.environ.get("FEDERATION_SYNC_SERVER_API_KEY", "").strip() |
There was a problem hiding this comment.
Peer bootstrap uses local API key
High Severity
The _resolve_gateway_api_key function incorrectly falls back to the local FEDERATION_SYNC_SERVER_API_KEY for remote peers when peer.gateway_export_api_key is not explicitly set. This causes 401 authentication errors when bootstrap_all_peers attempts to fetch metadata, as remote gateways expect their own specific API keys, preventing historical data synchronization.
Reviewed by Cursor Bugbot for commit a973a15. Configure here.
| hello = hello.model_copy(update={"timestamp": datetime.now(UTC)}) | ||
|
|
||
| _peer_registry(request).register(hello) | ||
| return {"status": "registered", "site_name": hello.site_name} |
There was a problem hiding this comment.
Site-hello skips peer data backfill
Medium Severity
site-hello only updates the in-memory PeerRegistry. It never pulls the registering peer’s export lists into local fed-* indices. When an already-running site receives hello from a newly started peer, that peer’s existing public assets are not indexed until a full restart bootstrap.
Reviewed by Cursor Bugbot for commit a973a15. Configure here.
|
|
||
| COPY pyproject.toml ./ | ||
| COPY sds_federation ./sds_federation | ||
| RUN uv sync --no-dev |
There was a problem hiding this comment.
Docker build omits lockfile
Medium Severity
The image copies only pyproject.toml and source, then runs uv sync --no-dev without uv.lock or --frozen. Gateway Dockerfiles copy the lockfile and sync frozen; federation builds therefore resolve floating dependency versions and can diverge from tested resolves.
Reviewed by Cursor Bugbot for commit a973a15. Configure here.
There was a problem hiding this comment.
let's add a redeploy recipe for consistency with the other services; redeploy: build -> down -> up -> logs.
| search-path = ["sds_federation"] | ||
|
|
||
| python-platform = "linux" | ||
| python-version = "3.13" |


In this PR:
federation/(v1) application with:services:bootstrap.py: for initialization of federated data from home site and peers (including when new peer is added)fed_index.py: for handling (external peer) asset indexing on webhook eventslocal_events.py: for handling redis dispatches to fetch local datapeer registry.py: for registering new peers and holding site information from site hellospeer_sync.py: for packaging and sending asset data to peer sites (through their webhook routes)routes:health.py: (stub for now) for pinging site health (is connection established?)webhooks.py: for receiving payloads FROM peers to index into LOCAL federated asset indices as well as asite-hellohook to confirm federation between peersschemasandmodels: for type checking and providing data structures to federation configs, events, and documents (how asset docs are represented byFederatedDatasetDoc,FederatedCaptureDocmay warrant further consideration re: anticipating schema flexibility)mainapp that subscribes to redis events for picking up signals from gateway (handled in PR Scaffolding: Federation gateway setup #299)Note
High Risk
New cross-site replication path with API-key minting, OpenSearch writes, and peer webhooks; misconfiguration or weak origin checks could affect federated metadata integrity across deployments.
Overview
Introduces a new
federation/FastAPI sync service that keeps federated dataset/capture metadata in shared OpenSearch indices and exchanges updates with peer sites.Runtime flow: On startup, bootstrap mints or uses a gateway export Api-Key (
FEDERATION_SYNC_DRF_TOKEN→get-federation-sync-api-key), pulls local and peer/federation/export/lists intofed-*indices, then sendssite-helloto configured peers. A Redis subscriber on site-scopedfederation:events:*channels loads the local doc from OpenSearch (after gateway indexing) and POSTsdataset-updated/capture-updatedwebhooks to peers; inbound webhooks index peer docs with stale-event guards. Peersync_service_urlcan be updated fromsite-hello; optional peer CA paths support TLS verification.Ops & tooling: Docker/compose (local + prod),
justfile, dev PKI script,/sync/healthoperational checks, and sharedfederation-shared.envdocs for sync credentials. Repo pre-commit gains federation-specific ruff, deptry, and pyrefly hooks.Tests: Broad pytest coverage (regression, integration, two-site mesh) without a live gateway.
Reviewed by Cursor Bugbot for commit a973a15. Bugbot is set up for automated code reviews on this repo. Configure here.