Repository navigation
Conversation
`build(validate=True)` and `abuild(validate=True)` raise a ValueError when an action or a transition condition reads a state key that no action writes and the initial state does not provide. `Graph.validate()` returns the same problems without raising. The check runs before persisted state is loaded and is off by default, since Burr does not enforce reads/writes at runtime and apps with stale declarations still run today. Part of apache#67. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…idation - llm-adventure-game: `win` declared `reads=["challenges"]`, which is a module-level list, not state. - simulation: `forecast` writes `current_timestep` without declaring it (same fix in the docs copy). Both examples run today only because declarations are not enforced at runtime. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
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.
Adds an opt-in check that fails fast when an action or a transition condition reads a state key that no action writes and the initial state does not provide. Today that only shows up as a
KeyErroronce the action runs, often after earlier (LLM) steps have already run. This is the first check described in #67 and the "build-time graph validation" item in the planned-capabilities list.Changes
Graph.validate(initial_state_keys=())returns a list of problems (empty when there are none). It reports actionreadsand condition keys that are not in the initial state and not in any action'swrites. Keys starting with__are skipped.ApplicationBuilder.build(validate=False)/abuild(validate=False): whenTrue, raise aValueErrorlisting every problem. The initial keys are those fromwith_stateplusinitialize_from(default_state=...). The check runs before any persisted state is loaded, so the result does not depend on what has been saved.docs/concepts/state-machine.rst.examples/llm-adventure-game:windeclaredreads=["challenges"], which is a module-level list, not state.examples/simulation(and its copy indocs/examples/data-science/simulation.md):forecastwritescurrent_timestepwithout declaring it.How I tested this
tests/core/test_graph.pyandtests/core/test_application.py, covering a valid graph, an unset action read, an unset condition key, initial state keys,__keys,abuild,initialize_fromdefault state, and validation being off by default.tests/suite in a Linux container (Python 3.12, with graphviz), excluding the persister integration and Bedrock tests: 773 passed, 1 skipped.scripts/check_asf_headers.pyon the changed files.Notes
Why opt-in: Burr does not enforce declarations at runtime.
State.subsetskips missing keys, and single-step actions can write keys they do not declare. So an app with a stale declaration (like the two examples) still runs today, and turning this on by default would break it. Whether it should later become a default warning is the maintainers' call.Not included from Add graph validation/compilation #67:
state.get(...)or an earlier branch, and actions have no way to declare an optional read (conditions haveoptional_keys).halt_before/halt_afterreachability.Happy to follow up on any of these.
This does not touch
_validate_transitions, so it should not conflict with fix(core): reject transitions after defaults #906.Checklist
🤖 Generated with Claude Code