From 9b40fa7f87bc12994ba326eacd73048512a8bfbe Mon Sep 17 00:00:00 2001 From: Sam Catlow Date: Fri, 2 Oct 2026 12:33:54 +1000 Subject: [PATCH] fix(config): carry max_retries into the worker TaskConfig snapshot The remediate round cap runs inside archie-agent and reads TaskContext.Cfg.MaxRetries, but TaskConfig did not carry the global Config.MaxRetries: ForTask and ToConfig both dropped it, so a default configuration reached the cap as 0 and a remediation never parked. Carry the value (a repo-level override still wins via EffectiveMaxRetries) and pin it with a red-first cap test traced through ForTask/ToConfig. Refs: archie-core-ad3p --- .../skills/archie-config-and-flags/SKILL.md | 5 ++-- internal/app/archied/reload.go | 12 ++++---- internal/config/config.go | 29 ++++++++++++------- internal/config/config_test.go | 4 ++- internal/daemon/daemon_test.go | 2 +- internal/domain/workflow/remediate_test.go | 29 +++++++++++++++++++ 6 files changed, 61 insertions(+), 20 deletions(-) diff --git a/.agents/skills/archie-config-and-flags/SKILL.md b/.agents/skills/archie-config-and-flags/SKILL.md index 87eca6959..77e23674a 100644 --- a/.agents/skills/archie-config-and-flags/SKILL.md +++ b/.agents/skills/archie-config-and-flags/SKILL.md @@ -225,8 +225,9 @@ Classify multi-identity changes field by field. Never label aggregate ## Preserve worker and secret boundaries -`Config.ForTask` creates a detached root snapshot: models, budgets, dispatch, -diff cap, notification, and forge host. `TaskConfig.ToConfig` reconstructs +`Config.ForTask` creates a detached root snapshot: models, budgets, the +retry/remediation cap (`MaxRetries`), dispatch, diff cap, notification, and +forge host. `TaskConfig.ToConfig` reconstructs only those fields. Forge tokens, provider values, NATS credential references, repos, and infrastructure settings do not enter `TaskConfig`. diff --git a/internal/app/archied/reload.go b/internal/app/archied/reload.go index 6f43202f0..93a8dc7c5 100644 --- a/internal/app/archied/reload.go +++ b/internal/app/archied/reload.go @@ -135,11 +135,13 @@ var reloadableFields = map[string]bool{ // TestReloadableFieldsCoverForTaskSnapshot. "Label": true, "BotUser": true, - // Worked example of the every-consumer criterion above: the sole - // consumer is the webui maxRetriesFor handler (api_tasks.go:380,383), - // which re-reads per request; the daemon never reads MaxRetries. The - // per-task half of this list is pinned mechanically; this webui-only - // entry is pinned by TestChangedNonReloadableFields. + // MaxRetries has two consumers, both re-reading it: the webui + // maxRetriesFor handler (api_tasks.go:380,383) reads it per request, and + // ForTask carries it into every dispatched TaskConfig, where the + // container's remediation round cap reads it (StageRemediationRoundCap). + // The per-task half of this list is pinned mechanically by + // TestReloadableFieldsCoverForTaskSnapshot; the webui-only entry is pinned + // by TestChangedNonReloadableFields. "MaxRetries": true, // Tools.Policy (MaxResultChars/SpillDir) is carried into TaskConfig by // ForTask (config.go) and applied fresh per dispatch via diff --git a/internal/config/config.go b/internal/config/config.go index 04f57afe8..49788524a 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -610,17 +610,22 @@ type ModelLimits struct { type TaskConfig struct { // BotUser and BotEmail are non-secret commit attribution carried to the // sandbox because the worker owns local deterministic commits. - BotUser string `json:"bot_user"` - BotEmail string `json:"bot_email"` - Models map[string]string `json:"models"` - ModelLimits map[string]ModelLimits `json:"model_limits,omitempty"` - Budgets Budgets `json:"budgets"` - Dispatch Dispatch `json:"dispatch"` - DiffCapLines int `json:"diff_cap_lines"` - Notify Notify `json:"notify"` - Forge TaskForge `json:"forge"` - ToolPolicy ToolPolicy `json:"tool_policy"` - Review Review `json:"review"` + BotUser string `json:"bot_user"` + BotEmail string `json:"bot_email"` + Models map[string]string `json:"models"` + ModelLimits map[string]ModelLimits `json:"model_limits,omitempty"` + Budgets Budgets `json:"budgets"` + // MaxRetries is the global retry/remediation cap workflow stages read + // (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"` + Notify Notify `json:"notify"` + Forge TaskForge `json:"forge"` + ToolPolicy ToolPolicy `json:"tool_policy"` + Review Review `json:"review"` } // DiffCapOf returns a DiffCapLines value for n. It exists because the field is @@ -656,6 +661,7 @@ func (c Config) ForTask() TaskConfig { Models: cloneStringMap(c.Models), ModelLimits: maps.Clone(c.ModelLimits), Budgets: c.Budgets, + MaxRetries: c.MaxRetries, Dispatch: Dispatch{Trigger: c.Dispatch.Trigger, AckReaction: c.Dispatch.AckReaction, Labels: cloneStringMap(c.Dispatch.Labels)}, DiffCapLines: c.DiffCap(), Notify: c.Notify, @@ -676,6 +682,7 @@ func (tc TaskConfig) ToConfig() Config { 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, Labels: cloneStringMap(tc.Dispatch.Labels)}, DiffCapLines: &tc.DiffCapLines, Notify: tc.Notify, diff --git a/internal/config/config_test.go b/internal/config/config_test.go index 489ae57db..457e401d9 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -143,6 +143,7 @@ func TestConfigForTaskJSONRoundTrip(t *testing.T) { WallClock: Duration(45 * time.Minute), GateMaxFailures: 3, }, + MaxRetries: 7, Dispatch: Dispatch{ Trigger: "label", AckReaction: "eyes", @@ -167,6 +168,7 @@ func TestConfigForTaskJSONRoundTrip(t *testing.T) { BotEmail: cfg.BotEmail, Models: cfg.Models, Budgets: cfg.Budgets, + MaxRetries: cfg.MaxRetries, Dispatch: cfg.Dispatch, DiffCapLines: cfg.DiffCap(), Notify: cfg.Notify, @@ -199,7 +201,7 @@ func TestConfigForTaskJSONRoundTrip(t *testing.T) { if err != nil { t.Fatal(err) } - assertJSONKeys(t, data, "bot_user", "bot_email", "models", "budgets", "dispatch", "diff_cap_lines", "notify", "forge", "tool_policy", "review") + assertJSONKeys(t, data, "bot_user", "bot_email", "models", "budgets", "max_retries", "dispatch", "diff_cap_lines", "notify", "forge", "tool_policy", "review") var forgePayload map[string]json.RawMessage var payload map[string]json.RawMessage diff --git a/internal/daemon/daemon_test.go b/internal/daemon/daemon_test.go index 31187b55e..e4d56c6ea 100644 --- a/internal/daemon/daemon_test.go +++ b/internal/daemon/daemon_test.go @@ -2098,7 +2098,7 @@ func TestDispatchCapturesTheAttemptsEffectiveConfig(t *testing.T) { // repositories, identities or lock state. wantKeys := []string{ "bot_email", "bot_user", "budgets", "diff_cap_lines", "dispatch", - "forge", "model_limits", "models", "notify", "review", "tool_policy", + "forge", "max_retries", "model_limits", "models", "notify", "review", "tool_policy", } gotKeys := make([]string, 0, len(doc)) for key := range doc { diff --git a/internal/domain/workflow/remediate_test.go b/internal/domain/workflow/remediate_test.go index 0b022d7b8..32a72182e 100644 --- a/internal/domain/workflow/remediate_test.go +++ b/internal/domain/workflow/remediate_test.go @@ -98,6 +98,35 @@ func TestStageRemediationRoundCapZeroMeansUnlimited(t *testing.T) { } } +// TestStageRemediationRoundCapReadsTheWorkerCarriedGlobalCap pins the cap's +// value across the daemon/worker boundary. The round cap runs inside +// archie-agent, so a default configuration (no per-repo override) only enforces +// the global max_retries when config.ForTask carries it into TaskConfig and +// ToConfig restores it. Before that carry existed tc.Cfg.MaxRetries was always +// 0, so the loop meant to stop an endless remediation never stopped. +func TestStageRemediationRoundCapReadsTheWorkerCarriedGlobalCap(t *testing.T) { + forge := &fakeForge{} + carried := config.Config{MaxRetries: 2}.ForTask().ToConfig() + tc := &TaskContext{ + Task: &Task{ID: 1, RemediationRounds: 2, PRNumber: 9}, + // No per-repo override: the global cap has to reach the worker. + Repo: config.Repo{}, + Cfg: carried, + Forge: forge, + Log: slog.New(slog.DiscardHandler), + } + if err := StageRemediationRoundCap().Run(t.Context(), tc); err != nil { + t.Fatalf("StageRemediationRoundCap: %v", err) + } + if tc.Outcome.Status != StatusParked { + t.Fatalf("Outcome.Status = %q, want parked at the configured global cap (TaskConfig.MaxRetries = %d reaches the run as %d)", + tc.Outcome.Status, 2, carried.MaxRetries) + } + if len(forge.commented) != 1 { + t.Fatalf("commented = %v, want exactly one cap comment", forge.commented) + } +} + func TestStageRemediationCommitPushSkipsAnEmptyTreeWithoutError(t *testing.T) { trees := &fakeTrees{commitAllChanged: false} tc := &TaskContext{