Skip to content

bug(pull): the Phase-2 lease-renewal heartbeat was never built — a hung turn is re-delivered while it is still running #2846

Closed

Description

@obasilakis

Summary

Phase 2 of #1081 specifies a lease-renewal heartbeat:

Lease renewal: a worker heartbeat renews lease_expires_at for legitimately long turns (reuse the #307 heartbeat path) so they're never reaped out from under themselves.

It was never built. lease_expires_at is written exactly once, at claim (db/schedules/queue.py:136), and thereafter only ever set to NULL on re-queue or park. There is no renew endpoint, no renewal call in the agent's pull worker, and no code path anywhere that extends a live lease.

The reaper, correspondingly, does no liveness check. Its own docstring says it recovers a row when the worker "dies or hangs" (lease_reaper_service.py) — it cannot distinguish a dead worker from a turn that is still running.

Consequence

A turn that outlives timeout_seconds + SLOT_TTL_BUFFER is re-queued and re-claimed while the original is still executing. That is not recovery — it is two workers running the same execution_id concurrently, which is the one thing the design is explicit that re-delivery must never cause.

Three things fall out:

  1. It is precisely the condition feat(pull): platform-injected execution id for the side-effect guard — Tier-6 T6.3, blocks default-ON for side-effect agents #2392 exists for. Re-delivery deliberately preserves the execution_id so effect_guard can de-duplicate; that guarantee assumes the two attempts are sequential. Two concurrent attempts can interleave either side of the guard's claim.
  2. The overbooking meter cannot see it. M3 measures peak concurrent distinct claimed_by_worker, and both attempts are legitimately claimed — so a reaper-induced double-run reads as normal occupancy, not as a breach.
  3. The agent-side cap is not a backstop. The worker pool bounds how many claims an agent holds; it does not prevent the same execution being claimed twice, once by each of two workers.

How reachable is it

Narrow today, but not theoretical. The worker enforces its own turn timeout at timeout_seconds, 300s inside the lease, so the gap only opens when that enforcement itself fails — a turn that hangs past its own kill. That is exactly the stuck-reader / leaked-thread family this codebase keeps producing (#728, #1502, #1661, #2398, #2455), and #2398 wedged an agent on eu2 for ~22 hours as recently as 2026-09-10.

It is also about to get much wider. Per the decision on #1989 (2026-09-16) the durable queue carries all traffic and the push path is deleted, so this stops being a property of a three-agent pilot and becomes a property of every execution on every agent.

Scope

  1. Clamp the turn limit at claim. claim_next_task sizes the lease from the agent's execution_timeout_seconds and caps the turn limit (task_overrides.timeout_seconds) at the same value (absent → that value), so a healthy turn always ends inside its lease.
  2. No lease-renewal heartbeat. With the clamp it has nothing to do for a healthy turn, and for a hung turn it would keep the lease alive forever. TARGET_ARCHITECTURE.md §Recovery and MESSAGE_ENVELOPE_SCHEMA.md §3.5 / OPEN-4 say so.
  3. Name the shortened limit. When the clamp shortens a limit, log it; if the turn then times out, the failure text says the limit was shortened, so the operator knows which setting to change.
  4. Reaper docstring states the assumption: an expired lease means the worker died or its own kill failed. Only workers in the same agent container can re-claim, so a frozen agent-server claims nothing.

Acceptance criteria

  • A queued job whose timeout exceeds the agent's (agent timeout lowered while it waited) is handed a turn limit no greater than the agent timeout — tested
  • A job with no recorded timeout is handed the agent timeout, not the worker's 900s default — tested
  • The turn limit plus SLOT_TTL_BUFFER fits inside the lease — tested
  • A timeout failure on a clamped job names the shortened limit, and a failure computing that note never blocks the terminal write — tested
  • The reaper docstring, TARGET_ARCHITECTURE.md and MESSAGE_ENVELOPE_SCHEMA.md agree with the code (no heartbeat)

Notes

Activity

  1. added
    priority-p1
    type-bug
    theme-reliability
    on Sep 16, 2026
  2. added
    status-ready
    complexity-high
    priority-p2
    and removed
    priority-p1
    on Sep 17, 2026
  3. removed
    status-ready
    on Sep 21, 2026
  4. obasilakis commented on Sep 21, 2026

    @obasilakis
    ContributorAuthor

    /claim

  5. added
    status-in-progress
    on Sep 21, 2026
  6. github-actions commented on Sep 21, 2026

    @github-actions

    Claimed by @obasilakis. Label status-in-progress added.

    Next steps:

    1. Create branch: feature/2846-<short-slug>
    2. Implement the feature
    3. Open a PR with Fixes #2846
  7. added
    status-in-dev
    and removed
    status-in-progress
    on Sep 22, 2026
  8. removed
    status-in-dev
    on Oct 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

complexity-highpriority-p2theme-reliabilitytype-bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions