Skip to content

fix(enrich): stop the contact batch at the first quota 429 - #295

Open
posthog-eu[bot] wants to merge 3 commits into
mainfrom
posthog-self-driving/fixmcp-investigate-contact-enrichment-f1a6fc
Open

posthog-eu[bot] wants to merge 3 commits into
mainfrom
posthog-self-driving/fixmcp-investigate-contact-enrichment-f1a6fc

Conversation

@posthog-eu

@posthog-eu posthog-eu Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Problem

  • A user who asks the assistant to enrich a list of contacts gets a run of failed calls after the account quota runs out. Each failed call is a paid action that the user sees fail.
  • The enrichment quota is per account, not per contact. After the first 429, every other leadbay_enrich_contacts call fails the same way until the window resets.
  • The generic QUOTA_EXCEEDED hint says only "wait, then retry". It does not say that the quota is shared. So the agent moved on to the next contact, about one call per second, until the list ended.
  • Telemetry for the spike shows one batch. The first enrich call already got 429. The calls that followed were all different contacts, all 429, and none had retry_after. The client did not retry. Each failure was a new call from the agent.

Origin

  • Scout: signals-scout-general
  • First signal: 2026-10-21
  • Inbox report: open
  • Task started by: auto-start, after the report was rated P2 and ready to fix

Changes

  • Stop-the-batch hint on a quota 429. leadbay_enrich_contacts puts an enrich-specific sentence in front of the generic hint when either enrich path (paid or org fallback) returns QUOTA_EXCEEDED. The sentence tells the agent that the quota is shared, to stop the batch, not to retry in a loop, and to tell the user which contacts are done and which remain.
  • The error code, the generic hint (with its {{commerce}} split), and _meta (http_status, retry_after) do not change. Telemetry still records the terminal reason as QUOTA_EXCEEDED / 429.
  • Description: the QUOTA section of enrich-contacts.md.tmpl now says "One 429 ends the whole batch", so the agent knows before the first 429. The description is about 6.3k chars, far under the 17k cap.
  • New test file enrich-contacts-quota-stops-batch.test.ts covers the paid path, the org fallback path, and a non-quota error.
Question from the report Answer
Does the client retry a quota response? No. Only 401s on reads are retried.
Is the quota shared across contacts? Yes, per account. The new hint says so.
Is there a clear retry-after / limit message? retry_after is passed through when the backend sends it. It was absent in this spike, so the hint points to leadbay_account_status for the window.

Note

This is guidance to the agent, not a server-side block. The hosted server is stateless per request, so it cannot remember a 429 across calls without new shared state. If the pattern comes back, a per-token short-circuit is the next step.

Checks

  • pnpm build, pnpm -r typecheck, pnpm test (components, core, promptforge, mcp): all pass.
  • No version bump or CHANGELOG entry. Those come with the next release bump.

Agent context

  • Not done: a client-side quota pre-check. The repo removed that deliberately (product#3865), because ai_credits counts credits consumed, not credits remaining.

Created with PostHog Desktop from this inbox report.

🤖 Generated with Claude Code

The enrichment quota is per account, not per contact. After a 429, the
generic QUOTA_EXCEEDED hint only said "wait, then retry", so an agent that
enriched a list moved on to the next contact and each call failed the same
way.

leadbay_enrich_contacts now puts a stop-the-batch hint in front of the
generic hint on a 429 from either enrich path. The code, the generic hint
and the 429 metadata stay the same. The tool description also says that one
429 ends the whole batch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Generated-By: PostHog Desktop
Task-Id: 24c048cd-ccb9-4d68-bd91-ffacb0b7bb7d
@posthog-eu
posthog-eu Bot requested a review from milstan October 21, 2026 03:33
Remove the nested try, the test-only export and the duplicate assertions.
The behavior does not change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Generated-By: PostHog Desktop
Task-Id: 24c048cd-ccb9-4d68-bd91-ffacb0b7bb7d
@posthog-eu
posthog-eu Bot marked this pull request as ready for review October 21, 2026 03:48
@posthog-eu

posthog-eu Bot commented Oct 21, 2026

Copy link
Copy Markdown
Author

The Claude Code Review/claude-review failure does not come from this diff. The action stops before the review starts, because a bot account opened this PR, and bots are not on the action's allowed_bots list. The fix is in .github/workflows/claude-code-review.yml, which this PR must not change. A maintainer can re-run the review by hand, or allow the bot in that workflow. All the other checks pass (build-and-test, contracts, isolation, gate, release-pr).

…fixmcp-investigate-contact-enrichment-f1a6fc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants