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
- Variables
- func ModelAllowed(allowed []string, adapter, model string) bool
- func ValidID(s string) bool
- func ValidModel(s string) bool
- func ValidRelPath(p string) bool
- func ValidSHA256(s string) bool
- func ValidateTools(tools []ToolStatus) error
- type Accept
- type Ack
- type AdapterStatus
- type Control
- type ControlAck
- type ControlResult
- type Decline
- type DiffResult
- type Enroll
- type Enrolled
- type Envelope
- type Error
- type GitTokenRequest
- type GitTokenResponse
- type Header
- type Hello
- type HelloOK
- type Lease
- type Offer
- type PR
- type Ping
- type Policy
- type Pong
- type Progress
- type RotateAck
- type Rotated
- type ShipPreviewRepo
- type ShipPreviewResult
- type ShipPushRepo
- type ShipPushResult
- type ShipResult
- type Status
- type ToolStatus
Constants ¶
const ( // ReasonUnsafe: agent_browser is no longer a root-owned regular file // that only root can write. ReasonUnsafe = "unsafe" // ReasonScanIncomplete: the host socket scan hit a limit, so the masked // list may miss a socket. No browser job runs on the host. ReasonScanIncomplete = "scan_incomplete" )
Browser not-ready reasons, besides missing and unsupported_os.
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).
const ( ReasonNoWorker = "no_worker" // queued_reason ReasonWorkerLost = "worker_lost" ReasonWorkerRestarted = "worker_restarted" ReasonSecretMissing = "secret_missing" ReasonPolicyDenied = "policy_denied" 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).
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).
const ( PrefixJoinToken = "dd_wjn_" PrefixCredential = "dd_wrk_" PrefixJobToken = "dd_wjt_" )
Token prefixes (§1, §3, §5.4). Only SHA-256 hashes are stored.
const ( PathSocket = "/worker/v1/ws" PathPrefix = "/worker/v1/" )
Paths (§1, §7).
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 MaxAllowedModels = 16 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).
const ( ToolGit = "git" ToolGh = "gh" )
Tool names a hello or status may report (§4.1).
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).
const ( Version = 1 Protocol = 1 )
Version is the envelope's "v" (§1). Protocol is the highest protocol number this build speaks (§4.1).
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).
const ( ReasonMissing = "missing" ReasonTooOld = "too_old" ReasonSignedOut = "signed_out" ReasonNoKey = "no_key" ReasonUnsupportedOS = "unsupported_os" )
Adapter not-ready reasons (§4.1).
const ( DeclineBusy = "busy" DeclinePolicyDenied = "policy_denied" DeclineSecretMissing = "secret_missing" DeclineBadSpec = "bad_spec" DeclineInternal = "internal" // DeclineModelNotAllowed: the job's model is not in the host's policy // allowed_models. Additive in 0.2.0-rc4. DeclineModelNotAllowed = "model_not_allowed" )
Decline reasons (§5.2).
const ( GitAccessRead = "read" GitAccessWrite = "write" )
Git token access levels.
const ( CodeGitHubAppNotConfigured = "github_app_not_configured" CodeGitHubNotInstalled = "github_not_installed" CodeRepoNotInstalled = "repo_not_installed" CodeRepoNotGitHub = "repo_not_github" )
Error codes of the git-token endpoint and remote start (§14).
const ( // ReasonSubmittedRefMissing: the remote has no such ref, or a SHA ref // did not resolve to that commit. Line: "submitted_ref_missing: <repo> <ref>". ReasonSubmittedRefMissing = "submitted_ref_missing" // ReasonNoMergeBase: the submitted commit shares no history with the // base. Line: "no_merge_base: <repo> <ref>". ReasonNoMergeBase = "no_merge_base" )
Job reasons (§9) a verify_submitted run can fail with before any check.
const CapBlobsV1 = "blobs.v1"
Capabilities (§10). Every v1 worker advertises CapBlobsV1.
const CapBrowserV1 = "browser.v1"
CapBrowserV1: the worker understands JobSpec.App.browser, previewCmd, previewUrl and agentHosts. Whether its browser is ready is the "browser" tool's readiness, not this capability.
const CapGitTokenV1 = "gittoken.v1"
CapGitTokenV1: the worker fetches per-job GitHub tokens from PathGitToken and ships by push only; the server opens PRs (§14).
const CapVerifySubmittedV1 = "verify_submitted.v1"
CapVerifySubmittedV1: the worker understands JobSpec.mode "verify_submitted", JobSpec.submittedRefs and Status.submittedHeads.
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.
const GitTokenPathSuffix = "/git-token"
GitTokenPathSuffix is appended to PathPrefix + "jobs/{job_id}".
const MaxMaskedSockets = 128
MaxMaskedSockets bounds policy.masked_sockets on the wire.
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).
const ReasonRepoAuth = "repo_auth"
ReasonRepoAuth prefixes a job or ship failure caused by GitHub auth: "repo_auth: <repo>".
const ToolBrowser = "browser"
ToolBrowser is the tools[] entry for the host's headless browser (policy agent_browser). A worker sends it only when the policy sets agent_browser: a server before browser.v1 refuses the name (ValidateTools).
Variables ¶
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).
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 ModelAllowed ¶
ModelAllowed is the allowed_models rule, shared by the worker (which enforces it) and a scheduler (which can skip a worker that would decline). A nil or empty list allows any model. Otherwise the model must be listed exactly (case-sensitive; an alias such as "sonnet" does not cover a full "claude-…" id). An empty model, the CLI's own default, is refused for the adapters that take a model and allowed for grok, which has none.
func ValidID ¶
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 ¶
ValidModel reports whether s may be passed to an agent CLI as a model (§6.5).
func ValidRelPath ¶
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 ¶
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, gh or browser.
Types ¶
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.
type ControlAck ¶
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 DiffResult ¶
type Enroll ¶
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 ¶
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 ¶
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 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"`
}
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).
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 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"`
// Additive in 0.2.0-rc3 (worker browser, B4): the host's ceiling for
// display. AllowedDomains is policy agent_allowed_domains, MaxCostUSD
// policy max_cost_usd (0: unset), Browser policy agent_browser ("": off)
// and MaskedSockets the host sockets a browser job's sandbox hides.
AllowedDomains []string `json:"allowed_domains"`
MaxCostUSD int `json:"max_cost_usd"`
Browser string `json:"browser"`
MaskedSockets []string `json:"masked_sockets"`
// Additive in 0.2.0-rc4: policy allowed_models, the models a job may
// run on (at most MaxAllowedModels, exact names). Absent: any model.
AllowedModels []string `json:"allowed_models,omitempty"`
}
Policy mirrors /etc/dd-worker/policy.toml for scheduling and display. The worker enforces its own copy regardless (§6.5).
type Progress ¶
type ShipPreviewRepo ¶
type ShipPreviewResult ¶
type ShipPreviewResult struct {
Repos []ShipPreviewRepo `json:"repos"`
}
Results of the remote-only controls (§6.3).
type ShipPushRepo ¶
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).