Skip to content

feat(server): reject resource names that are not RFC 1123 labels - #406

Merged
rakyll merged 1 commit into
google:mainfrom
mvanhorn:cursor/validate-resource-names-dfaf
Sep 25, 2026
Merged

rakyll merged 1 commit into
google:mainfrom
mvanhorn:cursor/validate-resource-names-dfaf

Conversation

@mvanhorn

@mvanhorn mvanhorn commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

ax apply accepted any metadata.name. Names were only checked when the controller created the Substrate ActorTemplate / Actor, which require a lowercase RFC 1123 label, so Task-With-Caps was stored and then failed seconds later with a confusing ActorCreationFailed condition (and the template error before it is swallowed as a WARN, see #366). This moves the check to apply time.

Fixes #370

What changed

  • pkg/apis/v1alpha1: ValidateName (^[a-z0-9]([-a-z0-9]*[a-z0-9])?$, at most 63 characters, matching Substrate's k8s-short-name) and ValidateObjectMeta, which checks metadata.name and, when set, metadata.atespace (it becomes a Substrate atespace name too; empty still defaults to default in the server). ValidateTask now runs it first; new ValidateWorkspace / ValidateModel do the same for the other kinds.
  • internal/server: UpdateWorkspace and UpdateModel call the new validators and return InvalidArgument. UpdateTask already goes through ValidateTask, so it needed no change (this also keeps the diff out of the way of Replace UpdateTask with CreateTask and enforce immutability #398).
  • docs/manifests.md: one paragraph on the naming rule.

The error is phrased so it is actionable straight from the CLI:

Error: applying document 1: rpc error: code = InvalidArgument desc = metadata.name: invalid value "Task-With-Caps": must be a lowercase RFC 1123 label: at most 63 lowercase alphanumeric characters or '-', starting and ending with an alphanumeric character

Notes for review:

  • An empty name is now rejected too; previously it was saved under the key default/. The shipped examples and demo.sh all use valid names.
  • Possible follow-up, deliberately left out to keep the API rule identical to Substrate's: the controller derives <task>-tmpl-<8 hex>, so a task name longer than 49 characters still produces a template name over 63. If you'd like, I can cap task names at 49 in a follow-up.

How tested

  • go test ./... (green), go vet ./..., go mod tidy leaves go.mod / go.sum unchanged.
  • New tests: TestValidateName (valid / invalid table incl. 63 vs 64 chars, uppercase, _, ., leading / trailing -, whitespace, unicode), TestValidateObjectMeta (name and atespace cases, all three kinds), and internal/server TestUpdate_RejectsInvalidNames (Task / Workspace / Model return InvalidArgument, nothing is persisted, valid names still save). The existing TestValidateTask fixtures just gained a name.
  • End to end: built ax and ax-server from this branch, ran ax-server against a local Redis, and applied manifests with an uppercase task name, an underscore workspace name, a dotted atespace, and a valid name (first screenshot).

Evidence

ax apply rejecting invalid names and atespaces at apply time, then accepting a valid one

go test output for the new name validation tests

Demo

ax apply rejecting invalid names

Full-resolution MP4

@google-cla

google-cla Bot commented Sep 25, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

cursor Bot pushed a commit to mvanhorn/ax that referenced this pull request Sep 25, 2026
Keeps the test valid alongside metadata.name validation (google#406).

Co-authored-by: Matt Van Horn <[email protected]>
@rakyll

rakyll commented Sep 25, 2026

Copy link
Copy Markdown
Member

Can you sign the CLA?

mvanhorn added a commit to mvanhorn/ax that referenced this pull request Sep 25, 2026
Keeps the test valid alongside metadata.name validation (google#406).

Co-authored-by: Matt Van Horn <[email protected]>
ax apply accepted any metadata.name, but Substrate requires actor,
ActorTemplate and atespace names to be lowercase RFC 1123 labels. A name
such as Task-With-Caps was therefore stored, and only failed seconds
later with an asynchronous ActorCreationFailed condition that the user
had to dig out of ax describe or the controller logs.

Validate metadata.name (and metadata.atespace when set) against
[a-z0-9]([-a-z0-9]*[a-z0-9])? with a 63 character limit for Task,
Workspace and Model alike, and return InvalidArgument at apply time.

Fixes google#370

Co-authored-by: Matt Van Horn <[email protected]>
@mvanhorn
mvanhorn force-pushed the cursor/validate-resource-names-dfaf branch from 06fe19f to 46a5012 Compare September 25, 2026 14:52
@mvanhorn

Copy link
Copy Markdown
Contributor Author

Thanks @rakyll. The CLA was already signed; the commits had the wrong author email, which I've fixed. cla/google is green now on this PR and #405.

@rakyll rakyll left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you!

@rakyll
rakyll merged commit 099f24a into google:main Sep 25, 2026
9 checks passed
@mvanhorn

Copy link
Copy Markdown
Contributor Author

Thanks for the merge @rakyll!

mvanhorn added a commit to mvanhorn/ax that referenced this pull request Oct 14, 2026
Keeps the test valid alongside metadata.name validation (google#406).

Co-authored-by: Matt Van Horn <[email protected]>
mvanhorn added a commit to mvanhorn/ax that referenced this pull request Oct 15, 2026
Keeps the test valid alongside metadata.name validation (google#406).

Co-authored-by: Matt Van Horn <[email protected]>
mayawang pushed a commit that referenced this pull request Oct 19, 2026
* feat(controller): apply Task resource limits to the ActorTemplate

TaskSpec.resources is documented and accepted by ax-server, but the
controller never read it, so spec.resources.limits had no effect on the
sandbox. Translate limits.cpu and limits.memory into the Substrate
ActorTemplate resources block (Substrate's {name, quantity} list) when
provisioning the per-task template.

Substrate sizes sandboxes by limits only, so requests are documented as
not applied. A limits change already yields a new template because the
launch spec is part of the template digest via AX_TASK_YAML; a test now
pins that behaviour.

Fixes #369

Co-authored-by: Matt Van Horn <[email protected]>

* controller: validate resource limits and never fall back without them

Address review on #405:

- Validate spec.resources before provisioning, at apply time via
  ValidateTask and again in the reconciler. Quantities follow the
  Kubernetes quantity grammar, must be greater than zero, and the cpu
  limit must be below 1000 cores, matching what Substrate enforces on the
  ActorTemplate. Invalid values fail the reconcile with Ready=False,
  reason InvalidResources.
- When a task has limits and Substrate rejects the per-task template,
  fail the reconcile (reason TemplateCreationFailed) instead of falling
  back to the default template, which would run the task without the
  limits it asked for. Tasks without limits keep the existing fallback.
- Reject spec.resources.requests with a clear message: Substrate sizes
  sandboxes by limits alone, so accepting and ignoring it was misleading.
  The docs and examples/task.yaml drop the requests block.
- Tests: failure paths for invalid limits and for a rejected template
  with and without limits, plus an explicit assertion that a limits
  change yields a differently named template.

Co-authored-by: Matt Van Horn <[email protected]>

* test: name the ValidateTask fixtures in TestValidateResources

Keeps the test valid alongside metadata.name validation (#406).

Co-authored-by: Matt Van Horn <[email protected]>

* v1alpha1: follow the ResourceReqs to ResourcesSpec rename

#485 renamed ResourceReqs to ResourcesSpec, so this branch no longer
built against main (pkg/apis/v1alpha1/resources.go:40). Use the new name
in ValidateResources, substrate.ResourceLimits, and their tests.

---------

Co-authored-by: Matt Van Horn <[email protected]>
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.

ax-server accepts resource names that Substrate rejects (RFC 1123); failure surfaces asynchronously as ActorCreationFailed

2 participants