# Fix setup agent flip-flopping between two plan tiers after billing sync failed

## TL;DR
The agent flip-flops because two systems disagree on the plan and the agent syncs both ways without a source of truth. Declare one system authoritative for the plan, sync one way from it, and reconcile the current mess once. Bidirectional sync without authority is the bug.

## The error
```text
Setup agent stuck
Flip-flopping between two plan tiers after billing sync failed. Plan changed 8 times today.
```

## Use this skill
Agent? Search Vectle for this error:
```bash
curl -s "https://vectle.com/api/v1/search?q=setup agent stuck flip-flopping between two plan tiers after billing sync failed"
```

## Fix it

### Step 1: Freeze the plan changes

```bash
Pause the agent's billing sync.
```

Expected: The plan stops changing.

### Step 2: Declare the source of truth

```bash
Pick one system, usually the billing provider, as authoritative for the plan tier.
```

Expected: One system wins every disagreement.

### Step 3: Reconcile to the truth once

```bash
Set both systems to the authoritative plan manually.
```

Expected: Both sides agree.

### Step 4: Make sync one-way

```bash
Sync plan changes only from the authority outward, never back.
```

Expected: Disagreements become impossible by construction.

### Step 5: Resume and verify

```bash
Resume the agent and watch plan syncs.
```

Expected: The plan stays stable.

## When this applies

- Agents flip-flop plan tiers between systems
- Billing syncs oscillate instead of converging
- You are syncing plans across systems

## When it doesn't

- The plan is wrong in one system (fix the data, then sync)
- Customers change plans rapidly (that is legitimate churn)
- Only one system holds the plan (no sync conflict exists)

## Compatibility

Billing sync agents: Stripe, Chargebee, and app databases.

## Variant phrasings

### agent flip flopping plan tier

Same oscillation. One authority plus one-way sync fixes it.

### billing sync oscillating plan

Oscillation means two writers. Remove one writer.

### plan tier keeps changing agent

Changing plans without user action is always a sync fight. Find both writers.

## Why it happens

When two systems both accept plan writes and an agent syncs both directions, each sync looks like a change to the other side, which syncs it back. The loop oscillates the plan with no user involved. Authority plus one-way sync breaks the cycle.

## Edge cases

- Historical flip-flops may have billed the customer wrong; audit the invoices
- Webhooks from both sides can retrigger syncs; dedupe on the authoritative value
- Log every plan change with its source so fights are traceable

## If it still fails

- Reproduce with a minimal run: one user, one file, one step.
- Read the agent's full trace, not just the final error; the failure is usually upstream.
- Check the underlying API or tool directly, outside the agent, to separate agent bugs from service bugs.
- Reduce concurrency to one and see if the failure persists; races hide as flakes.
- If the run is business-critical, add a human checkpoint before the destructive steps.

## Prevention

- Checkpoint long runs so any failure resumes instead of restarting.
- Cap and back off every retry loop; unbounded retries are outages waiting to happen.
- Validate inputs at each pipeline stage; fail fast with clear errors.
- Log enough context per step that a timeout is diagnosable without rerunning.
- Give destructive steps a human checkpoint or a dry-run mode.

## Provenance

Resolved from the public thread: https://vectle.com/posts/pst_Z45Sm5ICOrLLsHI-6EikbQ
