bunqueue
AGENTS.md569 starsChanged 4 months agoMITView on GitHub
This file applies to the entire repository unless a more specific AGENTS.md exists in a subdirectory. bunqueue is a high-performance job queue written in TypeScript for Bun. The server and embedded runtime are Bun-only. Persistence uses bun:sqlite; public clients may run in other runtimes through the network protocol. - Before every git commit and every git push, invoke the skeptic custom subagent and wait for its verdict. It must inspect the complete staged diff, identify at least three potential failure…
- Reads credentials
- Commits and pushes
Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about checking a change actually works.
Of the AGENTS.md files we read, the 11,773 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 repository4 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- sdk/CLAUDE.mdCLAUDE.md
- bunqueue-devSkill
- bunqueueSkill
The file
Show its rules and text
We split this AGENTS.md into the rules it gives an agent
38 rules. About 1 is common, 19 are distinctive, and 18 are very specific to this project.
≈1
Common · estimate
Many files like this have a rule of this kind.
≈19
Distinctive · estimate
This author's own choices. Worth a look.
18
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 24
Before every git commit and every git push, invoke the skeptic custom subagent and wait for its verdict.
- Distinctive: line 31
When a bug is reported, first add a regression test that reproduces it.
- Distinctive: line 36
Keep all repository content in English, including source comments, tests, internal documentation, user-facing documentation and agent …
- Distinctive: line 38
Keep changes narrowly scoped to the requested behavior.
- Very specific: line 40
Use rg/rg --files for repository searches and apply_patch for manual source edits.
- Very specific: line 44
Keep hot queue paths synchronous while a shard lock is held.
- Distinctive: line 50
Use deterministic tie-breakers for paginated queries and add migrations for schema or index changes.
- Distinctive: line 52
Do not silently change externally visible scheduling semantics.
- Distinctive: line 55
Keep source files at or below 300 lines.
- Very specific: line 64
Every code change must update the corresponding internal technical documentation under /docs in the same change-set.
- Very specific: line 67
Update docs/features/<slug>.md when changing a module.
- Very specific: line 69
Update docs/data-model.md and/or the relevant feature document when changing a public type, SQLite table or index, TCP command, HTTP …
- Very specific: line 72
Update docs/architecture.md when components, data flows, or the module map change.
- Distinctive: line 78
Run repository tests in an isolated OrbStack Machine by default.
- Very specific: line 118
Do not use a translated amd64 Machine on Apple Silicon as final evidence.
- Very specific: line 123
Create Machines with both --isolated and --isolate-network.
- Very specific: line 144
Use a unique Machine name for every final candidate and delete it after its logs and environment manifest have been copied to artifacts/.
- Very specific: line 153
Run git diff --check on the host before creating the sanitized snapshot, because the Machine deliberately receives no .git directory.
- Distinctive: line 155
Run benchmarks only on native macOS, never in an OrbStack Machine or container.
- Distinctive: line 173
Do not commit if any suite fails or could not be run.
- Distinctive: line 192
Add regression tests for every confirmed bug.
- Distinctive: line 198
Prefer targeted tests in the current isolated development Machine during iteration.
- Distinctive: line 210
Treat the sandbox as process, filesystem, network, database, port, and environment isolation, not as separate physical machines.
- Very specific: line 215
Read complete suite output from artifacts/test-sandbox/<timestamp>/.
- Very specific: line 217
Read SDK-gate output from artifacts/test-sandbox-sdk/<timestamp>/ with the same anomaly and retained-container discipline.
- Very specific: line 219
Every sandbox run must emit complete logs, per-suite NDJSON resource samples, per-suite JSON, and the aggregate summary.json/summary.md.
- Distinctive: line 222
Treat memory slope or end-to-start growth as an investigation signal, not proof of a leak.
- Common: line 225
Never mount the repository, Docker socket, credentials, or the user's home directory into a test container.
- Distinctive: line 229
Use unique queue names and unique temporary SQLite paths.
- Very specific: line 231
Remove SQLite .db, -wal, and -shm files created by the test.
- Distinctive: line 232
Avoid timing-only assertions when state can be observed directly.
- Distinctive: line 234
Do not weaken an existing test merely to make a behavior change pass.
- Distinctive: line 236
Never publish benchmark results from Docker or a VM.
- Very specific: line 249
Use Markdown for self/total time and caller/callee triage, then the .cpuprofile in Chrome DevTools or VS Code for interactive flame …
- Very specific: line 267
Before every authorized git commit, update docs/src/content/docs/changelog.md for the staged changes and include that update in the same …
- Distinctive: line 272
Before every authorized git push, verify that each outgoing commit already contains its corresponding changelog update and has a compliant …
- Very specific: line 275
Do not create commits, push, bump the package version, or publish unless the user explicitly authorizes the relevant action.
- Distinctive: line 280
Call out any test or check that could not be run and why.
≈ “Common” is an estimate: at least 1 in 5 of the 16,595 AGENTS.md 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
AGENTS.md
This file applies to the entire repository unless a more specific AGENTS.md
exists in a subdirectory.
Project overview
bunqueue is a high-performance job queue written in TypeScript for Bun. The
server and embedded runtime are Bun-only. Persistence uses bun:sqlite; public
clients may run in other runtimes through the network protocol.
Repository map
src/application/: queue orchestration and use-case logic.src/domain/: jobs, shards, priority queues, counters, and limiters.src/infrastructure/: SQLite persistence and transport adapters.src/client/: public Queue/Worker APIs.test/: Bun unit, integration, regression, and reproduction tests.docs/: documentation site.sdk/: language SDKs and conformance fixtures.
Working rules
- Before every
git commitand everygit push, invoke theskepticcustom subagent and wait for its verdict. It must inspect the complete staged diff, identify at least three potential failure points per changed file, verify error handling, races, idempotency, type safety and test evidence, and run applicable checks.FAILblocks the operation;CONDITIONALrequires the user's explicit confirmation. The project profiles live at.codex/agents/skeptic.tomland.claude/agents/skeptic.md. - When a bug is reported, first add a regression test that reproduces it. Only after the test fails for the expected reason, use subagents to investigate fixes and prove the chosen fix with the passing regression test.
- Preserve user changes. Never run
git reset,git checkout,git clean, or discard unrelated edits unless the user explicitly requests it. - Keep all repository content in English, including source comments, tests, internal documentation, user-facing documentation and agent configuration.
- Keep changes narrowly scoped to the requested behavior. Do not refactor unrelated code while fixing a bug.
- Use
rg/rg --filesfor repository searches andapply_patchfor manual source edits. - Runtime source is TypeScript ESM. Follow the existing 2-space, single-quote, semicolon style; Oxlint and Oxfmt are authoritative.
- Keep hot queue paths synchronous while a shard lock is held. Do not introduce
an
awaitinside a synchronous critical section. - Maintain queue invariants together: heap membership,
jobIndex, processing maps, counters, temporal indexes, group ownership, and concurrency slots must transition exactly once. - SQLite filtering, ordering, and pagination must happen in a consistent order. Use deterministic tie-breakers for paginated queries and add migrations for schema or index changes.
- Do not silently change externally visible scheduling semantics. Add explicit regression coverage when priority, delay, FIFO-group, retry, or recovery behavior changes.
- Keep source files at or below 300 lines. Give each file one responsibility and export only what is needed; split a file instead of growing it beyond that boundary.
- Respect the lock hierarchy:
jobIndex->completedJobs->shards[N]->processingShards[N]. Read prerequisite state before acquiring the next lock and always release locks infinally.
Documentation
- Every code change must update the corresponding internal technical
documentation under
/docsin the same change-set. A code change is not complete while its documentation is stale. - Update
docs/features/<slug>.mdwhen changing a module. New modules also need links fromdocs/README.mdanddocs/architecture.md. - Update
docs/data-model.mdand/or the relevant feature document when changing a public type, SQLite table or index, TCP command, HTTP endpoint, environment variable, or default value. - Update
docs/architecture.mdwhen components, data flows, or the module map change. The Astro user documentation underdocs/src/content/docs/and its changelog are separate from the internal technical reference.
Validation
Run repository tests in an isolated OrbStack Machine by default. A macOS host run is diagnostic only and does not count as final validation evidence. Run the narrowest relevant tests while iterating:
BUNQUEUE_EMBEDDED=1 bun test test/path-to-test.test.ts
bun run test:model
bun run typecheck
bunx oxlint src test/path-to-test.test.ts
bunx oxfmt --check src test/path-to-test.test.ts
git diff --checkMANDATORY: Run bun run test:model after every change that can affect job
lifecycle, persistence/recovery, scheduling/order, dependencies, deduplication,
leases, rate/concurrency limits, counters, temporal indexes, or jobIndex.
This command runs the fast-check asynchronous command model against a real
TCP broker and SQLite. It is targeted iteration evidence, not a replacement for
the final sandbox (the sandbox's unit suite runs it again).
The model must continue to enforce conservation, no loss/resurrection,
exclusive delivery, custom-ID idempotency, retry/stall bounds, legal
transitions, priority/FIFO/LIFO/delay/group/dependency ordering, unique keys,
rate/concurrency/TTL resource rules, counter/index coherence, idempotent
recovery, and DLQ exactly-once. When it fails, record the printed seed,
counterexample, and replay path. Distinguish a model error from an engine
divergence; for a confirmed engine bug, preserve the minimized sequence as a
deterministic test/repro-model-*.test.ts regression before fixing it.
OrbStack Machine gate
Final Linux validation must run in a fresh, disposable OrbStack Machine. The
canonical local environment is Ubuntu 24.04 on the Mac's native architecture;
on Apple Silicon this means arm64. Allocate 4 CPUs, request 16 GiB of memory,
and at least 32 GiB of disk, then record the effective cgroup limits because
OrbStack may clamp them to its global limits. GitHub Actions ubuntu-latest
provides the independent native amd64 gate. Every release must also run the
same native product suites in a fresh Debian 13 Machine using the Mac's native
architecture.
Do not use a translated amd64 Machine on Apple Silicon as final evidence.
Rosetta is useful for diagnostics, but process-heavy Bun tests can behave
differently under translation. Record such a run as diagnostic and repeat it
on a native-architecture Machine.
Create Machines with both --isolated and --isolate-network. Do not use
--mount or --forward-ssh-agent. Never expose the macOS repository, home
directory, Docker socket, credentials, SSH agent, package-manager tokens, or
real environment files to a Machine. A tracked placeholder-only template such
as .env.example is allowed only after its contents have been reviewed.
Transfer an explicit sanitized worktree snapshot over OrbStack's built-in SSH
transport; it must contain all tracked and intended untracked
changes while excluding .git, ignored files, node_modules, artifacts,
SQLite databases, generated test output, secrets, and credentials.
Provision the exact Bun version pinned by CI and install from the frozen lockfile. Then run, directly in each Machine:
bun test --parallel=4
bun scripts/tcp/run-all-tests.ts
bun scripts/embedded/run-all-tests.ts
bun run typecheck
bun run check:oxcUse a unique Machine name for every final candidate and delete it after its
logs and environment manifest have been copied to artifacts/. Record the
distro, version, architecture, kernel, Bun version/revision, command, exit code,
duration, and exact test totals. A reused Machine or a host-only run is not
release evidence. OrbStack Machines and containers share OrbStack's underlying
Linux kernel, so this is strong filesystem/process/network separation but not a
separate-kernel or physical-machine security boundary.
The Machine gate supplements rather than replaces the container gates below.
Run git diff --check on the host before creating the sanitized snapshot,
because the Machine deliberately receives no .git directory.
Run benchmarks only on native macOS, never in an OrbStack Machine or container.
MANDATORY: After ANY code modification, run the isolated validation before committing:
bun run test:sandboxThe sandbox builds the current worktree and runs ALL THREE required suites in parallel, in separate disposable containers:
bun test --parallel=4 # Unit tests (four isolated file workers)
bun scripts/tcp/run-all-tests.ts # TCP integration tests (~50 suites)
bun scripts/embedded/run-all-tests.ts # Embedded integration tests (~35 suites)Do not commit if any suite fails or could not be run. No exceptions.
MANDATORY: After ANY modification under sdk/, run the isolated SDK
validation before handoff (and again before committing if more SDK edits were
made):
bun run test:sandbox:sdkThis second gate runs the native tests and shared protocol conformance checks
for every official external SDK in separate disposable containers. Both
test:sandbox and test:sandbox:sdk are required after SDK changes; a targeted
native SDK test is diagnostic feedback, not a replacement for the sandbox.
The exact native commands are a diagnostic fallback when Docker is unavailable, not proof that sandbox isolation passed. Report the unavailable sandbox as a blocker before commit.
Add regression tests for every confirmed bug. A useful regression test should fail on the buggy implementation, exercise the public or real persistence path, and assert both the returned result and any affected counters/state.
Test hygiene
- Prefer targeted tests in the current isolated development Machine during iteration; use fresh disposable Machines and the sandbox for the final full gates. A host-native run is diagnostic only. Never run one container per individual unit test.
- Model campaigns can be deepened without editing source:
BUNQUEUE_MODEL_RUNS=500 BUNQUEUE_MODEL_COMMANDS=150 BUNQUEUE_MODEL_SEED=<signed-seed> bun run test:model. Preserve the sign printed byfast-check. Never remove or weaken an invariant merely to make a generated history pass. - The three top-level suites run concurrently by default. Use
BUNQUEUE_TEST_SEQUENTIAL=1only to diagnose possible resource contention; it runs the same commands with the same isolation. - Treat the sandbox as process, filesystem, network, database, port, and
environment isolation, not as separate physical machines. Suite containers
still share the OrbStack VM kernel, Docker daemon scheduling, CPU, memory,
and disk I/O. A failure seen only under parallel load must be reproduced with
BUNQUEUE_TEST_SEQUENTIAL=1before attributing it to application behavior. - Read complete suite output from
artifacts/test-sandbox/<timestamp>/. On failure, preserve the runner's retained container until the cause is known. - Read SDK-gate output from
artifacts/test-sandbox-sdk/<timestamp>/with the same anomaly and retained-container discipline. - Every sandbox run must emit complete logs, per-suite NDJSON resource samples,
per-suite JSON, and the aggregate
summary.json/summary.md. Review reported anomalies and slow-test rankings before handoff; do not report only pass/fail. - Treat memory slope or end-to-start growth as an investigation signal, not proof of a leak. Individual tests share a process and heap; confirm suspected leaks with a focused repeated-process, post-GC reproduction.
- Never mount the repository, Docker socket, credentials, or the user's home directory into a test container. Tests need no external network access.
- TCP functional files must use a fresh server, dynamic ports, and a unique temporary SQLite directory. Do not connect tests to an existing server.
- Use unique queue names and unique temporary SQLite paths.
- Close
QueueManager, Queue, Worker, server, and database instances in cleanup. - Remove SQLite
.db,-wal, and-shmfiles created by the test. - Avoid timing-only assertions when state can be observed directly. When testing delays or long-polling, use generous bounds and deterministic timestamps.
- Do not weaken an existing test merely to make a behavior change pass; update it only when the intended contract has explicitly changed.
- Never publish benchmark results from Docker or a VM. Run benchmarks natively, with a fresh process, database, ports, queues, and competitor state per sample. Docker Compose is only for functional tests requiring external services and must use a unique project name and disposable volumes.
CPU and memory profiling
- Profile a representative full workload for long enough to collect meaningful samples; a short smoke run is only a harness check. Use fresh process/state and record a separate unprofiled baseline. Profiled timings are diagnostic, never publishable benchmark results.
- Generate both CPU views in one native run:
bun --cpu-prof --cpu-prof-md --cpu-prof-dir=<artifact-dir> <workload>. Use Markdown for self/total time and caller/callee triage, then the.cpuprofilein Chrome DevTools or VS Code for interactive flame analysis. - Generate heap formats in separate native runs because
--heap-prof-mdoverrides--heap-profwhen combined:bun --heap-prof --heap-prof-dir=<artifact-dir> <workload>andbun --heap-prof-md --heap-prof-dir=<artifact-dir> <workload>. Both snapshots are written on process exit, so exercise cleanup and terminate normally. - Confirm leaks with repeated workload/cleanup cycles at equivalent checkpoints:
call
Bun.gc(true), recordbun:jscheapStats(),process.memoryUsage(), andQueueManager.getMemoryStats(), then compare retained types and retainer chains. RSS growth alone is not proof of a leak. - Bun has separate JavaScriptCore and native heaps. Use heap snapshots/stats for
JavaScript retention and opt-in
Bun.unsafe.mimallocDump()for native allocator diagnosis. Never expose profiling as an unauthenticated endpoint; snapshots may contain job payloads or secrets. Store outputs only under ignoredartifacts/.
Commits and handoff
- Before every authorized
git commit, updatedocs/src/content/docs/changelog.mdfor the staged changes and include that update in the same commit. The commit message is mandatory and must be a non-empty, concise, specific English description of the actual changes; generic placeholder messages are forbidden. - Before every authorized
git push, verify that each outgoing commit already contains its corresponding changelog update and has a compliant commit message. Do not edit the changelog solely because a push is being performed. - Do not create commits, push, bump the package version, or publish unless the
user explicitly authorizes the relevant action. Version bumps and
bun publishare separate release actions and are not implied by permission to commit or push. Never publish withnpm publish. - Report the files changed, behavior fixed, and exact validation commands/results.
- Call out any test or check that could not be run and why.
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.

