Skip to content

Client-side MOD-API federation (#415, Project 1) - #472

Merged
micheldumontier merged 16 commits into
mainfrom
design/mod-api-federation-415
Nov 24, 2026
Merged

micheldumontier merged 16 commits into
mainfrom
design/mod-api-federation-415

Conversation

@micheldumontier

Copy link
Copy Markdown
Contributor

Closes part of #415 (Project 1 of 2). Adds client-side MOD-API federation: GET /api/v1/ontologies?federated=true queries configured remote Semantic Artefact Catalogues at request time, dedups their artefacts against the local page by IRI, and returns them in a separate federated block — storing nothing. Carries the ESWC live-demo use case.

Design & plan (in this PR)

  • docs/superpowers/specs/2026-11-24-mod-api-federation-design.md — design (incl. an independent review folded in)
  • docs/superpowers/specs/2026-11-24-bulk-discovery-ingest-feasibility.md — Project 2 feasibility/go-no-go (not built here)
  • docs/superpowers/plans/2026-11-24-mod-api-federation.md — the TDD plan this implements

What's included

  • ontoexplorer/modules/federation/: config + Peer model, per-peer MOD-API response adapters (handles our real flattened JSON-LD @graph), an SSRF/auth/redirect/size-capped HTTP client, and a concurrent fan-out service (partial-failure tolerant, Redis-cached, dedup+append).
  • GET /api/v1/ontologies?federated=true (on list_ontologies) returns a separate federated: {catalogues, results} block — off by default (federation_enabled=False), zero behavior change when inactive, remote rows never interleaved into ontologies[].
  • Frontend: an "Include federated catalogues" toggle + an "Also found in other catalogues" section with safeHttp-guarded outbound links.

Safety

  • Allowlist-only (the federated param is a boolean; no caller-controlled URL ever reaches outbound); async_guarded_transport() + per-hop redirect re-validation + any https→http downgrade refused; per-peer secret resolved from env and sent only to the peer host; streaming response size cap; javascript:/data: can't reach an href (backend http(s)-only and frontend safeHttp).
  • A dead/slow/hung peer or hung Redis never degrades the core catalogue beyond the fan-out budget; a service failure degrades to a normal response (no 500).

Testing

  • 102 backend + 10 frontend federation tests pass (TDD; each task independently reviewed + an Opus whole-branch review). No new failures in touched areas (8 failures are pre-existing/unrelated).

Not in this PR (owner-gated)

  • The services-repo configmap enabling federation + the demo peers. The external demo needs two prerequisites: a reachable second OntoExplorer instance and an AgroPortal API key (+ its current MOD host). The code self-federates without them.
  • Project 2 (bulk discovery→ingest) — feasibility doc only; recommendation is gated MOD-API harvest, not auto-bulk GitHub.

🤖 Generated with Claude Code

micheldumontier and others added 16 commits November 24, 2026 11:48
Splits #415 into two projects after a design pass:

- Project 1 (build-ready): client-side MOD-API federation — query remote
  SACs at request time, RRF-merge + source-attribute, store nothing.
  Carries the ESWC live demo (self + AgroPortal peers). Allowlist-only,
  guarded-transport, partial-failure tolerant.

- Project 2 (feasibility/go-no-go): bulk discovery -> existing ingest
  pipeline (MOD-API harvest + GitHub OWL scan). Finding: the plumbing is
  trivial (ingest_ontology.delay), the project is the admission gate
  (dedup/license/quality/capacity). Recommend gated MOD-API harvest;
  do NOT auto-bulk GitHub (curated review queue instead); resolve #402
  + dedup-at-admission first.

Docs only; no code. Awaiting approval to plan/build Project 1.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Project 1 (federation):
- drop RRF for dedup+append (rrf_merge is 2-arg/same-corpus; local is
  single SQL page) — remote rows deduped vs local by IRI, returned in a
  separate federated.results block, never interleaved into Ontology[]
- auth first-class (OntoPortal/AgroPortal require an API key -> 401);
  AgroPortal host moved (lirmm.fr->agroportal.eu) + https->http + needs key
- client owns streaming size cap (guard has none) + explicit redirect policy
  (re-validate each hop, final host must be allowlisted)
- federation on first page only; named test coverage; Prerequisites section
  (second instance + AgroPortal key are owner decisions)

Project 2 (bulk ingest feasibility):
- add peer-politeness (outbound rate-limit) + provenance/freshness gates
- soften admission-time canonical-IRI dedup (unreliable; needs post-parse
  backstop); label capacity per-onto figure as directional

Docs only; no code.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…ased)

- Project 1: build-ready 7-task TDD plan (config → adapters → client →
  service → API → frontend → ops), with Global Constraints, Review Focus
  mapped to tasks, and the demo prerequisites called out as non-blocking.
- Project 2: phased program plan (Phase 0 prereqs #402/dedup/license →
  Phase 1 gate framework (first TDD-able) → Phase 2 MOD-API harvest →
  Phase 3 evaluate → Phase 4 GitHub review-queue), contingent on go/no-go.

Docs only; no code.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Federation is OFF by default. Peers parse defensively from
FEDERATION_PEERS_JSON (malformed -> [] with a warning); auth.secret_ref
names an env var and no secret is embedded.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…atch RecursionError

Task 1 review follow-ups (security-relevant, minor): base_url with embedded
userinfo is rejected (keeps "no secrets in parsed config"), invalid ports are
rejected, and pathological nested JSON (RecursionError) no longer escapes
get_federation_peers()'s never-raise guarantee. +2 tests.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…-API adapters

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…mbers, dedup, status Literal

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…, timeout

search_artefacts / fetch_catalogue over the SSRF-guarded transport, with a
manual redirect loop (allowlist + no https->http downgrade to non-allowlisted
host), auth sent only to the peer's own host, a streaming response byte cap,
and a per-peer timeout. Failures surface as a typed FederationFetchError with a
stable reason (unauthorized/timeout/oversize/blocked_redirect/error).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…old + streaming cap

Fix round 1 from review:
- _check_redirect now refuses ANY https->http downgrade before the allowlist
  decision, closing a cleartext-secret leak on a 302 from https to http on the
  peer's own allowlisted host (auth was re-attached because host still matched).
- cross-allowlisted-peer test proves A's secret is withheld when a redirect
  lands on peer B's host (B is actually contacted; the real withhold branch runs).
- oversize test now drives a multi-chunk async stream and asserts the transfer
  is aborted mid-stream, not after buffering the whole body.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…up+append

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
… to a cache miss

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…ock)

Fan-out to MOD-API peers only when federated AND federation_enabled AND
offset==0 AND q non-empty; started up-front so it overlaps the local query.
Remote rows are returned in a separate 'federated' block, never in ontologies[].

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…de, zero-peer paths

list_ontologies is now a thin wrapper over _list_ontologies_local so the
in-flight fan-out task is cancelled if the local query raises.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…alogues' section (#415)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…b a11y cue (#415)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…apikey)

Whole-branch review follow-ups:
- adapter landing-URL fallback now mirrors the client's {base_url}{mod_path}
  /artefacts construction instead of hardcoding /mod/, so a homepage-less
  artefact from a peer whose MOD-API isn't at /mod (e.g. AgroPortal /mod-api)
  gets a resolvable source_landing_url. Self peer sets mod_path="/mod".
- client fetch-failure log uses the typed reason / exception class, not the
  raw exception str, which for an apikey_param peer could stringify the URL
  and leak the key into logs.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@micheldumontier
micheldumontier merged commit 239ddd1 into main Nov 24, 2026
5 checks passed
@micheldumontier
micheldumontier deleted the design/mod-api-federation-415 branch November 24, 2026 17:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant