refactor!: remove the diff-size cap and its gate.diff-size step

This commit is contained in:
sam committed 2026-10-24 22:19:23 +11:00
1 parent e577b48860
commit 7abc816735
20 files changed
+132 -241

No files matched your search

@@ -97,10 +97,6 @@ func (h *hybridTrees) Snapshot(ctx context.Context, dir, destDir string) error {
return h.local.Snapshot(ctx, dir, destDir)
}
func (h *hybridTrees) ChangedLines(ctx context.Context, dir, base string) (int, error) {
return h.local.ChangedLines(ctx, dir, base)
}
// ChangedFileStats forwards to the local worktree manager.
func (h *hybridTrees) ChangedFileStats(ctx context.Context, dir, base string) (task.ChangeStats, error) {
return h.local.ChangedFileStats(ctx, dir, base)
+6 -7
View File
@@ -110,13 +110,12 @@ var reloadableFields = map[string]bool{
// Per-task snapshot: ForTask carries these into every dispatched
// TaskContext (config.go ForTask), built fresh from d.Cfg.Get() at
// dispatch.
"DiffCapLines": true,
"Budgets": true,
"Dispatch": true,
"Models": true,
"ModelLimits": true,
"Notify": true,
"Review": true,
"Budgets": true,
"Dispatch": true,
"Models": true,
"ModelLimits": true,
"Notify": true,
"Review": true,
// Poll loops read the dispatch label each cycle.
"Label": true,
// MaxRetries has two consumers, both re-reading it: the webui maxRetriesFor
@@ -132,7 +132,6 @@ func runtimeToolConfigFrom(ctx context.Context, reader controlplanerpc.ResourceR
if err := layerResourceJSON(ctx, reader, versions, TaskPolicyKind, &policy); err != nil {
return config.Config{}, nil, err
}
out.DiffCapLines = new(policy.DiffCapLines)
out.Notify = config.Notify{Webhook: policy.NotifyWebhook, MinSeverity: policy.NotifyMinSeverity, Secret: policy.NotifySecret}
if err := layerResource(ctx, reader, versions, ToolSettingsKind, func(settings toolSettings) error {
+1 -5
View File
@@ -11,7 +11,6 @@ import (
const TaskPolicyKind = "task-policy"
type taskPolicy struct {
DiffCapLines int `json:"diff_cap_lines"`
NotifyWebhook string `json:"notify_webhook"`
NotifyMinSeverity string `json:"notify_min_severity"`
NotifySecret config.SecretRef `json:"notify_secret"`
@@ -22,9 +21,6 @@ func taskPolicyDefinition() Definition {
return taskPolicyOf(cfg)
}, Validate: func(input []byte) error {
return validateAs(input, func(doc taskPolicy) error {
if doc.DiffCapLines < 0 {
return fmt.Errorf("diff_cap_lines must not be negative")
}
if doc.NotifyWebhook != "" {
parsed, err := url.Parse(doc.NotifyWebhook)
if err != nil || parsed.Host == "" || (parsed.Scheme != "http" && parsed.Scheme != "https") {
@@ -44,7 +40,7 @@ func taskPolicyDefinition() Definition {
func taskPolicyOf(cfg config.Config) taskPolicy {
return taskPolicy{
DiffCapLines: cfg.DiffCap(), NotifyWebhook: cfg.Notify.Webhook,
NotifyWebhook: cfg.Notify.Webhook,
NotifyMinSeverity: cfg.Notify.MinSeverity, NotifySecret: cfg.Notify.Secret,
}
}
+23 -50
View File
@@ -394,11 +394,7 @@ type Config struct {
IdentityGrants map[string][]string `toml:"-" yaml:"-" json:"-"`
// BotEmail is the git author email; defaults to the GitHub noreply
// address for BotUser.
BotEmail string `toml:"bot_email" yaml:"bot_email"`
// DiffCapLines parks a task whose diff exceeds this many changed lines. Nil
// takes the default; 0 means no cap. Read it with DiffCap.
DiffCapLines *int `toml:"diff_cap_lines" yaml:"diff_cap_lines"`
BotEmail string `toml:"bot_email" yaml:"bot_email"`
Forge Forge `toml:"forge" yaml:"forge"`
Dispatch Dispatch `toml:"dispatch" yaml:"dispatch"`
@@ -483,19 +479,10 @@ type TaskConfig struct {
// (remediate's round cap via Repo.EffectiveMaxRetries). It is carried to the
// worker for the same reason as Budgets: the stage that enforces it runs
// inside archie-agent, not the daemon.
MaxRetries int `json:"max_retries"`
Dispatch Dispatch `json:"dispatch"`
DiffCapLines int `json:"diff_cap_lines"`
Forge TaskForge `json:"forge"`
ToolPolicy ToolPolicy `json:"tool_policy"`
}
// DiffCap returns the changed-line cap; 0 means no cap.
func (c Config) DiffCap() int {
if c.DiffCapLines == nil {
return 0
}
return *c.DiffCapLines
MaxRetries int `json:"max_retries"`
Dispatch Dispatch `json:"dispatch"`
Forge TaskForge `json:"forge"`
ToolPolicy ToolPolicy `json:"tool_policy"`
}
// TaskForge is the non-secret forge configuration needed by workflow stages.
@@ -507,16 +494,15 @@ type TaskForge struct {
// needed to run a workflow.
func (c Config) ForTask() TaskConfig {
return TaskConfig{
BotUser: c.BotUser,
BotEmail: c.BotEmail,
Models: cloneStringMap(c.Models),
ModelLimits: c.aliasedModelLimits(),
Budgets: c.Budgets,
MaxRetries: c.MaxRetries,
Dispatch: Dispatch{Trigger: c.Dispatch.Trigger, AckReaction: c.Dispatch.AckReaction},
DiffCapLines: c.DiffCap(),
Forge: TaskForge{Host: c.Forge.Host},
ToolPolicy: c.Tools.Policy,
BotUser: c.BotUser,
BotEmail: c.BotEmail,
Models: cloneStringMap(c.Models),
ModelLimits: c.aliasedModelLimits(),
Budgets: c.Budgets,
MaxRetries: c.MaxRetries,
Dispatch: Dispatch{Trigger: c.Dispatch.Trigger, AckReaction: c.Dispatch.AckReaction},
Forge: TaskForge{Host: c.Forge.Host},
ToolPolicy: c.Tools.Policy,
}
}
@@ -542,16 +528,15 @@ func (c Config) aliasedModelLimits() map[string]ModelLimits {
// workflow stages read via TaskContext.Cfg.
func (tc TaskConfig) ToConfig() Config {
return Config{
BotUser: tc.BotUser,
BotEmail: tc.BotEmail,
Models: cloneStringMap(tc.Models),
ModelLimits: maps.Clone(tc.ModelLimits),
Budgets: tc.Budgets,
MaxRetries: tc.MaxRetries,
Dispatch: Dispatch{Trigger: tc.Dispatch.Trigger, AckReaction: tc.Dispatch.AckReaction},
DiffCapLines: &tc.DiffCapLines,
Forge: Forge{Host: tc.Forge.Host},
Tools: ToolsConfig{Policy: tc.ToolPolicy},
BotUser: tc.BotUser,
BotEmail: tc.BotEmail,
Models: cloneStringMap(tc.Models),
ModelLimits: maps.Clone(tc.ModelLimits),
Budgets: tc.Budgets,
MaxRetries: tc.MaxRetries,
Dispatch: Dispatch{Trigger: tc.Dispatch.Trigger, AckReaction: tc.Dispatch.AckReaction},
Forge: Forge{Host: tc.Forge.Host},
Tools: ToolsConfig{Policy: tc.ToolPolicy},
}
}
@@ -583,21 +568,9 @@ func (c Config) Clone() Config {
v := *c.Tools.WebFetch.Enabled
c.Tools.WebFetch.Enabled = &v
}
c.DiffCapLines = cloneIntPtr(c.DiffCapLines)
return c
}
// cloneIntPtr copies an optional int so a clone cannot write through to the
// original. Optional ints carry a real meaning in their zero value (see
// DiffCapLines), which is why they are pointers in the first place.
func cloneIntPtr(v *int) *int {
if v == nil {
return nil
}
n := *v
return &n
}
func cloneRepos(repos []Repo) []Repo {
if repos == nil {
return nil
+1 -1
View File
@@ -301,7 +301,7 @@ var modelFreeStepTypes = map[string]bool{
CloseIssueStepName: true, CommentStepName: true, CommandRunStepName: true,
WorkflowCallStepName: true, RepoPrepareStepName: true, RepoToolingStepName: true,
RepoCommitStepName: true,
RepoOpenPRStepName: true, GateRepositoryName: true, GateDiffSizeStepName: true, DiffRulesStepName: true,
RepoOpenPRStepName: true, GateRepositoryName: true, DiffRulesStepName: true,
}
// UsesModel reports whether a pinned definition has any step that may call a
-9
View File
@@ -18,7 +18,6 @@ const (
RepoCommitStepName = "repo.commit"
RepoOpenPRStepName = "repo.open-pr"
GateRepositoryName = "gate.repository"
GateDiffSizeStepName = "gate.diff-size"
repoBranchTask = "task"
gateExpectTestFailure = "test-failure"
)
@@ -31,14 +30,6 @@ func RepoStepTypes() []StepType {
{Name: RepoCommitStepName, Factory: newRepoCommitStage, Settings: repoCommitSettings{}},
{Name: RepoOpenPRStepName, Factory: newRepoOpenPRStage, Settings: repoOpenPRSettings{}},
{Name: GateRepositoryName, Factory: newGateRepositoryStage, Settings: gateRepositorySettings{}},
{Name: GateDiffSizeStepName, Factory: func(settings yaml.Node) (Stage, error) {
if err := noSettings(GateDiffSizeStepName, settings); err != nil {
return Stage{}, err
}
stage := StageDiffCap()
stage.Name = GateDiffSizeStepName
return stage, nil
}},
}
}
@@ -39,7 +39,6 @@ steps:
reference: Implements
push: true
if_empty: complete
- type: gate.diff-size
- type: repo.open-pr
settings:
review: true
@@ -61,7 +61,6 @@ steps:
message: "fix: {{ task.title }} (archie)"
reference: Fixes
push: true
- type: gate.diff-size
- type: repo.open-pr
settings:
body: "{{ steps.fix.summary }}"
-25
View File
@@ -137,31 +137,6 @@ func closeNoChangesIssue(ctx context.Context, tc *TaskContext) error {
return nil
}
// StageDiffCap parks tasks whose diff exceeds the configured line cap --
// oversized changes need human pre-approval, not an auto-opened PR.
func StageDiffCap() Stage {
return Stage{Name: "diff-cap", Run: func(ctx context.Context, tc *TaskContext) error {
capLines := tc.Cfg.DiffCap()
if capLines <= 0 {
return nil
}
lines, err := tc.Trees.ChangedLines(ctx, tc.Dir, tc.Repo.BaseBranch())
if err != nil {
return err
}
if lines > capLines {
// No "approve" here: a parked task's operator actions are retry,
// abandon and reject (internal/taskstate), so telling the operator
// to approve sent them looking for a button that does not exist.
tc.Outcome = Outcome{
Status: StatusParked,
Detail: fmt.Sprintf("diff is %d changed lines (cap %d) -- split the issue, or raise diff_cap_lines and retry", lines, capLines),
}
}
return nil
}}
}
// OpenPR opens the task's pull request, records its number, and sets
// the terminal pr_open outcome. Stages that need to act after the PR
// exists (e.g. posting evidence comments) call this and then do so in
-1
View File
@@ -75,7 +75,6 @@ type Trees interface {
Push(ctx context.Context, dir, branch string) error
Diff(ctx context.Context, dir, base string) (string, error)
ChangedFiles(ctx context.Context, dir, base string) ([]string, error)
ChangedLines(ctx context.Context, dir, base string) (int, error)
// Snapshot exports HEAD's tracked files into destDir with no.git directory
// -- no commit history, branch name, or reflog. Used to build the
// reviewer's isolated workspace.
@@ -13,7 +13,6 @@ import (
// without reading the code that applies it.
const (
defaultPollInterval = 60 * time.Second
defaultDiffCapLines = 400
defaultWebListen = "127.0.0.1:8484" // "off" disables
defaultMaxRetries = 3
defaultForgeType = "github"
@@ -209,12 +208,6 @@ func (l *Loader) applyGeneralDefaults(cfg *config.Config) {
if cfg.PollInterval == 0 {
cfg.PollInterval = config.Duration(defaultPollInterval)
}
// Only an absent key takes the default. An explicit 0 is the documented
// way to switch the cap off and must survive.
if cfg.DiffCapLines == nil {
capLines := defaultDiffCapLines
cfg.DiffCapLines = &capLines
}
if cfg.Web.Listen == "" {
cfg.Web.Listen = defaultWebListen
}
-14
View File
@@ -630,20 +630,6 @@ func (m *Manager) HasUncommittedChanges(ctx context.Context, dir string) (bool,
return !status.IsClean(), nil
}
// ChangedLines reports lines added+deleted vs the base branch -- the
// input to the diff-size cap.
func (m *Manager) ChangedLines(ctx context.Context, dir, base string) (int, error) {
p, err := m.patch(ctx, dir, base)
if err != nil {
return 0, err
}
total := 0
for _, stat := range p.Stats() {
total += stat.Addition + stat.Deletion
}
return total, nil
}
// Diff returns the unified diff of all committed changes against base.
func (m *Manager) Diff(ctx context.Context, dir, base string) (string, error) {
p, err := m.patch(ctx, dir, base)