Skip to content

perf(self_hosted_hub): look up agent quota before taking the register lock - #1386

Open
loadez wants to merge 2 commits into
mainfrom
ws/hub-register-lock
Open

loadez wants to merge 2 commits into
mainfrom
ws/hub-register-lock

Conversation

@loadez

@loadez loadez commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

Agent registration takes a per-organization advisory lock so the agent count and the insert stay atomic against the quota. The quota lookup (a cache hit most of the time, a remote call on a miss) ran inside that lock, so a miss stalled every registration for the organization. It now runs before the lock; only the count and the insert stay inside it.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-03T19:26:31.731274Z d2f3096 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d2f3096e05

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

agentToken = t
return nil
})
orgQuota, err := s.findQuotaForNewAgent(r.Context(), agentType.OrganizationID.String())

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Coalesce quota loads before bypassing the registration lock

When an organization's five-minute quota cache entry is cold or expired and many agents register concurrently, every request now reaches this lookup before acquiring the advisory lock. getQuotaWithTTL performs an unsynchronized cache miss followed by loadQuota, while FeatureHubProvider opens a new gRPC connection for each load, so a registration burst can fan out into one Feature Hub request per agent and reject valid registrations if the resulting calls overload or fail. Add per-organization request coalescing to the quota client, or retain serialization specifically for cache misses.

Useful? React with 👍 / 👎.

@loadez
loadez force-pushed the ws/hub-register-lock branch from d2f3096 to 29f8276 Compare November 6, 2026 10:45
… lock

Agent registration took the organization-wide advisory lock and then
fetched the organization quota while holding it. On a quota cache miss
that is a call to the feature service, and every other registration for
the organization queues behind it.

Fetch the quota (and reject when the feature is not available) before
taking the lock. The lock now only covers counting the registered agents
and inserting the new one, so the quota check stays atomic.

Error responses are unchanged.
…onnection pool

The test environment defaults to a pool of one connection, which serializes
the goroutines, so the test passed even with the register lock removed.
Widen the pool for that test and restore it afterwards.
@loadez
loadez force-pushed the ws/hub-register-lock branch from 29f8276 to 36a8528 Compare November 10, 2026 11:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

2 participants