feat(miner-hands): add pure per-attempt cost/turn metering to gittensory-engine - #4428
Conversation
…ory-engine New packages/gittensory-engine/src/miner/attempt-metering.ts: pure accumulation of a coding-agent attempt's usage (tokens/turns/wall-clock/cost) and a pure evaluation of the running totals against a per-axis budget. Numbers only — no IO, no Date.now, no randomness, no enforcement (a ceiling reached is reported, never acted on). Mirrors the governor/rate-limit.ts discipline. Breach semantics: an axis breaches at or above its ceiling (>=); an omitted ceiling never breaches. Enforcement (graceful-stop vs SIGKILL) and attempt-log persistence (JSONbored#4294) are separate concerns. Closes JSONbored#4311
|
🚨 Contributor flagged. Click here for more info: Superagent Dashboard |
|
Superagent didn't find any vulnerabilities or security issues in this PR. |
|
Tip 🟩🟩🟩🟩🟩🟩🟩🟩🟩🟩🟩🟩 ✅ Gittensory review result - approve/merge recommendedReview updated: 2026-07-09 17:29:14 UTC
✅ Suggested Action - Approve/Merge
Review summary Nits — 5 non-blocking
Flagged checks (non-blocking)
Linked issue satisfactionAddressed Review context
Contributor next steps
Signal definitions
🟩 Safe / merged · 🟦 Advisory · 🟨 Held for review · 🟥 Blocked / closed 💰 Earn for open-source contributions like this. Gittensor lets GitHub contributors earn for the work they already do — register to start earning →. Checked by Gittensory, a quiet PR intelligence layer for OSS maintainers.
|
Adds pure per-attempt cost/turn metering to the engine (Closes #4311).
New
packages/gittensory-engine/src/miner/attempt-metering.ts: a pure accumulator + budget evaluator for a coding-agent attempt's usage.accumulateAttemptUsage(total, next)/meterAttemptUsage(increments)— fold usage increments ({tokens, turns, wallClockMs, costUsd}) into a running total. Pure; no mutation.evaluateAttemptBudget(totals, budget)— check totals against per-axis ceilings (maxTokens/maxTurns/maxWallClockMs/maxCostUsd), returning{ totals, withinBudget, breaches }.Metered unit is pinned explicitly (the issue's open design point): each axis is a plain numeric counter; drivers (CLI-subprocess vs. Agent-SDK) normalize their native usage shape to this unit. Breach semantics: an axis breaches at or above its ceiling (
>=), so exactly-at-ceiling is a breach — the boundary the caller must stop on; an omitted ceiling never breaches.Numbers only — no IO, no
Date.now(), no randomness, no enforcement (a reached ceiling is reported, never acted on). Mirrors thegovernor/rate-limit.tsdiscipline. The breach-response wiring (graceful-stop vs. hard SIGKILL) and attempt-log persistence (#4294) are explicitly separate, maintainer-owned concerns.Test
test/attempt-metering.test.ts— accumulation (incl. no-mutation + empty), within-budget, the exactly-at-ceiling boundary, just-under, each axis independently, multiple breaches, the omitted-ceiling arm, and a mid-attempt breach across incremental steps. Full engine suite: 321 pass;test:engine-paritygreen.site//CNAME/**/lovable/**; noCHANGELOG.md. New engine module + test + one entrypoint re-export.