Commit fe9d7ad
fix(state): address PR #19508 P1+P2 review feedback
Mac 3-lens review (architect / code-review / security) flagged 3 P1
correctness bugs. Fixes:
P1.1 — Calendar-aware EMA weighting (hermes_state.py)
Was: raw_weights = [alpha * (1-alpha)**(n-1-i) for i in range(n)]
Now: weights by (today_utc - day).days. Days with no data correctly
get zero weight (absent from result); gaps don't compress older data.
Defeats the index-based bias toward sparsely-running skills.
P1.2 — Volume-weighted cost / duration EMA (hermes_state.py + view)
Was: ema_X = sum(w * avg_X) — biased equal-weight across days
regardless of invocation count.
Now: skill_stats_daily exposes total_duration_s / total_cost_usd
alongside avg_*. EMA computed as
sum(w_d * total_d) / sum(w_d * count_d)
so a day with 100 fast calls correctly outweighs a day with 1 slow
call within the same EMA term.
P1.3 — Surface telemetry write failures (cron/scheduler.py)
Was: except: logger.debug(...) — silent swallow at DEBUG; broken
writer invisible until dashboard goes empty.
Now: logger.warning(..., exc_info=True). Operator sees regressions;
cron still cannot fail (warning never raises).
Plus P2.1 (multi-skill cron cost split — divides session cost evenly
when len(job["skills"]) > 1, preventing per-skill EMA cost-doubling),
P2.2 (DROP VIEW IF EXISTS before CREATE for migration idempotency),
and P3 nits (dead conditional on error_msg slice; docstring half-life
math corrected — α=0.3 ≈ 1.94d, not 5d; α≈0.129 for true 5-day).
Smoke-tested off-tree:
skill-a-gappy (days 0,1,7) success_rate=0.954 ← gap correctly
down-weights day-7
skill-b-tight (days 0,1,2) success_rate=1.000
skill-c-vol (1 slow + 100 fast) duration=1.69s cost=$0.0024/call
← volume-weighted
Constraint: pure additive view change — DROP+CREATE on every connect
is safe because skill_stats_daily has no rowids/triggers depending on
its identity. Existing rows in skill_invocations untouched.
Confidence: high (3 scenarios validated)
Scope-risk: narrow (same file boundaries as original PR)
Not-tested: multi-skill cron live-fire (smoke uses synthetic data)
Machine: orion-terminal
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent ffdc581 commit fe9d7ad
2 files changed
Lines changed: 98 additions & 27 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1363 | 1363 | | |
1364 | 1364 | | |
1365 | 1365 | | |
1366 | | - | |
| 1366 | + | |
| 1367 | + | |
1367 | 1368 | | |
1368 | 1369 | | |
1369 | 1370 | | |
| |||
1402 | 1403 | | |
1403 | 1404 | | |
1404 | 1405 | | |
1405 | | - | |
| 1406 | + | |
| 1407 | + | |
| 1408 | + | |
| 1409 | + | |
1406 | 1410 | | |
1407 | 1411 | | |
1408 | 1412 | | |
1409 | 1413 | | |
1410 | 1414 | | |
1411 | 1415 | | |
1412 | | - | |
1413 | | - | |
1414 | | - | |
1415 | | - | |
| 1416 | + | |
| 1417 | + | |
| 1418 | + | |
| 1419 | + | |
| 1420 | + | |
| 1421 | + | |
| 1422 | + | |
| 1423 | + | |
| 1424 | + | |
| 1425 | + | |
| 1426 | + | |
| 1427 | + | |
| 1428 | + | |
| 1429 | + | |
| 1430 | + | |
| 1431 | + | |
| 1432 | + | |
| 1433 | + | |
| 1434 | + | |
| 1435 | + | |
| 1436 | + | |
| 1437 | + | |
| 1438 | + | |
1416 | 1439 | | |
1417 | 1440 | | |
1418 | 1441 | | |
| |||
1422 | 1445 | | |
1423 | 1446 | | |
1424 | 1447 | | |
1425 | | - | |
1426 | | - | |
1427 | | - | |
1428 | | - | |
1429 | | - | |
| 1448 | + | |
| 1449 | + | |
| 1450 | + | |
| 1451 | + | |
| 1452 | + | |
1430 | 1453 | | |
1431 | 1454 | | |
1432 | 1455 | | |
1433 | 1456 | | |
1434 | | - | |
| 1457 | + | |
| 1458 | + | |
| 1459 | + | |
| 1460 | + | |
| 1461 | + | |
| 1462 | + | |
1435 | 1463 | | |
1436 | | - | |
| 1464 | + | |
1437 | 1465 | | |
1438 | 1466 | | |
1439 | 1467 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| 24 | + | |
24 | 25 | | |
25 | 26 | | |
26 | 27 | | |
| |||
124 | 125 | | |
125 | 126 | | |
126 | 127 | | |
127 | | - | |
| 128 | + | |
| 129 | + | |
128 | 130 | | |
129 | 131 | | |
130 | 132 | | |
| |||
133 | 135 | | |
134 | 136 | | |
135 | 137 | | |
| 138 | + | |
136 | 139 | | |
137 | 140 | | |
138 | 141 | | |
| |||
788 | 791 | | |
789 | 792 | | |
790 | 793 | | |
791 | | - | |
792 | | - | |
793 | | - | |
794 | | - | |
| 794 | + | |
| 795 | + | |
| 796 | + | |
| 797 | + | |
| 798 | + | |
| 799 | + | |
| 800 | + | |
| 801 | + | |
| 802 | + | |
| 803 | + | |
| 804 | + | |
| 805 | + | |
| 806 | + | |
| 807 | + | |
795 | 808 | | |
796 | 809 | | |
797 | 810 | | |
| |||
803 | 816 | | |
804 | 817 | | |
805 | 818 | | |
806 | | - | |
| 819 | + | |
| 820 | + | |
| 821 | + | |
807 | 822 | | |
808 | 823 | | |
809 | 824 | | |
810 | 825 | | |
811 | 826 | | |
812 | 827 | | |
813 | 828 | | |
814 | | - | |
| 829 | + | |
| 830 | + | |
815 | 831 | | |
816 | 832 | | |
817 | 833 | | |
| |||
825 | 841 | | |
826 | 842 | | |
827 | 843 | | |
| 844 | + | |
| 845 | + | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
| 850 | + | |
| 851 | + | |
| 852 | + | |
| 853 | + | |
| 854 | + | |
| 855 | + | |
828 | 856 | | |
829 | 857 | | |
830 | 858 | | |
831 | 859 | | |
832 | | - | |
| 860 | + | |
| 861 | + | |
| 862 | + | |
833 | 863 | | |
834 | 864 | | |
835 | 865 | | |
| |||
847 | 877 | | |
848 | 878 | | |
849 | 879 | | |
850 | | - | |
851 | | - | |
852 | | - | |
853 | | - | |
854 | | - | |
855 | | - | |
| 880 | + | |
| 881 | + | |
| 882 | + | |
| 883 | + | |
| 884 | + | |
| 885 | + | |
856 | 886 | | |
857 | 887 | | |
| 888 | + | |
| 889 | + | |
| 890 | + | |
| 891 | + | |
| 892 | + | |
| 893 | + | |
| 894 | + | |
| 895 | + | |
| 896 | + | |
| 897 | + | |
| 898 | + | |
| 899 | + | |
| 900 | + | |
858 | 901 | | |
859 | 902 | | |
860 | 903 | | |
| |||
0 commit comments