Skip to content

feat(amico-run): attribute CPU cost to principal and Lab from the solve unit cgroup (#2133) - #2134

Merged
aarontrowbridge merged 1 commit into
lane/0.4.1from
opencode/issue-2133
Nov 4, 2026
Merged

aarontrowbridge merged 1 commit into
lane/0.4.1from
opencode/issue-2133

Conversation

@aarontrowbridge

Copy link
Copy Markdown
Contributor

Closes #2133. Replaces #2121 (closed), whose CPU measurement was wrong. Part of the central hub (ADR 0041 §5).

What: every local solve now writes a receipt carrying cpu_seconds measured from the solve unit's cgroup (cpu.stat usage_usec of the amico-run-<id> unit, read before Julia spawns and again at the start of settle, before teardown), principal and lab (from AMICO_PRINCIPAL / AMICO_LAB, set by the hub frontdoor later), and cost_usd only when a human has configured ~/.amico/amicode/rates.json ({"cpu_usd_per_second": n}), with cost_basis: list_price_estimate. No unit/cgroup (macOS, protection: none) records cost_basis: unmeasured, never an engine-process figure. costTotals() rolls up by principal and Lab, with an (unattributed) bucket. Accounting failure never fails a run.

Why #2121 was wrong: process.cpuUsage() counts only the engine process, but Julia is a child in its own unit, so every solve would have been costed at about zero.

Verified by the director (re-run, not the implementer's report):

  • 85 targeted amico-run tests pass (cost, executor cost, adopt, run_lock, ledger, placement); no process-CPU API in the code.
  • Independent measurement against known workloads in real transient units: one busy process for 2 s measured 2.01 CPU-s, four busy processes for 2 s measured 8.04 (a wall-clock or single-process measure would say 2), a sleeping unit measured 0.00. No leaked units.
  • Implementer's own runs: amico-run 139 files / 2524 tests pass; schema 382 pass; typecheck clean; the real-unit slow test runs (not skipped) and recorded 1.518 s for a 1.5 s burn through the bundled amico run.

Behaviour changes to know about: every local run now appends a receipt (to hold the unmeasured case), so two tests that assumed "no receipt for local runs" were updated; gpuTotals now skips executor: "local" rows so GPU sums aren't inflated. No rate is set by default, so dollars appear only after a human supplies one.

Needs a human: create rates.json to get dollars; the hub frontdoor must set AMICO_PRINCIPAL/AMICO_LAB. Dollar figures are list-price estimates, not invoices.

…ve unit cgroup

Measure a local solve's real CPU from its transient unit's cgroup (cpu.stat
usage_usec delta, startRun to settle) instead of the engine process clock.
Emit a local receipt with cpu_seconds, principal, lab, and a cost_usd priced
from ~/.amico/amicode/rates.json (list_price_estimate); unmeasured when no
cgroup. Add costTotals rollup by principal and Lab. Accounting never fails a run.
@coderabbitai

coderabbitai Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 641f887e-1bc3-4865-8e58-858a89e28e5a

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@aarontrowbridge
aarontrowbridge merged commit 55467dd into lane/0.4.1 Nov 4, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant