fix(workflows): reject a non-integer current_step_index in RunState.load() - #4325
Open
Noor-ul-ain001 wants to merge 1 commit into
Open
fix(workflows): reject a non-integer current_step_index in RunState.load()#4325Noor-ul-ain001 wants to merge 1 commit into
Noor-ul-ain001 wants to merge 1 commit into
Conversation
…oad() RunState.load() shape-checks every other persisted field on resume -- workflow_id, installed_workflow_id, installed_registry_root, and inputs -- raising a clean "Invalid run state: ..." ValueError on a malformed value. current_step_index was the one field passed through unchecked. resume() later slices `definition.steps[state.current_step_index :]` with no guard of its own, so a non-int value (e.g. a hand-edited or externally-written state.json) reaches that slice and raises a raw `TypeError: slice indices must be integers or None or have an __index__ method` from deep inside resume() instead. A negative value slices from the end instead of failing, silently resuming from the wrong step. This mirrors the sibling field-validation pattern in RunState.load() (e.g. the workflow_id/installed_workflow_id checks) and the recurring "validate cleanly vs. crash at runtime" bug class already fixed across this codebase for step configs (e.g. github#4144, github#3899). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FW9fAYsCBCAgdKWovtSyqt
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.
Summary
RunState.load()shape-checks every other persisted field it restores on resume —workflow_id,installed_workflow_id,installed_registry_root,inputs— raising a cleanInvalid run state: ...ValueErroron a malformed value.current_step_indexwas the one field passed through with no check at all (state_data.get("current_step_index", 0)).resume()later slicesdefinition.steps[state.current_step_index :]with no guard of its own, so a non-intcurrent_step_index(e.g. a hand-edited or externally-writtenstate.json) reaches that slice and raises a rawTypeError: slice indices must be integers or None or have an __index__ methodfrom deep insideresume(), instead of the same clean domain error every sibling field already gets. A negative value slices from the end of the step list instead of failing, silently resuming from the wrong step.casesblock on switch steps #4144 for switch'scases, fix(workflows): reject mismatched run state IDs #3899 for run-state IDs) — here it shows up inRunState.load()'s field validation instead of a step'svalidate()/execute()pair.Test plan
test_load_rejects_invalid_current_step_index(parametrized over a string, float, negative int, list, dict, and bool) totests/test_workflows.py::TestRunStateDID NOT RAISE <class 'ValueError'>for all 6 cases — and passes with it (stashed onlysrc/specify_cli/workflows/engine.py, kept the test)tests/test_workflows.py::TestRunState— 31 passed, no regressionstests/test_workflows.py— 851 passed; the 17 failed / 82 errored are pre-existing Windows-only symlink-guard tests (need Developer Mode elevation) andPermissionError: [WinError 5]on the sharedpytest-of-Etmp dir, both unrelated to this change (confirmed identical onmain)Co-Authored-By: Claude Sonnet 5 noreply@anthropic.com
Claude-Session: https://claude.ai/code/session_01FW9fAYsCBCAgdKWovtSyqt