Skip to content

Emit ax.task.state_changed after committed task writes - #665

Open
JeffLuoo wants to merge 1 commit into
google:mainfrom
JeffLuoo:t5-task-state-events
Open

JeffLuoo wants to merge 1 commit into
google:mainfrom
JeffLuoo:t5-task-state-events

Conversation

@JeffLuoo

@JeffLuoo JeffLuoo commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

Emit ax.task.state_changed after each task write that changes the task's phase, so task timelines and cost attribution can join AX tasks with Agent Substrate's ate.actor.* events.

Part of #675. Main has no task outcome or exit code now (#707, #756), so the event does not carry them. Related to #13 and #471.

  • The task write helpers return a taskWrite (phase before and after, write time). Each handler passes the phase that it read under the per-task lock, so a write needs no extra read.
  • The caller emits through the new telemetry.EmitAt. CreateTask and clearStoredTaskState emit after applyActor, so Provisioned gets ate.actor.uid with no extra Substrate call.
  • Attributes: ax.task.name, ate.atespace, ax.task.id, ax.task.phase, ax.task.previous_phase, and ate.actor.uid (Provisioned only).
  • Phases: Provisioned (the first phase, because server: store a task only once its actor exists #761 stores a task only after its actor exists), Queued (after a transient ResumeTask error), Terminating, Deleted. docs/observability.md explains each one.
  • substratetest gets a GetActor error and a GetActor hook for the tests.

Validation

make verify, go build, go test ./... (27 packages), and go test -race for internal/server, internal/substrate, and internal/telemetry. The tests cover each phase change, failed creates, failed store writes, an unreadable actor, and the write-time timestamp.

Written with help from an AI coding assistant.

@JeffLuoo
JeffLuoo force-pushed the t5-task-state-events branch from 226eb58 to d75c553 Compare November 20, 2026 16:00
@JeffLuoo
JeffLuoo requested review from erain and mayawang November 20, 2026 16:20
@mayawang

Copy link
Copy Markdown
Collaborator

Thanks Jeff! Before getting into the design: we're in the bug-bash freeze for v0.4, and task timelines / cost attribution aren't on the v0.4 or v1.0 list yet. Since this wraps the task write path, could we park it until after v1.0 and talk through where it fits then? Happy to look sooner if there's a user waiting on it

@JeffLuoo

Copy link
Copy Markdown
Collaborator Author

Thanks Maya, happy to respect the v0.4 freeze. One framing note: this isn't only for cost. It's the task-level counterpart of Substrate's ate.actor.state_changed / ate.actor.crashed. Today AX keeps no history of why a task went Failed, when a delete moved it to Terminating, or when its actor was recreated with a new UID; ax describe only shows the current state. The events carry ate.actor.uid, so operators can line up task and actor timelines and tell an AX problem from a Substrate one.

What do you think would be the best version to have this PR? No user is blocked on it, so I'll keep it rebased and we can talk through where it fits after v1.0.

@mayawang

Copy link
Copy Markdown
Collaborator

That's a good point, task history for debugging is a real gap, and lining up with the ate.actor.* events makes sense. Could you open an issue with that framing? Let's look at where it fits once the rc is out

@mayawang

Copy link
Copy Markdown
Collaborator

Heads-up: #719 dropped TaskApplier, so this will need a rebase onto store.Store when we pick it back up.

@JeffLuoo
JeffLuoo force-pushed the t5-task-state-events branch from d75c553 to bda9fa6 Compare November 24, 2026 14:53
@JeffLuoo
JeffLuoo requested a review from rakyll as a code owner November 24, 2026 14:53
@JeffLuoo
JeffLuoo force-pushed the t5-task-state-events branch from bda9fa6 to 22cb5e1 Compare November 24, 2026 18:42
@JeffLuoo

Copy link
Copy Markdown
Collaborator Author

@mayawang updated

@mayawang

Copy link
Copy Markdown
Collaborator

Holding merge until @rakyll weighs in on #675 for v0.4.0. Also please rebase now that #748 and #750 have merged since both touch server.go, and #750 logs failed updateTask writes in recordFailure.

@JeffLuoo
JeffLuoo force-pushed the t5-task-state-events branch 2 times, most recently from a5460fc to e93aa79 Compare November 25, 2026 20:26
Cost attribution and task timelines need a record of each change of task phase that joins with the actor events of Agent Substrate.

The task write helpers return a taskWrite with the phase before and after the write and the time of the write. Each handler passes the phase that it read under the per-task lock, so a write needs no extra read. The caller emits the taskWrite through the new telemetry.EmitAt. CreateTask and clearStoredTaskState emit after applyActor, so a Provisioned record gets ate.actor.uid with no extra Substrate call.

The phases are Provisioned, Queued (after a transient ResumeTask error), Terminating, and Deleted. A failed write, or a write that keeps the phase, emits nothing. substratetest gets a GetActor error and a GetActor hook for the tests.
@JeffLuoo
JeffLuoo force-pushed the t5-task-state-events branch from e93aa79 to 031c8c0 Compare November 26, 2026 14:56
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.

2 participants