Skip to content

[3821 by Claude Opus 5.5] Fly Machines: bake runtime packages into a derived agent image - #3825

Merged
integry merged 11 commits into
3758-epic-runtime-abstraction-sc0from
3821/claude-opus-5-5-fly-machines-bake-runtime-20261126-2328-m2d
Nov 27, 2026
Merged

integry merged 11 commits into
3758-epic-runtime-abstraction-sc0from
3821/claude-opus-5-5-fly-machines-bake-runtime-20261126-2328-m2d

Conversation

@propr-dev

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

Copy link
Copy Markdown
Contributor

AI Implementation Summary

Closes #3821

Branch: 3821/claude-opus-5-5-fly-machines-bake-runtime-20261126-2328-m2d
Commits: ✅ Changes committed (d2359b4)


AI Processing Completed

Execution Details:

Summary:
Fly Machines now bake the runtime packages into a derived agent image again, built once per base image digest and package list. I couldn't run the live acceptance here, so fly-e2e.yml (agent_runtime=fly-machines) still needs a run from your side. Typecheck and zero-warning lint pass on packages/core, and the unit, API and Settings UI suites I ran all pass.

One overlap to decide on: the issue says a build Machine must count against PROPR_FLY_MACHINES_MAX, but that setting doesn't exist on the base branch; it's #3822's scope. To meet the requirement I put back the cap from before 53a9fb5 (fly/capacity.ts, its test, the config field, docs and .env.example) and extended it to build Machines. Expect a conflict with #3822's PR; keep whichever cap version you prefer, as long as build Machines and startup leftovers still take slots.

Restored from 3807-derived-fly-image-reference (cfbdeca): derivedImage.ts, registry.ts, wrapperBuild.ts, the wrapper's build mode and its test file. These were adapted to the current branch: package MCP servers, per-runtime package lists and the new index format. This includes the R0 publish-time check: every dpkg -L file must be in the layer, and the layer must be at least the installed size.

New on top of that:

  • Capacity:
    • A build Machine takes a slot before it's created and frees it only once Fly confirms it deleted.
    • One whose deletion or lost create can't be confirmed keeps its slot, and the worker retries the delete in the background every minute.
    • A run waits for its agent Machine's slot only after any build it needed is gone, so on the Free Plan a run never has both Machines at once.
  • Leftovers at startup: before its first Fly run, each worker process lists the agent app's propr-build-* Machines, and each one holds a slot until it's gone. One older than any build could take is deleted. A younger one may be another worker's build in progress, so it is only waited out.
  • Lost agent creates: if a create response is lost and the follow-up lookup fails, the run keeps its slot until a lookup succeeds.
  • Compute usage: imageWaitMs (build wait) and queueMs (slot wait) are their own fields, and wall time is measured from dispatch.
  • Settings text: reads "Installed in a derived Fly Machine image" again.
  • Refactor: to stay under the 400-line lint limit, the build Machine code moved into new modules (fly/imageBuilder.ts, fly/dispatch.ts, fly/exitPoll.ts).

Tests: the restored derived-image suite plus 3 new tests pass (36), and so does the capacity suite (9). The new tests cover a build Machine holding a slot so no agent Machine runs beside it, a stuck delete keeping its slot until the background retry, and leftovers found by prefix. I disabled the build Machine's slot and confirmed the two cap tests fail without it.

flyE2eMcpAutomation fails only when PROPR_DEMO_MODE=true is set; it passes without it, and that test only exercises Sprites.

Live workflow:

  • It now expects the "Installed agent runtime packages in a derived Fly Machine image" log line and records the digest the first run built.
  • A new step then checks from a fresh process:
    • the same list reuses that digest with no build Machine.
    • adding cowsay builds exactly one new digest.
    • no Machines are left in the agent app.
  • I checked that the YAML, shell and embedded script parse; actionlint isn't available here.

Docs: the Fly Machines row of the per-runtime package table in agent-runtime.md, a new "Derived Fly images" section (build steps, fallback, tag cleanup, capacity), and the Fly tutorial.

No previews: the only visible change is that one Settings sentence.

Review digest

Risk-tiered paths

  • High risk (1 file)
    • .github/workflows/fly-e2e.yml (+62/−3): CI or workflow file
  • Normal risk (16 files)
    • .env.example (+3/−0)
    • packages/core/src/agents/runtime/agentRuntimePackageIndex.ts (+7/−6)
    • packages/core/src/agents/runtime/agentRuntimePackageProfile.ts (+1/−1)
    • packages/core/src/agents/runtime/computeUsage.ts (+4/−0)
    • packages/core/src/agents/runtime/fly/api.ts (+66/−7)
    • packages/core/src/agents/runtime/fly/capacity.ts (added, +124/−0)
    • packages/core/src/agents/runtime/fly/config.ts (+3/−1)
    • packages/core/src/agents/runtime/fly/derivedImage.ts (added, +378/−0)
    • packages/core/src/agents/runtime/fly/dispatch.ts (added, +78/−0)
    • packages/core/src/agents/runtime/fly/exitPoll.ts (added, +70/−0)
    • packages/core/src/agents/runtime/fly/imageBuilder.ts (added, +282/−0)
    • packages/core/src/agents/runtime/fly/packages.ts (+5/−2)
    • packages/core/src/agents/runtime/fly/registry.ts (added, +169/−0)
    • packages/core/src/agents/runtime/fly/wrapper.ts (+31/−15)
    • packages/core/src/agents/runtime/fly/wrapperBuild.ts (added, +246/−0)
    • packages/core/src/agents/runtime/flyMachinesRuntime.ts (+41/−84)
  • Low risk (11 files)
    • docs/docs/architecture/agent-runtime.md (+23/−5)
    • docs/docs/tutorials/setup-fly.md (+2/−2)
    • packages/api/test/agentRuntimeIndexRoutes.test.ts (+2/−2)
    • packages/api/test/agentRuntimeRoutes.test.ts (+1/−1)
    • propr-ui/src/pages/SettingsPage/AgentRuntimePackagesSection.test.tsx (+3/−3)
    • test/agentRuntimePackagesRemoteSettings.test.ts (+4/−4)
    • test/flyDerivedImage.test.ts (added, +1,090/−0)
    • test/flyMachinesCapacity.test.ts (added, +281/−0)
    • test/flyMachinesCreateRequest.test.ts (+2/−0)
    • test/flyMachinesRuntime.test.ts (+2/−0)
    • test/flyRuntimePackages.test.ts (+5/−1)

Diff size: 28 files changed, +2,985/−137 lines

View task for the run's logs and conversation.


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


💡 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!

Fly Machines now bake the runtime packages into a derived agent image again, built once per base image digest and package list. I couldn't run the live acceptance here, so `fly-e2e.yml` (`agent_runtime=fly-machines`) still needs a run from your side. Typecheck and zero-warning lint pass on `packages/core`, and the unit, API and Settings UI suites I ran all pass.

One overlap to decide on: the issue says a build Machine must count against `PROPR_FLY_MACHINES_MAX`, but that setting doesn't exist on the base branch; it's #3822's scope. To meet the requirement I put back the cap from before 53a9fb5 (`fly/capacity.ts`, its test, the config field, docs and `.env.example`) and extended it to build Machines. Expect a conflict with #3822's PR; keep whichever cap version you prefer, as long as build Machines and startup leftovers still take slots.

Restored from `3807-derived-fly-image-reference` (cfbdeca): `derivedImage.ts`, `registry.ts`, `wrapperBuild.ts`, the wrapper's `build` mode and its test file. These were adapted to the current branch: package MCP servers, per-runtime package lists and the new index format. This includes the R0 publish-time check: every `dpkg -L` file must be in the layer, and the layer must be at least the installed size.

New on top of that:
- Capacity:
  - A build Machine takes a slot before it's created and frees it only once Fly confirms it deleted.
  - One whose deletion or lost create can't be confirmed keeps its slot, and the worker retries the delete in the background every minute.
  - A run waits for its agent Machine's slot only after any build it needed is gone, so on the Free Plan a run never has both Machines at once.
- Leftovers at startup: before its first Fly run, each worker process lists the agent app's `propr-build-*` Machines, and each one holds a slot until it's gone. One older than any build could take is deleted. A younger one may be another worker's build in progress, so it is only waited out.
- Lost agent creates: if a create response is lost and the follow-up lookup fails, the run keeps its slot until a lookup succeeds.
- Compute usage: `imageWaitMs` (build wait) and `queueMs` (slot wait) are their own fields, and wall time is measured from dispatch.
- Settings text: reads "Installed in a derived Fly Machine image" again.
- Refactor: to stay under the 400-line lint limit, the build Machine code moved into new modules (`fly/imageBuilder.ts`, `fly/dispatch.ts`, `fly/exitPoll.ts`).

Tests: the restored derived-image suite plus 3 new tests pass (36), and so does the capacity suite (9). The new tests cover a build Machine holding a slot so no agent Machine runs beside it, a stuck delete keeping its slot until the background retry, and leftovers found by prefix. I disabled the build Machine's slot and confirmed the two cap tests fail without it.

`flyE2eMcpAutomation` fails only when `PROPR_DEMO_MODE=true` is set; it passes without it, and that test only exercises Sprites.

Live workflow:
- It now expects the "Installed agent runtime packages in a derived Fly Machine image" log line and records the digest the first run built.
- A new step then checks from a fresh process:
  - the same list reuses that digest with no build Machine.
  - adding `cowsay` builds exactly one new digest.
  - no Machines are left in the agent app.
- I checked that the YAML, shell and embedded script parse; actionlint isn't available here.

Docs: the Fly Machines row of the per-runtime package table in `agent-runtime.md`, a new "Derived Fly images" section (build steps, fallback, tag cleanup, capacity), and the Fly tutorial.

No previews: the only visible change is that one Settings sentence.

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 27, 2026

Copy link
Copy Markdown
Contributor Author

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

Overall Evaluation

The PR restores derived Fly package images with substantial lifecycle handling and tests. It needs changes before merge: the retry path can deadlock under the new capacity cap, and concurrent cache revalidation can start duplicate builds.

✅ Layer integrity checks — The worker verifies compressed and uncompressed digests and rejects layers lacking the wrapper’s dpkg verification.

✅ Cleanup obligations — Unconfirmed build deletion retains its capacity slot and schedules background reconciliation.

✅ Fallback coverage — Tests cover registry failures, installation failures, missing images, and recovery from lost build-create responses.

This review is a static analysis of the supplied code; no commands were run. The authoritative check summary reports no failures and five pending checks.

Merge blockers

Every finding below was introduced by this PR and must be resolved before merging.

F1: 🔴 Rebuilding after refusal deadlocks capacity

  • Category: correctness

  • Required behavior: A run must prepare its derived image before holding its agent Machine slot, so rebuilding remains possible with PROPR_FLY_MACHINES_MAX=1.

  • Evidence: packages/core/src/agents/runtime/fly/derivedImage.ts:createAgentMachine, packages/core/src/agents/runtime/fly/dispatch.ts:dispatchFlyRun, packages/core/src/agents/runtime/fly/imageBuilder.ts:buildLayer

    1. Configure a one-Machine cap and reuse a cached derived image whose registry tag has subsequently disappeared.
    2. dispatchFlyRun selects the cached image and acquires the agent slot.
    3. Fly refuses the agent create with HTTP 422 because the image is unavailable. createAgentMachine invalidates the cache and awaits selectFlyPackageImage while retaining that slot.
    4. Selection finds no published derived image and reaches buildLayer, which awaits another slot using a signal that never aborts.
    5. The run cannot finish its create until the build finishes, while the build cannot start until the run releases its slot.

    The run stalls until externally cancelled; no Machine needs to exist for this deadlock. The normal dispatch ordering prevents it on initial selection but is bypassed during retry. The supplied refused-image rebuild tests omit the cap, while the cap tests omit refused-image rebuilding. With a larger cap, enough concurrent refused creates can exhaust all slots in the same way. static trace: followed slot acquisition, retry selection, builder acquisition, and final cleanup in the supplied diff.

  • Minimum fix: On a confirmed create refusal, release the agent reservation before preparing the replacement image, then reacquire capacity before the next agent create. Keep reservation ownership and final cleanup idempotent, and add a capped refused-image rebuild regression.

F2: 🔴 Concurrent rechecks discard replacement builds

  • Category: correctness

  • Required behavior: Concurrent runs in one worker must share one preparation for the same base image and package list.

  • Evidence: packages/core/src/agents/runtime/fly/derivedImage.ts:cachedImage

    1. An existing cache entry is old enough to recheck, and its registry tag has been deleted.
    2. Runs A and B both capture that same entry and await stillPublished. Both registry lookups report the missing tag.
    3. A resumes first, deletes the old entry, and starts a replacement preparation, inserting its pending promise into images.
    4. B resumes afterward and unconditionally executes images.delete(key). This deletes A’s replacement entry, although B checked only the old entry.
    5. B finds no cached preparation and starts another build for the same key.

    The competing actor acts during the awaited registry recheck. The later cached ??= images.get(key) protection cannot help because B has already deleted the replacement. With available capacity, two build Machines run and publish competing manifests; with a one-slot cap, the duplicate preparation remains queued and can still rebuild unnecessarily. static trace: the unconditional deletion after await this.stillPublished(...) permits this ordering; the supplied deleted-tag test exercises only sequential runs.

  • Minimum fix: Delete an invalidated entry only if images.get(key) still equals the entry that was checked. Otherwise adopt or re-evaluate the replacement entry. Add a regression with two deferred missing-tag rechecks and assert exactly one replacement build.

Suggestions

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

S1: 🟢 Record live acceptance evidence

Run the updated Fly workflow and attach its build, reuse, changed-list, and teardown results. The mocked registry and Machine tests provide useful coverage, but the implementation summary explicitly leaves live acceptance unverified. This is additional validation, not a separately demonstrated code blocker.

Score

The integrity checks and extensive tests are valuable, but two concurrency defects remain in core image preparation and capacity handling. Current checks report no failures, with five still pending.

Score: 6/10


🤖 Review Details

  • Model: GPT-6 Astra
  • Time: 1m 9s
  • Tokens: 107,862 (106,287 in / 1,575 out)
  • Cost: $1.03

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 F1 F2 S1

🤖 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 ed91970

Addressed 1 AI review comment (IDs: 7206104484)

Addressed findings F1, F2

Summary of Changes

I fixed F1 and F2, and added a regression test for each. I checked that each test fails when its fix is removed: the F1 test hangs until its 15 s timeout, which is the deadlock, and the F2 test builds twice. With the fixes in, the four Fly suites pass (91 tests), and typecheck and zero-warning lint pass on packages/core.

F1: rebuild after a refused create deadlocked under the cap

  • Fix: when Fly refuses an agent create (HTTP 422, so no Machine exists), createAgentMachine now gives up the run's slot before it checks the registry or rebuilds. It waits for a slot again only if a retry will actually happen. If the same image comes back or the run is stopping, the run fails without taking the slot back. The build Machine can now get the slot even with PROPR_FLY_MACHINES_MAX=1.
  • Slot ownership: dispatchFlyRun (in fly/dispatch.ts) now holds the run's slot. Its release() frees whichever slot the run holds at that moment and does nothing the second time. The runtime's final cleanup, including keeping the slot after a lost create, still calls it unchanged, so a run that gave up its slot and then failed can't free it twice.
  • Queue time: any wait to take the slot back is added to queueMs.
  • Sibling check: I found no other place where a run holds its agent slot while waiting on a build. On the first selection the slot is still taken only after the image is ready, and build and leftover slots work as before. Because each refused run frees its own slot first, the larger-cap case where many refused runs used up every slot is covered too.
  • Test: "a refused create under PROPR_FLY_MACHINES_MAX=1 gives up its slot to rebuild the image, then takes it again". It checks the exact order: refused launch, create build, destroy build, create launch, destroy launch. It also checks that only one Machine ever runs at a time, and that a later run gets the freed slot.

F2: concurrent rechecks discarded a replacement build

  • Fix: in cachedImage, a run that finds the tag missing now removes the cache entry only if it is still the entry it checked. If another run already started a replacement build, this run uses that build.
  • Sibling check: the other places that remove cache entries (invalidate and the failure handler in startPreparation) don't have this problem.
  • Test: "concurrent rechecks that both find the tag deleted share one replacement build". Two runs hold the deleted-tag lookup open at the same time. The test checks that exactly one replacement build runs and that both agent Machines start from the rebuilt image.

I also added a sentence to the derived-image paragraph in docs/docs/architecture/agent-runtime.md explaining that a run gives up its slot while it rebuilds after a refusal.

I found nothing else to report. There are no previews, because nothing visible changed.

Review digest

Risk-tiered paths

  • High risk: none
  • Normal risk (2 files)
    • packages/core/src/agents/runtime/fly/derivedImage.ts (+14/−2)
    • packages/core/src/agents/runtime/fly/dispatch.ts (+25/−6)
  • Low risk (2 files)
    • docs/docs/architecture/agent-runtime.md (+1/−1)
    • test/flyDerivedImage.test.ts (+70/−0)

Diff size: 4 files changed, +110/−9 lines


🤖 Implementation Details

  • Model: Claude Opus 5.5 (medium)
  • Requested By: @propr-ultrafix
  • Time: 7m 22s
  • Tokens: 1,155,323 (1,146,196 in / 9,127 out)
  • Cost: $0.80
  • Subscription usage: Weekly +1%

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

I fixed F1 and F2, and added a regression test for each. I checked that each test fails when its fix is removed: the F1 test hangs until its 15 s timeout, which is the deadlock, and the F2 test builds twice. With the fixes in, the four Fly suites pass (91 tests), and typecheck and zero-warning lint pass on `packages/core`.

**F1: rebuild after a refused create deadlocked under the cap**
- **Fix:** when Fly refuses an agent create (HTTP 422, so no Machine exists), `createAgentMachine` now gives up the run's slot before it checks the registry or rebuilds. It waits for a slot again only if a retry will actually happen. If the same image comes back or the run is stopping, the run fails without taking the slot back. The build Machine can now get the slot even with `PROPR_FLY_MACHINES_MAX=1`.
- **Slot ownership:** `dispatchFlyRun` (in `fly/dispatch.ts`) now holds the run's slot. Its `release()` frees whichever slot the run holds at that moment and does nothing the second time. The runtime's final cleanup, including keeping the slot after a lost create, still calls it unchanged, so a run that gave up its slot and then failed can't free it twice.
- **Queue time:** any wait to take the slot back is added to `queueMs`.
- **Sibling check:** I found no other place where a run holds its agent slot while waiting on a build. On the first selection the slot is still taken only after the image is ready, and build and leftover slots work as before. Because each refused run frees its own slot first, the larger-cap case where many refused runs used up every slot is covered too.
- **Test:** "a refused create under PROPR_FLY_MACHINES_MAX=1 gives up its slot to rebuild the image, then takes it again". It checks the exact order: refused launch, create build, destroy build, create launch, destroy launch. It also checks that only one Machine ever runs at a time, and that a later run gets the freed slot.

**F2: concurrent rechecks discarded a replacement build**
- **Fix:** in `cachedImage`, a run that finds the tag missing now removes the cache entry only if it is still the entry it checked. If another run already started a replacement build, this run uses that build.
- **Sibling check:** the other places that remove cache entries (`invalidate` and the failure handler in `startPreparation`) don't have this problem.
- **Test:** "concurrent rechecks that both find the tag deleted share one replacement build". Two runs hold the deleted-tag lookup open at the same time. The test checks that exactly one replacement build runs and that both agent Machines start from the rebuilt image.

I also added a sentence to the derived-image paragraph in `docs/docs/architecture/agent-runtime.md` explaining that a run gives up its slot while it rebuilds after a refusal.

I found nothing else to report. There are no previews, because nothing visible changed.

PR: #3825
Comment by: @propr-ultrafix (ID: 0)
Model: Claude Opus 5.5

ProPR-Agent: claude/claude-opus-5-5
@propr-dev

propr-dev Bot commented Nov 27, 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 27, 2026

Copy link
Copy Markdown
Contributor Author

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

Overall Evaluation

The PR restores derived Fly images with shared builds, registry caching, fallback installation, and capacity accounting. It needs changes before merge: lost agent creates can release capacity prematurely, and startup reconciliation can prevent cancellation from settling.

✅ Verified layer transfer — The worker checks compressed size, digest, and uncompressed diff ID before publishing.

✅ Rebuild capacity handling — A refused agent create releases its slot before rebuilding, avoiding a deadlock with a cap of one.

✅ Focused regression coverage — Added tests cover shared builds, registry failures, deleted tags, and failed builder cleanup.

This is a static review of the supplied code; no commands were run. Current checks report 20 passed, three pending, and no failures.

Merge blockers

Every finding below was introduced by this PR and must be resolved before merging.

F3: 🔴 Retain capacity for late agent creates

  • Category: correctness

  • Required behavior: An unconfirmed create must retain its capacity obligation while the Machine may still appear.

  • Evidence: packages/core/src/agents/runtime/fly/capacity.ts, releaseUndeletedFlyMachineSlot; packages/core/src/agents/runtime/fly/dispatch.ts, createFlyAgentMachine.

    1. An agent create loses its response. The client's three name lookups return nothing, producing MachineNotFoundAfterCreateError; its documented contract explicitly says creation may still be in flight.
    2. createFlyAgentMachine marks this outcome unconfirmed.
    3. Cleanup schedules an immediate lookup with afterMs: 0. If that lookup also returns nothing, its callback returns true, permanently releasing the slot.
    4. A queued run can create its Machine before the original delayed create becomes visible. The original Machine then exists without a retained lookup or cleanup obligation, exceeding the configured capacity.

    The successful empty lookup supplies no stronger evidence than the three empty lookups that deliberately produced an unconfirmed outcome. Unlike settleLostBuilder, this sibling path has no observation window. static trace: followed the new error classification through dispatch and slot cleanup. proposed regression: return empty results through the immediate cleanup lookup, then expose the original Machine; assert capacity remains held until reconciliation deletes it.

  • Minimum fix: Give lost agent creates a bounded reconciliation window comparable to lost builder creates, retaining the slot and cleanup obligation throughout it. Do not treat the first immediate empty lookup as confirmation.

F4: 🔴 Allow cancellation during startup reconciliation

  • Category: correctness

  • Required behavior: Cancelling a run waiting for capacity must remove that run from the wait and allow it to settle without creating a Machine.

  • Evidence: packages/core/src/agents/runtime/fly/dispatch.ts, dispatchFlyRun; packages/core/src/agents/runtime/fly/derivedImage.ts, reconcileLeftovers.

    1. A worker starts with PROPR_FLY_MACHINES_MAX=1 and discovers two leftover builders, with a young builder listed first.
    2. Reconciliation acquires the first slot and starts watching that builder. It then awaits a slot for the second leftover using AbortSignal.any([]).
    3. The user cancels the run while this acquisition is pending. dispatchFlyRun directly awaits the shared reconciliation promise without racing it against the run's signal.
    4. The cancelled run cannot settle until the first leftover disappears and reconciliation advances. A legitimate ongoing build can keep cancellation blocked for many minutes.

    The cancellation support in the later agent-slot acquisition is never reached. Sharing reconciliation across runs is appropriate, but it does not require each cancelled caller to remain attached. Existing leftover coverage lists the stale builder first and uses two slots, so it does not exercise this blocked acquisition. static trace: followed the uncancellable acquisition through the direct dispatch await.

  • Minimum fix: Await shared reconciliation through the run's cancellation-aware startupStep mechanism while allowing reconciliation itself to continue retaining and cleaning up leftover Machines.

Suggestions

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

S2: 🟢 Exercise the rebuilt image

The new live workflow verifies that changing packages publishes a new digest, but does not launch that digest and execute the added package. Extending the smoke test would strengthen end-to-end evidence that the rebuilt layer is usable. This is optional additional coverage; the existing tests already inspect layer contents and publication.

Score

The implementation has substantial focused coverage, but two recovery and cancellation defects remain in the new capacity lifecycle. The reported checks have no failures, with three still pending.

Score: 6/10


🤖 Review Details

  • Model: GPT-6 Astra
  • Time: 1m 7s
  • Tokens: 108,464 (106,755 in / 1,709 out)
  • Cost: $1.04

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 F3 F4 S2

🤖 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 5d41d3e

Addressed 1 AI review comment (IDs: 7206543993)

Addressed findings F3, F4

Summary of Changes

I fixed F3 and F4 and added a regression test for each. Each new test fails on the old code and passes with the fix.

F3: lost agent creates kept their slot too briefly

  • Fix: in fly/capacity.ts, an empty lookup after a lost create no longer frees the slot right away. The worker keeps looking the Machine up by name, and only an empty lookup at least 60 seconds after cleanup starts frees the slot. That matches the 60-second window build Machines already get. A failed lookup still frees nothing, and a Machine that turns up late is deleted before the slot is freed.
  • Tests: two new cases in test/flyMachinesCapacity.test.ts:
    • The create's lookups come back empty, then the original Machine appears. The slot stays held, the late Machine is deleted, and only then does the queued run create its own Machine.
    • Nothing ever appears. The slot is held for the whole window, then freed.
  • Sibling paths: the build-Machine path (settleLostBuilder) already had this window. The adopted-create path (resolveBuilder) relies on that earlier window, so neither needed changes.

F4: cancelling a run blocked during startup reconciliation

  • Fix: dispatchFlyRun in fly/dispatch.ts now waits for the shared leftover reconciliation through startupStep(signal, …). A cancelled run settles straight away with no Machine created. Reconciliation keeps going in the background, and the leftovers it found keep their slots until they are gone.
  • Test: one new case in test/flyDerivedImage.test.ts with PROPR_FLY_MACHINES_MAX=1 and the young leftover listed first. The cancelled run settles at once without touching any Machine. Once the young leftover is gone, the old one takes the slot and is deleted, then the next run starts.

Checks: the capacity suite (11) and the derived-image suite (39) pass. Typecheck and zero-warning lint on packages/core pass. I also updated the lost-create sentence in docs/docs/architecture/agent-runtime.md.

Independent discovery: none.

Review digest

Risk-tiered paths

  • High risk: none
  • Normal risk (2 files)
    • packages/core/src/agents/runtime/fly/capacity.ts (+13/−6)
    • packages/core/src/agents/runtime/fly/dispatch.ts (+4/−1)
  • Low risk (3 files)
    • docs/docs/architecture/agent-runtime.md (+1/−1)
    • test/flyDerivedImage.test.ts (+24/−0)
    • test/flyMachinesCapacity.test.ts (+64/−3)

Diff size: 5 files changed, +106/−11 lines


🤖 Implementation Details

  • Model: Claude Opus 5.5 (medium)
  • Requested By: @propr-ultrafix
  • Time: 15m 22s
  • Tokens: 1,771,039 (1,758,066 in / 12,973 out)
  • Cost: $1.05

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

I fixed F3 and F4 and added a regression test for each. Each new test fails on the old code and passes with the fix.

**F3: lost agent creates kept their slot too briefly**
- **Fix:** in `fly/capacity.ts`, an empty lookup after a lost create no longer frees the slot right away. The worker keeps looking the Machine up by name, and only an empty lookup at least 60 seconds after cleanup starts frees the slot. That matches the 60-second window build Machines already get. A failed lookup still frees nothing, and a Machine that turns up late is deleted before the slot is freed.
- **Tests:** two new cases in `test/flyMachinesCapacity.test.ts`:
  - The create's lookups come back empty, then the original Machine appears. The slot stays held, the late Machine is deleted, and only then does the queued run create its own Machine.
  - Nothing ever appears. The slot is held for the whole window, then freed.
- **Sibling paths:** the build-Machine path (`settleLostBuilder`) already had this window. The adopted-create path (`resolveBuilder`) relies on that earlier window, so neither needed changes.

**F4: cancelling a run blocked during startup reconciliation**
- **Fix:** `dispatchFlyRun` in `fly/dispatch.ts` now waits for the shared leftover reconciliation through `startupStep(signal, …)`. A cancelled run settles straight away with no Machine created. Reconciliation keeps going in the background, and the leftovers it found keep their slots until they are gone.
- **Test:** one new case in `test/flyDerivedImage.test.ts` with `PROPR_FLY_MACHINES_MAX=1` and the young leftover listed first. The cancelled run settles at once without touching any Machine. Once the young leftover is gone, the old one takes the slot and is deleted, then the next run starts.

**Checks:** the capacity suite (11) and the derived-image suite (39) pass. Typecheck and zero-warning lint on `packages/core` pass. I also updated the lost-create sentence in `docs/docs/architecture/agent-runtime.md`.

**Independent discovery:** none.

PR: #3825
Comment by: @propr-ultrafix (ID: 0)
Model: Claude Opus 5.5

ProPR-Agent: claude/claude-opus-5-5
@propr-dev

propr-dev Bot commented Nov 27, 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 27, 2026

Copy link
Copy Markdown
Contributor Author

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

Overall Evaluation

The PR restores derived Fly images with shared builds, registry reuse, fallback installation, and capacity accounting. The supplied code supports the intended approach, but live acceptance remains a material verification gap.

✅ Safe image publication — The worker verifies layer size, compressed digest, uncompressed digest, and the guest’s dpkg verification record before publishing.

✅ Careful capacity handling — Refused agent creates release their slot before rebuilding, avoiding a deadlock with PROPR_FLY_MACHINES_MAX=1. Unconfirmed builder cleanup retains capacity and schedules retries.

✅ Focused regression coverage — Added tests exercise concurrent reuse, deleted tags, fallback installation, delayed creates, cancellation, and cleanup failures.

This was a static review of the supplied diff and context; no commands were run. Current checks show 21 passed, two pending, and no failures.

Merge blockers

No merge blockers.

Suggestions

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

S3: 🟢 Complete live Fly acceptance

Run the updated fly-e2e.yml with agent_runtime=fly-machines and retain its results. The unit fixtures thoroughly exercise orchestration, but they cannot establish that Fly’s actual filesystem, registry authentication, and resulting image behave together as expected. The workflow now checks initial installation, reuse from a fresh process, rebuilding after a package change, and teardown. This is a verification follow-up, not a demonstrated code defect.

S4: 🟢 Bound the layer transfer

Consider passing the remaining build deadline through download() to scanFile() in packages/core/src/agents/runtime/fly/imageBuilder.ts. Currently, waitForBuild() observes the deadline, but subsequent layer reads do not receive it. An explicit transfer bound would make the documented build lifetime more predictable during slow API responses; this is optional operational hardening.

Score

The implementation has substantial targeted coverage and no verified merge blocker from static inspection. Live Fly acceptance is still needed to establish confidence in the central image-building path.

Score: 7/10


🤖 Review Details

  • Model: GPT-6 Astra
  • Time: 1m 27s
  • Tokens: 109,808 (107,949 in / 1,859 out)
  • Cost: $1.06

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

⚠️ Ultrafix stopped before reaching its goal. Requested goal: 8/10. Last score: 7/10. Stopped in cycle 3 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 27, 2026
@propr-dev propr-dev Bot changed the title 🔨 [3821 by Claude Opus 5.5] Fly Machines: bake runtime packages into a derived agent image ⚠️❼ [3821 by Claude Opus 5.5] Fly Machines: bake runtime packages into a derived agent image Nov 27, 2026
@propr-dev

propr-dev Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor Author

🔀 Resolved merge conflicts from 3758-epic-runtime-abstraction-sc0 into 3821/claude-opus-5-5-fly-machines-bake-runtime-20261126-2328-m2d in commit 588d8cb

Conflicting Files

  • .env.example
  • .github/workflows/fly-e2e.yml
  • docs/docs/architecture/agent-runtime.md
  • docs/docs/tutorials/setup-fly.md
  • packages/core/src/agents/runtime/fly/api.ts
  • packages/core/src/agents/runtime/fly/capacity.ts
  • packages/core/src/agents/runtime/flyMachinesRuntime.ts
  • test/flyMachinesCapacity.test.ts

Resolution Summary

I resolved all 8 conflicted files and no conflict markers remain anywhere. The core type-check and lint pass, and the five Fly suites (capacity, runtime, create request, runtime packages, derived image) pass 105 of 105, including the target branch's two new tests.

Background: this PR already carried an earlier version of the PROPR_FLY_MACHINES_MAX work. It had then reworked it for derived images: build Machines take slots, lost creates get a lookup window, and the runtime moved to dispatch.ts. Meanwhile #3823 landed on 3758-epic-runtime-abstraction-sc0 with three later changes: a stricter value check, deadlines on test waits, and a fix that frees the slot when Fly reports the Machine gone during deletion retries. So I kept the PR's structure throughout and ported those three changes onto it.

File What conflicted How I resolved it
fly/api.ts Both sides added gone, find and MachineCreateUnconfirmedError. The PR also added list, MachineNotFoundAfterCreateError, createRejected and an optional find. Took the PR version. It already does everything the target branch's version does, and the derived-image code needs the extra pieces.
fly/capacity.ts Both sides added this file. The target branch added a FlyMachineSlot class with the "gone during retries" fix; the PR has the lookup window (lostCreateWindowMs) and handles a missing find. Kept the PR's functions, because its runtime and dispatch.ts pass the slot's release around and don't use FlyMachineSlot. Added the stricter check (so 1e2 and 0x2 are rejected) and a new destroyFreeingSlot() that carries the fix: if a deletion fails but Fly confirms the Machine is gone, the slot is freed and retries stop.
flyMachinesRuntime.ts The target branch wired in FlyMachineSlot; the PR rewrote the code around dispatchFlyRun. Kept the PR version. Its destroy now calls destroyFreeingSlot, so the target branch's fix applies.
test/flyMachinesCapacity.test.ts Both sides added this file. The target branch added deadlines and descriptions to until(), more invalid values, and two new tests (a deletion answered with HTTP 404, and a Machine that vanishes while its deletion keeps failing). The PR added the lookup-window and Machines API tests. Merged both: the target branch's helpers and new tests, plus the PR's tests with descriptions added to their waits. Test resets now include lostCreateWindowMs, and the API test uses the static MachinesClient import.
.github/workflows/fly-e2e.yml Each side added a different check step in the same place: the PR's derived-image check and the target branch's queueing check. Kept both, with the queueing check first. The derived-image check ends by asserting that no Machines are left. If it ran first, the second run might still be using its Machine. The YAML parses.
.env.example Two wordings of the PROPR_FLY_MACHINES_MAX comment. Kept the PR's, which also counts build Machines.
docs/.../agent-runtime.md Two sections: the usage logging (and, on the PR side, the "Derived Fly images" section), and the capacity paragraphs. Kept the PR's text, which covers derived images and build Machines. Added the target branch's sentence on invalid values and its wording on freeing a slot when Fly reports the Machine destroyed or unknown during retries.
docs/.../setup-fly.md The Free Plan note. Kept the PR's note and added the target branch's points: a slot is freed only once the Machine is destroyed or gone, and the cap counts per worker.

The live Fly check in fly-e2e.yml was not run here, so the new step order hasn't been tried against a real Fly app.


🤖 Resolution Details

  • Model: Claude Opus 5.5
  • Time: 4m 58s

View Task Execution


System-triggered merge conflict resolution

@propr-dev propr-dev Bot changed the title ⚠️❼ [3821 by Claude Opus 5.5] Fly Machines: bake runtime packages into a derived agent image 🔨 [3821 by Claude Opus 5.5] Fly Machines: bake runtime packages into a derived agent image Nov 27, 2026
@integry

integry commented Nov 27, 2026

Copy link
Copy Markdown
Owner

#3823 (PROPR_FLY_MACHINES_MAX) is merged into the epic: please merge it in

#3823 merged into 3758-epic-runtime-abstraction-sc0 (ef801a9). This PR has its own copy of packages/core/src/agents/runtime/fly/capacity.ts and related api.ts changes, which conflict with it. Please:

  1. Merge the epic in and keep [3822 by Claude Opus 5.5] Fly Machines: PROPR_FLY_MACHINES_MAX concurrency cap that queues instead of failing at the org limit #3823's capacity code as the base.
    • Keep FlyMachineSlot, acquireFlyMachineSlot, releaseSlotWhenGone and releaseUndeletedFlyMachineSlot.
    • Keep MachinesApi.gone/find and MachineCreateUnconfirmedError.
    • Keep [3822 by Claude Opus 5.5] Fly Machines: PROPR_FLY_MACHINES_MAX concurrency cap that queues instead of failing at the org limit #3823's R1 fix: FlyMachineSlot.destroy frees the slot when the deletion fails but api.gone confirms the Machine is gone, 404 included.
    • Layer only what this PR needs on top:
      • builder Machines count against the cap;
      • a refused agent create frees its slot before rebuilding (your F1);
      • a late or unconfirmed builder or agent create keeps its slot (F3);
      • cancellation works during startup reconciliation (F4).
    • Don't keep two copies of the slot logic.
  2. Builder Machine deletion: take the same 404-or-gone rule as R1, so a builder Machine deleted outside ProPR can't hold a slot forever.
  3. Smoke workflow: keep [3822 by Claude Opus 5.5] Fly Machines: PROPR_FLY_MACHINES_MAX concurrency cap that queues instead of failing at the org limit #3823's cap mode and its webhook delivery check (it matches deliveries by issue number). Your derived-image checks run in the default Fly Machines run.

Once it's pushed, I'll run Fly Machines live (the default run, then cap mode) on the new head.

Automatically resolved merge conflicts after merging target branch into PR branch.
Resolved conflicts in:
- .env.example
- .github/workflows/fly-e2e.yml
- docs/docs/architecture/agent-runtime.md
- docs/docs/tutorials/setup-fly.md
- packages/core/src/agents/runtime/fly/api.ts
- packages/core/src/agents/runtime/fly/capacity.ts
- packages/core/src/agents/runtime/flyMachinesRuntime.ts
- test/flyMachinesCapacity.test.ts

PR: #3825
Model: Claude Opus 5.5
@propr-dev

propr-dev Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor Author

✅ Applied the requested follow-up changes in commit 56c74bc

Summary of Changes

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 [3822 by Claude Opus 5.5] Fly Machines: PROPR_FLY_MACHINES_MAX concurrency cap that queues instead of failing at the org limit #3823's wording.
  • R1: [3822 by Claude Opus 5.5] Fly Machines: PROPR_FLY_MACHINES_MAX concurrency cap that queues instead of failing at the org limit #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.

Review digest

Risk-tiered paths

  • High risk (1 file)
    • .github/workflows/fly-e2e.yml (+2/−1): CI or workflow file
  • Normal risk (5 files)
    • packages/core/src/agents/runtime/fly/api.ts (+3/−7)
    • packages/core/src/agents/runtime/fly/capacity.ts (+64/−14)
    • packages/core/src/agents/runtime/fly/dispatch.ts (+19/−40)
    • packages/core/src/agents/runtime/fly/imageBuilder.ts (+10/−9)
    • packages/core/src/agents/runtime/flyMachinesRuntime.ts (+6/−10)
  • Low risk (2 files)
    • docs/docs/architecture/agent-runtime.md (+1/−1)
    • test/flyDerivedImage.test.ts (+41/−3)

Diff size: 8 files changed, +146/−85 lines


🤖 Implementation Details

  • Model: Claude Opus 5.5 (medium)
  • Requested By: @integry
  • Time: 18m 21s
  • Tokens: 4,595,690 (4,571,757 in / 23,933 out)
  • Cost: $2.05

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: 7207255537✓

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
@integry

integry commented Nov 27, 2026

Copy link
Copy Markdown
Owner

My review of 56c74bc

The capacity merge looks right:

  • the agent slot is taken after image selection, so a run never holds a builder slot and an agent slot together;
  • a refused create frees its slot before selecting an image again;
  • the builder slot is freed in finally, or handed to the unresolved record;
  • the build is shared in-process, and one waiter cancelling doesn't affect the others;
  • the layer is re-verified on the worker, the tag is pushed after the blobs, and the tag covers the recipe, base digest and package list.

Please fix these four. They're failure modes that waste the Free Plan's 3 Machines or block runs for close to an hour:

R1: a builder that dies mid-build is waited out for the whole deadline

In imageBuilder.ts, waitForBuild treats a failed probe as "keep polling" and never checks whether the Machine still exists. If the wrapper dies after reporting building (an OOM kill during apt, a host failure, or an uncaught exception in wrapperBuild.ts build(): snapshot(), dpkg_installed() with check=True, the run_install Popen), auto_destroy removes the Machine. Every waiting run then blocks until bootTimeout plus the build deadline (about 45 minutes) before falling back, and the builder slot is held all that time.

  • Fix: after a few failed probes in a row, call api.gone(id) and fail fast when it's gone. Wrap the whole of build() in the wrapper so any exception writes build-error with a message.

R2: no deadline on the layer download or the push

Only waitForBuild gets deadline. download (up to 4 GiB in 256 KiB exec chunks) and pushDerived have no overall bound, and the builder and its slot stay held during the download. There's a second effect: another worker's startup search deletes builders older than buildDeadlineMs + removalWindowMs (derivedImage.ts), so it can delete a live builder mid-download.

  • Fix: pass the remaining deadline (AbortSignal.timeout) into download/scanFile. Give the push its own bound. Keep the leftover-age threshold above the real worst-case builder lifetime (build plus download).

R3: a build that fails the same way every time is retried every 10 minutes, forever

Every non-apt failure is handled the same way: back off for the fixed 10-minute failureBackoffMs, then build again. That includes build-error, a failed dpkg verification, and the size check below. Each retry starts a new builder Machine, which counts against PROPR_FLY_MACHINES_MAX and Fly's 3-Machine Free Plan limit.

  • Fix: back off exponentially per key (for example 10 min, doubling, capped at 24 h, reset when the list or base changes). Runs keep falling back to install-at-start in the meantime. Log once per backoff step, not on every run.

R4: the size check ignores dpkg path-exclude

if (rawBytes < verified.installedBytes) throw … compares the layer with apt's Installed-Size, which counts the full package contents. verify_layer honours path-exclude (docs, man pages and locales are excluded on slim Debian and Ubuntu images); this check doesn't. A package whose size is mostly docs or locales gives a layer smaller than Installed-Size, so the build fails every time and then loops (R3).

  • Fix: subtract the excluded paths' bytes, or drop the check, since the dpkg read-back already proves the files are present. Add a test with a package whose docs are excluded.

Nits (optional)

  • watchUntilGone (derivedImage.ts): a leftover builder that was young when found, but later passes maxAge without being destroyed, holds a slot for good. Move it to the stale path once it's old enough.
  • Two workers can build the same key at once. That costs Machines, not correctness: a recheck recovers. Re-resolving the tag just before creating a builder would narrow the window.

The default Fly Machines live run on 56c74bc is in progress. I'll run cap mode after these fixes.

@propr-dev

propr-dev Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor Author

✅ Applied the requested follow-up changes in commit b3d423a

Summary of Changes

I've fixed all four issues and both nits. The derived-image suite (50 tests, 8 of them new) and the other Fly suites pass: 116 tests in total. Typecheck and zero-warning lint on packages/core are clean. I also put the old code back for R1, R3 and R4 and confirmed their new tests fail on it; the R1 test hangs on the old code, as you described. The cap-mode live run is still yours to do.

R1: builder dies mid-build

  • Gone check: waitForBuild counts failed probes in a row. After 3 it calls api.gone(id) and fails the build straight away if the Machine is gone, so the run falls back without waiting out the deadline. If the gone lookup itself errors, polling just carries on.
  • Wrapper: build() in wrapperBuild.ts now wraps the whole build. Any exception (from snapshot(), dpkg_installed() or the Popen) writes build-error with its message. It writes build-failed only when apt actually ran and failed.

R2: download and push deadlines

  • Download: the result read and the layer download (scanFile) now get AbortSignal.timeout set to whatever is left of the build deadline.
  • Push: RegistryApi.upload/blob/push take an optional signal. pushDerived runs under a new pushTimeoutMs setting (30 min).
  • Signature change: to stay within the lint parameter limit, upload now takes { digest, size } and push takes { mediaType, body }.
  • Leftover age: the startup search now uses a new builderLifetimeMs: the build deadline (which now includes the download), plus the deletion window and the lost-create window, plus a 10-minute margin. That works out to PROPR_FLY_BOOT_TIMEOUT plus 57 minutes.

R3: exponential backoff

  • Schedule: a failed build backs off for 10 minutes, doubling after each further failure of the same build, up to 24 hours (new failureBackoffMaxMs setting).
  • Reset: a new base manifest or a changed package list starts again at 10 minutes, and a successful build clears the backoff.
  • When it's counted: each failure is counted once per shared build, however many runs were waiting on it, so concurrent runs can't push it up several steps. The warning is logged once per step, not once per run.
  • Unchanged: apt failures and failures where a build Machine's deletion can't be confirmed keep their existing handling. A registry error before the base manifest resolves keeps the fixed 10 minutes.

R4: size check

  • New field: the build Machine now reports layerBytes, the total size of the packages' regular files that are actually in the layer. It counts each inode once, because tar stores a hard link without data (git-core has many).
  • Check: the worker requires the uncompressed layer to be at least layerBytes. Anything path-exclude kept out isn't on disk, so it can't be counted, and the check no longer compares against apt's Installed-Size.
  • Tests:
    • a Python test with a 2 MiB Installed-Size package whose docs are excluded.
    • a hard-link test.
    • a worker-level test where the layer is smaller than Installed-Size and still gets pushed.

Nits

  • Ageing leftover: watchUntilGone now deletes a leftover that was young when found once it passes builderLifetimeMs, so it can't hold a slot for good.
  • Re-resolve: once a run holds the builder slot, buildLayer looks up the derived tag again just before the create. If another worker has pushed it by then, the run uses it and creates no build Machine.

I updated the "Derived Fly images" section of agent-runtime.md to match. Nothing visible changes, so there are no previews.

Review digest

Risk-tiered paths

  • High risk: none
  • Normal risk (4 files)
    • packages/core/src/agents/runtime/fly/derivedImage.ts (+61/−11)
    • packages/core/src/agents/runtime/fly/imageBuilder.ts (+60/−20)
    • packages/core/src/agents/runtime/fly/registry.ts (+17/−16)
    • packages/core/src/agents/runtime/fly/wrapperBuild.ts (+31/−8)
  • Low risk (2 files)
    • docs/docs/architecture/agent-runtime.md (+5/−5)
    • test/flyDerivedImage.test.ts (+221/−12)

Diff size: 6 files changed, +395/−72 lines


🤖 Implementation Details

  • Model: Claude Opus 5.5 (medium)
  • Requested By: @integry
  • Time: 13m 36s
  • Tokens: 3,726,266 (3,687,133 in / 39,133 out)
  • Cost: $2.15

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: 7207678716✓

I've fixed all four issues and both nits. The derived-image suite (50 tests, 8 of them new) and the other Fly suites pass: 116 tests in total. Typecheck and zero-warning lint on `packages/core` are clean. I also put the old code back for R1, R3 and R4 and confirmed their new tests fail on it; the R1 test hangs on the old code, as you described. The cap-mode live run is still yours to do.

**R1: builder dies mid-build**
- **Gone check:** `waitForBuild` counts failed probes in a row. After 3 it calls `api.gone(id)` and fails the build straight away if the Machine is gone, so the run falls back without waiting out the deadline. If the `gone` lookup itself errors, polling just carries on.
- **Wrapper:** `build()` in `wrapperBuild.ts` now wraps the whole build. Any exception (from `snapshot()`, `dpkg_installed()` or the Popen) writes `build-error` with its message. It writes `build-failed` only when apt actually ran and failed.

**R2: download and push deadlines**
- **Download:** the result read and the layer download (`scanFile`) now get `AbortSignal.timeout` set to whatever is left of the build deadline.
- **Push:** `RegistryApi.upload`/`blob`/`push` take an optional signal. `pushDerived` runs under a new `pushTimeoutMs` setting (30 min).
- **Signature change:** to stay within the lint parameter limit, `upload` now takes `{ digest, size }` and `push` takes `{ mediaType, body }`.
- **Leftover age:** the startup search now uses a new `builderLifetimeMs`: the build deadline (which now includes the download), plus the deletion window and the lost-create window, plus a 10-minute margin. That works out to `PROPR_FLY_BOOT_TIMEOUT` plus 57 minutes.

**R3: exponential backoff**
- **Schedule:** a failed build backs off for 10 minutes, doubling after each further failure of the same build, up to 24 hours (new `failureBackoffMaxMs` setting).
- **Reset:** a new base manifest or a changed package list starts again at 10 minutes, and a successful build clears the backoff.
- **When it's counted:** each failure is counted once per shared build, however many runs were waiting on it, so concurrent runs can't push it up several steps. The warning is logged once per step, not once per run.
- **Unchanged:** apt failures and failures where a build Machine's deletion can't be confirmed keep their existing handling. A registry error before the base manifest resolves keeps the fixed 10 minutes.

**R4: size check**
- **New field:** the build Machine now reports `layerBytes`, the total size of the packages' regular files that are actually in the layer. It counts each inode once, because tar stores a hard link without data (git-core has many).
- **Check:** the worker requires the uncompressed layer to be at least `layerBytes`. Anything `path-exclude` kept out isn't on disk, so it can't be counted, and the check no longer compares against apt's Installed-Size.
- **Tests:**
  - a Python test with a 2 MiB Installed-Size package whose docs are excluded.
  - a hard-link test.
  - a worker-level test where the layer is smaller than Installed-Size and still gets pushed.

**Nits**
- **Ageing leftover:** `watchUntilGone` now deletes a leftover that was young when found once it passes `builderLifetimeMs`, so it can't hold a slot for good.
- **Re-resolve:** once a run holds the builder slot, `buildLayer` looks up the derived tag again just before the create. If another worker has pushed it by then, the run uses it and creates no build Machine.

I updated the "Derived Fly images" section of `agent-runtime.md` to match. Nothing visible changes, so there are no previews.

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

ProPR-Agent: claude/claude-opus-5-5
@propr-dev propr-dev Bot changed the title 🔨 [3821 by Claude Opus 5.5] Fly Machines: bake runtime packages into a derived agent image ⚠️❼ [3821 by Claude Opus 5.5] Fly Machines: bake runtime packages into a derived agent image Nov 27, 2026
@integry

integry commented Nov 27, 2026

Copy link
Copy Markdown
Owner

Live on f095a52: the default mode passes; cap mode fails one log check

Default Fly Machines mode passes: https://github.com/integry/propr/actions/runs/45980220361 ✅

  • The first run built registry.fly.io/propr-e2e-agents-45980220361-1@sha256:9bdc985b9468….
  • A fresh process with the same list reused that digest with 0 build Machines.
  • A changed list built exactly 1 new digest (…336edfe2af84…).
  • No Machines were left in the agent app, and no token fragments appeared in the log.

Cap mode (PROPR_FLY_MACHINES_MAX=1) fails: https://github.com/integry/propr/actions/runs/45982542980 ❌, in "Verify the linked PR, its runtime package and its agent execution":

Idle wake webhookRecovery.redelivered=1
Fixture file line 2: FIGlet Copyright (C) 1991-2012 …
##[error]Missing 'Installed agent runtime packages in a derived Fly Machine image' log after the idle stop

The packages did work: the agent's line 2 is the figlet banner, and the instance's PROPR_RUNTIME_PACKAGES profile says "appliedBy":"Installed in a derived Fly Machine image" with a buildId. But the per-run install log line the step looks for isn't in the logs it collected. Please find out which it is and fix it:

  1. The check misses the line. In cap mode the first issue's run is delayed by the queue and the idle stop or wake (webhookRecovery.redelivered=1), so the line may fall outside the window or source the step reads (it's in the default run). If so, read it from wherever the derived-image build step already finds it, or match it to the run by run/task id, not by timing.
  2. Or the code skips the line. On a run that waited for a slot, or a run started after an idle wake, does the agent launch on the derived image without logging "Installed agent runtime packages in a derived Fly Machine image"? If so, log it on every launch that uses the derived image. The check is part of the acceptance, so it shouldn't be weakened to make it pass.

Also, for cap mode, put in the step summary which image the queued second run launched with (it should be the same derived digest, with no second build Machine).

I'll run cap mode again once it's pushed. The default mode doesn't need to run again unless the runtime code changes.

@propr-dev propr-dev Bot changed the title ✅❽ [3821 by Claude Opus 5.5] Fly Machines: bake runtime packages into a derived agent image 🔨 [3821 by Claude Opus 5.5] Fly Machines: bake runtime packages into a derived agent image Nov 27, 2026
@propr-dev

propr-dev Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor Author

✅ Applied the requested follow-up changes in commit b434ca9

Summary of Changes

The failing check was at fault, not the runtime. Issue #80's agent did launch from the derived image. I fixed the check without weakening it, and the cap-mode summary now says which image the queued run used.

What happened in 45982542980: the step searched only flyctl logs --no-tail, which keeps just the most recent lines. When it ran at 10:44:22, the oldest line it had was from 10:43:16. Both runs had built and started around 10:41, and issue #81 (the queued one) finished at 10:43:18, before #80. So the build line had already dropped out of the buffer when the step looked. The worker process was the same one throughout (pid 20), so it wasn't a restart either.

What I found in the code: there was a real gap, though it isn't what failed this run. The build line is logged once per shared build, under whichever run started it. In cap mode that can be #81's run. A run that reuses the worker's cached image logged nothing at all, so the queued run's image couldn't be shown.

Changes:

  • Runtime (fly/derivedImage.ts): every agent Machine created from a derived image now logs Launched the agent Fly Machine from the derived image, with run, machine, image and the package-list digest. That covers a run that built the image, one that found the registry tag, one that used the cache, and the retry after Fly refuses a create. I added a sentence about it to agent-runtime.md.
  • Workflow, "Observe idle stop…": the full log stream ($OUT/app-logs.jsonl) now starts at the idle stop in every mode, not only MCP or cap mode.
  • Workflow, "Verify the linked PR…":
    • It reads the stream plus the --no-tail buffer, filtered to after the idle stop.
    • It still requires the Installed agent runtime packages in a derived Fly Machine image line, with the same digest, count and registry.fly.io/$AGENT_APP@sha256: checks.
    • It now also requires a launch line whose run name matches issue-$ISSUE- (the format is <agent>-issue-<n>-<task id>), with the same image as the build.
  • Workflow, cap step:
    • It requires a launch line for the run of $ISSUE2 with the same DERIVED_IMAGE.
    • It requires exactly one build line since the idle stop.
    • The step summary now shows the queued run's name, its Machine, the image it launched from, and the build count.

Testing:

  • I added a test where one run builds and a second run reuses the cached image; both log a launch line with the same image and the build is logged once. The derived-image, capacity and Fly runtime suites pass (117 tests).
  • Core typecheck and zero-warning lint pass.
  • The three changed steps parse with bash -n.
  • I ran the new jq selection on logs shaped like this run's. The old query comes back empty, and the new one finds the build and matches the launch line to issue-80 (and not to issue-8).
  • I couldn't confirm the exact run-name format from real logs, because the failure dump redacts run as <long>. The issue-<n> match is based on the code (buildClaudeContainerName). If your cap run fails with "No 'Launched the agent Fly Machine…' record for the run of …", that match is the place to look.

Because this touches runtime code (one new log line, no behaviour change), you may want to run default mode once more along with cap mode. Default mode now also runs the new launch-line check for its first issue.

Review digest

Risk-tiered paths

  • High risk (1 file)
    • .github/workflows/fly-e2e.yml (+30/−7): CI or workflow file
  • Normal risk (1 file)
    • packages/core/src/agents/runtime/fly/derivedImage.ts (+13/−2)
  • Low risk (2 files)
    • docs/docs/architecture/agent-runtime.md (+1/−1)
    • test/flyDerivedImage.test.ts (+21/−0)

Diff size: 4 files changed, +65/−10 lines


🤖 Implementation Details

  • Model: Claude Opus 5.5 (medium)
  • Requested By: @integry
  • Time: 10m 53s
  • Tokens: 3,881,718 (3,860,775 in / 20,943 out)
  • Cost: $1.80

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: 7216310644✓

The failing check was at fault, not the runtime. Issue #80's agent did launch from the derived image. I fixed the check without weakening it, and the cap-mode summary now says which image the queued run used.

**What happened in 45982542980:** the step searched only `flyctl logs --no-tail`, which keeps just the most recent lines. When it ran at 10:44:22, the oldest line it had was from 10:43:16. Both runs had built and started around 10:41, and issue #81 (the queued one) finished at 10:43:18, before #80. So the build line had already dropped out of the buffer when the step looked. The worker process was the same one throughout (pid 20), so it wasn't a restart either.

**What I found in the code:** there was a real gap, though it isn't what failed this run. The build line is logged once per shared build, under whichever run started it. In cap mode that can be #81's run. A run that reuses the worker's cached image logged nothing at all, so the queued run's image couldn't be shown.

**Changes:**
- **Runtime (`fly/derivedImage.ts`):** every agent Machine created from a derived image now logs `Launched the agent Fly Machine from the derived image`, with `run`, `machine`, `image` and the package-list digest. That covers a run that built the image, one that found the registry tag, one that used the cache, and the retry after Fly refuses a create. I added a sentence about it to `agent-runtime.md`.
- **Workflow, "Observe idle stop…":** the full log stream (`$OUT/app-logs.jsonl`) now starts at the idle stop in every mode, not only MCP or cap mode.
- **Workflow, "Verify the linked PR…":**
  - It reads the stream plus the `--no-tail` buffer, filtered to after the idle stop.
  - It still requires the `Installed agent runtime packages in a derived Fly Machine image` line, with the same digest, count and `registry.fly.io/$AGENT_APP@sha256:` checks.
  - It now also requires a launch line whose run name matches `issue-$ISSUE-` (the format is `<agent>-issue-<n>-<task id>`), with the same image as the build.
- **Workflow, cap step:**
  - It requires a launch line for the run of `$ISSUE2` with the same `DERIVED_IMAGE`.
  - It requires exactly one build line since the idle stop.
  - The step summary now shows the queued run's name, its Machine, the image it launched from, and the build count.

**Testing:**
- I added a test where one run builds and a second run reuses the cached image; both log a launch line with the same image and the build is logged once. The derived-image, capacity and Fly runtime suites pass (117 tests).
- Core typecheck and zero-warning lint pass.
- The three changed steps parse with `bash -n`.
- I ran the new jq selection on logs shaped like this run's. The old query comes back empty, and the new one finds the build and matches the launch line to `issue-80` (and not to `issue-8`).
- I couldn't confirm the exact run-name format from real logs, because the failure dump redacts `run` as `<long>`. The `issue-<n>` match is based on the code (`buildClaudeContainerName`). If your cap run fails with "No 'Launched the agent Fly Machine…' record for the run of …", that match is the place to look.

Because this touches runtime code (one new log line, no behaviour change), you may want to run default mode once more along with cap mode. Default mode now also runs the new launch-line check for its first issue.

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

ProPR-Agent: claude/claude-opus-5-5
@propr-dev propr-dev Bot changed the title 🔨 [3821 by Claude Opus 5.5] Fly Machines: bake runtime packages into a derived agent image ✅❽ [3821 by Claude Opus 5.5] Fly Machines: bake runtime packages into a derived agent image Nov 27, 2026
@integry

integry commented Nov 27, 2026

Copy link
Copy Markdown
Owner

Cap mode on b434ca9: the queued run hit Fly's machine limit (HTTP 422) even with PROPR_FLY_MACHINES_MAX=1

https://github.com/integry/propr/actions/runs/45990086071. The first issue (#88) built the derived image (…@sha256:a767e721cce4…) and opened its PR at 11:38:56. The queued issue (#89) failed at 11:38:51:

❌ AI processing failed before producing publishable work.
System Error: Fly Machines API POST returned HTTP 422: Your organization has reached its machine limit.

The step then waited out its timeout: "No unique linked PR for the queued run integry/propr-fly-fixture#89".

The likely cause: the queued run created its Machine the moment the slot was freed, and Fly still counted a Machine that was on its way out. That would be the first run's agent Machine (deletion returned but not yet removed from the org count), or this PR's builder Machine, if its slot is freed when the build finishes rather than when Fly confirms it's gone. The ProPR Machine plus that one plus the new one is 4 > 3. #3823's cap runs passed without a builder, which points at the builder.

Fixes (all three):

  1. The builder slot: free it only once api.gone(builder) is true, as for agent Machines, never at build exit or download end.
  2. Treat a 422 "machine limit" on create as a capacity wait, not a run failure. Keep the run's slot, back off (e.g. 5 s, 10 s, 20 s … up to about 5 minutes in total), and retry the same create (the same launch name, so it stays idempotent). Log Fly organization machine limit reached; retrying create with the attempt number. Fail the run only after the bound, with a clear message. This also covers Machines outside ProPR's view (another worker, or a deletion Fly hasn't finished).
  3. Diagnostics: on a 422, log the agent app's Machine list (id, state, name; no env), so the next failure shows what was counted.

Tests: a create that gets a 422 twice and then succeeds keeps one slot and launches once. A builder whose exit comes before gone keeps its slot until gone. After the bound, the run fails with the machine-limit message.

The fix for the earlier cap-mode log check worked: the derived image was found and the install was logged. I'll rerun cap mode after this.

@propr-dev propr-dev Bot changed the title ✅❽ [3821 by Claude Opus 5.5] Fly Machines: bake runtime packages into a derived agent image 🔨 [3821 by Claude Opus 5.5] Fly Machines: bake runtime packages into a derived agent image Nov 27, 2026
@propr-dev

propr-dev Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor Author

✅ Applied the requested follow-up changes in commit 142907c

Summary of Changes

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.

Review digest

Risk-tiered paths

  • High risk: none
  • Normal risk (3 files)
    • packages/core/src/agents/runtime/fly/derivedImage.ts (+11/−4)
    • packages/core/src/agents/runtime/fly/imageBuilder.ts (+21/−10)
    • packages/core/src/agents/runtime/fly/machineLimit.ts (added, +70/−0)
  • Low risk (4 files)
    • docs/docs/architecture/agent-runtime.md (+2/−2)
    • docs/docs/tutorials/setup-fly.md (+1/−1)
    • test/flyDerivedImage.test.ts (+38/−3)
    • test/flyMachinesCapacity.test.ts (+59/−1)

Diff size: 7 files changed, +202/−21 lines


🤖 Implementation Details

  • Model: Claude Opus 5.5 (medium)
  • Requested By: @integry
  • Time: 13m 14s
  • Tokens: 3,405,227 (3,384,575 in / 20,652 out)
  • Cost: $1.64

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: 7218159098✓

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
@propr-dev propr-dev Bot changed the title 🔨 [3821 by Claude Opus 5.5] Fly Machines: bake runtime packages into a derived agent image ✅❽ [3821 by Claude Opus 5.5] Fly Machines: bake runtime packages into a derived agent image Nov 27, 2026
@integry

integry commented Nov 27, 2026

Copy link
Copy Markdown
Owner

Cap mode on 142907c: the 422 retry works, but the check rejects it, and we can't yet see what Fly counted

https://github.com/integry/propr/actions/runs/46003305762. Both runs finished: the queued issue #96 opened PR #97 at 13:14:52, and the first issue #95 opened PR #98 at 13:15:49. So the new retry on HTTP 422 recovered. The step failed only because its check rejects any log line matching "machine limit":

##[error]A run hit Fly's organization machine limit (HTTP 422) despite PROPR_FLY_MACHINES_MAX=1

With PROPR_FLY_MACHINES_MAX=1, ProPR holds at most 2 Machines (its own plus one agent or builder slot). So a 422 means Fly still counted a Machine that ProPR already treated as gone: a destroyed one Fly hadn't removed from the org count yet, or a builder that auto_destroy hadn't finished. That's Fly's eventual consistency. The retry is the right answer to it, but we should see it and limit it.

Please:

  1. Show the diagnostic: print the logged Machine list from the 422 record (id, state, name) in the step output and the step summary. The workflow only has it in $OUT/app-logs.jsonl, so nobody can see what Fly counted. Upload app-logs.jsonl as a short-lived artifact (1 day) after redacting tokens with redact_fly_tokens.
  2. Make the check precise: fail when a run failed with the machine-limit error, or when retries ran past a bound (say more than 60 s in total, or more than 3 attempts). A retried 422 that then succeeds is a warning (::warning::) with the Machine list. It's not an error.
  3. Free slots later if needed: if the list shows a Machine in destroyed (or destroying) state still being counted, gone should treat destroying as not gone. A short settle delay (for example 2 s) after gone before freeing the slot would remove most 422s without the retry having to absorb them. Decide from what the list shows, and say what you found.

I'll run cap mode again after this.

@propr-dev propr-dev Bot changed the title ✅❽ [3821 by Claude Opus 5.5] Fly Machines: bake runtime packages into a derived agent image 🔨 [3821 by Claude Opus 5.5] Fly Machines: bake runtime packages into a derived agent image Nov 27, 2026
@propr-dev

propr-dev Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor Author

✅ Applied the requested follow-up changes in commit 1045708

Summary of Changes

I've made changes 1 and 2. For change 3, I didn't change when slots are freed, because I still couldn't see what Fly counted. The record from run 46003305762 only existed in $OUT/app-logs.jsonl, and the job log has only the step's error line. Also, Fly's default Machine list leaves out destroyed Machines, so that record may not have shown the cause anyway. The Fly suites, typecheck and zero-warning lint all pass. I ran the new report script against made-up logs for each case, but not in the real workflow, and actionlint isn't available here.

1. Showing the diagnostic

  • Destroyed Machines are now listed: on each 422, the worker lists the agent app's Machines with include_deleted=true, so a Machine Fly destroyed but still counts shows up. Each one is still only id, state and name.
  • Each retried create logs how it ended: either … create accepted after retries or … create given up, with attempts and waitedMs (time since the first refusal).
  • Output: a new script, .github/fly-e2e/machine-limit-report.sh, prints every Machine list in the step output and as a table in the step summary. It also runs when the queued run opens no PR, so a failed run's list is shown before the step fails.
  • Artifact: a new always() step runs app-logs.jsonl through redact_fly_tokens and uploads it as fly-e2e-worker-log-<attempt> with retention-days: 1. Only the redacted copy is uploaded. I also replace GitHub token patterns (gh?_…, github_pat_…), since the artifact can be downloaded from a public repo. If a Fly token fragment turns up, the copy is still uploaded and that step fails.

2. A precise check

  • It fails when:
    • a create was given up.
    • a run failed with Fly's raw 422 (any line mentioning "machine limit" that isn't one of the new records).
    • a create was refused but logged no outcome.
    • an accepted create needed more than 3 retries or more than 60 s.
  • It warns (::warning::, with the last Machine list) when a create was retried and then accepted within that bound.

The tests now also check that destroyed Machines are requested, what the logged Machine list contains, and that exactly one outcome record is logged on success and when the bound is reached. The docs describe the new records.

3. What I found

  • destroying already counts as not gone. MachinesClient.gone returns true only for destroyed or a 404, so no change was needed there.
  • A 2 s settle delay would apply only to builders. Builder slots are the only ones freed after gone. An agent Machine's slot is still freed as soon as its DELETE returns, without waiting for gone.
  • My guess at the cause: an agent Machine being torn down, not a builder. The queued feat(ui): Add side menu navigation #96 finished first, so #95's agent create likely came right after feat(ui): Add side menu navigation #96's Machine was deleted. I can't confirm that from the logs I had.

Decision for you: the next cap-mode run will show what Fly counted. If it lists the other run's agent Machine (destroying, or destroyed but still counted), the fix is to free agent slots on gone plus a short settle delay, not the delay on builders alone. If it lists a propr-build-* Machine in destroyed, a settle delay after the builder's gone is enough. Tell me which and I'll add it.

Review digest

Risk-tiered paths

  • High risk (1 file)
    • .github/workflows/fly-e2e.yml (+40/−7): CI or workflow file
  • Normal risk (3 files)
    • .github/fly-e2e/machine-limit-report.sh (added, +81/−0)
    • packages/core/src/agents/runtime/fly/api.ts (+4/−3)
    • packages/core/src/agents/runtime/fly/machineLimit.ts (+21/−6)
  • Low risk (2 files)
    • docs/docs/architecture/agent-runtime.md (+1/−1)
    • test/flyMachinesCapacity.test.ts (+34/−5)

Diff size: 6 files changed, +181/−22 lines


🤖 Implementation Details

  • Model: Claude Opus 5.5 (medium)
  • Requested By: @integry
  • Time: 12m 49s
  • Tokens: 2,762,968 (2,739,437 in / 23,531 out)
  • Cost: $1.49

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: 7219338238✓

I've made changes 1 and 2. For change 3, I didn't change when slots are freed, because I still couldn't see what Fly counted. The record from run 46003305762 only existed in `$OUT/app-logs.jsonl`, and the job log has only the step's error line. Also, Fly's default Machine list leaves out destroyed Machines, so that record may not have shown the cause anyway. The Fly suites, typecheck and zero-warning lint all pass. I ran the new report script against made-up logs for each case, but not in the real workflow, and actionlint isn't available here.

**1. Showing the diagnostic**
- **Destroyed Machines are now listed:** on each 422, the worker lists the agent app's Machines with `include_deleted=true`, so a Machine Fly destroyed but still counts shows up. Each one is still only `id`, `state` and `name`.
- **Each retried create logs how it ended:** either `… create accepted after retries` or `… create given up`, with `attempts` and `waitedMs` (time since the first refusal).
- **Output:** a new script, `.github/fly-e2e/machine-limit-report.sh`, prints every Machine list in the step output and as a table in the step summary. It also runs when the queued run opens no PR, so a failed run's list is shown before the step fails.
- **Artifact:** a new `always()` step runs `app-logs.jsonl` through `redact_fly_tokens` and uploads it as `fly-e2e-worker-log-<attempt>` with `retention-days: 1`. Only the redacted copy is uploaded. I also replace GitHub token patterns (`gh?_…`, `github_pat_…`), since the artifact can be downloaded from a public repo. If a Fly token fragment turns up, the copy is still uploaded and that step fails.

**2. A precise check**
- **It fails when:**
  - a create was given up.
  - a run failed with Fly's raw 422 (any line mentioning "machine limit" that isn't one of the new records).
  - a create was refused but logged no outcome.
  - an accepted create needed more than 3 retries or more than 60 s.
- **It warns** (`::warning::`, with the last Machine list) when a create was retried and then accepted within that bound.

The tests now also check that destroyed Machines are requested, what the logged Machine list contains, and that exactly one outcome record is logged on success and when the bound is reached. The docs describe the new records.

**3. What I found**
- **`destroying` already counts as not gone.** `MachinesClient.gone` returns true only for `destroyed` or a 404, so no change was needed there.
- **A 2 s settle delay would apply only to builders.** Builder slots are the only ones freed after `gone`. An agent Machine's slot is still freed as soon as its DELETE returns, without waiting for `gone`.
- **My guess at the cause:** an agent Machine being torn down, not a builder. The queued #96 finished first, so #95's agent create likely came right after #96's Machine was deleted. I can't confirm that from the logs I had.

**Decision for you:** the next cap-mode run will show what Fly counted. If it lists the other run's agent Machine (`destroying`, or `destroyed` but still counted), the fix is to free agent slots on `gone` plus a short settle delay, not the delay on builders alone. If it lists a `propr-build-*` Machine in `destroyed`, a settle delay after the builder's `gone` is enough. Tell me which and I'll add it.

PR: #3825
Comment by: @integry (ID: 7219338238)
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 derived Fly images with shared builds, registry reuse, fallback installation, and builder capacity accounting. It is merge-ready within the reviewed scope, conditional on the pending checks completing successfully.

✅ Capacity coordination — Image selection precedes agent-slot acquisition, and a refused derived-image create releases its slot before rebuilding, avoiding a deadlock with PROPR_FLY_MACHINES_MAX=1.

✅ Builder cleanup — Builder deletion is confirmed through api.gone; unresolved builders retain their slots and receive background reconciliation.

✅ Image verification — Publication follows package-file verification and worker-side checks of the downloaded layer’s size, compressed digest, and uncompressed digest.

This was a static review of the supplied diff and surrounding context. No commands were run. The supplied current-head status reports 19 passed checks, four pending, and no failures.

Merge blockers

No merge blockers.

Suggestions

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

S7: 🟢 Exercise diagnostic reporting independently

Add small fixture-based tests for .github/fly-e2e/machine-limit-report.sh, covering recovered retries, exhausted retries, missing outcomes, and incomplete log records. Its early success condition checks only Machine-list and unknown-record counts, so outcome-only records deserve explicit coverage. This would improve confidence in the diagnostic workflow; it does not establish a production runtime blocker.

S8: 🟢 Refresh the smoke-test description

The “Nightly smoke fixture” paragraph in docs/docs/tutorials/setup-fly.md still describes the expected Fly install message as … at Fly Machine start. The workflow now requires the derived-image build message and checks image reuse. Updating that remaining paragraph would make the operational documentation consistent; the implemented workflow already performs the stronger checks.

Score

The implementation addresses the core objective and includes substantial coverage of failure, cleanup, and concurrency paths. No merge-blocking defect was established from the supplied code; final readiness remains conditional on the pending checks.

Score: 8/10


🤖 Review Details

  • Model: GPT-6 Astra
  • Time: 1m 3s
  • Tokens: 125,450 (124,153 in / 1,297 out)
  • Cost: $1.20

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 S7 S8

🤖 Review by ProPR

@propr-dev propr-dev Bot changed the title 🔨 [3821 by Claude Opus 5.5] Fly Machines: bake runtime packages into a derived agent image ✅❽ [3821 by Claude Opus 5.5] Fly Machines: bake runtime packages into a derived agent image Nov 27, 2026

integry commented Nov 27, 2026

Copy link
Copy Markdown
Owner

/ultrafix goal=8 max=3

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

propr-dev Bot commented Nov 27, 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 changed the title ✅❽ [3821 by Claude Opus 5.5] Fly Machines: bake runtime packages into a derived agent image 🔨 [3821 by Claude Opus 5.5] Fly Machines: bake runtime packages into a derived agent image Nov 27, 2026
@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 derived Fly images keyed by base manifest and package list, with shared builds, start-time fallback, and capacity accounting. Based on the supplied diff and surrounding context, it is merge-ready within the reviewed scope.

✅ Safe build teardown — Build slots remain held until deletion is confirmed; unresolved creates and deletions retain cleanup obligations.

✅ Verified image transfer — The wrapper checks package-file coverage, and the worker validates compressed size, digest, and uncompressed diff ID before publishing.

✅ Focused regression coverage — Added tests exercise shared builds, cancellation, missing cached images, lost creates, and capacity retention.

The authoritative checks report 24 passed, zero failed, and zero pending. This was a static review; no commands or live Fly tests were run.

Merge blockers

No merge blockers.

Suggestions

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

S9: 🟢 Exercise multi-chunk registry uploads

The registry test named “uploads in chunks” supplies a small layer that exercises only one PATCH. An additional fixture exceeding UPLOAD_CHUNK would verify successive content ranges, updated upload locations, and file offsets. This is optional coverage; the supplied implementation does not demonstrate an upload defect.

S10: 🟢 Record live acceptance evidence

Attach results from both the ordinary Fly Machines workflow and its capacity mode when available. These would complement the supplied unit coverage by exercising actual registry authentication, image application, and Fly deletion visibility. No failure in those external interactions is established by this review.

Score

The implementation addresses the objective with substantial recovery and regression coverage, and all reported current-head checks pass. Static review found no demonstrated merge blocker.

Score: 8/10


🤖 Review Details

  • Model: GPT-6 Astra
  • Time: 1m 11s
  • Tokens: 123,714 (122,540 in / 1,174 out)
  • Cost: $1.17

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 S9 S10

🤖 Review by ProPR

@propr-dev propr-dev Bot removed the ultrafix label Nov 27, 2026
@propr-dev propr-dev Bot changed the title 🔨 [3821 by Claude Opus 5.5] Fly Machines: bake runtime packages into a derived agent image ✅❽ [3821 by Claude Opus 5.5] Fly Machines: bake runtime packages into a derived agent image Nov 27, 2026
@integry
integry merged commit a1d0200 into 3758-epic-runtime-abstraction-sc0 Nov 27, 2026
49 checks passed
@propr-dev propr-dev Bot changed the title ✅❽ [3821 by Claude Opus 5.5] Fly Machines: bake runtime packages into a derived agent image [3821 by Claude Opus 5.5] Fly Machines: bake runtime packages into a derived agent image Nov 27, 2026
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