8000 Separate heartbeat adoption decisions from their side effects by chrismeyersfsu · Pull Request #16722 · ansible/awx · GitHub
[go: up one dir, main page]

Skip to content

Separate heartbeat adoption decisions from their side effects - #16722

Closed
chrismeyersfsu wants to merge 1 commit into
ansible:develfrom
chrismeyersfsu:cmeyers/adoption-decisions
Closed

chrismeyersfsu wants to merge 1 commit into
ansible:develfrom
chrismeyersfsu:cmeyers/adoption-decisions

Conversation

@chrismeyersfsu
Copy link
Copy Markdown
Member
SUMMARY

The heartbeat's decisions about lost instances and orphaned jobs are mixed in with the queries, receptor calls and dispatcher calls that act on them. Testing a decision today means setting up all of that, which in practice means a running cluster.

This moves the decisions into awx/main/tasks/adoption_decisions.py. They read plain attributes and touch no database, receptor or dispatcher:

Function Decides
find_lost_instances Which peers are lost (this instance is judged separately)
gate_lost_instances Which lost instances may be handled while the mesh re-establishes (execution and hop only)
lost_instance_job_action What happens to a running job of a lost instance (reap today; the AAP-89602 adoption hook)
lost_instance_disposition Deprovision, mark offline, or leave the lost instance
startup_job_action Adopt or reap a running job at startup
running_job_action Adopt, reap or leave a possibly orphaned job on a periodic heartbeat
adoption_deadline_passed Whether an orphan has been silent past HADR_JOB_ADOPTION_TIMEOUT

awx/main/tasks/system.py keeps its queries and side effects and calls these. Behavior is unchanged. The query in _process_running_jobs still narrows the candidates; running_job_action repeats its conditions so the decision is complete and testable on its own.

Why: cross-controller adoption (AAP-89602, #16669) adds several new decisions here: when a controller is really gone, whether there is capacity to adopt, and who owns a claimed job. Failure testing of #16669 on a docker-compose cluster turned up defects in exactly these decisions: a slow controller judged lost while still running, claims at zero capacity, and a silent playbook timed out as dead. Each of those took a cluster run of 5 to 25 minutes to reproduce. With the decisions separated, the same cases are table-driven unit tests that run in milliseconds. A few such cases are included as examples (slow controller, clock skew, quiet job). They document today's behavior; they do not change it.

ISSUE TYPE
  • Bug, Docs Fix or other nominal change
COMPONENT NAME
  • Other (dispatcher heartbeat)
STEPS TO REPRODUCE AND EXTRA INFO
$ py.test awx/main/tests/unit/tasks/test_adoption_decisions.py awx/main/tests/unit/tasks/test_receptor_adoption.py \
    awx/main/tests/functional/tasks/test_tasks_system.py awx/main/tests/functional/test_dispatch.py
213 passed
$ py.test awx/main/tests/unit/tasks awx/main/tests/functional/tasks
320 passed
$ ruff check / ruff format --check (changed files)
All checks passed!

Move the decisions the heartbeat makes about lost instances and orphaned
jobs into awx.main.tasks.adoption_decisions: which peers are lost, which
lost instances the mesh gate lets through, what happens to a lost
instance and its jobs, whether a running job is adopted, reaped or left
alone, and whether an orphan is past the adoption deadline. The
functions read plain attributes and touch no database, receptor or
dispatcher, so they can be tested with simple objects.

awx.main.tasks.system keeps the queries and side effects and calls the
decisions. Behavior is unchanged.

Co-Authored-By: Claude <noreply@anthropic.com>
@coderabbitai
coderabbitai Bot commented Oct 11, 2026
Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true

Comment @coderabbitai help to get the list of available commands.

@sonarqubecloud
Copy link
Copy Markdown

@chrismeyersfsu
Copy link
Copy Markdown
Member Author

Superseded by the stacked PRs starting at #16723 (then #16724, with two more to follow).

@codecov
codecov Bot commented Oct 11, 2026 •
Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.42105% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.08%. Comparing base (f8314ad) to head (44e5e2f).
✅ All tests successful. No failed tests found.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

0