Skip to content

atelet: start image prep before the snapshot manifest fetch - #4024

Open
yuekui2 wants to merge 2 commits into
agent-substrate:mainfrom
yuekui2:ipp-upstream/1-prep-start
Open

yuekui2 wants to merge 2 commits into
agent-substrate:mainfrom
yuekui2:ipp-upstream/1-prep-start

Conversation

@yuekui2

@yuekui2 yuekui2 commented Nov 20, 2026 •

Copy link
Copy Markdown

Part of #4023.

Restore fetched the snapshot manifest before it started the sandbox asset and OCI bundle prep. The prep reads only the request, so it now starts first and overlaps the manifest fetch. Only the snapshot download needs the manifest. A manifest failure cancels the prep leg and waits for it to return. Asset fetches and image pulls it started keep running detached, as they do when the snapshot download fails.

Testing: go test -race ./cmd/atelet/.... TestRestoreManifestFailureStopsPrep checks that the manifest fetch overlaps the prep, and that a manifest failure returns while the asset fetch is still running. The manifest-failure tests join the detached asset fetch before cleanup.

I used an AI agent to port this commit from our fork, address review comments, and draft this description. I reviewed the code and commit message.

The sandbox asset and OCI bundle prep reads only the request, so Restore
now starts it before fetching the snapshot manifest. Only the snapshot
download needs the manifest. A manifest failure cancels the prep and
waits for it before returning.

A failed restore can leave a detached asset fetch running, so the tests
that fail on the manifest join it before cleanup.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Just leaving some questions.

Comment thread cmd/atelet/main.go
if sandboxRec, err = unmarshalSandboxRecord(manifest); err != nil {
return nil, fmt.Errorf("while unmarshalling sandbox record: %w", err)
dManifest = time.Since(tManifest)
stopPrep()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

On a manifest failure, stopPrep unblocks the caller, but filecache runs the flight on WithoutCancel, so the asset download keeps going after Restore returns. Is that intended? Have you considered starting prep only after readLocalSnapshot succeeds, or in parallel with just the remote fetch, so a never-uploaded snapshot doesn't kick off node work? If it's fine as is, maybe drop 'waits for it' from the description.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Intended. The flights are shared and detached so they warm the cache for the next caller. The same already happens when the snapshot download fails. A never-uploaded snapshot fails on the remote fetch, so starting prep after readLocalSnapshot or alongside only the remote fetch still starts it. Only waiting for the manifest avoids it, and that undoes the change. The leftover work is one deduplicated asset fetch and one image pull under pullTimeout. I fixed the wording in the commit message, the stopPrep comment and the description.

Spec: &ateletpb.WorkloadSpec{},
Snapshot: lifecycleSnapshot(actorUID, snapshotName, 1, ateletpb.SnapshotFidelity_SNAPSHOT_FIDELITY_MEMORY),
})
waitAssetFetch(t, s, rec)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Could we get a test where the manifest fetch blocks or fails while prep is in flight? Right now nothing checks that the overlap actually happens or that stopPrep cancels the unpack.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Added TestRestoreManifestFailureStopsPrep. The manifest fetch answers NotFound only once the asset fetch has started, and the asset fetch blocks until the test releases it. Restore must return while it is still blocked. Without the overlap the manifest fetch never answers and the test times out.

Comment thread cmd/atelet/main.go Outdated
Comment on lines +1782 to +1789
// stopPrep cancels the prep leg after a manifest failure and waits for it,
// so its phases are reported as cut short.
stopPrep := func() {
cancelPrep()
if gErr := g.Wait(); gErr != nil {
dAssets, dBundles = assetsAfterCollateral(prepFailedPhase, dAssets), 0
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Have you considered making the manifest fetch a group leg that starts the download on success, so every failure goes through the single g.Wait/isCollateral path instead of a separate stopPrep? I realize that would let a prep error beat the manifest NotFound, so keeping it inline may well be the better call.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I kept it inline for the reason you gave. ate-api-server acts on the NotFound, and a group would let a prep error replace it. The download leg would also have to start from inside the manifest leg.

Also say that the asset fetches and image pulls a cancelled prep started
keep running detached.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants