cctally 1.113.0 → 1.115.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.
- package/CHANGELOG.md +47 -0
- package/README.md +4 -6
- package/bin/_cctally_account.py +32 -8
- package/bin/_cctally_cache.py +6035 -722
- package/bin/_cctally_completion.py +1287 -0
- package/bin/_cctally_config.py +37 -0
- package/bin/_cctally_core.py +400 -2
- package/bin/_cctally_dashboard.py +98 -20
- package/bin/_cctally_dashboard_conversation.py +292 -23
- package/bin/_cctally_dashboard_envelope.py +16 -3
- package/bin/_cctally_dashboard_perf.py +128 -9
- package/bin/_cctally_dashboard_sources.py +285 -213
- package/bin/_cctally_db.py +1177 -23
- package/bin/_cctally_diagnosis_sources.py +22 -4
- package/bin/_cctally_doctor.py +572 -45
- package/bin/_cctally_five_hour.py +84 -33
- package/bin/_cctally_forecast.py +108 -15
- package/bin/_cctally_journal.py +3950 -116
- package/bin/_cctally_journal_repair.py +101 -12
- package/bin/_cctally_milestone_history.py +82 -9
- package/bin/_cctally_parser.py +42 -0
- package/bin/_cctally_percent_breakdown.py +3 -2
- package/bin/_cctally_project.py +8 -2
- package/bin/_cctally_quarantine.py +652 -0
- package/bin/_cctally_quota.py +227 -37
- package/bin/_cctally_quota_model.py +360 -83
- package/bin/_cctally_record.py +691 -149
- package/bin/_cctally_rederive.py +320 -41
- package/bin/_cctally_refresh.py +84 -13
- package/bin/_cctally_source_analytics.py +83 -17
- package/bin/_cctally_statusline.py +6154 -517
- package/bin/_cctally_store.py +367 -53
- package/bin/_cctally_transcript.py +8 -7
- package/bin/_cctally_tui.py +61 -56
- package/bin/_cctally_weekrefs.py +128 -21
- package/bin/_lib_account_binding.py +152 -0
- package/bin/_lib_account_protocol.py +386 -0
- package/bin/_lib_aggregators.py +4 -0
- package/bin/_lib_cache_coverage.py +13 -1
- package/bin/_lib_cache_report.py +35 -6
- package/bin/_lib_cache_writer_lock.py +19 -3
- package/bin/_lib_clone_copy.py +142 -0
- package/bin/_lib_codex_conversation.py +32 -0
- package/bin/_lib_codex_conversation_query.py +297 -49
- package/bin/_lib_codex_conversation_watch.py +59 -14
- package/bin/_lib_codex_drain_admission.py +214 -0
- package/bin/_lib_codex_metadata.py +18 -1
- package/bin/_lib_codex_publication_barrier.py +277 -0
- package/bin/_lib_codex_rollout_container.py +502 -0
- package/bin/_lib_conversation_dispatch.py +3 -0
- package/bin/_lib_conversation_query.py +106 -59
- package/bin/_lib_conversation_retention.py +1605 -640
- package/bin/_lib_cost_provenance.py +53 -2
- package/bin/_lib_detector_access_registry.py +3817 -0
- package/bin/_lib_doctor.py +714 -69
- package/bin/_lib_five_hour.py +126 -0
- package/bin/_lib_fmt.py +11 -0
- package/bin/_lib_ingest_frontier.py +414 -20
- package/bin/_lib_journal.py +141 -10
- package/bin/_lib_jsonl.py +5 -4
- package/bin/_lib_legacy_spool.py +126 -0
- package/bin/_lib_legacy_writer_evidence.py +136 -0
- package/bin/_lib_merge_gate.py +231 -86
- package/bin/_lib_meter_rate_change.py +10 -0
- package/bin/_lib_outcome_quarantine.py +690 -0
- package/bin/_lib_perf.py +27 -1
- package/bin/_lib_pricing.py +199 -9
- package/bin/_lib_pricing_check.py +20 -4
- package/bin/_lib_quarantine.py +154 -0
- package/bin/_lib_quota_calibration.py +53 -8
- package/bin/_lib_quota_copy.py +2 -1
- package/bin/_lib_quota_model.py +288 -46
- package/bin/_lib_reclaim_planner.py +792 -0
- package/bin/_lib_rederive.py +319 -82
- package/bin/_lib_segment_summary.py +35 -2
- package/bin/_lib_snapshot_cache.py +21 -0
- package/bin/_lib_sqlite_close.py +81 -0
- package/bin/_lib_statusline_candidates.py +292 -23
- package/bin/_lib_subscription_weeks.py +100 -17
- package/bin/_lib_tick_stats.py +217 -17
- package/bin/_lib_wal_checkpoint.py +1077 -0
- package/bin/_lib_write_budget.py +483 -0
- package/bin/_lib_write_io.py +703 -0
- package/bin/cctally +31 -1
- package/dashboard/static/assets/{ConversationsView-CEZ-BUyi.js → ConversationsView-Bc8LCOAZ.js} +1 -1
- package/dashboard/static/assets/{DoctorModal-CE1oH_Zy.js → DoctorModal-D--qVBwe.js} +1 -1
- package/dashboard/static/assets/ModalRoot-DLPgyAM_.js +1 -0
- package/dashboard/static/assets/{ProjectsDrillPanel-B3DZoCeD.js → ProjectsDrillPanel-z53a4v4M.js} +1 -1
- package/dashboard/static/assets/{SourceDetailModal-CHp9EgLP.js → SourceDetailModal-Bw0T8W-W.js} +1 -1
- package/dashboard/static/assets/{UpdateModal-5iKST6jo.js → UpdateModal-D5AKx4Yw.js} +1 -1
- package/dashboard/static/assets/index-BKITk1CT.css +1 -0
- package/dashboard/static/assets/{index-Cm0VTxJC.js → index-BXDOzSng.js} +3 -3
- package/dashboard/static/assets/{outlineNavigation-DkXGL8J6.js → outlineNavigation-JObY7cUY.js} +1 -1
- package/dashboard/static/dashboard.html +2 -2
- package/package.json +19 -1
- package/dashboard/static/assets/ModalRoot-D5Y8IFUG.js +0 -1
- package/dashboard/static/assets/index-Dt4tqf43.css +0 -1
package/bin/_cctally_quota.py
CHANGED
|
@@ -313,6 +313,10 @@ PROJECTION_GATE_CALLERS: "dict[str, tuple[str, ...]]" = {
|
|
|
313
313
|
#: and requires a statement verb earlier in that text than the match. Nothing
|
|
314
314
|
#: about which reads are covered changed; what changed is that the count now
|
|
315
315
|
#: means what its name says.
|
|
316
|
+
# #968 adds eight cache cursor/thread reads, one doctor prune-debt read,
|
|
317
|
+
# and two frontier cursor/debt reads. Fixed cursor pairs, thread tuples/TEMP
|
|
318
|
+
# views and debt enums cannot reach either quota projection table. This
|
|
319
|
+
# census is consumed only by test_selector_state_496_s5b.py; see its audit.
|
|
316
320
|
PROJECTION_DYNAMIC_READ_SITES: "dict[str, int]" = {
|
|
317
321
|
"_cctally_account.py": 1,
|
|
318
322
|
# Three, all in `_import_legacy_conversation_rows`: `FROM main.{table}`,
|
|
@@ -340,7 +344,7 @@ PROJECTION_DYNAMIC_READ_SITES: "dict[str, int]" = {
|
|
|
340
344
|
# has work without performing it (#780). `{table}` iterates the same
|
|
341
345
|
# hardcoded `_LEGACY_BRIDGE_TABLES` tuple as the three reads above, so
|
|
342
346
|
# neither reaches a projection family and neither needs an entry below.
|
|
343
|
-
"_cctally_cache.py":
|
|
347
|
+
"_cctally_cache.py": 17,
|
|
344
348
|
# One, not two, since #750 S4: `_get_latest_row_for_week` composed
|
|
345
349
|
# its `WHERE` clauses instead of branching on `as_of_utc`, so its
|
|
346
350
|
# two near-identical `FROM {table_name}` reads became one. The
|
|
@@ -352,7 +356,7 @@ PROJECTION_DYNAMIC_READ_SITES: "dict[str, int]" = {
|
|
|
352
356
|
# Six, not seven: `cctally: rebuilt stats.db from {} journal segment(s)` is
|
|
353
357
|
# an operator line, not a statement, and no longer counts.
|
|
354
358
|
"_cctally_db.py": 6,
|
|
355
|
-
"_cctally_doctor.py":
|
|
359
|
+
"_cctally_doctor.py": 2,
|
|
356
360
|
"_cctally_five_hour.py": 1,
|
|
357
361
|
# Sixteen, not eighteen: the two `event {} rev {} conflicts with effective
|
|
358
362
|
# rev {} from {}` refusals are prose and no longer count.
|
|
@@ -365,7 +369,14 @@ PROJECTION_DYNAMIC_READ_SITES: "dict[str, int]" = {
|
|
|
365
369
|
# `budget_milestones`, `projected_milestones` or
|
|
366
370
|
# `project_budget_milestones`. None is a projection table, so it needs no
|
|
367
371
|
# entry below.
|
|
368
|
-
|
|
372
|
+
#
|
|
373
|
+
# Nineteen since #825/#832 fix round E: `_rematerialize_scratch_row`'s
|
|
374
|
+
# row lookup by journal id and `_delete_scratch_row`'s removal by row id
|
|
375
|
+
# touch only a derivation-completion SCRATCH projection, and the table
|
|
376
|
+
# they interpolate is always an `_EVT_SPECS` table (the snapshot, reset,
|
|
377
|
+
# block and milestone families). None is a projection table, so neither
|
|
378
|
+
# needs an entry below.
|
|
379
|
+
"_cctally_journal.py": 19,
|
|
369
380
|
"_cctally_pricing_check.py": 1,
|
|
370
381
|
# One, in `_read_stats_component`: a single `SELECT {column} FROM
|
|
371
382
|
# {table}` shared by `week_reset_events` and `weekly_credit_floors`,
|
|
@@ -373,12 +384,30 @@ PROJECTION_DYNAMIC_READ_SITES: "dict[str, int]" = {
|
|
|
373
384
|
# so no `PROJECTION_DYNAMIC_READ_ACTIONS` classification applies.
|
|
374
385
|
"_cctally_quota_model.py": 1,
|
|
375
386
|
"_cctally_quota.py": 1,
|
|
387
|
+
# Two, both #825/#832 revision 5 per-account row counts:
|
|
388
|
+
# `_account_rows`' `SELECT COUNT(*) FROM {table}` behind the projection's
|
|
389
|
+
# classification evidence, and `_tokens_from`'s `SELECT COUNT(*),
|
|
390
|
+
# MAX(rowid) FROM {table}` behind a waiting head's dependency tokens
|
|
391
|
+
# (`_wait_tokens` before fix round K13, which shares it with the
|
|
392
|
+
# activating event's non-waiting read).
|
|
393
|
+
# `{table}` is always one of the hardcoded `weekly_usage_snapshots`,
|
|
394
|
+
# `week_reset_events`, `weekly_credit_floors`, `five_hour_reset_events`
|
|
395
|
+
# or `five_hour_blocks`; neither site reaches a quota projection table, so
|
|
396
|
+
# no `PROJECTION_DYNAMIC_READ_ACTIONS` classification applies.
|
|
397
|
+
"_cctally_statusline.py": 2,
|
|
376
398
|
# One, in `_codex_rollup_revision`: the table is selected from a hardcoded
|
|
377
399
|
# pair of Codex conversation rollups. Neither is a quota projection table,
|
|
378
400
|
# so no `PROJECTION_DYNAMIC_READ_ACTIONS` classification applies.
|
|
379
401
|
"_lib_codex_conversation_query.py": 1,
|
|
380
402
|
"_lib_conversation_query.py": 1,
|
|
381
|
-
|
|
403
|
+
# Four, not two, since #901's paced retention (`f2077468a`, spec §5.4):
|
|
404
|
+
# `group_row_count` counts the rows a deletion's reservation charges with
|
|
405
|
+
# `SELECT COUNT(*) FROM {table}` in its two shapes (by identity key, and by
|
|
406
|
+
# source path for a NULL-identity group). `{table}` comes from
|
|
407
|
+
# `_GROUP_TABLES`, a hardcoded pair (`conversation_messages`,
|
|
408
|
+
# `codex_conversation_events`); neither is a quota projection table, so no
|
|
409
|
+
# `PROJECTION_DYNAMIC_READ_ACTIONS` classification applies.
|
|
410
|
+
"_lib_conversation_retention.py": 4,
|
|
382
411
|
# Five: `_target_has_cursor_gap` selects one of the two accounting source
|
|
383
412
|
# tables, `_conversation_source_paths` and `_conversation_target_risk`
|
|
384
413
|
# select one of the two transcript source tables, and #769 S6's
|
|
@@ -393,7 +422,7 @@ PROJECTION_DYNAMIC_READ_SITES: "dict[str, int]" = {
|
|
|
393
422
|
# total over those two names and raises on anything else. Every choice here
|
|
394
423
|
# is hardcoded; none is a quota projection table, so no
|
|
395
424
|
# `PROJECTION_DYNAMIC_READ_ACTIONS` classification applies.
|
|
396
|
-
"_lib_ingest_frontier.py":
|
|
425
|
+
"_lib_ingest_frontier.py": 8,
|
|
397
426
|
"_lib_snapshot_cache.py": 1,
|
|
398
427
|
"_lib_subscription_weeks.py": 1,
|
|
399
428
|
}
|
|
@@ -1307,6 +1336,107 @@ def _codex_quota_required_text_present(values: Iterable[object]) -> bool:
|
|
|
1307
1336
|
value is None or not str(value).strip() for value in values)
|
|
1308
1337
|
|
|
1309
1338
|
|
|
1339
|
+
# ── #901 W1: reading the maintained raw-partition maxima (spec §5.1, T1) ─────
|
|
1340
|
+
|
|
1341
|
+
#: The objects the latest-only read and the general loader's plan pins depend
|
|
1342
|
+
#: on, probed together once per load.
|
|
1343
|
+
_CODEX_QUOTA_READ_OBJECTS = (
|
|
1344
|
+
"codex_quota_partition_latest", "idx_qws_partition_capture",
|
|
1345
|
+
"trg_qws_latest_ins", "trg_qws_latest_del", "trg_qws_latest_upd",
|
|
1346
|
+
"idx_qws_codex_load_order", "idx_qws_physical_group",
|
|
1347
|
+
)
|
|
1348
|
+
_CODEX_QUOTA_SUMMARY_OBJECTS = frozenset(_CODEX_QUOTA_READ_OBJECTS[:5])
|
|
1349
|
+
|
|
1350
|
+
#: The latest path's SELECT list over the summary join, aliased so every name
|
|
1351
|
+
#: the interpretation loop reads resolves exactly as it does on the window path.
|
|
1352
|
+
_CODEX_QUOTA_LATEST_SELECT = ", ".join(
|
|
1353
|
+
f"q.{column} AS {column}" for column in (
|
|
1354
|
+
"source", "source_root_key", "source_path", "line_offset",
|
|
1355
|
+
"captured_at_utc", "observed_slot", "logical_limit_key", "limit_id",
|
|
1356
|
+
"limit_name", "window_minutes", "used_percent", "resets_at_utc",
|
|
1357
|
+
"plan_type", "individual_limit_json", "reached_type",
|
|
1358
|
+
"observed_model", "account_key", "canonical_resets_at_utc",
|
|
1359
|
+
))
|
|
1360
|
+
|
|
1361
|
+
|
|
1362
|
+
def _codex_quota_read_objects(conn: sqlite3.Connection) -> "frozenset[str]":
|
|
1363
|
+
"""Which of the read-path objects this store carries (one probe)."""
|
|
1364
|
+
placeholders = ",".join("?" for _ in _CODEX_QUOTA_READ_OBJECTS)
|
|
1365
|
+
return frozenset(
|
|
1366
|
+
str(row[0]) for row in conn.execute(
|
|
1367
|
+
f"SELECT name FROM sqlite_master WHERE name IN ({placeholders})",
|
|
1368
|
+
_CODEX_QUOTA_READ_OBJECTS)
|
|
1369
|
+
)
|
|
1370
|
+
|
|
1371
|
+
|
|
1372
|
+
def _codex_quota_latest_summary_ready(read_objects: "frozenset[str]") -> bool:
|
|
1373
|
+
"""True when the summary and everything that maintains it are present.
|
|
1374
|
+
|
|
1375
|
+
The five objects are created and bootstrapped in one transaction
|
|
1376
|
+
(``_cctally_db._apply_codex_quota_latest_summary``), and SQLite drops a
|
|
1377
|
+
table's triggers and indexes only together with the table, so their joint
|
|
1378
|
+
presence means the summary has been maintained since its bootstrap.
|
|
1379
|
+
Anything less — a read-only open of a store migration 047 has not reached,
|
|
1380
|
+
or a legacy shape — keeps the window query, which selects the same rows.
|
|
1381
|
+
"""
|
|
1382
|
+
return _CODEX_QUOTA_SUMMARY_OBJECTS <= read_objects
|
|
1383
|
+
|
|
1384
|
+
|
|
1385
|
+
def _sqlite_order_value(value) -> tuple:
|
|
1386
|
+
"""Rank a stored value the way SQLite's BINARY ORDER BY ranks it.
|
|
1387
|
+
|
|
1388
|
+
NULL first, then numbers (integers and reals compared numerically), then
|
|
1389
|
+
text in code-point order (which is UTF-8 byte order), then blobs.
|
|
1390
|
+
"""
|
|
1391
|
+
if value is None:
|
|
1392
|
+
return (0, 0)
|
|
1393
|
+
if isinstance(value, (int, float)):
|
|
1394
|
+
return (1, value)
|
|
1395
|
+
if isinstance(value, str):
|
|
1396
|
+
return (2, value)
|
|
1397
|
+
return (3, bytes(value))
|
|
1398
|
+
|
|
1399
|
+
|
|
1400
|
+
def _codex_quota_latest_rows(
|
|
1401
|
+
conn: sqlite3.Connection, requested: "set[str] | None",
|
|
1402
|
+
) -> "list[sqlite3.Row]":
|
|
1403
|
+
"""Every valid physical row tied at its raw partition's maximum second.
|
|
1404
|
+
|
|
1405
|
+
One scan of the summary (one row per retained raw partition) and one
|
|
1406
|
+
``idx_qws_partition_capture`` seek per partition. ``CROSS JOIN`` fixes the
|
|
1407
|
+
summary as the outer loop and ``INDEXED BY`` the inner seek, so the plan
|
|
1408
|
+
cannot drift into walking the snapshots. The window path's ORDER BY
|
|
1409
|
+
(``source_root_key, captured_at_utc, resets_at_utc, source_path,
|
|
1410
|
+
line_offset``) is reproduced here in Python over this bounded set, so the
|
|
1411
|
+
rows reach the interpretation loop in exactly the order they did before.
|
|
1412
|
+
"""
|
|
1413
|
+
import _cctally_db
|
|
1414
|
+
|
|
1415
|
+
on = " AND ".join(
|
|
1416
|
+
f"{expr} = s.{key}" for key, expr in zip(
|
|
1417
|
+
_cctally_db._CODEX_QUOTA_LATEST_KEY_COLUMNS,
|
|
1418
|
+
_cctally_db._codex_quota_latest_key_exprs("q.")))
|
|
1419
|
+
sql = (
|
|
1420
|
+
f"SELECT {_CODEX_QUOTA_LATEST_SELECT}"
|
|
1421
|
+
" FROM codex_quota_partition_latest AS s"
|
|
1422
|
+
" CROSS JOIN quota_window_snapshots AS q"
|
|
1423
|
+
" INDEXED BY idx_qws_partition_capture"
|
|
1424
|
+
f" ON {on} AND unixepoch(q.captured_at_utc) = s.latest_capture_epoch"
|
|
1425
|
+
f" WHERE {_cctally_db._codex_quota_latest_validity_sql('q.')}"
|
|
1426
|
+
)
|
|
1427
|
+
params: "list[object]" = []
|
|
1428
|
+
if requested is not None:
|
|
1429
|
+
sql += (" AND s.k_source_root_key IN ("
|
|
1430
|
+
+ ",".join("quote(?)" for _ in requested) + ")")
|
|
1431
|
+
params.extend(sorted(requested))
|
|
1432
|
+
rows = conn.execute(sql, params).fetchall()
|
|
1433
|
+
rows.sort(key=lambda row: tuple(
|
|
1434
|
+
_sqlite_order_value(row[name]) for name in (
|
|
1435
|
+
"source_root_key", "captured_at_utc", "resets_at_utc",
|
|
1436
|
+
"source_path", "line_offset")))
|
|
1437
|
+
return rows
|
|
1438
|
+
|
|
1439
|
+
|
|
1310
1440
|
# --------------------------------------------------------------------------
|
|
1311
1441
|
# #500 §6.4 — the fold-time operator attribution overlay
|
|
1312
1442
|
# --------------------------------------------------------------------------
|
|
@@ -1449,6 +1579,56 @@ def _codex_attribution_stored_limit_keys(logical_limit_key: str) -> "list[str]":
|
|
|
1449
1579
|
)
|
|
1450
1580
|
|
|
1451
1581
|
|
|
1582
|
+
def _codex_shard_axis_filter(axes: tuple) -> "tuple[str, tuple]":
|
|
1583
|
+
"""The WHERE clause and parameters selecting one attribution axis shard.
|
|
1584
|
+
|
|
1585
|
+
Rows are STORED under whichever length and key spelling the provider sent,
|
|
1586
|
+
so the filter enumerates every equivalent rather than snapping in SQL —
|
|
1587
|
+
which it could not do and still seek the index.
|
|
1588
|
+
"""
|
|
1589
|
+
root_key, limit_key, slot, window_minutes = axes
|
|
1590
|
+
limit_keys = _codex_attribution_stored_limit_keys(limit_key)
|
|
1591
|
+
minutes = sorted({
|
|
1592
|
+
int(value)
|
|
1593
|
+
for value in codex_snap_equivalent_window_minutes(window_minutes)
|
|
1594
|
+
})
|
|
1595
|
+
axis_clause = (
|
|
1596
|
+
" WHERE source='codex' AND source_root_key = ?"
|
|
1597
|
+
" AND logical_limit_key IN ("
|
|
1598
|
+
+ ",".join("?" * len(limit_keys)) + ")"
|
|
1599
|
+
" AND observed_slot = ?"
|
|
1600
|
+
" AND window_minutes IN (" + ",".join("?" * len(minutes)) + ")"
|
|
1601
|
+
)
|
|
1602
|
+
return axis_clause, (root_key, *limit_keys, slot, *minutes)
|
|
1603
|
+
|
|
1604
|
+
|
|
1605
|
+
def _codex_witness_anchors(
|
|
1606
|
+
conn: sqlite3.Connection, anchor_expr: str, axis_clause: str,
|
|
1607
|
+
axis_params: tuple, witnesses: "Sequence[str]",
|
|
1608
|
+
) -> "set[str]":
|
|
1609
|
+
"""Pass 1: the canonical anchors of the groups a witness reset reaches.
|
|
1610
|
+
|
|
1611
|
+
#901 Amendment 19 T1 (spec I1): the set is built in Python from the
|
|
1612
|
+
streamed rows. ``SELECT DISTINCT`` sorted the anchors of every capture
|
|
1613
|
+
carrying a witness reset through a temp b-tree — a window group's whole
|
|
1614
|
+
activity — and one attribution axis shard is not a bound. The result is
|
|
1615
|
+
the same set; the Python set holds one entry per distinct anchor.
|
|
1616
|
+
"""
|
|
1617
|
+
pass_one = (
|
|
1618
|
+
f"SELECT {anchor_expr} AS anchor"
|
|
1619
|
+
" FROM quota_window_snapshots"
|
|
1620
|
+
+ axis_clause
|
|
1621
|
+
+ " AND unixepoch(resets_at_utc) IN ("
|
|
1622
|
+
+ ",".join("unixepoch(?)" for _ in witnesses) + ")"
|
|
1623
|
+
)
|
|
1624
|
+
anchors: "set[str]" = set()
|
|
1625
|
+
for row in conn.execute(pass_one, (*axis_params, *witnesses)):
|
|
1626
|
+
if row[0] is None or not str(row[0]).strip():
|
|
1627
|
+
continue
|
|
1628
|
+
anchors.add(str(row[0]))
|
|
1629
|
+
return anchors
|
|
1630
|
+
|
|
1631
|
+
|
|
1452
1632
|
def _load_codex_window_group_evidence(
|
|
1453
1633
|
conn: sqlite3.Connection, assertions: "Sequence[Mapping[str, object]]",
|
|
1454
1634
|
) -> "tuple[_wa.WindowGroup, ...]":
|
|
@@ -1557,36 +1737,10 @@ def _load_codex_window_group_evidence(
|
|
|
1557
1737
|
witness_texts: "dict[str, str]" = {}
|
|
1558
1738
|
model_scoped: "dict[tuple, bool]" = {}
|
|
1559
1739
|
for axes, shard_witnesses in sorted(shards.items()):
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
limit_keys = _codex_attribution_stored_limit_keys(limit_key)
|
|
1565
|
-
minutes = sorted({
|
|
1566
|
-
int(value)
|
|
1567
|
-
for value in codex_snap_equivalent_window_minutes(window_minutes)
|
|
1568
|
-
})
|
|
1569
|
-
witnesses = sorted(shard_witnesses)
|
|
1570
|
-
axis_clause = (
|
|
1571
|
-
" WHERE source='codex' AND source_root_key = ?"
|
|
1572
|
-
" AND logical_limit_key IN ("
|
|
1573
|
-
+ ",".join("?" * len(limit_keys)) + ")"
|
|
1574
|
-
" AND observed_slot = ?"
|
|
1575
|
-
" AND window_minutes IN (" + ",".join("?" * len(minutes)) + ")"
|
|
1576
|
-
)
|
|
1577
|
-
axis_params = (root_key, *limit_keys, slot, *minutes)
|
|
1578
|
-
anchors: "set[str]" = set()
|
|
1579
|
-
pass_one = (
|
|
1580
|
-
f"SELECT DISTINCT {anchor_expr} AS anchor"
|
|
1581
|
-
" FROM quota_window_snapshots"
|
|
1582
|
-
+ axis_clause
|
|
1583
|
-
+ " AND unixepoch(resets_at_utc) IN ("
|
|
1584
|
-
+ ",".join("unixepoch(?)" for _ in witnesses) + ")"
|
|
1585
|
-
)
|
|
1586
|
-
for row in conn.execute(pass_one, (*axis_params, *witnesses)):
|
|
1587
|
-
if row[0] is None or not str(row[0]).strip():
|
|
1588
|
-
continue
|
|
1589
|
-
anchors.add(str(row[0]))
|
|
1740
|
+
axis_clause, axis_params = _codex_shard_axis_filter(axes)
|
|
1741
|
+
anchors = _codex_witness_anchors(
|
|
1742
|
+
conn, anchor_expr, axis_clause, axis_params,
|
|
1743
|
+
sorted(shard_witnesses))
|
|
1590
1744
|
if not anchors:
|
|
1591
1745
|
continue
|
|
1592
1746
|
# ONE SHARD PER GROUP, for the reason the loader states at its own group
|
|
@@ -1983,6 +2137,16 @@ def load_codex_quota_observations(
|
|
|
1983
2137
|
and therefore the same verdict as the full load, on a store where the full
|
|
1984
2138
|
load meant interpreting 266,337 rows to answer a question about 608 of them.
|
|
1985
2139
|
|
|
2140
|
+
#901 W1 (spec §5.1, T1): on a store carrying cache migration 047's objects
|
|
2141
|
+
the candidate rows come from ``codex_quota_partition_latest``, a
|
|
2142
|
+
trigger-maintained table holding every raw partition's maximum whole-second
|
|
2143
|
+
capture, joined back to every physical row tied at that second through
|
|
2144
|
+
``idx_qws_partition_capture``. The window query described below stays as the
|
|
2145
|
+
fallback for a store without those objects (a read-only open before the
|
|
2146
|
+
migration ran, or a legacy shape); both select exactly the same rows, and
|
|
2147
|
+
tests/test_901_partition_latest_maintenance.py holds the summary to the
|
|
2148
|
+
frozen pre-#901 window query after every writer class.
|
|
2149
|
+
|
|
1986
2150
|
SQL narrows to the rows that can possibly win, and Python still decides. The
|
|
1987
2151
|
partition is the RAW spelling of every column the interpretation reads
|
|
1988
2152
|
(root, limit key, slot, window minutes, limit id and name, observed model,
|
|
@@ -2106,6 +2270,8 @@ def load_codex_quota_observations(
|
|
|
2106
2270
|
"canonical_resets_at_utc" if has_anchor
|
|
2107
2271
|
else "NULL AS canonical_resets_at_utc"
|
|
2108
2272
|
)
|
|
2273
|
+
# #901: one probe for the summary and the two plan-pin indexes.
|
|
2274
|
+
read_objects = _codex_quota_read_objects(conn)
|
|
2109
2275
|
# Public #5: the model is read from THIS table alone. There used to be a
|
|
2110
2276
|
# COALESCE onto the nearest preceding `codex_session_entries.model` at
|
|
2111
2277
|
# or before the snapshot's byte offset, for rows written before the
|
|
@@ -2129,9 +2295,26 @@ def load_codex_quota_observations(
|
|
|
2129
2295
|
model_expr=model_expr, account_expr=account_expr,
|
|
2130
2296
|
anchor_expr=anchor_expr,
|
|
2131
2297
|
)
|
|
2298
|
+
# #901 W3 (spec §5.1, T1/T3): pin the plan. Unpinned, the planner sorts
|
|
2299
|
+
# an unbounded or multi-root load through a temp b-tree via the
|
|
2300
|
+
# `source` autoindex, and the load-order index hijacks the projector's
|
|
2301
|
+
# per-group shards into a whole-root walk (both measured). A bounded
|
|
2302
|
+
# `max_rows` read keeps its plan: its sorter holds at most `max_rows`
|
|
2303
|
+
# rows. Each pin is applied only when its index exists, so a store
|
|
2304
|
+
# without them keeps today's SQL.
|
|
2305
|
+
if group_filter is not None:
|
|
2306
|
+
table_hint = (
|
|
2307
|
+
" INDEXED BY idx_qws_physical_group"
|
|
2308
|
+
if "idx_qws_physical_group" in read_objects else "")
|
|
2309
|
+
elif physical_signatures is None and max_rows is not None:
|
|
2310
|
+
table_hint = ""
|
|
2311
|
+
else:
|
|
2312
|
+
table_hint = (
|
|
2313
|
+
" INDEXED BY idx_qws_codex_load_order"
|
|
2314
|
+
if "idx_qws_codex_load_order" in read_objects else "")
|
|
2132
2315
|
sql = f"""
|
|
2133
2316
|
SELECT {select_list}
|
|
2134
|
-
FROM quota_window_snapshots
|
|
2317
|
+
FROM quota_window_snapshots{table_hint}
|
|
2135
2318
|
WHERE source='codex' AND source_root_key IS NOT NULL
|
|
2136
2319
|
"""
|
|
2137
2320
|
params: list[object] = []
|
|
@@ -2271,9 +2454,16 @@ def load_codex_quota_observations(
|
|
|
2271
2454
|
shard_sql = f"{head}{clause}{order_by}"
|
|
2272
2455
|
for group in group_filter:
|
|
2273
2456
|
shards.append((shard_sql, (*params, *group)))
|
|
2457
|
+
if latest_per_identity and _codex_quota_latest_summary_ready(
|
|
2458
|
+
read_objects):
|
|
2459
|
+
# #901 W1 (spec §5.1, T1): the maintained summary yields exactly
|
|
2460
|
+
# the rows the window query above selects, without sorting history.
|
|
2461
|
+
row_source = _codex_quota_latest_rows(conn, requested)
|
|
2462
|
+
else:
|
|
2463
|
+
row_source = _iter_shard_rows(conn, shards)
|
|
2274
2464
|
result: list[QuotaObservation] = []
|
|
2275
2465
|
signature_tuples: dict[str, dict[str, list[tuple[object, ...]]]] = {}
|
|
2276
|
-
for row in
|
|
2466
|
+
for row in row_source:
|
|
2277
2467
|
if not _codex_quota_required_text_present(
|
|
2278
2468
|
row[name] for name in _CODEX_QUOTA_REQUIRED_TEXT
|
|
2279
2469
|
):
|