Repository navigation
fix(hitl,state,types): least-surprise fixes to the approval gates, result state and goal typing - #84
Merged
Merged
Conversation
A resume payload rejected by the Pydantic model (or of the wrong shape) was
recorded as a human_form_invalid failure with the count pre-set past
max_retries, so a typo blacklisted the action and, with no alternative,
ended the run in no_plan. It is an input error, not a decision: the gate
now raises the interrupt again with attempt, validation_errors and
rejected_payload in the payload. A form can be declined explicitly with
False or {"approved": False, "reason": ...}, recorded and blacklisted like
a denied boolean gate; the form gate had no way to say no before.
LangGraph returns only the channels a run wrote to, so result["blacklisted_actions"] and result["action_failure_counts"] raised KeyError precisely when nothing had gone wrong. The defaults now live in one table, STATE_DEFAULTS: GoapGraph.initial_state seeds them, the planner fills any that a hand-built input left out, and rehydrate_state fills them on the way out.
✅ Code Quality Report
Quality Gates
🎉 All quality gates passed! This PR maintains high code quality standards. 📊 View detailed MFCQI breakdownRun |
A boolean gate asks a yes/no question, but any non-empty string, non-zero
number, dict without approved or with a non-boolean approved counted as
approval, so Command(resume="no") approved the action. Only True / False
and {"approved": <bool>, "reason": ...} are decisions now; anything else
re-raises the interrupt with attempt, validation_errors and
rejected_payload, exactly like the typed-form gate. Both gate payloads
carry attempt and effects. _is_approved is replaced by
_approval_decision, which returns approved / denied / invalid.
GoalSpec.conditions, SoftGoal.conditions and GoalSpec.objectives were
annotated as MappingProxyType although every caller passes a dict and
__post_init__ converts it, so GoalSpec(conditions={...}) was a mypy error
in user code. The fields are annotated as Mapping (what a caller writes)
and still converted to an immutable MappingProxyType at construction.
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.
Four least-surprise defects, two of which surfaced while writing the LangGraph-refactor screencasts (#83). All are fixed test-first here; no behaviour is merely documented.
1. A typed form that fails validation is asked again, not blacklisted.
A resume payload rejected by the Pydantic model (or of the wrong shape, such as
True) was recorded as ahuman_form_invalidfailure with the failure count pre-set pastmax_retries. One typo blacklisted the action and, with no alternative, ended the run inno_plan. That is an input error, not a decision. The gate now raises the interrupt again withattempt,validation_errors(loc/msg/typeper error) andrejected_payloadin the payload; a corrected submission goes through. Each round needs a human resume, so nothing loops on its own.The form gate also had no way to say no.
False, or{"approved": False, "reason": ...}when the model has noapprovedfield, now declines the form and is recorded and blacklisted exactly like a denied boolean gate (human_approval_denied).2. Every bookkeeping key is present in every result.
LangGraph returns only the channels a run wrote to, so
result["blacklisted_actions"]andresult["action_failure_counts"]raisedKeyErrorprecisely when nothing had gone wrong (likewisereplan_reason,skipped_subgoals,reflection_context,current_subgoal_index,no_plan_explanation). The defaults now live in one table,langgoap.graph.state.STATE_DEFAULTS:GoapGraph.initial_stateseeds them, the planner fills any that a hand-built input ({"goal": ..., "world_state": ...}) left out, andrehydrate_statefills them on the way out. Covered for sync, async, the convenienceinvoke, and hand-built inputs.3. The boolean approval gate asks again instead of guessing.
Any non-empty string, non-zero number, dict without
approvedor with a non-booleanapprovedcounted as approval, soCommand(resume="no")approved the action. OnlyTrue/Falseand{"approved": <bool>, "reason": ...}are decisions now; anything else re-raises the interrupt withattempt,validation_errorsandrejected_payload, exactly like the typed-form gate. Both gate payloads carryattemptandeffects. (Command(resume=None)never reaches the gate: LangGraph itself rejects it.)4.
GoalSpec(conditions={...})type-checks.GoalSpec.conditions,SoftGoal.conditionsandGoalSpec.objectiveswere annotated asMappingProxyTypealthough every caller passes a dict and__post_init__converts it, so the literal every user writes was a mypy error. They are annotated asMappingnow and still converted to an immutableMappingProxyTypeat construction.Tests:
tests/integration/test_form_hitl.py(re-ask with errors, wrong shape, denial byFalseand by dict, async parity; the old "invalid = denial" test is replaced),tests/test_failure_counts.py(denied form keeps both counts; invalid form re-asks and leaves counts alone), newtests/test_state_defaults.py,tests/integration/test_human_in_the_loop.py(ambiguous answers are asked again, sync and async),tests/test_graph_nodes.py(_approval_decision), newtests/test_goal_typing.py. Docs:ActionSpec.require_human_approvaldocstring, concepts page, CHANGELOG. Full non-API suite: 2019 passed locally; black, isort, mypy, vulture clean.#83 will be updated on top of this so its email-assistant notebook shows the re-ask instead of the old blacklisting.