cctally 1.115.0 → 1.116.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/bin/_cctally_cache.py +85 -4
  3. package/bin/_cctally_completion.py +80 -12
  4. package/bin/_cctally_core.py +106 -9
  5. package/bin/_cctally_dashboard.py +6 -9
  6. package/bin/_cctally_dashboard_envelope.py +26 -32
  7. package/bin/_cctally_db.py +85 -4
  8. package/bin/_cctally_doctor.py +38 -5
  9. package/bin/_cctally_five_hour.py +83 -1017
  10. package/bin/_cctally_journal.py +1307 -180
  11. package/bin/_cctally_journal_repair.py +9 -7
  12. package/bin/_cctally_oauth_samples.py +280 -0
  13. package/bin/_cctally_parser.py +5 -0
  14. package/bin/_cctally_quarantine.py +14 -4
  15. package/bin/_cctally_quota.py +70 -8
  16. package/bin/_cctally_quota_model.py +35 -4
  17. package/bin/_cctally_record.py +414 -123
  18. package/bin/_cctally_rederive.py +632 -235
  19. package/bin/_cctally_refresh.py +29 -0
  20. package/bin/_cctally_statusline.py +984 -47
  21. package/bin/_cctally_store.py +972 -58
  22. package/bin/_cctally_tui.py +62 -7
  23. package/bin/_cctally_update.py +25 -0
  24. package/bin/_lib_account_protocol.py +201 -18
  25. package/bin/_lib_clone_copy.py +46 -11
  26. package/bin/_lib_dashboard_sources.py +57 -15
  27. package/bin/_lib_detector_access_registry.py +273 -52
  28. package/bin/_lib_doctor.py +302 -1
  29. package/bin/_lib_journal.py +145 -25
  30. package/bin/_lib_journal_router.py +166 -48
  31. package/bin/_lib_oauth_samples.py +238 -0
  32. package/bin/_lib_pricing_check.py +0 -12
  33. package/bin/_lib_provider_activity.py +770 -0
  34. package/bin/_lib_quarantine.py +3 -2
  35. package/bin/_lib_quota_model.py +96 -6
  36. package/bin/_lib_rebuild_progress.py +146 -0
  37. package/bin/_lib_record.py +22 -0
  38. package/bin/_lib_rederive.py +299 -3
  39. package/bin/_lib_snapshot_cache.py +43 -1
  40. package/bin/_lib_stale_proof.py +708 -0
  41. package/bin/_lib_statusline_candidates.py +65 -5
  42. package/bin/_lib_worker_launches.py +315 -0
  43. package/bin/cctally +6 -11
  44. package/dashboard/static/assets/{ConversationsView-Bc8LCOAZ.js → ConversationsView-Dflb_myA.js} +1 -1
  45. package/dashboard/static/assets/DoctorModal-DFX5CfIs.js +1 -0
  46. package/dashboard/static/assets/{ModalRoot-DLPgyAM_.js → ModalRoot-HlxoagIa.js} +1 -1
  47. package/dashboard/static/assets/{ProjectsDrillPanel-z53a4v4M.js → ProjectsDrillPanel-C3PJy1xx.js} +1 -1
  48. package/dashboard/static/assets/{SourceDetailModal-Bw0T8W-W.js → SourceDetailModal-BczsWKhD.js} +1 -1
  49. package/dashboard/static/assets/{UpdateModal-D5AKx4Yw.js → UpdateModal-Os-Lo5cs.js} +1 -1
  50. package/dashboard/static/assets/{index-BXDOzSng.js → index-CYZ3NLqF.js} +3 -3
  51. package/dashboard/static/assets/{outlineNavigation-JObY7cUY.js → outlineNavigation-k-zIif6W.js} +1 -1
  52. package/dashboard/static/dashboard.html +1 -1
  53. package/package.json +7 -2
  54. package/bin/_lib_merge_gate.py +0 -452
  55. package/dashboard/static/assets/DoctorModal-D--qVBwe.js +0 -1
@@ -418,6 +418,30 @@ REGISTRY: "tuple[AccessContract, ...]" = (
418
418
  classes=('range-keyed', 'period-keyed'),
419
419
  inert_rule=None,
420
420
  ),
421
+ AccessContract(
422
+ function='_cctally_core:open_db',
423
+ sql_fingerprint='CREATE INDEX IF NOT EXISTS idx_claude_oauth_samples_five_hour ON claude_oauth_samples (account_key, five_hour_window_key, requested_at_utc)',
424
+ table='claude_oauth_samples',
425
+ keys=(),
426
+ predicate='',
427
+ ordering='',
428
+ selected=(),
429
+ effects='write',
430
+ classes=('singleton',),
431
+ inert_rule=MAINT,
432
+ ),
433
+ AccessContract(
434
+ function='_cctally_core:open_db',
435
+ sql_fingerprint='CREATE INDEX IF NOT EXISTS idx_claude_oauth_samples_weekly ON claude_oauth_samples (account_key, weekly_resets_at_utc, requested_at_utc)',
436
+ table='claude_oauth_samples',
437
+ keys=(),
438
+ predicate='',
439
+ ordering='',
440
+ selected=(),
441
+ effects='write',
442
+ classes=('singleton',),
443
+ inert_rule=MAINT,
444
+ ),
421
445
  AccessContract(
422
446
  function='_cctally_core:open_db',
423
447
  sql_fingerprint='CREATE INDEX IF NOT EXISTS idx_cost_week_start_at_time ON weekly_cost_snapshots(week_start_at, captured_at_utc DESC, id DESC)',
@@ -586,6 +610,30 @@ REGISTRY: "tuple[AccessContract, ...]" = (
586
610
  classes=('singleton',),
587
611
  inert_rule=MAINT,
588
612
  ),
613
+ AccessContract(
614
+ function='_cctally_core:open_db',
615
+ sql_fingerprint='CREATE TABLE IF NOT EXISTS claude_oauth_samples ( account_key TEXT NOT NULL, observation_id TEXT NOT NULL, requested_at_utc TEXT NOT NULL, captured_at_utc TEXT NOT NULL, weekly_percent REAL, weekly_resets_at_utc TEXT, five_hour_percent REAL, five_hour_resets_at_utc TEXT, five_hour_window_key INTEGER, PRIMARY KEY (account_key, observation_id) )',
616
+ table='claude_oauth_samples',
617
+ keys=(),
618
+ predicate='',
619
+ ordering='',
620
+ selected=(),
621
+ effects='write',
622
+ classes=('singleton',),
623
+ inert_rule=MAINT,
624
+ ),
625
+ AccessContract(
626
+ function='_cctally_core:open_db',
627
+ sql_fingerprint='CREATE TABLE IF NOT EXISTS claude_weekly_observation_decisions ( observation_id TEXT PRIMARY KEY, disposition TEXT NOT NULL, decision_op_id TEXT NOT NULL )',
628
+ table='claude_weekly_observation_decisions',
629
+ keys=(),
630
+ predicate='',
631
+ ordering='',
632
+ selected=(),
633
+ effects='write',
634
+ classes=('singleton',),
635
+ inert_rule=MAINT,
636
+ ),
589
637
  AccessContract(
590
638
  function='_cctally_core:open_db',
591
639
  sql_fingerprint="CREATE TABLE IF NOT EXISTS five_hour_block_models ( id INTEGER PRIMARY KEY AUTOINCREMENT, block_id INTEGER NOT NULL, five_hour_window_key INTEGER NOT NULL, model TEXT NOT NULL, input_tokens INTEGER NOT NULL DEFAULT 0, output_tokens INTEGER NOT NULL DEFAULT 0, cache_create_tokens INTEGER NOT NULL DEFAULT 0, cache_read_tokens INTEGER NOT NULL DEFAULT 0, cost_usd REAL NOT NULL DEFAULT 0, entry_count INTEGER NOT NULL DEFAULT 0, account_key TEXT NOT NULL DEFAULT 'unattributed', UNIQUE(account_key, five_hour_window_key, model), FOREIGN KEY (block_id) REFERENCES five_hour_blocks(id) )",
@@ -624,7 +672,7 @@ REGISTRY: "tuple[AccessContract, ...]" = (
624
672
  ),
625
673
  AccessContract(
626
674
  function='_cctally_core:open_db',
627
- sql_fingerprint='CREATE TABLE IF NOT EXISTS five_hour_credit_confirmation_state ( account_key TEXT NOT NULL, five_hour_window_key INTEGER NOT NULL, source TEXT NOT NULL, baseline_pct REAL NOT NULL, pending_low_pct REAL, pending_at_utc TEXT, pending_observation_id TEXT, PRIMARY KEY (account_key, five_hour_window_key, source) )',
675
+ sql_fingerprint='CREATE TABLE IF NOT EXISTS five_hour_credit_confirmation_state ( account_key TEXT NOT NULL, five_hour_window_key INTEGER NOT NULL, source TEXT NOT NULL, baseline_pct REAL NOT NULL, pending_low_pct REAL, pending_at_utc TEXT, pending_observation_id TEXT, baseline_observation_id TEXT, baseline_generation TEXT, pending_generation TEXT, pending_position TEXT, PRIMARY KEY (account_key, five_hour_window_key, source) )',
628
676
  table='five_hour_credit_confirmation_state',
629
677
  keys=(),
630
678
  predicate='',
@@ -1030,10 +1078,21 @@ REGISTRY: "tuple[AccessContract, ...]" = (
1030
1078
  classes=('singleton',),
1031
1079
  inert_rule=MAINT,
1032
1080
  ),
1081
+ # Reviewed re-pin (#797/#823/#840 Task 2, base 5f3db4ddd), for open_db
1082
+ # #1, #2 and #3. Changed: only the producer `open_db` itself, whose
1083
+ # epoch-1019 schema block now also creates `claude_oauth_samples`, its
1084
+ # two indexes and `claude_weekly_observation_decisions`, and creates
1085
+ # `five_hour_credit_confirmation_state` with four more NULLABLE
1086
+ # columns. Those are literal statements, registered as their own MAINT
1087
+ # contracts above. No line of these three dynamic sites, their helpers
1088
+ # or the bindings they read changed, so each site's table selection,
1089
+ # predicates, ordering, selected columns, execution condition and
1090
+ # read-only effect are unchanged and the contract and its MAINT inert
1091
+ # rule stand.
1033
1092
  AccessContract(
1034
1093
  function='_cctally_core:open_db',
1035
1094
  sql_fingerprint='dynamic:_cctally_core:open_db#1',
1036
- sql_shape='sha256:fccb556342da9ffa',
1095
+ sql_shape='sha256:447a3914f169d52f',
1037
1096
  table='dynamic',
1038
1097
  keys=(),
1039
1098
  predicate='dynamic SQL',
@@ -1046,7 +1105,7 @@ REGISTRY: "tuple[AccessContract, ...]" = (
1046
1105
  AccessContract(
1047
1106
  function='_cctally_core:open_db',
1048
1107
  sql_fingerprint='dynamic:_cctally_core:open_db#2',
1049
- sql_shape='sha256:4422797e3a6480ba',
1108
+ sql_shape='sha256:596eea4ecd91f526',
1050
1109
  table='dynamic',
1051
1110
  keys=(),
1052
1111
  predicate='dynamic SQL',
@@ -1059,7 +1118,7 @@ REGISTRY: "tuple[AccessContract, ...]" = (
1059
1118
  AccessContract(
1060
1119
  function='_cctally_core:open_db',
1061
1120
  sql_fingerprint='dynamic:_cctally_core:open_db#3',
1062
- sql_shape='sha256:63e58c7c98c1aa20',
1121
+ sql_shape='sha256:425db89e4d3c5003',
1063
1122
  table='dynamic',
1064
1123
  keys=(),
1065
1124
  predicate='dynamic SQL',
@@ -1208,18 +1267,6 @@ REGISTRY: "tuple[AccessContract, ...]" = (
1208
1267
  classes=('cross-period',),
1209
1268
  inert_rule=JOURNAL,
1210
1269
  ),
1211
- AccessContract(
1212
- function='_cctally_journal:_keep_five_hour_retirement',
1213
- sql_fingerprint='SELECT 1 FROM five_hour_reset_events WHERE account_key = ? AND five_hour_window_key = ? AND unixepoch(effective_reset_at_utc) <= unixepoch(?) LIMIT 1',
1214
- table='five_hour_reset_events',
1215
- keys=('account_key', 'five_hour_window_key'),
1216
- predicate='account_key = ? AND five_hour_window_key = ? AND unixepoch(effective_reset_at_utc) <= unixepoch(?)',
1217
- ordering='',
1218
- selected=('1',),
1219
- effects='read',
1220
- classes=('period-keyed', 'range-keyed'),
1221
- inert_rule=None,
1222
- ),
1223
1270
  AccessContract(
1224
1271
  function='_cctally_journal:_keep_five_hour_retirement',
1225
1272
  sql_fingerprint='SELECT five_hour_percent, five_hour_resets_at, five_hour_window_key, weekly_observation_held FROM weekly_usage_snapshots WHERE id = ?',
@@ -1244,29 +1291,22 @@ REGISTRY: "tuple[AccessContract, ...]" = (
1244
1291
  classes=('period-keyed',),
1245
1292
  inert_rule=JOURNAL,
1246
1293
  ),
1294
+ # #840 (spec section 4.8): the convergence keepers keep a retirement only
1295
+ # through exact effective suppression membership. The candidates are the
1296
+ # active effective decisions whose retained record names the snapshot id;
1297
+ # membership is decided on the decoded payload's exact `suppression` list,
1298
+ # so a row is matched by exact logical identity, never by a percentage band.
1247
1299
  AccessContract(
1248
- function='_cctally_journal:_keep_weekly_retirement',
1249
- sql_fingerprint='SELECT effective_reset_at_utc, observed_pre_credit_pct FROM week_reset_events WHERE account_key = ? AND new_week_end_at = ? AND observed_pre_credit_pct IS NOT NULL',
1250
- table='week_reset_events',
1251
- keys=('account_key', 'new_week_end_at'),
1252
- predicate='account_key = ? AND new_week_end_at = ? AND observed_pre_credit_pct IS NOT NULL',
1253
- ordering='',
1254
- selected=('effective_reset_at_utc', 'observed_pre_credit_pct'),
1255
- effects='read',
1256
- classes=('period-keyed',),
1257
- inert_rule=None,
1258
- ),
1259
- AccessContract(
1260
- function='_cctally_journal:_keep_weekly_retirement',
1261
- sql_fingerprint='SELECT effective_at_utc, observed_pre_credit_pct FROM weekly_credit_floors WHERE week_start_date = ? AND account_key = ? AND observed_pre_credit_pct IS NOT NULL',
1262
- table='weekly_credit_floors',
1263
- keys=('week_start_date', 'account_key'),
1264
- predicate='week_start_date = ? AND account_key = ? AND observed_pre_credit_pct IS NOT NULL',
1300
+ function='_cctally_journal:_suppression_retires',
1301
+ sql_fingerprint="SELECT event_id, event_json FROM journal_effective_events WHERE status = 'active' AND event_json LIKE ?",
1302
+ table='journal_effective_events',
1303
+ keys=(),
1304
+ predicate="status = 'active' AND event_json LIKE ?",
1265
1305
  ordering='',
1266
- selected=('effective_at_utc', 'observed_pre_credit_pct'),
1306
+ selected=('event_id', 'event_json'),
1267
1307
  effects='read',
1268
- classes=('period-keyed',),
1269
- inert_rule=None,
1308
+ classes=('cross-period',),
1309
+ inert_rule=JOURNAL,
1270
1310
  ),
1271
1311
  AccessContract(
1272
1312
  function='_cctally_journal:_converge_row_from_effective',
@@ -1280,10 +1320,21 @@ REGISTRY: "tuple[AccessContract, ...]" = (
1280
1320
  classes=('period-keyed',),
1281
1321
  inert_rule=JOURNAL,
1282
1322
  ),
1323
+ # Reviewed re-pin (#797/#823/#840 Task 6 Part B, base 79847ac5a). Changed:
1324
+ # the producer `_converge_row_from_effective` takes a `suppressors`
1325
+ # keyword and passes it, with the converged event id, to
1326
+ # `_keep_five_hour_retirement` and `_keep_weekly_retirement`, which now
1327
+ # keep a retirement only through exact effective suppression membership
1328
+ # (`_suppression_retires`, its own contract above) instead of the removed
1329
+ # credit-band and five-hour-credit reads (their three contracts are
1330
+ # removed). Both sites' target-table `SELECT id ... WHERE journal_id = ?`
1331
+ # and `UPDATE ... WHERE id = ?`, their keys, predicates, execution
1332
+ # conditions and effects are unchanged, so the contracts and their inert
1333
+ # rules stand.
1283
1334
  AccessContract(
1284
1335
  function='_cctally_journal:_converge_row_from_effective',
1285
1336
  sql_fingerprint='dynamic:_cctally_journal:_converge_row_from_effective#1',
1286
- sql_shape='sha256:87a7fa0212f80043',
1337
+ sql_shape='sha256:d325c0f9da12ebb6',
1287
1338
  table='dynamic',
1288
1339
  keys=(),
1289
1340
  predicate='dynamic SQL',
@@ -1296,7 +1347,7 @@ REGISTRY: "tuple[AccessContract, ...]" = (
1296
1347
  AccessContract(
1297
1348
  function='_cctally_journal:_converge_row_from_effective',
1298
1349
  sql_fingerprint='dynamic:_cctally_journal:_converge_row_from_effective#2',
1299
- sql_shape='sha256:b723310f1bacf1af',
1350
+ sql_shape='sha256:d92a33339d28a17e',
1300
1351
  table='dynamic',
1301
1352
  keys=(),
1302
1353
  predicate='dynamic SQL',
@@ -1356,10 +1407,17 @@ REGISTRY: "tuple[AccessContract, ...]" = (
1356
1407
  classes=('period-keyed',),
1357
1408
  inert_rule=JOURNAL,
1358
1409
  ),
1410
+ # Reviewed re-pin (#797/#823/#840 Task 6 Part B, base 79847ac5a). Changed:
1411
+ # the producer `_emit_harvest_row`'s derivation-completion branch passes
1412
+ # its retention's applied decisions (`applied_records`) to
1413
+ # `_converge_row_from_effective` as `suppressors` (#840 exact suppression
1414
+ # membership). The harvested table, keys, predicates, ordering, execution
1415
+ # conditions and effects are unchanged, so the contracts and their inert
1416
+ # rules stand.
1359
1417
  AccessContract(
1360
1418
  function='_cctally_journal:_emit_harvest_row',
1361
1419
  sql_fingerprint='dynamic:_cctally_journal:_emit_harvest_row#1',
1362
- sql_shape='sha256:36b3715496826795',
1420
+ sql_shape='sha256:aca33abe5dcc2e43',
1363
1421
  table='dynamic',
1364
1422
  keys=(),
1365
1423
  predicate='dynamic SQL',
@@ -1372,7 +1430,7 @@ REGISTRY: "tuple[AccessContract, ...]" = (
1372
1430
  AccessContract(
1373
1431
  function='_cctally_journal:_emit_harvest_row',
1374
1432
  sql_fingerprint='dynamic:_cctally_journal:_emit_harvest_row#2',
1375
- sql_shape='sha256:36b3715496826795',
1433
+ sql_shape='sha256:aca33abe5dcc2e43',
1376
1434
  table='dynamic',
1377
1435
  keys=(),
1378
1436
  predicate='dynamic SQL',
@@ -1562,7 +1620,7 @@ REGISTRY: "tuple[AccessContract, ...]" = (
1562
1620
  AccessContract(
1563
1621
  function='_cctally_journal:_publish_generation_in_place',
1564
1622
  sql_fingerprint='dynamic:_cctally_journal:_publish_generation_in_place#1',
1565
- sql_shape='sha256:c03310d569d06566',
1623
+ sql_shape='sha256:dbbfb479a47a1d9c',
1566
1624
  table='dynamic',
1567
1625
  keys=(),
1568
1626
  predicate='dynamic SQL',
@@ -1575,7 +1633,7 @@ REGISTRY: "tuple[AccessContract, ...]" = (
1575
1633
  AccessContract(
1576
1634
  function='_cctally_journal:_publish_generation_in_place',
1577
1635
  sql_fingerprint='dynamic:_cctally_journal:_publish_generation_in_place#2',
1578
- sql_shape='sha256:4c08ed64ebe47aa4',
1636
+ sql_shape='sha256:75c421b6460d6364',
1579
1637
  table='dynamic',
1580
1638
  keys=(),
1581
1639
  predicate='dynamic SQL',
@@ -1588,7 +1646,7 @@ REGISTRY: "tuple[AccessContract, ...]" = (
1588
1646
  AccessContract(
1589
1647
  function='_cctally_journal:_publish_generation_in_place',
1590
1648
  sql_fingerprint='dynamic:_cctally_journal:_publish_generation_in_place#3',
1591
- sql_shape='sha256:4c08ed64ebe47aa4',
1649
+ sql_shape='sha256:75c421b6460d6364',
1592
1650
  table='dynamic',
1593
1651
  keys=(),
1594
1652
  predicate='dynamic SQL',
@@ -1601,7 +1659,7 @@ REGISTRY: "tuple[AccessContract, ...]" = (
1601
1659
  AccessContract(
1602
1660
  function='_cctally_journal:_publish_generation_in_place',
1603
1661
  sql_fingerprint='dynamic:_cctally_journal:_publish_generation_in_place#4',
1604
- sql_shape='sha256:9fa2bbec8283329c',
1662
+ sql_shape='sha256:1ed2b4533f0fd067',
1605
1663
  table='dynamic',
1606
1664
  keys=(),
1607
1665
  predicate='dynamic SQL',
@@ -1614,7 +1672,7 @@ REGISTRY: "tuple[AccessContract, ...]" = (
1614
1672
  AccessContract(
1615
1673
  function='_cctally_journal:_publish_generation_in_place',
1616
1674
  sql_fingerprint='dynamic:_cctally_journal:_publish_generation_in_place#5',
1617
- sql_shape='sha256:4c08ed64ebe47aa4',
1675
+ sql_shape='sha256:75c421b6460d6364',
1618
1676
  table='dynamic',
1619
1677
  keys=(),
1620
1678
  predicate='dynamic SQL',
@@ -1678,10 +1736,67 @@ REGISTRY: "tuple[AccessContract, ...]" = (
1678
1736
  # passes the decoded prefix and its effective `by_id` to the pure helper,
1679
1737
  # which orders decisions by first appearance. No SQL was added or changed,
1680
1738
  # so the contract and its MAINT inert rule stand.
1739
+ # Reviewed re-pin (#997 T-A5/T-A6, base b193e984e). Added: the
1740
+ # `_lib_rebuild_progress` bindings (`_sink`, `_phase`, `_counters`,
1741
+ # `_last_write`, `THROTTLE_SECONDS`) and its `phase`, `tick` and `_emit`,
1742
+ # which the producer now calls to report progress to a detached worker's
1743
+ # state file; they hold process-local progress state, execute no SQL and
1744
+ # are no-ops unless a worker installed a sink. Changed: the producer (the
1745
+ # phase and tick calls, the Codex quota observations retained as
1746
+ # `QuotaLineSource` coordinates for the cache leg, and the record's
1747
+ # `peakResidentBytes` and `quotaLockMaxHoldSeconds`) and
1748
+ # `_backfill_five_hour_blocks` (a throttled tick every 1,024 blocks in its
1749
+ # insert loop). This site's `SELECT COUNT(*) FROM {tbl}` over
1750
+ # `_REBUILD_COUNT_TABLES`, its execution condition and its read-only
1751
+ # effect are unchanged, so the contract and its MAINT inert rule stand.
1752
+ # Reviewed re-pin (#997 T-C1/T-C3 and the revision-10 fix round, base
1753
+ # 9282d8b73). Changed: the producer builds its prefix hasher through
1754
+ # `_new_prefix_hasher` (the streamed accumulator with its segment opener),
1755
+ # compacts retained records with `_lib_journal.compact_retained` right
1756
+ # after decode, computes the open-block projection's first observations
1757
+ # and the late `effective` fields before releasing the read-pass state,
1758
+ # and reads the quota bundle after that release. None of these executes
1759
+ # SQL; this site's `SELECT COUNT(*) FROM {tbl}` over
1760
+ # `_REBUILD_COUNT_TABLES`, its execution condition and its read-only
1761
+ # effect are unchanged, so the contract and its MAINT inert rule stand.
1762
+ # Reviewed re-pin (#997 D19, base 0bfc75475). Changed: the closure's
1763
+ # imported producer `_backfill_five_hour_blocks`, whose `only_missing`
1764
+ # key query now takes each account's latest qualifying snapshot from one
1765
+ # `ROW_NUMBER()` ranking pass instead of a correlated subquery per row.
1766
+ # The selected keys are identical (T19 holds the old query as its oracle);
1767
+ # the producer's own execute sites are not registered accesses, and this
1768
+ # site's `SELECT COUNT(*) FROM {tbl}` over `_REBUILD_COUNT_TABLES`, its
1769
+ # execution condition and its read-only effect are unchanged, so the
1770
+ # contract and its MAINT inert rule stand.
1771
+ # Reviewed re-pin (#797/#823/#840 Task 2, base 5f3db4ddd). Added: the
1772
+ # fold applier `_cctally_journal._apply_op_weekly_observation_decision`
1773
+ # and the function it calls,
1774
+ # `_cctally_oauth_samples.apply_weekly_observation_decision_op`, with
1775
+ # its bindings `_DECISION_LISTS`, `_DISPOSITIONS` and `_UPSERT_DECISION`
1776
+ # (the reviewed weekly decision projection, upserting
1777
+ # `claude_weekly_observation_decisions` by observation id). Changed:
1778
+ # `FOLD_APPLIERS` (the two reviewed decision kinds now map to that
1779
+ # applier), the helper `open_db` (the epoch-1019 schema statements, see
1780
+ # the open_db re-pin) and the producer (its read pass offers each
1781
+ # admitted record to `_cctally_oauth_samples.RebuildProjector`, which
1782
+ # projects provider samples in bounded batches). This site's
1783
+ # `SELECT COUNT(*) FROM {tbl}` over `_REBUILD_COUNT_TABLES` (left
1784
+ # unchanged, so `db rebuild --json` keeps its counts), its execution
1785
+ # condition and its read-only effect are unchanged, so the contract and
1786
+ # its MAINT inert rule stand.
1787
+ # Reviewed re-pin (#797/#823/#840 Task 6, base 31bb25621). Changed: the
1788
+ # binding `_cctally_oauth_samples._DECISION_LISTS`, which now maps the
1789
+ # reviewed decision payload schema 3 (the `retract` disposition) to its
1790
+ # `weekly_axis_decisions` list, the hold projection schema 2 already
1791
+ # used, so a retraction folds into `claude_weekly_observation_decisions`
1792
+ # as the `hold` it projects. The applier's upsert, its table and its key
1793
+ # are unchanged; this site's `SELECT COUNT(*) FROM {tbl}` over
1794
+ # `_REBUILD_COUNT_TABLES`, its execution condition and its read-only
1795
+ # effect are unchanged, so the contract and its MAINT inert rule stand.
1681
1796
  AccessContract(
1682
1797
  function='_cctally_journal:_rebuild_stats_index_locked',
1683
1798
  sql_fingerprint='dynamic:_cctally_journal:_rebuild_stats_index_locked#1',
1684
- sql_shape='sha256:043784567bb14b97',
1799
+ sql_shape='sha256:1663fdf5858150ab',
1685
1800
  table='dynamic',
1686
1801
  keys=(),
1687
1802
  predicate='dynamic SQL',
@@ -2347,10 +2462,16 @@ REGISTRY: "tuple[AccessContract, ...]" = (
2347
2462
  classes=('cross-period',),
2348
2463
  inert_rule=MAINT,
2349
2464
  ),
2465
+ # Reviewed re-pin (#997 T-C1 and the revision-10 fix round, base
2466
+ # 9282d8b73): the producer builds its prefix hasher through
2467
+ # `_new_prefix_hasher` and passes each segment's size to `begin_segment`
2468
+ # (the streamed accumulator, D12). The hasher executes no SQL; the SQL
2469
+ # text, its execution condition and its read-only effect are unchanged,
2470
+ # so the contract and its MAINT inert rule stand.
2350
2471
  AccessContract(
2351
2472
  function='_cctally_journal:stats_index_matches_journal_prefix',
2352
2473
  sql_fingerprint='dynamic:_cctally_journal:stats_index_matches_journal_prefix#1',
2353
- sql_shape='sha256:5c869b43c418d251',
2474
+ sql_shape='sha256:393317bef4c27f3d',
2354
2475
  table='dynamic',
2355
2476
  keys=(),
2356
2477
  predicate='dynamic SQL',
@@ -2360,10 +2481,11 @@ REGISTRY: "tuple[AccessContract, ...]" = (
2360
2481
  classes=('cross-period',),
2361
2482
  inert_rule=MAINT,
2362
2483
  ),
2484
+ # Same reviewed re-pin as #1 (#997 D12).
2363
2485
  AccessContract(
2364
2486
  function='_cctally_journal:stats_index_matches_journal_prefix',
2365
2487
  sql_fingerprint='dynamic:_cctally_journal:stats_index_matches_journal_prefix#2',
2366
- sql_shape='sha256:46cf0672d1ac6f95',
2488
+ sql_shape='sha256:9c0c2275046f7719',
2367
2489
  table='dynamic',
2368
2490
  keys=(),
2369
2491
  predicate='dynamic SQL',
@@ -2481,6 +2603,24 @@ REGISTRY: "tuple[AccessContract, ...]" = (
2481
2603
  classes=('singleton',),
2482
2604
  inert_rule=Q7,
2483
2605
  ),
2606
+ # #797/#823/#840 epoch 1019 (spec 4.3 D8): the provider-sample
2607
+ # projection, reached from `_pipeline_claude_usage` through
2608
+ # `project_record`. One row per admitted keyed api observation, keyed by
2609
+ # account and observation id; INSERT OR IGNORE, so a replay of the same
2610
+ # record writes nothing. Not inert: the stale-contributor reducer reads
2611
+ # these rows as provider evidence.
2612
+ AccessContract(
2613
+ function='_cctally_oauth_samples:project_sample',
2614
+ sql_fingerprint='INSERT OR IGNORE INTO claude_oauth_samples (account_key, observation_id, requested_at_utc, captured_at_utc, weekly_percent, weekly_resets_at_utc, five_hour_percent, five_hour_resets_at_utc, five_hour_window_key) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)',
2615
+ table='claude_oauth_samples',
2616
+ keys=('account_key', 'observation_id'),
2617
+ predicate='',
2618
+ ordering='',
2619
+ selected=(),
2620
+ effects='write',
2621
+ classes=('singleton',),
2622
+ inert_rule=None,
2623
+ ),
2484
2624
  AccessContract(
2485
2625
  function='_cctally_quarantine:load_state',
2486
2626
  sql_fingerprint='SELECT MAX(seq) FROM outcome_quarantine_triggers',
@@ -2904,10 +3044,16 @@ REGISTRY: "tuple[AccessContract, ...]" = (
2904
3044
  classes=('singleton',),
2905
3045
  inert_rule=CODEX,
2906
3046
  ),
3047
+ # Reviewed re-pin (#997 T-C4, base 9282d8b73): the producer shares
3048
+ # repeated text values, reset instants and `QuotaWindowIdentity` objects
3049
+ # within one call through `_QuotaLoadValues` (D17). That helper executes
3050
+ # no SQL and returns equal values in the same order; the SQL text, its
3051
+ # execution condition and its read-only effect are unchanged, so the
3052
+ # contract and its inert rule stand.
2907
3053
  AccessContract(
2908
3054
  function='_cctally_quota:load_codex_quota_observations',
2909
3055
  sql_fingerprint='dynamic:_cctally_quota:load_codex_quota_observations#1',
2910
- sql_shape='sha256:6a6e082ae339b9cf',
3056
+ sql_shape='sha256:1f20459441a53e78',
2911
3057
  table='dynamic',
2912
3058
  keys=(),
2913
3059
  predicate='dynamic SQL',
@@ -3115,12 +3261,53 @@ REGISTRY: "tuple[AccessContract, ...]" = (
3115
3261
  ),
3116
3262
  AccessContract(
3117
3263
  function='_cctally_record:_read_five_hour_source_state',
3118
- sql_fingerprint='SELECT baseline_pct, pending_low_pct, pending_at_utc, pending_observation_id FROM five_hour_credit_confirmation_state WHERE account_key = ? AND five_hour_window_key = ? AND source = ?',
3264
+ sql_fingerprint='SELECT baseline_pct, pending_low_pct, pending_at_utc, pending_observation_id, baseline_observation_id, baseline_generation, pending_generation, pending_position FROM five_hour_credit_confirmation_state WHERE account_key = ? AND five_hour_window_key = ? AND source = ?',
3119
3265
  table='five_hour_credit_confirmation_state',
3120
3266
  keys=('account_key', 'five_hour_window_key', 'source'),
3121
3267
  predicate='account_key = ? AND five_hour_window_key = ? AND source = ?',
3122
3268
  ordering='',
3123
- selected=('baseline_pct', 'pending_low_pct', 'pending_at_utc', 'pending_observation_id'),
3269
+ selected=('baseline_pct', 'pending_low_pct', 'pending_at_utc', 'pending_observation_id', 'baseline_observation_id', 'baseline_generation', 'pending_generation', 'pending_position'),
3270
+ effects='read',
3271
+ classes=('period-keyed',),
3272
+ inert_rule=None,
3273
+ ),
3274
+ # #797/#823/#840 spec 4.9 (D3, D11): the v2 detector's eager rebase of
3275
+ # the window's other contributors at a credit, the ordinal of a credit's
3276
+ # retained causal facts, and the selected credit's content for its
3277
+ # generation (the row `resolve_five_hour_reset_event` chose by logical
3278
+ # order; the id only fetches it). All three read one account and window.
3279
+ AccessContract(
3280
+ function='_cctally_record:_rebase_five_hour_sources',
3281
+ sql_fingerprint='SELECT source, baseline_pct, pending_low_pct, pending_at_utc, pending_observation_id, baseline_observation_id, baseline_generation, pending_generation, pending_position FROM five_hour_credit_confirmation_state WHERE account_key = ? AND five_hour_window_key = ?',
3282
+ table='five_hour_credit_confirmation_state',
3283
+ keys=('account_key', 'five_hour_window_key'),
3284
+ predicate='account_key = ? AND five_hour_window_key = ?',
3285
+ ordering='',
3286
+ selected=('source', 'baseline_pct', 'pending_low_pct', 'pending_at_utc', 'pending_observation_id', 'baseline_observation_id', 'baseline_generation', 'pending_generation', 'pending_position'),
3287
+ effects='read',
3288
+ classes=('period-keyed',),
3289
+ inert_rule=None,
3290
+ ),
3291
+ AccessContract(
3292
+ function='_cctally_record:_record_five_hour_credit_facts',
3293
+ sql_fingerprint="SELECT COUNT(*) FROM five_hour_credit_confirmation_state WHERE account_key = ? AND five_hour_window_key = ? AND source LIKE '#credit|%'",
3294
+ table='five_hour_credit_confirmation_state',
3295
+ keys=('account_key', 'five_hour_window_key'),
3296
+ predicate="account_key = ? AND five_hour_window_key = ? AND source LIKE '#credit|%'",
3297
+ ordering='',
3298
+ selected=('COUNT(*)',),
3299
+ effects='read',
3300
+ classes=('period-keyed',),
3301
+ inert_rule=None,
3302
+ ),
3303
+ AccessContract(
3304
+ function='_cctally_record:five_hour_credit_generation',
3305
+ sql_fingerprint='SELECT detected_at_utc, prior_percent, post_percent, effective_reset_at_utc FROM five_hour_reset_events WHERE id = ?',
3306
+ table='five_hour_reset_events',
3307
+ keys=('id',),
3308
+ predicate='id = ?',
3309
+ ordering='',
3310
+ selected=('detected_at_utc', 'prior_percent', 'post_percent', 'effective_reset_at_utc'),
3124
3311
  effects='read',
3125
3312
  classes=('period-keyed',),
3126
3313
  inert_rule=None,
@@ -3175,7 +3362,7 @@ REGISTRY: "tuple[AccessContract, ...]" = (
3175
3362
  ),
3176
3363
  AccessContract(
3177
3364
  function='_cctally_record:_write_five_hour_source_state',
3178
- sql_fingerprint='INSERT INTO five_hour_credit_confirmation_state (account_key, five_hour_window_key, source, baseline_pct, pending_low_pct, pending_at_utc, pending_observation_id) VALUES (?, ?, ?, ?, ?, ?, ?) ON CONFLICT(account_key, five_hour_window_key, source) DO UPDATE SET baseline_pct = excluded.baseline_pct, pending_low_pct = excluded.pending_low_pct, pending_at_utc = excluded.pending_at_utc, pending_observation_id = excluded.pending_observation_id',
3365
+ sql_fingerprint='INSERT INTO five_hour_credit_confirmation_state (account_key, five_hour_window_key, source, baseline_pct, pending_low_pct, pending_at_utc, pending_observation_id, baseline_observation_id, baseline_generation, pending_generation, pending_position) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ON CONFLICT(account_key, five_hour_window_key, source) DO UPDATE SET baseline_pct = excluded.baseline_pct, pending_low_pct = excluded.pending_low_pct, pending_at_utc = excluded.pending_at_utc, pending_observation_id = excluded.pending_observation_id, baseline_observation_id = excluded.baseline_observation_id, baseline_generation = excluded.baseline_generation, pending_generation = excluded.pending_generation, pending_position = excluded.pending_position',
3179
3366
  table='five_hour_credit_confirmation_state',
3180
3367
  keys=(),
3181
3368
  predicate='',
@@ -3732,6 +3919,40 @@ REGISTRY: "tuple[AccessContract, ...]" = (
3732
3919
  classes=('cross-period',),
3733
3920
  inert_rule=MAINT,
3734
3921
  ),
3922
+ # #997 T-A1 (spec D1, D6): the disposable scratch policy applied to the
3923
+ # completion replay copies, the owed-outputs predecessor and the rederive
3924
+ # scratch, never to a published index. It probes for the usage table and,
3925
+ # when present, creates the three partial `replay_usage_*` indexes on that
3926
+ # scratch (`_REPLAY_SCRATCH_INDEXES`, the dynamic site). Both run on a
3927
+ # private scratch before its replay, never inside a live automatic
3928
+ # decision; an index changes no result set, and the order-insensitivity of
3929
+ # every statement it can serve is audited in the #997 plan's appendix and
3930
+ # pinned by `tests/test_997_replay_indexes.py`.
3931
+ AccessContract(
3932
+ function='_cctally_store:apply_disposable_scratch_policy',
3933
+ sql_fingerprint="SELECT 1 FROM sqlite_schema WHERE type = 'table' AND name = 'weekly_usage_snapshots'",
3934
+ table='weekly_usage_snapshots',
3935
+ keys=(),
3936
+ predicate="type = 'table' AND name = 'weekly_usage_snapshots'",
3937
+ ordering='',
3938
+ selected=('1',),
3939
+ effects='read',
3940
+ classes=('cross-period',),
3941
+ inert_rule=MAINT,
3942
+ ),
3943
+ AccessContract(
3944
+ function='_cctally_store:apply_disposable_scratch_policy',
3945
+ sql_fingerprint='dynamic:_cctally_store:apply_disposable_scratch_policy#1',
3946
+ sql_shape='sha256:fe12cdb5583c26fc',
3947
+ table='dynamic',
3948
+ keys=(),
3949
+ predicate='dynamic SQL',
3950
+ ordering='',
3951
+ selected=(),
3952
+ effects='write',
3953
+ classes=('singleton',),
3954
+ inert_rule=MAINT,
3955
+ ),
3735
3956
  AccessContract(
3736
3957
  function='_cctally_sync_week:_cmd_sync_week_via_ingest',
3737
3958
  sql_fingerprint='SELECT id, week_start_date, week_end_date, week_start_at, week_end_at, range_start_iso, range_end_iso, cost_usd, mode FROM weekly_cost_snapshots WHERE journal_id LIKE ? ORDER BY id DESC LIMIT 1',