workerproto

package
v0.2.0-rc2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 20, 2026 License: Apache-2.0 Imports: 8 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package workerproto holds the wire types of worker protocol v1 (docs/contracts/worker-protocol-v1.md, frozen 2026-11-15): frames, codes, limits and the validators both the worker (cmd/dd-worker) and the server hub use. It is plain data: it imports exec for the embedded job types and nothing from store, db, api, jobs, analytics or feedback (boundary_test.go).

Decoding is lenient on unknown keys (encoding/json's default) and strict on required keys: every frame type has Validate, which a receiver calls after Unmarshal and answers with Error{Code: CodeBadFrame} when it fails (§2).

Index

Constants

View Source
const (
	CodeBadFrame      = "bad_frame"
	CodeUnknownType   = "unknown_type"
	CodeFrameTooLarge = "frame_too_large"
	CodeLeaseLost     = "lease_lost"
	CodeSeqGap        = "seq_gap"
	CodeBlobMissing   = "blob_missing"
	CodeNotOwner      = "not_owner"
	CodeInternal      = "internal"
)

Frame error codes (§9).

View Source
const (
	ReasonWorkerUnavailable  = "worker_unavailable" // API 409
	ReasonNoWorker           = "no_worker"          // queued_reason
	ReasonWorkerLost         = "worker_lost"
	ReasonWorkerRestarted    = "worker_restarted"
	ReasonSecretMissing      = "secret_missing"
	ReasonPolicyDenied       = "policy_denied"
	ReasonAdapterUnavailable = "adapter_unavailable"
	ReasonBaseMissing        = "base_missing"
	ReasonLFSMissing         = "lfs_missing" // W3: an LFS repo on a host without git-lfs
	ReasonSpoolFull          = "spool_full"
	ReasonAgentAuth          = "agent_auth"
)

Job reasons: the normative "<code>: " prefix on exec.Done.Line and exec.Status.Error, and the queued reason (§9).

View Source
const (
	CloseNormal                                   = websocket.StatusNormalClosure
	ClosePolicy                                   = websocket.StatusPolicyViolation
	CloseTooBig                                   = websocket.StatusMessageTooBig
	CloseReplaced            websocket.StatusCode = 4000
	CloseRevoked             websocket.StatusCode = 4001
	CloseProtocolUnsupported websocket.StatusCode = 4002
	CloseOrgMismatch         websocket.StatusCode = 4003
)

WebSocket close codes (§1), typed for github.com/coder/websocket, the one WebSocket library both dd-worker and serve use (the maintainers approved it 2026-11-15).

View Source
const (
	PrefixJoinToken  = "dd_wjn_"
	PrefixCredential = "dd_wrk_"
	PrefixJobToken   = "dd_wjt_"
)

Token prefixes (§1, §3, §5.4). Only SHA-256 hashes are stored.

View Source
const (
	PathSocket = "/worker/v1/ws"
	PathPrefix = "/worker/v1/"
)

Paths (§1, §7).

View Source
const (
	MaxFrameBytes        = 1 << 20
	MaxEventBytes        = 768 << 10
	MaxStringFieldBytes  = 256 << 10
	MaxDiffBytes         = 512 << 10
	MaxBatchEvents       = 64
	BatchInterval        = time.Second
	FirstFrameDeadline   = 10 * time.Second
	HeartbeatSec         = 20
	OfflineAfter         = 60 * time.Second
	OfferAnswerTimeout   = 30 * time.Second
	LateAcceptGrace      = 5 * time.Second
	LeaseDuration        = 120 * time.Second
	JobTokenAfterDone    = 10 * time.Minute
	ReadinessRecheck     = 5 * time.Minute
	CancelGrace          = 3 * time.Second
	CancelDeadline       = 5 * time.Second
	RotationInterval     = 30 * 24 * time.Hour
	PendingCredentialTTL = 7 * 24 * time.Hour
	MaxPendingCreds      = 2
	ReplacedBackoffMin   = 60 * time.Second
	ReplacedMaxPer10Min  = 3
	SpoolMaxBytes        = 200 << 20
	SpoolEndedJobTTL     = 24 * time.Hour
	MaxAdapters          = 8
	MaxTools             = 8
	MaxBlobsPerJob       = 200
	MaxBlobBytesPerJob   = 100 << 20
	NoteBlobAbove        = 64 << 10
	BadFramesBeforeClose = 3
	BadFrameWindow       = 60 * time.Second
	FramesPerMinute      = 1000
	UnauthSocketsPerIP   = 3
	EnrolPerIPPerHour    = 10
	UpgradesPerCredMin   = 30
	BlobPutsPerTokenHour = 600
)

Limits (§1, §4–§7, §11).

View Source
const (
	ToolGit = "git"
	ToolGh  = "gh"
)

Tool names a hello or status may report (§4.1).

View Source
const (
	MinGitVersion = "2.32.0"
	MinGhVersion  = "2.0.0"
)

Minimum tool versions; older reports too_old (§4.1). git 2.32 is the first to honour GIT_CONFIG_GLOBAL/GIT_CONFIG_SYSTEM, which the pinned worktree git needs (W3, docs/worker-w3.md §3.5).

View Source
const (
	Version  = 1
	Protocol = 1
)

Version is the envelope's "v" (§1). Protocol is the highest protocol number this build speaks (§4.1).

View Source
const (
	TypeEnroll        = "enroll"
	TypeEnrolled      = "enrolled"
	TypeHello         = "hello"
	TypeHelloOK       = "hello_ok"
	TypePing          = "ping"
	TypePong          = "pong"
	TypeStatus        = "status"
	TypeRotated       = "rotated"
	TypeRotateAck     = "rotate_ack"
	TypeOffer         = "offer"
	TypeAccept        = "accept"
	TypeDecline       = "decline"
	TypeLease         = "lease"
	TypeProgress      = "progress"
	TypeAck           = "ack"
	TypeControl       = "control"
	TypeControlResult = "control_result"
	TypeControlAck    = "control_ack"
	TypeError         = "error"
)

Frame types (§3–§6).

View Source
const (
	ReasonMissing       = "missing"
	ReasonTooOld        = "too_old"
	ReasonSignedOut     = "signed_out"
	ReasonNoKey         = "no_key"
	ReasonUnsupportedOS = "unsupported_os"
)

Adapter not-ready reasons (§4.1).

View Source
const (
	DeclineBusy               = "busy"
	DeclineAdapterUnavailable = "adapter_unavailable"
	DeclinePolicyDenied       = "policy_denied"
	DeclineSecretMissing      = "secret_missing"
	DeclineBadSpec            = "bad_spec"
	DeclineInternal           = "internal"
)

Decline reasons (§5.2).

View Source
const (
	GitAccessRead  = "read"
	GitAccessWrite = "write"
)

Git token access levels.

View Source
const (
	CodeGitHubAppNotConfigured = "github_app_not_configured"
	CodeGitHubNotInstalled     = "github_not_installed"
	CodeRepoNotInstalled       = "repo_not_installed"
	CodeRepoNotGitHub          = "repo_not_github"
	CodeGitHubUnavailable      = "github_unavailable"
)

Error codes of the git-token endpoint and remote start (§14).

View Source
const CapBlobsV1 = "blobs.v1"

Capabilities (§10). Every v1 worker advertises CapBlobsV1.

View Source
const CapGitTokenV1 = "gittoken.v1"

CapGitTokenV1: the worker fetches per-job GitHub tokens from PathGitToken and ships by push only; the server opens PRs (§14).

View Source
const DetailServerLacksGitToken = "server lacks gittoken.v1"

DetailServerLacksGitToken is the bad_spec decline detail from a gittoken.v1 worker whose server did not list the capability.

View Source
const GitTokenPathSuffix = "/git-token"

GitTokenPathSuffix is appended to PathPrefix + "jobs/{job_id}".

View Source
const ReasonNoGitHelper = "no_git_helper"

ReasonNoGitHelper: git has no credential route to github.com (no gh credential helper and no ssh-agent). The other tool reasons are the adapter ones: missing, too_old, signed_out (§4.1).

View Source
const ReasonRepoAuth = "repo_auth"

ReasonRepoAuth prefixes a job or ship failure caused by GitHub auth: "repo_auth: <repo>".

Variables

View Source
var AllowedBlobTypes = []string{"image/png", "image/jpeg", "image/webp", "image/gif", "text/plain"}

AllowedBlobTypes are the content types a blob PUT may carry; the server sniffs magic bytes and refuses a mismatch or SVG with 415 (§7).

View Source
var DefaultAdapterOrder = []string{"claude", "grok", "codex", "antigravity"}

DefaultAdapterOrder applies when the app's agent setting is empty and the host policy sets no order (§5.1, decision at freeze).

Functions

func ValidID

func ValidID(s string) bool

ValidID reports whether s is a valid job, lease, request or worker id (§2): no '.', ':' or '/', so it is safe as a path component.

func ValidModel

func ValidModel(s string) bool

ValidModel reports whether s may be passed to an agent CLI as a model (§6.5).

func ValidRelPath

func ValidRelPath(p string) bool

ValidRelPath reports whether p is a safe relative path (§2): not empty, not absolute, no backslash or NUL, no "." or ".." segment, and every segment made of [A-Za-z0-9._-].

func ValidSHA256

func ValidSHA256(s string) bool

ValidSHA256 reports whether s is 64 lowercase hex characters (§2).

func ValidateTools

func ValidateTools(tools []ToolStatus) error

ValidateTools checks hello's and status's optional tools (§4.1): at most MaxTools entries, each named git or gh.

Types

type Accept

type Accept struct {
	Header
	JobID   string `json:"job_id"`
	LeaseID string `json:"lease_id"`
}

func (Accept) Validate

func (f Accept) Validate() error

type Ack

type Ack struct {
	Header
	JobID string `json:"job_id"`
	Seq   int64  `json:"seq"`
}

Ack is cumulative: everything up to and including Seq.

func (Ack) Validate

func (f Ack) Validate() error

type AdapterStatus

type AdapterStatus struct {
	Name           string `json:"name"`
	Version        string `json:"version"`
	CredentialMode string `json:"credential_mode"`
	Ready          bool   `json:"ready"`
	MinOK          bool   `json:"min_ok"`
	Reason         string `json:"reason,omitempty"`
}

AdapterStatus is one coding-agent CLI's readiness on the host, checked under the exact child env a job would get.

type Control

type Control struct {
	Header
	JobID     string       `json:"job_id"`
	LeaseID   string       `json:"lease_id"`
	RequestID string       `json:"request_id"`
	Control   exec.Control `json:"control"`
	JobToken  string       `json:"job_token,omitempty"`
}

Control carries an exec.Control and, for a resume, a fresh job token.

func (Control) Validate

func (f Control) Validate() error

type ControlAck

type ControlAck struct {
	Header
	JobID     string `json:"job_id"`
	RequestID string `json:"request_id"`
}

type ControlResult

type ControlResult struct {
	Header
	JobID     string          `json:"job_id"`
	RequestID string          `json:"request_id"`
	OK        bool            `json:"ok"`
	Result    json.RawMessage `json:"result,omitempty"`
	Code      string          `json:"code,omitempty"`
	Detail    string          `json:"detail,omitempty"`
}

func (ControlResult) Validate

func (f ControlResult) Validate() error

type Decline

type Decline struct {
	Header
	JobID   string `json:"job_id"`
	LeaseID string `json:"lease_id"`
	Reason  string `json:"reason"`
}

func (Decline) Validate

func (f Decline) Validate() error

type DiffResult

type DiffResult struct {
	Repo      string `json:"repo"`
	Diff      string `json:"diff"`
	Truncated bool   `json:"truncated"`
}

type Enroll

type Enroll struct {
	Header
	Hostname      string `json:"hostname"`
	MachineIDHash string `json:"machine_id_hash"`
	Version       string `json:"version"`
	OS            string `json:"os"`
	Arch          string `json:"arch"`
}

func (Enroll) Validate

func (f Enroll) Validate() error

type Enrolled

type Enrolled struct {
	Header
	WorkerID   string `json:"worker_id"`
	OrgID      string `json:"org_id"`
	Credential string `json:"credential"`
}

Enrolled carries the credential once. Never log it (§11).

type Envelope

type Envelope struct {
	V    int    `json:"v"`
	Type string `json:"type"`
}

Envelope is decoded first to dispatch on Type; the receiver then decodes the same bytes into the frame struct.

type Error

type Error struct {
	Header
	Code     string `json:"code"`
	RefType  string `json:"ref_type,omitempty"`
	Detail   string `json:"detail,omitempty"`
	JobID    string `json:"job_id,omitempty"`
	LeaseID  string `json:"lease_id,omitempty"`
	Expected int64  `json:"expected,omitempty"`
	SHA256   string `json:"sha256,omitempty"`
}

type GitTokenRequest

type GitTokenRequest struct {
	Repo   string `json:"repo"`
	Access string `json:"access"`
}

GitTokenRequest is the body of POST /worker/v1/jobs/{job_id}/git-token.

type GitTokenResponse

type GitTokenResponse struct {
	Token     string `json:"token"`
	ExpiresAt string `json:"expires_at"`
	URL       string `json:"url"`
}

GitTokenResponse never reaches a log, the spool, meta.json or the DB.

type Header struct {
	V    int    `json:"v"`
	Type string `json:"type"`
}

Header is embedded in every frame.

func NewHeader

func NewHeader(t string) Header

NewHeader stamps v and type.

type Hello

type Hello struct {
	Header
	WorkerID     string          `json:"worker_id"`
	Version      string          `json:"version"`
	Protocol     int             `json:"protocol"`
	Capabilities []string        `json:"capabilities"`
	MaxJobs      int             `json:"max_jobs"`
	BusyJobIDs   []string        `json:"busy_job_ids"`
	Adapters     []AdapterStatus `json:"adapters"`
	Tools        []ToolStatus    `json:"tools,omitempty"`
	Policy       Policy          `json:"policy"`
}

func (Hello) Validate

func (f Hello) Validate() error

type HelloOK

type HelloOK struct {
	Header
	Protocol     int      `json:"protocol"`
	HeartbeatSec int      `json:"heartbeat_sec"`
	ServerTime   string   `json:"server_time"`
	Capabilities []string `json:"capabilities"`
}

type Lease

type Lease struct {
	Header
	JobID      string `json:"job_id"`
	LeaseID    string `json:"lease_id"`
	LeaseUntil string `json:"lease_until"`
	JobToken   string `json:"job_token"`
}

Lease grants or re-attaches a lease, with a fresh job token (§5.3).

type Offer

type Offer struct {
	Header
	JobID      string `json:"job_id"`
	LeaseID    string `json:"lease_id"`
	LeaseUntil string `json:"lease_until"`
	Adapter    string `json:"adapter"`
	Model      string `json:"model"`
	Mode       string `json:"mode"`
	SpecURL    string `json:"spec_url"`
	JobToken   string `json:"job_token"`
}

Offer carries a job token. Never log it (§11).

func (Offer) Validate

func (f Offer) Validate() error

type PR

type PR struct {
	Kind     string `json:"kind"`
	Repo     string `json:"repo"`
	Branch   string `json:"branch"`
	Base     string `json:"base"`
	Status   string `json:"status"`
	URL      string `json:"url,omitempty"`
	GHNumber int    `json:"ghNumber,omitempty"`
	GHState  string `json:"ghState,omitempty"`
	Error    string `json:"error,omitempty"`
}

type Ping

type Ping struct {
	Header
	JobIDs []string `json:"job_ids,omitempty"`
}

Ping renews the leases of JobIDs held by this worker (§4.2, §5.3).

type Policy

type Policy struct {
	Valid               bool     `json:"valid"`
	Enabled             bool     `json:"enabled"`
	Orgs                []string `json:"orgs"`
	Adapters            []string `json:"adapters"`
	AllowVerifyCommands bool     `json:"allow_verify_commands"`
	AllowShip           bool     `json:"allow_ship"`
	Repos               []string `json:"repos"`
	MinSandbox          string   `json:"min_sandbox"`
	MaxTurns            int      `json:"max_turns"`
	MaxWallSec          int      `json:"max_wall_sec"`
}

Policy mirrors /etc/dd-worker/policy.toml for scheduling and display. The worker enforces its own copy regardless (§6.5).

type Pong

type Pong struct{ Header }

type Progress

type Progress struct {
	Header
	JobID   string       `json:"job_id"`
	LeaseID string       `json:"lease_id"`
	Seq     int64        `json:"seq"`
	Events  []exec.Event `json:"events"`
}

func (Progress) Validate

func (f Progress) Validate() error

type RotateAck

type RotateAck struct{ Header }

type Rotated

type Rotated struct {
	Header
	Credential string `json:"credential"`
}

Rotated carries a new pending credential. Never log it (§11).

type ShipPreviewRepo

type ShipPreviewRepo struct {
	Repo    string   `json:"repo"`
	Files   []string `json:"files"`
	Message string   `json:"message"`
}

type ShipPreviewResult

type ShipPreviewResult struct {
	Repos []ShipPreviewRepo `json:"repos"`
}

Results of the remote-only controls (§6.3).

type ShipPushRepo

type ShipPushRepo struct {
	Repo    string `json:"repo"`
	Branch  string `json:"branch"`
	Base    string `json:"base"`
	Pushed  bool   `json:"pushed"`
	HeadSHA string `json:"head_sha,omitempty"`
	Error   string `json:"error,omitempty"`
}

type ShipPushResult

type ShipPushResult struct {
	Repos []ShipPushRepo `json:"repos"`
}

ShipPushResult is a ship control_result under gittoken.v1: the worker pushes only, and the server opens or updates the PR per repo.

type ShipResult

type ShipResult struct {
	PRs []PR `json:"prs"`
}

ShipResult's PRs use job.prs[]'s shape (kind "pr" on a worker).

type Status

type Status struct {
	Header
	Adapters   []AdapterStatus `json:"adapters"`
	Tools      []ToolStatus    `json:"tools,omitempty"`
	Policy     Policy          `json:"policy"`
	MaxJobs    int             `json:"max_jobs"`
	BusyJobIDs []string        `json:"busy_job_ids"`
}

type ToolStatus

type ToolStatus struct {
	Name    string `json:"name"`
	Version string `json:"version"`
	Ready   bool   `json:"ready"`
	Reason  string `json:"reason,omitempty"`
}

ToolStatus is one repo tool's readiness on the host (git, gh), checked under the env the worker's own clone and push get. Display only: the server does not schedule on it (§4.1).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL