Skip to content

refactor(pausescheduling): centralize pause scheduling repos and run pause writes in transactions - #1043

Merged
andrzejfudro merged 3 commits into
mainfrom
feat/pause-scheduling-storage-prep
Oct 1, 2026
Merged

andrzejfudro merged 3 commits into
mainfrom
feat/pause-scheduling-storage-prep

Conversation

@andrzejfudro

@andrzejfudro andrzejfudro commented Sep 30, 2026 •

Copy link
Copy Markdown
Collaborator

Author note

There will be a follow up PR with linking pause repositories with transactions. This is split to keep PRs smaller and overall all of it is done to make PR that will add migration and real spanner implementation as small as possible.

Summary

Prepares pause scheduling for Spanner: pause repos are now created in one place (storage, still as fakes), and pause writes in the actuator and ESS run inside RunInTransaction.

Key Changes

  • Storage: PauseSchedulingStore (PauseState() / PausedTasks()) on storage.Storage, backed by fakes in spanner.go for now. New WorkUnitTxRepository.UpdateWorkUnitStatus.
  • Actuator: HandlePause creates the paused task and sets SCHEDULING_PAUSED (read-modify-write via tx.WorkUnits) in a single transaction. Prod wiring takes the repos from storage.
  • ESS: resumption worker registration runs in a transaction. Prod wiring takes the repos from storage.
  • Health service: only a TODO. It has no storage today, and adding it needs lazy, non-fatal Spanner init.
  • Tests: handler/worker tests use MockStorage as the tx runner, plus tx failure cases.

Verification

  • bazel test //internal/storage/... //cmd/actuator/... //cmd/health_service/... //cmd/experiment_state_server/... (Passed)

TAG=agy
CONV=aca941d1-8c29-4820-96a9-0200c1071207

…ites in transactions

Initialize the pause state and paused task repositories inside storage
(still in-memory fakes) and expose them via PauseState()/PausedTasks(), so
switching to Spanner later is a single-place change. The actuator and ESS
now take the repos from storage instead of creating fakes themselves.

The actuator pause handler and the ESS resumption worker registration now
run inside RunInTransaction. The work unit status update goes through the
new WorkUnitTxRepository.UpdateWorkUnitStatus. The pause repos are still
called through their non-tx accessors; binding them to the transaction is a
follow-up.

TAG=agy
CONV=aca941d1-8c29-4820-96a9-0200c1071207

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request refactors the pause scheduling mechanism to use a transactional approach for buffering tasks and updating work unit execution statuses. It introduces a TransactionRunner interface to ensure atomicity, updates the Storage interface to expose repositories for pause state and paused tasks, and migrates status updates to use a more robust UpdateWorkUnitStatus method. My feedback highlights the need for a nil-check when fetching work units to prevent potential panics and suggests using spanner.CommitTimestamp for database update times to avoid clock skew issues.

@andrzejfudro
andrzejfudro marked this pull request as ready for review September 30, 2026 15:27
@andrzejfudro andrzejfudro changed the title refactor(storage): centralize pause scheduling repos and run pause writes in transactions refactor(pausescheduling): centralize pause scheduling repos and run pause writes in transactions Sep 30, 2026
@andrzejfudro andrzejfudro added the priority::2-high top of mind. should not wait. label Oct 1, 2026
Wrap batch resolution persistence in w.txRunner.RunInTransaction in ResumptionWorker.replayBatch so all pause scheduling writes execute within a transaction boundary.

TAG=agy
CONV=aca941d1-8c29-4820-96a9-0200c1071207
…xecutions

Replace the status-only UpdateWorkUnitStatus mutation with a transaction-scoped
TxRepository.UpdateWorkUnitExecutions that runs the existing merge, current
execution ID check, state transition guard, status history and experiment
status denormalization inside the caller's read-write transaction. The
transaction body of Repository.UpdateWorkUnitExecutions is moved unchanged into
a shared helper. Rename updateExecutionStatus to markExecutionSchedulingPaused.

TAG=agy
CONV=aca941d1-8c29-4820-96a9-0200c1071207
@andrzejfudro
andrzejfudro force-pushed the feat/pause-scheduling-storage-prep branch from 7e4e15b to 53196b1 Compare October 1, 2026 12:46
@andrzejfudro
andrzejfudro requested a review from pachopepe October 1, 2026 12:47
@andrzejfudro
andrzejfudro added this pull request to the merge queue Oct 1, 2026
Merged via the queue into main with commit 1c4b198 Oct 1, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

priority::2-high top of mind. should not wait.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants