---
title: Partition Shipped Consumers By Market Format Class
type: task
status: completed
description: >-
  Four call sites in trade-review and roster-asset-lineage read KeepTradeCut values with
  is_superflex hardcoded to true, producing correct output for our superflex league and silently
  wrong output for any single-QB league. Derives the class from the league format and threads it as
  a parameter, implementing the partition-key-never-a-branch decision in code that already shipped.
base_uri: user:task/league/partition-shipped-consumers-by-market-format-class.md
created_at: '2026-08-03T22:49:40.889Z'
entity_id: f33c1209-4037-4e9b-b058-cb0099019b2b
finished_at: '2026-08-04T21:13:24.498Z'
observations:
  - ████████████████████████████████████████████████
  - ████████████████████████████████████████████████
  - ████████████████████████████████████████████████
  - ████████████████████████████████████████████████
  - ████████████████████████████████████████████████
  - ████████████████████████████████████████████████
  - ████████████████████████████████████████████████
  - ████████████████████████████████████████████████
owner_identity_uri: █████████████████████████
priority: Medium
public_read: true
relations:
  - relates [[████████████████████████-███████-█████-████████████]]
  - relates [[███████████████████████-█████-█████████-████████]]
started_at: '2026-08-04T20:33:11.408Z'
tags:
  - user:tag/league-xo-football.md
updated_at: '2026-10-26T05:00:32.281Z'
visibility_analyzed_at: '2026-11-05T23:49:47.373Z'
---

# Partition Shipped Consumers By Market Format Class

## Overview

Four call sites in recently-shipped code read KeepTradeCut values with `is_superflex` hardcoded to `true`. They
produce correct output for our own league and silently wrong output for any single-QB league, with no error.

[[████████████████████████-███████-█████-████████████]] decided 2026-07-30 that market format class is **a partition
key, never a branch**, and committed to shipping both classes. That decision is already violated by code that
shipped within the week, in files the rebuild never opens — which is why this is its own entity rather than part of
the cutover.

## Background

| site | call |
| --- | --- |
| `libs-server/trade-review/grade-trades.mjs:110` | `.where('is_superflex', true)` |
| `libs-server/trade-review/grade-trades.mjs:285` | `load_pick_ktc_indexes({ is_superflex: true })` |
| `libs-server/roster-asset-lineage/compute-snapshots-bulk.mjs:93` | `.where('is_superflex', true)` |
| `libs-server/roster-asset-lineage/compute-snapshots-bulk.mjs:239` | `load_pick_ktc_indexes({ is_superflex: true })` |

Neither module takes the class as a parameter and neither derives it from the league it is processing.
`roster_asset_holding` carries `league_format_id` but no format-class column, so a consumer holding a snapshot row
cannot recover which class valued it.

`load_pick_ktc_indexes` already takes `is_superflex` as a named parameter, so the seam exists at the bottom of the
stack. What is missing is the derivation at the top and the plumbing between.

**Latent today, not broken.** League 1 is superflex, so every current output is correct. The defect fires the first
time either module runs for a single-QB league, which the rebuild commits to supporting.

### The axis has five spellings, and this task should not add a sixth

`format_category` (smallint 1-6, written by the `trg_cmv_classify_league_format` trigger on `league_formats`),
`ktc_qb_axis`, `is_superflex`, the data-view `qb` param, and `sqb`/`sqbrbwrte`. The rebuild pins
`market_format_class` as a text closed set for its own new tables.

This task uses **`is_superflex`**, the boolean these sources already carry, and derives it from
`league_formats.sqb` / `sqbrbwrte`. It does not introduce `market_format_class` into shipped consumers — that
spelling belongs to the rebuild's new tables, and coining it here would put a sixth spelling into a sixth place
before the fifth is retired.

## Design

Derive the class once per run, at each module's entry point, from the league format being processed. Thread it as a
named parameter to the two KTC read helpers. No branch, no default, no fallback to superflex — a caller that cannot
supply a class is a caller with no league, and that should throw rather than guess.

The derivation belongs in one shared helper rather than open-coded twice, for the same reason the discretionary-cap
expression is being collapsed to one home: two derivations of one fact drift.

**Do not add a format-class column to `roster_asset_holding` in this task.** The class is recoverable from
`league_format_id`, which the table already carries, so a stored copy would be a denormalization with no reader. If
the rebuild's snapshot consumers later need it without a join, that is their call to make with a reader in hand.

### Knowledge Base Impact

- `text/league/player-valuation-system.md` — § "Asset-lineage attribution" and § "Trade grading" both
  describe these modules and neither states that the values are superflex-only. That omission is what let the
  hardcode read as complete
- No guideline change. The partition-key rule is already stated on
  [[████████████████████████-███████-█████-████████████]]; this task implements it rather than establishing it

### Working tier

None needed.

### Orchestrator shape

Single task entity. Four call sites and one helper.

## Plan

- [ ] **Derive market format class from the league format, in one shared helper**
  - Purpose: two open-coded derivations drift; one is the end state
  - Reads `league_formats`, returns the boolean the KTC tables key on. Throws rather than defaulting when the
    format cannot be resolved
  - Verify: a single-QB format resolves false and a superflex format true, asserted by query against live formats
    rather than by fixture alone

- [ ] **Thread the class through `libs-server/trade-review/grade-trades.mjs`**
  - Both sites: the player-valuation read at line 110 and `load_pick_ktc_indexes` at line 285
  - Coordinate before starting — a `█████████████████████████████` session recently shipped this module's consumer
    surface. Check `base thread list --running` and message the owner if live
  - Verify: grading league 1 produces byte-identical output to today, since league 1 is superflex; and grading a
    single-QB format selects `is_superflex = false` rows, asserted by count

- [ ] **Thread the class through `libs-server/roster-asset-lineage/compute-snapshots-bulk.mjs`**
  - Both sites: the KTC index build at line 93 and `load_pick_ktc_indexes` at line 239
  - Verify: recomputing snapshots for league 1 leaves every `keeptradecut_value_at_acquisition` and
    `_at_termination` unchanged, to the cent

- [ ] **Assert no hardcode survives**
  - Verify: grep for `is_superflex: true` and `'is_superflex', true` across `libs-server/` returns zero hits
    outside test fixtures. Validate the pattern against a known occurrence BEFORE trusting its zero — a negative
    grep that cannot match reads exactly like a clean result

- [ ] **Update `text/league/player-valuation-system.md`**
  - Verify: both sections state which format class the values they describe are drawn from
