Skip to content

ateapi: record each actor-provisioned volume as an ExternalVolume - #3746

Draft
hajiler wants to merge 5 commits into
agent-substrate:mainfrom
hajiler:shared-volumes/pr3-provisioned-external-volumes
Draft

hajiler wants to merge 5 commits into
agent-substrate:mainfrom
hajiler:shared-volumes/pr3-provisioned-external-volumes

Conversation

@hajiler

@hajiler hajiler commented Nov 9, 2026

Copy link
Copy Markdown
Collaborator

Part of #1637. Stacked on #3744: the first commit is that PR, review the second (ateapi: record each actor-provisioned volume as an ExternalVolume). I will rebase onto main once #3744 merges.

Moves the per-actor volume bookkeeping onto the ExternalVolume resource without changing what an actor mounts: still one volume per actor, provisioned from external.template, deleted with the actor.

  • Resume records each provisioned volume as an ExternalVolume in the actor's atespace right after CreateVolume returns, and names it in the new status.externalVolumes.volumes[].externalVolumeName. The status keeps its copy of the handle, so the hot paths read nothing new.
  • Delete removes the record after the storage. A missing record (actors from before this change, or a status that never got written) is not an error.
  • A retry after a crash between the CSI call and the actor write reuses the record it left when it names the same volume; a record naming other storage fails the resume with FAILED_PRECONDITION.
  • Record names are <volume>-<hash of actor UID and volume>: deterministic, unique across actors and recreations, and within a DNS label whatever the volume name's length.

Known gap until actor references land: DeleteExternalVolume does not yet refuse a record a live actor provisioned. The actor keeps working from its status copy and its delete still removes the storage.

AI use: drafted with an AI agent under my direction.

  • Tests pass: controlapi unit tests for the record keeping and the name, the functional lifecycle test extended to check the record after resume and after delete, hack/verify-all.sh, apitool validate, hack/verify/proto-breaking.sh. The e2e sub-test combinedvolumes/ExternalVolumeRecorded is new and has not been run on a cluster yet.
  • Docs updated

@hajiler
hajiler force-pushed the shared-volumes/pr3-provisioned-external-volumes branch 2 times, most recently from c49c5b2 to 177fdb4 Compare November 9, 2026 22:17
@hajiler

hajiler commented Nov 9, 2026

Copy link
Copy Markdown
Collaborator Author

Rebased onto the current #3744 head (adds its apitool example/annotation fix); the last commit is still the one to review.

@hajiler hajiler left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Adversarial review of the logic introduced in this PR (focusing on security, failure/recovery bugs, validation, and code/comment health). Inline comments cover:

  1. deleteActorVolumes (volumes.go:253, volumes.go:256): Unconditional DeleteExternalVolume can delete an unrelated ExternalVolume record (including after "record naming other storage fails the volume"), and when the actor status write fails after recordExternalVolume, falling back to actorVolumeID passes the CSI request name rather than the recorded VolumeId to DeleteVolume before deleting the only copy of resp.VolumeID.
  2. createActorVolumes / recordExternalVolume (volumes.go:163, volumes.go:211): ExternalVolume rows are written to Postgres without running apivalidation (where driver_name has stricter bounds than ExternalVolumeStatus.volume_type and CSI responses are unvalidated), store.ErrVolumeRegistered surfaces as codes.Internal, and VolumeContext is not checked when reusing an existing record.
  3. API & docs (ateapi.proto, csi-volumes.md, combinedvolumes_test.go): ObjectRef vs string external_volume_name per api-style-guide.md §2.3, proto doc-comment conventions, leftover client-only lifetime wording in docs, and asserting VolumeContext in e2e.

recordName = provisionedExternalVolumeName(actorUID, vol.GetName())
}
volumeRef := resources.ExternalVolumeRef{Atespace: actor.GetMetadata().GetAtespace(), Name: recordName}
if _, err := volumeStore.DeleteExternalVolume(ctx, volumeRef, store.DeletePreconditions{}); err != nil && !errors.Is(err, store.ErrNotFound) {

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

DeleteExternalVolume here deletes volumeRef by name alone with empty DeletePreconditions{} and without checking that the stored ExternalVolume actually records this actor's volume.

Two cases delete a record this actor does not own:

  1. Right after TestCreateActorVolumes's "record naming other storage fails the volume" case (volumes_test.go:358-377), team-a/<derived> records "somebody-elses-disk" while vol.StorageVolumeId and vol.ExternalVolumeName stay empty on the actor. Calling DeleteActor to clean up that actor (or deleting an actor that was never resumed while <derived> exists) derives recordName and deletes "somebody-elses-disk"'s ExternalVolume record.
  2. After an actor resumes, if its ExternalVolume record is deleted via DeleteExternalVolume (as docs/guides/csi-volumes.md:136 notes) and a global owner registers another volume under the same name, DeleteActor deletes the new volume's ExternalVolume record.

When vol.GetStorageVolumeId() != "", read stored first, verify stored.GetDriverName() == vol.GetVolumeType() && stored.GetVolumeId() == vol.GetStorageVolumeId(), and pass store.DeletePreconditions{UID: stored.GetMetadata().GetUid()} to DeleteExternalVolume.

// derived name when the status does not name it.
recordName := vol.GetExternalVolumeName()
if recordName == "" {
recordName = provisionedExternalVolumeName(actorUID, vol.GetName())

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

When the actor write after recordExternalVolume fails (or ateapi crashes in between), vol.GetStorageVolumeId() is still "", while the ExternalVolume at provisionedExternalVolumeName(actorUID, vol.GetName()) holds the real resp.VolumeID returned by CreateVolume.

Because line 233 falls back to volID = actorVolumeID(actorUID, vol.GetName()) (which is CreateVolumeRequest.Name, not the driver-assigned VolumeId, e.g. "substrate-..." vs MockVolumePlugin's "mock-vol-substrate-...", "nfs-server#...", "projects/.../disks/...", or "vol-..."), plugin.DeleteVolume(ctx, volID) misses the real volume: if the driver returns NotFound, line 256 then deletes the ExternalVolume record, erasing the only persisted copy of resp.VolumeID and leaking the volume (or if the driver returns InvalidArgument on a malformed volume ID, DeleteActor is stuck). TestDeleteActorVolumes (volumes_test.go:631) masked this by seeding record(derived, "substrate-actor-uid-123-vol1") instead of "mock-vol-substrate-actor-uid-123-vol1".

Note a security subtlety if reading stored.GetVolumeId() when vol.GetStorageVolumeId() == "": deleteActorVolumes must not blindly pass an unverified stored.GetVolumeId() to plugin.DeleteVolume, or an atespace editor deleting an unresumed actor when <derived> was registered by a global owner for "somebody-elses-disk" would destroy "somebody-elses-disk" in the storage backend. Persisting StorageVolumeId on actor.Status before creating the ExternalVolume record avoids both issues: vol.GetStorageVolumeId() == "" then guarantees Substrate never wrote <derived>, and createActorVolumes can also reject a pre-existing <derived> before plugin.CreateVolume provisions an unrecorded disk.

Comment thread api/ateapi/v1/ateapi.proto Resolved
Comment thread api/ateapi/v1/ateapi.proto Resolved
Comment thread docs/guides/csi-volumes.md Resolved
Comment thread docs/guides/csi-volumes.md Resolved

@hajiler hajiler left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This review was produced by an AI agent (Jetski) run by the PR author.

Adversarial pass over the last two commits (935ea3c, 946bcba) only. I found two new problems. If the record write fails after CreateVolume, the volume handle is lost and the disk can leak. During a roll or rollback, an older ate-api-server deletes actors without deleting their records. The earlier inline threads on this PR are all still open at this head and are not repeated here. go build, go test -race ./cmd/ateapi/..., apitool validate, proto-breaking, codegen, gofmt, go-modules and licenses all pass. Cross-PR, outside the diff. (1) The first commit no longer matches #3744's head: patch-id 57e10859 vs c85dfa74. #3744 has since moved to maxBytes bounds and a NUL check on volume_context, dropped ifDisabled on CreateExternalVolumeRequest, added UNIQUE (record_atespace, record_name) and reworded several docs. The last two commits rebase onto c0a3d7b without conflicts. (2) The last two commits use the old actor-side name ExternalVolumeStatus in volumes.go (createActorVolumes and deleteActorVolumes signatures), volumes_test.go, validation_test.go and the ExternalVolume proto comment. Each needs the Actor prefix after #4021. (3) Field numbers do not collide across #3744, #3745 and this PR. The same reference is ObjectRef external_volume in #3745 but string external_volume_name here. Commit messages, outside the diff: 946bcba says it renames "the maxPrefix variable ... which shadowed the builtin max". It renamed max to maxPrefix. It also says "Validate external_volume_name's format", but the commit only adds tests for validation 935ea3c added.

Comment thread api/ateapi/v1/ateapi.proto Outdated
// A client registers a volume that already exists in the storage system.
// Substrate records one for every volume it provisions for an actor from
// `ExternalVolumeTemplate`, named in the actor's
// `ExternalVolumeStatus.external_volume_name`, and deletes it with the actor.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

"deletes it with the actor" only holds once every ate-api-server replica runs this code. During the roll, or after a rollback (version-skew-policy.md), an older replica's DeleteActor deletes the storage and leaves the record. The record keeps its external_volume_keys row and, through ON DELETE RESTRICT, makes DeleteAtespace fail with FAILED_PRECONDITION. If the older release predates #3744, no API can remove the record. Either soften this sentence and note it in the description, or have a newer server remove records whose actor no longer exists.

return f.externalVolumeStore.DeleteExternalVolume(ctx, volumeRef, precondition)
}

func TestCreateActorVolumesRecordErrors(t *testing.T) {

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

AGENTS.md prefers rows in an existing table test. TestCreateActorVolumes already has an existing field, and a store failingExternalVolumeStore column would take these two rows. The rows also use only a generic connection reset. store.ErrVolumeRegistered, the store error that can actually happen here, has no row.

hajiler and others added 5 commits December 1, 2026 11:53
An ExternalVolume is an atespace-scoped record of a CSI volume that already
exists in the storage system: the driver, the volume ID and the volume
context the node plugin needs to mount it. Its lifetime is independent of
any actor, and an atespace cannot be deleted while it holds one.

This adds the resource, its Postgres table and store methods, the OpenFGA
type and RPC permissions, the Create, Get, List and Delete RPCs, and the
kubectl-ate commands. Create requires the ExternalVolumes preview gate and
a global owner. Get, List and Delete work with the gate off, so turning it
off cannot strand a record. Delete removes the record and leaves the
storage in place.

Nothing references an ExternalVolume yet. Actor templates still provision
a volume per actor from external.template.

Signed-off-by: Elijah Rodriguez-Beltran <elijahrb@google.com>
Every volume provisioned for an actor from external.template now has an
ExternalVolume in the actor's atespace, named in the actor's
ExternalVolumeStatus.external_volume_name. The record is written right
after CreateVolume returns and deleted by the actor's delete workflow
after the storage, so a retry after a crash in between converges: the
retried CreateVolume returns the same volume and the record it left is
reused when it names that volume.

The actor status keeps its copy of the volume handle, so resume, suspend
and delete read nothing new. The record name is the volume name with a
hash of the actor UID and volume name, which keeps it a DNS label and
unique across actors and across a namesake created after the actor is
deleted. Actors provisioned before this change have no record, and
deleting them tolerates that.

Signed-off-by: Elijah Rodriguez-Beltran <elijahrb@google.com>
Cover a failed storage delete keeping the record, a volume already gone
from storage still losing its record, and store errors while recording
or deleting one. Validate external_volume_name's format and update
rules. The partial-failure functional test checks that only the
provisioned volume gets a record and that none is left after delete.

Rename the maxPrefix variable in provisionedExternalVolumeName, which
shadowed the builtin max. Note in the resource model that Substrate
writes ExternalVolumes too.
Validate the record before writing it, since ExternalVolume.driver_name
is shorter than ExternalVolumeStatus.volume_type and the volume ID and
context come from the CSI driver unchecked. A volume already registered
under another ExternalVolume fails the resume with FailedPrecondition
instead of Internal, and a leftover record is only reused when its
volume context matches too. Docs and proto comments scope the
delete-with-the-actor rule to volumes Substrate provisioned.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
ExternalVolumeStatus.external_volume replaces external_volume_name, as
the API style guide asks for cross-resource references. Callers can pass
it straight to GetExternalVolume.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@hajiler
hajiler force-pushed the shared-volumes/pr3-provisioned-external-volumes branch from 946bcba to 325fe49 Compare December 1, 2026 20:59

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.

1 participant