Skip to content

Runner proto lifecycle - #633

Merged
itssimrank merged 6 commits into
mainfrom
runner-proto-lifecycle
Nov 17, 2026
Merged

itssimrank merged 6 commits into
mainfrom
runner-proto-lifecycle

Conversation

@itssimrank

Copy link
Copy Markdown
Collaborator

Summary

Stacked on the common-ground TaskRow / TaskApplier seam (internal/store/task_apply.go, internal/server/server.go, AGENTS.md). Introduces the minimal pull-based runner wire contract (ax.runner.v1) and the pure, I/O-free task/runner state transitions operating directly on store.TaskRow, with zero server or runner runtime wiring yet.

Introduces the minimal pull-based runner wire contract (ax.runner.v1) and the pure, I/O-free task/runner state transitions operating directly on store.TaskRow (#591 seam), with zero server or runner runtime wiring yet.

Key Changes

  • pkg/apis/runner/v1/runner.proto (runner.pb.go): Adds AssignmentMode (IDLE, RUN, RESUME, SETUP), ClaimAssignmentRequest/Response, ExecSpec, GoalPayload, and ReportEventsRequest/Response (SetupFinished, CommandStarted, CommandExited).
  • internal/lifecycle/lifecycle.go:
    • Claim: per-actor X-AX-Runner-Token minting with ClaimNonce retry idempotency, RUN vs RESUME (live MEMORY child) vs SANDBOX_CRASHED (unexpected restart) vs IDLE selection.
    • ApplyEvents: seq deduplication, run_id fencing, and terminal COMPLETED/FAILED TaskOutcome recording with parkActor signaling on CommandExited.
    • IsTerminal / IsExecutionTerminal: treats PROVISIONING_FAILED (with no Outcome) as retryable while locking terminal execution outcomes.

Testing

  • go test -v -count=1 ./internal/lifecycle/... ./pkg/apis/runner/...
  • golangci-lint run ./internal/lifecycle/... ./pkg/apis/runner/... (0 issues)

siyuanfoundation and others added 6 commits November 17, 2026 15:52
…n contracts

Establish the minimal shared seam between the Task Reconciliation Loop
and the Task Runner + ax-server workstreams:

- Add transactional TaskApplier (TaskKey, TaskRow, DeleteTaskRow sentinel,
  ApplyFunc, LifecycleState / SetLifecycleState, ScrubStoredTask) and
  ErrLockTimeout in internal/store.
- Add pure Task lifecycle contract types (ActionKind, SuspendReason,
  Action, State, sealed Input variants, Output, TransitionFunc,
  IsTerminal), Transition contract stub, and NextReconcileAt in
  internal/lifecycle.
- Sync AGENTS.md and skills/substrate/SKILL.md.
- Clarify on CreateInput that CreateTask always initializes new tasks in TASK_STATE_QUEUED (starting directly in TASK_STATE_SUSPENDED is unsupported).
- Guard nil receiver in (*TaskRow).SetLifecycleState and document Task.Status initialization in ApplyFunc.
- Guard non-zero ClaimDeadline in NextReconcileAt so a zero time cannot schedule a QUEUED task as permanently overdue.
- Expand lifecycle and store unit tests for past NotBefore, zero ClaimDeadline, terminal SUSPEND_ACTOR_SYNC, LastResumedAt, and nil-field/nil-receiver isolation.

Signed-off-by: siyuanfoundation <[email protected]>
- Drop MaxQueueWaitDuration so RESOURCE_EXHAUSTED backs off RESUME_ACTOR while keeping the task in TASK_STATE_QUEUED rather than failing after 30m (#468).
- Remove the ErrUnimplemented Transition stub (transition.go) so the state-machine PR adds Transition alongside its real implementation; preserve pure-transition contract invariants on TransitionFunc.

Signed-off-by: siyuanfoundation <[email protected]>
- Drop queue, lease, sweep, and timer types (Action, ActionKind, SuspendReason, NextReconcileAt, ErrLockTimeout, reconciler/sweep inputs) so this phase reuses AX's synchronous Substrate lifecycle path (#515, #468, #592).
- Extract server.storedStatus into store.StoredStatus and use it in TaskRow.SetLifecycleState so stored TaskStatus.state covers only AX-owned states while live actor state continues to be read from Substrate.
- Track Runnable, ClaimNonce, RunnerToken*, ActiveRunID, RunSeq, and LastAckedRunnerSeq on lifecycle.State for pull-based runner assignment and event fencing.

Signed-off-by: siyuanfoundation <[email protected]>
- Move runner control fields directly onto store.TaskRow and remove internal/lifecycle from this seam so the runner + ax-server PR introduces internal/lifecycle alongside its real Transition implementation and tests.

Signed-off-by: siyuanfoundation <[email protected]>

@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.

LGTM to land the contract, with two things to settle before the :8081 handler wires it up:

  1. v0.1 risk: restartedSameRun also matches on in_memory_run_id, but if that's set the runner survived, so it wasn't a restart. An interactive task (or one suspended mid-setup) resumed from a memory snapshot would come back FAILED/SANDBOX_CRASHED, which hits the suspend/resume demo step. Crash should mean in_memory empty and last_started matching.
  2. Long-term: ExecSpec/GoalPayload duplicate what the mounted runner already reads from the Task (goal, config, MCP, launcher choice), and argv is empty for goal tasks with no defined meaning. Could we pick one source of truth? That would also give goal-less interactive tasks IDLE instead of RUN (#632).

Small: ApplyEvents could guard on IsTerminal so a late CommandExited can't overwrite CANCELLED.

@itssimrank

Copy link
Copy Markdown
Collaborator Author

/cc @siyuanfoundation

@itssimrank

Copy link
Copy Markdown
Collaborator Author
LGTM to land the contract, with two things to settle before the :8081 handler wires it up:

v0.1 risk: restartedSameRun also matches on in_memory_run_id, but if that's set the runner survived, so it wasn't a restart. An interactive task (or one suspended mid-setup) resumed from a memory snapshot would come back FAILED/SANDBOX_CRASHED, which hits the suspend/resume demo step. Crash should mean in_memory empty and last_started matching.
Long-term: ExecSpec/GoalPayload duplicate what the mounted runner already reads from the Task (goal, config, MCP, launcher choice), and argv is empty for goal tasks with no defined meaning. Could we pick one source of truth? That would also give goal-less interactive tasks IDLE instead of RUN (https://github.com/google/ax/issues/632).
Small: ApplyEvents could guard on IsTerminal so a late CommandExited can't overwrite CANCELLED.

Addressed in follow-up #635

@itssimrank
itssimrank merged commit 18b8739 into main Nov 17, 2026
10 checks passed
@mayawang mayawang mentioned this pull request Nov 17, 2026
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