In software engineering, the most dangerous error isn’t a Crash—it’s a Hang.
A crash is loud. You get a stack trace, the process dies, and you fix it. A hang, however, is silent. The user waits. The spinner spins indefinitely. Trust evaporates by the second.
In the world of local AI, the “Silent Hang” is epidemic. The culprit? Usually a CLI tool waiting for an invisible permission prompt (Allow access? [y/N]) while running in a background process.
We built Superbrain to kill the Silent Hang for good.
The Architecture of Resilience
Superbrain is an autonomous supervision layer. It follows the “Observer-Critic” pattern, but with permission to kill.
1. Overwatch Layer 👁️
“I see everything.” Overwatch doesn’t just run the process; it wraps it in a protective layer that monitors:
- Stdout/Stderr: Real-time log parsing for error signatures.
- Resource Usage: Detecting CPU/RAM spikes or flatlines.
- Stall Detection: Flagging any process that hasn’t output a byte in 30 seconds.
2. The Internal Doctor ⚕️
“Diagnosis: Permission Block.” When Overwatch flags a stall, the Doctor steps in to analyze the specific state. It recognizes the signature of a frozen CLI:
- Symptom: Zero output for 5 seconds immediately after startup.
- Symptom: The last output line matches the regex
(.*)permission(.*). - Diagnosis: User Input Block.
3. The Healer (Stdin Injection) 💉
“I’ll handle this.” The Healer doesn’t blindly restart the process—that would just loop the error. Instead, it performs Microsurgery.
- It injects
y\ndirectly into the frozen process’sstdin. - It flushes the stream.
- It waits for the result.
- Result: The process resumes immediately.
- User Experience: A 500ms delay instead of an infinite hang.
The State Box: Security & the Vault
Resilience requires state. But where do you put it? You can’t pollute the user’s project folder. You can’t rely on effortless temp dirs.
Enter The State Box.
The Vault: ~/.switchailocal
This is a canonical, hardened directory designed for maximum privacy:
- Permission Auto-Hardening: On boot, Superbrain checks permissions. If they aren’t
0700(User Only), it fixes them. No curiosity seekers allowed. - Credential Inversion: API keys never live in the code config. They live in the Vault, encrypted at rest.
Atomic Durability
We treat configuration like a database transaction. We use a Rename-Swap pattern for every write operation:
- Buffered write to
config.tmp. - Hardware Sync (
fsync). - Atomic Rename to the final destination.
This prevents the “Half-Written Brain” scenario where a sudden power loss corrupts your routing matrix logic.
Conclusion
Superbrain and the State Box are the Guardians. One protects the Process (Runtime). The other protects the Memory (Storage).
Together, they turn a fragile script into a fortress. Because when you’re building the infrastructure for Intelligence, “it mostly works” isn’t good enough.
Sebastian Schkudlara
Intelligent Proxy Patterns: Building a Gateway That Learns