Skip to content

server: clean up internal/server and cmd/ax-server #749

Todo

Description

@rakyll

Findings from a review of internal/server and cmd/ax-server.

Bugs

  • -template and -template-atespace are dead: TaskManager stores defaultTemplate/defaultTemplateAtespace (internal/controller/task.go) but never reads them. Remove the flags, the startup log field, the NewTaskManager parameters, and the args in deploy/ax-server.yaml, deploy/embed.go, and test/e2e/manifests/ax-server.yaml.
  • UpdateModel treats any store error in its defaultMetadata callback as "not found", so a transient read error on an existing model assigns it a new uid and createTime. Only store.ErrNotFound should mean create; other errors should return Internal.
  • recordFailure ignores the updateTask error (_ = s.updateTask(...)), so a failed write can leave a stale stored state without a log line.

Duplication

  • The four List handlers unpack the request by hand; pageStart(req.GetAtespace(), req.GetPageSize(), req.GetPageToken()) is enough because proto getters are nil-safe.
  • DeleteTask, SuspendTask, and ResumeTask repeat the same lock, getStoredTask, and NotFound/Internal mapping; a lockStoredTask helper would remove it.
  • Mapping Substrate errors to Unavailable (transient) or Internal is written out in SuspendTask, recordFailure, DeleteWorkspace, and prepareWorkspace, with another variant in deleteTask.
  • defaultMetadata takes a callback that saveGateway ignores the arguments of, CreateWorkspace passes as nil, and UpdateModel uses to hide the bug above. Pass the previous *ObjectMeta directly.
  • DeleteGateway reads the gateway before deleting it; let the store's DeleteGateway return store.ErrNotFound, as DeleteModel now does. Keep its lock, which orders deletes against saveGateway's check-then-create.

Small things

  • gateway.go hard-codes "default" three times instead of v1alpha1.DefaultAtespace.
  • Redundant defaulting: clearStoredTaskState re-defaults the atespace, DeleteTask checks for nil metadata, SuspendTask/ResumeTask nil-check task.Status (the task manager already does), and CreateTask handles a nil task.Spec after validation.
  • getStoredTask is a one-line wrapper meant to keep handlers off s.store for tasks, but deleteTask, listTasks, and CreateTask call the store directly anyway. Enforce the rule or drop the wrapper.
  • ListModels and ListGateways load every row and slice in memory, while tasks and workspaces page in the store.
  • cmd/ax-server: the API http.Server has no ReadHeaderTimeout (the metrics server does); err != http.ErrServerClosed should use errors.Is; the ADDR env var is unprefixed unlike AX_STORE/AX_RUNNER_VOLUME_IMAGE and missing from the -addr help; os.Exit in the serve goroutines skips the deferred telemetry flush.
  • Comments: the doubled // --- gRPC AXServer implementation --- / // --- Tasks --- header; SuspendTask does not use recordFailure like ResumeTask does, which is probably intended (a failed suspend should not fail the task) but should be stated.

To investigate

  • DeleteWorkspace does not check for tasks that still bind the Workspace, and fetchWorkspace turns NotFound into nil, so a task relying on its Workspace's profile would resume with an empty profile. Not verified what template resolution does then.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions