Skip to content

Reject a Task whose bound Workspace does not exist - #461

Merged
erain merged 3 commits into
mainfrom
fix/missing-task-workspaces-450
Nov 3, 2026
Merged

erain merged 3 commits into
mainfrom
fix/missing-task-workspaces-450

Conversation

@erain

@erain erain commented Oct 13, 2026 •

Copy link
Copy Markdown
Collaborator

Creating a Task that binds a Workspace that does not exist now fails with FailedPrecondition naming the Workspace and atespace, and nothing is saved or provisioned. Before this change, CreateTask looked the Workspace up after saving the Task and dropped any lookup error. Because Tasks are immutable, a Task created before its Workspace kept an empty /workspace until it was deleted and applied again. A store error during the lookup now fails with Internal.

Changes:

  • internal/server/server.go: CreateTask resolves spec.workspace before saving and passes the resolved Workspace to Suspend. SuspendTask and ResumeTask are unchanged.
  • docs/manifests.md: documents that the bound Workspace must exist first, and that ax apply creates documents in file order.

The examples on main (examples/claude-code/task.yaml, the README, demo.sh, and the E2E manifests) already list the Workspace before the Task that binds it. examples/task.yaml, which this PR previously reordered, was removed on main, so #460 no longer applies.

Refs #450. This PR does not reorder documents in ax apply; that remains open in the issue.

Testing (Go 1.27.1, linux/amd64):

  • New TestCreateTask_RequiresBoundWorkspace (table-driven, real memory store, in-process Substrate fake). It covers a missing Workspace, a Workspace in another atespace, a wrapped ErrNotFound, a store error, a present Workspace in the default and a named atespace, and a Task with no binding. Rejected Tasks must leave no stored record and no actor. Accepted Tasks with a binding must get AX_WORKSPACE_YAML in their actor template.
  • After merging main (explicit Suspend/Resume from controller: replace Reconcile with explicit Suspend and Resume #536): go mod tidy && git diff --exit-code go.mod go.sum, go build ./cmd/ax ./cmd/ax-server ./cmd/ax-task-runner, go test -count=1 ./..., go vet ./..., gofmt -l . all pass. Postgres and E2E tiers were not run (no store or E2E changes).

Prepared with an AI coding assistant; I reviewed and tested every change.

Reject missing workspace references before a Task is persisted or
provisioned. Report backend lookup failures and reuse the resolved
workspaces in binding order.
Main now binds at most one Workspace per Task (spec.workspace) and the
server takes a concrete TaskReconciler, so the earlier change no longer
applied. CreateTask now resolves the one bound Workspace before saving:
a missing Workspace fails with FailedPrecondition and a store error with
Internal, and nothing is saved or provisioned in either case.

Replace the separate admission test with a table-driven test in
server_test.go that runs against the in-process Substrate fake and checks
that an accepted Task's template carries AX_WORKSPACE_YAML.

examples/task.yaml listed its Task before its Workspace, which `ax
apply` would now reject, so list the Task last. Document the ordering
requirement in docs/manifests.md.
@erain erain changed the title Reject Tasks whose referenced Workspaces do not exist Reject a Task whose bound Workspace does not exist Oct 29, 2026
@erain
erain marked this pull request as ready for review October 29, 2026 21:49
@erain
erain requested review from mayawang and rakyll as code owners October 29, 2026 21:49

@mayawang mayawang left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nice, failing up front is much better than a task stuck with an empty workspace forever. LGTM! Once it's in, can you close #460 since this covers it?

@mayawang mayawang mentioned this pull request Oct 30, 2026
@rakyll

rakyll commented Oct 31, 2026

Copy link
Copy Markdown
Member

We should be able to fix the merge conflicts and merge this, right?

Main replaced Reconcile with explicit Suspend and Resume, so CreateTask
now passes the Workspace it resolved before saving to Suspend instead of
fetching it again.

Main also removed examples/task.yaml, so the reordering of that example
is dropped. The remaining examples already list the Workspace before the
Task that binds it.
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.

3 participants