Skip to content

feat(resumption): implement paused task filtering during unpause replay - #972

Merged
andrzejfudro merged 1 commit into
mainfrom
feat/resumption-task-filtering
Sep 24, 2026
Merged

andrzejfudro merged 1 commit into
mainfrom
feat/resumption-task-filtering

Conversation

@andrzejfudro

@andrzejfudro andrzejfudro commented Sep 23, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Adds live WorkUnit task filtering to the ESS unpause resumption worker so obsolete and terminal tasks are marked with skipped resolution status (with structured skip reasons logged) instead of being replayed to Kubernetes.

Key Changes

  • internal/storage/spanner/pausedtask: Extended PausedTask with WorkUnit *essmsgpb.WorkUnit (with deep-copy isolation in Fake) and defined ResolutionStatusReplayed = "replayed" and ResolutionStatusSkipped = "skipped".
  • cmd/experiment_state_server/resumption/filter.go: Implemented ShouldSkipTask evaluating the 4 filtering rules (superseded execution ID, terminal execution state, update while paused, and stale update priority), returning (bool, TaskFilterReason).
  • cmd/experiment_state_server/resumption/worker.go: Integrated ShouldSkipTask and parent WorkUnit integrity checks into replayBatch, logging the skip reason and marking skipped tasks with ResolutionStatusSkipped. Passed task.WorkUnit to EnqueueWorkUnitTask for replayed tasks.
  • Tests: Added comprehensive unit test matrices in filter_test.go, worker_test.go, and fake_test.go.

Verification

  • bazel test //cmd/experiment_state_server/resumption/... //internal/storage/spanner/pausedtask/... (Passed)
  • ./.githooks/pre-commit (Passed)

TAG=agy
CONV=f9e059b6-7b63-42cf-aee9-8c4aaeabedd1

@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 implements task filtering logic during unpause resumption in the experiment state server. It introduces a new ShouldSkipTask function to evaluate paused tasks against their live WorkUnit state based on four terminal rules, updating the resumption worker to skip obsolete or terminal tasks. The feedback suggests adding defensive nil checks for the task object, its parent WorkUnit, and the current execution in both the resumption worker and the filtering logic to prevent potential nil pointer dereferences and server panics.

Extend pausedtask.PausedTask with its parent WorkUnit and define
ResolutionStatusReplayed and ResolutionStatusSkipped. Implement ShouldSkipTask
in resumption/filter.go to evaluate paused tasks against live WorkUnit state
across the 4 terminal and obsolete rules, and wire filtering into
ResumptionWorker.replayBatch.

TAG=agy
CONV=f9e059b6-7b63-42cf-aee9-8c4aaeabedd1
@andrzejfudro
andrzejfudro force-pushed the feat/resumption-task-filtering branch from c3e84db to 3c8b388 Compare September 24, 2026 07:26
@andrzejfudro
andrzejfudro marked this pull request as ready for review September 24, 2026 07:30
@github-actions
github-actions Bot requested a review from AntonTyb September 24, 2026 07:30

@AntonTyb AntonTyb left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

general design question - what is the approach to storing information/spec for the tasks going thru queue (aka Redis)? asking as this is a non-trival element as it represent (short term) state...

@andrzejfudro

Copy link
Copy Markdown
Collaborator Author

@AntonTyb The general flow is:

  1. During the pause, tasks are intercepted and buffered to PausedTasks in Spanner.
  2. During resumption, ESS receives a trigger message (SCHEDULING_RESUME) via Redis stream to initiate the resumption process.
  3. In the resumption worker:
    • Fetches a batch of paused tasks from Spanner joined with the current parent WorkUnit.
    • Evaluates the live WorkUnit state to filter out tasks that became obsolete or terminal while paused (what this PR implements).
    • For valid tasks, dynamically reconstructs the fresh Redis payload (ActuatorPayload) and enqueues it to xmc-tasks-stream for Actuator to consume and immediately ACK.
    • Marks the tasks as processed in Spanner (replayed or skipped), and repeats until all pending tasks are cleared.

To directly answer your question:
PausedTasks only stores minimal metadata and ActionProto; the source of truth remains the WorkUnit. During replay, we fetch the live WorkUnit via SQL join, allowing EnqueueWorkUnitTask to construct a fresh, valid payload on the fly rather than keeping static/stale state in Redis.

one note here: I still operate here on the in-memory stubs instead of Spanner as this is still work-in-progress but this is the direction.

@AntonTyb

Copy link
Copy Markdown
Collaborator

@AntonTyb The general flow is:

  1. During the pause, tasks are intercepted and buffered to PausedTasks in Spanner.

  2. During resumption, ESS receives a trigger message (SCHEDULING_RESUME) via Redis stream to initiate the resumption process.

  3. In the resumption worker:

    • Fetches a batch of paused tasks from Spanner joined with the current parent WorkUnit.
    • Evaluates the live WorkUnit state to filter out tasks that became obsolete or terminal while paused (what this PR implements).
    • For valid tasks, dynamically reconstructs the fresh Redis payload (ActuatorPayload) and enqueues it to xmc-tasks-stream for Actuator to consume and immediately ACK.
    • Marks the tasks as processed in Spanner (replayed or skipped), and repeats until all pending tasks are cleared.

To directly answer your question: PausedTasks only stores minimal metadata and ActionProto; the source of truth remains the WorkUnit. During replay, we fetch the live WorkUnit via SQL join, allowing EnqueueWorkUnitTask to construct a fresh, valid payload on the fly rather than keeping static/stale state in Redis.

one note here: I still operate here on the in-memory stubs instead of Spanner as this is still work-in-progress but this is the direction.

so let me phrase this question differently - if the current setup is implemented as is and we make changes to the structure of the message going thru the queue - will it result in Major or Minor or Patch version change (assuming no other changes)? and then on user side - when rollout occurs with some message in the queue - will new code be always able to deal with new message structure or can it result in a breaking (non-backward compatible) change and thus should be flagged as a bigger change?

@AntonTyb AntonTyb left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

correlation to versions and backward compatiblity question asked in comment

@andrzejfudro

Copy link
Copy Markdown
Collaborator Author

@AntonTyb Overall the convention of working with protobufs is to never introduce breaking changes at once (by that I mean e.g. changing the type of existing fields) - it should always follow the pattern of deprecating old fields and introducing new ones. There should always be a transition window in which both structures are supported by the code, and that marks the distinction between minor and major bump depending on when we drop the fallback code.

Let's say that an invasive change is being made to action proto - at this point the Actuator must still handle messages that have an older payload. This is not unique to pause scheduling: an upgrade can happen while tasks are in-flight in the Redis queue, and those older messages need to be handled cleanly after the rollout.

What pause scheduling changes is the timeframe for how long a message can be persisted: seconds in normal queue operations vs. hours or days for paused tasks.

So to answer directly:

  1. If we change the structure of an action, we must maintain a fallback for the older structure; this is a Minor version bump
  2. Whenever we remove the fallback code for the old structure, that is a Major bump.
  3. For purely additive optional fields, it is a Minor bump

@AntonTyb

Copy link
Copy Markdown
Collaborator

@AntonTyb Overall the convention of working with protobufs is to never introduce breaking changes at once (by that I mean e.g. changing the type of existing fields) - it should always follow the pattern of deprecating old fields and introducing new ones. There should always be a transition window in which both structures are supported by the code, and that marks the distinction between minor and major bump depending on when we drop the fallback code.

Let's say that an invasive change is being made to action proto - at this point the Actuator must still handle messages that have an older payload. This is not unique to pause scheduling: an upgrade can happen while tasks are in-flight in the Redis queue, and those older messages need to be handled cleanly after the rollout.

What pause scheduling changes is the timeframe for how long a message can be persisted: seconds in normal queue operations vs. hours or days for paused tasks.

So to answer directly:

  1. If we change the structure of an action, we must maintain a fallback for the older structure; this is a Minor version bump
  2. Whenever we remove the fallback code for the old structure, that is a Major bump.
  3. For purely additive optional fields, it is a Minor bump

and the proposed implementation will support this behavior?

@AntonTyb AntonTyb left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

chg mngt question

@andrzejfudro
andrzejfudro added this pull request to the merge queue Sep 24, 2026
Merged via the queue into main with commit d2b35db Sep 24, 2026
12 checks passed
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.

2 participants