Skip to content

fix: report what a repository sync actually did - #1922

Merged
joshunrau merged 1 commit into
mainfrom
fix/instrument-repo-sync-reporting
Nov 18, 2026
Merged

joshunrau merged 1 commit into
mainfrom
fix/instrument-repo-sync-reporting

Conversation

@thomasbeaudry

@thomasbeaudry thomasbeaudry commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

An administrator adding or syncing an instrument repository is now told what the sync did. A repository laid out in any way other than lib/{file,forms,interactive,series} used to register cleanly and import nothing, logged as a success with 0 imported, and the repositories page could report 22 imported while listing 12 of them. This was found on a live instance whose 22 forms sat under public/forms, where every page agreed that nothing was wrong.

Changes

  • Adding a repository that provides no instrument directories is refused, naming the four lib/* directories looked in and the index filenames looked for, instead of registering a repository with nothing in it.
  • A sync that matches nothing keeps the instrument list it already had, so a bad upstream commit or an unresolvable series no longer de-lists instruments that are still stored and still assignable to groups.
  • The repositories page counts and lists the instruments a repository provides through one function, so the column and the View dialog cannot disagree, and an instrument a repository provides but did not create is no longer missing from both.
  • A repository that provides two editions of one instrument lists both; the latest-edition collapse that hid one is gone.
  • The activity log records how many instruments a sync stored for the first time, and the Imported cell reads 22 (12 new) with 22 imported: 12 new, 10 already stored on hover. An entry that imported nothing, and one written before the field existed, read as the bare total.
  • A sync whose every instrument failed is reported as Failed rather than Partial success.
  • InstrumentRepoSyncLog gains a nullable createdCount, and createdCount becomes an accepted sortBy value for GET /v1/instrument-repos/sync/logs.

Decisions

  • createdCount is nullable rather than defaulted to 0. MongoDB has no migration here, so an entry written before this field has no count, which is not the same fact as having created nothing; the UI renders the two identically but the column keeps the distinction.
  • The new/already-stored split rides inside the Imported column rather than becoming columns of its own. Two numeric columns would take their width from the repository name, whose header cannot truncate, and admin-instrument-repos.spec.ts holds both tables to the 764px the admin page has. Real columns need something else dropped or a wider table.
  • The count resolves ids against the loaded instruments rather than reading instrumentIds.length directly, which costs a correct count on first paint: it shows the id count until the instruments load, then refines. The alternative kept the fast path but let the column claim an instrument the dialog could not show.
  • A wrongly laid out repository is a BadGatewayException. downloadAndExtractRepo already reports a wrong URL, a missing repository and an insufficient token the same way; BadRequestException in this module is reserved for a URL that fails to parse, before any upstream call.

Risks

  • An instrument a repository provides but did not create still has sourceRepoId: null, so the group-manage visibility rule treats it as manually uploaded. This change does not touch that; it is unchanged from before and stays as it was.
  • InstrumentsService.deleteById does not prune the deleted id from any repository's instrumentIds, so a stale id survives until the next successful sync. The count and the dialog now both leave such an id out, so the page is consistent, but the stored list stays wrong until then. Accepted: pruning on delete is the structural fix and belongs with that method, not here.

Notes

Verified against a live instance with two real repositories (26 and 27 instruments): the column matches the activity log's total, the hover split matches a sync that re-found 26 instruments and created 5 of them, and an entry written before createdCount existed still renders. Sync-log rows covering each rendering — refused import, all instruments failed, partial, re-found, unreadable repository — were inserted directly and inspected.

Adversarial review

Reviewed at commit 8adf22b. pnpm check: green.

Findings

  1. apps/api/src/instrument-repos/instrument-repos.service.ts:633 (with apps/web/src/routes/_app/admin/instrument-repos/index.tsx:232) — a sync in which every instrument fails to load still replaces instrumentIds with [], and now that the web page reads both the count and the View dialog off that list, such a sync makes a repository report zero instruments it in fact still provides — guard the case where nothing was matched, or keep the previously stored ids, so a failed pass never de-lists instruments the repository still provides.
  2. apps/web/src/routes/_app/admin/instrument-repos/index.tsx:232 — the repositories table's instrument count and the View dialog's instrument list are now derived from two different sources, so they disagree whenever an id in instrumentIds has no stored instrument — derive the count from the same function as the list once the instrument info has loaded, or prune the id on delete.

Fixed

    1. syncRepo replaces the stored instrument list only when the pass matched something, leaving lastSyncedAt untouched too, with the failures still recorded against the entry.
    1. The count resolves through providedInstruments, the same function the dialog lists, with instrumentIds.length only as the pre-query fallback.

Attestation

I, Claude Opus 5, attest that the review block above reports the adversarial review as it ran on the commit named, with every finding it returned.

Four ways the instrument repository pages disagreed with the sync behind them.

An import that discovered no instrument directories was recorded as a success with 0
imported. A repository laid out any other way downloads cleanly and yields nothing, so
that entry was indistinguishable from a genuinely empty repository, against the rule
that nothing fails silently. `importInstruments` now refuses it, naming the four
`lib/*` directories it looked in and what it looked for, so the entry reads FAILED with
an actionable reason and adding such a repository fails up front rather than
registering it with nothing in it.

A sync no longer replaces the stored instrument list unless it matched something. Every
instrument failing to load — a bad upstream commit, a series whose member edition is
gone — is not evidence that the repository provides nothing, and writing an empty list
would de-list instruments that are still stored and still assignable. The entry records
each failure, so such a pass is reported rather than hidden.

The repositories page counted and listed instruments by `sourceRepoId`, which records
which import created an instrument, while the activity log counted `instrumentIds`,
which is what the repository provides. The two differ for every instrument already
stored when the repository was registered: the import recovers its id from the conflict
and counts it, but leaves its provenance alone. A repository could report 22 imported
and list 12. Both the count and the dialog now resolve the ids the repository provides
through one function, so neither can drift from the other, and an id whose instrument
was since deleted is in neither.

The activity log recorded only the total, so an import of instruments already present
read as 22 new. A sync now also records how many it created, and the Imported cell
reads `22 (12 new)` with the whole split on hover. The field is nullable because Mongo
has no migration: an entry written before this has no count, which is not zero. An
entry that imported nothing reads as the bare total, since a run that stored nothing
has no split to show.

The status itself consulted neither count: a repository-level message read as a failure
and any instrument failure as a partial success. A readable repository whose every
instrument fails to compile or load records no message and nothing imported, so the log
announced "Partial success" beside an imported count of 0. A partial success needs a
part that succeeded, so such an entry now reads FAILED, while one that stored some of
its instruments and skipped others still reads PARTIAL.

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

Copy link
Copy Markdown

This pull request was closed because its body does not meet .agents/skills/opening-pr/SKILL.md:

  • The review block does not state pnpm check: green.

Fix the body with gh pr edit <number> --body-file <path>, then gh pr reopen <number>.

@github-actions github-actions Bot closed this Nov 17, 2026
@gdevenyi gdevenyi reopened this Nov 17, 2026
@github-actions

Copy link
Copy Markdown

This pull request was closed because its body does not meet .agents/skills/opening-pr/SKILL.md:

  • The review block does not state pnpm check: green.

Fix the body with gh pr edit <number> --body-file <path>, then gh pr reopen <number>.

@github-actions github-actions Bot closed this Nov 17, 2026
@thomasbeaudry thomasbeaudry reopened this Nov 17, 2026
@github-actions github-actions Bot added the Status: Waiting on Review Automated: unreviewed, pushed since the last review, or review re-requested label Nov 17, 2026
@joshunrau
joshunrau merged commit a25f979 into main Nov 18, 2026
12 of 14 checks passed
@joshunrau
joshunrau deleted the fix/instrument-repo-sync-reporting branch November 18, 2026 17:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Status: Waiting on Review Automated: unreviewed, pushed since the last review, or review re-requested

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants