error-pattern-safety
Error Pattern Safety Guidelines for Agentic Engines
Skill by kaushal-waygood
Install
Works with Claude Code, Claude apps, Codex, Cursor, Gemini CLI, GitHub Copilot, VS Code, OpenCode, Goose, Windsurf. Read the repository before you give any tool access to your data.
npx agentmarket install skill/kaushal-waygood-error-pattern-safety
Asks which of your tools to add it to (Claude Code, Codex, Cursor, VS Code, Windsurf, Gemini CLI, Claude Desktop) and shows the change first. See https://agentmart.dev/cli.
Get the weekly diff
The weekly diff: one email a week with new agent tools, notable updates and grade changes, plus security alerts for tools you follow. Double opt-in, one-click unsubscribe.
About
Reviews
Write a reviewNo reviews yet. Installed it? Reviews come from verified installers only. How reviews work
Permissions: not checked yet.
What's inside
- Skill name
error-pattern-safety- Description
- Error Pattern Safety Guidelines for Agentic Engines
- License
- MIT
- Instructions
- 204 lines in SKILL.md · view on GitHub
Files (1)
- SKILL.md
SKILL.md (first lines)
# Error Pattern Safety Guidelines
This document outlines the safety guidelines for error pattern regex in agentic engines to prevent infinite loops in JavaScript.
## The Problem
When using regex patterns with the JavaScript global flag (`/pattern/g`), patterns that can match zero-width (empty strings) can cause infinite loops. This happens because:
1. JavaScript's `regex.exec()` with the `g` flag uses `lastIndex` to track position
2. When a pattern matches zero-width, `lastIndex` doesn't advance
3. The same position is matched repeatedly, causing an infinite loop
## Dangerous Pattern Examples
**❌ NEVER USE THESE PATTERNS:**
```javascript
// Pure .* - matches everything including empty string at end
/.*/g
// Single character with * - matches zero or more (including zero)
/a*/g
// Patterns that can match empty string
/(x|y)*/g
```
## Safe Pattern Examples
**✅ ALWAYS USE PATTERNS LIKE THESE:**
```javascript
// Required prefix before .*
/error.*/gi
/error.*permission.*denied/gi
// Specific structure with required content
/\[(\d{4}-\d{2}-\d{2})\]\s+(ERROR):\s+(.+)/g
// Required characters throughout
/access denied.*user.*not authorized/gi
```
## Pattern Safety Rules
1. **Always require at least one character match**
- Use `.+` instead of `.*` when you need "something"
- Ensure pattern has required prefix/suffix
2. **Never use bare `.*` as the entire pattern**
- Always combine with required text: `error.*`
- Never just `.*` or `.*?`
3. **Test patterns against empty string**
```javascript
const regex = /your-pattern/g;
if (regex.test("")) {
throw new Error("Pattern matches empty string - DANGEROUS!");
}
```
4. **Use specific anchors when possible**
- Start: `^error.*`
- End: `.*error$`
- Word boundaries: `\berror\b`
## Validation Tests
All error patterns must pass these tests:
### Go Tests (pkg/workflow/engine_error_patterns_infinite_loop_test.go)
```go
// Test that pattern doesn't match empty string
func TestPatternSafety(t *testing.T) {
pattern := "your-pattern"
regex := regexp.MustCompile(pattern)
if regex.MatchString("") {
t.Error("Pattern matches empty string!")
}
}
```
### JavaScript Tests (pkg/workflow/js/validate_errors.test.cjs)
```javascript
test("should not match empty string", () => {
const regex = new RegExp("your-pattern", "g");
expect(regex.test("")).toBe(false);
});
```
## Safety Mechanisms in validate_errors.cjs
The `validate_errors.cjs` script has built-in protections:
1. **Zero-width detection**: Checks if `regex.lastIndex` stops advancing
2. **Iteration warning**: Warns at 1000 iterations
3. **Hard limit**: Stops at 10,000 iterations to prevent hang
```javascript
// Safety check in validate_errors.cjs
if (regex.lastIndex === lastIndex) {
core.error(`Infinite loop detected! Pattern: ${pattern.pattern}`);
break;
}
```
## Adding New Error Patterns
When adding new error patterns to engines:
1. **Write the pattern with required content**
```go
{
Pattern: `(?i)error.*permission.*denied`,
LevelGroup: 0,From kaushal-waygood/agentic-self-healing-ci, MIT.
More from kaushal-waygood/agentic-self-healing-ci
- 0.401score
gh-agent-session
kaushal-waygood
GitHub CLI Agent Session Extension
SkillDFreshness: DClaude Code +9 - 0.401score
gh-agent-task
kaushal-waygood
GitHub CLI Agent Task Extension
SkillDFreshness: DClaude Code +9 - 0.401score
github-mcp-server
kaushal-waygood
GitHub MCP Server Documentation
SkillDFreshness: DClaude Code +9 - 0.387score
Dictation Instructions
kaushal-waygood
Instructions for fixing speech-to-text errors and improving text quality in gh-aw documentation and workflows
SkillDFreshness: DClaude Code +9 - 0.208score
custom-agents
kaushal-waygood
No description from the publisher yet.
SkillDFreshness: DClaude Code +9
Signals
- Stars
- 0
- Forks
- 0
- Open issues
- 0
- Last commit (this folder)
- Dec 2, 2025 (11 months ago)
From GitHub (fetched Oct 24, 2026).
Details
- License
- MIT
- Website
- gh.io/gh-aw
- First seen
- Oct 24, 2026
- Last checked
- Oct 24, 2026
- Source
- GitHubgithub-graphql
Same skill elsewhere
Copies of this SKILL.md published by others; search shows only one of them.
More from kaushal-waygood
- 0.401score
gh-agent-session
kaushal-waygood
GitHub CLI Agent Session Extension
SkillDFreshness: DClaude Code +9 - 0.401score
gh-agent-task
kaushal-waygood
GitHub CLI Agent Task Extension
SkillDFreshness: DClaude Code +9 - 0.401score
github-mcp-server
kaushal-waygood
GitHub MCP Server Documentation
SkillDFreshness: DClaude Code +9 - 0.387score
Dictation Instructions
kaushal-waygood
Instructions for fixing speech-to-text errors and improving text quality in gh-aw documentation and workflows
SkillDFreshness: DClaude Code +9
Cite this page
error-pattern-safety skill. Agent Mart. https://agentmart.dev/skills/kaushal-waygood-error-pattern-safety (last updated 2026-10-24)