refactor(orchestrator): centralize request termination#424
Draft
albertywu wants to merge 1 commit into
Draft
Conversation
albertywu
force-pushed
the
wua/refactor-request-termination
branch
from
July 22, 2026 18:27
53c4a82 to
e684e2d
Compare
Summary: Intent: - Remove duplicated terminal request state and log publication logic. - Keep existing controller behavior while standardizing CAS and idempotency handling. Changes: - Add a shared request terminal-state reconciliation helper with metadata support. - Migrate cancel, conclude, and merge-conflict failure paths to the helper. - Preserve declaration-level retryability for storage version conflicts.
albertywu
force-pushed
the
wua/refactor-request-termination
branch
from
July 22, 2026 18:56
e684e2d to
9b4145c
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
Centralizes existing request terminal-state reconciliation without changing the queue topology or pipeline behavior.
Scope: This is a code refactor. It does not change anything core to the architecture, so an RFC is not needed: the same controllers make terminal decisions, the same queues and payloads carry work, and the same request-log path materializes status. This PR only replaces duplicated terminal request CAS and log-publication code with a shared helper.
request.ReconcileTerminalStateonce for the affected request; conclude callsrequest.ReconcileTerminalStateonce for each batch member, passing the selected terminal outcome.RequestLogalready supportedmap[string]stringmetadata, but each terminal path constructed its log independently, so metadata propagation was call-site-specific.TerminalOutcome{LastError, Metadata}torequest.ReconcileTerminalState, which includes that context in the matching terminal request log.request.ReconcileTerminalStateperforms the terminal CAS, same-state log repair, competing-terminal preservation, version handling, and log publication in one implementation.request.ReconcileTerminalStatefor the shared state-and-log mechanics insubmitqueue/core/request.Helper call path: In every After case above, request terminal-state reconciliation and the matching log are performed by
request.ReconcileTerminalState. Unbatched cancel and merge-conflict handling call it directly; conclude calls it once for each member request. The helper does not update batch state.This preserves the existing request state-machine and request-log behavior.
concludestill consumes BatchID messages, individual requests are still terminated by the controller that owns the decision, and DLQ behavior is unchanged in this PR.ReconcileTerminalStateusageCancelledSucceeded,Failed, orCancelledmaps to requestLanded,Error, orCancelledbatch_id.ErrorLastError.Conceptual flow:
Future callers should use this helper only after deciding that a request must enter a terminal state and needs the matching public request log. The caller owns the business decision and supplies
State,LastError, andMetadata; the helper owns the CAS, version advancement, state-to-status mapping, idempotency, and log publication. Do not use it for non-terminal request transitions, batch transitions, or log-only events.Test Plan
✅
make lint && make check-tidy && make check-gazelle && make testRevert Plan
Revert this PR to restore per-controller request termination logic.
Stack