feat minor bridge feat/phase-2g-bundle #86 / 100
AI Agent git-import/068377df · 85 days ago · May 2, 2026 · Diff

feat(bridge): auto-route /api/v1/index to background fn for big jobs (sync stays snappy)

PR 2 of the embedding-scale fix. Sync re-index now runs a cheap preflight (chunk + hash + cache lookup) and routes to the new bridge-index-background Netlify Function when the embed phase won't fit in the 60 s sync cap (estimate >= 30 s, chunks >= 500, first index, or post-dim-migration). Small-delta and cache-hit re-indexes still return inline in ~1 s.

The background function has a 15-min platform max (Netlify -background suffix), runs the same Express handler with globalThis.__bridge_internal_request set so it skips the routing decision, and is gated by HMAC over (canisterUid, vaultId, jobId, ts) signed with SESSION_SECRET (60 s replay window) plus the user's JWT.

A Netlify-Blob job lock with 16-min TTL prevents double-clicks from double-billing DeepInfra; releaseJobLock(expectedJobId) prevents a stale background fn from clobbering a fresh lock. A last-indexed sidecar (also Netlify Blob) feeds a new GET /api/v1/index/status that the Hub UI polls to render "Last indexed: N minutes ago" next to the Re-index button (passive, no live-progress bar).

Edge cases: kickoff failure releases the lock + returns 502; second click while a job runs returns 409 status:already_running with the existing jobId; local self-host without Blob store falls through to sync; older deploys without the status endpoint silently leave the UI line empty.

Tunable env (all clamped, sane defaults): INDEXER_SYNC_BUDGET_SECONDS (30, [5..55]), INDEXER_MAX_SYNC_CHUNKS (500, [50..5000]).

Tests: +84 (1881 total pass, 0 fail). Six new files cover the routing math, lock semantics, sidecar round-trip, HMAC sign/verify (incl. tamper + replay), and source-string contract asserts on the Express + UI wiring so a future refactor cannot silently drop the routing branch, lock acquire/release, or the "Last indexed" line.

sha256:2e950fbdf59124c4d3c0608f8c5d0120c0f4b6e206f2c9f8274c6ce8c280d229 sha
sha256:f8771a19bf9a717b44a386a099dc316808971cf1be26871f31f4e628f75226e3 snapshot

0 comments

No comments yet. Be the first to start the discussion.

To add a comment, use the Muse CLI: muse hub commit comment sha256:2e950fbdf59124c4d3c0608f8c5d0120c0f4b6e206f2c9f8274c6ce8c280d229 --body "your comment"