Commit 2c79382
Do start/end-change processing in the background (backend) (#3710)
This is based on https://github.com/overmindtech/workspace/pull/3709 and
combines all backend changes from
https://github.com/overmindtech/workspace/pull/3701 into a single
commit. To test, run `start-change` and `end-change` SLI commands (using
th eold endpoints) to verify that the state is correctly changed, with
jobs kicking off in the background).
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> **High Risk**
> High risk because it rewires change lifecycle processing and state
transitions to asynchronous jobs with new DB coordination primitives;
mistakes could leave changes stuck in-progress or skip snapshots/metrics
under concurrency and retry scenarios.
>
> **Overview**
> Start/end-change snapshot processing is moved to **background River
jobs**: the RPCs now enqueue `StartChangeWorker`/`EndChangeWorker` jobs
and return immediately, while workers handle gateway snapshotting,
status transitions, metric updates, and `all_modifications` population.
>
> To coordinate concurrency and retries, the PR adds
`start_change_in_progress`/`end_change_in_progress` flags on `changes`
plus a new `change_job_queue` table to safely queue an end-change
arriving during start-change completion, and introduces new SQL/queries
for atomic flag setting, row locking, and completion paths (including
“complete without snapshot” on final retry).
>
> Performance and reliability improvements include switching
`all_modifications` writes to a `COPY FROM` bulk insert API, adding
savepoint-isolated `populateAllModifications` in the end-change worker
to prevent transaction poisoning, and updating `RunTaskWorker` messaging
to reflect snapshot initiation rather than completion.
>
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
9807c52eeddf39e38ce05e2a47bfb934766b611c. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
GitOrigin-RevId: 7e0176d68698b54ea0f7cfbe1d72da7015a7c92a1 parent acd4153 commit 2c79382
2 files changed
Lines changed: 290 additions & 122 deletions
0 commit comments