Skip to content

Commit ccf161e

Browse files
committed
Add async lifecycle review rules for agents
1 parent e7d3adb commit ccf161e

1 file changed

Lines changed: 47 additions & 0 deletions

File tree

‎AGENTS.md‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Repository agent instructions
2+
3+
Follow the repository conventions in `CLAUDE.md`. Read `DESIGN.md` before making visual or interaction changes.
4+
5+
## Async jobs and polling
6+
7+
For features with background jobs, polling, retries, cancellation, or shutdown:
8+
9+
- Define the lifecycle states and ownership before implementation: pending, running, completed, failed, cancelled, stale, and closing.
10+
- Treat persisted state, in-memory jobs, subprocesses, HTTP requests, and rendered UI as separate state holders. Define how each transitions and settles.
11+
- Never apply a background response without proving it is still current. Use a generation, attempt ID, version, or guarded merge so older polling responses cannot overwrite newer actions.
12+
- Do not release a concurrency slot when cancellation is requested. Keep the job tracked until its underlying invocation or subprocess has terminated.
13+
- Do not let a retry replace a locally active job, even when its persisted lease has expired or wall-clock time changes.
14+
- Validate retry context against the current snapshot, plan revision, assignment, and referenced code. If any context is stale, disable retry and require a new request.
15+
- Preserve the original timeout, cancellation, and shutdown reason through every layer. Do not replace actionable errors with generic cancellation text.
16+
- Begin shutdown by rejecting new work at the outer admission boundary. Drain already-admitted HTTP requests, then cancel and await jobs, then close storage.
17+
- Polling endpoints should read only the state they need. Do not rebuild Git history or the full review merely to retrieve background-job status.
18+
19+
## Async review UI
20+
21+
- A background response must not erase text, selections, attachments, navigation changes, or other input made after the request started.
22+
- Clear a submitted draft only if its current value and attachment still match what was submitted. Treat this as compare-and-swap behavior.
23+
- Preserve completed historical results, but visibly mark them stale when their snapshot, plan revision, assignment, or referenced code no longer matches.
24+
- When polling updates one part of the screen, update only that state. Preserve scroll position unless the user was already following the bottom.
25+
26+
## Required race regressions
27+
28+
Before opening or updating a PR for asynchronous behavior, test every applicable interleaving with controllable promises, clocks, and partial requests:
29+
30+
- Poll starts, then a user action completes, then the old poll returns.
31+
- A job lease expires, then retry is attempted while the original job still runs.
32+
- Timeout fires, then the provider remains unsettled temporarily, then retry is attempted.
33+
- Shutdown starts, then a new request arrives.
34+
- A request is partially received, then shutdown starts, then the request completes.
35+
- An abort error fires, then subprocess close arrives later.
36+
- Submit starts, then the user edits the composer or switches items, then the response returns.
37+
- Referenced code is reassigned or the snapshot changes, then retry or rendering occurs.
38+
39+
Every reproduced race requires a failing-before and passing-after regression. Assert both the visible result and the durable state when they can diverge.
40+
41+
## Review readiness
42+
43+
- Run final validation against the exact pushed head after the last change.
44+
- Report current test counts separately from historical milestone counts.
45+
- Before requesting automated review, report the current head, CI state, mergeability, unresolved threads, and deferred follow-up issues.
46+
- Reproduce summary-only review concerns or turn them into a concrete follow-up issue. Do not repeatedly patch vague wording without a failure case.
47+
- For each review round, record what changed, what was declined and why, and the regression evidence. Re-request review until a round returns no new findings.

0 commit comments

Comments
 (0)