Skip to content

Implement reasoning trigger gate with cooldown logic#60

Merged
Devnil434 merged 2 commits into
Devnil434:mainfrom
dilshadalikhan2004:feat/reasoning-trigger-gate
May 16, 2026
Merged

Implement reasoning trigger gate with cooldown logic#60
Devnil434 merged 2 commits into
Devnil434:mainfrom
dilshadalikhan2004:feat/reasoning-trigger-gate

Conversation

@dilshadalikhan2004
Copy link
Copy Markdown
Contributor

@dilshadalikhan2004 dilshadalikhan2004 commented May 16, 2026

Summary by CodeRabbit

  • New Features
    • Added configurable thresholds for reasoning behavior (dwell time and cooldown intervals).
    • Implemented trigger mechanism for reasoning that evaluates suspicious activity patterns based on zone presence, dwell duration, and action types with cooldown protection to prevent excessive re-triggering.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 16, 2026

Warning

Rate limit exceeded

@dilshadalikhan2004 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 35 minutes and 49 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 8dc044e2-a0f6-4854-b557-1c98bb8f02ea

📥 Commits

Reviewing files that changed from the base of the PR and between 415d18d and a044ef1.

⛔ Files ignored due to path filters (1)
  • poetry.lock is excluded by !**/*.lock
📒 Files selected for processing (3)
  • .gitignore
  • services/memory/trigger.py
  • tests/test_trigger.py
📝 Walkthrough

Walkthrough

This PR adds configuration-driven reasoning trigger logic to detect suspicious track patterns. A new settings module exposes dwell and cooldown thresholds, a trigger service implements gating rules and per-track cooldown state, and comprehensive tests validate all trigger conditions and cooldown behavior.

Changes

Reasoning Trigger Gate

Layer / File(s) Summary
Settings configuration for reasoning parameters
libs/config/settings.py
Added reasoning_dwell_threshold_seconds and reasoning_cooldown_seconds fields to Settings class; migrated from ConfigDict to SettingsConfigDict to enable .env-based environment variable loading for the new threshold parameters.
Trigger service with cooldown gating logic
services/memory/trigger.py
Implemented should_trigger_reasoning() that gates trigger decisions through ordered checks: zone presence, dwell time threshold, suspicious-action intersection, and per-track cooldown enforcement. Module maintains _reasoning_cooldowns state map and exposes reset_cooldown() to clear cooldown after event completion.
Trigger service unit tests
tests/test_trigger.py
Added helper function make_event() and six test cases covering rejection conditions (no zones, below dwell threshold, no suspicious actions), successful trigger with cooldown initialization, cooldown-based rejection, and cooldown reset enabling retriggering.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related issues

  • Issue #42: Directly related; both changes implement the same in-memory cooldown and gating logic in services/memory/trigger.py, including should_trigger_reasoning, reset_cooldown, SUSPICIOUS_ACTIONS, and cooldown state management.

Poem

A rabbit hops through reasoning's gate,
With cooldown checks to regulate,
Dwell time grows, zones align,
Suspicious actions cross the line—
Trigger fires, then waits its time. 🐰✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 22.22% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and accurately describes the primary change: implementing a reasoning trigger gate with cooldown logic, which is reflected across all three modified files.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 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 33-54: The gate logic can be silently broken by negative
thresholds; before applying the dwell and cooldown checks, validate that
settings.reasoning_dwell_threshold_seconds and
settings.reasoning_cooldown_seconds are non-negative (and that
event.dwell_time_seconds is not negative). If any of these values are invalid,
log a clear error (or raise a ValueError) and either clamp to 0 or abort the
check (return False) so the gate behavior is deterministic; update the
validation near where event.dwell_time_seconds,
settings.reasoning_dwell_threshold_seconds, and
settings.reasoning_cooldown_seconds are used (also consider adding this check
once at function entry or initialization) and keep
_reasoning_cooldowns/monotonic() logic unchanged.

In `@tests/test_trigger.py`:
- Around line 1-9: The tests in tests/test_trigger.py rely on ambient env config
for dwell/cooldown causing nondeterminism; add an autouse pytest fixture that
pins the relevant config values used by should_trigger_reasoning and
reset_cooldown (e.g., dwell_time, cooldown_time) to fixed constants for the test
run by monkeypatching the config loader or os.environ before importing/using
those functions; ensure the fixture is autouse and scoped to the module so all
tests (including lines ~26-115) see the pinned values and remove reliance on
external .env.
🪄 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: b0da8842-53a8-4fba-85a4-6b0cae7bd592

📥 Commits

Reviewing files that changed from the base of the PR and between 8469d4a and 415d18d.

📒 Files selected for processing (3)
  • libs/config/settings.py
  • services/memory/trigger.py
  • tests/test_trigger.py

Comment thread services/memory/trigger.py
Comment thread tests/test_trigger.py
@dilshadalikhan2004
Copy link
Copy Markdown
Contributor Author

Addressed the review feedback:

  • added detailed docstrings
  • added validation guards for invalid threshold values
  • stabilized tests with fixed config fixture

All trigger gate tests are passing successfully.

@Devnil434 Devnil434 merged commit 3c1cb36 into Devnil434:main May 16, 2026
1 check passed
@dilshadalikhan2004
Copy link
Copy Markdown
Contributor Author

Hi @Devnil434 this is merged & solved but i did not get any points ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants