Skip to content

feat(worker): report container setup phase durations as run client events - #125

Merged
captainsafia merged 3 commits into
mainfrom
feat/worker-setup-phase-client-events
Aug 12, 2026
Merged

feat(worker): report container setup phase durations as run client events#125
captainsafia merged 3 commits into
mainfrom
feat/worker-setup-phase-client-events

Conversation

@captainsafia

@captainsafia captainsafia commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Summary

The worker reports the duration of each setup phase to warp-server as run client events, for the Docker and Kubernetes backends. This closes the observability gap between the oz_run_claimed and worker_container_ready timeline events. Before this change, that window was opaque: the worker sent no signals between the task claim and the first API call from the container.

Changes

  • Add setupEventReporter (internal/worker/setup_events.go). It sends one client event for each completed setup phase to POST /api/v1/agent/runs/{runId}/client-events. It authenticates with the per-task API key and the workload token from the task assignment.
  • Report three phases from the Docker backend:
    • setup_worker_image_pull: the image pull, including the no-op pull when the image is cached.
    • setup_worker_sidecar_prep: the sidecar volume preparation, including the sidecar image pull.
    • setup_worker_container_start: the container create call through the container start call.
  • Report five phases from the Kubernetes backend. The kubelet performs the pulls and the starts, so a tracker (internal/worker/kubernetes_setup_events.go) derives the phases from pod status timestamps delivered by the existing pod watch and safety poll:
    • setup_worker_job_create: the Job create API call, timed directly.
    • setup_worker_pod_schedule: pod creation to the PodScheduled condition. This surfaces node capacity and autoscaler waits.
    • setup_worker_sidecar_prep: the first copy-sidecar-* init container start to the last finish, including the kubelet's sidecar image pulls. Absent in image-volumes mode.
    • setup_worker_setup_command: the setup init container run time, when a setup command is configured.
    • setup_worker_container_start: the end of init (or scheduling) to the task container start, including the kubelet's task image pull.
  • Report each phase on failure with is_error: true. The Kubernetes tracker reports each phase one time; repeated watch deliveries do not duplicate events, and pod-derived timestamps keep latencies accurate when a watch update arrives late.
  • Add the reporter to TaskParams. The field can be nil, and all methods are safe on a nil reporter.
  • Promote github.com/google/uuid to a direct dependency.

Where the data lands

The server ingests each event as a ClientSetupMetricPayload and needs no changes. The events appear in the metrics ambient_agents/client/events and ambient_agents/client/event_latency_ms with timeline_phase="oz_run_claimed", next to the existing setup_* events that the in-container client reports for the later phases.

Notes

  • Reporting is best-effort and asynchronous. A report failure or a slow server does not delay or fail the task.
  • The direct and command backends do not report these events yet. The command backend hands execution to an operator runtime, which can post the same events itself with the credentials in the dispatch payload.
  • Kubernetes pod timestamps have one-second granularity, so very short phases can report 0 ms.

Testing

  • go build ./..., go vet ./..., and go test ./... pass.
  • Unit tests cover the reporter construction gating, the request path, the auth headers, the payload fields, the non-2xx error path, and nil-receiver safety.
  • Kubernetes tracker tests cover the full phase lifecycle with once-only reporting, the image-volumes mode, a failed sidecar init with is_error, the wait for all sidecar init containers, and nil safety.

Conversation: https://staging.warp.dev/conversation/bfa633f7-0c7d-45e4-bd78-f43a0f2865be
Run: https://oz.staging.warp.dev/runs/019ff6db-8344-7d14-93bd-f3b596c0aa85

This PR was generated with Oz.

captainsafia and others added 2 commits August 12, 2026 17:08
…ents

The worker now reports the duration of each Docker setup phase to warp-server. The phases are the image pull, the sidecar preparation, and the container create and start.

The worker sends each phase as a run client event with a setup metric payload. It uses the task API key and the workload token from the task assignment. The server records the events in the metric ambient_agents/client/event_latency_ms with the timeline phase oz_run_claimed. This data shows where the time goes between the claim of a run and the container ready event.

The reports are best-effort and asynchronous. A report failure does not change task execution.

Co-Authored-By: Warp Agent <agent@warp.dev>
…vents

The Kubernetes backend now reports setup phase durations to warp-server. The kubelet performs the image pulls and the container starts for this backend, so the worker derives the phases from pod status timestamps instead of direct measurement.

The backend times the Job create call and reports it as setup_worker_job_create. A tracker inspects each pod snapshot from the pod watch and the safety poll. It reports setup_worker_pod_schedule from pod creation to the PodScheduled condition, setup_worker_sidecar_prep across the copy-sidecar init containers, setup_worker_setup_command for the setup init container, and setup_worker_container_start from the end of init to the task container start.

The tracker reports each phase one time. A failed init container reports its phase with is_error set. Pods without init containers (image-volumes mode) report only the schedule and container start phases.

Co-Authored-By: Warp Agent <agent@warp.dev>

Copy link
Copy Markdown
Contributor Author

This PR was generated with Warp.

View run View conversation

Address review feedback on the setup phase reporting.

Share the task pod container names between the pod-spec construction in kubernetes.go and the phase tracker. Both sides now use the kubernetesTaskContainerName, kubernetesSetupContainerName, and kubernetesSidecarInitPrefix constants, so a container rename cannot silently break phase reporting.

Log a warning when setup event reporting is disabled for a task. The warning states the reason: no server root URL, or no task API key in the assignment env vars. A fleet-wide config or credential change is now visible in the worker logs.

Do not record cancellations as setup errors. The new startPhase and startPhaseIf helpers time each phase and skip the report when the context was cancelled, because a cancelled phase is neither a success nor a failure. The Docker and Kubernetes direct-timing sites now use these helpers.

Skip the Docker sidecar-prep phase for tasks without sidecars, matching the Kubernetes backend, so zero-sidecar tasks do not emit near-zero samples that skew the phase percentiles.

Co-Authored-By: Warp Agent <agent@warp.dev>
@captainsafia
captainsafia marked this pull request as ready for review August 12, 2026 21:06

@vorporeal vorporeal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

yeah sure

@captainsafia
captainsafia merged commit 7fdc307 into main Aug 12, 2026
7 checks passed
@captainsafia
captainsafia deleted the feat/worker-setup-phase-client-events branch August 12, 2026 22:12
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