Bind container deletion and exit callbacks to instances - #2201
Open
sturdy4days wants to merge 4 commits into
Open
Bind container deletion and exit callbacks to instances#2201sturdy4days wants to merge 4 commits into
sturdy4days wants to merge 4 commits into
Conversation
Return the server-generated ID and instance token from container creation, expose safe JSON CLI output with mixed-version fail-closed negotiation, and reject start/bootstrap after force-deletion reservation. Add deterministic ownership, compatibility, integration, and command-reference coverage.
Keep ContainerClient.create source-compatible as async throws -> Void while discarding the optional server reply internally. Expose create results only through createWithResult and compile-check both exact function types.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Type of Change
Motivation and Context
Addresses #2116.
Container IDs can be explicitly reused. A delayed delete or exit callback that only carries an ID can therefore act on a replacement container after the original instance has gone away. Force deletion makes the ownership boundary especially important because stopping and cleanup span asynchronous work.
This change:
container create --format jsonfor orchestrators that need to retain that exact ownership token without a later inspect;container delete --if-instance-token TOKEN IDand validates the token while holding the container lifecycle lock;Backward compatibility is preserved. The legacy create route and ordinary create output remain supported. The public Swift
ContainerClient.create(...)API retains its exact legacyasync throws -> Voidsignature and discards optional reply data internally;createWithResult(...)is the only result-returning create API. An older client can ignore the optional result returned by a newer server. Result-capable create checks the server capability and uses a distinct route, so a newer client fails before creation when connected to an older server instead of creating a container without receiving its identity. Legacy unconditional delete remains supported, while a conditional delete against an older tokenless container is rejected without deleting it.Credit and overlap: @nassersala documented the reusable-ID race and an earlier local token-precondition proof of concept in this #2116 comment. This PR does not claim origin of that model. The comment describes an unpublished 9-file local patch; no public branch or PR is linked. This implementation covers the same ownership concern while also handling force-delete ID reservation/revalidation, mixed-version capability negotiation, atomic machine-readable create results, start/bootstrap reservation checks, and stale exit-callback generation ownership.
This is a source proposal only. It is not merged, released, or active in a shipped runtime.
Testing
Current local validation at
5a1500c39ae60f9231d809c752bb6d53dd9cb1c3:make swift-fmt-checkVoidand result-returning function referencesmake test— 788 non-integration tests in 88 suites passedTestCLICreateCommand: 6/6 passed, including JSON create identity matching the persisted server tokenTestCLIRmRaceCondition: 3/3 passed, including deterministic same-ID replacement and stale-token rejectiongit diff --check, signed-history verification, andgit fsck --full --no-danglingThe final compatibility-only commit changes the legacy client method's static return type and discards the same optional reply internally; it does not alter the wire request, route, server, JSON-create path, or runtime behavior. The prior selected integration evidence therefore remains applicable and was not rerun.
The integration warmup completed and the selected suites passed. The Makefile invocation then interpreted an empty serial-suite filter as an unfiltered broader phase; that phase was detected and interrupted, and is not claimed as validation. The remaining isolated
buildkitcontainer and Apple Container services were stopped, the disposable app root/kernel/artifacts were removed, the host returned tounregistered, and the default-store kernel hash remained unchanged.