@windyroad/risk-scorer 0.16.5 → 0.16.6
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.
|
@@ -69,20 +69,36 @@ five_used_i=${five_used%%.*}; week_used_i=${week_used%%.*}
|
|
|
69
69
|
five_elapsed=$(elapsed_pct "$five_reset" "$FIVE_WINDOW")
|
|
70
70
|
week_elapsed=$(elapsed_pct "$week_reset" "$WEEK_WINDOW")
|
|
71
71
|
|
|
72
|
-
#
|
|
73
|
-
#
|
|
74
|
-
|
|
75
|
-
|
|
72
|
+
# Smart glide-path pacing (P160 refinement 2026-07-06). Rather than a fixed
|
|
73
|
+
# catch-up sleep that snaps back to the ideal line, throttle PROPORTIONALLY to
|
|
74
|
+
# how far over the glide-path to the window reset we are, easing off as we
|
|
75
|
+
# converge — like a runner who is ahead of pace slowing down to drift back,
|
|
76
|
+
# not stopping dead. The "safe rate" for the remainder of a window =
|
|
77
|
+
# budget-left / time-left (x1000 fixed-point; 1000 = on pace, 0 = budget blown
|
|
78
|
+
# with time still on the clock). When safe_rate < 1 we must burn slower, so we
|
|
79
|
+
# sleep CAP*(1 - safe_rate). As we slow, wall-clock advances, time-left shrinks,
|
|
80
|
+
# safe_rate climbs back toward 1, and the sleep eases to zero exactly as we
|
|
81
|
+
# rejoin pace — converging BEFORE the quota is consumed, while still letting
|
|
82
|
+
# work through the whole time (never a hard stop; at worst one call per CAP).
|
|
83
|
+
safe_rate_x1000() { # used_i elapsed_pct headroom_pp
|
|
84
|
+
local budget=$(( 100 - $3 - $1 )) rem=$(( 100 - $2 ))
|
|
85
|
+
[ "$rem" -le 0 ] && { printf '1000'; return; } # window reset → unconstrained
|
|
86
|
+
[ "$budget" -le 0 ] && { printf '0'; return; } # budget blown → max throttle
|
|
87
|
+
printf '%s' $(( budget * 1000 / rem ))
|
|
88
|
+
}
|
|
76
89
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
[ "$gap" -le 0 ] && emit_ok # behind/on pace → fast no-op
|
|
90
|
+
s5=$(safe_rate_x1000 "$five_used_i" "$five_elapsed" 0)
|
|
91
|
+
s7=$(safe_rate_x1000 "$week_used_i" "$week_elapsed" "$WEEK_HEADROOM_PP")
|
|
80
92
|
|
|
81
|
-
#
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
93
|
+
# Tighter window governs = smaller safe_rate.
|
|
94
|
+
safe="$s5"; [ "$s7" -lt "$safe" ] && safe="$s7"
|
|
95
|
+
[ "$safe" -ge 1000 ] && emit_ok # on/under pace on both windows → fast no-op
|
|
96
|
+
|
|
97
|
+
# Proportional ease-back: far over → near CAP (slow, but still one call per CAP);
|
|
98
|
+
# slightly over → a short sleep; on pace → zero. The smooth glide, not a stop.
|
|
99
|
+
sleep_secs=$(( CAP_SECONDS * (1000 - safe) / 1000 ))
|
|
85
100
|
[ "$sleep_secs" -le 0 ] && emit_ok
|
|
101
|
+
[ "$sleep_secs" -gt "$CAP_SECONDS" ] && sleep_secs="$CAP_SECONDS"
|
|
86
102
|
|
|
87
103
|
sleep "$sleep_secs" 2>/dev/null
|
|
88
104
|
emit_ok
|