Documentation
¶
Overview ¶
Package remediation is the remediation-controller's engine — three reconcilers over the Finding/Remediation kinds:
The spawner is the queue-admission writer: it turns approvals and revivals into Queued findings and materializes one immutable, Pending Remediation child per attempt, stamped with its scheduling priority (internal/priority). The remediation reconciler grants bounded slots to pending remediations in priority order (internal/schedule), launches the coding agent in an ephemeral Kubernetes Job, and applies the result when the Job completes: on success it replays the agent's changeset through the forge write seam (internal/forge + internal/ghpush — the only holder of a forge write credential) and opens the pull request; on failure it re-queues or exhausts the finding. Merging stays human; the merge webhook (integration-controller) completes the finding.
The binary also hosts internal/controller/rollup — the all-time statistics aggregation and the finding TTL.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CRRunner ¶
type CRRunner interface {
Create(ctx context.Context, spec jobs.Spec) (string, error)
Result(ctx context.Context, jobName string) ([]envelope.Event, error)
Status(ctx context.Context, jobName string) (jobs.Status, error)
Delete(ctx context.Context, jobName string) error
}
CRRunner is the slice of the jobs client the CRD-native remediation engine needs (distinct name: the legacy Runner interface lives in controller.go until the cutover).
type ForgeWriter ¶
type ForgeWriter interface {
// Push replays the changeset as branch on the repository.
Push(ctx context.Context, namespace, repoURL, branch string, cs *envelope.Changeset) error
// EnsurePR opens (or finds, idempotently by head branch) the pull
// request for branch.
EnsurePR(ctx context.Context, namespace, repoURL, branch, title, body string) (number int64, url string, err error)
}
ForgeWriter performs the two forge writes remediation owns: the branch push (Git Data API, scoped write token) and the pull request. It wraps internal/forge + internal/ghpush; tests substitute a fake.
func NewForgeWriter ¶
func NewForgeWriter(forges *forge.Store) ForgeWriter
NewForgeWriter builds the production ForgeWriter over the shared forge store.
type RemediationReconciler ¶
type RemediationReconciler struct {
client.Client
// Runner creates and observes agent Jobs.
Runner CRRunner
// Forge performs the branch push and PR creation.
Forge ForgeWriter
// Namespace the CRs live in.
Namespace string
// MaxConcurrent bounds simultaneously running remediations (default 1).
MaxConcurrent int
// MaxAttempts bounds remediation attempts per finding.
MaxAttempts int32
// Aging lifts long-waiting remediations.
Aging schedule.AgingPolicy
// Enabled is the set of harness ids this deployment can run. launch
// re-checks the spawner-resolved harness against it, so an enabled-set
// change between spawn and launch fails the run cleanly instead of
// creating an unrunnable Job.
Enabled []string
// Now is the clock seam; nil means time.Now.
Now func() time.Time
// Log receives diagnostics; nil discards.
Log *slog.Logger
}
RemediationReconciler grants bounded slots to pending remediations in priority order, launches the agent Job, and applies results: push + PR on success, retry or exhaustion on failure.
func (*RemediationReconciler) Reconcile ¶
func (r *RemediationReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error)
Reconcile handles the singleton scheduler request and per-object runs.
func (*RemediationReconciler) SetupWithManager ¶
func (r *RemediationReconciler) SetupWithManager(mgr ctrl.Manager) error
SetupWithManager wires the reconciler and its scheduler fan-in.
type SpawnerReconciler ¶
type SpawnerReconciler struct {
client.Client
// Namespace the CRs live in.
Namespace string
// Weights tune the scheduling-priority computation.
Weights priority.Weights
// Enabled is the set of harness ids this deployment can run (those with a
// credential). Allowlist is the canonical model ids the investigation may
// suggest; DefaultModel is the fallback when the suggestion is unusable.
// Together they resolve the investigation's chosen model to the harness
// (and thus the runner image + credential) the Remediation will run on.
Enabled []string
Allowlist []string
DefaultModel string
// AutoMaxTurns/AutoTokenBudget is what patchy spends unattended: the
// budget every remediation is entitled to, and the line past which an
// estimate needs human approval. These must match the runner's
// PATCHY_REMEDIATE_AUTO_* configuration — the pod re-derives the same
// floor, so a mismatch merely wastes the larger of the two rather than
// misbehaving.
AutoMaxTurns int32
AutoTokenBudget int64
// ManualMaxTurns/ManualTokenBudget bound what a human approval can grant.
ManualMaxTurns int32
ManualTokenBudget int64
// Now is the clock seam; nil means time.Now.
Now func() time.Time
// Log receives diagnostics; nil discards.
Log *slog.Logger
}
SpawnerReconciler is the queue-admission writer: it turns approvals and revivals into Queued findings (edges 10 and 18) and materializes one Pending Remediation per attempt for every Queued finding, stamped with its scheduling priority.
func (*SpawnerReconciler) SetupWithManager ¶
func (r *SpawnerReconciler) SetupWithManager(mgr ctrl.Manager) error
SetupWithManager wires the spawner.