feat(scheduler): dispatch applies from workers#136
Draft
aparajon wants to merge 12 commits into
Draft
Conversation
There was a problem hiding this comment.
Pull request overview
This PR shifts apply execution to a durable queue + scheduler-worker dispatch model, so HTTP/webhook requests persist the apply and return quickly while background workers claim and start engine work (local and gRPC Tern), preserving observers and IDs.
Changes:
- Updated
Service.ExecuteApplyto enqueue apply/task records durably and wake scheduler workers instead of dispatching engine work inline. - Extended Local and gRPC Tern clients to dispatch queued applies from scheduler claims (including external_id syncing for gRPC).
- Updated integration/E2E/unit tests to start the scheduler where applies now require worker dispatch.
Reviewed changes
Copilot reviewed 20 out of 20 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| pkg/webhook/webhook_e2e_test.go | Starts scheduler in webhook E2E setup so queued applies are dispatched. |
| pkg/webhook/comment_observer.go | Updates observer documentation for queued/scheduler-based dispatch timing. |
| pkg/webhook/apply_handlers.go | Aligns webhook handler comments with enqueue-before-dispatch flow. |
| pkg/tern/observer.go | Clarifies pending-observer semantics vs API service’s pending-observer registry. |
| pkg/tern/local_control_resume.go | Adds queued-apply dispatch path for pending applies during resume. |
| pkg/tern/local_client.go | Updates pendingObserver comment to match new direct-Apply-only usage. |
| pkg/tern/grpc_client.go | Implements queued apply dispatch for gRPC mode and stores external_id after dispatch; adjusts metrics on completion. |
| pkg/tern/client.go | Updates client interface docs to reflect scheduler-claimed work semantics. |
| pkg/api/service.go | Adds scheduler synchronization primitives and per-target pending observer registry. |
| pkg/api/scheduler.go | Adds worker wakeups for queued applies and mutex-protects scheduler lifecycle. |
| pkg/api/proto_helpers.go | Removes now-unused helper for converting stored table changes to proto changes. |
| pkg/api/progress_handlers.go | Maps VSchema change type to vschema_update for API responses. |
| pkg/api/plan_handlers.go | Reworks apply to enqueue durable apply/task rows, attach observer, wake scheduler, and return apply_identifier. |
| pkg/api/handlers_test.go | Adds coverage for enqueueing + scheduler wake behavior and updates handler expectations (no inline dispatch). |
| integration/workflow_test.go | Starts scheduler in integration server setup. |
| integration/scheduler_test.go | Stops scheduler explicitly in test to validate subsequent recovery behavior. |
| integration/resolve_apply_id_test.go | Waits for scheduler to dispatch queued gRPC apply and populate external_id. |
| integration/hybrid_mode_test.go | Starts scheduler for hybrid local/remote targets. |
| integration/grpc_integration_test.go | Passes storage to gRPC client and waits for scheduler-dispatched external_id; starts scheduler. |
| integration/cli_test.go | Starts scheduler in CLI integration setups and passes storage to gRPC client. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
2472dfa to
1419f3d
Compare
1419f3d to
4a8eb4b
Compare
9b1402f to
e399bdf
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
/startmarks the apply claimable, wakes workers, and returns accepted/rejected without running schema change work in the HTTP handler/startis called before an apply reacheswaiting_for_deployThe wake fast path keeps the first-time CLI/webhook experience responsive: after an apply is accepted or restarted, users should see work start right away instead of waiting for the next scheduler poll. It is not a second queue; workers still claim from storage, and the normal polling loop remains the correctness path if a wake is dropped or coalesced.
🤖 Generated by Codex.