Repository navigation
fix(workflows): stop the generic cancellation text erasing the real reason - #214
Merged
Merged
Conversation
…eason Two sweeps already diagnose why a session cannot continue and write it onto the session: ScanQuotaErrorsActivity reads a spend limit off the live terminal, and ScanDeadContainersActivity reports a pod whose node died. Both messages were then overwritten, because cancellation cleanup runs last and reports the same "Workflow cancelled" for every reason a session can be cancelled for. The loss is not cosmetic. CompleteStepActivity's quota detector reads `error_message`, so a clobbered session also lost `error_category: :quota_exceeded`; the step was marked cancelled with no message at all, and the run surfaced as a bare "cancelled" with a nil failure_reason. On 2026-09-05 eleven production runs ended that way. All eleven were one thing — "You've hit your individual spend limit · run /usage-credits" — and none of them said so. Finding that out took an archaeology session across Temporal history and Loki. - A specific reason now outranks a generic one whichever arrives last (TerminalSession.preferred_error_message), applied at both cleanup writers. - The cancellation fan-out carries a diagnosed reason onto the step run, so a user sees why. A generic reason is still dropped: "cancelled" with no message already says everything "Workflow cancelled" would. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Signed-off-by: Artem Petrov <[email protected]>
This was referenced Nov 10, 2026
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.
What this fixes
On 2026-09-05 eleven production runs ended
cancelled, withfailure_reason: nil,step_run.error_message: "", and every session saying the same thing:They were not cancelled by anyone. All eleven hit the same wall:
ScanQuotaErrorsActivityread that off the live terminal and wrote it onto each session — correctly. Cleanup then overwrote it, because cancellation runs last and reports one generic string for every reason a session can be cancelled for.Establishing that took Temporal history plus a Loki query, for a fact the system had already discovered and then thrown away.
Why it is not only cosmetic
CompleteStepActivitydetects quota exhaustion by readingsession.error_message. A clobbered session therefore also lost:error_category: :quota_exceededon the step run,WorkflowRun#mark_quota_failed!and the credential attribution that goes with it.The same erasure hits
ScanDeadContainersActivity, whose "Agent container vanished: its node most likely died or the pod was evicted" met the same fate — that is how the node-eviction incident in aixle-infra#34 presented, too.The change
A specific reason outranks a generic one, whichever arrives last.
TerminalSession.preferred_error_message(existing, incoming)encodes it, applied at both writers that were clobbering:BaseStrategy#after_cleanupandAdmittedPhaseActivity#finalize_session.The cancellation fan-out carries a diagnosed reason onto the step run.
WorkflowService#cancel_active_step_runsreads the session after cancelling (cleanup may have just written the reason) and passes it toStepRun#mark_cancelled!, which now takes one. A generic reason is still dropped on purpose — a cancelled step with no message already says everything "Workflow cancelled" would.What it does not do
It does not change which sessions get cancelled, or turn a cancellation into a failure.
fail_sessionstill routes an admitted session through cancel, because that is what releases the reservation. This is about what the system remembers, not what it does.Tests
docker compose exec -T web make check_all— green (backend 91.81%, frontend 80.76%).Covers: a diagnosed reason survives a later generic one; a generic reason is still used when nothing better is known; one specific reason may replace another;
mark_cancelled!records a reason and leaves an earlier message alone without one; the fan-out carries a diagnosed reason to the step run and drops a generic one.🤖 Generated with Claude Code