Skip to content

fix(api): answer bulk load only after saving - #662

Merged
DerekRoberts merged 2 commits into
mainfrom
fix/bulk-load-after-save
Oct 9, 2026
Merged

DerekRoberts merged 2 commits into
mainfrom
fix/bulk-load-after-save

Conversation

@DerekRoberts

@DerekRoberts DerekRoberts commented Oct 9, 2026 •

Copy link
Copy Markdown
Member

POST /api/pub-code/bulk-load started the database writes and sent 200 straight away. If saving failed, the crawler still saw success, so the scheduled crawl went green even when nothing was stored.

Changes

  • bulkLoad now waits for insertOrUpdate and answers 200 only after the entries are saved.

  • A save failure goes to the handler's existing catch: it's logged, emailed when EMAIL_RECIPIENTS is set, and answered with 500 { message: "Internal server error" }. The crawler already exits 1 on an error response, so a failed load now fails the scheduled run.

  • The sendEmailForError helper was only used by the old fire-and-forget path, so it's removed.

  • New tests in api/test/bulk-load.test.js:

    • a failed save answers 500;
    • 200 is sent only after a slow save finishes.

    Both fail on the old code.

Tests and CI

The new tests need no database. They run in CI's API Tests job (added in #658, now on main). All 8 API tests pass there, including #658's MongoDB integration tests, which poll for the save and so work with or without this change.

Because the response now waits for the save, a very large payload could take longer to answer. Sequential saves of a few hundred entries should finish well within the route timeout.


Thanks for the PR!

Deployments, as required, will be available below:

Please create PRs in draft mode. Mark as ready to enable:

After merge, new images are deployed in:

Bulk load answered 200 before the entries were written, so the crawler never saw a database failure and its run looked successful. The handler now waits for the save, and a failure goes to the existing catch: it is logged, emailed when recipients are set, and answered with 500, which makes the crawler exit 1.
Copilot AI balanced review requested due to automatic review settings October 9, 2026 18:36
@DerekRoberts DerekRoberts self-assigned this Oct 9, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The implementation correctly propagates persistence failures and the focused tests cover the regression.

0 open findings

What changed in this PR

Ensures bulk-load requests report success only after database persistence completes.

Changes:

  • Awaits bulk insert/update operations and routes failures through existing error handling.
  • Removes obsolete fire-and-forget error-email helper.
  • Adds tests for save failures and delayed saves.
File Description
api/​src/​services/​pub-code-service.js Awaits persistence before responding.
api/​test/​bulk-load.test.js Verifies failure and response-order behavior.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@DerekRoberts
DerekRoberts merged commit 5c2e17b into main Oct 9, 2026
18 checks passed
@DerekRoberts
DerekRoberts deleted the fix/bulk-load-after-save branch October 9, 2026 18:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants