sleep-aware-background-work

sleep-aware-background-work is a cursor rule for Cursor from paperclipai/paperclip. It costs 0 tokens per session (1,463 once invoked), scanned A, original, MIT.

A set of rules for making background work wait for real events or deadlines instead of repeatedly checking while idle. It covers services, workers, database connections, adapters, plugins, and runners.

In plain words
What is it for?
Use it when adding background activity, database work, retries, expiry handling, startup logic, or service-worker behavior.
Why use it?
It prevents needless polling, reduces idle work, and makes sleeping or restarting background processes safer and easier to recover.

Cursor rule for Cursor

Written for Cursor: a Cursor rule (.mdc).

Good fit Use it when adding background activity, database work, retries, expiry handling, startup logic, or service-worker behavior.

Compare 6 cursor rules from other repositories ↓
Install with agentmods
npx agentmods add rules/paperclipai/paperclip/sleep-aware-background-work
About the project

Paperclip is a Node.js server and React application for coordinating AI agents as a business team, with goals, organizational roles, budgets, governance, and work tracking in one interface. It is used by people managing multiple agents or autonomous agent organizations across tools such as OpenClaw, Claude Code, Codex, and Cursor. The catalogue includes skills, agents, an MCP add-on, and an instruction for working with Paperclip.

paperclipai/paperclip · 107,300 stars · on GitHub · paperclip.ing

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Clone the repo
git clone --depth 1 https://github.com/paperclipai/paperclip

Made for: Cursor.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for sleep-aware-background-work

README.md
[![agentmods](https://agentmods.dev/badge/rules/paperclipai/paperclip/sleep-aware-background-work/github.svg)](https://agentmods.dev/rules/paperclipai/paperclip/sleep-aware-background-work)
Your own site
<a href="https://agentmods.dev/rules/paperclipai/paperclip/sleep-aware-background-work"><img src="https://agentmods.dev/badge/rules/paperclipai/paperclip/sleep-aware-background-work/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for sleep-aware-background-work

Your own site · 80×15
<a href="https://agentmods.dev/rules/paperclipai/paperclip/sleep-aware-background-work"><img src="https://agentmods.dev/badge/rules/paperclipai/paperclip/sleep-aware-background-work.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 1,463 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00000 $0.01463
Opus 5.5 $0.00000 $0.00585
Sonnet 5.5 $0.00000 $0.00293
Haiku 4.5 $0.00000 $0.00146

Measured 4d ago against content hash 7d9500845bcc, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade A, and why

sleep-aware-background-work scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 4d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

rules/sleep-aware-background-work.mdc · 120 lines

How it starts

The opening of the file, as written. The whole thing — 120 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Background work must become idle

Apply to new or materially changed background work, its producers, and its startup/lifecycle wiring. This includes server/src/index.ts, service workers, DB connection management, adapters, and plugin or runner background activity.

This is a prospective review requirement, not a demand to migrate every existing loop. Do not block unrelated edits on untouched polling. Adding a duty to an existing heartbeat or sweep, extending its lifetime, or copying its polling pattern is new behavior and must meet this rule. An unchanged adjacent loop is not precedent or permission.

Choose the trigger before the mechanism

An idle subsystem must not repeatedly query the database or contact another service merely to discover that it is still idle. Ask: if nothing changes, is there a real obligation to act at a future time?

Obligation Required approach
Local state changes or an operation completes Direct call, event, promise, or completion callback
A database write creates work Transaction-aware notification from the supported producer
A routine, expiry, or retry is due later Register its actual next deadline with the shared scheduler
Delivery, cleanup, a claim, or a write remains unresolved Recovery tied to that concrete obligation and its resolution
Work must survive restart Reconstruct from the existing durable source of truth at startup/resume

Split mixed duties. Deliver on an event; schedule a retry only after failure or while an obligation remains. Do not add setInterval, recursive timeouts, sleep loops, or heartbeat callbacks that scan empty work indefinitely. Putting the same scan behind the scheduler is still polling. A larger interval or .unref() does not establish idle behavior. Configuration or retained completed history alone must not keep an otherwise idle worker scanning.

Reuse the shared lifecycle

  • Server workers use delivery-work-coordinator.ts and its work-scheduler.ts for coalescing, non-overlapping execution, retries, and named deadlines. Do not create a per-feature scheduler or independent maintenance timer in index.ts. Adapter, plugin, and runner work uses the owning host's lifecycle interface; extend that boundary when needed instead of importing server internals.
  • Register, replace, and cancel the actual next deadline. No pending work, unresolved write, or future obligation means no scheduled scan. An unconditional nextRunAt = now + interval is not a deadline unless a real obligation requires it.
  • Existing rows remain durable truth; notifications are hints to inspect them. Do not add a table per timer or thread recovery bookkeeping through callers. Keep work predicates and provider behavior in their owning services, consistent with module-boundaries.mdc.
  • Use notifyDeliveryWork and work-signals.ts for database-produced work. Await intent registration before the relevant write in its transaction. A nested savepoint release is not an outer commit. Preserve uncertainty until the transaction protocol establishes settlement; one empty query or elapsed timeout cannot prove an uncertain write will not commit later.
  • Account for every supported producer. Process-local notifications do not cover other replicas, independent SQL writers, or external events without ingress. Do not remove their only recovery path without replacing that contract.
  • Use the shared database client for idle connection release and reconnect. Do not add permanent DB keepalives/listeners or scattered connect/disconnect wrappers as a substitute for a wake contract.

Read the full file on GitHub · 120 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 4d ago First seen · 120 lines · 0 tokens per session scan A 7d9500845bcc

Subscribe to this mod's changes

sleep-aware-background-work is a cursor rule published in the GitHub repository paperclipai/paperclip (107,300 stars, last pushed today), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 1,463 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-10-22.