quota: z.ai credit-bucket back-pressure + resource gate + usage accounting (Redmine 490+491)
The loop now consults quota and host state before every dispatch and
DEFERS gated work with a logged reason instead of letting turns die at
the provider (the 2026-08-28 19:00 quota-wall failure mode, replayed as
a test). Adds internal/quota: 5h/weekly credit buckets (provider poll
when z.ai ships an endpoint - fake-server tested - else locally
estimated from the documented credit formula), TZ-aware peak window
(default 01:00-05:00 America/Chicago weekdays, matching the documented
z.ai peak Mon-Fri 14:00-18:00 Singapore), block/defer thresholds, a
read-only load/mem/disk/IO-PSI monitor, an optional redis shared-state
hop (stdlib RESP2 mini-client) so all instances of an account
coordinate, per-class token+credit accounting in loop.jsonl, and
`harness quota status|probe|gate`. Config: [quota] + [resources]
sections; README runbook covers the redis container and deploy-time
cgroup enforcement.
💘 Generated with Crush
Assisted-by: Crush:glm-5.2
This commit is contained in:
+16
-3
@@ -10,6 +10,7 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@@ -48,6 +49,15 @@ func (d TOMLDoc) Bool(key string) (bool, bool) {
|
||||
return v, ok
|
||||
}
|
||||
|
||||
func (d TOMLDoc) Float(key string) (float64, bool) {
|
||||
if v, ok := d[key].(float64); ok {
|
||||
return v, true
|
||||
}
|
||||
// Bare integers read as floats too (max_load_avg = 6 parses as int64).
|
||||
v, ok := d[key].(int64)
|
||||
return float64(v), ok
|
||||
}
|
||||
|
||||
func (d TOMLDoc) StringList(key string) ([]string, bool) {
|
||||
raw, ok := d[key].([]any)
|
||||
if !ok {
|
||||
@@ -280,10 +290,13 @@ func parseScalar(v string, no int) (any, error) {
|
||||
return false, nil
|
||||
}
|
||||
n, err := parseTOMLInt(v)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("harness.toml:%d: unsupported value %q (want string, int, bool, or array)", no, v)
|
||||
if err == nil {
|
||||
return n, nil
|
||||
}
|
||||
return n, nil
|
||||
if f, ferr := strconv.ParseFloat(strings.ReplaceAll(v, "_", ""), 64); ferr == nil {
|
||||
return f, nil
|
||||
}
|
||||
return nil, fmt.Errorf("harness.toml:%d: unsupported value %q (want string, int, float, bool, or array)", no, v)
|
||||
}
|
||||
|
||||
func parseTOMLInt(v string) (int64, error) {
|
||||
|
||||
Reference in New Issue
Block a user