betting-brain-v3 / rules
Cursor rule8 starsChanged 14 months agoMITView on GitHub
Process management and zombie process prevention patterns
Where files are headingNew Cursor rule files have more rules about planning and tracking tasks, and fewer about code style.
Of the Cursor rule files we read, the 1,531 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repository27 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- .cursor/rules/99-floor.mdcCursor rule
- .cursor/rules/ai-friendly-testing.mdcCursor rule
- .cursor/rules/analytics-stub-api.mdcCursor rule
- .cursor/rules/analytics-testing.mdcCursor rule
- .cursor/rules/api-patterns.mdcCursor rule
- .cursor/rules/browser-extension.mdcCursor rule
- .cursor/rules/bun-runtime.mdcCursor rule
- .cursor/rules/cache-optimization.mdcCursor rule
- .cursor/rules/ci-integration.mdcCursor rule
- .cursor/rules/ci-patterns.mdcCursor rule
- .cursor/rules/cloudflare-infrastructure.mdcCursor rule
- .cursor/rules/cloudflare-workers.mdcCursor rule
- .cursor/rules/code-searchability.mdcCursor rule
- .cursor/rules/coverage-thresholds.mdcCursor rule
- .cursor/rules/database-patterns.mdcCursor rule
- .cursor/rules/documentation.mdcCursor rule
- .cursor/rules/endpoint-routing.mdcCursor rule
- .cursor/rules/file-naming.mdcCursor rule
- .cursor/rules/mcp-integration.mdcCursor rule
- .cursor/rules/production-security.mdcCursor rule
- .cursor/rules/quality-standards.mdcCursor rule
- .cursor/rules/root-organization.mdcCursor rule
- .cursor/rules/security-patterns.mdcCursor rule
- .cursor/rules/testing.mdcCursor rule
- .cursor/rules/testing-patterns.mdcCursor rule
- .cursor/rules/test-setup-patterns.mdcCursor rule
The file
We split this process-management.mdc into the rules it gives an agent
2 rules. About 0 are common, 2 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 64
Always use process manager in tests:
- Distinctive: line 85
Always ensure scripts handle cleanup on exit:
≈ “Common” is an estimate: at least 1 in 5 of the 3,030 Cursor rule files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
---
version: "1.0.0"
globs: "*.ts,*.js"
description: "Process management and zombie process prevention patterns"
lastUpdated: "2025-10-08"
dependencies: ["bun-runtime", "quality-standards"]
---
# Process Management Rules
## Zombie Process Prevention
**ALWAYS use the process cleanup utility for spawning child processes:**
```typescript
// ❌ BAD - Can create zombie processes
const proc = Bun.spawn(['command', 'args']);
await Promise.race([proc.exited, timeout]); // Process not killed on timeout
// ✅ GOOD - Automatic cleanup
import processManager from './tests/utils/process-cleanup';
const proc = processManager.spawn(['command', 'args']);
try {
await Promise.race([proc.exited, timeout]);
} catch (error) {
await processManager.kill(proc, 15, 2000);
} finally {
await processManager.killAll(3000);
}
```
## Process Spawning Patterns
### Script Files
For automation scripts that spawn processes:
```typescript
import processManager from '../tests/utils/process-cleanup';
async function runCommand(command: string[], timeout: number) {
const proc = processManager.spawn(command, {
cwd: process.cwd(),
stdio: ['ignore', 'pipe', 'pipe']
});
try {
const exitCode = await Promise.race([
proc.exited,
new Promise<never>((_, reject) =>
setTimeout(() => reject(new Error('Timeout')), timeout)
)
]);
return exitCode === 0;
} catch (error) {
await processManager.kill(proc, 15, 2000);
throw error;
}
}
```
### Test Files
Always use process manager in tests:
```typescript
import { describe, test, beforeEach, afterEach } from 'bun:test';
import processManager from '../utils/process-cleanup';
describe('My Test Suite', () => {
afterEach(async () => {
// Cleanup all spawned processes after each test
await processManager.killAll(3000);
});
test('should spawn process', async () => {
const proc = processManager.spawn(['echo', 'hello']);
await proc.exited;
});
});
```
## Signal Handling
Always ensure scripts handle cleanup on exit:
```typescript
// Automatic via processManager (recommended)
import processManager from './tests/utils/process-cleanup';
// Signal handlers are automatically set up
// Or manual (if needed)
process.on('SIGINT', async () => {
console.log('Cleaning up...');
await processManager.killAll(3000);
process.exit(0);
});
```
## Timeout Enforcement
**ALWAYS set timeouts for spawned processes:**
```typescript
// ❌ BAD - No timeout
await proc.exited;
// ✅ GOOD - With timeout
await Promise.race([
proc.exited,
new Promise((_, reject) =>
setTimeout(() => reject(new Error('Timeout')), 30000)
)
]);
```
## Cleanup Patterns
### Try-Finally Pattern
```typescript
let proc;
try {
proc = processManager.spawn(['command']);
await proc.exited;
} finally {
if (proc) {
await processManager.kill(proc);
}
await processManager.killAll(); // Cleanup all
}
```
### Async Function Cleanup
```typescript
async function myFunction() {
try {
const proc = processManager.spawn(['command']);
return await proc.exited;
} finally {
await processManager.killAll(3000);
}
}
```
## Key Files
- [Process Cleanup Utility](mdc:tests/utils/process-cleanup.ts) - Global process manager
- [CI Local Script](mdc:scripts/ci-local.ts) - Example usage in CI
- [Build Automation](mdc:scripts/automation/build-and-test.ts) - Example usage in automation
## Rules Summary
1. ✅ **Always** use `processManager.spawn()` instead of `Bun.spawn()` directly
2. ✅ **Always** set timeouts for process execution
3. ✅ **Always** kill processes on timeout/error
4. ✅ **Always** cleanup in `finally` blocks
5. ✅ **Always** call `processManager.killAll()` at script end
6. ❌ **Never** leave spawned processes untracked
7. ❌ **Never** spawn processes without timeout
8. ❌ **Never** forget cleanup in test `afterEach`
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

