Skip to content

fix: eliminate race condition in awxkit gateway user sync - #16658

Open
adrisala wants to merge 1 commit into
develfrom
fix/awxkit-user-create-race-condition
Open

adrisala wants to merge 1 commit into
develfrom
fix/awxkit-user-create-race-condition

Conversation

@adrisala

@adrisala adrisala commented Sep 16, 2026

Copy link
Copy Markdown
Contributor
SUMMARY

User.create() polls controller for gateway user sync via poll_until, then makes a second GET call to retrieve the user. Under CI load, this second call can return empty results (race condition), causing IndexError: pop from empty list.

Fix: return the user object directly from poll_until instead of doing a redundant second GET.

Affects 11+ tests in tower-qa CI pipeline controller-2.7-next-cont-a-legacy that create users through the gateway flow.

ISSUE TYPE
  • Bug, Docs Fix or other nominal change
COMPONENT NAME
  • Other
STEPS TO REPRODUCE AND EXTRA INFO
  1. Run tower-qa tests that create users via gateway on a loaded 2.7 containerized environment
  2. factories.user() calls User.create() which posts to gateway, then polls controller for sync
  3. After poll_until confirms sync, a second ctrl_users_api.get().results.pop() can fail with IndexError if the second GET races

Before:

poll_until(
    lambda: len(ctrl_users_api.get(username=gw_user.username).results) > 0,
    interval=1, timeout=30,
)
user = ctrl_users_api.get(username=gw_user.username).results.pop()  # RACE!

After:

def _get_synced_user():
    results = ctrl_users_api.get(username=gw_user.username).results
    return results[0] if results else None

user = poll_until(_get_synced_user, interval=1, timeout=30)

Verified on live 2.7 containerized environment.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Improved gateway user creation by reliably waiting for controller synchronization before completing the operation.
    • The newly synchronized user is now returned directly when available, while unavailable users are handled safely without causing an additional lookup failure.
    • Existing polling timing and timeout behavior remain unchanged.

@coderabbitai

coderabbitai Bot commented Sep 16, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: 27443d64-e7e3-4846-be01-154d8225b553

📥 Commits

Reviewing files that changed from the base of the PR and between f332cce and 86d4e89.

📒 Files selected for processing (1)
  • awxkit/awxkit/api/pages/users.py

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

The gateway user-creation flow now returns the first controller-synced user from polling. It removes the separate readiness poll and second user fetch. The polling interval remains 1 second, and the timeout remains 30 seconds.

Changes

Gateway user synchronization

Layer / File(s) Summary
Return the synchronized controller user
awxkit/awxkit/api/pages/users.py
poll_until assigns the result of _get_synced_user directly to user. The redundant second GET and pop are removed. The polling interval and timeout remain unchanged.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Merge Risk: ⚪ Minimal · up to 86d4e

The synchronization change removes the redundant fetch without introducing a concrete user-creation or merge-blocking risk.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 1 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: fixing the race condition in awxkit gateway user synchronization.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/awxkit-user-create-race-condition

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

poll_until confirms the user exists in controller after gateway
creation, but a second GET call could return empty results under
load. Return the user directly from poll_until instead.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@adrisala
adrisala force-pushed the fix/awxkit-user-create-race-condition branch from f332cce to 86d4e89 Compare September 16, 2026 13:53
@sonarqubecloud

Copy link
Copy Markdown

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