fix(workflow): poll for WS_STARTED after checkout to break ready_to_start loop#2033
Open
msawczynk wants to merge 1 commit into
Open
Conversation
…tart loop `check_workflow_for_launch` calls `start_workflow_for_record` and then immediately re-validates via `validator.validate()`. Because the router processes `start_workflow` asynchronously, the validate call can return `WS_READY_TO_START` before the `WS_STARTED` transition is visible. At that point `handled_ready_to_start` is already `True`, so the outer loop falls to the "already-handled" guard and returns `WorkflowGate(allowed=False)`. The user sees "Workflow approved but not yet checked out" a second time and is prompted to check out again, creating an infinite loop until the session is restarted. Fix: after a successful `start_workflow_for_record`, poll with exponential back-off (0.5 → 1 → 2 → 2 s, ≤5.5 s total) until the router confirms `WS_STARTED` or retries are exhausted. On success the outer loop breaks immediately; on failure the outer loop continues to its normal handling. Confirmed in lab: `pam launch <record>` with auto-checkout no longer loops; gateway reaches "Establishing secure session" without error. Co-authored-by: Cursor <cursoragent@cursor.com>
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.
Problem
pam launch(andpam tunnel) exhibit an infinite prompt loop when theworkflow
ready_to_start→ checkout → re-validate cycle races the router:pam launch --auto-checkouthitsWS_READY_TO_START→ confirmscheckout →
start_workflow_for_recordis called.check_workflow_for_launchimmediately callsvalidator.validate()again.start_workflowis processed asynchronously by the router,the validate call can still return
WS_READY_TO_STARTbeforeWS_STARTEDis visible.handled_ready_to_startis alreadyTrue, so the "already-handled"guard fires and the function returns
WorkflowGate(allowed=False).time and is prompted to check out again → loop.
Fix
After a successful
start_workflow_for_record, poll with exponentialback-off (0.5 → 1 → 2 → 2 s, ≤5.5 s total) until the router
confirms
WS_STARTEDor retries are exhausted.round-trip in the happy path once the router catches up, typically
within the first 0.5 s poll).
behaviour, no regression).
Testing
Verified in a live Keeper lab environment:
pam launch <record> --auto-checkoutno longer loops; reaches"Establishing secure session" without repeating the checkout prompt.
pam workflow startbeforepam launch) is unaffected —the router already returns
WS_STARTEDby the timepam launchruns.--waitpolling path (_poll_until_state_change) is unchanged.Files changed
keepercommander/commands/workflow/mfa.pyimport time; replace barecontinueafter checkout with back-off pollMade with Cursor