GitNexus/gitnexus-web
Ankit Verma a839d029ac
feat(api): report branch and index freshness on the serve repo routes (#3232)
* feat(api): report branch and index freshness on the serve repo routes

`GET /api/repos` and `GET /api/repo` now return the branch an index was
built from, its `lastCommit`, and — where it can be computed — how far
behind the working tree it is. All of it already existed: the fields are
on `RegistryEntry`, and `checkStalenessAsync` is the helper MCP
`list_repos` and `gitnexus status` already use. Only HTTP never asked.

#3199 made this pointed. A branch-pinned analyze registers its own entry,
so one repository yields two rows in /api/repos, and telling them apart
over HTTP meant pattern-matching the clone-directory suffix — a layout
detail that is trimmed for long refs and absent for path-registered repos.

Staleness is reported in the shape `list_repos` already returns: present
only when the index is behind, carrying commitsBehind and hint. It is
meaningful for path-registered repos; a url-registered repo is cloned
--depth 1, so its recorded commit is HEAD and a diverged history cannot be
walked by rev-list anyway. Documented in repo-projection.ts rather than
left to be discovered.

The projections live in their own module so the field list is assertable.
Route-inline, they were reachable only by booting a server, which is how
`branch` stayed unexposed while `gitnexus list` printed it.

/api/repos also gains the rate limiter it lacked: this change makes one
unauthenticated GET cost a `git rev-list` per registered repo, the shape
this codebase already limits elsewhere.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* fix(api): bound the staleness probe and keep liveness off the fan-out route

Addresses the tri-review on #3232.

P1. `checkStalenessAsync` caught every git ERROR but not a HANG — a working
tree on a disconnected mount or behind a stuck lock never settles, and
/api/repos fans that out once per registered repo. Worse, the web liveness
probe used /api/repos on a 2s budget and re-polls on failure, so each failed
probe stacked another N children on a server that was actually healthy.

Two independent fixes, because either alone still leaves a sharp edge:
- `execFileAsync` now carries a 5s timeout, so a hang is killed and routed
  into the same fail-closed "not stale" answer the existing catch already
  gives a bad SHA. This also protects MCP `list_repos`, which shares the
  helper.
- `probeBackendStatus` (and `isDatabaseReady` through it) asks /api/health
  instead. Liveness should not cost one subprocess per indexed repo. Health
  sits behind the same /api/* edge gate, so the 401 "gated vs absent"
  distinction is preserved.

P2. rate-limit.test.ts pins which routes carry a limiter so a dropped one
fails a test before CodeQL has to catch it; /api/repos was newly limited but
not pinned. Added, and verified it fails when the limiter is removed.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
Co-authored-by: Gergő Magyar <gergomagyar@icloud.com>
2026-09-09 17:28:45 +01:00
..
e2e fix(web): use repo path identity in switcher (#2420) 2026-07-11 11:43:47 +01:00
src feat(api): report branch and index freshness on the serve repo routes (#3232) 2026-09-09 17:28:45 +01:00
test feat(indexing): add Objective-C semantic indexing support (#3179) 2026-09-09 09:40:21 +00:00
.gitignore gitnexus wal cleanup preventing reindexing issue fixed 2026-02-06 06:35:15 +05:30
index.html feat: configure prettier with pre-commit hook (#563) 2026-03-28 14:58:04 +00:00
package-lock.json chore(deps)(deps-dev): bump joi (#3231) 2026-09-09 06:37:16 +01:00
package.json chore(deps)(deps-dev): bump @testing-library/react in /gitnexus-web (#3143) 2026-09-03 06:20:05 +01:00
playwright.config.ts feat: configure prettier with pre-commit hook (#563) 2026-03-28 14:58:04 +00:00
tsconfig.app.json feat: unify web and cli ingestion pipeline (#536) 2026-03-28 14:07:11 +00:00
tsconfig.json feat: configure prettier with pre-commit hook (#563) 2026-03-28 14:58:04 +00:00
tsconfig.node.json feat: merge gitnexus-mcp into gitnexus package - unified CLI+MCP 2026-02-04 01:12:41 +05:30
vercel.json ci(web): use npm ci for deterministic Vercel installs (#1764) 2026-05-22 05:08:42 +01:00
vite.config.ts feat: add docker support (#848) 2026-04-18 08:39:18 +01:00
vitest.config.ts feat(web): Introduce Tree View and Circles View in Web Viewer (#1799) 2026-05-26 18:05:50 +01:00