Skip to content

fix: address valid review comments from PR #1359#1380

Merged
henrypark133 merged 1 commit intostagingfrom
fix/pr-1359-review-fixes-v2
Mar 18, 2026
Merged

fix: address valid review comments from PR #1359#1380
henrypark133 merged 1 commit intostagingfrom
fix/pr-1359-review-fixes-v2

Conversation

@henrypark133
Copy link
Collaborator

Summary

Addresses valid review comments from PR #1359 with four targeted fixes:

Also migrates crate::safety::SafetyLayer import to ironclaw_safety::SafetyLayer per project convention (CLAUDE.md).

Test plan

  • cargo fmt passes
  • cargo clippy --all --benches --tests --examples --all-features passes with zero warnings
  • cargo test passes (2 pre-existing failures in test_cancel_job_completed and test_execute_empty_tool_name_returns_not_found are unrelated)
  • Updated test_routine_sentinel_detection_exact_match test covers new exact-match behavior and NOT_ROUTINE_OK false positive case
  • Existing discovery schema tests (routine_create_discovery_schema_keeps_legacy_aliases, event_emit_discovery_schema_keeps_source_alias) validate cached schemas return correct content

Closes #1361, #1369, #1371
Related: #1359

🤖 Generated with Claude Code

- Cache discovery_schema() with OnceLock for routine tools (fixes #1361, #1371)
- Early-return on empty event cache before allocating Vec (fixes #1369)
- Extract batch concurrent count query helper to reduce duplication
- Fix ROUTINE_OK sentinel substring matching
- Migrate crate::safety import to ironclaw_safety per project convention

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings March 18, 2026 21:25
@github-actions github-actions bot added scope: agent Agent core (agent loop, router, scheduler) scope: tool/builtin Built-in tools size: M 50-199 changed lines risk: medium Business logic, config, or moderate-risk modules contributor: core 20+ merged PRs labels Mar 18, 2026
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refines the routine engine and built-in tools by addressing several review comments from a previous PR. The changes focus on improving performance through schema caching and early-return optimizations, enhancing correctness by fixing a sentinel matching logic, and improving code maintainability by deduplicating common database query patterns and updating a dependency import.

Highlights

  • Schema Caching: Implemented OnceLock for discovery_schema() in RoutineCreateTool and RoutineSystemEventEmitTool to prevent redundant JSON schema rebuilding on every call.
  • Optimized Event Triggering: Added early-return logic to check_event_triggers() and emit_system_event() to skip unnecessary database queries and allocations when no event matchers are present.
  • Code Deduplication: Extracted a batch_concurrent_counts() helper function to consolidate identical batch query patterns, improving maintainability.
  • Sentinel Matching Fix: Corrected the ROUTINE_OK sentinel detection to use an exact match on trimmed content, preventing false positives from substrings like NOT_ROUTINE_OK.
  • Dependency Migration: Updated the import path for SafetyLayer to align with project conventions.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR applies targeted performance and correctness fixes to the routine tooling and routine engine, addressing review feedback from PR #1359 (schema caching, trigger fast-paths, deduped batch queries, and stricter ROUTINE_OK sentinel handling).

Changes:

  • Cache complex tool discovery schemas for routine_create and event_emit using OnceLock to avoid rebuilding JSON on every call.
  • Add fast-path early returns for empty matcher caches and extract a shared batch_concurrent_counts() helper to dedupe batch-query logic.
  • Tighten ROUTINE_OK sentinel detection to an exact match on trimmed content and update the related test; migrate SafetyLayer import to ironclaw_safety.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/tools/builtin/routine.rs Adds OnceLock caching for discovery schemas to reduce repeated schema construction cost.
src/agent/routine_engine.rs Adds matcher fast-paths, dedupes batch concurrent-count query logic, updates ROUTINE_OK detection, and adjusts SafetyLayer import.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +345 to +355
async fn batch_concurrent_counts(&self, routine_ids: &[Uuid]) -> Option<HashMap<Uuid, i64>> {
match self
.store
.count_running_routine_runs_batch(routine_ids)
.await
{
Ok(counts) => Some(counts),
Err(e) => {
tracing::error!("Failed to batch-load concurrent counts: {}", e);
None
}
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the routine engine by introducing early return optimizations in event trigger checks, extracting batch concurrent count logic into a dedicated helper function, and updating the SafetyLayer dependency to an external crate. It also improves the precision of the ROUTINE_OK sentinel detection to require an exact match, with corresponding test updates. Additionally, schema generation for routine_create_discovery_schema and event_emit_discovery_schema is now cached using OnceLock for performance.

@henrypark133 henrypark133 merged commit ec04354 into staging Mar 18, 2026
18 checks passed
@henrypark133 henrypark133 deleted the fix/pr-1359-review-fixes-v2 branch March 18, 2026 22:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor: core 20+ merged PRs risk: medium Business logic, config, or moderate-risk modules scope: agent Agent core (agent loop, router, scheduler) scope: tool/builtin Built-in tools size: M 50-199 changed lines

Projects

None yet

3 participants