Skip to content

fix: harden the connector token pool and run cap for one-entry platforms - #5455

Open
mbani01 wants to merge 5 commits into
mainfrom
fix/issue-1156-connector-run-hardening
Open

mbani01 wants to merge 5 commits into
mainfrom
fix/issue-1156-connector-run-hardening

Conversation

@mbani01

@mbani01 mbani01 commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

What this fixes

Three weaknesses in the shared connectors framework. They start to matter when a connector runs with a one-entry token pool and maxConcurrentRuns: 1, which the Sessionize connector will do. No connector behaviour changes in the normal case.

1. A temporary sign-in failure no longer looks like a broken credential

When a pool entry has no cached token and minting one fails for a temporary reason (provider.unavailable or provider.rate_limit), acquire used to end with ProviderAuthError('token pool empty'). That class dead-letters a unit after 5 failed runs, so a provider login outage of about 15 minutes stopped healthy units until someone restarted them.

Now such a failure gives a retry time: the provider's own resume time, and never less than 5 minutes after the failed mint. acquire throws a RateLimitError with that time, so the unit is parked and runs again by itself. The HTTP client does not retry this error, so a failed mint is tried once per run.

  • This path is used only where the pool would have reported "token pool empty". When a parked or budget-exhausted entry already gives a wait time, that time decides, as before.
  • A rejected credential (provider.auth, provider.contract) still quarantines the entry, as before. Any other error class keeps the old outcome.
  • The error has its own message, token pool has no usable token, waiting to retry a failed mint, and does not carry the mint error.

2. A paused run counts as a live run

For a platform with a run cap, the dispatcher asks Temporal whether a lease-lapsed unit still has a run. Only the status RUNNING counted. A workflow that an operator paused was treated as having no run, so a second run could start for the same unit. PAUSED now counts as live.

3. Releasing an orphaned unit cannot overwrite what a finished run recorded

A long run could end in the few seconds between the dispatcher's claim and its deferral write. The deferral then replaced the next run time the run had just saved, which cost one extra run. rescheduleUnit now updates the unit only while it is still locked ("lockedAt" IS NOT NULL). Every end-of-run write clears the lock, so a unit whose run has ended is left alone. The lookup is by primary key; no index or schema change.

Effect on existing connectors

  • GitHub: if one installation token fails to mint for a temporary reason, the next entry is used, as before. Only when no entry is usable and none gives a wait time does a unit now wait 5 minutes and retry, where it used to count an auth failure.
  • Credly: a rate-limited token request now parks the unit for at least 5 minutes.

Known limits, not fixed here

  • A mint failure that is classed temporary but never recovers (for example after a provider changes its login page) now parks the unit again and again and no longer dead-letters. It shows as a parked unit with the message above.
  • The retry time is not stored on the pool entry, so other runs of the same platform try the mint again before it.
  • rescheduleUnit returns nothing, so a caller can log a deferral that the new guard skipped.
  • Older and not touched: the GitHub minter classes a rate-limited token request (429 or a rate-limit 403) as a contract error, which quarantines that installation entry for good. This needs its own change.
  • Older and not touched: a lease-lapsed unit whose run ended after the claim can still be started again at once when it is admitted, not deferred.

Tests

New tokenPool.test.ts (the pool had no tests): a table of pool states, plus one test with the real HTTP client that proves a failed mint is called once per request. dispatcherActivities.test.ts covers PAUSED. syncUnits.test.ts has a database test for the guarded deferral. 1,019 connector and worker tests and 62 data-access connector tests pass.

Notes for review

  • services/libs/data-access-layer/src/connectors/syncUnits.ts needs a code owner.
  • rescheduleUnit has one comment line for the lock invariant, under the "non-obvious invariant" rule in AGENTS.md.

Refs linuxfoundation/lfx-cdp-insights-ops#1156

…first

The retry time counts from the failed mint and is never shorter than the delay.
A parked or budget-exhausted entry still decides the wait, as before this change.

Refs linuxfoundation/lfx-cdp-insights-ops#1156

Signed-off-by: Mouad BANI <mouad-mb@outlook.com>
@mbani01
mbani01 requested review from a team and lfx-one as code owners November 26, 2026 17:07
Copilot AI balanced review requested due to automatic review settings November 26, 2026 17:07
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@cursor

cursor Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

PR Summary

Medium Risk
Touches connector dispatch concurrency, token acquisition error semantics, and sync-unit scheduling races—important for sync reliability but behavior-preserving in the common path except for transient mint and edge deferral cases.

Overview
Transient token mint failures no longer surface as ProviderAuthError('token pool empty'). When minting fails with provider.unavailable or provider.rate_limit, acquire aggregates the earliest retry time (provider resumeAt or at least 5 minutes) and throws a dedicated RateLimitError, so units park instead of marching toward dead-letter. Auth/contract failures still quarantine; multi-entry pools still fail over to the next entry.

Run-cap admission treats Temporal workflows in PAUSED the same as RUNNING when deciding whether a lease-lapsed unit still has a live run, blocking a second concurrent run on capped platforms (e.g. Sessionize).

Orphan deferral is guarded: rescheduleUnit updates nextRunAt and clears the lock only while lockedAt is still set, so a deferral after claim cannot overwrite nextRunAt (and watermark) already written by a run that finished between claim and defer.

New tokenPool.test.ts covers acquire/mint-retry behavior; existing dispatcher and DAL tests cover PAUSED live detection and the reschedule guard.

Reviewed by Cursor Bugbot for commit 320e0f6. Bugbot is set up for automated code reviews on this repo. Configure here.

@lfx-one

lfx-one commented Nov 26, 2026 •

Copy link
Copy Markdown

@mbani01 I'm starting review 1 of this pull request now (started 2026-11-26 17:07 UTC using review agent v0.1.34). This usually takes a few minutes. I'll update this comment with the summary when I'm done. If there's no summary here after about 45 minutes, the review stopped: push a new commit, or post a comment that begins with a mention of me followed by re-review, to start another. For help with the review agent, see https://github.com/linuxfoundation/lfx-review-agent/issues.


Hi @mbani01, thanks for the clear write-up and the thorough tests.

Summary

This pull request makes a transient token-mint failure park the unit with a retry time instead of counting as an auth failure. It also treats a paused sync workflow as a live run and stops a late deferral from overwriting a finished run's schedule. The change is small and well tested.

Decision

✅ Approved

Details

Overall impression: The three changes are scoped tightly to the connectors framework and follow the repo's conventions. ensureUsableToken now returns a resolution carrying an optional retry time. acquire uses the parked or budget wait first, then the mint retry time, then the old empty-pool error. The AND "lockedAt" IS NOT NULL guard in rescheduleUnit is by primary key, and the new database test covers both a finished run and an unfinished one. The PAUSED status is covered by the extended dispatcher test. The only comment added is one line for a non-obvious invariant, which AGENTS.md allows.

Other reviewers and CI checks: Cursor Bugbot and Greptile found no issues. The required DCO check passed on 320e0f6.

Documentation reminder: changed token pool acquire after a transient mint failure, paused sync run workflow. Please check product pages and external docs; the author and maintainers own those updates.

Rule files: read AGENTS.md; skipped none

Questions, problems, or feedback: https://github.com/linuxfoundation/lfx-review-agent/issues

@greptile-apps

greptile-apps Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Confidence Score: 5/5 · The PR appears safe to merge; no actionable issues were found.RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no actionable issues were found.

Summary

This PR hardens token acquisition and capped connector runs.

  • Temporary token-mint failures now give the unit a retry time.
  • Paused workflows now count as live when the dispatcher checks run caps.
  • Deferrals leave a finished run's recorded schedule untouched.

Acknowledged limits from mbani01: permanently temporary mint failures keep parking; mint retry times are not shared across runs; skipped deferrals can still be logged; GitHub’s existing mint-rate-limit classification remains unchanged; and an admitted unit can still restart after its previous run finishes during dispatch. These are explicitly deferred, not new findings.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Acquire token] --> B{Usable entry?}
  B -->|Yes| C[Return token]
  B -->|No| D{Parked or budget wait?}
  D -->|Yes| E[Return existing wait time]
  D -->|No| F{Temporary mint failure?}
  F -->|Yes| G[Return mint retry time]
  F -->|No| H[Report empty pool]
  G --> I[Worker parks unit]
Loading

Reviews (1) · Last reviewed commit: "fix: wait at least the mint retry delay ..." · Reviewed by Greptile

@lfx-one lfx-one 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.

No blocking, security or privacy findings. The token pool, run cap and guarded deferral changes read correctly and the new tests cover each path.

Documentation

This pull request changes behavior that may also be described outside this repository, such as product pages or an external docs site. I can't read those, so please check them; the author and maintainers own those updates. Changed here:

  • token pool acquire after a transient mint failure (now throws a rate-limit error with a retry time instead of a token pool empty auth error)
  • paused sync run workflow (now counts as a live run for run caps)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues block the connector retry and concurrency changes.

No open issues 🎉

What changed in this PR

Hardens the shared connector framework for single-token platforms with a one-run limit, ahead of Sessionize’s planned use of this configuration.

Changes:

  • Parks transient token-mint failures with a retry deadline instead of treating them as authentication failures.
  • Counts paused workflows as live runs when enforcing concurrency limits.
  • Preserves deadlines recorded by completed runs during dispatcher deferral, with regression tests for all three changes.
File Description
services/​libs/​data-access-layer/​src/​connectors/​syncUnits.ts Restricts rescheduling to units that remain locked.
services/​libs/​data-access-layer/​src/​connectors/​syncUnits.test.ts Tests deferral before and after a run completes.
services/​libs/​connectors/​src/​pool/​tokenPool.ts Adds retry deadlines for transient mint failures while preserving existing wait-time precedence.
services/​libs/​connectors/​src/​pool/​tokenPool.test.ts Covers pool failure states, fallback entries, and HTTP retry boundaries.
services/​apps/​connectors_worker/​src/​activities/​dispatcherActivities.ts Treats PAUSED workflows as live for run-cap accounting.
services/​apps/​connectors_worker/​src/​activities/​dispatcherActivities.test.ts Extends live-run admission coverage to paused workflows.

Review effort: Balanced

@mbani01 mbani01 self-assigned this Nov 26, 2026
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.

4 participants