Skip to content

fix(workflows): stop the generic cancellation text erasing the real reason - #214

Merged
artempartos merged 1 commit into
developfrom
fix/preserve-cancellation-reason
Sep 5, 2026
Merged

artempartos merged 1 commit into
developfrom
fix/preserve-cancellation-reason

Conversation

@artempartos

Copy link
Copy Markdown
Contributor

What this fixes

On 2026-09-05 eleven production runs ended cancelled, with failure_reason: nil, step_run.error_message: "", and every session saying the same thing:

error_message = "Workflow cancelled"

They were not cancelled by anyone. All eleven hit the same wall:

⎿  You've hit your individual spend limit · run /usage-credits to ask your…

ScanQuotaErrorsActivity read 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

CompleteStepActivity detects quota exhaustion by reading session.error_message. A clobbered session therefore also lost:

  • error_category: :quota_exceeded on 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_cleanup and AdmittedPhaseActivity#finalize_session.

The cancellation fan-out carries a diagnosed reason onto the step run. WorkflowService#cancel_active_step_runs reads the session after cancelling (cleanup may have just written the reason) and passes it to StepRun#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_session still 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

…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]>
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.

1 participant