feat(native): migrate SwarmPinService onto DbClient (#176, stacked on #209)#210
feat(native): migrate SwarmPinService onto DbClient (#176, stacked on #209)#210Dewinator wants to merge 1 commit into
Conversation
…ollow-up to PR #209 First service migrated off the `(supabaseUrl, supabaseKey)` pattern and onto the shared DbClient surface that PR #209 introduced. Stacked on top of `agent/db-client-factory` (PR #209) — that branch must merge first. `mcp-server/src/services/swarm-pin.ts`: - Constructor now takes `DbClient` (PostgrestClient | PGliteAdapter) instead of url + key. The service no longer constructs its own SupabaseClient; it consumes the one its caller hands in. - `defaultDeps()` widens `db` locally because TypeScript can't unify the .from() generic signatures across the two backends, even though the chain shape is runtime-identical (gated by pglite-adapter contract tests). The widening is local to the closure so it doesn't leak into the rest of the service. - Dropped the `@supabase/supabase-js` import — the service now lives entirely on the DbClient abstraction. `mcp-server/src/index.ts`: - Constructs a single PostgrestClient inline for swarm-pin, in the same style as middleware/{absorber,digester,prime-fetcher}.ts. The other ~17 service constructors still take (url, key) — they will migrate one-by-one, with the index.ts module-level boot moved to `await createDbClient()` once enough services are on the DbClient surface to make the async refactor worth its blast radius. - Comment marker explains why the mode-switch (MYCELIUM_USE_PGLITE=1) isn't yet wired here — that lights up when index.ts goes async. `mcp-server/src/__tests__/swarm-pin.test.ts`: - Constructor calls now pass a typed-but-empty STUB_DB cast. The orchestration tests inject SwarmPinDeps so the underlying client is never touched — the cast is purely to satisfy the new signature. - All 14 tests still pass: buildPinReason (5), pinLesson orchestration (6), swarmPinLesson ethics-gate (2), schema validation (1). Validation: npm run build → clean node --test dist/__tests__/swarm-pin.test.js → 14/14 passed node --test dist/__tests__/db-client.test.js → 4/4 passed (no regression) node --test dist/__tests__/*.test.js → 1010/1011 passed, 1 skipped, 0 failures Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The previous "0 PRs offen" snapshot is stale: the agent itself opened a 4-PR queue in the last 4 ticks (#208 standalone + #209→#210→#211 stack). Refresh the Aktiver-Code-Bestand block to credit landed sub-tasks (#202 DATA_DIR, #203 Tauri shell, #204 CI gate, #205 migration helpers) and add a Queue-Stand note that names the open stack, the linear merge constraint, and the ~19 still-supabase-direct services that the DbClient migration sub-story will work through atomically. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…ture) + 26h Reed-lag Last refresh (ec8a088, tick 173) captured the 4-PR native-app cluster (#208/#209/#210/#211) right after Reed drained #202-#207. Tick 174 then opened PR #212 (W4.1 echo-chamber row 4), which is off-track from the native-app cluster — it's a Wave-4 fixture PR against issue #196, not a DbClient or sidecar-bundle PR. CLAUDE.md still framed the queue as 4 PRs all in one narrative; this corrects it to 5 PRs with the fixture-PR called out separately, and surfaces the empirical Reed-lag (≈26 h since the 2026-05-03 10:24 UTC merge wave) so the next tick has the right baseline for the queue-too-deep guard. Also corrects ~21 → 22 (true grep count today on main) for the Supabase-direct service file count, with explicit "verbleibend nach Merge: 20" so the next DbClient-migration tick can locate the right service to pick. No production code touched; pure CLAUDE.md doc-accuracy fix, direct-to-main per the agent-loop convention for risk-free doc refreshes.
The bird's-eye doc lagged the 2026-05-03 merge wave (PRs #202–#207 landing sub-tasks 1, 2, 3-scaffold, 4, 5, 7-core) and the W3 spike chain that settled the empirical mDNS budgets on `main`. Changes: - Wave 1 row: 9-PR queue → 5-PR queue (#208 sidecar bundling closing sub-task 3; #209→#210→#211 linear DbClient migration stack; unrelated W4.1 fixture #212). Note the 22-services DbClient sub-story with 2 already in flight. - Wave 3 row: design-spike-only → 11-spike chain on `main` with named empirical budgets (64 KiB / 2 000 ms hostile-fetch, 5-s/3-fail heartbeat → 15 s eviction, ~1.3 s cold-rebrowse settle, 260 ms wake republish, 4 000 ms blocked-network threshold from K=10 trials). Cross-platform re-validation (Linux/Avahi, Windows) named as the open item before locking the library pick. - Wave 1 narrative: matches the 5-PR reality, removes stale "9 PRs 998/999 tests green" claim, keeps the queue-drain gate on sub-tasks 6/8/9/10. Verified: 11 spike files in experiments/swarm-discovery/, PRs #202–#207 all merged (gh pr list --state merged), 5 open PRs all CLEAN+MERGEABLE. Refresh date bumped to 2026-05-04. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…sub-task 3 After PR #210 (SwarmPin) and #211 (Skills) the canonical native-app-track.md just says "20 services remain" — but doesn't tell Reed which one to pick next, what shape each one is (Group A constructor-only vs Group B full SwarmPin-style swap), or how big it is. Adds docs/native-dbclient-migration-tracker.md with a per-service table: LOC, .from() / .rpc() callsite counts, current import (PostgrestClient vs SupabaseClient), and a recommended PR order (Group A smallest-first, then Group B smallest-first, then the agent-bus layer last). Linked from native-app-track.md DbClient sub-story section so it surfaces when Reed (or the next agent tick) picks PR #213. Empirical counts via grep against main HEAD a1fb5de — methodology block included so the table is reproducible. The numbers are upper bounds (some hits are in comments/strings); order-of-magnitude is what matters. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Local empirical validation 2026-05-05 (227th-tick) — first SwarmPin DbClient migration greenPR #210 had no prior comments; the stack-base PR #209 was revalidated against Setup
ResultsFocused replay of the SwarmPin suite: Migration shape — empirical cross-checkDiff vs. Stack readiness — no blockers from this PR
RecommendationMerge order remains #209 → #210 → #211 (linear stack). #210 is locally clean against today's main and the stack-base; no merge-conflict signals from 🤖 Posted by autonomous tick (mycelium 227th — local PR-validation, no new PR opened, queue-bound) |
Summary
First service migrated off the
(supabaseUrl, supabaseKey)constructor pattern and onto the sharedDbClientsurface that PR #209 introduced. Stacked onagent/db-client-factory— that PR must merge first.Why
PR #209 landed the
DbClientfactory +MYCELIUM_USE_PGLITEswitch as the foundation. The next step is migrating ~17 services off the legacy(url, key)pattern, one at a time, so each migration is reviewable on its own. SwarmPinService is the smallest service still on the legacy shape (~250 LOC, 14 tests, narrow surface) — ideal first target.Changes
mcp-server/src/services/swarm-pin.ts:DbClient(PostgrestClient | PGliteAdapter) instead of url + key. Service no longer constructs its own SupabaseClient.defaultDeps()widensdblocally because TypeScript can't unify the.from()generics across the two backends. Runtime chain shape is identical (gated bypglite-adapter.contract.test.ts). Widening is local to the closure — does not leak.@supabase/supabase-jsimport.mcp-server/src/index.ts:middleware/{absorber,digester,prime-fetcher}.ts. The other ~17 service constructors still take(url, key)— they will migrate one-by-one.MYCELIUM_USE_PGLITEmode-switch isn't yet wired here: it lights up whenindex.tsboot goes async (await createDbClient()), and the async refactor is worth doing once enough services consume DbClient to make the blast radius pay off.mcp-server/src/__tests__/swarm-pin.test.ts:SwarmPinDepsso the underlying client is never touched — the cast purely satisfies the new signature.Validation
Stacking
Base:
agent/db-client-factory(PR #209). When #209 merges to main, GitHub will auto-rebase this PR's base to main.Test plan
Related
🤖 Generated with Claude Code