Repository navigation
Description
π€ This is an automated pull request from Repo Assist.
Summary
Two targeted performance improvements to hot-path code in OpenClaw.Shared.
1. ExecApprovalPolicy.Evaluate β hoist normalizedShell out of the loop
Before: normalizedShell was allocated inside the foreach loop, once per rule that carries a Shells filter. With the default 21-rule policy, this allocates a new string on every iteration that has a shell filter β wasted work since the value is identical for the lifetime of the call.
After: Compute (shell ?? "powershell").ToLowerInvariant() once before the loop. Zero behaviour change; one string allocation instead of N.
2. NotificationCategorizer.MatchesRule β cache compiled Regex instances
Before: The method used Regex.IsMatch(text, pattern, options, matchTimeout) β the overload that accepts a matchTimeout bypasses .NET's internal static regex cache (this is documented .NET behaviour). A new Regex object was compiled from scratch on every notification for every regex-pattern user rule.
After: A ConcurrentDictionary(string, Regex?) caches compiled instances keyed by pattern. Each Regex is still constructed with matchTimeout = 100 ms (ReDoS protection preserved), but subsequent notifications reuse the same compiled automaton. Invalid patterns are stored as null so RegexParseException is only thrown once.
Test Status
β
All 432 non-integration tests pass (dotnet test). Integration tests are skipped in this environment (Windows-only).
No behaviour changes β purely performance improvements.
Generated by Repo Assist Β· β·
To install this agentic workflow, run
gh aw add githubnext/agentics/workflows/repo-assist.md@cbb46ab386962aa371045839fc9998ee4e97ca64
Note
This was originally intended as a pull request, but GitHub Actions is not permitted to create or approve pull requests in this repository.
The changes have been pushed to branch repo-assist/improve-exec-notify-perf-2026-03-17-04ada35e031dac93.
To fix the permissions issue, go to Settings β Actions β General and enable Allow GitHub Actions to create and approve pull requests.
Show patch preview (98 of 98 lines)
From 95bf71e4dbe13c2b447a9b10ced5a8c83a588ef0 Mon Sep 17 00:00:00 2001
From: "github-actions[bot]" <github-actions[bot]@users.noreply.github.com>
Date: Tue, 17 Mar 2026 00:42:37 +0000
Subject: [PATCH] perf: hoist shell normalisation and cache notification regex
objects
ExecApprovalPolicy.Evaluate: normalizedShell was allocated inside the
foreach loop for every rule that carries a shell filter. Moving the
computation before the loop avoids the repeated allocation on the hot
command-evaluation path.
NotificationCategorizer.MatchesRule: the static Regex.IsMatch overload
that accepts a matchTimeout bypasses .NET's internal regex cache, so a
new Regex object was compiled on every incoming notification for each
regex-pattern user rule. Replace with a ConcurrentDictionary<string,
Regex?> that caches compiled instances (constructed with the 100 ms
timeout so ReDoS protection is preserved). Subsequent notifications
reuse the same compiled automaton.
---
src/OpenClaw.Shared/ExecApprovalPolicy.cs | 4 ++-
.../NotificationCategorizer.cs | 25 +++++++++++++++----
2 files changed, 23 insertions(+), 6 deletions(-)
diff --git a/src/OpenClaw.Shared/ExecApprovalPolicy.cs b/src/OpenClaw.Shared/ExecApprovalPolicy.cs
index 3731ce4..3e1ad03 100644
--- a/src/OpenClaw.Shared/ExecApprovalPolicy.cs
+++ b/src/OpenClaw.Shared/ExecApprovalPolicy.cs
@@ -95,6 +95,9 @@ public class ExecApprovalPolicy
};
}
+ // Compute once; only used if any rule has shell filters.
+ var normalizedShell = (shell ?? "powershell").ToLowerInvariant();
+
foreach (var rule in _rules)
{
if (!rule.Enabled) continue;
@@ -102,7 +105,6 @@ public class ExecApprovalPolicy
// Check shell filter
if (rule.Shells is { Length: > 0 })
{
- var normalizedShell = (shell ?? "powershell").ToLowerInvariant();
if (!rule.Shells.Any(s => s.Equals(normalizedShell, Strin
... (truncated)Metadata
Metadata
Assignees
Type
Fields
Priority
Activity