Architectural Invariant Design: Bun 1.2 Multi-Tenant Worker Memory Isolation & Execution Quotas
Bun 1.2 Multi-Tenant Worker Memory Isolation & Execution Quotas defines an industrial-grade behavioral standard for backend engineering. Enforces strict heap budgets, thread-level WebWorker isolation, and execution CPU/memory quotas when running untrusted multi-tenant workloads in Bun 1.2. Prohibits in-process evaluation and ensures all worker instances are aggressively terminated via deterministic abort signals and heap bounds to prevent noisy-neighbor memory leakage. Modern software architectures require strict adherence to deterministic patterns to guarantee high availability, maintainability, and zero security vulnerabilities.
Hazard Analysis: What Breaks Without This Rule
The following failure modes have been cataloged from hundreds of hours of production code reviews where AI assistants produced non-compliant implementations:
| Failure Mode | AI Symptom (The Anti-Pattern) | Severity | Production Impact & Remedy |
|---|---|---|---|
| AI Hallucination & Deprecation Drift | Executing untrusted tenant code within the primary process heap or unmetered, long-lived WebWorkers without hard termination ceilings. | Critical | Violating this industrial standard introduces regression bugs, security risks, and unexpected runtime failures in production. Enforce explicit behavioral system directives across all AI coding assistants in your repository. |
| Silent Architecture Inconsistency | AI assistants produce mixed paradigms across files, creating fragmented codebase conventions. | Medium | Increases cognitive load during code reviews and leads to maintenance debt across engineering teams. Pin project conventions in .cursor/rules, CLAUDE.md, and AGENTS.md so all team agents follow identical guardrails. |
Step-by-Step Production Directives
Each rule constraint below is injected into the AI agent's system prompt to establish deterministic boundaries:
Engineers MUST ALWAYS instantiate isolated WebWorkers using `new Worker(new URL(..., import.meta.url), { smol
Engineers MUST ALWAYS instantiate isolated WebWorkers using `new Worker(new URL(..., import.meta.url), { smol: true })` for tenant execution to reduce baseline JavaScriptCore heap footprint.
Engineers MUST NOT execute tenant-provided code via `eval()`, `new Function()`, or dynamic `import()` within the host application thread or shared worker pools.
Engineers MUST NOT execute tenant-provided code via `eval()`, `new Function()`, or dynamic `import()` within the host application thread or shared worker pools.
Engineers MUST ALWAYS enforce an absolute wall-clock CPU timeout using `AbortController` coupled with `worker.terminate()` to guarantee tenant execution bounds.
Engineers MUST ALWAYS enforce an absolute wall-clock CPU timeout using `AbortController` coupled with `worker.terminate()` to guarantee tenant execution bounds.
Workers MUST communicate solely via strictly serialized structured clone messages or `ArrayBuffer` transfers
Workers MUST communicate solely via strictly serialized structured clone messages or `ArrayBuffer` transfers; shared mutable state across tenant boundaries is strictly prohibited.
Worker managers MUST inspect memory delta and trigger explicit garbage collection or worker disposal when memory threshold limits (e.g., 64MB per worker) are exceeded.
Worker managers MUST inspect memory delta and trigger explicit garbage collection or worker disposal when memory threshold limits (e.g., 64MB per worker) are exceeded.
Engineers MUST ALWAYS wrap worker messaging in safe cleanup blocks (`finally { worker.terminate()
Engineers MUST ALWAYS wrap worker messaging in safe cleanup blocks (`finally { worker.terminate(); }`) for ephemeral tenant jobs to prevent dangling thread handles.
Frequently Asked Technical Questions
Common questions developers face when configuring AI coding assistants for this stack:
Q:Why is Bun 1.2 Multi-Tenant Worker Memory Isolation & Execution Quotas critical for AI coding assistants?
Enforces strict heap budgets, thread-level WebWorker isolation, and execution CPU/memory quotas when running untrusted multi-tenant workloads in Bun 1.2. Prohibits in-process evaluation and ensures all worker instances are aggressively terminated via deterministic abort signals and heap bounds to prevent noisy-neighbor memory leakage. Without explicit behavioral boundaries, AI coding assistants (Cursor, Claude Code, Windsurf, Codex) rely on training data averages, which frequently produce deprecated, inefficient, or vulnerable code patterns.
Q:How does adopting this rule prevent AI hallucinations?
This rule explicitly declares what the AI must avoid (Executing untrusted tenant code within the primary process heap or unmetered, long-lived WebWorkers without hard termination ceilings.) and prescribes verified positive examples. Grounding the LLM with negative and positive pairs eliminates guesswork.
Q:Which AI coding environments are supported?
This specification is multi-platform compatible: Cursor (.cursor/rules/*.mdc & .cursorrules), Anthropic Claude Code (CLAUDE.md), Windsurf (.windsurfrules), Codex / Cline (AGENTS.md), and GitHub Copilot (.github/copilot-instructions.md).
Q:Can I combine this rule with other technology stacks?
Yes. Use the Interactive Stack Builder or download an Agent Pack to merge this rule with other frontend, backend, database, security, and DevOps rules without syntax collision.