Files
PaperClipAI/rules
DottaandPaperclip 13a83dd68a docs: require sleep-aware background work in reviews (#17138)
## Thinking Path

> - Paperclip manages agents in instances that can be idle between
tasks.
> - Recurring empty database and network checks can keep idle instances
and databases awake.
> - Worker migrations already use events, transaction-aware signals, and
shared deadlines.
> - New features can still add idle scans unless contributors and code
reviewers share an explicit rule.
> - This PR makes that rule discoverable through the repository rule
loader and Greptile.
> - The rule applies to added or expanded behavior without requiring
unrelated legacy polling to be removed.

## Linked Issues or Issue Description

Refs #15625, #17000, #17094, #17106, and #17129.

**Current behavior**

The repository has module ownership and runtime dependency rules, but no
explicit review requirement against new idle polling. A new duty in a
heartbeat tick can undo the benefits of previous worker migrations.

**Proposed behavior**

Require events for changed state, transaction-aware signals for
database-produced work, and shared scheduling for real deadlines. Reject
recurring empty scans, including scans disguised as scheduler callbacks.
Review narrow polling exceptions against concrete obligations and sleep
impact.

**Reason and benefit**

Make sleep-aware design a default review expectation. Preserve delivery,
ambiguous-commit recovery, drain/resume, and external wake correctness
while preventing new permanent idle traffic. Existing unrelated polling
stays outside the requested change.

## What Changed

- Add rules/sleep-aware-background-work.mdc for server, database,
adapter, plugin, and runner background paths, including
server/src/index.ts.
- Require concrete triggers, pending-work predicates, quiet conditions,
actual deadlines, and lifecycle evidence.
- Describe narrow exceptions for active operations and external sources,
with required scope, stop conditions, and sleep limitations.
- Distinguish in-process scheduling from durable Cloud wake coverage.
- Register the matching scopes in .greptile/files.json and link the rule
from rules/README.md.
- Reuse the existing module-boundary rule for ownership instead of
duplicating provider policy.

## Verification

- Passed: JSON parsing, required rule metadata, exact parity between
frontmatter globs and Greptile scopes, and all repository links.
- Passed: 15 representative path matches, including server startup,
nested service workers, producer routes, tests, database signals,
adapters, plugins, and both runner source trees. UI, CLI, docs, and
workflow paths remain outside this rule's glob scope.
- Passed: git diff --check.
- Manually checked contrasting review cases: reject a new empty queue
interval; reject an always-rescheduled empty scan; allow an actual retry
deadline; allow a bounded active readiness probe with lifecycle cleanup;
leave untouched legacy loops alone; reject sleep approval based only on
an internal timer.
- No runtime code changed. Application builds and tests were not rerun
for this rules-only change. This validates rule structure and intended
interpretation, not future reviewer compliance or deployed sleep.
- Greptile: 5/5 on 0b95bbd38a, with no
findings or unresolved threads. Full hosted CI passed on the same head:
https://github.com/paperclipai/paperclip/actions/runs/39664730299.
- An additional audit of existing rule scopes initially assumed all YAML
glob strings were quoted. The audit was corrected to accept the existing
unquoted form; all rule-to-manifest mappings then passed without changes
to those rules.

## Risks

- Broad source globs can surface the rule on unrelated edits. Its body
limits enforcement to new or materially changed background behavior and
explicitly excludes unrelated legacy migration demands.
- A blanket ban on every timer would reject legitimate active
operations. Narrow exceptions require evidence and do not exempt
permanent empty scans.
- Greptile and agent rule loading provide review guidance, not a
mechanical proof that no polling exists. No regex timer ban or new
runtime behavior is introduced.

## Model Used

OpenAI GPT-6 through Codex with reasoning, source and session
inspection, editing, and structural validation. Exact serving model ID
and context-window size are not exposed in this session.

## Checklist

- [x] I have included a thinking path that traces from project context
to this change
- [x] I have specified the model used (with version and capability
details)
- [x] I have checked ROADMAP.md and confirmed this PR does not duplicate
planned core work
- [x] I have searched GitHub for duplicate or related PRs and linked
them above
- [x] I have either (a) linked existing issues with `Fixes: #` / `Closes
#` / `Refs #` OR (b) described the issue in-PR following the relevant
issue template
- [x] I have not referenced internal/instance-local Paperclip issues or
links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip`
URLs)
- [x] My branch name describes the change (e.g. `docs/...`, `fix/...`)
and contains no internal Paperclip ticket id or instance-derived details
- [x] I have run tests locally and they pass
- [x] I have added or updated tests where applicable
- [x] I have updated relevant documentation to reflect my changes
- [x] I have considered and documented any risks above
- [x] All Paperclip CI gates are green
- [x] Greptile is 5/5 with no open P2s, recommendations, or follow-ups
- [x] I will address all Greptile and reviewer comments before
requesting merge

Co-authored-by: Paperclip <noreply@paperclip.ing>
2026-10-21 15:11:42 -05:00
..

Repository rules

Keep architectural guidance in focused .mdc files here. Each file is Markdown with YAML frontmatter containing a description and an alwaysApply boolean. For scoped rules, set alwaysApply: false and provide comma-separated, repository-relative globs. For repository-wide rules, set alwaysApply: true and omit globs. Use ** for all descendants of a directory. Include sibling entry points explicitly when needed.

Root AGENTS.md tells coding agents to read matching rules before editing or reviewing code. This directory is a repository convention: Cursor does not automatically load it as .cursor/rules/, and the .mdc extension alone does not make a tool apply a rule.

Greptile reads matching rule files through .greptile/files.json and receives loading instructions from .greptile/rules.md. The rule body remains here as the single source of truth. Repository configuration takes effect when the files are available on the reviewed branch; local files alone are not visible to the hosted reviewer.

When adding or changing a rule:

  1. State the scope, required behavior, examples, exceptions, and review criteria.
  2. Add its path to .greptile/files.json. Copy its globs into that entry's scope array, one pattern per element. For alwaysApply: true, omit scope.
  3. Keep the rule's frontmatter and the Greptile scope synchronized. Verify that the scope covers representative files and excludes unrelated directories.
  4. Keep detailed policy in the rule file instead of copying it into tool settings.

Product behavior is covered by product-harness-responsibility.mdc: routine work belongs to the harness, and user-facing detail must support an outcome or a real decision. This applies to orchestration as well as UI.

See the Greptile file-reference documentation for the manifest format.

Background execution is covered by sleep-aware-background-work.mdc: new or expanded work must become quiet, use events and real scheduler deadlines, and preserve recovery across transactions, drain, and restart. This rule covers server/src/index.ts and the worker/producer paths in its scope. It does not require unrelated legacy polling to be migrated in the same PR.