Skip to content

cargo-target-janitor: both deletion-safety liveness reads are single-page — queue_claims caps at 1000 rows and open_pr_branches at 500 PRs, so a claimed task or open-PR worktree past the page silently loses its never-delete protection #6618

Closed

Description

@dezren39

Problem

The cargo target janitor (infra/cargo-target-janitor/bin/cargo_target_janitor.py) deletes Cargo target directories under ~/git/fleet. Its safety policy (README) is absolute — "Never remove a target for a currently claimed repo-health-code-pilot task" or for "a worktree whose branch has an open PR" — and it fails closed when a liveness source is unavailable (README: "If either source is unavailable, cleanup stops"; an invalid gh response raises SafetyError, janitor :246).

Both liveness reads that implement those two protections are single-page reads with a silent cap, so a source that is truncated is indistinguishable from a source that is complete — the one failure shape that does not stop cleanup:

  1. Claimed tasks — queue_claims (:186), query at :188-192:
    tasks?select=id,queue,status,payload&queue=eq.repo-health-code-pilot&status=eq.claimed&limit=1000
    One GET, no offset/range follow-up, no check that the page came back full. Claimed task IDs past row 1000 are absent from the returned set, so discover_targets never applies the live-claimed-task protection (:309) to their targets — and the apply loop's per-removal re-check calls the same function (:512), so the re-check is blind in exactly the same way.
  2. Open PR branches — open_pr_branches (:219), gh pr list --limit 500 (:229-230):
    One call, no page follow. Open PRs past the first 500 contribute no branch names, so their worktrees never get the open-pr-worktree protection (:311/:313), at plan time (:423) and at the apply re-check (:513) alike.

Same-pattern site to disposition while fixing: queue_task_states (:211) also ends in limit=1000; its ID set is built from local fleet directories, so it is bounded differently, but the fix should state why it is or is not safe.

Evidence (verified this run)

Laptop primary @ 2bb307550b (== origin/main). Probe ~/git/fleet/probe-janitor-pages/probe_janitor_pages.py loads the real janitor module and stubs only the two servers, honouring their documented limit semantics (PostgREST limit=N returns at most N rows; gh --limit N returns at most N PRs):

  • Server holds 1005 claimed tasks → queue_claims returns 1000, task IDs 1001–1005 missing, exactly 1 query issued. Control (3 claimed) returns all 3.
  • Server holds 600 open PRs → open_pr_branches returns 500 branch names, 100 missing, exactly 1 gh call (--limit 500).
  • PROBE PASS, exit 0.

Live headroom today (2026-11-06, gh pr list): 259 open PRs — under the 500 cap, but already past half of it in a repo whose fleet lanes open PRs continuously. The claimed-task count could not be read today (queue backend outage, #6450); nothing here claims either cap has already been exceeded live. The defect is that when a cap is crossed, the janitor's two never-delete protections silently stop applying to the overflow — in a tool whose hourly timer runs with --apply (README "Run and schedule").

Related: #6605 (same first-page-only flaw in fleet dispatch-test's scan, filed today); #5952 (the janitor's tests run in no workflow — a pagination test added here needs a venue, or it joins that gap).

Why it matters

Every other safety input in this tool fails closed: unreadable process table, invalid gh JSON, helper unavailable, path escaping the fleet root — all raise and stop. A full page is the only degraded input that is silently treated as ground truth, and it degrades precisely the two protections that stand between a live task / open PR and shutil.rmtree of its build directory. Deleting a claimed task's target mid-build costs a full recompile of pkgs/id and can fail the task's verification; deleting an open PR's worktree target does the same to its holder.

Acceptance criteria

  • queue_claims returns claimed IDs beyond the first 1000 (offset/range pagination, or an equivalent complete read), OR raises SafetyError when a page comes back exactly full so cleanup stops instead of proceeding on a known-incomplete set.
  • open_pr_branches likewise pages past 500 open PRs, OR fails closed on a full page.
  • The apply-loop re-checks (:512/:513) use the same complete/fail-closed reads — no second, weaker copy.
  • queue_task_states' limit=1000 (:211) is dispositioned in the change (fixed the same way, or a comment/test records why its locally-bounded ID set cannot exceed it).
  • Tests in infra/cargo-target-janitor/tests/test_cargo_target_janitor.py cover the over-page cases for both reads (stub server/gh returning full pages), plus the at-cap boundary; existing 13 tests still pass.
  • README safety policy updated if the chosen behaviour is fail-closed-on-full-page, so the documented contract matches the code.

Activity

  1. added
    kind/bugSomething isn't working (prefixed form of the classic bug label)
    task/triageQueue packet kind: verify, reproduce, and route this item
    on Nov 6, 2026
  2. developing-today commented on Nov 6, 2026

    @developing-today
    Contributor
  3. dezren39 commented on Nov 6, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · filed

  4. dezren39 commented on Nov 6, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · design-architect pass 63 — adopted as a phase of design #6622

  5. dezren39 commented on Nov 7, 2026

    @dezren39
    MemberAuthor

    Picked up by repo-worker-code-l — working this now. (Fleet queue fallback mode: the queue backend is down, so this issue's comments carry the claim. The claim stays live while repo-worker-code-l posts progress markers; after 30 minutes of silence any other worker may pick this up.)

    🤖 Agent note · picked up

  6. 109 remaining items

  7. dezren39 commented on Nov 10, 2026

    @dezren39
    MemberAuthor

    agent-note:v1 — state: handed_off (task 13709, lane code-t)

  8. dezren39 commented on Nov 10, 2026

    @dezren39
    MemberAuthor

    Lane code-x picked up task 13709 (issue #6618) — handed off to opencode claimant.

  9. dezren39 commented on Nov 10, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · handed off

  10. dezren39 commented on Nov 10, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · handed off to opencode claimant — Agent: queue worker (repo-worker-code), lane code-d — Session/ID: task 13709, repo-queue-worker-shift-d 2026-11-10 run. Task 13709 (small_fix) for issue #6618: cargo-target-janitor: both deletion-safety liveness reads are single-page. Fresh check: issue #6618 OPEN, no held/user/owned/do-not-merge/do-not-auto-edit labels, no status/needs-triage. Execution lane row 5546 = opencode. Checkpointed handed_off with reason: scheduled shift is time-bounded; claimant is the persistent execution session. Parking task 13709 for 20 minutes for the claimant window.

  11. dezren39 commented on Nov 10, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · handed off

  12. dezren39 commented on Nov 10, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · handed off to opencode claimant — Agent: queue worker (repo-worker-code), lane code-e — Session/ID: task 13709, repo-queue-worker-shift-e 2026-11-10 run. Task 13709 (small_fix) for issue #6618: cargo-target-janitor deletion-safety liveness reads are single-page; attempts 3/4 on this claim. Fresh check: issue #6618 OPEN, no held/user/owned/do-not-merge/do-not-auto-edit labels, no status/needs-triage. Execution lane row 5546 = opencode. Checkpointed handed_off (handoff reason: scheduled shift is time-bounded; claimant is the persistent execution session); parking task 13709 for 20 minutes for the claimant window.

  13. dezren39 commented on Nov 10, 2026

    @dezren39
    MemberAuthor

    agent-note: task 13709 handed off to opencode claimant (lane row 5546) by lane code-m. Handoff reason: scheduled shift is time-bounded; claimant is the persistent execution session. Issue #6618 verified OPEN with no hard-stop labels and no status/needs-triage (fresh gh). Parked 1200s for the claimant.

  14. dezren39 commented on Nov 10, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · handed off

  15. dezren39 commented on Nov 11, 2026

    @dezren39
    MemberAuthor

    Lane code-b, task 13709 — outcome: already done on current main; closing with evidence.

  16. removed
    status/parkedDeliberately paused with a recorded resume condition
    queue/parkedQueue task is parked (waiting on CI, time, or an event)
    work/assignedQueue worker lifecycle state
    on Nov 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    app/cargo-target-janitorPackage/app: cargo-target-janitor (infra/ in this repo)kind/bugSomething isn't working (prefixed form of the classic bug label)priority/normalOrdinary priority (the default)source/creatorFiled by the new-issue-creator jobsource/design-architectFiled by the repo design architect jobstatus:donetask/small-fixQueue packet kind: bounded fix with reproduction and targeted tests

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions