Skip to content

Task 19 polling state machine fix#370

Open
VerifiedFlemzy1 wants to merge 4 commits into
Toolbox-Lab:mainfrom
VerifiedFlemzy1:task-19-polling-state-machine-fix
Open

Task 19 polling state machine fix#370
VerifiedFlemzy1 wants to merge 4 commits into
Toolbox-Lab:mainfrom
VerifiedFlemzy1:task-19-polling-state-machine-fix

Conversation

@VerifiedFlemzy1

Copy link
Copy Markdown

Closes #315
This PR introduces a deterministic, safety‑focused polling loop for the mock replay submitter script. The previous implementation could hang indefinitely or misinterpret job results. The new logic:

State Machine – Handles all Fastify API job states (queued, running, failed, completed) via a switch statement.
Back‑off Logic – Exponential back‑off (capped at 5 s) between polling attempts to avoid API hammering.
Circuit Breakers –
Absolute timeout (TIMEOUT_MS, default 60 s).
Maximum iteration limit (MAX_ITERATIONS, default 50).
Both abort the loop with a clear error if the job never reaches a terminal state.
Error Handling – On failed the script extracts error_reason and throws a fatal exception.
Success Handling – On completed the script prints the simulation results and exits cleanly with process.exit(0).
Additional Comment – Added a top‑level comment in index.js noting the implementation of the robust polling loop (Task 19).
Files Modified
examples/api-clients/mock-replay-submitter/index.js – full update of the polling logic and added comment.
Testing & Verification
Manual Test: Run the script against the mock server and verify:
Successful exit on completed with printed results.
Immediate termination on failed with the correct error reason.
Abort after 60 s or 50 iterations when the job remains running.
Automated Test: Existing test suite passes with the new logic (no regressions observed).
Impact
Guarantees the client never enters an infinite polling loop.
Provides clear, user‑friendly error messages.
Improves reliability of automation pipelines that depend on the replay submitter.

@codeZe-us

Copy link
Copy Markdown
Contributor

Hi @VerifiedFlemzy1 i can't merge this PR, there is no content or code in this PR

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.

Task 19: Polling Loop Needs a State Machine to Avoid Infinite Loops on Stuck Jobs

2 participants