Skip to content

fix(graph): waits look once per resume; cache the tracer hook signature lookup - #107

Merged
bsbodden merged 1 commit into
mainfrom
fix/wait-replay-tracer-cache
Nov 22, 2026
Merged

bsbodden merged 1 commit into
mainfrom
fix/wait-replay-tracer-cache

Conversation

@bsbodden

Copy link
Copy Markdown
Contributor

Review of main since v0.3.0 (#96–#106) before the 0.3.1 release: two measured defects in the unreleased wait and tracer work, fixed test-first, plus three small tidy-ups.

What changed

  • Waits looked N times after N notifications. ActionSpec.wait looped on interrupt() inside one task, and LangGraph replays a resumed task from its first line, so after N idle notifications the next one ran on_resume and the sensors N+1 times (measured +1, +2, … +10 per notify). A wait now looks once per resume; when nothing it watches changed it raises StillWaiting, the executor returns no step and no record, and the observer sends the plan back to the same step so the wait pauses again in a fresh task. The new bookkeeping key prepared_wait tells that task the wait's execute has run; it is cleared when the wait ends and by every new plan. After: per idle notification 1 on_resume, 1 sensor pass; execute runs at start and once more on the first resume (LangGraph's replay), then never.
  • Tracer hook calls cost 42 µs. The thread_id keyword filtering (Tracer hooks receive thread_id as an explicit keyword argument #104) called inspect.signature per hook call, including on_search_expand, which fires per A* expansion (bare hook: 0.17 µs). langgoap.tracing._context now remembers the accepted keyword names per hook function (accepted_keywords, keyed on __func__ so instances share) and hook_kwargs consults current_thread_id() only for hooks that take thread_id. After: 3.4 µs per call.
  • GoapGraph.waiting_action returns None, not the string "None", when a payload hides the action name.
  • interrupt_payload in langgoap.graph.state serves both GoapResult.interrupt and GoapGraph.waiting.
  • GoapGraph.compiled compiles under the mailbox lock, so two OS threads starting at once compile once.
  • CHANGELOG (0.3.1 entry), the concepts page and the ActionSpec.wait docstring describe the one-look-per-resume semantics.

Test plan

  • tests/test_wait_actions.py: replay counts per notify on both executors, sync and async; a wait's returned dict reaches the final state after idle notifications; a new plan prepares a wait afresh.
  • tests/test_thread_api.py: notify and resume called from inside on_stop are queued and delivered in order.
  • tests/test_tracer_thread_id.py: every instance of a tracer class gets its own thread id (the cache is per function); a **kwargs hook receives thread_id.
  • tests/test_waiting_action.py: a hidden action name gives None. tests/test_state_defaults.py: prepared_wait in the bookkeeping table.
  • make lint clean; full suite 2302 passed, 2 skipped. The foood engine (langgoap-0.3.1 branch) reinstalled against this branch: 35 tests pass, no engine change needed.

…re lookup

- A wait looped on interrupt() inside one task, and LangGraph replays a
  resumed task from its first line: after N idle notifications the next
  one ran on_resume and the sensors N+1 times.  A wait now looks once per
  resume; when nothing it watches changed it raises StillWaiting, the
  executor returns no step and no record, and the wait pauses again in a
  fresh task.  The new state key prepared_wait tells that task the wait's
  execute has run already; it is cleared when the wait ends and by every
  new plan.  Measured: per idle notification 1 on_resume and 1 sensor pass
  (was N), execute twice in total (start and LangGraph's one replay).
- The thread_id keyword filtering called inspect.signature on every hook
  call: 42 us per call on on_search_expand, which fires per A* expansion.
  The accepted keyword names are remembered per hook function and
  current_thread_id() is consulted only for hooks that take thread_id:
  3.4 us per call.
- waiting_action returns None, not the string "None", when a payload
  hides the action name; one interrupt_payload helper serves
  GoapResult.interrupt and GoapGraph.waiting; GoapGraph.compiled compiles
  under the mailbox lock so two OS threads starting at once compile once.
@bsbodden bsbodden added the bug Something isn't working label Nov 22, 2026
@github-actions

Copy link
Copy Markdown

✅ Code Quality Report

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

Quality Gates

  • MFCQI Score: ✅ Minimum 0.75 (Current: 0.8113877457437999)
  • 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.

@bsbodden
bsbodden merged commit 10bb26c into main Nov 22, 2026
20 checks passed
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