Repository navigation
feat(workflows): make run dispatch durable and fail loudly - #256
Merged
Merged
Conversation
A WorkflowRun was committed and then handed to Temporal by an inline RPC
whose result nobody read. TemporalService.start_workflow does not raise on
a failed RPC — it returns { ok: false, ... } — and WorkflowService.start
discarded that, recorded a `workflow_started` activity and returned the
run as if it had started. A `rescue StandardError` underneath logged one
line and returned the same run, so the only two ways a dispatch could fail
both ended in a success response.
Nothing re-drove such a run. The stale-run reaper only touches
`running`/`paused` runs past four hours, the admission reconciler does not
look at runs at all, and the existing outbox covers trigger events — the
hop before this one. A run created while Temporal was unreachable sat in
`pending` forever, indistinguishable from one the worker had not picked up
yet.
Two changes, and they need each other:
* Loud. dispatch! reads the result and raises DispatchFailed, so the
caller gets an exception and Sentry an event. A deployment that has
switched Temporal off is not a failure and does not raise: it has no
executor to strand a run from, and no relay either, since the relay is
itself a Temporal schedule.
* Durable. The run is enrolled in the outbox in the same write that
creates it, and WorkflowRunRelay re-drives anything still undispatched
past the grace window, beside the existing event relay on the same
minutely cron. So a Temporal outage costs a delay, not the work.
Re-dispatch is safe because the execution id is per-run and duplicates are
now rejected, with a rejected duplicate reported as success — which also
means a finished run can never be silently re-run.
The relay deliberately ignores runs the worker has already advanced and
runs cancelled while undispatched: the first needs nothing, the second
must never be started.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Signed-off-by: Artem Petrov <[email protected]>
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.
Follow-up to #253 / #255, from the same incident: the queue is sold as always available, so a
stall has to be loud and the work has to survive it.
The hole
WorkflowService.startcommitted the run, then dispatched it to Temporal with an inline RPCwhose result nobody read:
TemporalService.start_workflowdoes not raise on a failed RPC — it answers{ ok: false, ... }.So a Temporal outage never even reached that
rescue: it produced a committed run, aworkflow_startedactivity, and a success response. Therescuecaught the other half(ActiveRecord, NoMethodError) and also returned the run as if started.
Nothing re-drove it:
CleanupStaleRunsActivityrunning/pausedpast 4h —pendingis out of scopeSessionAdmissionReconcilerOutboxRelayA run created while Temporal was unreachable stayed
pendingforever, and looked exactly like onethe worker had simply not picked up yet.
The change
Loud.
dispatch!reads the result and raisesWorkflowService::DispatchFailed. The callergets an exception and Sentry an event.
A deployment that has switched Temporal off is not a failure and does not raise — it has no
executor to strand a run from, and no relay either, since the relay is itself a Temporal schedule.
The check is on
TemporalService.enabled?, the deployment's own switch, not on the shape of theerror string. Development and test keep working exactly as before.
Durable. The run is enrolled in the outbox in the same write that creates it
(
relay_state: "pending"), andWorkflowRunRelayre-drives anything still undispatched pastWorkflowRun::RELAY_GRACE, in the same minutelyoutbox_relay_workflowtick as the event relay —events first, since draining them is what creates runs.
The two halves need each other. Loud without durable turns an outage into lost work; durable
without loud is the silence this incident was made of.
Idempotent.
start_workflow_executionnow passesreject_duplicate: true. The execution id isper-run, so a duplicate start can only mean this run's execution already exists — reported as
success, which is how a re-drive of a run Temporal did receive settles. It also forbids reusing
the id after the execution closed, so a finished run can never be silently re-run.
The relay ignores runs the worker has already advanced (nothing to do) and runs cancelled while
undispatched (must never be started), and gives up after
RELAY_MAX_ATTEMPTSso one poison runcannot own every sweep.
Consequence worth naming
A user whose run fails to dispatch now sees an error instead of a run page — and the run still
starts within the grace window. That is the intended trade: the alternative is what we had, where
nobody saw anything at all.
Schema
db/schema.rbwas edited by hand (columns + partial index, alphabetical, version bumped) ratherthan dumped from a local database, per the local-dump hazards.
SchemaParityTestreplays themigrations into a throwaway database and diffs, so CI is the arbiter of whether the hand edit
matches what Rails renders.
🤖 Generated with Claude Code