Skip to content

fix(hitl,state,types): least-surprise fixes to the approval gates, result state and goal typing - #84

Merged
bsbodden merged 4 commits into
mainfrom
fix/form-reask-state-defaults
Nov 15, 2026
Merged

bsbodden merged 4 commits into
mainfrom
fix/form-reask-state-defaults

Conversation

@bsbodden

@bsbodden bsbodden commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

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 a human_form_invalid failure with the failure count pre-set past max_retries. One typo blacklisted the action and, with no alternative, ended the run in no_plan. That is an input error, not a decision. The gate now raises the interrupt again with attempt, validation_errors (loc / msg / type per error) and rejected_payload in 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 no approved field, 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"] and result["action_failure_counts"] raised KeyError precisely when nothing had gone wrong (likewise replan_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_state seeds them, the planner fills any that a hand-built input ({"goal": ..., "world_state": ...}) left out, and rehydrate_state fills them on the way out. Covered for sync, async, the convenience invoke, and hand-built inputs.

3. The boolean approval gate asks again instead of guessing.
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. (Command(resume=None) never reaches the gate: LangGraph itself rejects it.)

4. GoalSpec(conditions={...}) type-checks.
GoalSpec.conditions, SoftGoal.conditions and GoalSpec.objectives were annotated as MappingProxyType although every caller passes a dict and __post_init__ converts it, so the literal every user writes was a mypy error. They are annotated as Mapping now and still converted to an immutable MappingProxyType at construction.

Tests: tests/integration/test_form_hitl.py (re-ask with errors, wrong shape, denial by False and 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), new tests/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), new tests/test_goal_typing.py. Docs: ActionSpec.require_human_approval docstring, 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.

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.
@github-actions

github-actions Bot commented Nov 15, 2026 •

Copy link
Copy Markdown

✅ Code Quality Report

Metric Score Status
MFCQI Score 0.8111449010551001 ✅ Good
Test Coverage 94% ✅ Good
Security Issues 0 ✅ Clean

Quality Gates

  • MFCQI Score: ✅ Minimum 0.75 (Current: 0.8111449010551001)
  • Test Coverage: ✅ Minimum 80% (Current: 94%)
  • Security: ✅ Zero vulnerabilities (Current: 0)

🎉 All quality gates passed! This PR maintains high code quality standards.

📊 View detailed MFCQI breakdown

Run uv run python -m mfcqi analyze langgoap locally to see detailed metrics breakdown.

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.
@bsbodden bsbodden changed the title fix(hitl,state): re-ask invalid typed forms; results carry every state key fix(hitl,state,types): least-surprise fixes to the approval gates, result state and goal typing Nov 15, 2026
@bsbodden
bsbodden merged commit fbac52b into main Nov 15, 2026
19 checks passed
@bsbodden
bsbodden deleted the fix/form-reask-state-defaults branch November 15, 2026 22:39
@bsbodden bsbodden added the bug Something isn't working label Nov 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant