jobs

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2026 License: MIT Imports: 17 Imported by: 0 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 jobs creates and observes the ephemeral Kubernetes Jobs that run agent-runner: one Job per issue attempt, deterministically named, labelled so orphans can be reaped, and garbage collected via TTL plus an owner-referenced per-Job Secret.

The Job shape carries the isolation model: the short-lived GitHub token reaches only the init container (which clones the repository and then strips credentials from the clone), while the agent container gets the model API key and PATCHY_* configuration but no GitHub credentials at all — the remediation-controller owns every GitHub side effect. Results come back on the agent container's stdout as envelope events, followed live and re-read at completion as the idempotent fallback.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Name

func Name(repo string, issue, attempt int) string

Name is the deterministic Job (and per-Job Secret) name for one attempt: patchy-<repohash>-i<issue>-a<attempt>. Always DNS-1123 safe and <=63 chars — the repo appears only as a hash, the true owner/name lives in the annotation.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client creates and observes agent Jobs in one namespace.

func New

func New(cs kubernetes.Interface, cfg Config, log *slog.Logger) *Client

New builds a Client, applying Config defaults.

func (*Client) Create

func (c *Client) Create(ctx context.Context, spec Spec) (string, error)

Create builds and creates the per-Job Secret (token + issue markdown), then the Job itself, then owner-references the Secret to the Job so it is garbage collected with it. Returns the Job name.

func (*Client) Delete

func (c *Client) Delete(ctx context.Context, jobName string) error

Delete removes a Job and its pods (propagation: background).

func (*Client) Follow

func (c *Client) Follow(ctx context.Context, jobName string, fn func(envelope.Event) error) error

Follow streams the agent container's stdout, decoding envelope events and delivering them to fn as they arrive. It returns when the pod's log stream ends. If the log stream cannot be opened or breaks, the caller falls back to Result.

func (*Client) List

func (c *Client) List(ctx context.Context) ([]Owned, error)

List returns the Jobs patchy owns in the namespace — used to reap orphans.

func (*Client) Result

func (c *Client) Result(ctx context.Context, jobName string) ([]envelope.Event, error)

Result reads the completed Job's full logs and returns every envelope event found — the idempotent fallback/reconciliation path.

func (*Client) Status

func (c *Client) Status(ctx context.Context, jobName string) (Status, error)

Status reports the named Job's state.

type Config

type Config struct {
	Namespace          string        // where Jobs run, e.g. "patchy-agents"
	Image              string        // agent-runner image
	ServiceAccount     string        // pod service account
	Deadline           time.Duration // activeDeadlineSeconds
	TTL                time.Duration // ttlSecondsAfterFinished
	AnthropicSecret    string        // name of the Secret holding the model credential
	AnthropicSecretKey string        // key within it (default "api-key")
	// AnthropicSecretEnv is the env var the credential is injected into the
	// agent container as: ANTHROPIC_API_KEY (the default) for an API key, or
	// CLAUDE_CODE_OAUTH_TOKEN for a `claude setup-token` OAuth token.
	AnthropicSecretEnv string
	// Env is extra PATCHY_* configuration passed through to every runner
	// (models, timeouts, ceilings, thresholds, harness selection).
	Env map[string]string
	// Resource strings (Kubernetes quantities), optional.
	CPURequest, MemoryRequest, CPULimit, MemoryLimit string
}

Config configures Job creation.

type Owned

type Owned struct {
	Name    string
	Repo    string
	Issue   int
	Attempt int
	Status  Status
}

Owned is one Job patchy created, with the issue it belongs to parsed back out of its labels and annotations.

type Spec

type Spec struct {
	Repo     string // "owner/name"
	Issue    int
	Attempt  int
	Phase    string // agentrun phase: "classify+remediate" | "remediate"
	CloneURL string // https URL of the repo
	// BaseSHA is the default branch's head at Job creation; the clone is
	// pinned to it and the agent's commit parents it.
	BaseSHA string
	// Token is the short-lived scoped GitHub token; it reaches the init
	// container only, via the per-Job Secret.
	Token         string
	IssueMarkdown string // the issue handoff file content
	// ClassificationMarkdown is optional: the /approve remediate-only re-run.
	ClassificationMarkdown string
}

Spec is one agent Job to create.

type Status

type Status struct {
	Active    int32
	Succeeded int32
	Failed    int32
	// Done means the Job reached a terminal condition (Complete or Failed).
	Done bool
}

Status reports a Job's state.

Jump to

Keyboard shortcuts

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