---
title: Iterate Sleeper transactions across all weeks in fetch_league_data
type: task
status: completed
description: >-
  fetch_league_data passes options.week through unchanged; without --week the per-week Sleeper
  endpoint returns 0 transactions instead of the full-season 735. Orchestrator should iterate weeks
  1..18 by default; --week becomes optional scoping.
base_uri: user:task/league/sleeper-multi-week-transaction-iteration.md
created_at: '2026-05-08T01:19:38.208Z'
entity_id: 7eb04d5e-63a9-4358-92d3-0d61c3f79331
finished_at: '2026-05-09T03:55:26.242Z'
observations:
  - ████████████████████████████████████████████████
  - ████████████████████████████████████████████████
owner_identity_uri: █████████████████████████
priority: Medium
public_read: true
relations:
  - follows [[user:task/github/mistakia/league/162-import-and-sync-external-leagues.md]]
  - relates [[████████████████████-███████-███████████-██████-███-████-████████████]]
tags:
  - user:tag/league-xo-football.md
updated_at: '2026-06-08T17:42:51.461Z'
visibility_analyzed_at: '2026-11-05T23:50:28.125Z'
---

## Context

Identified during post-merge validation of mistakia/league#162. The Sleeper transactions endpoint is per-week (`/league/{id}/transactions/{week}`), but `SyncOrchestrator.fetch_league_data` passes `options: { week: fetch_options.week }` through unchanged. Without `--week`, `fetch_options.week` is undefined, the adapter substitutes `current_season.week`, and live verification confirmed: `transactions: 0`.

Live week-by-week probe against fixture league `1182953443152855040` for 2025:

```
week=0..18: 0, 390, 22, 29, 33, 39, 18, 15, 24, 17, 12, 19, 19, 4, 27, 33, 19, 15, 0
total: 735 transactions
```

A user calling "fetch transactions" without specifying a week reasonably expects "all transactions"; getting zero is a silent footgun.

## Recommendation

Make the orchestrator iterate `week=1..18` and concatenate results when `fetch_options.week` is undefined. Treat `--week` as optional scoping. This matches the dominant sync use case (full-season import) while preserving the fast per-week path for incremental syncs.

Apply at the orchestrator layer (not the adapter) so the per-week endpoint stays a thin one-to-one mapping of the platform's API. The orchestrator already knows whether `week` was specified.

## Scope

**File**: `libs-server/external-fantasy-leagues/sync/sync-orchestrator.mjs`

`fetch_league_data` block ~lines 174-195 currently does:

```
adapter.get_transactions({
  league_id: external_league_id,
  options: { week: fetch_options.week },
  year: fetch_options.year
})
```

When `fetch_options.week` is undefined and `include_transactions !== false`:

- Loop weeks 1..18 (or pull from `current_season` constants if a max-week constant exists), call adapter per week
- Concatenate results
- Optional optimization: parallelize with bounded concurrency (e.g., 4-8 simultaneous fetches) to avoid serialized 18× latency

Same treatment in `sync_league` if it relies on `fetch_options.week` for the transaction step. (The current implementation routes through `transaction_sync.sync_transactions` — verify that path has the same gap.)

## Acceptance Criteria

- Calling `node scripts/sync-external-league.mjs --platform=sleeper --external-league-id=1182953443152855040 --internal-league-id=1 --dry-run` (or full mode) without `--week` retrieves all 735 transactions for the 2025 season.
- Specifying `--week N` retrieves only that week (existing behavior).
- Transaction count documented in `sleeper-sync-results.json` expected output reflects multi-week reality (regenerate via `scripts/update-fixtures.mjs --skip-collect` if fixture-loading paths change).
- Test added/updated in `test/external-fantasy-leagues-sync-orchestrator.spec.mjs` or `test/external-fantasy-leagues-sleeper-integration.spec.mjs` verifying that `fetch_league_data` without a week iterates and concatenates. Use the existing fixture (week=1, 296 transactions) — mock `api_client.get` to return the same fixture for all weeks and assert the orchestrator called it 18 times.
- Concurrency bound: max N simultaneous in-flight requests (configurable; default 4 or 8). Document the choice with a brief comment if it deviates from existing patterns.
- Suite: `yarn test --reporter min test/external-fantasy-leagues-*.spec.mjs` stays green.
- ESLint clean.

## Interaction With Other Tasks

- This task delivers full-season transaction visibility. Without [[████████████████████-███████-███████████-██████-███-████-████████████]], the mapper still drops every transaction, so end-to-end sync remains zero. Both tasks together unblock real Sleeper transaction sync.
- Either task can land first; recommend the mapper fix first since fewer fixture regenerations are needed.

## Out of Scope

- Year-spanning iteration (multiple seasons). Single-season scope.
- Per-platform max-week handling for non-Sleeper platforms. Other adapters may have different transaction endpoint shapes — handle each on its own merits when fixtures land.
- Caching / incremental-sync intelligence (only fetch weeks since last sync). Future optimization.
