Repository navigation
store: add TaskRow, TaskApplier, and StoredStatus runner seam - #591
Conversation
7553795 to
96983ae
Compare
|
/cc @YoyinZyc @itssimrank |
96983ae to
0b72372
Compare
0b72372 to
c08f503
Compare
c08f503 to
e845c29
Compare
135a549 to
328aa77
Compare
6f70de5 to
f22e770
Compare
70804a9 to
d3fb2b4
Compare
| WaitWorkspaceTag bool | ||
| } | ||
|
|
||
| func (*CreateInput) isInput() {} |
There was a problem hiding this comment.
nit: Consider adding a comment clarifying whether CreateTask supports starting directly in TASK_STATE_SUSPENDED or if CreateInput always initializes new tasks in TASK_STATE_QUEUED.
There was a problem hiding this comment.
Addressed in b2a7af6: documented on CreateInput that CreateTask does not support starting directly in TASK_STATE_SUSPENDED and always initializes new tasks in TASK_STATE_QUEUED.
| // SetLifecycleState writes s onto r and recomputes NextReconcileAt at now. | ||
| // Live Substrate actor identity fields (status.actor and status.actor_uid) are | ||
| // scrubbed so they are never persisted. | ||
| func (r *TaskRow) SetLifecycleState(s lifecycle.State, now time.Time) { |
There was a problem hiding this comment.
nit: Guard if r == nil in SetLifecycleState (matching Clone and LifecycleState), and document in ApplyFunc that Apply initializes Task.Status if nil before mirroring Task.Status.Generation.
There was a problem hiding this comment.
Addressed in b2a7af6: added the if r == nil guard in SetLifecycleState (with test coverage) and documented in ApplyFunc that Apply initializes Task.Status if nil before mirroring Generation.
| // 2. Otherwise, if the task is in QUEUED (not deleting) with a ClaimDeadline, | ||
| // the row is due at that exact ClaimDeadline (no periodic polling). | ||
| // 3. Steady-state tasks (WORKING, IDLE, SUSPENDED, terminal) return nil. | ||
| func NextReconcileAt(state State, now time.Time) *time.Time { |
There was a problem hiding this comment.
Guard state.ClaimDeadline != nil && !state.ClaimDeadline.IsZero() so a zero ClaimDeadline cannot schedule a QUEUED task as permanently overdue.
There was a problem hiding this comment.
Addressed in b2a7af6: guarded !state.ClaimDeadline.IsZero() in NextReconcileAt and added a zero-ClaimDeadline test case.
| } | ||
| } | ||
|
|
||
| func TestNextReconcileAt(t *testing.T) { |
There was a problem hiding this comment.
Consider adding TestNextReconcileAt cases for a past NotBefore and a terminal task with a queued SUSPEND_ACTOR_SYNC action, plus LastResumedAt and nil-field isolation checks in TestStateCloneAndIdentifiers.
There was a problem hiding this comment.
Addressed in b2a7af6: added TestNextReconcileAt coverage for past NotBefore and terminal COMPLETED with queued SUSPEND_ACTOR_SYNC, plus LastResumedAt and nil/empty-field isolation checks in TestStateCloneAndIdentifiers.
|
Nice to have the seam spelled out before both streams build on it. Two things I'd like to settle here, since they're cheap to change now:
Smaller: I'd trim the stub-only parts (Transition, the lock/lease errors, NextReconcileAt) and land them with the PRs that implement them, and reuse storedStatus instead of a second scrubber. @rakyll curious if you see 1 the same way |
Good catch. I removed
Dropped
|
b2a7af6 to
db058d6
Compare
|
Thanks, that's a fair distinction, an AX suspended isn't the actor's suspended. Since the async path makes stored state the source of truth with a loop syncing actor state in, that's a deliberate change from #515, so I'd like @rakyll to sign off on that direction before both streams build on it. On capacity, works for me as a stopgap, could you add a TODO pointing at agent-substrate/substrate#2059 so the backoff goes when Substrate queues? |
mayawang
left a comment
There was a problem hiding this comment.
Approving so you and Simran aren't blocked, Jaana can do the retrospective storage review when she's back. Let's keep one line from standup: storing AX's own task states is fine, but no Substrate actor attributes in the store (actor UID, actor state, worker), read those live like today. So: non-blocking, could the persisted ActorUID move out of stored State (or be documented as the one fencing exception for Jaana to review), and please add the TODO pointing at agent-substrate/substrate#2059 for the capacity backoff. Needs a rebase on main too.
|
I haven't been able to follow up on the earlier design conversation related to this but do we have a real reconciliation use case for tasks? I think we should remove ax apply, and switch to ax create. Tasks may need mutation only for input steering but they will rely on some input protocol for those use cases. We cannot easily use Substrate as the underlying layer with queueing and additional capabilities with mutations. |
…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 (google#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 (google#515, google#468, google#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]>
13210a7 to
95f055b
Compare
|
Thanks for trimming, this fits v0.1 well, good to merge. Two things for the follow-up that implements the runner channel (the :8081 handler and the TaskApplier store):
Who's picking up that follow-up, and do we have an ETA? Steps 2–4 of the hero demo can't go live until it lands, so it tells us what we can show at the exit gate. |
We will add a rule to allow ingress to the
They are both needed actually. the JWT token is to proves which actor the traffic is from through the egress gateway, the runner token is to prove the request is from the runner process instead of the agent running in the actor.
I can add the port rule as the followup. |
|
Thanks, both makes sense. One follow-up on the token: the runner starts the launcher as the same uid, so how do we keep the runner token out of the agent's reach? And for the :8081 handler itself, is that you too, and any rough ETA? |
The launcher will not be launched with the same uid. We will default to use 1000 first. |
Summary
This PR establishes the minimal shared
internal/storeseam between theTaskApplierStore and Pull-Based Task Runner +ax-serverworkstreams on top of AX's existing synchronous Substrate lifecycle path (#515,#592):store.TaskKey,store.TaskRow,store.DeleteTaskRow,store.ApplyFunc/store.TaskApplier, andstore.StoredStatus(extracted fromserver.storedStatus).Runner wire protos (
runner.proto), pureinternal/lifecycletransition rules,:8081/:8080server handlers,ax-task-runner, and PostgreSQL/in-memoryTaskApplierimplementations land in their respective follow-up PRs. Merging this PR introduces zero runtime or database behavior changes.Seam Overview
flowchart LR GRPC["ax-server gRPC (:8080, sync Substrate RPCs)"] -- "store.TaskApplier.Apply" --> TasksDB[("store.TaskRow (Task, Runnable, ActiveRunID, RunnerToken*)")] Runner["ax-server Runner HTTP (:8081, Claim / Events)"] -- "store.TaskApplier.Apply" --> TasksDBTaskApplier)store.TaskApplier(TaskKey,TaskRow,DeleteTaskRow,ApplyFunc,StoredStatus)tasksrunner columns (generation,actor_uid,runnable,active_run_id,run_seq,runner_token_hash,runner_token_confirmed,claim_nonce,last_acked_runner_seq); implementTaskApplier(Apply,GetTaskRow) ininternal/store/{postgres,memory}.ax-serverstore.TaskApplier,store.TaskRow,store.StoredStatuspkg/apis/runner/v1wire protocol andinternal/lifecyclestate transitions operating on*store.TaskRow; wire:8081runner HTTP server (ClaimAssignment,ReportEvents, andWorkspaceManager'sSetupCoordinator), sharedProfileActorTemplate+ warm WorkspaceTagprovisioning on:8080, andax-task-runner.Contract Rules
store.StoredStatus& live actor state (#515).server.storedStatusis extracted intostore.StoredStatusand reused byinternal/serverandApply. StoredTaskStatus.statecovers only AX-owned states (v1alpha1.IsAXTaskState:QUEUEDduring provisioning, plus terminalCOMPLETED,FAILED,CANCELLED), whileWORKING,SUSPENDED,SUSPENDING,status.actor, andstatus.actor_uidcontinue to be derived live from Agent Substrate on read.TaskRow.Runnabletracks whether execution is authorized so:8081ClaimAssignmentreturnsASSIGNMENT_MODE_IDLEwhen a paused actor is woken externally (e.g.ax ssh).store.ApplyFunc&store.DeleteTaskRow(internal/store/task_apply.go). Returningnilorcurrentitself leaves storage unchanged; returningstore.DeleteTaskRow(matched strictly by pointer identity) deletes the row; returning any other non-nil*TaskRowscrubsTask.StatusviaStoredStatusand inserts or updates atGeneration + 1. Perform all Substrate RPCs and external reads outsideApplyso the row lock is held only across pure in-memory transitions.store.TaskRow).ActorUIDbinds:8081Actor JWT claims to the active actor incarnation;RunSeq(r-1,r-2, ...) is a task-lifetime monotonic run ID allocator that never resets across retries or cold restores;RunnerTokenHash/RunnerTokenConfirmed/ClaimNonceauthenticate PID 1 and make lost-response initial claim retries idempotent; andLastAckedRunnerSeqdeduplicates runner events within the active run.Known Limitations of the Synchronous Path (Deferred to Async Reconciler Phase)
Adapting the synchronous Substrate path keeps this phase small and aligned with
#515,#468, and#592, with the following intentional trade-offs until background reconciliation lands:exit_code != 0while PID 1ax-task-runnerremains alive) are handled viaReportEvents, and terminal actor parking (SuspendActorafterCOMPLETED/FAILED) retries transient Substrate errors. However, if the sandbox itself crashes (ACTOR_STATE_CRASHED/OOMKilled) or the runner hangs silently, there is no background loop to executeREVERT_ACTOR+ResumeActor(GetTasksurfacesFAILED/SANDBOX_CRASHEDfrom live actor state).ax ssh: Waking aSUSPENDED,COMPLETED, orFAILEDactor viaax ssh(atenet-router) safely receivesASSIGNMENT_MODE_IDLEonClaimAssignmentso the task command never re-runs, but without a background drift sweep AX does not automatically re-suspend the actor after theax sshsession ends.IDLEmulti-turn parking or background timers yet: Agent-drivenTASK_STATE_IDLE(POST /idle) and wall-clock budget timers are deferred to the next phase.Key Changes
internal/store&internal/server: Extractedstore.StoredStatusfromserver.storedStatus(internal/server/server.go) and addedTaskApplier(TaskKey,TaskRow,DeleteTaskRow,ApplyFuncintask_apply.go+task_apply_test.go).AGENTS.md: Syncedinternal/store/summary and test package count (22).Testing
make verify(buf format,buf lint,buf generate,go mod tidy,go fmt,golangci-lint—0 issues)go build ./cmd/ax ./cmd/ax-server ./cmd/ax-task-runnergo test -race -count=1 ./...(all 22 test packages pass)