Skip to content

Keep runner jobs in step with the runner: one claim, delivered cancellations, requeued lost hand-outs - #29

Merged
waynesun09 merged 20 commits into
mainfrom
emu-04-runner-lifecycle
Nov 19, 2026
Merged

waynesun09 merged 20 commits into
mainfrom
emu-04-runner-lifecycle

Conversation

@waynesun09

@waynesun09 waynesun09 commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

Part of #39

Runner lifecycle: one claim per job, cancellations that reach the runner, no lost hand-outs

What this fixes

On GitHub, a job runs on exactly one runner, a cancelled job stops on its runner, and a job handed to a runner either reaches it or goes back to the queue. With several actions/runner runners on the emulator, none of these held:

# GitHub Emulator before this PR
1 A job runs once, on one runner Two polls could claim the same queued job. 5 of 32 jobs ran twice (4 runners, 8 runs). The runner that lost the race retried a bare 404 on its lease forever and never took another job
2 Cancelling a running job stops it on the runner concurrency: cancel-in-progress or a run cancel marked the job cancelled in the database only. The runner ran it to the end, so a superseded stage ran twice. The runner's final report then overwrote cancelled
3 Deleting a repository cancels its running jobs; the runners take new work The runner got 401s and a 404 lease, was never told to stop, and stayed busy for good. Later jobs queued with no free runner
4 A cancellation reaches the runner Two gaps: a late finish report of the runner's previous job freed it after it had taken the next one, and the cancellation check skips idle runners. The message long-poll also read a stale job row from a pinned SQLite WAL snapshot
5 A job reaches the runner it was handed to actions/runner abandons its message poll whenever its status changes. The emulator kept serving the abandoned request, which could still claim a job and answer it to nobody. The job then hung in progress, or failed with every step queued. A runner whose first poll timed out under load hit the same case
6 Deleting a runner keeps its jobs' history A runner deleting itself through the runner protocol or the pipelines routes left its jobs pointing at the deleted row. SQLite ignores the dangling foreign key; PostgreSQL answers 500. The custom runner's long-poll (_poll_for_jobs) also held one read transaction across all its passes

Changes

All in src/app/api/actions_distributed_task.py unless noted.

  1. Atomic claim. Both claim paths (_poll_for_jobs in actions_dispatch.py, _claim_next_job) go through _claim_queued_job: UPDATE ... WHERE id = :id AND status = 'queued'. Only the poll that changes the row owns the job. Accepting, renewing or completing a job request the runner does not hold answers 404 with a TaskAgentJobNotFoundException body, which makes the runner give the job up.
  2. Cancellation. The message long-poll returns one JobCancellation message ({"jobId", "timeout"}) for a busy runner whose job was cancelled. _complete_job keeps a cancelled conclusion and still frees the runner.
  3. Deleted or lost job. The emulator remembers the job it handed to each runner. When that job is gone, the runner gets JobCancellation. A runner that polls as Online while held busy is freed, and its lost job fails. The first 2 minutes after a hand-out are exempt.
  4. Cancellation delivery. A report frees a runner only if the runner has not moved on to another job. Each long-poll pass ends its transaction, and the cancellation check reads the job fresh.
  5. Hand-outs.
    • Only a runner's newest poll may hand out a job: each poll takes a per-runner generation, and the claim runs under a per-runner lock.
    • A job the runner neither acknowledged (DELETE of the message) nor named as lastMessageId goes back to the queue. The same holds for a poll with no lastMessageId while the job has not started a step.
    • Nothing is requeued within 5 s of its hand-out, and the requeue is a conditional UPDATE, so a report that commits first wins.
    • The poll commits before it claims.
    • Broker events are logged under github_emulator.runner_broker. app.main gives the github_emulator loggers a handler (GITHUB_EMULATOR_LOG_LEVEL, default INFO).
  6. Runner delete. The runner-protocol and pipelines delete routes use _delete_runner_and_detach_history, as the admin route does. The custom runner's long-poll (_poll_for_jobs in actions_dispatch.py) commits before each wait.

Lint: the touched files meet the ruff rules. Imports move to the top of actions_distributed_task.py, an unused import and two unused assignments are removed, and main.py imports are sorted. No behaviour changes there.

Ledger: one docs/bugs/fixed/ entry per fix, each listed in PLAN.md.

Tests

File Covers Run against main
tests/actions/test_job_claim_race.py (3) Two polls on one job, forced interleaving, both claim paths; lease renewal by a non-holder gets the exception body Fail: the second poll also claims the job; the renewal 404 has no typeKey
tests/actions/test_runner_job_cancellation.py (3) One JobCancellation per cancelled job; none for a running job; the report keeps cancelled and frees the runner Error: the cancellation helper does not exist
tests/actions/test_runner_orphaned_jobs.py (4) Deleted job cancelled on its runner; Online frees a held runner; Busy and a fresh hand-out are left alone Error: no hand-out record (_holding) exists
tests/actions/test_runner_cancel_delivery.py (3) Cancellation seen across sessions; a late report leaves the runner on its new job; the held job's report frees it Error: no hand-out record (_holding) exists
tests/actions/test_runner_lost_handout.py (4) Unreceived job requeued, not failed; abandoned first poll requeued; a newer poll replaces an older one; stress: 4 runners, 12 jobs, half the polls abandoned, every job runs exactly once Error: no poll generation or hand-out record exists
tests/actions/test_execution.py::test_pool_distributed_task_protocol_flow No job points at a runner after its agent delete Fail: a job still points at the deleted runner
tests/actions/test_runner_broker_races.py (7) A lost cancellation response is sent again; a late Online poll keeps the cancellation; a superseded poll hands out nothing; a runner an older poll made busy gets no second job; acknowledgements and reports wait for the runner's lock; acknowledgements are kept per runner Fail
tests/actions/test_runner_self_delete.py (1) A runner removing itself mid-job is removed and its job fails Fail: 422
tests/test_startup_logging.py (2) A custom admin password never reaches the startup log; an unknown log level falls back to INFO Fail: the password is logged; the app does not start

Each fails or errors on the code before its fix. Full suite: runs in this pull request's CI (ci.yml).

test_a_newer_poll_replaces_an_older_one_before_it_can_claim can fail once on a loaded machine: the test database's 0.1 s lock timeout answers the older poll with 503. It passes on rerun. The production lock timeout is far longer.

Effect on existing behaviour

  • The single-runner flow is unchanged: one runner, one poll, the same messages.
  • New message type on the long poll: JobCancellation ({"jobId", "timeout"}, the message actions/runner reads), sent only for a busy runner's cancelled or deleted job, and again on each poll until the runner deletes the message or reports the job's end.
  • A job request the runner does not hold answers 404 with the TaskAgentJobNotFoundException body; it keeps the earlier detail field.
  • A runner polling Online while held busy for over 2 minutes is freed, and its job fails. Before, it stayed busy.
  • A job its runner never acknowledged or named as lastMessageId goes back to the queue (not before 5 s after the hand-out). Before, it hung or failed.
  • More INFO lines in the server log (github_emulator.runner_broker). Set GITHUB_EMULATOR_LOG_LEVEL=WARNING to quiet them; an unknown level falls back to INFO. The first-start line names the admin account, never its password.
  • Runner deletes through any route detach the runner's jobs; runner_name stays on them. A runner removing itself mid-job is removed and the job fails; the admin route still refuses a runner that is running a job.

Known limits

  • A job stays in progress if the runner's worker process dies without reporting the job's end (JobCompleted, or the job request's finish). There is no server-side abandonment timeout yet.

Follow-up with the upstream-runner protocol PR

That PR adds the plans/{planId}/events route, which completes the job from JobCompleted from plan version 8. Whichever of the two merges second must let that route free the runner of a cancelled job. The guard is if job.status != "completed" or job.conclusion == "cancelled": before _complete_job. Without it, a cancelled job's runner stays busy after its report on plan version 8. This PR alone needs no change there: on main the job-request finish route always calls _complete_job.

@waynesun09
waynesun09 requested a review from jctanner November 18, 2026 22:35
@qodo-code-review

qodo-code-review Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

PR Summary by Qodo

Prevent duplicate runner claims and recover lost job hand-outs

🐞 Bug fix 🧪 Tests 📝 Documentation 🕐 40+ Minutes

Grey Divider

AI Description

• Claim jobs atomically across both runner protocols to prevent duplicate execution.
• Deliver cancellations and recover hand-outs lost to abandoned polls or idle runners.
• Preserve job history during runner deletion and add lifecycle regression coverage.
Merge Risk 🟡 Medium

Blast radius 🔴 High 💥 3 capabilities

  • 3 affected capabilities span independent functional scopes: Application startup observability, GitHub Actions runner execution integration.
  • The custom dispatch poll, upstream distributed-task poll, acknowledgement endpoints, completion endpoints, and output-bearing plan events all implement one bounded end-to-end behavior: assigning a workflow job to one runner, accepting its execution result, and exposing its result to subsequent workflow processing.
  • They are protocol hops in the same integration, not independent functional scopes.
  • Lost-handout requeue, cancellation delivery, freeing a runner after a report, and protection of a runner's persisted busy state are separate system outcomes within the same runner execution integration.
  • They share runner/job ownership state and affect whether subsequent workflow jobs can execute.
  • Logger handler/level setup and Alembic's preservation of existing loggers determine whether startup, migration, and runner-broker diagnostics reach the server log.
  • This is independent of the Actions execution state machine because it changes diagnostics rather than job ownership or workflow outcomes.
Behavioral complexity 🔴 High 🧩 Multiple interactions

  • Before: each poll read candidates and then mutated job and runner state directly, while reports and acknowledgements could interleave with polling.
  • After: conditional updates, per-runner locks, poll generations, acknowledgement windows, cancellation acknowledgement state, fresh reads, late-report checks, and conditional output persistence coordinate multiple asynchronous requests.
  • New correctness conditions remain that exactly one claimant owns a queued job, only the newest live poll may hand it out, an acknowledgement cannot be missed during receipt classification, a completion cannot free a runner after it has moved to another job, and reported outputs must be committed only for the still-owned completion.
  • The current delta adds an explicit session/identity-map refresh after waiting; this narrows stale-read behavior but still participates in the existing ordering protocol rather than eliminating it.
  • Before: output events were assigned directly before completion.
  • After: output values are passed into the conditional completion update.
  • New correctness condition: outputs must follow the same ownership and cancellation ordering as the job conclusion.
  • These are interacting states and coordinated invariants, not routine use of an existing mapper or lock.
Potential damage 🟡 Medium 🩹 Incorrect results

  • If the claim/ownership invariant fails, the same job can run twice, be left in progress on a runner that never received it, or have a late report alter the wrong runner's availability.
  • The new output merge is part of the same conditional completion update, so a report/event ordering error can also produce incorrect downstream workflow outputs.
  • A code rollback removes the new race-handling behavior, but it does not automatically undo externally executed duplicate steps or repair already persisted duplicate, missing, or incorrect conclusions and outputs.
  • Persisted job rows and outputs can generally be repaired or requeued by an operator and the application can be reverted.
  • External workflow side effects from duplicate execution require workflow-specific compensation; already-consumed incorrect outputs or external effects are not automatically reversible.
Assessed commit 20a9861
Diagram

graph TD
  R["Runner poll"] --> B["Message broker"] --> S{"Runner idle?"}
  S -->|"Cancelled job"| C["Job cancellation"]
  S -->|"Available"| Q["Queued jobs"] --> A{"Atomic claim?"}
  A -->|"Won"| J["Job request"]
  A -->|"Lost"| B
  S -->|"Lost hand-out"| Q
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Persist delivery and acknowledgement state
  • ➕ Coordinates polls across server processes and survives restarts.
  • ➕ Makes cancellation delivery and lost hand-outs recoverable without process-local maps.
  • ➖ Requires a larger schema and protocol-state change.
  • ➖ Adds database coordination to each poll and acknowledgement.

Recommendation: The PR's conditional database claim is the right immediate fix for duplicate execution. Its in-memory poll generations, acknowledgements, and cancellation tracking are pragmatic for a single-process emulator, but persistent delivery state is the stronger follow-up if multiple server workers or restart recovery are required.

Files changed (17) +1440 / -142

Bug fix (3) +364 / -81
actions_dispatch.pyShare an atomic claim across runner protocols +44/-16

Share an atomic claim across runner protocols

• Adds a conditional queued-job update that assigns a job and marks its runner busy only when the claim wins. The custom runner poll uses it and commits between empty long-poll passes to see newly queued work.

src/app/api/actions_dispatch.py

actions_distributed_task.pyReconcile upstream runner claims, cancellations, and hand-outs +314/-59

Reconcile upstream runner claims, cancellations, and hand-outs

• Uses the shared atomic claim, sends cancellation messages, and preserves cancelled conclusions without freeing a runner that has moved to another job. Poll generations, acknowledgements, fresh reads, and conditional requeues recover lost hand-outs; job-request errors now tell a non-owning runner to abandon the job. Runner deletion uses the history-detaching helper, and broker lifecycle events are logged.

src/app/api/actions_distributed_task.py

actions_pipelines.pyDetach job history when pipeline runners deregister +6/-6

Detach job history when pipeline runners deregister

• Routes repository and enterprise runner deregistration through the existing deletion helper, retaining job history without dangling runner references.

src/app/api/actions_pipelines.py

Tests (6) +723 / -2
test_execution.pyVerify runner deletion detaches historical jobs +8/-2

Verify runner deletion detaches historical jobs

• Extends the distributed-task protocol flow to assert that deleting a pool agent leaves no job referencing its runner row.

tests/actions/test_execution.py

test_job_claim_race.pyForce concurrent claims through both poll paths +223/-0

Force concurrent claims through both poll paths

• Synchronizes two sessions after candidate selection to verify exactly one runner claims a job in each protocol. Also checks that a non-owner's lock renewal receives the exception body the upstream runner recognizes.

tests/actions/test_job_claim_race.py

test_runner_cancel_delivery.pyCover stale cancellations and late completion reports +91/-0

Cover stale cancellations and late completion reports

• Verifies a polling session sees cancellation committed elsewhere and that a previous job's late report does not free a runner holding its next job.

tests/actions/test_runner_cancel_delivery.py

test_runner_job_cancellation.pyVerify cancellation messages and final conclusions +84/-0

Verify cancellation messages and final conclusions

• Checks one cancellation message per cancelled job, no message for an active job, and preservation of the cancelled conclusion when the runner reports completion.

tests/actions/test_runner_job_cancellation.py

test_runner_lost_handout.pyExercise abandoned polls and lost hand-out recovery +221/-0

Exercise abandoned polls and lost hand-out recovery

• Tests requeueing after lost first or subsequent messages, replacement of an older poll, and a multi-runner stress case with abandoned polls. The stress test verifies jobs complete once and runners finish idle.

tests/actions/test_runner_lost_handout.py

test_runner_orphaned_jobs.pyCover deleted jobs and idle-runner reconciliation +96/-0

Cover deleted jobs and idle-runner reconciliation

• Verifies that a deleted job triggers cancellation, an idle runner's older lost job fails and releases it, and busy or newly assigned runners remain occupied.

tests/actions/test_runner_orphaned_jobs.py

Documentation (7) +289 / -0
PLAN.mdIndex six resolved runner lifecycle bugs +6/-0

Index six resolved runner lifecycle bugs

• Adds links to the new fixed-bug write-ups in the runner evaluation plan.

PLAN.md

cancellation-never-reaches-a-runner-that-moved-on.mdDocument cancellation delivery races +34/-0

Document cancellation delivery races

• Explains how late completion reports and stale long-poll reads prevented cancellation delivery, and records the fixes and regression tests.

docs/bugs/fixed/cancellation-never-reaches-a-runner-that-moved-on.md

job-handed-to-an-abandoned-runner-poll.mdDocument recovery of abandoned hand-outs +66/-0

Document recovery of abandoned hand-outs

• Describes abandoned and timed-out polls, the poll-generation and acknowledgement safeguards, requeue behavior, tests, and a known test lock-timeout flake.

docs/bugs/fixed/job-handed-to-an-abandoned-runner-poll.md

runner-self-delete-leaves-jobs-pointing-at-it.mdDocument runner deletion and pool-poll fixes +28/-0

Document runner deletion and pool-poll fixes

• Records why runner deletion must detach historical jobs and why each pool long-poll pass needs a fresh transaction.

docs/bugs/fixed/runner-self-delete-leaves-jobs-pointing-at-it.md

runner-stays-busy-after-its-job-is-deleted.mdDocument orphaned-job recovery +41/-0

Document orphaned-job recovery

• Explains cancellation when a held job disappears, reconciliation when a runner reports itself idle, and the remaining lack of a server-side abandonment timeout.

docs/bugs/fixed/runner-stays-busy-after-its-job-is-deleted.md

two-runners-claim-the-same-job.mdDocument duplicate claims and conditional assignment +76/-0

Document duplicate claims and conditional assignment

• Details the race across both claim paths, the runner's lock-renewal behavior after losing a job, and the atomic-claim regression tests.

docs/bugs/fixed/two-runners-claim-the-same-job.md

upstream-runner-keeps-running-a-cancelled-job.mdDocument upstream runner cancellation +38/-0

Document upstream runner cancellation

• Describes cancellation messages, preservation of the cancelled conclusion after a runner report, and the in-memory delivery limitation.

docs/bugs/fixed/upstream-runner-keeps-running-a-cancelled-job.md

Other (1) +64 / -59
main.pyExpose runner broker diagnostics in server logs +64/-59

Expose runner broker diagnostics in server logs

• Attaches a handler to the emulator logger and makes its level configurable with GITHUB_EMULATOR_LOG_LEVEL. Other edits reorganize imports and simplify existing exception-suppression blocks.

src/app/main.py

@fullsend-ai-review

fullsend-ai-review Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

🤖 Finished Review · ✅ Success · Started 10:37 PM UTC · Completed 10:50 PM UTC

Commit: f5b9938 · View workflow run →

Runtime: pi · Model: sonnet → claude-sonnet-5-5 · Effort: high · Cost: $3.32

@qodo-code-review

qodo-code-review Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)

Grey Divider


Action required

1. Cancelled jobs can keep running unnoticed ✓ Resolved

Resolving commit: af18d34

Resolution reason
In _settle_idle_runner, before the in-progress search that clears the hold, the author added a
check: if the held job is cancelled and its cancellation is not yet acknowledged, and the job is
within the 2-minute idle grace period, the runner is kept busy and the function returns after
commit, so the hold is not dropped and _pending_cancellation can deliver the cancellation. The
cancellation is also now re-sent on every live poll until acknowledged (_cancellation_acknowledged),
and a poll re-checks generation and runner busy state before handing out a job. This differs from
the suggested fix (which checks pending cancellation directly before clearing) but addresses the
same race.
Description
_settle_idle_runner searches only for in_progress jobs, then clears _holding and marks the
runner online when that search is empty. If a cancellation has already marked the held job completed
while an earlier Online poll is still active, this runs before _pending_cancellation, so the
runner receives no cancellation and can be offered another job.

2. An abandoned poll can still take a job ✓ Resolved

Resolving commit: af18d34

Resolution reason
Adds a re-check of the poll generation (and client disconnect) immediately before the hand-out, so a
superseded poll returns 204 instead of claiming a job; also refreshes the runner's busy state before
claiming so an older poll's claim is not duplicated.
Description
dt_get_messages checks its generation only once before several awaited operations and a committed
claim. A newer poll can advance the generation while the older one is inside the lock, yet the older
poll still claims and returns the job to a response the runner may have abandoned.

3. A lost response loses the cancellation ✓ Resolved

Resolving commit: af18d34

Resolution reason
Delivery is tracked by the runner's acknowledgement rather than by building the response.
Unacknowledged cancellations are re-sent on later polls, so a lost response no longer suppresses the
cancellation. Per-runner acknowledgement state replaces the job-id set.
Description
_pending_cancellation adds the job ID to _cancellations_sent before its message response reaches
the runner. If that long-poll response is abandoned or lost, subsequent polls suppress the
cancellation even though the runner never received it.


Remediation recommended

4. A late report can still free a runner on its new job ✓ Resolved

Resolving commit: af18d34

Resolution reason
The diff adds _report_job_end, which runs _complete_job and the commit under
_runner_lock(runner.id), and routes dt_complete_job, dt_update_pool_job_request and
dt_delete_pool_job_request through it. Polls also take the same lock when claiming, and re-read
runner.busy/status before handing out a job (db.refresh). So a report can no longer interleave with
a poll's claim, which addresses the race. The fix serializes via the runner lock rather than the
conditional UPDATE suggested, but it is a valid alternative: the report's free and the claim's
busy=True are now mutually exclusive. The finding's "left busy" check in _complete_job is not shown
changed, but the race window it describes is closed by the lock.
Description
_complete_job decides through _runner_moved_on and then writes runner.busy = False without
holding _runner_lock, and the commit comes only after dispatch_ready_jobs and
check_run_completion have run. If the poll's claim of the next job commits busy=True inside that
window, the report's later commit overwrites it, so the runner shows idle while it runs that job and
the cancellation check skips it.

5. Restarted servers cannot cancel deleted jobs ✗ Dismissed
Description
_holding is process-local, and _pending_cancellation falls back to looking up a job row when
that map is empty. After repository deletion removes the held job row, an application restart loses
the only remaining job identity, so the runner's next poll cannot receive its cancellation.

6. Received jobs can return to the queue ✓ Resolved

Resolving commit: af18d34

Resolution reason
The fix serializes receipt-bearing events with settlement rather than adding receipt state to the
requeue predicate. Acknowledgements (dt_delete_pool_message) now take the runner's lock
(_runner_lock) so they cannot land mid-decision, and _settle_idle_runner runs under that same
per-runner lock via the poll path, with a re-check of the poll generation and a runner refresh
before claiming. Acknowledgements are stored per runner (_acknowledged[runner.id]) and the poll
re-reads the runner state before handing out a job. This matches the suggested fix's second option
("serialize acknowledgement and receipt-bearing timeline updates with settlement"). The
timeline-update path is not explicitly serialized in the diff, so the coverage is partial, but the
acknowledgement race the finding names is addressed.
Description
_settle_idle_runner checks _acknowledged and the loaded step state before issuing a requeue
update whose predicate checks neither receipt signal. An acknowledgement or timeline update arriving
between that check and the update can establish that the runner received the job, but the poll still
requeues it for another claim.

View medium (1)
7. Runners mid-job can no longer remove themselves ✓ Resolved

Resolving commit: af18d34

Resolution reason
Self-deregistration routes now pass fail_live_jobs=True; the helper fails the runner's in-progress
jobs (completed/failure), dispatches and completes their runs, then deletes the runner, while the
admin route still refuses with 422 for a running job.
Description
dt_delete_pool_agent and both pipelines deregister routes now call
_delete_runner_and_detach_history, which answers 422 whenever the runner still has an
in_progress job. Upstream runners never get a stale-job requeue unless an emulator-protocol runner
polls (_requeue_stale_jobs only runs from _poll_for_jobs), and the PR's known limits say a job
whose worker died stays in progress, so config.sh remove for such a runner now fails for good
where it used to succeed.


Informational

8. A bad log-level setting stops the server from starting ✓ Resolved

Resolving commit: af18d34

Resolution reason
Added _log_level(name) in src/app/main.py which strips and uppercases the value, uses
logging.getLevelName to resolve it, and if the result is not a known integer level logs a warning
naming the bad value and returns logging.INFO. setLevel is now called with the resolved level. A
test (tests/test_startup_logging.py::test_an_unknown_log_level_falls_back_to_info) checks the
fallback, a warning, and that ' warning ' is accepted. This is the same fix as suggested,
implemented without an explicit try/except ValueError.
Description
logger.setLevel(os.environ.get("GITHUB_EMULATOR_LOG_LEVEL", "INFO").upper()) runs when app.main
is imported and raises ValueError for any name logging does not recognise. A typo such as WARN 
or verbose therefore stops the app from importing at all, when it could fall back to INFO.

9. A poll-loop comment wrongly says commit expires objects ✓ Resolved

Resolving commit: af18d34

Resolution reason
The comment was rewritten to say the session does not expire on commit, and db.expire_all() was
restored after db.commit() in the poll loop, so the next pass reads fresh rows. This matches the
suggested fix (re-add expire_all after commit) and corrects the misleading comment.
Description
The new comment in _poll_for_jobs says the commit expires the loaded objects, and on that basis
db.expire_all() is removed, but async_session is created with expire_on_commit=False. A later
reader relying on the comment will expect fresh runner and job attributes on each pass, while the
identity map keeps returning the objects loaded on the first pass.

10. Two in-memory job-id sets grow forever ✓ Resolved

Resolving commit: af18d34

Resolution reason
The unbounded per-job set _acknowledged is replaced by a dict keyed by runner id (one entry per
runner, overwritten on each acknowledgement), so memory no longer grows with jobs.
_cancellations_sent is removed and replaced by _cancellation_acknowledged, also keyed per runner.
_runner_locks gains a pruning step that deletes stale entries from other event loops that are not
held. This addresses the growth concern differently from the suggested fix (no completion-based
pruning, but bounded per-runner structures), which is a valid alternative.
Description
_acknowledged and _cancellations_sent gain a job id for every acknowledged or cancelled job and
nothing ever removes one, and _runner_locks gains an entry for every (event loop, runner) pair. On
a long-running emulator this memory grows with the total number of jobs ever run rather than with
the number of runners.

Grey Divider

Context sources
❌ Tickets: failed to load — Ticket collection could not establish complete evidence
✅ Compliance rules (platform): 6 rules
✅ Cross-repo context — repo relationships
  Explored: repo: fullsend-ai/fullsend (sha: f28397f5) — View relationship
✅ Context preparation
  Commit messages: summarized; full text retained for this review
Review mode: Auto: 🧠 Deep: Concurrency-heavy runner lifecycle spans multiple independent paths and failure modes.

Grey Divider

Tip of the day
💡 Did you know, you can describe a rule in plain language on the Rules page and Qodo drafts it for you

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

Comment thread src/app/api/actions_distributed_task.py Resolved
Comment thread src/app/api/actions_distributed_task.py Resolved
Comment thread src/app/api/actions_distributed_task.py Resolved
Comment thread src/app/api/actions_distributed_task.py Resolved
Comment thread src/app/api/actions_distributed_task.py Resolved
Comment thread src/app/api/actions_distributed_task.py Resolved
Comment thread src/app/api/actions_distributed_task.py Resolved
Comment thread src/app/main.py Resolved
Comment thread src/app/api/actions_distributed_task.py Resolved
Comment thread src/app/api/actions_dispatch.py Resolved
@fullsend-ai-review fullsend-ai-review Bot added the risk/moderate PR risk: moderate label Nov 18, 2026
@fullsend-ai-review

fullsend-ai-review Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

Risk Assessment: moderate (2/5)

Details

Moderate risk preserved: substantial diff size and change coupling across Actions runner dispatch logic remain balanced by zero protected or security-sensitive paths, no dependency or CI changes, solid test coverage, and stable author history across incremental updates.

Previous run

Risk Assessment: moderate (2/5)

Details

Moderate risk: substantial diff size and change coupling across Actions runner dispatch logic are balanced by zero protected or security-sensitive paths, no dependency or CI changes, solid test coverage, and single-author stability.

Previous run (2)

Risk Assessment: moderate (2/5)

Details

Moderate risk: substantial diff size and change coupling across Actions runner dispatch logic are balanced by zero protected or security-sensitive paths, no dependency or CI changes, solid test coverage, and single-author stability.

Previous run (3)

Risk Assessment: moderate (2/5)

Details

Moderate risk: substantial diff size and change coupling across Actions runner dispatch logic are balanced by zero protected or security-sensitive paths, no dependency or CI changes, solid test coverage, and single-author stability.

Previous run (4)

Risk Assessment: moderate (2/5)

Details

Moderate risk: substantial diff size and change coupling across Actions runner dispatch logic are balanced by zero protected or security-sensitive paths, no dependency or CI changes, solid test coverage, and single-author stability.

Previous run (5)

Risk Assessment: moderate (2/5)

Details

Moderate risk: substantial diff size and change coupling across Actions runner dispatch logic are balanced by zero protected or security-sensitive paths, no dependency or CI changes, solid test coverage, and single-author stability.

Previous run (6)

Risk Assessment: moderate (2/5)

Details

Moderate risk: substantial diff size and change coupling across Actions runner dispatch logic are balanced by zero protected or security-sensitive paths, no dependency or CI changes, solid test coverage, and single-author stability.

@fullsend-ai-review

fullsend-ai-review Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

Review

Findings

Medium

  • [edge-case] src/app/api/actions_dispatch.py:479 — The conditional claim protects the job, but not the runner. Two concurrent custom-protocol polls authenticated as the same runner can claim different queued jobs: neither _poll_for_jobs nor this UPDATE checks or atomically reserves the runner's availability, and the upstream protocol's process-local lock cannot prevent this across server workers. Both jobs then remain assigned to one runner.
    Remediation: Atomically reserve an idle runner in the same transaction as the job claim, and abandon the claim if that reservation fails. Add a concurrent same-runner/two-job regression test.
  • [edge-case] src/app/api/actions_distributed_task.py:1325 — Concurrent JobCompleted events can still overwrite the first committed result and outputs. Both events can pass dt_raise_plan_event's status check before waiting for the runner lock. After the first event completes, _report_job_end rechecks only runner_id, and the _complete_job UPDATE (WHERE status != completed OR conclusion IS NULL OR conclusion != cancelled) permits an already-completed non-cancelled job to be written again, so a delayed event can replace outputs after dependent jobs consumed the first values. This contradicts the handler's own comment that a repeat after completion changes neither outputs nor result. A completed/cancelled row is correctly preserved.
    Remediation: Recheck terminal status under the runner lock and make the completion UPDATE conditional on a nonterminal stored status, keeping the separate path that frees a cancelled job's runner without replacing its outputs. Add a test with two completion events waiting on the same lock.
  • [breaking-api] src/app/api/actions_distributed_task.py — The broker protocol now sends new JobCancellation messages with ids offset by _CANCELLATION_MESSAGE_BASE, re-sent on every live poll until the runner deletes the message. Message-queue state lives only in process memory (_holding, _acknowledged, _cancellation_acknowledged, _poll_generation) and is lost on restart and not shared across multiple workers.
    Remediation: Document the new message type, id scheme, and single-process assumption.

Low

  • [edge-case] src/app/api/actions_distributed_task.py:1098 — Cancellation of a deleted job depends entirely on _holding. After a server restart clears that map, a runner still executing a deleted repository's job has no corresponding database job to recover here, so its Busy polls receive no cancellation and the deleted job keeps executing until the runner finishes.
    Remediation: Persist the outstanding runner hand-out, including its job GUID, or retain a durable cancellation tombstone when deleting its job.
  • [edge-case] src/app/api/actions_distributed_task.py:1088 — The restart fallback is bypassed by an Online poll. With _holding empty after restart and a recently cancelled job still assigned to a busy runner, _settle_idle_runner finds no in-progress jobs and clears the runner's busy state before _pending_cancellation runs; the grace-period protection only applies when _holding contains the job.
    Remediation: Recover the outstanding cancelled assignment before settling an Online runner, and apply the same acknowledgement/grace-period protection to recovered assignments.
  • [auth-bypass] src/app/api/actions_pipelines.py:191 — The unauthenticated pipelines deletion path invokes the helper with fail_live_jobs=True. An anonymous request can mark a runner's in-progress jobs completed/failure and trigger dependent-job dispatch and run completion; no caller identity, runner ownership, or repository authorization is checked. The repository pipelines DELETE route and the enterprise route likewise have no authentication dependency, so an anonymous caller knowing a runner ID can remove its registration and sessions.
    Remediation: Require authenticated, target-authorized deletion before enabling fail_live_jobs; add negative tests showing anonymous and unrelated callers cannot change live jobs.
  • [auth-bypass] src/app/api/actions_pipelines.py:184 — The repository pipelines deletion lookup validates runner_id only. Neither owner nor repo is resolved or compared with the runner's repository, so even a fabricated repository path can delete a runner belonging to another repository or enterprise.
    Remediation: Resolve owner/repo, constrain the runner lookup by repository ID, and independently authorize the caller to delete that target.
  • [injection-vuln] src/app/api/actions_distributed_task.py:1347 — Broker logging interpolates unescaped runner.name and result_str into server logs. A runner can submit a result containing newlines or control characters, forging subsequent log entries; other broker messages also interpolate runner.name and the user-controlled lastMessageId without escaping.
    Remediation: Escape control characters in runner names, reported results, and lastMessageId before logging, or use structured logging; log the normalized result.
  • [scope-creep] src/app/main.py:176 — Cosmetic sorting and reordering of middleware and REST API router imports in create_app() expands the diff without contributing to runner lifecycle defect remediation (the PR body acknowledges it as ruff import sorting).
    Remediation: Revert the cosmetic import reordering or move it into a project-wide formatting sweep.
  • [pattern-inconsistency] src/app/main.py:35 — Direct os.environ.get("GITHUB_EMULATOR_LOG_LEVEL", "INFO") at module load bypasses the application's configuration pattern (Settings in app/config.py); the _log_level parsing helper (line 26) likewise lives in app/main.py rather than with config normalization.
    Remediation: Add a LOG_LEVEL field on Settings and access it via settings.LOG_LEVEL.
  • [missing-doc] README.md:91 — The Configuration table in README.md lists GITHUB_EMULATOR_* variables but omits GITHUB_EMULATOR_LOG_LEVEL, introduced in src/app/main.py (sets the github_emulator logger level, default INFO).
    Remediation: Add an entry for GITHUB_EMULATOR_LOG_LEVEL to the Configuration table in README.md.
  • [breaking-api] src/app/api/actions_distributed_task.py — _report_job_end returns False and changes nothing when the job is no longer the runner's. dt_complete_job and both job-request finish paths turn that into a 404 / TaskAgentJobNotFound response; only dt_raise_plan_event ignores the result and answers 200, so a discarded JobCompleted event (outputs included) looks successful to the client.
    Remediation: Document as intended emulator behaviour; consider a distinguishable status or warning log for the raise-plan-event path.
  • [breaking-api] src/app/api/actions_distributed_task.py — Only a runner's newest poll (by arrival generation) may hand out a job, so older polls now get an empty response where they previously could receive a job.
    Remediation: Note it in the protocol documentation.
  • [breaking-api] src/app/api/actions_distributed_task.py — A runner reporting Online/idle while holding an in-progress job now has the job requeued (never received) or failed (idle past _IDLE_GRACE); runner state reports now have side effects on jobs.
    Remediation: Document the thresholds _ACK_WINDOW and _IDLE_GRACE.
  • [backward-incompatible] src/app/api/actions_runners.py:180 — _delete_runner_and_detach_history has a new fail_live_jobs mode: a runner deleting itself now fails its live jobs with failure where before it was refused with 422; the 422 stays for other callers.
    Remediation: Document the difference between self-delete and admin delete.
  • [breaking-api] src/app/api/actions_distributed_task.py:1318 — A cancelled job keeps cancelled and its existing outputs when the runner reports its end; _complete_job applies reported outputs in the same conditional UPDATE, so outputs from a late report are discarded. Intended by the PR (tested).
    Remediation: Document the new semantics.
  • [breaking-api] src/app/api/actions_distributed_task.py:1243 — _free_runner_unless_cancelled and _settle_idle_runner keep a runner busy while its held job's cancellation is unacknowledged; an Online poll no longer frees the runner immediately.
    Remediation: Document the grace period.
  • [breaking-api] src/app/api/actions_distributed_task.py:1212 — A job a runner never received is requeued with runner_id, runner_name and started_at cleared; API consumers can see in_progress go back to queued.
    Remediation: Document the transition.

Earlier findings

  • PR-level / src/app/api/actions_distributed_task.py:1856, edge-case, resolved — dt_raise_plan_event no longer writes job.outputs before the runner lock; outputs now go through _report_job_end into _complete_job's conditional UPDATE (incremental diff).
  • alembic/env.py:18 and src/app/main.py:109, scope-creep, reclassified to info — both enable this PR's new github_emulator.runner_broker log handler (documented bug entry, covered by tests/test_startup_logging.py).
  • src/app/api/actions_distributed_task.py, breaking-api (plan/timeline scoping in _job_for_plan), reclassified to info — identical on the base branch.

Next steps:

  • /fs-fix — agent addresses review findings automatically
  • /fs-fix <your instruction> — agent fixes with your specific guidance
  • Push commits directly — review re-runs automatically on push
  • /fs-fix-stop — disable automatic fix runs for this PR

4 finding(s) below the low severity threshold were not posted.

Previous run

<!--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ImlkIjoiZl8xNDAxNzRmMDRmZWViOWUwIiwic3RhdHVzIjoicmVzb2x2ZWRfYnlfY2hhbmdlIn0seyJpZCI6ImZfNGVlYWQ5YTZhNmMyYTEzMSIsInN0YXR1cyI6InJlc29sdmVkX2J5X2NoYW5nZSJ9LHsiaWQiOiJmXzI0MzQ3NzFhZmQ3OTVkZTMiLCJzdGF0dXMiOiJyZXNvbHZlZF9ieV9jaGFuZ2UifSx7ImlkIjoiZl9mNTg5NTE1ZDkzZTMwNmU0Iiwic3RhdHVzIjoicmVzb2x2ZWRfYnlfY2hhbmdlIn0seyJpZCI6ImZfNjdjMGM1ODM2ZDBiNzcxNSIsInN0YXR1cyI6InJlc29sdmVkX2J5X2NoYW5nZSJ9LHsiaWQiOiJmX2I2YmZlY2VlY2ZjNDk5ODciLCJzdGF0dXMiOiJyZXNvbHZlZF9ieV9jaGFuZ2UifSx7ImlkIjoiZl9mNTc4ZjI1YmQwZjE2NmU1Iiwic3RhdHVzIjoicmVzb2x2ZWRfYnlfY2hhbmdlIn0seyJpZCI6ImZfNzQzZTU4ZmZiN2I2ZTc2OSIsInN0YXR1cyI6InJlc29sdmVkX2J5X2NoYW5nZSJ9LHsiaWQiOiJmXzQzZTA4YjJiNjRkMmYwZjMiLCJzdGF0dXMiOiJyZXNvbHZlZF9ieV9jaGFuZ2UifSx7ImlkIjoiZl80ODc4Y2RkYTNjM2EzNjAxIiwic3RhdHVzIjoicmVzb2x2ZWRfYnlfY2hhbmdlIn1dfQ== -->

Review

Findings

Medium

  • [edge-case] src/app/api/actions_dispatch.py:482 — A custom-runner poll that finds no work calls db.expire_all() before sleeping (line ~589). That also expires the Runner. If a job appears on a later pass, _claim_queued_job reads runner.id and runner.name synchronously. Loading expired attributes on an AsyncSession raises MissingGreenlet, so work that arrives during a long poll produces an error instead of a hand-out. The new comment in the same function says the runner must not be expired.
    Remediation: Await db.refresh(runner) before using its attributes after expire_all(), or expire only the job/run objects. Add a regression test that queues work after the custom-runner poll has finished an empty pass.
  • [edge-case] src/app/api/actions_distributed_task.py:1856 — dt_raise_plan_event assigns job.outputs before taking the runner lock and re-checking ownership. If the job is requeued, reassigned or cancelled while the report waits, _report_job_end's ownership SELECT autoflushes the dirty outputs, and the rejected-ownership branch commits them (_complete_job also flushes before its conditional UPDATE). A report that should change nothing can persist outputs on a requeued, reassigned or cancelled job.
    Remediation: Move the status/ownership checks and the output assignment inside the same runner-locked transaction as completion, refresh the job there, and leave outputs untouched on rejected ownership or cancellation. Test an output-bearing JobCompleted event that waits behind a requeue and behind a cancellation.
  • [breaking-api] src/app/api/actions_distributed_task.py — Job-completion and job-request endpoints (dt_complete_job, dt_update_pool_job_request, dt_delete_pool_job_request) now answer 404 when the runner no longer holds the job; a late report for a requeued job used to get 200/204. _complete_job is also guarded by a per-runner lock and a moved-on check, so a late report for a job the runner has left completes the job but does not free the runner. The PR body documents this change.
    Remediation: Document the 404 and the lock/ownership semantics in the runner-protocol docs, and keep a test for the legacy report flow.
  • [breaking-api] src/app/api/actions_distributed_task.py — Message poll behaviour changed: cancellation messages use the _CANCELLATION_MESSAGE_BASE message-id offset, a lost hand-out is requeued, and an Online poll fails a job the runner lost. The message-id space and poll outcomes are now part of the protocol served to runners.
    Remediation: Document the message-id offset and the new poll outcomes. Make sure ids at or above the base cannot collide with real job ids.
  • [breaking-api] src/app/api/actions_distributed_task.py — A poll that is superseded, or whose claim loses the race, now returns 204 where it used to hand out a job. Jobs are claimed at most once, so a client that relied on the old double hand-out sees different behaviour. The change is intended and low risk for real runners.
    Remediation: Note the change in the protocol docs or changelog.

Low

  • [auth-bypass] src/app/api/actions_pipelines.py:191 — The pipelines runner-delete endpoints (repository and enterprise) have no authentication dependency or credential check. An anonymous caller who supplies a runner id can delete the registration. With fail_live_jobs=True the request now also fails the runner's running jobs and dispatches downstream work.
    Remediation: Require a valid runner/removal credential or an authorized administrator before calling the deletion helper. Add anonymous-request rejection tests for both endpoints.
  • [auth-bypass] src/app/api/actions_pipelines.py:184 — The repository pipelines delete handler selects the target only by Runner.id == runner_id. owner and repo are never resolved or checked against Runner.repo_id, so a repository-shaped URL can delete a runner of another repository or an enterprise and fail its active jobs.
    Remediation: Resolve the repository, constrain the target by runner id and repository id, and verify the caller may remove it. Test cross-repository and enterprise runner ids through this route.
  • [injection-vuln] src/app/api/actions_distributed_task.py:1340 — The newly enabled broker logging writes runner-controlled strings into plaintext server logs. This completion message logs runner.name and result_str unsanitized; other broker messages log runner.name, and the requeue message logs the unchecked lastMessageId query value. Newlines or terminal control characters can forge log records. Parameterized logging does not prevent that.
    Remediation: Escape CR/LF, ANSI escapes and other control characters in runner names, reported results and lastMessageId before logging, or use a formatter that encodes every string field.
  • [edge-case] src/app/api/actions_distributed_task.py:1098 — The restart fallback cannot recover a held job that was deleted. After a server restart _holding is empty, so the fallback only searches existing WorkflowJob rows. If the held job's repository was deleted, no cancellation is returned, and a runner still executing that job never receives it.
    Remediation: Persist the runner-to-job association independently of repository/job deletion and clear it on completion or cancellation acknowledgement. Cover restart after deletion in a test.
  • [scope-creep] src/app/main.py:182 — Bulk re-sorting of the router and middleware imports in create_app() is cosmetic and outside the runner lifecycle scope that issue Upstream the emulator fixes found by fullsend's behaviour tests #39 authorizes for this PR.
    Remediation: Revert the import re-sorting in src/app/main.py, keeping only imports the runner lifecycle changes need.
  • [scope-creep] src/app/main.py:109 — Admin-password log scrubbing in _ensure_admin_user() and the general github_emulator logger setup are logging and security hygiene changes beyond the runner job lifecycle fixes. A comment ties the logger setup to surfacing hand-out logs, so only the password scrubbing is clearly unrelated.
    Remediation: Move the admin-password log scrubbing and general logging configuration into a separate hygiene PR.
  • [scope-creep] alembic/env.py:18 — Changing the Alembic logging configuration (disable_existing_loggers=False, configure_logger check) and reordering model imports is outside the scope that issue Upstream the emulator fixes found by fullsend's behaviour tests #39 authorizes for this PR.
    Remediation: Move the Alembic logging and import changes into a separate database/logging PR.
  • [pattern-inconsistency] src/app/main.py:35 — GITHUB_EMULATOR_LOG_LEVEL is read with os.environ.get(...) and parsed by a module-level _log_level helper (line 26) in main.py. Every other GITHUB_EMULATOR_* setting is declared and parsed in app.config.Settings.
    Remediation: Declare LOG_LEVEL: str = 'INFO' in Settings (src/app/config.py), normalize unknown values with a field validator, and read settings.LOG_LEVEL in main.py.
  • [missing-doc] README.md:91 — This PR adds the GITHUB_EMULATOR_LOG_LEVEL variable (default INFO), but the Configuration table in README.md does not list it with the other GITHUB_EMULATOR_* variables.
    Remediation: Add a GITHUB_EMULATOR_LOG_LEVEL row (default INFO; sets the level for the github_emulator and runner broker loggers) to the Configuration table in README.md.
  • [breaking-api] src/app/api/actions_distributed_task.py — The not-found response for job-request endpoints changed from a bare HTTPException to a TaskAgentJobNotFoundException JSON body. It keeps detail, but the body shape changed.
    Remediation: No change required; keep the detail field.
  • [breaking-api] src/app/api/actions_distributed_task.py — dt_delete_pool_message now records acknowledgements in server state, only for the message id the runner currently holds. An ack for any other message is ignored but still returns 200. The response is unchanged, but the ack now has side effects.
    Remediation: No change required; document the ack semantics.
  • [backward-incompatible] src/app/api/actions_runners.py:180 — Runner self-deregistration through the pipelines endpoints (fail_live_jobs=True) now succeeds while a job is in progress and marks that job failed. The REST delete endpoints still refuse with 422 for a runner with a live job, so the two delete paths now behave differently.
    Remediation: Document the difference between the two delete paths.

Next steps:

  • /fs-fix — agent addresses review findings automatically
  • /fs-fix <your instruction> — agent fixes with your specific guidance
  • Push commits directly — review re-runs automatically on push
  • /fs-fix-stop — disable automatic fix runs for this PR

fullsend-ai-review[bot]

This comment was marked as outdated.

fullsend-ai-review[bot]

This comment was marked as outdated.

@fullsend-ai-review

fullsend-ai-review Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

🤖 Finished Review · ✅ Success · Started 11:17 PM UTC · Completed 11:37 PM UTC

Commit: af18d34 · View workflow run →

Runtime: pi · Model: sonnet → claude-sonnet-5-5 · Effort: high · Cost: $3.62

fullsend-ai-review[bot]

This comment was marked as outdated.

@waynesun09
waynesun09 force-pushed the emu-04-runner-lifecycle branch from af18d34 to 0fbcaea Compare November 18, 2026 23:39
@fullsend-ai-review

fullsend-ai-review Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

🤖 Finished Review · ✅ Success · Started 11:42 PM UTC · Completed 12:02 AM UTC

Commit: 0fbcaea · View workflow run →

Runtime: pi · Model: sonnet → claude-sonnet-5-5 · Effort: high · Cost: $4.28

fullsend-ai-review[bot]

This comment was marked as outdated.

fullsend-ai-review[bot]

This comment was marked as outdated.

@fullsend-ai-review

fullsend-ai-review Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

🤖 Finished Review · ✅ Success · Started 1:21 AM UTC · Completed 1:39 AM UTC

Commit: 352fc40 · View workflow run →

Runtime: pi · Model: sonnet → claude-sonnet-5-5 · Effort: high · Cost: $4.89

fullsend-ai-review[bot]

This comment was marked as outdated.

@jctanner jctanner left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Requesting changes — the mechanisms are real and well tested (the squad verified the atomic claim, the cancellation redelivery, the conditional completion, and the delete-detach), but two race windows remain that re-open exactly the class this PR closes:

  1. A cancellation can be lost while an Online poll settles. In _settle_idle_runner, a cancellation that commits between the held-job read and the in-progress-jobs query (which filters status="in_progress" and so misses the now-completed cancelled job) results in the hold being popped and the runner marked idle; _pending_cancellation then sees an idle runner and returns nothing — the worker is never told to stop. Re-read the held job's conclusion before clearing the hold (and serialize that decision with cancellation writes), plus the interleaving test the bot sketched.
  2. Poll generations are assigned after the initial awaits (token lookup, session select, heartbeat commit), so an older abandoned request delayed in those awaits can take a higher generation than a newer live poll and supersede it. Capture a monotonically increasing arrival sequence synchronously at handler entry and register the poll with it; add the reversed-initialization-order test.
  3. (Codex) _complete_job doesn't revalidate job ownership after waiting on the runner lock — a report that waited on the lock can complete a job the runner no longer holds. Re-check the hold/ownership after the lock wait.
    Also worth folding in: the pre-existing unauthenticated pipelines deregister is amplified by fail_live_jobs=True (#44's own-token requirement fixes it — coordinate), the docs misattribute the pool long-poll to actions_pipelines.py, and the main.py/alembic refactors are scope creep the bot already noted.

@waynesun09

Copy link
Copy Markdown
Member Author

Thanks, James. Rebased onto main at 3f31565 (with #30 and #31). #31's _job_for_plan checks and validate_job_token are kept on the job-server routes. Your items, in order:

  1. Cancellation during an Online settle: fixed in 1102702. The runner is now freed by one conditional UPDATE that re-reads the held job's conclusion, so a cancellation that commits mid-settle keeps the runner busy and goes out on that poll. The decision is serialised in the database, not with the runner lock: the cancellation writers (run cancel, concurrency supersede, run creation) run inside other requests' transactions, and one of them is reached from _complete_job while that lock is held. Test: test_a_cancellation_committed_while_an_online_poll_settles_is_sent commits the cancellation between the two reads.
  2. Poll generations: fixed in 1102702. A poll's generation is now its arrival number, taken before its first await. A poll that registers after a newer one keeps the newer generation and answers 204. Test: test_an_older_poll_that_initialises_last_does_not_replace_the_newer_one delays the older poll's token lookup until the newer poll is waiting.
  3. Ownership after the lock wait: fixed in 1102702. _report_job_end re-reads the job's runner once it holds the lock, and changes nothing if the job moved. The pool routes then answer TaskAgentJobNotFoundException; the legacy route answers 404. Test: test_a_report_that_waited_on_the_lock_does_not_end_a_job_its_runner_lost.
  4. Docs: fixed in d22851c. The long-poll that fix changed is the custom runner's _poll_for_jobs in actions_dispatch.py. The bug note now says so, and the PR description is corrected.
  5. Scope: b621b9c undoes the contextlib.suppress rewrites in main.py. What is left is the admin-password log fix, the log handler and level fallback, and ruff's import order. The import order has to stay: since Add repository hygiene: locked hash-checked installs, pre-commit, secret scanning, runner TLS verification #30, the hygiene check lints every file a PR touches, and main.py fails I001 on main. The alembic change stays as is (two lines in env.py, one in migrations.py). Without it, the startup migration disabled every existing logger, the app's included, so the broker's log lines this PR adds never appeared. tests/test_startup_logging.py covers it.
  6. Unauthenticated pipelines deregister: fix(#43): verify runner credentials on token exchange and deregister #44 (the fix for Check the runner's credential on the token exchange and deregister routes #43) makes both pipelines deregister routes require the runner's own token: 401 with no token, 403 with another runner's. That removes the case fail_live_jobs=True makes worse, so this PR leaves it to fix(#43): verify runner credentials on token exchange and deregister #44.

@fullsend-ai-review

fullsend-ai-review Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

🤖 Finished Review · ✅ Success · Started 5:42 PM UTC · Completed 5:58 PM UTC

Commit: d22851c · View workflow run →

Runtime: pi · Model: sonnet → claude-sonnet-5-5 · Effort: high · Cost: $3.70

fullsend-ai-review[bot]

This comment was marked as outdated.

fullsend-ai-review[bot]

This comment was marked as outdated.

GitHub assigns each job to exactly one runner. Both of the emulator's claim
paths, the emulator runner's poll (_poll_for_jobs) and the upstream
runner's message poll (_claim_next_job), read the queued jobs and then
wrote the assignment unconditionally. Two polls in separate sessions could
both read a job as queued and both claim it, so the job ran twice. With
four site-wide emulator runners and eight concurrent runs, five of 32 jobs
ran on two runners each. With two upstream runners, both ran job request 1.

The claim is now a conditional UPDATE on status = 'queued'. Only the poll
whose update changes the row owns the job and marks its runner busy. A poll
that loses moves on to the next matching job, or returns no job.

The upstream runner that lost the job got a bare 404 on every lock renewal.
The runner retries that, so it kept renewing and never took another job. It
gives a job up only on TaskAgentJobNotFoundException, so accepting,
renewing or completing a job request the runner does not hold now returns a
404 with that exception body.

Assisted-by: Claude
Signed-off-by: Wayne Sun <gsun@redhat.com>
A job request a runner does not hold answered {"detail": "Job request not
found"} before, and now the wrapped TaskAgentJobNotFoundException the
runner reads. The wrapped body keeps that detail field too, for clients
that read it.

Assisted-by: Claude
Signed-off-by: Wayne Sun <gsun@redhat.com>
Startup imports app.main, which sets up the github_emulator logger, then
runs the Alembic migrations. alembic/env.py applied alembic.ini's logging
with fileConfig, whose default disables every logger that already exists,
so the app's own lines stopped after startup. In the test suite, any
migration test that ran after app.main was imported did the same, which
left the startup-logging tests with an empty capture in CI.

env.py now applies alembic.ini's logging only on the command line (the app
sets configure_logger to False) and never disables existing loggers.

Assisted-by: Claude
Signed-off-by: Wayne Sun <gsun@redhat.com>
- A poll replaced while it claimed a job gave that job to a request the
  runner no longer reads. The poll checks again after the claim, gives the
  job back and frees the runner.
- A report of a job's end checked for a cancellation on the job it loaded
  before it took the runner's lock, so a cancellation committed meanwhile
  was overwritten. The write is now conditional on the stored row.
- A late Online poll freed a runner whose held job was deleted before the
  cancellation went out. Settling now keeps the runner busy until the
  runner acknowledges that cancellation.

Assisted-by: Claude
Signed-off-by: Wayne Sun <gsun@redhat.com>
- An Online poll that settles a busy runner read the held job, then
  listed the runner's in-progress jobs. A cancellation committing in
  between hid the job from the list, so the poll dropped the hold and
  freed the runner, and the cancellation was never sent. The runner is
  now freed by one conditional UPDATE that re-reads the held job's
  conclusion; a cancelled or deleted job keeps it busy, and the
  cancellation goes out on that poll. The cancellation writers run in
  other requests' transactions and do not take the runner's lock, so
  the decision is serialised in the database.
- A poll's generation was taken after its token lookup, session read
  and heartbeat commit, so an older poll delayed there could outrank a
  newer live one and take its job. The generation is now the poll's
  arrival number, taken before its first await; a poll that registers
  after a newer one keeps the newer one's generation and returns 204.
- A job report checked ownership before waiting on the runner's lock.
  A requeue under the lock could leave it completing a job the runner
  no longer held. _report_job_end now re-reads the job's runner once it
  holds the lock and changes nothing when it moved; the pool routes
  answer TaskAgentJobNotFoundException, the legacy route 404.

Each case has a test in test_runner_broker_races.py that fails on the
previous head.

Assisted-by: Claude
Signed-off-by: Wayne Sun <gsun@redhat.com>
Review asked to keep app/main.py and alembic to this branch's fixes.
The branch has to touch app/main.py (the admin password out of the
startup log, a handler and a GITHUB_EMULATOR_LOG_LEVEL fallback for the
app's loggers), and since #30 the hygiene check runs ruff on every file
a change touches. So app/main.py keeps ruff's import order (I001), and
its two try/except-pass blocks go back to main's shape with a noqa
for S110 instead of the contextlib.suppress rewrite.

alembic/env.py, migrations.py and tests/test_startup_logging.py get
ruff's import order for the same reason; their logging fix is
unchanged.

Assisted-by: Claude
Signed-off-by: Wayne Sun <gsun@redhat.com>
The note called it the pool long-poll. The fix was in the custom
runner's job long-poll, _poll_for_jobs in actions_dispatch.py; the
distributedtask message poll is dt_get_messages in
actions_distributed_task.py.

Assisted-by: Claude
Signed-off-by: Wayne Sun <gsun@redhat.com>
#34's plan-events route completed only a job still in progress. A job
cancelled while it ran is already completed, so its JobCompleted event
returned early and its runner stayed busy for good. A cancelled job now
reaches _complete_job too, which keeps the cancelled conclusion and
frees the runner; its outputs are left unchanged. A queued job, or a
job completed otherwise, still returns early.

The report goes through _report_job_end, so it runs under the runner's
lock and leaves a job that moved off the runner as it is, as the other
report routes do.

Test: test_job_completed_for_a_cancelled_job_frees_the_runner, from the
combined validation branch.

Assisted-by: Claude
Signed-off-by: Wayne Sun <gsun@redhat.com>
@waynesun09
waynesun09 force-pushed the emu-04-runner-lifecycle branch from d22851c to 11d6f3b Compare November 19, 2026 18:25
@waynesun09

Copy link
Copy Markdown
Member Author

Rebased onto main at 69c2a2b, which now has #27, #34, #36 and #38. #31's and #34's checks on the job-server routes are unchanged. main.py registers the pipelines router and #38's results router.
New commit 11d6f3b, from the #34 merge: a JobCompleted event for a job cancelled while it ran now reaches _complete_job through _report_job_end. The job keeps cancelled and its outputs, and the runner is freed; before, the runner stayed busy. Test: test_job_completed_for_a_cancelled_job_frees_the_runner. The other-plan 404 test came with #34.

@fullsend-ai-review

fullsend-ai-review Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

🤖 Finished Review · ✅ Success · Started 6:27 PM UTC · Completed 6:46 PM UTC

Commit: 11d6f3b · View workflow run →

Runtime: pi · Model: sonnet → claude-sonnet-5-5 · Effort: high · Cost: $4.73

fullsend-ai-review[bot]

This comment was marked as outdated.

fullsend-ai-review[bot]

This comment was marked as outdated.

dt_raise_plan_event set job.outputs before it took the runner's lock.
If the job was requeued or cancelled while the event waited, the
ownership check's autoflush (or _complete_job's flush) still wrote the
outputs. The outputs now go into _complete_job's conditional UPDATE,
so a rejected or cancelled report leaves them as they were.

Assisted-by: Claude
Signed-off-by: Wayne Sun <gsun@redhat.com>
_poll_for_jobs expires the session between passes, which expired the
runner too. A job queued during the long poll then failed the claim
with MissingGreenlet when _claim_queued_job read runner.id. Refresh
the runner after the wait, inside the next pass's read.

Assisted-by: Claude
Signed-off-by: Wayne Sun <gsun@redhat.com>
@fullsend-ai-review

fullsend-ai-review Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

🤖 Finished Review · ✅ Success · Started 7:13 PM UTC · Completed 7:28 PM UTC

Commit: 20a9861 · View workflow run →

Runtime: pi · Model: sonnet → claude-sonnet-5-5 · Effort: high · Cost: $3.06

waynesun09 added a commit that referenced this pull request Nov 19, 2026
repos.py: sorted imports, an unused Optional import and an unused
Response; the same fixes as on #29.

Assisted-by: Claude
Signed-off-by: Wayne Sun <gsun@redhat.com>

@fullsend-ai-review fullsend-ai-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Note: The following review comments could not be posted on the diff (GitHub returned 422) and are included here instead:

  • src/app/api/actions_pipelines.py (file-level): Line 184 ·
    [low] auth-bypass

The repository pipelines deletion lookup validates runner_id only. Neither owner nor repo is resolved or compared with the runner's repository, so even a fabricated repository path can delete a runner belonging to another repository or enterprise.

Suggested fix: Resolve owner/repo, constrain the runner lookup by repository ID, and independently authorize the caller to delete that target.

  • src/app/main.py (file-level): Line 176 ·
    [low] scope-creep

Cosmetic sorting and reordering of middleware and REST API router imports in create_app() expands the diff without contributing to runner lifecycle defect remediation (the PR body acknowledges it as ruff import sorting).

Suggested fix: Revert the cosmetic import reordering or move it into a project-wide formatting sweep.

@fullsend-ai-review fullsend-ai-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

See the review comment for full details.

Comment thread src/app/api/actions_dispatch.py Resolved
Comment thread src/app/api/actions_distributed_task.py Resolved
Comment thread src/app/api/actions_distributed_task.py Resolved
Comment thread src/app/api/actions_distributed_task.py Resolved
Comment thread src/app/api/actions_pipelines.py Resolved
Comment thread src/app/main.py Resolved
Comment thread src/app/api/actions_runners.py Resolved
Comment thread src/app/api/actions_distributed_task.py Resolved
Comment thread src/app/api/actions_distributed_task.py Resolved
Comment thread src/app/api/actions_distributed_task.py Resolved

@jctanner jctanner left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Re-verified at 20a9861 — all three races fixed: poll generations now come from a monotonic arrival counter taken before the first await; _settle_idle_runner tracks the watched job and re-checks its cancellation (_free_runner_unless_cancelled) before freeing the runner; _complete_job revalidates via _runner_moved_on after the lock wait. Approving.

@jctanner jctanner left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Re-verified at 20a9861 — all three races fixed: poll generations now come from a monotonic arrival counter taken before the first await; _settle_idle_runner tracks the watched job and re-checks its cancellation (_free_runner_unless_cancelled) before freeing the runner; _complete_job revalidates via _runner_moved_on after the lock wait. Approving.

@jctanner jctanner left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Re-verified at 20a9861 — all three races fixed: poll generations from a monotonic arrival counter before the first await; the watched job's cancellation re-checked (_free_runner_unless_cancelled) before freeing; _complete_job revalidates via _runner_moved_on after the lock wait. Approving.

@waynesun09
waynesun09 merged commit 49ab67b into main Nov 19, 2026
370 of 371 checks passed
@waynesun09
waynesun09 deleted the emu-04-runner-lifecycle branch November 19, 2026 23:16
waynesun09 added a commit that referenced this pull request Nov 19, 2026
repos.py: sorted imports, an unused Optional import and an unused
Response; the same fixes as on #29.

Assisted-by: Claude
Signed-off-by: Wayne Sun <gsun@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working risk/moderate PR risk: moderate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants