Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
129 changes: 78 additions & 51 deletions .agent-instructions/reference/rules/13-staging-verification-full.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ account's workers.dev subdomain and the Hetzner account.
| `staging` | `https://app.sammy.party` | `https://api.sammy.party` | `sam` / `staging` |
| `staging2` | `https://app.sammy2.party` | `https://api.sammy2.party` | `sam2` / `staging2` |

**Choosing one.** Read the lease of both (`task=staging-lease`, environments `staging` and
`staging2`) and take whichever is free. Each installation has its own lease, its own deploy
concurrency group and its own data, so two agents can verify at the same time. Deploy with
**Choosing one.** Read the queue of both (`node scripts/deploy/staging-lease.mjs status staging`
and `... status staging2`) and reserve the one that is free or has the shorter queue. Each
installation has its own lease and queue, its own concurrency groups and its own data, so two
agents can verify at the same time. Deploy with
`gh workflow run deploy-staging.yml --ref <branch> -f environment=staging2 -f sam_task_id=<id>`
(omit `environment` for `staging`). Storage activation and the agent-email DNS audit are
primary-only, and so is the signed GitHub-trigger audit (staging2 has no GitHub App). The
Expand Down Expand Up @@ -95,73 +96,99 @@ GitHub may label some checks as informational, advisory, or not strictly require

Staging deployment is **manual** — it does NOT run automatically on PRs. You must trigger it yourself:

1. **Read the environment lease** (the workflow enforces the same check atomically):
1. **Read the queue of both installations** (one `gh api` call each):

```bash
gh api --method GET repos/raphaeltm/simple-agent-manager/deployments \
-f environment=staging -f task=staging-lease -f per_page=1 \
--jq '.[0] | {id, payload}'
node scripts/deploy/staging-lease.mjs status staging2 # and: status staging
# Raw records, newest first (a `snapshot` plus newer `reservation` events):
gh api 'repos/raphaeltm/simple-agent-manager/deployments?environment=staging2&task=staging-lease&per_page=100' \
--jq '[.[] | {id, payload}]'
```

Use your selected environment name in every command. The latest `staging-lease`
deployment payload is authoritative; ordinary deployment statuses and a quiet
Actions queue do not release the slot. A held foreign branch with a future
`expiresAt` owns live verification even after its deploy finishes. Schedule a
one-time SAM wake at that exact UTC expiry (`schedules_write`, method `create`,
`message_session` action for your session), persist the accepted schedule ID,
and continue independent work or end the turn. On wake re-read once and retry
if free; if renewed, schedule a new wake. Do not poll, wait five minutes, or
negotiate the slot in chat.
`status` prints the holder, whether the slot is free, and the ordered queue
(branch, SAM task ID, reserved-at, turn window). There are two staging
installations, `staging` (`sammy.party`) and `staging2` (`sammy2.party`); pick the
one that is free or has the shorter queue and use that name in every command
below. They share the `staging` credentials but nothing else. staging2 sign-in is
workload identity only; see "Two Staging Installations" in the full reference.

No record means free (first-use bootstrap). A malformed latest record or API
error fails closed: ownership cannot be established safely. Inspect/fix the
record through the normal reviewed workflow; never delete history to bypass
another branch's lease.
2. **Reserve first, then deploy only on your turn.** Reserving takes seconds and
deploys nothing:

2. **Acquire by deploying your branch**, with your SAM task ID:
```bash
gh workflow run deploy-staging.yml --ref <your-branch> \
-f environment=staging2 -f lease_action=reserve -f sam_task_id=<your-task-id>
```

The run summary shows your position and estimated turn. When the slot is free
(holder released, or its lease expired), only the head of the queue may take it,
for `STAGING_LEASE_GRACE_MINUTES` (default 10); if it does not, the next entry
gets its own grace period and the missed one is dropped. If the holder released
early, the head's turn still lasts until the holder's announced expiry plus grace.
Schedule a one-time SAM wake (`schedules_write`, method `create`,
`message_session` for your session) at your turn start, persist the schedule ID,
and end the turn or do independent work. Do not poll, and **never dispatch a
deploy while another branch holds the lease or it is another branch's turn**: the
run is refused (your place is kept). A reservation expires after
`STAGING_LEASE_RESERVATION_MINUTES` (default 480) unless renewed by reserving
again, which keeps your place. While the holder is a branch whose workflow predates
the queue (its lease record is version 1), no reservation is written, because its
workflow cannot read queue records and would be locked out of its own lease:
schedule a wake at its expiry and reserve then.

On your turn, deploy (or `-f lease_action=acquire` to hold without deploying):

```bash
gh workflow run deploy-staging.yml --ref <your-branch> \
-f environment=staging -f sam_task_id=<your-task-id> -f lease_hold_minutes=30
-f environment=staging2 -f sam_task_id=<your-task-id> -f lease_hold_minutes=30
```

The serialized lease job reads, acquires and reads back the lease before any
deploy/audit job. A foreign active lease fails immediately with holder branch,
task and expiry. Same-branch redeploys renew it. Expiry is acquisition time plus
expected deployment time plus live-check hold. GitHub Environment variables
`STAGING_LEASE_EXPECTED_DEPLOY_MINUTES` (default 30),
`STAGING_LEASE_DEFAULT_HOLD_MINUTES` (default 30), and
`STAGING_LEASE_MAX_HOLD_MINUTES` (default 120) configure durations; positive
integer holds above the cap are rejected. Expected deploy time may be zero.
Choose a hold covering your checks; renew before expiry if needed. Failed or
cancelled runs retain the lease until release/expiry, so failures cannot expose
checks to an overwrite.

To reserve or renew without deploying, use `-f lease_action=acquire`. This
holds for just the requested live-check duration (no deploy allowance), and
also permits bounded lease lifecycle verification without full redeploys.
Audit-only runs acquire/renew through the same gate. Storage activation and
the agent-email DNS audit currently support only the primary `staging` slot;
unsupported combinations are rejected before lease acquisition. Lease writes must go
through this workflow; direct `gh api` writes bypass serialization.

3. **Watch the run and verify live**, then **release early** from the holder branch:
A deploy dispatch also reserves if you are not queued yet, and goes straight
through when the slot is free and nobody is waiting. The `queue` job records
places outside any concurrency group, so no later dispatch can cancel your place;
only a branch that holds the lease or whose turn it is reaches the serialized
`lease` job. Same-branch redeploys renew the lease. Expiry is acquisition time
plus expected deployment time (`STAGING_LEASE_EXPECTED_DEPLOY_MINUTES`, default
30; zero for `acquire`) plus the live-check hold
(`STAGING_LEASE_DEFAULT_HOLD_MINUTES`, default 30, capped by
`STAGING_LEASE_MAX_HOLD_MINUTES`, default 120). Failed or cancelled runs keep the
lease until release or expiry.

3. **Watch the run.** Keep the lease through every live check (section 2 below, and the
infrastructure checks where they apply); then **release** and hand over:

```bash
gh run list --workflow=deploy-staging.yml --branch=<your-branch> --limit=3 \
--json databaseId,status,conclusion,headSha
gh run watch <run-id>
# After live checks and test-resource cleanup:
```

After every live check and test-resource cleanup:

```bash
gh workflow run deploy-staging.yml --ref <your-branch> \
-f environment=staging -f lease_action=release -f sam_task_id=<your-task-id>
-f environment=staging2 -f lease_action=release -f sam_task_id=<your-task-id>
```

Confirm the release job passed and the newest payload has `state: released`.
Release shares the same environment concurrency group and refuses a foreign
holder. Expiry permits another branch to acquire automatically. Do not mistake
successful deployment completion for a release. Only the lease job receives
`deployments: write`; agents can inspect records with their existing `gh api`
read access. Leases are keyed by environment name for future staging slots.
Confirm the release run passed and `status` shows no holder. Release also
removes you from the queue if you were waiting. A branch that releases and wants
the slot again queues behind everyone already waiting. **If you release early,
message the next task in the queue** (`send_durable_message` to its SAM task ID
from `status`) so it can take its turn before its scheduled wake. Successful
deployment completion is not a release. Release only after your own deploy run
has finished: the next holder's deploy waits for an in-flight one in the
`staging-apply-<installation>` group, but your live checks are no longer
protected once you release.

Records are GitHub deployments with task `staging-lease`, keyed by installation.
A malformed snapshot or an unknown record version fails closed (no one can
change the lease until it is fixed through a reviewed change; never delete
history to get around another branch); a malformed reservation is skipped and
reported in the run. Branches whose workflow copy predates the queue are refused
by every queue record ("Malformed lease record"): they cannot reserve, deploy,
acquire or release until they update from `origin/main`. Only the `queue` and
`lease` jobs receive `deployments: write`; lease writes must go through the
workflow.

For container-backed Instant verification, `wrangler deploy` success means the
rollout started, not that every instance serves the new image. The shared staging
Expand Down
2 changes: 1 addition & 1 deletion .agents/skills/do/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Read the full workflow from `.claude/commands/do.md` and execute it. Use `.claud
4. **Implement** — follow checklist, push frequently, run quality checks. After the first push open the PR as a draft (`gh pr create --draft`); draft PRs run only quick CI checks. **For UI changes**: run mandatory Playwright visual audit with mock data on mobile + desktop viewports (see `.claude/rules/17-ui-visual-testing.md`)
5. **Validate** — full quality suite: lint, typecheck, test, build. As soon as the candidate is complete, mark the PR ready (`gh pr ready <pr-number>`), which starts the full CI suite, and request CodeRabbit at the same moment; reviews and staging then run in parallel with CI and CodeRabbit
6. **Review** — invoke local specialist skills / local subagents ($go-specialist, $cloudflare-specialist, etc.)
7. **Staging** — there are two installations, `staging` (`sammy.party`) and `staging2` (`sammy2.party`); read both leases and use whichever is free with `-f environment=<name>` (staging2 sign-in: workload identity). Read the latest environment-keyed GitHub deployment lease (`task=staging-lease`); when held by another branch, schedule a SAM wake at `expiresAt` instead of polling or chatting. Trigger `gh workflow run deploy-staging.yml --ref <branch> -f sam_task_id=<task-id>` to acquire/renew before deployment; after live checks release with the same command plus `-f lease_action=release` and confirm success. Configurable hold defaults/cap and commands: `.agent-instructions/reference/rules/13-staging-verification-full.md`. **Use `$CF_TOKEN` to query D1/KV/DNS directly** (see `.claude/rules/32-cf-api-debugging.md`) to verify migrations, data state, and feature flags — this is faster and more precise than UI-based checks. Then verify changed behavior end-to-end via Playwright. **For infrastructure changes** (cloud-init, VM agent, DNS, TLS, scripts/deploy): MUST provision a real VM and verify heartbeat arrives.
7. **Staging** — there are two installations, `staging` (`sammy.party`) and `staging2` (`sammy2.party`); read both queues with `node scripts/deploy/staging-lease.mjs status <name>` (one `gh api` call) and use the free or shorter one with `-f environment=<name>` (staging2 sign-in: workload identity). Reserve first: `gh workflow run deploy-staging.yml --ref <branch> -f environment=<name> -f lease_action=reserve -f sam_task_id=<task-id>`; schedule a SAM wake at your turn start (shown in the run summary and `status`) instead of polling or chatting, and never dispatch a deploy while another branch holds the lease or has its turn. On your turn deploy with the same command minus `lease_action` (only the head of the queue may take a freed slot, for a 10-minute grace period by default). After live checks release with `-f lease_action=release`, confirm success, and if you released early message the next task in the queue. Configurable hold defaults/cap and commands: `.agent-instructions/reference/rules/13-staging-verification-full.md`. **Use `$CF_TOKEN` to query D1/KV/DNS directly** (see `.claude/rules/32-cf-api-debugging.md`) to verify migrations, data state, and feature flags — this is faster and more precise than UI-based checks. Then verify changed behavior end-to-end via Playwright. **For infrastructure changes** (cloud-init, VM agent, DNS, TLS, scripts/deploy): MUST provision a real VM and verify heartbeat arrives.
8. **PR** — the PR is already ready from step 5 (create it now if not, not as a draft). Wait for the full CI run on the ready PR (the required `Durable Object Workers` check reports only after every job finished). CodeRabbit is requested when the PR is marked ready, through the trusted GitHub Actions path: apply the `coderabbit-review` label with `gh pr edit <pr-number> --add-label coderabbit-review`; if the label run did not fire (it never fires on a draft PR), run `gh workflow run coderabbit-bot-review.yml --ref main -f pr_number=<pr-number>`. Do not post `@coderabbitai review` directly with an agent token. Then wait about 15 minutes from the request, ending at once on a `Review skipped`, rate-limit or quota reply. A CodeRabbit review is not required, but one that arrives blocks merge: implement or resolve every finding with a reason, and give incremental reviews after pushed fixes the same wait. If no review arrives (silence, `Review skipped`, rate limit), record that in the PR's CodeRabbit Review Evidence and continue. Do not re-trigger in a loop, and never add `needs-human-review` or wait for a waiver because CodeRabbit is silent (see `.claude/rules/25-review-merge-gate.md`). If the user requested draft PR / do-not-merge, do not mark it ready; get the full suite with `gh workflow run ci.yml --ref <branch>`, stop at the draft PR and do not merge.
9. **Cleanup** — remove worktree, pull main

Expand Down
Loading
Loading