Skip to content

fix(workflow): target the -main run in Wait and AbortRun (EN-1220) - #183

Closed
flemzord wants to merge 1 commit into
mainfrom
fix/wait-abort-target-main
Closed

fix(workflow): target the -main run in Wait and AbortRun (EN-1220)#183
flemzord wants to merge 1 commit into
mainfrom
fix/wait-abort-target-main

Conversation

@flemzord

Copy link
Copy Markdown
Member

Problem (C2 + C3 — CRITICAL)

Initiate starts the real Run workflow as a detached child (ParentClosePolicy: ABANDON, id <instanceID>-main) and returns as soon as the child has started (run.go:53-64). The Initiate workflow (id == instanceID) is therefore already completed by the time the API calls Wait/AbortRun.

C2 — wrong target:

  • AbortRun called CancelWorkflow(ctx, instanceID, "") on the completed Initiate execution → cancellation never reaches the running stages. wait_event/delay instances were unabortable.
  • Wait called GetWorkflow(ctx, instanceID, "").Get() on the completed Initiate execution → returns immediately, so POST /workflows/{id}/instances?wait=true returned a non-terminated instance.

C3 — error handling in Wait:

if errors.Is(err, &serviceerror.NotFound{}) { ... }  // never matches: no Is/Unwrap on that type
return errors.Unwrap(err)                            // returns nil for non-wrapped errors → failure becomes success

Fix

  • Both Wait and AbortRun now target <instanceID>-main (matching what ReadInstanceHistory already does).
  • Wait uses errors.As(err, &notFound) for the NotFound case and returns the original error otherwise.

Test

TestWait (integration): after Wait returns, the instance is terminated (would be flaky/false under the old behavior); an unknown instance returns ErrInstanceNotFound.

Severity: CRITICAL.

…andling

Initiate starts the real Run workflow as a detached child with id
"<instanceID>-main" (ParentClosePolicy ABANDON) and returns as soon as
that child has started. The Initiate workflow (id == instanceID) is thus
already completed by the time the API calls Wait/AbortRun:

- AbortRun cancelled the completed Initiate execution, so cancellation
  never reached the running stages (wait_event/delay were unabortable).
- Wait returned immediately on the completed Initiate execution, so
  ?wait=true returned a non-terminated instance.

Both now target "<instanceID>-main" (matching ReadInstanceHistory).

Wait also mishandled errors: errors.Is(err, &serviceerror.NotFound{})
can never match (no Is/Unwrap on that type) and errors.Unwrap(err)
returned nil for non-wrapped errors, turning a failure into a success.
Use errors.As for NotFound and return the original error otherwise.

Adds TestWait covering both the terminate-wait and not-found paths.
@coderabbitai

coderabbitai Bot commented Jun 11, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@flemzord, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 41 minutes. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more credits in the billing tab to continue.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 4ea796cd-e8d9-4c91-8253-c99785672433

📥 Commits

Reviewing files that changed from the base of the PR and between 271bf8d and 9439080.

📒 Files selected for processing (2)
  • internal/workflow/manager.go
  • internal/workflow/manager_test.go
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/wait-abort-target-main

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@flemzord

flemzord commented Jun 11, 2026

Copy link
Copy Markdown
Member Author

Tracked in Jira: EN-1220 (Epic EN-1217).

@flemzord flemzord changed the title fix(workflow): target the -main run in Wait and AbortRun fix(workflow): target the -main run in Wait and AbortRun (EN-1220) Jun 11, 2026
@flemzord

flemzord commented Aug 5, 2026

Copy link
Copy Markdown
Member Author

Superseded by #199, which consolidates this change with the related reliability and safety fixes on top of the current main branch.

@flemzord flemzord closed this Aug 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant