Skip to content

[3822 by Claude Opus 5.5] Fly Machines: PROPR_FLY_MACHINES_MAX concurrency cap that queues instead of failing at the org limit - #3823

Merged
integry merged 4 commits into
3758-epic-runtime-abstraction-sc0from
3822/claude-opus-5-5-fly-machines-propr_fly_ma-20261126-2329-gqm
Nov 27, 2026
Merged

integry merged 4 commits into
3758-epic-runtime-abstraction-sc0from
3822/claude-opus-5-5-fly-machines-propr_fly_ma-20261126-2329-gqm

Conversation

@propr-dev

@propr-dev propr-dev Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

AI Implementation Summary

Closes #3822

Branch: 3822/claude-opus-5-5-fly-machines-propr_fly_ma-20261126-2329-gqm
Commits: ✅ Changes committed (a558988)


AI Processing Completed

Execution Details:

Summary:
PROPR_FLY_MACHINES_MAX is back in the Fly Machines runtime, and the unit tests, core type-check and lint all pass. The live check on Fly (fly-e2e.yml) has not been run, so the "second run waits, then succeeds with no 422" part of the acceptance is still unverified.

How it works

  • Setting: a positive whole number, unlimited when unset. Anything else (0, -1, 1.5, two, 1e2, 0x2, values too large to count exactly) fails the run with Invalid PROPR_FLY_MACHINES_MAX. I made the check stricter than the reference branch, which accepted 1e2.
  • Queueing: a run over the cap waits in arrival order after the package check and before its Machine is created. Cancelling a waiting run removes it from the queue without creating a Machine. Compute time starts after the wait.
  • Freeing a slot:
    • A deleted Machine frees its slot only once deletion is confirmed, including deletions retried in the background.
    • A Machine kept for recovery keeps its slot until Fly reports it destroyed or unknown. A failed check keeps the slot.
    • If a create's response and its follow-up lookup are both lost, the run keeps its slot until a lookup succeeds; a Machine found under the run's name is deleted first.
    • A run that never created a Machine frees its slot at once.
  • Per worker: the cap only counts Machines created by one worker process. With several workers, split the free slots between them; the docs say so.

Code

  • I started from a reversal of 53a9fb5 and merged it by hand where this branch had changed flyMachinesRuntime.ts.
  • New in fly/api.ts: gone(), find() and MachineCreateUnconfirmedError.
  • I moved the per-run slot bookkeeping into a small FlyMachineSlot class in fly/capacity.ts. Without that, the runtime file went over the 400-line lint limit.

Tests

  • test/flyMachinesCapacity.test.ts (8 tests) covers queue order, cancelling while waiting, release only after confirmed deletion, retained Machines, lost creates and invalid values. The Fly runtime, create-request and runtime-packages suites also pass.
  • To check the tests can fail, I broke the code two ways (freeing the slot before deletion, and freeing it right away for kept Machines). The suite caught both, and I restored the code.
  • test/flyE2eMcpAutomation.test.ts fails with one error both with and without my workflow change, so I didn't introduce it.

Live check: the workflow ran one issue at a time (WORKER_CONCURRENCY=1), so a second run could never wait. I added a manual-only input, fly_machines_max, that requires agent_runtime=fly-machines. It:

  • deploys with PROPR_FLY_MACHINES_MAX=1 and WORKER_CONCURRENCY=2, and labels a second issue just after the first.
  • requires a "run queued" log line, no "machine limit" error anywhere in the logs, and a successful Fly Machines run for both issues.
  • closes both issues' PRs and branches during cleanup.

The job's time limit rises to 140 minutes in this mode. To meet the acceptance, dispatch it with agent_runtime=fly-machines and fly_machines_max=true.

Docs: setup-fly.md, agent-runtime.md and .env.example recommend the Free Plan value: 3 Machines, minus the control plane and other apps' Machines, so usually PROPR_FLY_MACHINES_MAX=2. I also added the missing blank line in setup-fly.md that put the billing sentence inside the Free Plan quote.

While checking that test, I accidentally copied the committed .github and test folders over my edits. I restored the three edited test files from the same reversed patch and re-ran my saved workflow script. The final test, type-check and lint results above are from after the restore.

There's nothing visual to preview.

Review digest

Risk-tiered paths

  • High risk (1 file)
    • .github/workflows/fly-e2e.yml (+95/−21): CI or workflow file
  • Normal risk (5 files)
    • .env.example (+2/−0)
    • packages/core/src/agents/runtime/fly/api.ts (+33/−3)
    • packages/core/src/agents/runtime/fly/capacity.ts (added, +151/−0)
    • packages/core/src/agents/runtime/fly/config.ts (+3/−1)
    • packages/core/src/agents/runtime/flyMachinesRuntime.ts (+14/−6)
  • Low risk (6 files)
    • docs/docs/architecture/agent-runtime.md (+4/−2)
    • docs/docs/tutorials/setup-fly.md (+2/−2)
    • test/flyMachinesCapacity.test.ts (added, +249/−0)
    • test/flyMachinesCreateRequest.test.ts (+2/−0)
    • test/flyMachinesRuntime.test.ts (+29/−0)
    • test/flyRuntimePackages.test.ts (+2/−0)

Diff size: 12 files changed, +586/−35 lines

View task for the run's logs and conversation.


This PR was created automatically by ProPR after processing issue #3822.


💡 Need changes?

Comment on this PR to request refinements — the AI agent monitors comments and will update the implementation based on your feedback. Keep iterating until you're satisfied!

Live verification

Cap mode (agent_runtime=fly-machines, PROPR_FLY_MACHINES_MAX=1) passes on a10f4d7: https://github.com/integry/propr/actions/runs/45916874089 ✅

aec010e (R1: free the slot when Fly confirms the Machine is gone after a failed deletion, 404 included) changes only the deletion path, which the unit tests cover.

Final head aec010e: cap mode again https://github.com/integry/propr/actions/runs/45920133703 ✅ (clean teardown). Review 8/10 with no blockers, CI clean.

`PROPR_FLY_MACHINES_MAX` is back in the Fly Machines runtime, and the unit tests, core type-check and lint all pass. The live check on Fly (`fly-e2e.yml`) has not been run, so the "second run waits, then succeeds with no 422" part of the acceptance is still unverified.

How it works
- Setting: a positive whole number, unlimited when unset. Anything else (`0`, `-1`, `1.5`, `two`, `1e2`, `0x2`, values too large to count exactly) fails the run with `Invalid PROPR_FLY_MACHINES_MAX`. I made the check stricter than the reference branch, which accepted `1e2`.
- Queueing: a run over the cap waits in arrival order after the package check and before its Machine is created. Cancelling a waiting run removes it from the queue without creating a Machine. Compute time starts after the wait.
- Freeing a slot:
  - A deleted Machine frees its slot only once deletion is confirmed, including deletions retried in the background.
  - A Machine kept for recovery keeps its slot until Fly reports it destroyed or unknown. A failed check keeps the slot.
  - If a create's response and its follow-up lookup are both lost, the run keeps its slot until a lookup succeeds; a Machine found under the run's name is deleted first.
  - A run that never created a Machine frees its slot at once.
- Per worker: the cap only counts Machines created by one worker process. With several workers, split the free slots between them; the docs say so.

Code
- I started from a reversal of 53a9fb5 and merged it by hand where this branch had changed `flyMachinesRuntime.ts`.
- New in `fly/api.ts`: `gone()`, `find()` and `MachineCreateUnconfirmedError`.
- I moved the per-run slot bookkeeping into a small `FlyMachineSlot` class in `fly/capacity.ts`. Without that, the runtime file went over the 400-line lint limit.

Tests
- `test/flyMachinesCapacity.test.ts` (8 tests) covers queue order, cancelling while waiting, release only after confirmed deletion, retained Machines, lost creates and invalid values. The Fly runtime, create-request and runtime-packages suites also pass.
- To check the tests can fail, I broke the code two ways (freeing the slot before deletion, and freeing it right away for kept Machines). The suite caught both, and I restored the code.
- `test/flyE2eMcpAutomation.test.ts` fails with one error both with and without my workflow change, so I didn't introduce it.

Live check: the workflow ran one issue at a time (`WORKER_CONCURRENCY=1`), so a second run could never wait. I added a manual-only input, `fly_machines_max`, that requires `agent_runtime=fly-machines`. It:
- deploys with `PROPR_FLY_MACHINES_MAX=1` and `WORKER_CONCURRENCY=2`, and labels a second issue just after the first.
- requires a "run queued" log line, no "machine limit" error anywhere in the logs, and a successful Fly Machines run for both issues.
- closes both issues' PRs and branches during cleanup.

The job's time limit rises to 140 minutes in this mode. To meet the acceptance, dispatch it with `agent_runtime=fly-machines` and `fly_machines_max=true`.

Docs: `setup-fly.md`, `agent-runtime.md` and `.env.example` recommend the Free Plan value: 3 Machines, minus the control plane and other apps' Machines, so usually `PROPR_FLY_MACHINES_MAX=2`. I also added the missing blank line in `setup-fly.md` that put the billing sentence inside the Free Plan quote.

While checking that test, I accidentally copied the committed `.github` and `test` folders over my edits. I restored the three edited test files from the same reversed patch and re-ran my saved workflow script. The final test, type-check and lint results above are from after the restore.

There's nothing visual to preview.

ProPR-Agent: claude/claude-opus-5-5

integry commented Nov 26, 2026

Copy link
Copy Markdown
Owner

/ultrafix goal=8 max=3

@propr-dev propr-dev Bot added the ultrafix label Nov 26, 2026
@propr-dev

propr-dev Bot commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

🔄 Ultrafix loop started (goal: 8/10, max cycles: 3)

First action: /review

💡 Tip: Remove the ultrafix label from this PR to stop further ultrafix cycles.

@propr-dev

propr-dev Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor Author

✅ AI Code Review Complete requested by @propr-ultrafix

Posted 1 review:

View Task Details

@propr-dev

propr-dev Bot commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

🔍 AI Code Review — codex:gpt-6-astra

Overall Evaluation

The PR adds a process-local Fly Machine cap with FIFO queueing and lifecycle-aware slot release. The implementation looks sound within the supplied code, but the live capacity acceptance scenario remains unverified.

✅ Conservative slot retention — Failed deletion and recovery retention keep capacity occupied; failed existence checks do not free slots.

✅ Queue cancellation — Aborted waiters are removed, and idempotent release prevents double-decrementing capacity.

✅ Focused coverage — Added tests cover queue ordering, cancellation, deletion retries, retained Machines, uncertain creates, and invalid configuration.

No verified code blocker was found. Current checks show 18 passed, five pending, and no failures. This was a static review; no commands or tests were run.

Merge blockers

No merge blockers.

Suggestions

These are optional follow-ups and are not sent to /fix.

S1: 🟢 Complete live capacity verification

Run the added workflow with agent_runtime=fly-machines and fly_machines_max=true to establish that overlapping runs queue and both succeed against Fly. The supplied context explicitly leaves this acceptance scenario unverified. This is outstanding validation evidence, rather than a demonstrated code defect.

S2: 🟢 Bound asynchronous test waits

The until() helper in test/flyMachinesCapacity.test.ts waits indefinitely when its condition never becomes true. A deadline with a descriptive assertion would make lifecycle regressions fail promptly and diagnostically. This is an optional test-maintenance improvement.

Score

The implementation has useful lifecycle coverage and no verified blocker, but the explicitly identified live acceptance scenario remains a material verification gap.

Score: 7/10


🤖 Review Details

  • Model: GPT-6 Astra
  • Time: 23s
  • Tokens: 58,246 (57,762 in / 484 out)
  • Cost: $0.49

View Task


💡 Next step: Comment /fix to address every F# merge blocker, /fix all for every pending blocker and suggestion, or name records explicitly, as in /fix F3 S5.
F# and S# IDs increment across review comments and remain permanent, so selectors such as /fix F3 F5 stay unambiguous across cycles. S# suggestions stay optional: they are implemented only when you name them or request /fix all, and they never relax a merge blocker.

Copy and edit to choose records from this review:

/fix S1 S2

🤖 Review by ProPR

@propr-dev

propr-dev Bot commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

⚠️ Ultrafix stopped before reaching its goal. Requested goal: 8/10. Last score: 7/10. Stopped in cycle 1 of 3. The review has no actionable blockers, so no fix was scheduled. Manual review and merge are now required.

@propr-dev propr-dev Bot removed the ultrafix label Nov 26, 2026
@propr-dev propr-dev Bot changed the title 🔨 [3822 by Claude Opus 5.5] Fly Machines: PROPR_FLY_MACHINES_MAX concurrency cap that queues instead of failing at the org limit ⚠️❼ [3822 by Claude Opus 5.5] Fly Machines: PROPR_FLY_MACHINES_MAX concurrency cap that queues instead of failing at the org limit Nov 26, 2026
@integry

integry commented Nov 26, 2026

Copy link
Copy Markdown
Owner

Please fix S2: bound the until() helper in test/flyMachinesCapacity.test.ts. Give it a deadline (for example 5 s) and a descriptive assertion message, so a lifecycle regression fails promptly instead of hanging the test run. Test-only, so please don't touch the runtime code. I'm running the live PROPR_FLY_MACHINES_MAX=1 check (S1) on a558988 now.

@propr-dev propr-dev Bot changed the title ⚠️❼ [3822 by Claude Opus 5.5] Fly Machines: PROPR_FLY_MACHINES_MAX concurrency cap that queues instead of failing at the org limit 🔨 [3822 by Claude Opus 5.5] Fly Machines: PROPR_FLY_MACHINES_MAX concurrency cap that queues instead of failing at the org limit Nov 26, 2026
@propr-dev

propr-dev Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor Author

✅ Applied the requested follow-up changes in commit 14924bd

Summary of Changes

S2 is fixed: until() in test/flyMachinesCapacity.test.ts now has a deadline, so a lifecycle regression fails within seconds instead of hanging the run. Only that test file changed; the runtime code is untouched.

  • Deadline: each wait gives up after 5 s by default and fails with a message that says what it was waiting for, e.g. timed out after 5000 ms waiting until both capped runs are deleting their Machines. Every call now passes a short description like that.
  • Two longer waits: in the background-deletion-retry test, two waits cover the runtime's fixed 5 s cleanup retry (flyMachinesRuntime.ts:156). A 5 s limit there would race that retry and fail on a working build, so those two get 15 s.

Checks

  • The suite passes: 8 of 8 tests, in about 18.5 s.
  • I also ran a temporary copy with one condition that could never be met. It failed after 5.01 s with the message above instead of hanging, and I deleted the copy.
  • ESLint ignores this file (no lint rules apply to it), so there was no lint check to run.

Review digest

Risk-tiered paths

  • High risk: none
  • Normal risk: none
  • Low risk (1 file)
    • test/flyMachinesCapacity.test.ts (+26/−15)

Diff size: 1 file changed, +26/−15 lines


🤖 Implementation Details

  • Model: Claude Opus 5.5 (medium)
  • Requested By: @integry
  • Time: 4m 49s
  • Tokens: 439,618 (435,830 in / 3,788 out)
  • Cost: $0.39

Undo Changes • View Task Execution


💡 ProPR Slash Commands
Command Description Example
/merge Merge target branch into this PR and resolve conflicts /merge
/review Request an AI code review /review or /review claude-sonnet
/fix Address review blockers, or blockers and suggestions with /fix all /fix, /fix all, or /fix F3 S5
/switch Change the AI model for this PR /switch claude-opus
/use Override the model for a single follow-up run /use claude-sonnet
/ultrafix Loop review→fix cycles until score goal is met /ultrafix or /ultrafix goal=8 max=10

🤖 Generated by ProPR
Processing comment ID: 7206027586✓

S2 is fixed: `until()` in `test/flyMachinesCapacity.test.ts` now has a deadline, so a lifecycle regression fails within seconds instead of hanging the run. Only that test file changed; the runtime code is untouched.

- **Deadline:** each wait gives up after 5 s by default and fails with a message that says what it was waiting for, e.g. `timed out after 5000 ms waiting until both capped runs are deleting their Machines`. Every call now passes a short description like that.
- **Two longer waits:** in the background-deletion-retry test, two waits cover the runtime's fixed 5 s cleanup retry (`flyMachinesRuntime.ts:156`). A 5 s limit there would race that retry and fail on a working build, so those two get 15 s.

**Checks**
- The suite passes: 8 of 8 tests, in about 18.5 s.
- I also ran a temporary copy with one condition that could never be met. It failed after 5.01 s with the message above instead of hanging, and I deleted the copy.
- ESLint ignores this file (no lint rules apply to it), so there was no lint check to run.

PR: #3823
Comment by: @integry (ID: 7206027586)
Model: Claude Opus 5.5

ProPR-Agent: claude/claude-opus-5-5
@integry

integry commented Nov 27, 2026

Copy link
Copy Markdown
Owner

Live cap run fails in "Configure the signed App webhook…" (bug in this PR's workflow)

Runs https://github.com/integry/propr/actions/runs/45913844149 (attempts 1 and 2, on a558988, agent_runtime=fly-machines, cap mode) both fail with:

##[error]No successful App webhook delivery for integry/propr-fly-fixture#61. Check Webhook → Active in the fixture App settings and its recent deliveries.

Cause: in cap mode the step opens two issues, Fly smoke $APP and then Fly smoke $APP queued. The delivery check takes only the newest successful issues/opened delivery ([...][0].id) and compares its title exactly with Fly smoke $APP. The newest is the queued issue's delivery, so the check never matches.

Fix: check every successful issues/opened delivery in the recent page, not only the first. Pass when one of them has .request.payload.issue.number == $ISSUE; match on the issue number, not the title. In cap mode, also require a successful delivery for $ISSUE2. The error message should name the issue that's missing.

Once that's pushed, I'll run the cap mode live again.

@propr-dev

propr-dev Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor Author

✅ Applied the requested follow-up changes in commit a10f4d7

Summary of Changes

I fixed the webhook delivery check in the "Configure the signed App webhook…" step of .github/workflows/fly-e2e.yml. It no longer fails just because the queued issue's delivery is the newest one. I haven't run it live; that's the cap-mode run you're doing next.

What the check does now:

  • All deliveries: each pass reads the recent page (per_page=20, as before) and looks up every successful issues/opened delivery, not just the first. Each lookup is remembered, so the 12 retries don't fetch the same delivery twice.
  • Issue number: a delivery counts when .request.payload.issue.number matches. The title is no longer compared.
  • Cap mode: the step passes only once both $ISSUE and $ISSUE2 have a successful delivery. Otherwise it passes on $ISSUE alone.
  • Error message: after the 12 retries, it prints one error per issue still missing, for example No successful App webhook delivery for integry/propr-fly-fixture#62….
  • Lookup failures: if one delivery lookup or the list request fails, the step skips it and tries again on the next pass rather than stopping.

One addition you didn't ask for: a delivery only counts if its payload's repository is the fixture repo ($REPO). The App's delivery list covers every repo it's installed on, so issue #61 in another repo could otherwise produce a false pass.

Checks:

Review digest

Risk-tiered paths

  • High risk (1 file)
    • .github/workflows/fly-e2e.yml (+24/−8): CI or workflow file
  • Normal risk: none
  • Low risk: none

Diff size: 1 file changed, +24/−8 lines


🤖 Implementation Details

  • Model: Claude Opus 5.5 (medium)
  • Requested By: @integry
  • Time: 4m 39s
  • Tokens: 538,311 (534,132 in / 4,179 out)
  • Cost: $0.41

Undo Changes • View Task Execution


💡 ProPR Slash Commands
Command Description Example
/merge Merge target branch into this PR and resolve conflicts /merge
/review Request an AI code review /review or /review claude-sonnet
/fix Address review blockers, or blockers and suggestions with /fix all /fix, /fix all, or /fix F3 S5
/switch Change the AI model for this PR /switch claude-opus
/use Override the model for a single follow-up run /use claude-sonnet
/ultrafix Loop review→fix cycles until score goal is met /ultrafix or /ultrafix goal=8 max=10

🤖 Generated by ProPR
Processing comment ID: 7206394630✓

I fixed the webhook delivery check in the "Configure the signed App webhook…" step of `.github/workflows/fly-e2e.yml`. It no longer fails just because the queued issue's delivery is the newest one. I haven't run it live; that's the cap-mode run you're doing next.

**What the check does now:**
- **All deliveries:** each pass reads the recent page (`per_page=20`, as before) and looks up every successful `issues`/`opened` delivery, not just the first. Each lookup is remembered, so the 12 retries don't fetch the same delivery twice.
- **Issue number:** a delivery counts when `.request.payload.issue.number` matches. The title is no longer compared.
- **Cap mode:** the step passes only once both `$ISSUE` and `$ISSUE2` have a successful delivery. Otherwise it passes on `$ISSUE` alone.
- **Error message:** after the 12 retries, it prints one error per issue still missing, for example `No successful App webhook delivery for integry/propr-fly-fixture#62…`.
- **Lookup failures:** if one delivery lookup or the list request fails, the step skips it and tries again on the next pass rather than stopping.

**One addition you didn't ask for:** a delivery only counts if its payload's repository is the fixture repo (`$REPO`). The App's delivery list covers every repo it's installed on, so issue #61 in another repo could otherwise produce a false pass.

**Checks:**
- I pulled the step's script out and ran it against a fake App API that returns the newest-first order from your failed run (queued issue #62 first, #61 second, plus a failed delivery). It passes for #61 + #62 in cap mode and for #61 or #62 alone in normal mode. It fails, naming the issue, when #63 or #64 is expected.
- The workflow file still parses as YAML.
- `test/flyE2eMcpAutomation.test.ts` still fails its second test, the same failure it had before this PR's changes. Its first test, which reads this workflow file, passes.

PR: #3823
Comment by: @integry (ID: 7206394630)
Model: Claude Opus 5.5

ProPR-Agent: claude/claude-opus-5-5

integry commented Nov 27, 2026

Copy link
Copy Markdown
Owner

/review

@propr-dev

propr-dev Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor Author

✅ AI Code Review Complete requested by @integry

Posted 1 review:

View Task Details

@integry

integry commented Nov 27, 2026

Copy link
Copy Markdown
Owner

My review of a10f4d7: one blocker

Live: cap mode passes on a10f4d7. https://github.com/integry/propr/actions/runs/45916874089: with PROPR_FLY_MACHINES_MAX=1, the second run queued (active=1, queued=1), both runs opened their PRs, there was no 422, and teardown was clean. Thanks for the webhook-check fix.

R1 (blocker): a 404 on deletion holds the slot forever, and the cap then deadlocks

  • MachinesClient.destroy (fly/api.ts) throws on any HTTP error, 404 included.
  • retryCleanup (flyMachinesRuntime.ts) retries every 5 s with no end, and FlyMachineSlot.destroy releases only after a deletion that succeeds.
  • So if a run's Machine is already gone (deleted by an operator, fly machine destroy, Fly reclaiming it, or a destroy that succeeded at Fly but whose response was lost), every retry gets a 404. That run's slot is never freed. Once that happens to PROPR_FLY_MACHINES_MAX runs, every later run queues forever. Without the cap it was only an endless retry log; with it, all Fly Machines work stops.

Fix:

  1. destroy treats 404 (the Machine is unknown) as success. A destroyed record is already handled by gone.
  2. Make the retry loop able to free the slot: after a failed deletion, also ask api.gone(machine) and release when it's true (the same rule as releaseSlotWhenGone), instead of relying only on a deletion that succeeds.
  3. Tests:
    • a 404 on deletion frees the slot at once;
    • a Machine that disappears while its deletion keeps failing (for example 500, then gone returns true) frees the slot;
    • with max=1, a queued run starts after either case.

Notes, not blockers

  • The cap is per worker process (documented). Worth one line in setup-fly.md: with several workers, the effective limit is max × workers.
  • A create whose lookups all succeeded without finding the Machine releases at once. The comment says that race can't be closed, and I agree; it's fine as is.

@propr-dev

propr-dev Bot commented Nov 27, 2026

Copy link
Copy Markdown
Contributor Author

🔍 AI Code Review — codex:gpt-6-astra

Overall Evaluation

The PR implements process-local Fly Machine capacity limits with FIFO waiting, cancellation, and conservative slot retention during cleanup and recovery. No verified code blocker was found in the supplied diff, but the live capacity acceptance check remains unverified.

✅ Lifecycle-aware capacity — Slots remain occupied when deletion fails or a Machine is retained for recovery; failed existence checks do not release capacity.

✅ Webhook verification corrected — The workflow examines successful deliveries and matches repository plus issue number, requiring delivery for both capacity-test issues.

✅ Bounded test helper — until() now has descriptive deadlines, with additional time explicitly allowed for background cleanup retries.

This was a static review of the supplied code; no commands or tests were run. The authoritative check status reports 20 passed, three pending, and no failures.

Merge blockers

No merge blockers.

Suggestions

These are optional follow-ups and are not sent to /fix.

S3: 🟢 Complete the live capacity check

Run the updated workflow with agent_runtime=fly-machines and fly_machines_max=true, and attach evidence that a run queued and both issues completed without machine-limit errors. The supplied context contains no successful live result for the corrected workflow. This is outstanding acceptance verification rather than a demonstrated code defect; it does not justify additional implementation changes by itself.

S4: 🟢 Bound the remaining cleanup loop

In test/flyMachinesCapacity.test.ts, the first runtime capacity test still uses an unbounded while (api.destroys.length || api.live) loop. A regression that leaves a live Machine without scheduling its deletion could hang there despite the newly bounded until() helper. Adding a deadline or test-level timeout would improve failure diagnostics. This is optional hardening beyond the specific request to bound until().

Score

The implementation and targeted tests cover the principal capacity lifecycle paths, and the reported webhook bug is addressed. No code blocker is established, but the missing successful live capacity check is a material verification gap against the stated acceptance criterion.

Score: 7/10


🤖 Review Details

  • Model: GPT-6 Astra
  • Time: 26s
  • Tokens: 61,324 (60,706 in / 618 out)
  • Cost: $0.51

View Task


💡 Next step: Comment /fix to address every F# merge blocker, /fix all for every pending blocker and suggestion, or name records explicitly, as in /fix F3 S5.
F# and S# IDs increment across review comments and remain permanent, so selectors such as /fix F3 F5 stay unambiguous across cycles. S# suggestions stay optional: they are implemented only when you name them or request /fix all, and they never relax a merge blocker.

Copy and edit to choose records from this review:

/fix S3 S4

🤖 Review by ProPR

@propr-dev

propr-dev Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor Author

✅ Applied the requested follow-up changes in commit aec010e

Summary of Changes

I fixed R1. The retry loop can now free a slot when Fly confirms the Machine is gone, and that also stops the retries. All four Fly suites pass: 63 of 63, including the two new tests. The core type-check and lint are clean.

Fix 1 (404 counts as success) was already in place. MachinesClient.request in fly/api.ts doesn't throw on a DELETE that returns 404, so destroy already succeeds for an unknown Machine. This has been true since the Fly runtime was added, and an existing test in test/flyMachinesRuntime.test.ts covers it. So I didn't change api.ts. If you've seen a 404 hold a slot live, it must have come through some other path, and I'd need the log to find it.

Fix 2: the retry loop can now free the slot. When a deletion fails, FlyMachineSlot.destroy in fly/capacity.ts now asks api.gone(machine):

  • Gone (destroyed or unknown): the slot is freed, a log line says so, and the background retries stop.
  • Still there, or the check itself fails: the original error is passed on, so the slot is kept and the 5-second retry carries on. This is the same rule releaseSlotWhenGone uses.

Tests (added to test/flyMachinesCapacity.test.ts, both with PROPR_FLY_MACHINES_MAX=1):

  • 404 on deletion: the 404 goes through the real MachinesClient.destroy with fetch mocked. It frees the slot at once, the queued run starts, and there's no retry. This test also passes on the old code, because the 404 handling was already there.
  • Machine disappears while deletion keeps failing (500 every time): the queued run waits while Fly still lists the Machine. Once Fly reports it gone, the next retry frees the slot and the queued run starts. There are no more deletion attempts after that. This test fails when run against the old capacity.ts.

test/flyMachinesRuntime.test.ts only passes with PROPR_DEMO_MODE=true set. Without it, the file exits 1 even though all its subtests pass, and that happens on HEAD too. It's a local setup issue (no GitHub auth configured), not something this change caused.

Docs:

  • setup-fly.md: a slot is freed once the Machine is destroyed or Fly reports it gone. With several workers, the effective limit is PROPR_FLY_MACHINES_MAX × workers.
  • agent-runtime.md: a Machine whose deletion is being retried also frees its slot once Fly reports it destroyed or unknown, and a 404 on deletion counts as success.

There's nothing visual to preview.

Review digest

Risk-tiered paths

  • High risk: none
  • Normal risk (1 file)
    • packages/core/src/agents/runtime/fly/capacity.ts (+10/−2)
  • Low risk (3 files)
    • docs/docs/architecture/agent-runtime.md (+1/−1)
    • docs/docs/tutorials/setup-fly.md (+1/−1)
    • test/flyMachinesCapacity.test.ts (+66/−1)

Diff size: 4 files changed, +78/−5 lines


🤖 Implementation Details

  • Model: Claude Opus 5.5 (medium)
  • Requested By: @integry
  • Time: 9m 23s
  • Tokens: 1,085,288 (1,077,444 in / 7,844 out)
  • Cost: $0.67

Undo Changes • View Task Execution


💡 ProPR Slash Commands
Command Description Example
/merge Merge target branch into this PR and resolve conflicts /merge
/review Request an AI code review /review or /review claude-sonnet
/fix Address review blockers, or blockers and suggestions with /fix all /fix, /fix all, or /fix F3 S5
/switch Change the AI model for this PR /switch claude-opus
/use Override the model for a single follow-up run /use claude-sonnet
/ultrafix Loop review→fix cycles until score goal is met /ultrafix or /ultrafix goal=8 max=10

🤖 Generated by ProPR
Processing comment ID: 7206742688✓

I fixed R1. The retry loop can now free a slot when Fly confirms the Machine is gone, and that also stops the retries. All four Fly suites pass: 63 of 63, including the two new tests. The core type-check and lint are clean.

**Fix 1 (404 counts as success) was already in place.** `MachinesClient.request` in `fly/api.ts` doesn't throw on a `DELETE` that returns 404, so `destroy` already succeeds for an unknown Machine. This has been true since the Fly runtime was added, and an existing test in `test/flyMachinesRuntime.test.ts` covers it. So I didn't change `api.ts`. If you've seen a 404 hold a slot live, it must have come through some other path, and I'd need the log to find it.

**Fix 2: the retry loop can now free the slot.** When a deletion fails, `FlyMachineSlot.destroy` in `fly/capacity.ts` now asks `api.gone(machine)`:
- **Gone (destroyed or unknown):** the slot is freed, a log line says so, and the background retries stop.
- **Still there, or the check itself fails:** the original error is passed on, so the slot is kept and the 5-second retry carries on. This is the same rule `releaseSlotWhenGone` uses.

**Tests** (added to `test/flyMachinesCapacity.test.ts`, both with `PROPR_FLY_MACHINES_MAX=1`):
- **404 on deletion:** the 404 goes through the real `MachinesClient.destroy` with `fetch` mocked. It frees the slot at once, the queued run starts, and there's no retry. This test also passes on the old code, because the 404 handling was already there.
- **Machine disappears while deletion keeps failing (500 every time):** the queued run waits while Fly still lists the Machine. Once Fly reports it gone, the next retry frees the slot and the queued run starts. There are no more deletion attempts after that. This test fails when run against the old `capacity.ts`.

`test/flyMachinesRuntime.test.ts` only passes with `PROPR_DEMO_MODE=true` set. Without it, the file exits 1 even though all its subtests pass, and that happens on HEAD too. It's a local setup issue (no GitHub auth configured), not something this change caused.

**Docs:**
- **`setup-fly.md`:** a slot is freed once the Machine is destroyed or Fly reports it gone. With several workers, the effective limit is `PROPR_FLY_MACHINES_MAX` × workers.
- **`agent-runtime.md`:** a Machine whose deletion is being retried also frees its slot once Fly reports it destroyed or unknown, and a 404 on deletion counts as success.

There's nothing visual to preview.

PR: #3823
Comment by: @integry (ID: 7206742688)
Model: Claude Opus 5.5

ProPR-Agent: claude/claude-opus-5-5

integry commented Nov 27, 2026

Copy link
Copy Markdown
Owner

/review

@propr-dev

propr-dev Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor Author

✅ AI Code Review Complete requested by @integry

Posted 1 review:

View Task Details

@propr-dev

propr-dev Bot commented Nov 27, 2026

Copy link
Copy Markdown
Contributor Author

🔍 AI Code Review — codex:gpt-6-astra

Overall Evaluation

The PR restores a process-local Fly Machines cap with FIFO waiting, cancellation, and slot accounting through cleanup and recovery. The implementation is ready to merge within the reviewed scope, conditional on pending checks completing successfully.

✅ Conservative slot release — Failed deletions retain capacity unless Fly confirms absence; the current API client also treats DELETE 404 as success, addressing the previously reported deadlock.

✅ Queue lifecycle coverage — Tests cover FIFO admission, cancelled waiters, idempotent release, background deletion retries, retained Machines, and unconfirmed creates.

✅ Workflow correction — Webhook verification matches repository and issue number across successful deliveries and requires delivery for both capacity-test issues.

This was a static review of the supplied code and context; no commands or tests were run. The supplied current-head status reports no failures, with 13 checks pending.

Merge blockers

No merge blockers.

Suggestions

These are optional follow-ups and are not sent to /fix.

S5: 🟢 Test failure after slot acquisition

In test/flyMachinesCapacity.test.ts, the test named “a run that fails before creating a Machine frees its slot at once” fails during package loading, before slot.acquire() executes. Add a case that acquires the slot and then fails before creation—for example, through extension.beforeLaunch()—and verify a queued run proceeds. This would strengthen coverage of the cleanup boundary; static inspection does not establish a defect in that path.

S6: 🟢 Bound the remaining drain loop

The first runtime capacity test still uses an unbounded while (api.destroys.length || api.live) loop. Applying a deadline there would complement the bounded until() helper and ensure a cleanup regression produces a diagnostic failure promptly. This is optional test hardening rather than a demonstrated runtime problem.

Score

The implementation satisfies the scoped objective with substantial lifecycle coverage and addresses the earlier deletion and webhook issues. Static review found no merge blockers; current-head checks remain pending.

Score: 8/10


🤖 Review Details

  • Model: GPT-6 Astra
  • Time: 32s
  • Tokens: 63,577 (62,921 in / 656 out)
  • Cost: $0.53

View Task


💡 Next step: Comment /fix to address every F# merge blocker, /fix all for every pending blocker and suggestion, or name records explicitly, as in /fix F3 S5.
F# and S# IDs increment across review comments and remain permanent, so selectors such as /fix F3 F5 stay unambiguous across cycles. S# suggestions stay optional: they are implemented only when you name them or request /fix all, and they never relax a merge blocker.

Copy and edit to choose records from this review:

/fix S5 S6

🤖 Review by ProPR

@propr-dev propr-dev Bot changed the title 🔨 [3822 by Claude Opus 5.5] Fly Machines: PROPR_FLY_MACHINES_MAX concurrency cap that queues instead of failing at the org limit ✅❽ [3822 by Claude Opus 5.5] Fly Machines: PROPR_FLY_MACHINES_MAX concurrency cap that queues instead of failing at the org limit Nov 27, 2026
@integry
integry merged commit ef801a9 into 3758-epic-runtime-abstraction-sc0 Nov 27, 2026
41 checks passed
@propr-dev propr-dev Bot changed the title ✅❽ [3822 by Claude Opus 5.5] Fly Machines: PROPR_FLY_MACHINES_MAX concurrency cap that queues instead of failing at the org limit [3822 by Claude Opus 5.5] Fly Machines: PROPR_FLY_MACHINES_MAX concurrency cap that queues instead of failing at the org limit Nov 27, 2026
propr-dev Bot pushed a commit that referenced this pull request Nov 27, 2026
I've reworked the epic merge so #3823's capacity code is the base. All the Fly suites, the core typecheck and zero-warning lint pass. The live Fly Machines runs (default, then cap mode) are still yours to do.

The automatic merge commit (588d8cb) had resolved the conflict the wrong way. It deleted #3823's `FlyMachineSlot` in favour of this PR's own helper, made `MachinesApi.find` optional, and left a second copy of the slot-holding logic in `fly/dispatch.ts`. I undid all three.

**1. Capacity code (`fly/capacity.ts`)**
- **Kept as-is:** `FlyMachineSlot`, `acquireFlyMachineSlot`, `releaseSlotWhenGone`, `releaseUndeletedFlyMachineSlot` and `MachineCreateUnconfirmedError`. `MachinesApi.gone` and `find` are required again, with #3823's wording.
- **R1:** #3823's delete-or-confirm-gone code from `FlyMachineSlot.destroy` is now one function, `deleteFlyMachine`. A 404 on deletion counts as deleted, and so does a failed deletion once `api.gone` says the Machine is gone. Agent and builder Machines both use it.
- **What this PR adds on top:**
  - **Builders count against the cap:** a builder Machine takes a `FlyMachineSlot` of its own.
  - **F1:** a refused agent create gives up its slot (`releaseUnused`) while it rebuilds the image, then takes it again. `queueMs` includes the second wait.
  - **F3:** a lost create, whether its lookup failed or found nothing yet, keeps its slot through the 60s lookup window. This applies to agent and builder Machines.
  - **F4:** a run cancelled during startup reconciliation still stops waiting at once.
- **One copy:** the separate slot holder in `dispatch.ts` is gone. The runtime creates the run's `FlyMachineSlot` and passes it to dispatch.

**2. Builder Machine deletion:** builder deletion now follows the same rule as R1. New test: every DELETE of a builder fails, then Fly's GET (through the real `MachinesClient`) starts answering 404, as if it had been deleted outside ProPR. The slot is freed, the run waiting behind it starts, and the retries stop. With the gone check removed, the queued run never starts, so the test fails.

**3. Smoke workflow (`fly-e2e.yml`):** #3823's cap mode and its webhook delivery check (matched by issue number) are unchanged. The derived-image reuse, rebuild and teardown step now runs only in the default Fly Machines run, not in cap mode. The YAML parses; I couldn't run actionlint here.

**Tests:**

| Suite | Passed |
| --- | --- |
| Capacity | 13/13 |
| Derived image | 40/40 |
| Runtime | 42/42 |
| Create request | 3/3 |
| Runtime packages | 8/8 |
| `flyE2eMcpAutomation` | 2/2 |

`flyE2eMcpAutomation` still fails only when `PROPR_DEMO_MODE=true` is set, which isn't caused by this change. One existing test had relied on `find` being missing; it now makes the lookup fail on purpose.

I also added a sentence on the builder deletion rule to `agent-runtime.md`. Nothing visual changed, so there are no previews.

PR: #3825
Comment by: @integry (ID: 7207255537)
Model: Claude Opus 5.5

ProPR-Agent: claude/claude-opus-5-5
propr-dev Bot pushed a commit that referenced this pull request Nov 27, 2026
I've made all three fixes. The Fly suites pass (capacity 15/15, derived image 52/52, runtime/create-request/packages 53/53), and typecheck and zero-warning lint pass on `packages/core`. I couldn't reproduce the live cap-mode run here, so your rerun is the real check.

**1. Builder slot (`fly/imageBuilder.ts`).** `removeBuilder` used to return as soon as the DELETE succeeded, and that freed the slot. It now deletes once, then keeps polling `api.gone(builder)` until Fly confirms the Machine is gone. Only then is the slot freed. If that isn't confirmed within the removal window, the builder becomes an unresolved Machine that keeps its slot and is retried in the background. This also covers the other places builders get deleted: lost creates, unresolved records and leftovers from an earlier worker.

**2. 422 "machine limit" is now a capacity wait (new `fly/machineLimit.ts`).**
- **Retry:** `createWithinMachineLimit` retries the same launch (same name) after 5, 10, 20, 40 and then 60 s waits, for up to 5 minutes. The run keeps its slot the whole time. Each retry logs `Fly organization machine limit reached; retrying create` with `attempt` and `delayMs`.
- **Failure:** after the bound the run fails with `Fly organization machine limit reached: Fly refused the Machine create N times over Ns (…Fly's 422 message…). Delete Machines in the Fly organization or raise its limit, then retry the run.`
- **Where it applies:** agent creates, including the retried create after a refusal, and builder creates.
- **Derived image:** a machine-limit refusal no longer makes the worker discard its derived image and select again.
- **Builder past the bound:** a builder still refused falls back to installing the packages at Machine start.
- **Stopping:** a run that is being stopped ends the wait.

**3. Diagnostics.** Each 422 logs `Fly organization machine limit reached; Machines in the agent app` with only `id`, `state` and `name` for each Machine.

**Tests.** The three you asked for are in, and each one fails when its fix is disabled:
- A create refused twice and then accepted keeps one slot: three POSTs with the same name, one Machine, the queued run never overlaps (peak 1), and two Machine-list logs.
- A builder whose deletion returns but which Fly still lists holds the slot: no agent Machine is created until `gone` is true.
- After the bound, the run fails with the machine-limit message and the next run gets the slot.

Three existing tests changed because builders now get an extra `gone` check: one expected gone-check count went from 1 to 2, the fake-fetch test now answers `GET /machines/late1`, and the leftover fake now reports a deleted leftover as gone. The docs (`agent-runtime.md`, `setup-fly.md`) describe the retry, its log lines and the "gone, not just deleted" rule for builders.

**Decision for you:** your request says builders should wait for `gone` "as for agent Machines", but agent Machines don't do that. Their slot is still freed when the DELETE returns (the same `deleteFlyMachine` rule from #3823); I left that alone because fix 1 named only the builder. So a deleted agent Machine that Fly still counts can still trigger a 422 on the next run, which the new retry now absorbs. Making agent slots also wait for `gone` would let the queued run wait in the queue instead of hitting a 422 at all. It's a small change if you want it.

No previews: nothing visible changed.

PR: #3825
Comment by: @integry (ID: 7218159098)
Model: Claude Opus 5.5

ProPR-Agent: claude/claude-opus-5-5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant