Skip to content

fix(canary): B-02 judges pull pilots by their own worker pool; B-08 checks the pool is alive (#2840) - #3048

Merged
obasilakis merged 2 commits into
devfrom
feature/2840-b02-pull-aware
Sep 29, 2026
Merged

obasilakis merged 2 commits into
devfrom
feature/2840-b02-pull-aware

Conversation

@obasilakis

@obasilakis obasilakis commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • B-02 no longer false-fires on healthy pull pilots. Push agents keep the drain rule unchanged. A pilot is judged by its own worker pool: a row waiting over 120s while a worker is idle is critical (queued_not_claimed). That is B-02's only pull finding, because it clears once the pool claims again.
  • Pool size comes from the container env, not the database cap, which drifts from the running pool until a recreate (filed as feat(pull): resize a pilot's worker pool live when its parallel limit changes #3039). Busy = a running row whose lease has not expired.
  • New B-08 "Pull workers alive" owns every pool state that lasts until an operator acts: a stopped pilot with work older than 120s (pilot_stopped), a running container not in pull mode (workers_missing), and idle workers that have not polled for 300s (workers_silent). The poll time is a new agent:pull_poll:{name} Redis timestamp stamped on every claim attempt. It is a separate id because canary alerts fire only on green→red, so a state that lasts days would otherwise hold B-02 red and mute new push stalls.
  • The 24h stale-queue expiry now logs at warning. On a pilot it was the only trace of work nobody claimed.

Changes

  • src/backend/canary/invariants/b02_no_queued_without_slots_full.py: per-mode arms; shared pull_pool_state / oldest_queued_age
  • src/backend/canary/invariants/b08_pull_workers_alive.py: new
  • src/backend/canary/snapshot.py: is_pull_pilot, last_worker_poll_at, pull_container_env (keeps only the two pull keys; the env carries credentials; an unreadable env is labelled pull_env[<agent>])
  • src/backend/services/pull_coordination_service.py: record_worker_poll on every claim attempt (best-effort)
  • src/backend/services/pull_pilot.py, agent_runtime_state.py: key constant; keyspace registered as exempt, with the reason
  • src/backend/services/canary_alerts.py: B-02/B-08 name, runbook, summary, forensic
  • Docs: reliability area file, invariant catalog (B-08 entry + mapping), Phase-5 line in PULL_MIGRATION_STATUS.md, capacity feature flow, learnings entry, CSO diff report

Test Plan

  • pytest tests/unit/test_canary_invariants.py -k "B02 or B08": 42 pass, plus a parity test pinning the pool clamp to the agent image's pull_worker. Covers the eu2 2026-09-09 case, the idle/full/expired-lease pool, container pool vs database cap, no pull mode, stopped and unlisted containers, the Redis outage, and the timestamp formats.
  • End-to-end collect_snapshot tests: pilot status from PULL_MODE_PILOT_AGENTS, pool from the container env, and a credential-shaped env value absent from the snapshot. Mutation-checked: both deliberate breaks turn the tests red.
  • test_1081_pull_endpoints.py: an empty claim stamps the poll; a Redis failure never blocks a claim.
  • Guards: the 1560 key parity, 1880 alert parity and rendering, and 2337 invariant namespace tests. 814 related tests pass after rebasing on dev.
  • Full tests/unit: the failures on this machine also fail on dev, and the count varies between runs. The branch adds none; the two errors seen only on the branch pass when their file runs alone.
  • Soak: on eu2 after deploy, B-02 stays green on the three pilots through normal traffic.

Fixes #2840

🤖 Generated with Claude Code

obasilakis and others added 2 commits September 28, 2026 15:58
…08 checks the pool is alive (#2840)

B-02 fired critical on a healthy pull pilot caught between enqueue and
claim, because its only rule was the push drain's: free slots plus a stale
drain tick. The backend never drains a pilot, so neither signal applies.

B-02 now has one arm per dispatch mode. Push agents keep the drain rule. A
pilot is judged by the pool size in its container's own env (the database
cap drifts from it until a recreate, #3039) and by running rows whose lease
has not expired. A row waiting over 120s while a worker is idle, or while the
container runs no pull workers, is critical; a stopped pilot with aged work
is major.

B-08 (new) reports a running pilot whose pool cannot claim while its queue is
empty: a container without pull mode, or idle workers that have not polled
for 300s. The poll time is a new per-agent Redis timestamp written on every
claim attempt. It is a separate id because alerts fire only on green->red, so
a pool broken for days would otherwise hold B-02 red and mute new push
stalls.

The canary keeps only the two pull keys from the container env, which also
carries credentials. The 24h stale-queue expiry now logs at warning.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…ator acts (#2840)

A stopped pilot with work waiting, and a container without pull mode, stay
that way until someone starts or recreates the agent; cron keeps queueing
behind them. Under B-02 either would hold it red for days and mute new push
stalls, since alerts fire only on green->red. Both move to B-08. B-02's pull
arm now reports only an idle worker ignoring aged work, which clears once the
pool claims again.

Also from review: a container whose env cannot be read is now labelled in
sources_unavailable instead of skipped silently, the copied pool-clamp
constants are parity-tested against the agent image, and comments that
credited the poll timestamp to B-02 now name B-08.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@obasilakis
obasilakis force-pushed the feature/2840-b02-pull-aware branch from 26a882c to d7b1ff7 Compare September 28, 2026 13:59

@dolho dolho left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/review — #3048

Approving: no critical findings, and the fix is proven by mutation.

Scope: clean. #2840 asked for a pull-aware B-02 that doesn't skip pilots. Moving the long-lived states into a new B-08 is a reasoned split, not drift.

Plan completion (#2840 AC): 4 done, 1 unverifiable (the eu2 soak)

  • No fire when the claim lands inside the poll window: test_freshly_queued_row_on_idle_pool_does_not_fire.
  • Fires when workers stop claiming: test_aged_row_with_idle_worker_fires_critical, plus B-08 workers_silent.
  • Push path unchanged: test_push_agents_are_untouched_by_the_pilot_flag, and the existing TestInvariantB02 passes.
  • Phase-5 disposition stated in PULL_MIGRATION_STATUS.md.

Execution coverage

Changed Executed by Live consumer Verdict
b02._check_pull, pull_pool_state, oldest_queued_age TestInvariantB02Pull (13) INVARIANTS["B-02"] → canary cycle ✅
b08.check TestInvariantB08 (16) INVARIANTS["B-08"] ✅
snapshot._pull_env_of / _is_pull_pilot / _collect_last_worker_poll TestInvariantB02PullEndToEnd (real collect_snapshot) collect_snapshot() ✅
record_worker_poll test_every_claim_attempt_stamps_the_worker_poll routers/internal.py:163 via claim_next_task ✅
test_pull_pool_defaults_mirror_the_agent_worker (read_text) — vendored-constant parity with pull_worker.py 🛡 guard

Fix mutation: each mutation turned the listed number of tests red.

Mutation Tests red
Pilots routed back to the push arm 14, including the eu2 case and the end-to-end env-secret test
record_worker_poll call removed 1
Expired leases counted as busy 1 (test_expired_lease_counts_as_idle)

Unmodified: 413 pass and 3 skip (canary, 1081, 1880, 2337, 1560 suites).

Critical

None.

Informational

  • [I1] The learning goes straight into docs/memory/learnings.md (9/10), at :1032. It lands on the shared tail, which the file's header forbids ("so that two same-day PRs never conflict on this tail", #2945). Move it to a fragment under docs/memory/learnings/2026-09-28-<slug>.md.
  • [I2] A synchronous Redis write on the async poll path (5/10). pull_coordination_service.py:219 has record_worker_poll doing a blocking redis.set inside async def internal_next_task. The DB claim in the same handler was already synchronous, and it runs at most once every 15 s per idle worker, so the cost is negligible.

Clean

  • SQL: no raw SQL. Reads reuse _collect_executions.
  • Auth: no new endpoints. /next-task's dual auth is unchanged.
  • Credentials: _pull_env_of keeps only the TRINITY_PULL_MODE / TRINITY_MAX_PARALLEL_TASKS keys, and the end-to-end test checks a credential-shaped env value is absent from the snapshot.
  • Enum completeness: B-08 is registered in INVARIANTS, in canary_alerts (names, runbook, forensic, summary) and in the 2337 namespace test. 1880 parity passes.
  • Blindness labels: pull_env[...] / pull_poll[...] avoid the docker / redis prefixes, and a test pins it.
  • Enterprise-docs guard: no hits.
  • Docs: reliability.md has the B-02 and B-08 rows.

@obasilakis
obasilakis merged commit e871631 into dev Sep 29, 2026
25 of 26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants