Revision: 1 Last modified: 2026-12-04T19:00:00Z
select_sample.py builds the DEC-03 stratified baseline sample: the set of workable items that a
baseline measurement will be taken over.
Concretely it selects items with a closure event (Fixed / Implemented / Completed) inside a
[--as-of - --window-days, --as-of] window, stratifies by type (Bug / Task / Feature), and
adds every item reopened in the window.
Two properties are deliberate and are why this is its own tool rather than a query someone writes by hand:
- It reads the live
docs/workable_items.dband is read-only on it (C-006). It writes only--out(and--md). - It does no git operations at all. Unlike
cycle_report.py, it never touchesgit log— an item being in the sample is a tracker fact, not a history fact.
It also refuses to let its own instrument lie: a control needle must be found and a fabricated id must not be found, so an empty or mis-queried result cannot pass as a real (empty) sample.
This is an OPEN-GAP tool: contracts/common-conventions.md's own "Tool map" note lists
$FC/cycle/select_sample.py (T-A10) among the tools "no contract in this directory covers", so its
interface and RED fixtures are the source of truth.
python3(stdlib only).- The tracker DB, default
<repo_root>/docs/workable_items.db. Read-only. lib/fc_common.pybeside it. If it cannot be loaded the run is BLIND (4), not quietly partial.- No environment variables are read. No git required.
# the standard 90-day stratified sample
python3 scripts/fastcycle/cycle/select_sample.py \
--as-of 2026-12-04 --window-days 90 --min-per-type 5 \
--out sample.json
# also emit a human-readable summary
python3 scripts/fastcycle/cycle/select_sample.py \
--as-of 2026-12-04 --window-days 30 --min-per-type 5 \
--out sample.json --md sample.md
# prove the selection is reproducible
python3 scripts/fastcycle/cycle/select_sample.py \
--as-of 2026-12-04 --window-days 90 --out sample.json --determinism-check
# override the control needle
python3 scripts/fastcycle/cycle/select_sample.py \
--as-of 2026-12-04 --window-days 90 --out sample.json \
--needle-present-id ATM-953 --needle-fabricated-id ATM-99999-NEGATIVE-CONTROL| Flag | Required | Default | Meaning |
|---|---|---|---|
--as-of |
yes | — | Window end date. |
--window-days |
yes | — | Window length. |
--out |
yes | — | Selection document destination. |
--min-per-type |
no | 5 |
Minimum sample per type. |
--bulk-threshold |
no | 10 |
Threshold above which a closure is treated as a bulk import. |
--db-path |
no | <repo_root>/docs/workable_items.db |
Tracker DB. |
--repo-root |
no | auto-detected | Repository root. |
--md |
no | — | Also emit a Markdown summary. |
--determinism-check |
no | off | Run twice and require identical output (C-003). |
--needle-present-id / --needle-fixed-event / --needle-fixed-on-date / --needle-fabricated-id |
no | CT-009 defaults (ATM-953 Fixed 2026-07-28; ATM-99999-NEGATIVE-CONTROL) |
Control needle override. |
The C-001 five-code table, applied uniformly (the same mapping cycle_report.py documents for this tool
family):
| Code | Meaning |
|---|---|
0 |
Selection written — including the C-001-consistent NO_DATA_IN_WINDOW state. |
1 |
Reserved for a --determinism-check mismatch (C-003). |
2 |
Usage/config error. |
3 |
The control needle failed (C-004). |
4 |
BLIND — the tracker DB is unreadable, lib/fc_common.py cannot be loaded (V3-4), or a --determinism-check run timed out. |
Note the asymmetry with most other fastcycle tools: here 1 is not a general finding. It means
specifically "the same input produced two different selections", which is a reproducibility failure
rather than a data finding.
- An empty window. Reported as the
NO_DATA_IN_WINDOWstate with exit0— an honestly empty window is not an error and must not be confused with a broken query. - A control needle that is absent. Exit
3. The needle exists so that a genuine empty result and a broken instrument cannot look the same (§11.4.201(6), §11.4.273). - A needle default that postdates
--as-of. The default needle is derived at the as-of date so the control stays meaningful for historical windows. - Bulk-import / retroactive rows. Flagged
excluded_from_duration— listed in the sample but excluded from duration statistics (DEC-03: such rows are "listed… but excluded from duration statistics"). - A DB newer than expected. Read-only access means a schema surprise is a read failure (
4), never a write. --determinism-checktimeout.4, never a pass.
- Loads
lib/fc_common.py; failure is BLIND (4). - Opens the tracker DB read-only.
- Selects items with a closure event in the window, stratified by type with
--min-per-typeas the floor, plus every item reopened in the window. - Flags bulk-import rows
excluded_from_duration(threshold--bulk-threshold). - Runs the control needle: the present id must be found, the fabricated one must not be (
3if not). - With
--determinism-check: re-runs itself into a scratch output and compares documents; a mismatch is1, a timeout is4. - Writes
--out(and--md) and exits0.
Called by scripts/fastcycle/cycle/collect_baseline.py (the T045 orchestrator) and
scripts/fastcycle/cycle/cycle_report.py (when sampling is required).
Calls scripts/fastcycle/lib/fc_common.py only — no git, no subprocess to other fastcycle tools in
the ordinary path.
Guarded by scripts/fastcycle/tests/test_baseline_replay_red.sh (T024).
Contracts: specs/004-fast-dev-cycles/contracts/common-conventions.md (C-001..C-007); research.md
DEC-03, DEC-36; plan.md T-A10.
See also docs/scripts/collect_baseline.py.md, docs/scripts/baseline_replay.sh.md (the consumer of the
--sample document) and docs/scripts/cycle_report.py.md.
2026-12-04 — python3 -c "import ast;ast.parse(open('scripts/fastcycle/cycle/select_sample.py').read())"
→ exit 0. python3 scripts/fastcycle/cycle/select_sample.py with no arguments exits 2 with a usage
message (--as-of, --window-days and --out are required).