Skip to content

[issue-3364][slice-2/3] PR C — Supervision hardening (RE-SCOPED... - #3573

Merged
jwbron merged 17 commits into
egg/issue-3364/workfrom
egg/issue-3364/slice-2
Jul 10, 2026
Merged

jwbron merged 17 commits into
egg/issue-3364/workfrom
egg/issue-3364/slice-2

Conversation

@james-in-a-box

Copy link
Copy Markdown
Contributor

Behavioral / medium-high risk (highest here — weight toward test coverage on the exit-code plumbing seam). RE-SCOPED to honor binding HITL cq-2 (human-resolved opt-3: pause + re-plan to reconcile the file set with the #3447 JobSupervisor relocation; opt-2's stay-in-3-files partial-AC-C1 deviation was explicitly NOT chosen). AC-C1 ("classify as transient rate-limit, NOT abnormal, does NOT trip the fail-streak halt") is unreachable within the original 3 files: the orchestrator only propagates a per-agent EXIT CODE to the streak site (never the error TEXT), and #3447 moved the per-arm failure-recording layer (JobSupervisor) out of concurrent_executor.py into orchestrator/event_loop/_supervisor.py (+ _loop.py). The faithful mechanism (== cq-2 opt-1) is a distinct exit code EX_RATE_LIMITED mirroring EX_AUTH_FATAL end-to-end: auth_errors.py (define EX_RATE_LIMITED + is_transient_rate_limit_error for 429/rate-limit/ overloaded) -> egg_agent/main.py (emit it, auth-fatal precedence) -> kubernetes_spawner/_models.py (JOB_OUTCOME_RATE_LIMITED outcome mapping) -> event_loop/_loop.py + init.py (_observe_jobs branch -> record_rate_limited) -> event_loop/_supervisor.py (record_rate_limited: NO abnormal-streak increment) -> supervision_policy.py (pacing/fingerprint/threshold constants) -> concurrent_executor.py (windowed-retry / loop-guard / threshold-alert / landed-slice wiring at the on_exhausted / hitl_probe seam). cq-1: no hard ceiling, OVERSEER_ALERT once cumulative wait crosses threshold. AC-C6 invariance is a NEW risk surface: EX_RATE_LIMITED must not perturb the EX_AUTH_FATAL(=77) exit-code path or the ordinary abnormal path. ~8 source files vs the original 3 — blast radius up; test the plumbing seam heavily.

Base PR: #3524

What's in this PR

Commits (17):

.egg-state/brc-history/3364-implement-slice-2.json         | 6570 ++++++++++++++++++++++++++
 .egg-state/brc-history/3364-implement-slice-2.md           | 7844 ++++++++++++++++++++++++++++++++
 .egg-state/contracts/issue-3364.json                       |  136 +-
 docs/reference/agent-recovery.md                           |    7 +-
 orchestrator/concurrent_executor.py                        |  103 +
 orchestrator/event_loop/__init__.py                        |   79 +
 orchestrator/event_loop/_loop.py                           |   37 +
 orchestrator/event_loop/_supervisor.py                     |  228 +
 orchestrator/kubernetes_spawner/_models.py                 |   38 +-
 orchestrator/supervision_policy.py                         |  145 +
 orchestrator/tests/test_concurrent_executor_rate_limit.py  |  170 +
 orchestrator/tests/test_event_loop_rate_limited.py         |  322 ++
 orchestrator/tests/test_kubernetes_spawner_rate_limited.py |  124 +
 orchestrator/tests/test_supervision_policy.py              |  130 +
 shared/egg_agent/__main__.py                               |   21 +-
 shared/egg_agent/auth_errors.py                            |   56 +
 shared/egg_agent/tests/test_auth_errors_rate_limit.py      |  258 ++
 17 files changed, 16251 insertions(+), 17 deletions(-)

This slice

PR C — Supervision hardening (RE-SCOPED per HITL cq-2): EX_RATE_LIMITED exit-code mirror + windowed paced retry + deterministic-loop guard

Files affected:

  • shared/egg_agent/auth_errors.py
  • shared/egg_agent/__main__.py
  • orchestrator/kubernetes_spawner/_models.py
  • orchestrator/event_loop/__init__.py
  • orchestrator/event_loop/_loop.py
  • orchestrator/event_loop/_supervisor.py
  • orchestrator/supervision_policy.py
  • orchestrator/concurrent_executor.py
  • shared/egg_agent/tests/test_auth_errors_rate_limit.py
  • orchestrator/tests/test_kubernetes_spawner_rate_limited.py
  • orchestrator/tests/test_event_loop_rate_limited.py
  • orchestrator/tests/test_supervision_policy.py
  • orchestrator/tests/test_concurrent_executor_rate_limit.py
Tasks (8) + acceptance criteria
  • task-2-1: shared/egg_agent/auth_errors.py: add EX_RATE_LIMITED (a NEW process exit code, distinct from EX_AUTH_FATAL=77 and the reserved codes 64/75/143 the module docstring names) and is_transient_rate_limit_error(text) matching the throttling signatures (bare 429 / "rate limit" / "overloaded") that _AUTH_FATAL_PATTERNS deliberately EXCLUDES. Do NOT widen EX_AUTH_FATAL / _AUTH_FATAL_PATTERNS. Keep the two classifiers disjoint (a matched weekly/usage cap stays auth-fatal; a bare throttle is rate-limited).
    • Acceptance criteria: - EX_RATE_LIMITED defined, distinct from 77/64/75/143; is_transient_rate_limit_error matches 429/"rate limit"/"overloaded". - AC-C6: EX_AUTH_FATAL and _AUTH_FATAL_PATTERNS unchanged; is_auth_fatal_error behavior byte-identical; the two classifiers do not overlap.
  • task-2-2: shared/egg_agent/main.py (~:142): emit EX_RATE_LIMITED when is_transient_rate_limit_error(result.error), as a distinct branch alongside the existing if not result.success and is_auth_fatal_error(result.error): return EX_AUTH_FATAL. auth-fatal MUST take precedence (check it first), so a matched weekly cap still returns EX_AUTH_FATAL; the rate-limit branch fires only for the bare throttling signatures.
    • Acceptance criteria: - A throttled failure returns EX_RATE_LIMITED; an auth-fatal failure (incl. weekly cap) still returns EX_AUTH_FATAL; success/other return the prior code. - AC-C6: existing auth-fatal exit path unchanged.
  • task-2-3: orchestrator/kubernetes_spawner/_models.py: add a JOB_OUTCOME_RATE_LIMITED mapping in outcome_for — an _is_rate_limited_exit check (container exit_code == EX_RATE_LIMITED) mirroring the existing _is_auth_fatal_exit -> FATAL detection (which reads exit_code == EX_AUTH_FATAL). A non-matching exit code MUST still fall back to abnormal (today's behavior). Import EX_RATE_LIMITED from egg_agent.auth_errors alongside the existing EX_AUTH_FATAL import.
    • Acceptance criteria: - outcome_for returns JOB_OUTCOME_RATE_LIMITED for an EX_RATE_LIMITED exit; JOB_OUTCOME_FATAL for EX_AUTH_FATAL; abnormal otherwise. - AC-C6: the EX_AUTH_FATAL -> FATAL mapping and the abnormal fallback are unchanged.
  • task-2-4: orchestrator/event_loop/init.py + loop.py: define the JOB_OUTCOME_RATE_LIMITED constant (export it alongside the existing JOB_OUTCOME* constants) and add a _observe_jobs branch (mirroring the existing elif outcome == JOB_OUTCOME_FATAL / JOB_OUTCOME_ABNORMAL branches at _loop.py ~:94/:116) that routes a rate-limited outcome to a NEW supervisor.record_rate_limited(...) call. This is the per-arm interception point that keeps the throttle signature OFF the abnormal streak (record_abort is NOT called for this outcome).
    • Acceptance criteria: - JOB_OUTCOME_RATE_LIMITED constant exists and is observed; _observe_jobs routes it to record_rate_limited and NOT to record_abort. - AC-C6: the SUCCESS/LEGITIMATE/FATAL/ABNORMAL observe branches are unchanged.
  • task-2-5: orchestrator/event_loop/_supervisor.py: add record_rate_limited(...) that does NOT increment the per-key abnormal streak (mirror record_legitimate_outcome's "streak untouched" pattern at ~:100), so the throttling signature never trips the per-key streak>=10 halt — fully satisfying AC-C1. Capture/expose the failure fingerprint (signature + phase/slice progression) that the loop-guard (TASK-2-7) consumes; do not itself halt or escalate.
    • Acceptance criteria: - AC-C1: record_rate_limited leaves the abnormal streak untouched (the fail-streak halt does not fire on repeated rate-limit outcomes). - The fingerprint needed by the loop-guard is captured/exposed. - AC-C6: record_abort / record_success / record_legitimate_outcome streak behavior is unchanged.
  • task-2-6: orchestrator/supervision_policy.py: add the pacing + fingerprint + threshold constants/helpers the executor wiring consumes — the windowed retry window (hours-scale, NOT the 30s SUPERVISION_BACKOFF_CAP_SECONDS), a reset-time parse helper (pace from the error's reset time when present, else bounded backoff), the loop-guard fingerprint model (signature + progression identity + equality), and the cumulative-wait threshold that arms the cq-1 OVERSEER_ALERT. Leave SUPERVISION_BACKOFF_CAP_SECONDS and the existing abnormal backoff untouched.
    • Acceptance criteria: - AC-C2: windowed-retry window (hours) + reset-time-paced-else-backoff helpers exist and are distinct from the 30s abnormal cap. - AC-C4/AC-C5: fingerprint-equality model + cumulative-wait threshold constant present. - AC-C6: the existing 30s abnormal backoff/streak constants unchanged.
  • task-2-7: orchestrator/concurrent_executor.py (only the wiring that stays here — the JobSupervisor on_exhausted / hitl_probe seam, ~:1023/:1311): on the all-producers rate-limited signature, run the WINDOWED PACED RETRY (cq-1: NO hard wall-clock ceiling; emit an OVERSEER_ALERT once the cumulative wait crosses the TASK-2-6 threshold), using a restart_phase-equivalent that PRESERVES landed slices (re-arm only the in-flight/failed frontier — do not discard completed slice work), and the DETERMINISTIC-LOOP GUARD (using the TASK-2-5 fingerprint: escalate/ halt on an identical fingerprint at the same point; continue when state advances). Keep the threshold OVERSEER_ALERT orthogonal to the loop-guard escalation.
    • Acceptance criteria: - AC-C2/AC-C5: paced windowed retry with no hard ceiling + threshold OVERSEER_ALERT. - AC-C3: landed slices preserved across the paced restart. - AC-C4: loop-guard escalates on identical fingerprint at same point, continues when state advances.
  • task-2-8: Tests for PR C, weighted on the exit-code plumbing seam: is_transient_rate_limit_error classification (429/rate-limit/overloaded match; auth-fatal wording does NOT match); main emits EX_RATE_LIMITED for a throttle and still EX_AUTH_FATAL for a weekly cap; outcome_for maps EX_RATE_LIMITED -> JOB_OUTCOME_RATE_LIMITED and a stray code -> abnormal; _observe_jobs routes rate-limited -> record_rate_limited (NOT record_abort); record_rate_limited does NOT trip the streak halt; paced-retry pacing/window + threshold OVERSEER_ALERT (cq-1); landed-slice preservation across a paced restart; loop-guard escalates on identical fingerprint and continues when state advances. AC-C6 REGRESSION (new risk surface): EX_AUTH_FATAL(=77) exit-code handling and the ordinary abnormal path are unchanged by the new EX_RATE_LIMITED path. make lint + make test green.
    • Acceptance criteria: - AC-C7: classification, exit-code emission, outcome mapping, observe routing, no-streak-halt, pacing/window+threshold, landed-slice preservation, and loop-guard (both directions) all covered and green. - AC-C6: explicit regression asserting EX_AUTH_FATAL + abnormal paths unchanged.

Stack

egg-orchestrator and others added 17 commits July 6, 2026 23:05
…aced-retry path (PR C, #3364)

The supervision reference asserted exit 77 is the only exit code that
diverges from the record_abort streak path. PR C (#3364) adds a second
divergence: a bare throttle (429 / rate limit / overloaded, excluded from
EX_AUTH_FATAL per #3373) now exits EX_RATE_LIMITED, maps to
JOB_OUTCOME_RATE_LIMITED, and routes to record_rate_limited — no abnormal
streak increment, windowed paced retry across the rolling cap window with
no hard ceiling (per cq-1), threshold OVERSEER_ALERT, preserved landed
slices, and a deterministic-loop guard. Add the exception subsection,
the exit-code table row, and correct the 'one code diverges' summary.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…3364)

Reviewers reviewer_contract + reviewer_code NACKed v1: the doc described PR
C's supervision symbols (EX_RATE_LIMITED, is_transient_rate_limit_error,
JOB_OUTCOME_RATE_LIMITED, record_rate_limited) in present tense as shipped
fact, but no PR C code has landed (coder still WORKING; grep-confirmed absent
from orchestrator/ + shared/). Documenting ahead of code is premature.

Defer the agent-recovery.md update until PR C's implementation lands so the
doc describes the real landed symbols. The plan created no documenter task
for slice-2; this restores the file to its base state.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…paced retry + loop-guard

Re-scoped per binding cq-2 (EX_AUTH_FATAL-style exit-code mirror). A bare throttle
(429 / rate limit / overloaded) that auth_errors.py keeps OFF the EX_AUTH_FATAL path
currently falls to abnormal, feeds the >=10 agent-invocation-fail-streak halt, and
stops the pipeline in minutes (abnormal backoff caps at 30s). This routes it to a NEW
transient rate-limit class that never touches the abnormal streak and is PACED across
the rolling cap window instead.

- task-2-1 auth_errors.py: EX_RATE_LIMITED=69 + is_transient_rate_limit_error(),
  internally disjoint from is_auth_fatal_error (weekly cap on a 429 stays auth-fatal).
- task-2-2 __main__.py: emit EX_RATE_LIMITED for a bare throttle, auth-fatal first.
- task-2-3 kubernetes_spawner/_models.py: outcome_for -> JOB_OUTCOME_RATE_LIMITED
  (after EX_AUTH_FATAL->FATAL); stray code -> abnormal.
- task-2-4 event_loop/__init__.py + _loop.py: JOB_OUTCOME_RATE_LIMITED; _observe_jobs
  routes it to record_rate_limited (NOT record_abort).
- task-2-6 supervision_policy.py: paced-backoff + reset-parse helpers,
  RateLimitFingerprint, threshold + loop-guard constants (separate from 30s abnormal).
- task-2-7 concurrent_executor.py: _handle_rate_limited wired as rate_limited_notifier
  — cq-1 threshold OVERSEER_ALERT (no ceiling) + deterministic-loop-guard halt; paced
  retry preserves landed slices (normal respawn gate, no cold restart).

Also implements nominally-tester task-2-5 (record_rate_limited in _supervisor.py) —
coder task-2-4/2-7 hard-depend on it for an import-coherent green proposal; flagged as
a merge seam for the tester/reviewers.

AC-C1 (no fail-streak halt) / AC-C2+C5 (paced, no ceiling, threshold alert) / AC-C3
(landed slices preserved) / AC-C4 (loop-guard both directions) / AC-C6 (EX_AUTH_FATAL +
abnormal unchanged).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…-limit path (task-2-8)

Adds the PR C test surface, weighted on the exit-code plumbing seam:

- shared/egg_agent/tests/test_auth_errors_rate_limit.py: is_transient_rate_limit_error
  classification (429/rate-limit/overloaded match; auth-fatal + unrelated do NOT);
  EX_RATE_LIMITED=69 distinct from EX_AUTH_FATAL(77)/reserved codes; DISJOINTNESS
  (AC-C6: a weekly cap on a 429 stays auth-fatal, never both true); end-to-end CLI
  mapping (bare throttle -> EX_RATE_LIMITED, weekly-cap-on-429 -> EX_AUTH_FATAL,
  ordinary -> neither). CLI tests skip cleanly when claude_agent_sdk is absent.
- orchestrator/tests/test_kubernetes_spawner_rate_limited.py: outcome_for maps
  EX_RATE_LIMITED -> rate_limited; auth-fatal still -> fatal (precedence); stray code
  + read-failure -> abnormal (AC-C6 regression); live/exited never misclassified.
- orchestrator/tests/test_event_loop_rate_limited.py: _observe_jobs routes to
  record_rate_limited (NOT record_abort), reaps, keeps _key_meta; record_rate_limited
  never trips the streak halt (AC-C1) while record_abort still does (AC-C6);
  ready_to_respawn pacing; success/retire clear paced state; loop-guard escalates on
  identical fingerprint and resets when progression advances (AC-C4); cq-1 cumulative
  threshold alert latches once (AC-C5).
- orchestrator/tests/test_supervision_policy.py: rate-limit constants separate from
  abnormal SUPERVISION_BACKOFF_*; parse_rate_limit_reset_seconds (hints + clamp);
  rate_limit_backoff_seconds (bounded + reset precedence); RateLimitFingerprint
  structural equality/hash.
- orchestrator/tests/test_concurrent_executor_rate_limit.py: _handle_rate_limited
  threshold OVERSEER_ALERT (agent-rate-limited, no halt); deterministic-loop alert +
  halt_rate_limited; landed-slice preservation (only the looping arm halts); no-op when
  neither transition fires.

make lint (ruff) clean; the new suites are green (80 passed, 5 SDK-gated CLI tests
skipped locally — they run in CI). Covers AC-C7 + the AC-C6 regressions for task-2-8.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…genuine cap wall

v1 open-NACK barrier (reviewer_contract / reviewer_concurrency / reviewer_code /
reviewer_code_holistic) — all four flagged the SAME root cause: the
deterministic-loop guard used FROZEN BRC progression as deterministic-failure
evidence, but a genuine account-wide cap wall freezes progression identically
(every producer exits EX_RATE_LIMITED before doing any work, so the consensus
digest cannot move). On the bare-exit-code path the throttle signature is also
invariant, so the guard tripped after 5 identical retries (~7.5 min) and halted
the arm — re-imposing exactly the minutes-scale halt PR C exists to remove and
violating binding cq-1 / AC-C2 / AC-C5 (NO hard wall-clock ceiling).

Fix (upstream, in WHEN deterministic_loop is set — handler halt contract kept):
- record_rate_limited escalates ONLY on POSITIVE evidence the failure is no
  longer a fresh transient throttle: an exit signature present AND not
  classified as a transient rate limit (via is_transient_rate_limit_error) AND
  carrying no parseable reset hint. A genuine throttle (no signature on the
  orchestrator path, or throttle-classified text) NEVER satisfies this, so it
  paces INDEFINITELY with only the cq-1 threshold OVERSEER_ALERT.
- _observe_jobs no longer passes exit_detail for the rate-limit branch: the pod
  exit code ("exit_code=69") is not classifiable error text and would mis-read
  a genuine cap wall as deterministic. The param stays for a future enriched
  observer.
- The progression fingerprint is retained only to reset the repeat counter when
  state advances (AC-C4 "continue when state advances").

Tests (tester file, revised in lockstep per reviewer_code_holistic's explicit
ask; flagged as coder/tester seam): replaced the frozen-throttle-escalates
assertion with (a) AC-C5 regression — a steady frozen throttle paces past the
1800s threshold, alerts once, never exhausted; (b) escalation now requires a
non-throttle signature; kept advancing-progression-resets.

331 passed, ruff clean.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…no-ceiling guard (task-2-8 v2)

Builds on the coder's lockstep loop-guard fix (94fbf7c) which reworked this
file's TestLoopGuardAndThreshold to the corrected discriminator. Removes the now-
redundant test_cumulative_wait_threshold_alert_latches_once: three reviewers
(reviewer_code/_contract/_code_holistic) flagged its "advance progression each
retry to reach the threshold" framing as a corroborating tell of the wrong
contract, and its threshold-latch-once property is now covered on the CORRECT
frozen-progression cap-wall path by test_steady_throttle_never_escalates_and_
paces_past_threshold (asserts exactly one threshold_crossed at cumulative wait
>= 1800s while never halting).

Resulting TestLoopGuardAndThreshold pins the corrected AC-C4/AC-C5 contract:
- steady bare throttle (frozen progression, no signature): never deterministic_
  loop, never exhausted, threshold alert once, paces indefinitely (cq-1 no ceiling)
- steady throttle-classified signature ("429 rate limit"): never escalates
- non-throttle signature ("Traceback: KeyError"): escalates once past the guard
  threshold, sticky (AC-C4 positive deterministic evidence)
- advancing progression resets the guard counter

224 passed / 5 SDK-skipped; ruff + bandit(-ll) clean.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…ervision path (PR C, #3364)

PR C has landed (2bd6124 + loop-guard correction 94fbf7c). Document the
real shipped mechanism in the supervision reference, matched to the code:

- exit 69 EX_RATE_LIMITED (distinct from 77), is_transient_rate_limit_error
  matching 429 / rate limit / overloaded / too many requests; disjoint from
  auth-fatal (weekly/usage cap delivered as 429 stays exit 77).
- outcome_for -> JOB_OUTCOME_RATE_LIMITED; _observe_jobs -> record_rate_limited
  (abnormal streak untouched -> no fail-streak halt).
- windowed paced retry (reset-time-paced else bounded backoff; the five
  SUPERVISION_RATE_LIMIT_* constants), landed slices preserved, no hard
  ceiling per cq-1, sticky agent-rate-limited OVERSEER_ALERT at 30 min
  cumulative wait.
- deterministic-loop guard as CORRECTED post-NACK: escalates + halts
  (rate-limit-deterministic-loop) only on POSITIVE non-throttle evidence, not
  on a frozen fingerprint (a real cap wall freezes progression identically).

Adds the exception subsection + exit-code table row and corrects the
'one code diverges' summary to 'two codes diverge'.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant