Repository navigation
fix(graph): waits look once per resume; cache the tracer hook signature lookup - #107
Merged
Merged
Conversation
…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.
✅ Code Quality Report
Quality Gates
🎉 All quality gates passed! This PR maintains high code quality standards. 📊 View detailed MFCQI breakdownRun |
This was referenced Nov 24, 2026
Closed
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.
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
ActionSpec.waitlooped oninterrupt()inside one task, and LangGraph replays a resumed task from its first line, so after N idle notifications the next one ranon_resumeand the sensors N+1 times (measured +1, +2, … +10 per notify). A wait now looks once per resume; when nothing it watches changed it raisesStillWaiting, 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 keyprepared_waittells that task the wait'sexecutehas run; it is cleared when the wait ends and by every new plan. After: per idle notification 1on_resume, 1 sensor pass;executeruns at start and once more on the first resume (LangGraph's replay), then never.thread_idkeyword filtering (Tracer hooks receive thread_id as an explicit keyword argument #104) calledinspect.signatureper hook call, includingon_search_expand, which fires per A* expansion (bare hook: 0.17 µs).langgoap.tracing._contextnow remembers the accepted keyword names per hook function (accepted_keywords, keyed on__func__so instances share) andhook_kwargsconsultscurrent_thread_id()only for hooks that takethread_id. After: 3.4 µs per call.GoapGraph.waiting_actionreturnsNone, not the string"None", when a payload hides the action name.interrupt_payloadinlanggoap.graph.stateserves bothGoapResult.interruptandGoapGraph.waiting.GoapGraph.compiledcompiles under the mailbox lock, so two OS threads starting at once compile once.ActionSpec.waitdocstring 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:notifyandresumecalled from insideon_stopare 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**kwargshook receivesthread_id.tests/test_waiting_action.py: a hidden action name givesNone.tests/test_state_defaults.py:prepared_waitin the bookkeeping table.make lintclean; full suite 2302 passed, 2 skipped. The foood engine (langgoap-0.3.1branch) reinstalled against this branch: 35 tests pass, no engine change needed.