Implement Phase 4 reasoning trigger gate with cooldown#137
Implement Phase 4 reasoning trigger gate with cooldown#137dilshadalikhan2004 wants to merge 2 commits into
Conversation
|
Caution Review failedFailed to post review comments 📝 WalkthroughWalkthroughThis PR refactors the memory trigger reasoning-gate API from a TrackLifecycleEvent-plus-action-strings pattern to a TrackSequence-based pattern, updates action-classifier configuration defaults, and revises tests to use TrackSequence/ActionHint with fixtures and helpers. ChangesMemory Trigger API and Test Refactoring
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related issues
Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
services/memory/trigger.py (1)
11-11: 💤 Low value
_reasoning_cooldownsgrows unbounded and is unsynchronized.Entries are added on every successful trigger (Line 66) and only removed via
reset_cooldown. If reasoning fails orreset_cooldownis never called for some tracks, the dict accumulates one entry per track_id for the process lifetime. Additionally, the check-then-set on Lines 60-66 is not atomic, so concurrent invocations for the sametrack_idcould both trigger. If the pipeline ever processes tracks across threads, consider a lock and/or periodic eviction of stale entries.Also applies to: 57-66
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@services/memory/trigger.py` at line 11, _reasoning_cooldowns currently grows unbounded and is updated without synchronization; make access atomic and evict stale entries by introducing a lock (e.g., _reasoning_cooldowns_lock) and a TTL constant (e.g., REASONING_COOLDOWN_TTL) and wrap all reads/writes (checks, setting on trigger, and reset_cooldown) to _reasoning_cooldowns in that lock so the check-then-set around the trigger is atomic; additionally, on each access (or periodically) prune entries older than TTL so failed or forgotten track_ids don't accumulate, and ensure failures also clear their entries via reset_cooldown.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@services/memory/trigger.py`:
- Around line 43-45: The current gating in should_trigger_reasoning only ensures
seq.zones_visited is non-empty so it fires for any visited zone; either update
the function docstring to state it intentionally triggers on any visited zone,
or change the gating to require an intersection with the restricted-zone set
(e.g., filter seq.zones_visited against the restricted zones provided by Memory
or a RESTRICTED_ZONES constant) before returning True; locate
should_trigger_reasoning in services/memory/trigger.py and use the same
restricted-zone identifier used in services/memory/memory.py (or the
Memory.restricted_zones attribute) to perform the filtered check.
---
Nitpick comments:
In `@services/memory/trigger.py`:
- Line 11: _reasoning_cooldowns currently grows unbounded and is updated without
synchronization; make access atomic and evict stale entries by introducing a
lock (e.g., _reasoning_cooldowns_lock) and a TTL constant (e.g.,
REASONING_COOLDOWN_TTL) and wrap all reads/writes (checks, setting on trigger,
and reset_cooldown) to _reasoning_cooldowns in that lock so the check-then-set
around the trigger is atomic; additionally, on each access (or periodically)
prune entries older than TTL so failed or forgotten track_ids don't accumulate,
and ensure failures also clear their entries via reset_cooldown.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 706987e1-7a7a-41b2-896e-ae8f59ea75a6
📒 Files selected for processing (3)
libs/config/settings.pyservices/memory/trigger.pytests/test_trigger.py
| # Zone check | ||
| if not seq.zones_visited: | ||
| return False |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Inspect how zones_visited / zones_key is populated to see whether it is restricted-only.
rg -nP -C4 '\bzones_visited\b' --type=py
rg -nP -C4 '_zones_key|zones_present|restricted' --type=pyRepository: Devnil434/Eagle
Length of output: 50371
Fix restricted-zone gating in should_trigger_reasoning
services/memory/trigger.pyonly checks thatseq.zones_visitedis non-empty (if not seq.zones_visited: return False), so it will fire for any visited zone.services/memory/memory.pypopulateszones_visitedby collectingevent.zonevalues with no restricted-only filtering;tests/test_memory.py::test_zones_visited_populatedshows"safe_corridor"and"restricted_door"both ending up inseq.zones_visited.
Update the docstring/intent to match “any visited zone” or filterseq.zones_visitedagainst the restricted-zone set before allowing the trigger to proceed.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@services/memory/trigger.py` around lines 43 - 45, The current gating in
should_trigger_reasoning only ensures seq.zones_visited is non-empty so it fires
for any visited zone; either update the function docstring to state it
intentionally triggers on any visited zone, or change the gating to require an
intersection with the restricted-zone set (e.g., filter seq.zones_visited
against the restricted zones provided by Memory or a RESTRICTED_ZONES constant)
before returning True; locate should_trigger_reasoning in
services/memory/trigger.py and use the same restricted-zone identifier used in
services/memory/memory.py (or the Memory.restricted_zones attribute) to perform
the filtered check.
Summary
Implemented the Phase 4 reasoning trigger gate to prevent unnecessary VLM/LLM invocations by evaluating track sequences before triggering reasoning.
Changes
Added
should_trigger_reasoning(seq: TrackSequence) -> boolAdded in-memory cooldown tracking
Added
reset_cooldown(track_id)Added suspicious action detection for:
LINGERINGNEAR_KEYPADREPEATED_APPROACHAdded dwell threshold validation using centralized settings
Updated trigger tests to use
TrackSequenceTests
Added/updated tests covering:
All trigger tests pass successfully.
Note
The existing trigger tests were based on the older
TrackLifecycleEventinterface. They were updated to align with theTrackSequence-based API specified in Issue #42.Summary by CodeRabbit
New Features
Refactor