feat: add stall_ms and stall_count telemetry columns

Third approved port change: TelemetryRecorder.record_llm_call gains
stall_ms/stall_count (assembly gate derives from this signature).
Schema five edit points (both DDLs, both backfill decls, COLUMNS)
with INTEGER nullable columns appended last; telemetry_schema_sql
regenerates from the same constants untouched. Emitter forwards the
pair from retry._emit on the success branch only (cancelled hedge
loser rows stay NULL by construction); cache-hit and terminal rows
pass explicit None. Both **fields recorders pick the columns up with
zero signature change.
This commit is contained in:
2026-09-14 01:16:33 -04:00
parent 53bcf43172
commit e0b0be09a7
8 changed files with 220 additions and 25 deletions
+18 -4
View File
@@ -5,8 +5,8 @@
多处各存一份必然漂移,而漂移的表现是"下游照打印的 SQL 建完表,库仍报缺列"。
**`COLUMNS` 是 INSERT 字段序,不是物理列序**: 数据库自填的 `created_at` 不在其中(它带
`DEFAULT now()` / `datetime('now')`,库从不显式写它)。物理表列 = 36 个 INSERT 字段 +
`created_at` = 37;列数断言一律按物理列数写,两套口径混用是最易错处。
`DEFAULT now()` / `datetime('now')`,库从不显式写它)。物理表列 = 38 个 INSERT 字段 +
`created_at` = 39;列数断言一律按物理列数写,两套口径混用是最易错处。
本模块只依赖标准库: `telemetry/` 与 `backends/`、`transports/`、`structured/` 同层且
互不依赖(import-linter 契约执法)。
@@ -62,7 +62,9 @@ CREATE TABLE IF NOT EXISTS llm_calls (
cause_type TEXT,
error_body TEXT,
attempts INTEGER,
total_latency_ms INTEGER
total_latency_ms INTEGER,
stall_ms INTEGER,
stall_count INTEGER
);
"""
@@ -104,7 +106,9 @@ CREATE TABLE IF NOT EXISTS llm_calls (
cause_type TEXT,
error_body TEXT,
attempts INTEGER,
total_latency_ms INTEGER
total_latency_ms INTEGER,
stall_ms INTEGER,
stall_count INTEGER
);
"""
@@ -137,6 +141,10 @@ SQLITE_BACKFILL = (
("error_body", "TEXT"),
("attempts", "INTEGER"),
("total_latency_ms", "INTEGER"),
# 1.3.8 沉默归因两列(issue #27): 同样可空无默认——旧行 NULL = "补列之前
# 没记过这件事",与"观测过且零沉默"(0)是两回事
("stall_ms", "INTEGER"),
("stall_count", "INTEGER"),
)
# PG 补列的列定义。语句由此派生成两份文本(见下),使"库内执行的那份"与"打印给
@@ -163,6 +171,9 @@ _PG_BACKFILL_DECLS = (
("error_body", "TEXT"),
("attempts", "INTEGER"),
("total_latency_ms", "INTEGER"),
# 1.3.8 两列,列序与 SQLITE_BACKFILL 逐项对齐(理由同上)
("stall_ms", "INTEGER"),
("stall_count", "INTEGER"),
)
# 新列排在 created_at 之后: 与旧表 ALTER 追加的位置一致(见 SQLITE_BACKFILL 同款注释)。
@@ -212,6 +223,9 @@ COLUMNS = (
"error_body",
"attempts",
"total_latency_ms",
# —— 1.3.8 沉默归因(issue #27)——
"stall_ms",
"stall_count",
)
_COLUMN_SET = frozenset(COLUMNS)