Skip to content

ci(cleanup): fail the sweep leg when REST APIs can't be counted - #959

Merged
belaboe merged 7 commits into
mainfrom
fix/cleanup-rest-api-count
Nov 5, 2026
Merged

belaboe merged 7 commits into
mainfrom
fix/cleanup-rest-api-count

Conversation

@belaboe

@belaboe belaboe commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Problem

The scheduled stack cleanup (cleanup-stacks.yml) counts edge REST APIs per account against the 120-per-region quota, the limit that reds every deploy-dependent E2E lane when it fills up. When get-rest-apis failed, the step printed a warning and passed, so an account's count was invisible while it climbed. The warning's reason was always empty too: AWS CLI v2 writes its error as a blank line followed by the message, and the step printed only the first line.

The other sweeps had the same habit. A denied iam list-roles or ec2 describe-regions printed "nothing to sweep" and IAM roles in account: ?, a denied stack listing read as "no stacks", and a denied CloudFront listing printed "No custom Response Headers Policies found". Scheduled run 39937187759 shows all of these on the publish leg, which concluded success.

Change

  • New scripts/ci/rest-api-quota.sh:
    • makes one paginated get-rest-apis call;
    • reports <total> total, <edge> EDGE (cap 120) on every run;
    • warns from 80 EDGE APIs (was 110; override with REST_API_EDGE_WARN);
    • on a failed or unparseable listing, exits 1 with an ::error:: that carries the CLI's message. It never reads a failure as zero.
  • New scripts/ci/aws-error.sh, sourced by every cleanup step and by the quota script: the CLI's reason is its first non-blank line, with 12-digit numbers masked (the log is public), capped at 500 bytes and escaped for the annotation.
  • REST API step: a failed listing is an ::error:: and fails the step once the summary has printed. A failed list-stacks marks the ownership set incomplete, so nothing is deleted that run, and is a warning with the reason. Before, the empty stack list read as "no stack owns any API", which let a live stack's Blocks API be deleted.
  • IAM role step: a failed iam list-roles (or output that isn't a role listing) or ec2 describe-regions is an ::error:: with the reason and fails the step after its summary; the role count says "unknown, the listing failed" instead of ?. A per-region list-stacks or get-account failure, and any deferred candidate, is a warning.
  • e2e stack, Amplify sandbox and CloudFront listings, and the two DELETE_FAILED tallies: a failure is a warning with the reason instead of reading as "nothing there" or 0. A stack whose resources can't be read is logged by name, not by its ARN.
  • The calls that can fail a leg, and the ownership listings, use AWS_RETRY_MODE=adaptive AWS_MAX_ATTEMPTS=8, so a red leg means a persistent failure, not one throttled call.
  • The publish leg is removed. No E2E job has deployed to publish since ci(agent-bench): run the agent bench in the E2E account #878, and its role can't list REST APIs or IAM roles, so the leg could only fail (or, before this PR, pass while counting nothing). ci(cleanup): delete orphaned Lambda and RDS log groups of test stacks #967's new step and ci(cleanup): unblock Amplify sandboxes stuck on a cancelled table create #970 do not depend on it: ci(cleanup): delete orphaned Lambda and RDS log groups of test stacks #967 guards its step with matrix.environment == 'e2e', which every leg now is, and ci(cleanup): unblock Amplify sandboxes stuck on a cancelled table create #970 has no publish-specific logic.
  • The checkout runs on every leg and sparse-checks out scripts/ci.
  • New Build step "Test the stack cleanup's listing failures".

The sweep's deletion decisions are unchanged whenever the listings succeed; when a listing fails, it deletes strictly less. No IAM, OIDC trust, environment, permissions or prefix list is touched.

Human step after merge

  • The publish account still holds stacks, REST APIs and CloudWatch roles from before the move to the E2E pool. No sweep covers it now; clean it up by hand, once.

Tests

scripts/ci/rest-api-quota.test.mjs and scripts/ci/cleanup-listings.test.mjs run the script and the real run: blocks of the workflow steps against a stub aws on PATH; nothing reaches AWS.

  • The new listing tests: 7 fail on the previous head 030c7a4 and pass now (36/36). 28 of 28 hand mutants are killed, including the % escape, mask-before-cut, each new error and warning, each fail-closed gate and the publish leg coming back.
  • actionlint (with shellcheck), node scripts/check-actions-pinned.mjs, shellcheck and scripts/ci/e2e-selection.test.mjs are green.

Status

@changeset-bot

changeset-bot Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 3d78ebd

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@osama-rizk osama-rizk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This moves the REST API count into a tested script, fails the sweep leg when the listing or the count can't be read, and closes a real deletion hazard: on main, a failed list-stacks meant "no stack owns any API". Verdict: safe to merge on the code, with no blocking items. Two things should be settled first: the merge has to wait for the publish role grant, and the PR only fixes the REST API part of the silent-swallow problem.

What's good

  • The list-stacks fail-safe fixes a real bug. I ran the new test file against main in a Linux container, and "deletes nothing when the live stacks cannot be listed" fails there. A throttled or denied listing could have deleted a running E2E (end-to-end) stack's Blocks API.
  • The failure path is well guarded. 15 of 15 tests pass at head. I tried 12 mutants by hand and 11 were killed: the final exit 1, the || QUOTA_FAILED=1, the script's exit 1, the list-stacks fail-safe, the blank-line reason, both account-id masks, the EDGE filter, the -ge threshold, the "No custom REST APIs found" guard, and LIST_FAILED. The one survivor is a nit (inline).
  • One paginated get-rest-apis --output json call with a jq count replaces two JMESPath length() calls. The summary prints before the step fails, and later steps still run under if: always().
  • Taking the first non-blank stderr line explains the empty reason the current publish logs show. Cleanup run 39937187759 logs get-rest-apis failed, orphaned REST APIs were not swept: with nothing after the colon.
  • shellcheck, actionlint and check-actions-pinned are clean.

What needs work: 0 must-fix · 2 should-fix · 1 minor · 1 nit. Details are inline.

Speed / flakiness: PR Checks run time doesn't change. The new Build step took 1 s in run 39883970618. The Build job ran 13.0 min there, against 18.9 and 17.7 min in baseline runs 39812188339 and 39821845972. That gap is runner and cache variance, and this PR doesn't cause it. The flakiness benefit is real, but indirect and inferred:

  • The pool accounts already counted fine. Scheduled run 39937187759 reported 0, 0 and 5 EDGE.
  • So the new red leg today is publish only. Since #878 merged, no PR Checks E2E job deploys into publish.
  • The direct win for PR runs is the list-stacks fail-safe. A wrongly deleted live API would fail a running E2E job mid-test.
  • If a pool role later loses its REST API grant, the leg now goes red instead of letting the account fill up unseen.
  • The warning at 80 gives about 2.5 full runs of headroom (about 16 EDGE APIs per run) before the cap. Before, it gave less than one.

E2E integrity: No test is skipped, gated, loosened or retried. No required check or job layout changes, and the head commits carry no E2E: trailer. The PR adds a check: the new Build step runs the tests. When the listings succeed, the sweep makes the same deletions as before. The test "still deletes an old unowned test API and spares the stack-owned one" covers that, and I confirmed it by reading the diff. When a listing fails, the sweep now deletes strictly less. Nothing here can delete another run's stacks. The doc's claim "no PR removes or weakens a test" holds for this PR.

Open questions

  1. Who applies the publish role grant (apigateway:GET on /restapis and /restapis/*, plus iam:ListRoles), and is it applied before this is marked ready? Until then the run goes red every 2 h (see the inline comment on line 742).
  2. #878 has merged. Is the publish leg still needed? The header comment (lines 21-25) says to drop it once publish reports zero candidates, but publish can't report a REST API count until it gets the grant. So the grant is needed either way, or the criterion needs to change.
  3. Should the IAM (Identity and Access Management) role count get the same treatment in this PR, or as a tracked follow-up (inline on github-oidc-stack.ts)?

Cross-cutting

  • On the question of removing every silent swallow: this PR fixes only the REST API listing, the count and the REST-API-step list-stacks. These still read a denied call as "nothing there":

    • the e2e stack sweep's per-prefix list-stacks (lines 244-248);
    • the Amplify sandbox list-stacks ... || true (lines 445-448);
    • describe-regions and iam list-roles in the IAM step (lines 786-790 and 842-846);
    • the CloudFront list-response-headers-policies (lines 931-934).

    The publish leg hits three of these on every run today.

  • Merge order with #970: the checkout hunk is byte-identical, so git merges either order cleanly. The only reason to land #959 first is that #970's comment names scripts/ci/rest-api-quota.sh. #950, #951 and #946 add Build steps at the same spot in pr-checks.yml; keep both sides. #967 merges clean.

  • The PR is still a draft. These comments are on head 030c7a4.

Comment thread test-infra/github-oidc-stack.ts Outdated
// CloudFront response headers policies. Its calls swallow errors, so a missing
// grant here shows up as an empty sweep, not a failed job.
// CloudFront response headers policies. A REST API listing it can't read fails
// the job; its other calls swallow errors, so a missing grant there shows up

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking (should fix): the updated comment is accurate, and it's the scope gap. Only the REST API path stops swallowing errors. The IAM role count has the same blind-quota bug, and the publish leg hits it on every run today. Scheduled run 39937187759 printed iam list-roles failed — nothing to sweep this run and IAM roles in account: ? (quota 3000), with no annotation, and the leg was green. The 3000-role quota is the other quota this workflow names as a cause of CREATE failures.

These silent swallows remain at this head, in cleanup-stacks.yml:

  • lines 244-248: per-prefix list-stacks ... 2>/dev/null || echo "". A denied call reads as "no e2e stacks".
  • lines 445-448: the Amplify sandbox list-stacks ... || true.
  • lines 786-790 and 842-846: describe-regions and iam list-roles only echo. The count at lines 913-917 then prints ? silently.
  • lines 931-934: list-response-headers-policies ... 2>/dev/null || echo "" prints "No custom Response Headers Policies found". The publish leg prints exactly that, so you can't tell a denial from an empty account.

Fix: in this PR or a linked follow-up issue, give the IAM step the same treatment as the REST API step: an ::error:: with the masked reason, and exit 1 after its summary. Use the stderr-capture pattern from lines 607-617. For the stack and CloudFront listings, at least emit ::warning:: with the reason instead of 2>/dev/null || echo "".

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 74ecd5a and 4ada58e: a failed IAM role or region listing is now an ::error:: with the masked CLI reason and fails the step after its summary, and the stack, Amplify, REST ownership and CloudFront listings and both DELETE_FAILED tallies warn with the reason. Tests are in scripts/ci/cleanup-listings.test.mjs, green in PR Checks.

if [ "$EDGE" != "?" ] && [ "$EDGE" -ge 110 ] 2>/dev/null; then
echo "::warning::$EDGE/120 EDGE REST APIs in use — approaching the hard quota"
if [ "$LIST_FAILED" -ne 0 ] || [ "$QUOTA_FAILED" -ne 0 ]; then
exit 1

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking (should fix): this exit 1 is the intended signal, but its noise has no end date. The workflow runs every 2 h, so once this merges every run concludes failure: 12 a day, about 84 a week, until a role outside the repo is changed. Every one of those red runs has the same known cause. A real regression on a pool leg, like AWS_ROLE_ARNS drift or a lost grant, then looks the same as the expected publish failure from the run list. People stop opening red cleanup runs, which is how the original warning went unread for 261 runs. Since #878 merged, no PR Checks E2E job deploys into publish, so this red leg doesn't guard PR flakiness at all.

Fix: keep the PR in draft until the grant is applied, then mark it ready. If that can't happen soon, drop the publish leg under a written criterion, and track the grant in an issue linked here. Don't add continue-on-error: that would hide the failure again.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved by dropping the publish leg in 74ecd5a, with no continue-on-error, so no grant is needed and the 2-hourly runs don't go red; a test keeps the leg from coming back. The one-off clean-up of that account is listed in the PR body as a human step.

Comment thread .github/workflows/cleanup-stacks.yml Outdated
if ! LIVE_STACKS=$(aws cloudformation list-stacks \
--stack-status-filter CREATE_COMPLETE UPDATE_COMPLETE UPDATE_ROLLBACK_COMPLETE ROLLBACK_COMPLETE REVIEW_IN_PROGRESS CREATE_IN_PROGRESS UPDATE_IN_PROGRESS DELETE_IN_PROGRESS UPDATE_ROLLBACK_IN_PROGRESS ROLLBACK_IN_PROGRESS UPDATE_COMPLETE_CLEANUP_IN_PROGRESS UPDATE_ROLLBACK_COMPLETE_CLEANUP_IN_PROGRESS IMPORT_COMPLETE IMPORT_IN_PROGRESS IMPORT_ROLLBACK_IN_PROGRESS IMPORT_ROLLBACK_COMPLETE \
--query "StackSummaries[].StackName" --output text 2>/dev/null | tr '\t' '\n' | sort -u); then
echo " list-stacks failed, so the ownership set is incomplete this run"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking (minor): this branch is the most important fail-safe in the PR, but it is the least visible. 2>/dev/null on line 576 throws away the reason, and this line is a plain echo, not an annotation. A persistent denial or throttle here leaves the leg green and deletes nothing. It only surfaces through the DEFERRED warning, when candidates happen to exist. That is the same quiet pattern the PR removes for get-rest-apis.

Fix: capture stderr the way lines 608-611 do, and annotate it. The minimum change is this line:

Suggested change
echo " list-stacks failed, so the ownership set is incomplete this run"
echo "::warning::list-stacks failed, so the ownership set is incomplete and no REST API is deleted this run"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applied in 74ecd5a, with the CLI's reason added: a failed list-stacks there is now a ::warning::, asserted in the REST step test (PR Checks).

Comment thread .github/workflows/cleanup-stacks.yml Outdated
LIST_ERR=$(mktemp)
if ! APIS=$(AWS_RETRY_MODE=adaptive AWS_MAX_ATTEMPTS=8 aws apigateway get-rest-apis \
--query "items[].[id,name,createdDate]" --output text 2>"$LIST_ERR"); then
REASON=$(grep -m 1 -v '^[[:space:]]*$' "$LIST_ERR" | sed -E 's/[0-9]{12}/<account>/g' | head -c 500 || true)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking (nit): this reason extraction (first non-blank line, 12-digit mask, 500-byte cap, % escape) is copied in scripts/ci/rest-api-quota.sh:45-47. The two copies will drift. Also, no test covers the %→%25 escape: I removed ${REASON//%/%25} and all 15 tests still pass.

Fix: move the extraction into one small helper in scripts/ci/ that both the step and the script call. Add a test whose denied message contains a %, and assert it reaches the annotation as %25.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 74ecd5a: scripts/ci/aws-error.sh is now the one helper, used by every cleanup step and by rest-api-quota.sh. Tests pin the % to %25 escape (removing it fails 3 tests), and also the CR escape, the 500-byte cap and masking before the cut (3f8a69e, 4ada58e).

@belaboe

belaboe commented Oct 23, 2026

Copy link
Copy Markdown
Contributor Author

On the review's open questions: the publish leg is dropped in 74ecd5a, so questions 1 and 2 no longer need a grant, and the IAM count (question 3) is fixed in this PR. Both are in the updated description, and PR Checks is green.

@osama-rizk osama-rizk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the last review: 4 resolved · 2 new · 0 still open

Resolved, checked against the code at 4ada58e rather than the replies:

  • IAM (Identity and Access Management) role and region listings: a failed iam list-roles, unparseable role output or a failed ec2 describe-regions is now an ::error:: with the masked reason, and the step exits 1 after its summary. The count reads "unknown, the listing failed" instead of ?. The e2e stack, Amplify sandbox, CloudFront and both DELETE_FAILED listings now warn with the reason instead of reading as empty.
  • Publish leg: dropped, with no continue-on-error, and a test fails if it comes back. The reason is written in the workflow comment. I checked that no workflow still deploys test stacks into publish: publish-canary only runs test:e2e:local there, and #878 moved the bench job to the E2E account.
  • REST API (Application Programming Interface) ownership list-stacks failure: now a ::warning:: with the reason, and a test asserts it.
  • One shared helper: scripts/ci/aws-error.sh is used by every cleanup step and by rest-api-quota.sh, and tests pin the % to %25 escape.

How I checked:

  • The two cleanup test files pass 35/35 in a Linux container.
  • I wrote 20 mutants of my own, and the tests catch all 20. They include removing the % escape (3 tests fail, where it survived last round), the CR escape, the account-id mask, the IAM exit 1, each LIST_FAILED=1, the jq shape check, each new warning, the e2e "unknown" tally, the ARN-to-name change and putting the publish leg back.
  • actionlint, shellcheck and check-actions-pinned are clean.
  • I read the latest scheduled run on main (40291614787) without changing anything. The publish leg there still shows the old silent ? counts, which this PR replaces.

What's good:

  • One helper and one pattern (2>"$LIST_ERR" then aws_annotate) at every listing, so the next step written will copy the right thing.
  • Fail-closed gates stay fail-closed. Every failure path deletes the same or less than before.
  • Per-region failures are grouped into one warning naming the regions, which keeps the step under GitHub's 10-annotation limit.
  • The stack ARN (Amazon Resource Name) is no longer printed, so the account id stays out of the public log.

What needs work: 0 must-fix · 1 minor · 1 nit, details inline. Nothing blocks. This is a COMMENT and not an approval only because the PR is still a draft.

Open question for the author:

  • Who owns the one-off cleanup of the publish account, and where is it tracked once this PR's description is no longer in view? See the inline comment on lines 21-25 for what is there today.

Comment thread .github/workflows/cleanup-stacks.yml Outdated
Comment on lines +24 to +25
# (or, before, pass while counting nothing). The stacks left there from
# before the move are cleaned up by hand, once.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking (minor): dropping the leg is the right call, but the one-off cleanup it hands off has no owner and no issue. Once this merges, nothing in the repo points at it except this comment and a line in the PR description.

The latest scheduled run on main (40291614787), and the three before it, show the same leftovers in publish every time:

  • 17 my-app-*-runnerad-* stacks whose DeleteStack is AccessDenied for the publish role, so a person with broader access has to delete them;
  • 9 e2e stacks and 21 Amplify sandboxes stuck in DELETE_FAILED.

The REST API and IAM role counts there are unknown, because that role can't list them. The leg makes no progress from run to run, so you lose nothing by removing it. But these stacks will stay there, with nothing that reports them, until someone is given the job.

Fix: open an issue with this inventory and an owner, and link it from this comment in place of "by hand, once". Note in the issue that publish is the release account, so the deletes should be made from a reviewed list of exact stack names, not by prefix.

Comment thread .github/workflows/cleanup-stacks.yml Outdated
--output text 2>/dev/null || echo 0)
--output text 2>"$LIST_ERR"); then
aws_annotate warning "$LIST_ERR" "list-stacks failed, so the DELETE_FAILED Amplify sandboxes can't be counted"
STILL_FAILED=0

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking (nit): the e2e tally now prints unknown when its listing fails (line 358), but this Amplify tally still sets 0. The step summary then shows "Still DELETE_FAILED: 0" right after a warning that says the count couldn't be read. Today the publish leg reports 21 here, so a 0 after a denial looks like good news.

Fix: use the same pattern as the e2e step: set STILL_FAILED=unknown here, guard the -gt 0 warning at line 552 with [ "$STILL_FAILED" != unknown ] &&, and drop "(the count shows 0)" from the comment on line 528.

@osama-rizk osama-rizk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the last review: 2 resolved · 0 new · 0 still open

Resolved:

  • The Amplify DELETE_FAILED tally now prints unknown when list-stacks fails, and the quota warning is skipped in that case, matching the e2e step. Both paths are tested (unreadable count, and a readable count of 3 that warns).
  • The hand cleanup of the stacks left in the publish account is now tracked in #1036, with the inventory (17 my-app-*-runnerad-* stacks with DeleteStack denied, 9 e2e and 21 Amplify stacks in DELETE_FAILED, REST API and IAM (Identity and Access Management) role counts unreadable) and the steps. That inventory matches what the latest scheduled run on main still shows for the publish leg.

This branch was rebased onto main. I compared the commits before and after the rebase: the five earlier commits are unchanged apart from the pr-checks.yml context, and the new test step now sits in the "Local Build and Checks" job after the jobs were split. CI (continuous integration) ran it on this head, and all 36 tests in rest-api-quota.test.mjs and cleanup-listings.test.mjs pass there and locally on Linux. I also broke the new Amplify tally logic on purpose (reverting unknown to 0, inverting the guard, raising the warning threshold, dropping the annotation), and each change failed a test. actionlint and shellcheck are clean.

What's good:

  • The unknown handling now works the same way in both tally steps, so a failed read can no longer show up as a reassuring 0.
  • The workflow comment points at a real tracking issue instead of "by hand, once".

What needs work: nothing new from me; 0 blocking · 0 non-blocking.

Open questions:

  • #1036 still says the owner is "to be named by the maintainers". Since the publish account is the release account, could a maintainer with delete rights there take it before this merges, so the stacks don't drop out of view with the leg?

I'm leaving this as a comment while the PR is still a draft. Once it's marked ready for review, I have nothing outstanding.

osama-rizk
osama-rizk previously approved these changes Oct 27, 2026

@osama-rizk osama-rizk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving. This makes the scheduled cleanup fail loudly when it can't read an account, instead of reporting "nothing to sweep". It stops a failed list-stacks from making a live stack's API look deletable. The head (0f82e51) is unchanged since my last review, and every earlier finding is addressed.

Since the last review: 0 resolved · 0 new · 0 still open. All six earlier findings were resolved across 4ada58e, 7c0ef24 and 0f82e51:

  • the IAM role and region listings now fail the leg, and the other listings warn with the reason;
  • the publish leg is dropped, and a test guards against it coming back;
  • the list-stacks failure is now a warning with the reason;
  • the shared aws-error.sh pins the % escape;
  • #1036 tracks the publish account's one-off cleanup;
  • the Amplify DELETE_FAILED tally shows "unknown" when its listing fails.

Speed: neutral, and that's expected: this PR isn't meant to make PR Checks faster. The new "Test the stack cleanup's listing failures" step took 1 s in Local Build and Checks on head run 40346406976 (15:12:02 to 15:12:03Z). That job took 7.0 min there, against 4.2 to 6.5 min across 7 PR runs after #963. I put the gap down to runner variance, not to this step (inferred). The flakiness benefit is indirect. The edge REST API quota is now visible on every leg, so it can't fill up unseen. Today's main cleanup run 40486500191 still prints REST APIs remaining: ? total, ? EDGE and IAM roles in account: ? on publish, and the run is green. That's the blind spot this PR closes. The pool legs read 0 and 12 EDGE in that run.

Regression: none found. git merge-tree against current main (db15b5e, 12 commits past this PR's base, including #969, #952, #1032 and #948) merges clean. On the merged tree, the new step sits in local-build. The always() aggregator still requires local-build, local-unit and local-e2e to succeed. Both test files pass on the merged tree (36/36, Linux container). Head CI is green. Nothing changes for customers, since the PR touches only CI and test-infra.

Coverage / blind spots: no PR-check test or assertion is removed or skipped, and no required context can now end as skip-as-pass. The new tests run in a required job. One coverage move is disclosed: the scheduled sweep no longer covers the publish account, because its leg is dropped. That's sound, since no E2E job has deployed there since #878. The leftover inventory is tracked in #1036. The head commit has no E2E: trailer.

Follow-ups (non-blocking):

  • #1036 needs a named owner for the publish account's hand cleanup (17 runnerad stacks with DeleteStack AccessDenied, plus 9 e2e and 21 Amplify stacks in DELETE_FAILED).
  • The PR is still a draft. Mark it ready when you want it merged.

Merge-order note: merge this before #970. They conflict on one checkout comment line, and #970 carries that line in its final form.

belaboe added a commit that referenced this pull request Oct 27, 2026
The checkout comment named scripts/ci/aws-error.sh and
scripts/ci/rest-api-quota.sh, which come with #959. This PR now merges
first, so on main only scripts/ci/amplify-stuck-delete.sh exists; #959
names its scripts again when it rebases.

A test now pins what the Amplify step needs from that checkout: it runs on
every leg and includes scripts/ci. Restoring main's checkout (e2e legs
only, no scripts/ci) fails it.
belaboe added a commit that referenced this pull request Oct 27, 2026
The checkout comment named scripts/ci/aws-error.sh and
scripts/ci/rest-api-quota.sh, which come with #959. This PR now merges
first, so on main only scripts/ci/amplify-stuck-delete.sh exists; #959
names its scripts again when it rebases.

A test now pins what the Amplify step needs from that checkout: it runs on
every leg and includes scripts/ci. Restoring main's checkout (e2e legs
only, no scripts/ci) fails it.
belaboe added a commit that referenced this pull request Nov 5, 2026
The checkout comment named scripts/ci/aws-error.sh and
scripts/ci/rest-api-quota.sh, which come with #959. This PR now merges
first, so on main only scripts/ci/amplify-stuck-delete.sh exists; #959
names its scripts again when it rebases.

A test now pins what the Amplify step needs from that checkout: it runs on
every leg and includes scripts/ci. Restoring main's checkout (e2e legs
only, no scripts/ci) fails it.
@belaboe
belaboe marked this pull request as ready for review November 5, 2026 14:00
@belaboe
belaboe requested a review from a team as a code owner November 5, 2026 14:00
The REST API sweep in cleanup-stacks.yml counts EDGE REST APIs against
the 120-per-region quota. When get-rest-apis failed, the step printed a
warning and passed, so an account's count was never visible while it
filled up. The warning's reason was always empty too: the AWS CLI starts
its error with a blank line and the step printed only the first line.

- Move the count into scripts/ci/rest-api-quota.sh. It makes one
  get-rest-apis call, reports "<total> total, <edge> EDGE (cap 120)"
  every run, warns from 80 EDGE APIs (was 110), and exits 1 with an
  error annotation carrying the CLI's message when the listing fails or
  can't be parsed.
- A failed listing in the sweep is now an error annotation and fails
  the step after its summary prints. Later steps still run (if: always).
- Print the first non-blank line of the CLI error, with 12-digit
  account ids masked, since the log is public.
- A failed list-stacks no longer reads as "no stack owns any API": it
  marks the ownership set incomplete, so the sweep deletes nothing that
  run, the same as a failed describe-stack-resources already does.
- Check out scripts/ci on every leg, and run the new test in Build.

Tests: node --test scripts/ci/rest-api-quota.test.mjs (stub aws CLI).
…ckout

Review follow-ups: fail each get-rest-apis form separately in the stub,
assert the sweep's own error line, guard the checkout on every leg, and
clean up the fixtures. Skip the step tests without GNU date. Mask
account ids before truncating, escape % in the sweep annotation, use a
private temp file for its stderr, give both listings more retry
attempts, and drop the contradictory 'No custom REST APIs found' line
after a failed listing.
…publish leg

The IAM role step read a failed `iam list-roles` or `ec2 describe-regions`
as "nothing to sweep" and printed the role count as "?", with the leg
green. It now prints an error with the CLI's reason and fails the step once
its summary has printed, the same way the REST API step does. Both calls
retry in adaptive mode first.

The e2e stack, Amplify sandbox and CloudFront policy listings, the REST
API step's ownership listing, and the IAM step's per-region reads now warn
with the CLI's reason instead of discarding it. A failed CloudFront listing
no longer prints "No custom Response Headers Policies found". The IAM step
also warns when it defers candidates, like the REST API step.

The reason extraction (first non-blank line, account ids masked, 500-byte
cap, "%" escaped for the annotation) moves to scripts/ci/aws-error.sh, used
by every step and by rest-api-quota.sh. A test now pins the "%" escape.

The publish leg is removed. No E2E job has deployed to publish since #878,
and its role can't list REST APIs or IAM roles, so the leg could only fail.
The stacks left in that account are cleaned up by hand, once.

Tests: scripts/ci/cleanup-listings.test.mjs (new) and
scripts/ci/rest-api-quota.test.mjs, run by the Build job. 7 of the new
tests fail on the previous head; 15 of 15 hand mutants are killed.
…arded

From review of the previous commit:

- The test stub exited 1 on a fixture without a stack list, so the
  "listing works" tests went down the list-stacks failure path. It now
  prints nothing and exits 0, and the happy-path tests assert no
  annotation.
- The IAM step tests use a role that is a real sweep candidate, so a
  failed region listing or account-setting read is shown to delete
  nothing. New cases: the candidate is deleted when every gate holds, and
  an account setting that can't be read is a warning plus a deferral.
- A role listing that isn't JSON now counts as a failed listing, so the
  count can't abort the step before its summary.
- The ownership list-stacks calls in the REST API and IAM steps retry in
  adaptive mode, so one throttle doesn't defer the sweep.
- aws-error.sh: tests for the empty reason, the 500-byte cap and the
  "%"-before-CR escape order.

Tests: 32/32; 23 of 23 hand mutants are killed.
… a log line

From the second review:

- The DELETE_FAILED tallies in the e2e and Amplify steps read a failed
  listing as 0. Both now warn with the CLI's reason; the e2e summary
  shows "unknown".
- The IAM step printed the stack id (an ARN, with the account id) when a
  stack's resources could not be read. It prints the stack name.
- Per-region list-stacks and get-account failures are one warning each,
  naming the regions, so many regions can't push the other warnings past
  the 10 annotations GitHub shows per step.
- A test pins that the account id is masked before the reason is cut to
  500 bytes.

Tests: 35/35; 28 of 28 hand mutants are killed.
…can't be read

When list-stacks fails, the Amplify step's summary printed
"Still DELETE_FAILED: 0" right after the warning that the count could not
be read. It now prints unknown, as the e2e step does, and skips the
count warning. Tests cover both the unknown and a readable tally.
…ssue

The comment said the stacks left in publish are cleaned up "by hand,
once", with nothing tracking it. #1036 now lists them and the steps.
@belaboe
belaboe force-pushed the fix/cleanup-rest-api-count branch from 0f82e51 to 3d78ebd Compare November 5, 2026 14:31
@belaboe
belaboe merged commit dc7b4a6 into main Nov 5, 2026
19 of 20 checks passed
@belaboe
belaboe deleted the fix/cleanup-rest-api-count branch November 5, 2026 14:33
harsh62 added a commit that referenced this pull request Nov 5, 2026
Brings in "feat(core): serve an API namespace from a container compute"
(#1105) and "ci(cleanup): fail the sweep leg when REST APIs can't be counted"
(#959).

packages/core/src/api.ts: ApiNamespaceOptions keeps this branch's
httpErrorStatus option and its docs, and takes #1105's container compute docs
and widened `compute` type ('serverless' | 'container'). A container compute
serves the whole backend module through the shared dispatch core, which
already answers a 4xx ApiError of an httpErrorStatus namespace with its
status; http-server.test.ts now checks that against the Lambda handler.

.github/workflows/cleanup-stacks.yml (REST API sweep): takes #959's
list-stacks fail-safe (retries, the CLI's reason as a warning), its
rest-api-quota.sh headroom check and its exit on a listing or count failure,
and keeps this branch's separate ownership and budget deferral counts in the
summary and warnings.

# Conflicts:
#	.github/workflows/cleanup-stacks.yml
#	packages/core/src/api.ts

This branch was previously deployed

1 inactive deployment
e2e — 3d78ebdc Deployed Nov 5, 2026 by belaboe via E2E Amplify Interop (Browser) #5453
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants