Skip to content

bug(company-os): LLCHeartbeatRun.work_item_id is never written, so run cancel and the liveness monitor never release a checkout #19601

Closed

Description

@mrveiss

Problem

LLCHeartbeatRun.work_item_id (autobot-backend/llc/models/heartbeat_run.py:54) is never written by non-test code. The evidence:

  • None of the three constructors sets it: heartbeat_scheduler.py:534, comment_wake_service.py:130 and replay_service.py:215.
  • None of the four update(LLCHeartbeatRun) calls in heartbeat_scheduler.py (:328, :618, :666, :702) sets it.
  • A grep for .work_item_id = across llc/ finds no run assignment.

Two release paths depend on that column, so neither one ever fires:

  • Run cancel, autobot-backend/llc/api/runs.py:169-176: if run.work_item_id: drops llc:checkout:{work_item_id}.
  • Liveness monitor, autobot-backend/llc/scheduler/liveness_monitor.py:139-146: releases the Redis checkout lock and blocks the work item, both only if run.work_item_id.

Both paths also drop only the Redis fence. They never clear the DB checkout (checkout_run_id / checkout_locked_at), and the DB checkout is what work_item_queue.eligible_for (:118) actually reads. Wired up as they are, they would still leave the item unclaimable.

The stalled-run sweep (#16817) avoids the column. It releases by LLCWorkItem.checkout_run_id == run.id, which is the run's own key. That key is the model the other two paths could reuse.

Acceptance criteria

  • Choose one of these, recording the reason: either write work_item_id when a run checks out an item, or have cancel and the liveness monitor release by checkout_run_id the way the stalled-run sweep does. One release rule for a run's checkouts, not three.
  • Cancelling a run, and the liveness monitor recovering one, clears the DB checkout as well as the Redis fence, with an activity-log entry carrying a reason distinct from stalled.
  • Tests drive both paths. After a run cancel the item is claimable; after a liveness release the checkout and fence are cleared and the item is BLOCKED with a reason (reworded per owner decision 2026-11-21).

Related

Refs #16817

Activity

  1. changed the title [-]bug(llc): LLCHeartbeatRun.work_item_id is never written, so run cancel and the liveness monitor never release a checkout[/-] [+]bug(company-os): LLCHeartbeatRun.work_item_id is never written, so run cancel and the liveness monitor never release a checkout[/+] on Oct 30, 2026
  2. github-actions commented on Nov 4, 2026

    @github-actions
    Contributor

    needs-structure: this issue is missing:

    • a native parent issue (add one, or write Parent: #N in the body), unless this is an umbrella with sub-issues

    The label clears on the next issue event once all three are present (#19522).

  3. added
    needs-structureMissing goal milestone, matching phase label or native parent (#19522)
    on Nov 4, 2026
  4. 4 remaining items

  5. github-actions commented on Nov 13, 2026

    @github-actions
    Contributor

    Landed via the merge train (#21475, merge 1ccdc9655d) via #21446

  6. mrveiss commented on Nov 13, 2026

    @mrveiss
    OwnerAuthor

    Landed in #21446 (merge 1ccdc96)

    PR keyword: Refs, so this issue stays open. Evidence from origin/main.

    Criterion Evidence Ticked
    One release rule, reason recorded autobot-backend/llc/services/run_checkouts.py:6-12 (release keyed on checkout_run_id only; work_item_id deliberately not read), :117 release_checkouts_for_run; callers api/runs.py:186, scheduler/liveness_monitor.py:163, scheduler/stalled_run_sweep.py:186 yes
    Cancel and liveness recovery clear the DB checkout and the Redis fence, with a reason distinct from stalled DB: run_checkouts.py:106-107 (checkout_run_id = None, checkout_locked_at = None); fence: api/runs.py:189 and liveness_monitor.py:105 drop_released_fences; reasons cancelled (runs.py:131) and liveness_timeout (liveness_monitor.py:55) yes
    Tests drive both paths and assert the item is claimable afterwards cancel: autobot-backend/llc/tests/test_run_checkout_release_19601.py:182 asserts READY and offered again (:227). Liveness: test_liveness_monitor.py:315-327 asserts the checkout is cleared and the reason, but the monitor parks the item as BLOCKED (liveness_monitor.py:59), so it is not claimable afterwards no: the liveness path is not asserted claimable, and by design it is not

    Remaining

  7. mrveiss commented on Nov 19, 2026

    @mrveiss
    OwnerAuthor

    AC status verified against main at f98f24e (deployed to the local install), 2026-11-19. Only ACs with code evidence were ticked.

    • MET: release_checkouts_for_run (llc/services/run_checkouts.py:117-126; callers llc/api/runs.py:187, scheduler/liveness_monitor.py:163). Both paths clear the checkout and fence (test_liveness_monitor.py:315, :322, :327).
    • Open, needs an OWNER decision: "claimable afterwards" holds on the cancel path (test_run_checkout_release_19601.py:234, :239), but the liveness path parks items as BLOCKED by design (liveness_monitor.py:59; test_liveness_monitor.py:320). Reword the AC, or change the behaviour.
  8. mrveiss commented on Nov 21, 2026

    @mrveiss
    OwnerAuthor

    Owner decision, 2026-11-21: keep BLOCKED and reword the AC. A stalled run is suspicious, so a human unblocks its item. The liveness path clears the checkout and the fence and parks the item as BLOCKED with a reason, as built (llc/scheduler/liveness_monitor.py:59). Only the run-cancel path makes the item claimable afterwards. The AC is reworded to match.

  9. mrveiss commented on Nov 21, 2026

    @mrveiss
    OwnerAuthor

    AC3 verified against origin/main and ticked; all three ACs are now met.

    • Cancel path is claimable: llc/tests/test_run_checkout_release_19601.py:227 test_a_cancelled_runs_unfinished_item_goes_back_to_ready_with_its_assignee_and_is_offered_again. The item goes back to READY with its assignee, and checkout_next offers it again.
    • Liveness path: llc/tests/test_liveness_monitor.py:283 test_recovery_releases_every_checkout_the_run_made_and_their_fences. It asserts that the checkout is cleared (:314), that in-progress items are parked BLOCKED (:316), that the fences are dropped (:322), and that the activity reason is liveness_timeout (:327).
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

    backendbugSomething isn't workingneeds-structureMissing goal milestone, matching phase label or native parent (#19522)phase:M2.8Audit trail and run supervisionpriority: high

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions