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:
2026-08-29 05:37:15 -05:00
parent 9dbb20489c
commit fc518c475e
21 changed files with 2904 additions and 20 deletions
+39
View File
@@ -165,3 +165,42 @@ secret_ref = "env:HARNESS_GITEA_WEBHOOK_SECRET"
listen = ":8090" # publish on the LAN via docker -p
vkey_ref = "env:HARNESS_SERVE_VKEY"
# enabled_models = ["mopac-primary", "mopac-study"] # optional subset
# QUOTA GATE (Redmine 490, off by default until verified live): z.ai coding
# plan credit buckets (5h + weekly), back-pressure thresholds, TZ-aware peak
# window, and the redis shared-state hop so all harness instances of one
# account coordinate. The loop DEFERS gated work with a logged reason; it
# never hard-fails. With no usage_url it runs on locally estimated
# consumption against the configured plan limits (see README: z.ai has no
# public usage endpoint yet — LIVE VERIFICATION open).
# [quota]
# enabled = true
# account = "zai-max-1" # plan label shared across instances
# plan_5h_credits = 28000 # Max plan; Lite 2000/10000, Pro 12000/60000
# plan_weekly_credits = 140000
# usage_url = "" # set when z.ai ships the endpoint
# key_ref = "env:HARNESS_ZAI_KEY" # bearer for usage_url; never logged
# poll_interval_secs = 300
# defer_at_pct = 85 # heavy classes defer, flash tier continues
# block_at_pct = 95 # everything defers until reset (the wall)
# # Peak = z.ai Mon-Fri 14:00-18:00 Singapore == 01:00-05:00 America/Chicago
# # in winter (00:00-04:00 during US DST — adjust in March/November).
# peak_start = "01:00"
# peak_end = "05:00"
# timezone = "America/Chicago"
# peak_weekdays_only = true
# peak_classes = ["study", "read"] # flash/LLM-lite classes allowed in peak
# # Shared state for the 9 instances across 2 hosts (redis docker container
# # on 192.168.3.78; see README runbook). Empty = local-only estimates.
# redis_url = "redis://192.168.3.78:6390/0"
# RESOURCE GATE (Redmine 491, off by default): read-only host monitor —
# loadavg, mem available, work_root disk free, IO pressure (/proc/pressure
# io, skipped when PSI is absent). The loop defers dispatch while busy.
# cgroup enforcement is deploy-time (README runbook).
# [resources]
# enabled = true
# max_load_avg = 6.0
# min_mem_available_mb = 2048
# min_disk_free_mb = 5120
# max_io_delay_pct = 90.0