Skip to content

Phase 6: Fix duplicate-enrichment dispatch + git-push race (#755) - #763

Merged
neuromechanist merged 2 commits into
feature/issue-749-epic-import-robustnessfrom
feature/issue-755-phase6-enrich-race
Jun 16, 2026
Merged

neuromechanist merged 2 commits into
feature/issue-749-epic-import-robustnessfrom
feature/issue-755-phase6-enrich-race

Conversation

@neuromechanist

Copy link
Copy Markdown
Contributor

Summary

Metadata enrichment raced itself: a push to README/dataset_description fires /webhooks/github → dispatches run-enrichment.yml (client-commits), while the import-finalize / admin-reindex path runs enrichDataset in-process (force=true) and commits server-side. Both PUT .nemar/metadata.json to the same ref ~2s apart; the loser failed ("D1 cache is ahead of the repo").

Root cause split:

  • The workflow client-side git push already rebase-retries (run-enrichment.yml) → safe.
  • The server-side createOrUpdateFile (Contents API) threw on the 409 stale-SHA with no retry — the actual failing path.
  • run-enrichment.yml had no concurrency group, so N dispatches ran in parallel.

This PR (backend half):

  • Wraps createOrUpdateFile's GET-sha → PUT in a 3-attempt refetch-retry, gated by a new pure isContentsApiShaConflict(status, body) (409, or 422 with a sha/"does not match"/"fast forward" message — mirrors the existing isFastForwardConflict422 + commitFilesAsTree 422 loop). Last-writer-wins, no failure; closes the D1-ahead-of-repo divergence. Benefits every createOrUpdateFile caller.

The source_hash guard already no-ops sequential duplicates; .nemar/metadata.json is already excluded from ENRICHMENT_TRIGGER_PATHS (#643). Cross-repo concurrency group: nemarDatasets/.github#.

Closes #755
Part of epic #749

Test plan

  • bun test (293 pass; new no-mock isContentsApiShaConflict cases — 409 always, 422-by-message, unrelated-422 not retried, non-conflict statuses never retried); tsc + biome clean.
  • Gated live: reindex/re-import a dataset under concurrent dispatch → no commit failure; the workflow concurrency group cancels redundant runs.

Two concurrent enrichments (push-webhook run-enrichment.yml + in-process
admin-reindex/import enrichDataset) both PUT .nemar/metadata.json to the same
ref; the loser failed. The workflow client-push already rebase-retries, but the
server-side createOrUpdateFile (Contents API) threw on the 409 stale-SHA with no
retry. Wrap its GET-sha->PUT in a 3-attempt refetch loop, gated by a new pure
isContentsApiShaConflict(status, body) (409, or 422 with a sha/does-not-match/
fast-forward message; mirrors isFastForwardConflict422). Last-writer-wins, no
non-fast-forward failure; also closes the D1-ahead-of-repo divergence. No-mock
detector test.
@github-actions

github-actions Bot commented Jun 16, 2026 •

Copy link
Copy Markdown

📦 Package Preview

Your package is ready to test!

bun install -g nemar-cli@PR763

Version: 0.8.53-PR763.af1acc3
Commit: af1acc3


🤖 Updated on each push.

(1) Narrow the 422 conflict regex: drop the bare 'sha' alternation (it
over-matched unrelated 422s like 'Invalid sha for author' -> spurious retries);
the 409 arm already covers the stale-blob conflict, and the real 422 phrases are
'does not match'/'not a fast forward'. (2) Add the unreachable-guard throw after
the retry loop, matching commitFilesAsTree, so a future refactor can't silently
return void. +tests for the no-over-match cases.
@neuromechanist
neuromechanist merged commit ab44237 into feature/issue-749-epic-import-robustness Jun 16, 2026
1 check passed
@neuromechanist
neuromechanist deleted the feature/issue-755-phase6-enrich-race branch June 16, 2026 23:29

This branch was previously deployed

1 inactive deployment
npm — af1acc38 Deployed Jun 16, 2026 by neuromechanist via publish #1412
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