equipo: show hosted waits, limits and usage
Task 25. The task view says when checks wait for a hosted machine, and which hosted limit holds them and when it frees. Hosted reasons a machine could not run checks read in their own words. The Usage page gains a Hosted machines block (running now, VM hours today, estimated spend this month, against the person's limits; unknown, never zero, when unread). Owners get a per-person limit editor in the hosted section. Nineteen new keys, pending.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
16 files changed,
+838
−19
.rastrillo/budgets.txt+2 −2docs/superpowers/plans/2026-11-30-hosted-slice-2-copy.json+133 −0docs/superpowers/plans/CONTROLLER-REPORT-plan-3.md+19 −0docs/superpowers/plans/HOSTED-SLICE2-PROGRESS.md+64 −0internal/equipo/chat/hosted_limits.go+27 −16internal/equipo/chat/usage.go+76 −0internal/equipo/copy.go+21 −0internal/equipo/hosted_settings.go+58 −0internal/equipo/hosted_settings_test.go+1 −1internal/equipo/hosted_views_test.go+328 −0internal/equipo/settings_hub.go+17 −0internal/equipo/templates/hosted_settings.html+11 −0internal/equipo/templates/usage.html+3 −0internal/equipo/usage_page.go+46 −0internal/equipo/work_pages.go+26 −0internal/equipo/work_views.go+6 −0
diff --git a/.rastrillo/budgets.txt b/.rastrillo/budgets.txt| index d21952ae..761305f0 100644 |
| --- a/.rastrillo/budgets.txt |
| +++ b/.rastrillo/budgets.txt |
| @@ -15,7 +15,7 @@ time internal/equipo/team 60s Plan 3 loaded CI measured 45.985s; niced serial re |
| time internal/equipotest 300s Final fix package rerun measured 187.035s (review 172.4s); 300s gives 60 percent headroom for HTTP, sandbox, authority and final regression coverage. |
| time internal/equipo/hostedrun 60s Hosted slice 2 Task 21: TestDispatcherSimulation runs 200 seeds of the real chat store (SQLite) and dispatcher against a fake controller, with unlinked VMs that run to their 90-minute lifetime since review round 1, and one test drives the real controller over TLS for 90 simulated minutes; about 35 s of CPU in parallel subtests; measured 14 s on a 16 CPU docs-t1 under load 2.4; 60s covers a loaded 4 CPU runner. |
| -size internal/equipo 25304 8741 Preview, retry, merges, kept work, check-db, notifications, places, GitHub routes, installer, abilities, lookups, Mac waits, slice F codes, D1, probe details, Design's copy, /api/team; measured 24735. Hosted slice 2 Task 15 review 1: work.reason.pack_incomplete (pending); 24736. Task 17: work.reason.deps_conflict, deps_new_module, deps_missing, deps_too_large and token_renewal_failed (pending); 24741. Task 18: the owner setting "Run checks in a hosted VM" (config flag, routes, section, handler, four pending keys); 24825. Its review round 1: chatMe reports a roster denial as chat.ErrForbidden too (chatDenied); 24837. Task 21: the hosted dispatcher started only with EQUIPO_HOSTED_RUNNERS=1, execution on and a controller configured (EQUIPO_HOSTED_* config, RevokeRunner wiring), and the work.reason words for hosted_enrol_timeout, hosted_vm_lost and hosted_unavailable (pending); 24867. Task 22: hosted_enrol.go, a hosted VM's enrolment (POST /api/hosted/enrol) and its runner's challenge and renewal under /api/runner/v2 (the store methods over the runner and credential rows, the handlers, the routes only with EQUIPO_HOSTED_RUNNERS=1 and an admission reader), and mintRunnerCredential's lifetime and cap; 25248. Its tests (hosted_enrol_test.go: the routes through the whole application, and the runner's hosted.Start end to end through the test proxy) drive the unexported store, router and admission reader, so they live beside them and take the directory past the 8000-line test default; measured 8563 test lines. Task 22 review 1: the controller's deadline in the credential cap, and tests for a stale admission after a newer refusal, the first sighting and its window, code single use alone and the controller's deadline; 25256/8669. Review 2: a renewal reads the controller's admission record first, outside the transaction, and is capped by its current deadline; its tests (a deadline moved earlier after launch, the controller away or without a record); 25304/8724. Review 3: enrolment tests for a deadline moved earlier before enrolment and one already passed; 25304/8741. |
| +size internal/equipo 25478 9069 Preview, retry, merges, kept work, check-db, notifications, places, GitHub routes, installer, abilities, lookups, Mac waits, slice F codes, D1, probe details, Design's copy, /api/team; measured 24735. Hosted slice 2 Task 15 review 1: work.reason.pack_incomplete (pending); 24736. Task 17: work.reason.deps_conflict, deps_new_module, deps_missing, deps_too_large and token_renewal_failed (pending); 24741. Task 18: the owner setting "Run checks in a hosted VM" (config flag, routes, section, handler, four pending keys); 24825. Its review round 1: chatMe reports a roster denial as chat.ErrForbidden too (chatDenied); 24837. Task 21: the hosted dispatcher started only with EQUIPO_HOSTED_RUNNERS=1, execution on and a controller configured (EQUIPO_HOSTED_* config, RevokeRunner wiring), and the work.reason words for hosted_enrol_timeout, hosted_vm_lost and hosted_unavailable (pending); 24867. Task 22: hosted_enrol.go, a hosted VM's enrolment (POST /api/hosted/enrol) and its runner's challenge and renewal under /api/runner/v2 (the store methods over the runner and credential rows, the handlers, the routes only with EQUIPO_HOSTED_RUNNERS=1 and an admission reader), and mintRunnerCredential's lifetime and cap; 25248. Its tests (hosted_enrol_test.go: the routes through the whole application, and the runner's hosted.Start end to end through the test proxy) drive the unexported store, router and admission reader, so they live beside them and take the directory past the 8000-line test default; measured 8563 test lines. Task 22 review 1: the controller's deadline in the credential cap, and tests for a stale admission after a newer refusal, the first sighting and its window, code single use alone and the controller's deadline; 25256/8669. Review 2: a renewal reads the controller's admission record first, outside the transaction, and is capped by its current deadline; its tests (a deadline moved earlier after launch, the controller away or without a record); 25304/8724. Review 3: enrolment tests for a deadline moved earlier before enrolment and one already passed; 25304/8741. Task 25: what the person sees of hosted work: the checks line and timeline for a hosted wait and for each hosted limit (hostedWaitLine), the hosted reasons' words on the checks line and the merge decision, the Usage page's Hosted machines block (unknown, never zero, when unread), the owner's per-person limit editor (form, parsing, save route, the members it lists) and nineteen pending keys; hosted_views_test.go drives the store through the production wiring; 25478/9069. |
| size internal/wire 9902 - Protocols 31 to 35 (facts, diffs, evidence, CI units, files, places), abilities, 36 lookups, 37 Mac Engineering, 38 Design, unproven and probe detail codes, 39 hosted runners (hosted.go: placement, hosted_pack and deps transfer limits, enrolment types); measured 9848. Task 15 opened TransferHeader.Valid to hosted_pack (inbound, base then candidate) and added ReasonPackIncomplete; 9860. Its review round 1 registered it in StepReasons; 9862. Task 17: the hosted worker's reasons (deps_conflict, deps_new_module, deps_missing, deps_too_large, token_renewal_failed) registered in StepReasons, and TransferHeader.Valid opened to deps with the hosted_pack rules (the worker accepts the bundle; Task 23 sends it); 9884. Task 21: ReasonHostedEnrolTimeout, ReasonHostedVMLost and ReasonHostedUnavailable, registered in StepReasons; 9899. Task 23: SendPackCommand.Deps, refused below ProtocolHostedRunners; 9902. |
| size internal/equipotest - 12693 GitHub connect value search, lifecycle and sweep-log contracts; Task 21 migration fixtures, Rastrillo asset contract, renderer archive link; measured 0/12693 source/test lines. |
| time internal/runner/checks 90s CI worker measured 44.553s (44.6s rounded); |
| @@ -60,7 +60,7 @@ perf GET /api/v1/assistant/snapshot skip Assistant person API: bearer-only JSON |
| perf GET /api/v1/assistant/messages skip Assistant person API: bearer-only JSON for Base's chat, not a browser screen. |
| perf GET /api/v1/assistant/events skip Assistant event stream (Server-Sent Events), bearer-only and long-lived; not a screen. |
| perf GET /api/v1/assistant/abilities skip Assistant person API: bearer-only JSON for Base's Settings line, not a browser screen. |
| -size internal/equipo/chat 47123 21758 File facts/diffs, previews, merges, unfinished work, CI, receipts, Assistant files, places, abilities, lookups, go-aheads, Mac work, D1, Design specialists, grants, captures; 45093/18782. Hosted slice 2 Task 15: openHostedPack (the instance's send_pack for a hosted pack) and its test; 45105/18883. Its review round 1 added the report-ingestion test for pack_incomplete; 45105/18911. Task 18: hosted_setting.go (SetHostedChecks, hostedChecks, HostedSettings; owner only, roster in the transaction, audited) and its tests; 45208/19070. Its review round 1: the audit atomicity test; 45208/19113. Task 19: hosted_jobs.go (the hosted_jobs and hosted_challenges tables, HostedJob and its lifecycle: newHostedJob, the listed moves only, ended and failed only with stop proof or never-launched evidence, settleHostedJob once, hostedJobForRunner; each move audited in its transaction) and its tests, TestMigrationAdditive included; 45658/19577. Its review round 1: the never-launched evidence contract (HostedNeverLaunched, launch_by and launching_since, hostedLaunchReturned) and tests for it, settlement of unproven terminal records and audit atomicity; 45728/19739. Task 20: hosted_limits.go (per-person hosted limits, S2-9: hostedAdmit held in the write by a per-person lock row, hostedHoldFor, Allocate, hostedSettle at 4x the baseline, SetHostedLimits owner only with the roster, revision and audit in the transaction) and its tests; 46013/20214. Its coordinator ruling: a limit counts only while its setting owner is a current owner (defaults otherwise, checked in the admission transaction) and TestOwnerRaisesLimitRevoked; 46022/20284. Its review round 1: Allocate returns nothing for an empty or reversed span before widening, and its assertions; 46025/20290. Hosted slice 2 Task 21: placement on hosted VMs (placeHosted before the checks early return, its five rules), the bound runner's fits, Authorize by job identity, the hosted offline rule and withdrawal exemption, the hosted pack at dispatch, the step-terminal hook, and the dispatcher's store methods (HostedLive, HostedSweep, HostedLaunching with relaunch, HostedLaunched, HostedAdmitted, HostedFailed, HostedStopped, HostedNeverLaunched, HostedReplaces, PlaceHosted; end, settle, revoke, step moved on) in hosted_run.go, and hosted_place_test.go; 46665/20804. Task 21 review round 1: abandoned-intent evidence waits for the job's lifetime, the job keeps its lifetime and first running sight, admission takes the placing transaction's step attempt, provider-valid attempt IDs, HostedRunning, and the Retry, replacement-runner, cancelled-task and stopping-VM tests; 46709/20937. Its review round 2: TestHostedReplacesNeedsProof; 46709/20971. Task 22: hosted_enrol.go (the enrolment and renewal store steps inside the instance's write transaction: HostedClaimCode, HostedEnrolAdmit, HostedEnrolBind, HostedRunnerJob, HostedNewChallenge, HostedUseChallenge; hostedAdmitted shared with HostedAdmitted); its tests drive it through the instance's routes (internal/equipo); 46848/20971. Its review round 1: hostedAdmitted reports whether the record was kept, the enrolment records the first sighting and applies the window from it, and the launch view's deadline is kept (hosted_jobs.deadline, earliest wins); 46903/20971. Its review round 2: an admission record's current deadline is kept too (hostedAdmitted, for the dispatcher's refresh and the renewal's HostedRenewAdmit); 46932/20971. Round 3: HostedEnrolAdmit returns the job re-read after recording the admission, so the enrolment caps by its deadline; 46937/20971. Task 23: openHostedPack opens the deps bundle after the hosted pack (send_pack with Deps), the instance's chunk and byte checks per kind (wire.MaxChunks, wire.MaxBytes), deps_too_large for a bundle past its limit, and a hosted attempt's pack and bundle closed when its checks end; hosted_deps_test.go; 46957/21199. Task 24: hosted_results.go (hostedCertified, AdmissionFresh: a hosted worker's checks count as sandboxed and its base checks as trusted only through the job's fresh, valid admission record, never its hello; an uncertified hosted result is not kept, its job stops and the step goes again once; deps_new_module and deps_missing presented as needs_network), stepReport and acceptBaseChecks wired to it, the admission kept whole and the enrolment image (0129), and hosted_results_test.go; 47094/21522. Task 24 review round 1: the certification decision moved before any terminal checks report from a worker (done, failed, unsolicited cancelled, the early failure branches), the person's cancellation kept, and tests for those, a wrong step, a stopping job and each admission identity substitution; 47096/21714. Task 24 review round 2: hostedSettleCancel (under the person's cancellation or an ended task, an uncertified hosted runner's report settles only its termination, with no checks evidence, taint or retry) and TestHostedUncertifiedCancelRace; 47123/21758. |
| +size internal/equipo/chat 47210 21758 File facts/diffs, previews, merges, unfinished work, CI, receipts, Assistant files, places, abilities, lookups, go-aheads, Mac work, D1, Design specialists, grants, captures; 45093/18782. Hosted slice 2 Task 15: openHostedPack (the instance's send_pack for a hosted pack) and its test; 45105/18883. Its review round 1 added the report-ingestion test for pack_incomplete; 45105/18911. Task 18: hosted_setting.go (SetHostedChecks, hostedChecks, HostedSettings; owner only, roster in the transaction, audited) and its tests; 45208/19070. Its review round 1: the audit atomicity test; 45208/19113. Task 19: hosted_jobs.go (the hosted_jobs and hosted_challenges tables, HostedJob and its lifecycle: newHostedJob, the listed moves only, ended and failed only with stop proof or never-launched evidence, settleHostedJob once, hostedJobForRunner; each move audited in its transaction) and its tests, TestMigrationAdditive included; 45658/19577. Its review round 1: the never-launched evidence contract (HostedNeverLaunched, launch_by and launching_since, hostedLaunchReturned) and tests for it, settlement of unproven terminal records and audit atomicity; 45728/19739. Task 20: hosted_limits.go (per-person hosted limits, S2-9: hostedAdmit held in the write by a per-person lock row, hostedHoldFor, Allocate, hostedSettle at 4x the baseline, SetHostedLimits owner only with the roster, revision and audit in the transaction) and its tests; 46013/20214. Its coordinator ruling: a limit counts only while its setting owner is a current owner (defaults otherwise, checked in the admission transaction) and TestOwnerRaisesLimitRevoked; 46022/20284. Its review round 1: Allocate returns nothing for an empty or reversed span before widening, and its assertions; 46025/20290. Hosted slice 2 Task 21: placement on hosted VMs (placeHosted before the checks early return, its five rules), the bound runner's fits, Authorize by job identity, the hosted offline rule and withdrawal exemption, the hosted pack at dispatch, the step-terminal hook, and the dispatcher's store methods (HostedLive, HostedSweep, HostedLaunching with relaunch, HostedLaunched, HostedAdmitted, HostedFailed, HostedStopped, HostedNeverLaunched, HostedReplaces, PlaceHosted; end, settle, revoke, step moved on) in hosted_run.go, and hosted_place_test.go; 46665/20804. Task 21 review round 1: abandoned-intent evidence waits for the job's lifetime, the job keeps its lifetime and first running sight, admission takes the placing transaction's step attempt, provider-valid attempt IDs, HostedRunning, and the Retry, replacement-runner, cancelled-task and stopping-VM tests; 46709/20937. Its review round 2: TestHostedReplacesNeedsProof; 46709/20971. Task 22: hosted_enrol.go (the enrolment and renewal store steps inside the instance's write transaction: HostedClaimCode, HostedEnrolAdmit, HostedEnrolBind, HostedRunnerJob, HostedNewChallenge, HostedUseChallenge; hostedAdmitted shared with HostedAdmitted); its tests drive it through the instance's routes (internal/equipo); 46848/20971. Its review round 1: hostedAdmitted reports whether the record was kept, the enrolment records the first sighting and applies the window from it, and the launch view's deadline is kept (hosted_jobs.deadline, earliest wins); 46903/20971. Its review round 2: an admission record's current deadline is kept too (hostedAdmitted, for the dispatcher's refresh and the renewal's HostedRenewAdmit); 46932/20971. Round 3: HostedEnrolAdmit returns the job re-read after recording the admission, so the enrolment caps by its deadline; 46937/20971. Task 23: openHostedPack opens the deps bundle after the hosted pack (send_pack with Deps), the instance's chunk and byte checks per kind (wire.MaxChunks, wire.MaxBytes), deps_too_large for a bundle past its limit, and a hosted attempt's pack and bundle closed when its checks end; hosted_deps_test.go; 46957/21199. Task 24: hosted_results.go (hostedCertified, AdmissionFresh: a hosted worker's checks count as sandboxed and its base checks as trusted only through the job's fresh, valid admission record, never its hello; an uncertified hosted result is not kept, its job stops and the step goes again once; deps_new_module and deps_missing presented as needs_network), stepReport and acceptBaseChecks wired to it, the admission kept whole and the enrolment image (0129), and hosted_results_test.go; 47094/21522. Task 24 review round 1: the certification decision moved before any terminal checks report from a worker (done, failed, unsolicited cancelled, the early failure branches), the person's cancellation kept, and tests for those, a wrong step, a stopping job and each admission identity substitution; 47096/21714. Task 24 review round 2: hostedSettleCancel (under the person's cancellation or an ended task, an uncertified hosted runner's report settles only its termination, with no checks evidence, taint or retry) and TestHostedUncertifiedCancelRace; 47123/21758. Task 25: HostedUsage (a person's running jobs and this UTC day's and month's held or used figures, errors returned) and HostedLimitList (owner only, the roster in the transaction) in usage.go, with hostedCounted shared with hostedAdmit; 47210/21758. |
| perf GET /api/v1/questions/{id} skip Thin v1 person API: bearer-only JSON for devices; the browser reads questions on /tasks/{id}. |
| perf GET /api/v1/steps/{id}/log skip Thin v1 person API: bearer-only JSON for devices; the browser shows the log tail on /tasks/{id}. |
| perf GET /api/v1/connections/preference skip Connections slice 1 person API: bearer-only JSON for devices; the browser shows the preference on /conversation/connections. |
diff --git a/docs/superpowers/plans/2026-11-30-hosted-slice-2-copy.json b/docs/superpowers/plans/2026-11-30-hosted-slice-2-copy.json| index 6bd448b5..62775d27 100644 |
| --- a/docs/superpowers/plans/2026-11-30-hosted-slice-2-copy.json |
| +++ b/docs/superpowers/plans/2026-11-30-hosted-slice-2-copy.json |
| @@ -89,5 +89,138 @@ |
| "draft": "a hosted machine could not be started", |
| "paul_sees": true, |
| "reviewed": "" |
| + }, |
| + { |
| + "key": "hosted.limits", |
| + "where": "Settings, hosted checks section (owners only, EQUIPO_HOSTED_RUNNERS=1): heading of the per-person limits editor (Task 25)", |
| + "draft": "Limits for each person", |
| + "paul_sees": true, |
| + "reviewed": "" |
| + }, |
| + { |
| + "key": "hosted.limits_help", |
| + "where": "Settings, hosted checks section: the line under the per-person limits heading (Task 25)", |
| + "draft": "What each person’s hosted checks may use. Days and months follow UTC, and spend is estimated at four times the base price.", |
| + "paul_sees": true, |
| + "reviewed": "" |
| + }, |
| + { |
| + "key": "hosted.limits.running", |
| + "where": "Settings, hosted checks section, one person's limits: the field for hosted machines running at once (Task 25)", |
| + "draft": "Machines at once", |
| + "paul_sees": true, |
| + "reviewed": "" |
| + }, |
| + { |
| + "key": "hosted.limits.hours", |
| + "where": "Settings, hosted checks section, one person's limits: the field for VM hours a UTC day (Task 25)", |
| + "draft": "VM hours a day", |
| + "paul_sees": true, |
| + "reviewed": "" |
| + }, |
| + { |
| + "key": "hosted.limits.spend", |
| + "where": "Settings, hosted checks section, one person's limits: the field for estimated spend a UTC month in US dollars (Task 25)", |
| + "draft": "Estimated spend a month, in US dollars", |
| + "paul_sees": true, |
| + "reviewed": "" |
| + }, |
| + { |
| + "key": "work.checks.waiting_hosted", |
| + "where": "Task view, checks line and timeline: a checks step waits for its hosted machine (or for its primary to be online) (Task 25)", |
| + "draft": "Waiting for a hosted machine to run the checks", |
| + "paul_sees": true, |
| + "reviewed": "" |
| + }, |
| + { |
| + "key": "work.checks.hosted_limit_running", |
| + "where": "Task view, checks line and timeline: a checks step waits because the person's limit on hosted machines running at once is reached; it frees when a running machine stops (Task 25)", |
| + "draft": "Waiting: the limit on hosted machines running at once is reached. The checks start when one of them stops", |
| + "paul_sees": true, |
| + "reviewed": "" |
| + }, |
| + { |
| + "key": "work.checks.hosted_limit_daily", |
| + "where": "Task view, checks line and timeline: a checks step waits because the person's VM hours for this UTC day are used up; it frees at the next UTC midnight (Task 25)", |
| + "draft": "Waiting: today’s hosted machine hours are used up. The checks can start after midnight UTC", |
| + "paul_sees": true, |
| + "reviewed": "" |
| + }, |
| + { |
| + "key": "work.checks.hosted_limit_monthly", |
| + "where": "Task view, checks line and timeline: a checks step waits because the person's estimated spend limit for this UTC month is reached; it frees at the start of the next UTC month (Task 25)", |
| + "draft": "Waiting: this month’s hosted machine spend limit is reached. The checks can start when the next month begins, at midnight UTC", |
| + "paul_sees": true, |
| + "reviewed": "" |
| + }, |
| + { |
| + "key": "work.checks.hosted_reason", |
| + "where": "Task view, checks line and step result: checks a hosted machine could not run; %s is one of the hosted work.reason words (Task 25)", |
| + "draft": "Checks did not run: %s", |
| + "paul_sees": true, |
| + "reviewed": "" |
| + }, |
| + { |
| + "key": "usage.hosted", |
| + "where": "Usage page, EQUIPO_HOSTED_RUNNERS=1 only: heading of the hosted machines block (Task 25)", |
| + "draft": "Hosted machines", |
| + "paul_sees": true, |
| + "reviewed": "" |
| + }, |
| + { |
| + "key": "usage.hosted.running", |
| + "where": "Usage page, hosted machines block: label for the person's machines running now (Task 25)", |
| + "draft": "Running now", |
| + "paul_sees": true, |
| + "reviewed": "" |
| + }, |
| + { |
| + "key": "usage.hosted.running_value", |
| + "where": "Usage page, hosted machines block: machines running now of the person's limit, for example 1 of 2 (Task 25)", |
| + "draft": "%d of %d allowed at once", |
| + "paul_sees": true, |
| + "reviewed": "" |
| + }, |
| + { |
| + "key": "usage.hosted.hours", |
| + "where": "Usage page, hosted machines block: label for VM hours this UTC day (Task 25)", |
| + "draft": "VM hours today", |
| + "paul_sees": true, |
| + "reviewed": "" |
| + }, |
| + { |
| + "key": "usage.hosted.hours_value", |
| + "where": "Usage page, hosted machines block: VM hours today (held or used, so at most) of the person's daily limit, for example At most 4 of 8 hours allowed (Task 25)", |
| + "draft": "At most %s of %s hours allowed", |
| + "paul_sees": true, |
| + "reviewed": "" |
| + }, |
| + { |
| + "key": "usage.hosted.spend", |
| + "where": "Usage page, hosted machines block: label for the estimated spend this UTC month (Task 25)", |
| + "draft": "Estimated spend this month", |
| + "paul_sees": true, |
| + "reviewed": "" |
| + }, |
| + { |
| + "key": "usage.hosted.spend_value", |
| + "where": "Usage page, hosted machines block: estimated spend this month (at four times the baseline, so at most) of the person's monthly limit, for example At most $4.96 of $50 allowed (Task 25)", |
| + "draft": "At most %s of %s allowed", |
| + "paul_sees": true, |
| + "reviewed": "" |
| + }, |
| + { |
| + "key": "usage.hosted.note", |
| + "where": "Usage page, hosted machines block: the note under the figures saying they are estimates and how they are counted (Task 25)", |
| + "draft": "These are estimates. Each machine counts at four times its base price, the most it can be billed, so the real cost is usually lower. Days and months follow UTC.", |
| + "paul_sees": true, |
| + "reviewed": "" |
| + }, |
| + { |
| + "key": "usage.hosted.unknown", |
| + "where": "Usage page, hosted machines block: shown in place of a figure that could not be read; never a zero (Task 25)", |
| + "draft": "Unknown", |
| + "paul_sees": true, |
| + "reviewed": "" |
| } |
| ] |
diff --git a/docs/superpowers/plans/CONTROLLER-REPORT-plan-3.md b/docs/superpowers/plans/CONTROLLER-REPORT-plan-3.md| index 15cf4e0a..bb20e500 100644 |
| --- a/docs/superpowers/plans/CONTROLLER-REPORT-plan-3.md |
| +++ b/docs/superpowers/plans/CONTROLLER-REPORT-plan-3.md |
| @@ -7232,6 +7232,25 @@ records remain unchanged. |
| | `work.reason.hosted_enrol_timeout` | the hosted machine did not connect in time | Copy specialist | COPY REVIEW PENDING | |
| | `work.reason.hosted_vm_lost` | the hosted machine stopped before the checks finished | Copy specialist | COPY REVIEW PENDING | |
| | `work.reason.hosted_unavailable` | a hosted machine could not be started | Copy specialist | COPY REVIEW PENDING | |
| +| `hosted.limits` | Limits for each person | Copy specialist | COPY REVIEW PENDING | |
| +| `hosted.limits_help` | What each person’s hosted checks may use. Days and months follow UTC, and spend is estimated at four times the base price. | Copy specialist | COPY REVIEW PENDING | |
| +| `hosted.limits.running` | Machines at once | Copy specialist | COPY REVIEW PENDING | |
| +| `hosted.limits.hours` | VM hours a day | Copy specialist | COPY REVIEW PENDING | |
| +| `hosted.limits.spend` | Estimated spend a month, in US dollars | Copy specialist | COPY REVIEW PENDING | |
| +| `work.checks.waiting_hosted` | Waiting for a hosted machine to run the checks | Copy specialist | COPY REVIEW PENDING | |
| +| `work.checks.hosted_limit_running` | Waiting: the limit on hosted machines running at once is reached. The checks start when one of them stops | Copy specialist | COPY REVIEW PENDING | |
| +| `work.checks.hosted_limit_daily` | Waiting: today’s hosted machine hours are used up. The checks can start after midnight UTC | Copy specialist | COPY REVIEW PENDING | |
| +| `work.checks.hosted_limit_monthly` | Waiting: this month’s hosted machine spend limit is reached. The checks can start when the next month begins, at midnight UTC | Copy specialist | COPY REVIEW PENDING | |
| +| `work.checks.hosted_reason` | Checks did not run: %s | Copy specialist | COPY REVIEW PENDING | |
| +| `usage.hosted` | Hosted machines | Copy specialist | COPY REVIEW PENDING | |
| +| `usage.hosted.running` | Running now | Copy specialist | COPY REVIEW PENDING | |
| +| `usage.hosted.running_value` | %d of %d allowed at once | Copy specialist | COPY REVIEW PENDING | |
| +| `usage.hosted.hours` | VM hours today | Copy specialist | COPY REVIEW PENDING | |
| +| `usage.hosted.hours_value` | At most %s of %s hours allowed | Copy specialist | COPY REVIEW PENDING | |
| +| `usage.hosted.spend` | Estimated spend this month | Copy specialist | COPY REVIEW PENDING | |
| +| `usage.hosted.spend_value` | At most %s of %s allowed | Copy specialist | COPY REVIEW PENDING | |
| +| `usage.hosted.note` | These are estimates. Each machine counts at four times its base price, the most it can be billed, so the real cost is usually lower. Days and months follow UTC. | Copy specialist | COPY REVIEW PENDING | |
| +| `usage.hosted.unknown` | Unknown | Copy specialist | COPY REVIEW PENDING | |
| ## Task 21 |
diff --git a/docs/superpowers/plans/HOSTED-SLICE2-PROGRESS.md b/docs/superpowers/plans/HOSTED-SLICE2-PROGRESS.md| index c56181e1..4a98cc39 100644 |
| --- a/docs/superpowers/plans/HOSTED-SLICE2-PROGRESS.md |
| +++ b/docs/superpowers/plans/HOSTED-SLICE2-PROGRESS.md |
| @@ -1978,3 +1978,67 @@ Mutations. A script under `~/.cache/t24r2` applied each exact-string replace and |
| The field-clearing line inside `hostedSettleCancel` has no mutation of its own. A step that has not ended carries none of those fields, and the report's fields are never copied onto it. The settle path is the guard, and 367 removes it. |
| Budget: `internal/equipo/chat` 47096/21714 → 47123/21758, with its reason. |
| + |
| +## Task 25 |
| + |
| +What the person sees: hosted waits, limits, reasons and usage. |
| + |
| +- **Task view chips** (`work_pages.go`, `work_views.go`). `hostedWaitLine(step)` gives a checks step's wait. `waiting_hosted` shows `work.checks.waiting_hosted`. `hosted_limit` with `running`, `daily` or `monthly` shows `work.checks.hosted_limit_<reason>`, which names the limit and when it frees: when a running machine stops, after midnight UTC, or when the next UTC month begins. A limit wait with any other reason shows the plain hosted wait. The line is the task page's checks line, replacing "Running checks…", and the headline under the waiting step on the timeline. Teammates see the same. |
| +- **Reason words.** `hostedReasons` lists pack_incomplete, deps_conflict, deps_new_module, deps_missing, deps_too_large, token_renewal_failed, hosted_enrol_timeout, hosted_vm_lost and hosted_unavailable. For these, `checksLine` (`cannot_run`) says `work.checks.hosted_reason` ("Checks did not run: %s") with the reason's `work.reason` words, on the step's result and the task's checks line. The merge decision (`decisionOf`, NeedsMerge) says the same words. Task 24's presentation is kept: deps_new_module and deps_missing show as `needs_network` on the task's badge and decision. The step and the checks line, which read the step's own reason, show the dependency words. All nine `work.reason` keys already existed (pending), so none was added. |
| +- **Usage page.** `chat.HostedUsage(ctx, person)` (in `chat/usage.go`) reads, in one transaction: `CurrentPerson`, the person's limits (`hostedLimits`, a revoked setter's row giving the defaults), and `hostedCounted(person, now)`. `hostedCounted` was split out of `hostedAdmit` and is unchanged: a job that has not ended or failed counts as running; per UTC day and month, a settled job counts what it used and any other job its hold. The result is the jobs running now, the seconds for this UTC day and the micros for this UTC month. Any error is returned with a zero value, never as figures. The page (`usage_page.go`, `usage.html`) shows the "Hosted machines" block only with `EQUIPO_HOSTED_RUNNERS=1`: running now of the limit, VM hours today ("At most …", one decimal place) of the daily limit, and estimated spend this month ("At most …", `chat.Money`) of the monthly limit, with the note that these are estimates at four times the base price. On a read error, all three figures say `usage.hosted.unknown` ("Unknown") and the error is logged (`hosted_usage_unknown`). The rest of the page still renders. |
| +- **Owner's limit editor** (Task 18's section). `chat.HostedLimitList(ctx, owner, people)` checks `CurrentPerson`, then `isOwner` in the transaction. For each listed address it checks `Me`: someone no longer a current member (ErrForbidden) is left out, and any other error is returned. Each remaining person gets their limits and revision. The hosted settings page passes the active members' addresses and renders one form per person (`hosted_settings.html`): machines at once, VM hours a day and estimated spend a month in US dollars, with the revision as a hidden field. `POST /settings/hosted/limits` exists only with the flag (`hostedRoutes`). It parses the figures with `parseHostedLimits`, which takes a whole number of machines, hours and dollars that are not negative, not NaN and within bounds, and rounds them to seconds and micros. It then calls `SetHostedLimits` (Task 20: owner, roster, revision and audit in its transaction) with the session's address. |
| +- **Copy.** Nineteen new keys in `copy.go`, in their own group before `work.reason.preview_headers`, so no other line is realigned: `hosted.limits`, `hosted.limits_help`, `hosted.limits.running`, `hosted.limits.hours`, `hosted.limits.spend`, `work.checks.waiting_hosted`, `work.checks.hosted_limit_running`, `_daily`, `_monthly`, `work.checks.hosted_reason`, `usage.hosted`, `usage.hosted.running`, `.running_value`, `.hours`, `.hours_value`, `.spend`, `.spend_value`, `.note`, `.unknown`. They are marked with `python3 scripts/copy-status.py pending` (stdin `{"candidate": <worktree>, "keys": [the nineteen]}`; the inventory rows in `CONTROLLER-REPORT-plan-3.md` say COPY REVIEW PENDING) and listed with where they appear in `2026-11-30-hosted-slice-2-copy.json`. None is accepted. They use plain words, with no em dashes and no exclamation marks. |
| +- `TestHostedSettingHiddenWithoutFlag` now expects the third route. |
| + |
| +Red: |
| +1. With only the test file: `CGO_ENABLED=0 go test ./internal/equipo -run 'TestWaitingHosted|TestLimitChip|TestUsageShowsHosted|TestUsageUnknown|TestHostedLimitEditor' -count=1` failed to build (`s.Chat().HostedUsage undefined`, `unknown field Hosted in struct literal of type usageView`, `undefined: hostedUsageOf`, `s.Chat().HostedLimitList undefined`). |
| +2. With stubs (the types, zero-value functions, no keys), the same command failed on its assertions: |
| + - `hosted_views_test.go:51: work.checks.waiting_hosted has no words` |
| + - `hosted_views_test.go:80: work.checks.hosted_limit_running has no words` |
| + - `hosted_views_test.go:116: pack_incomplete: step result "Checks can't run on this runner", want "%!(EXTRA string=the hosted machine did not receive both commits it needed)"` |
| + - `hosted_views_test.go:202: usage {Limits:{Running:0 DailySeconds:0 MonthlyMicros:0} Running:0 DaySeconds:0 MonthMicros:0}` |
| + - `hosted_views_test.go:256: jobs: totals read with no error: {...}` |
| + - `hosted_views_test.go:285: owner's list [] <nil>` |
| + |
| +Tests (`internal/equipo/hosted_views_test.go`): |
| +- `TestWaitingHostedChip`: `waiting_hosted`, and `hosted_limit` with no reason or an unknown one. Checks line and timeline, for the creator and a teammate. |
| +- `TestLimitChipSaysWhich`: each limit's own words, distinct from each other and from the plain wait, on the checks line and the timeline. |
| +- `TestWaitingHostedReasons`: all nine reasons on the step result, the checks line and the merge decision. The decision says needs_network for the two dependency reasons Task 24 presents that way. |
| +- `TestUsageShowsHostedTotals`: production wiring (`NewStore`, `Bootstrap`, chat clock at 2026-12-01 12:00 UTC). Five job rows: |
| + - live (hold counts); |
| + - settled today (used counts, not hold); |
| + - failed across midnight without proof (today's part of the hold counts); |
| + - November's settled job (left out); |
| + - another person's (left out). |
| + |
| + Expected: 1 running, 14,400 s and 4,960,001 micros against the defaults. The rendered block reads "1 of 2", "At most 4 of 8 hours", "At most $4.96 of $50" and the note, and no "Unknown". An owner raises the limits to 3, 10 h and $75.50, and the page follows. Without the block, nothing shows. |
| +- `TestUsageUnknownStaysUnknown`: the jobs table renamed, the limits table renamed, or an unreadable hold. The store returns an error, the page shows exactly three "Unknown" figures, and no "$0", "0 of 0" or "0 of 0 hours". |
| +- `TestHostedLimitEditor`: the owner's list leaves out a person not on the roster and has the defaults at revision 0 and B's row at revision 1. The form fields render (`hours` 1.5 and 8, `dollars` 75.50 and 50.00). `parseHostedLimits` gives 4, 5,400 s and 75,500,000 micros, and refuses blanks, negatives, NaN, Inf, 1e300, words and a fractional machine count. A demoted member is refused `ErrForbidden`, and a lookup error is returned, not read as limits. |
| + |
| +Green: the brief's command, `CGO_ENABLED=0 go test ./internal/equipo -run 'TestWaitingHosted|TestLimitChip|TestUsageShowsHosted|TestUsageUnknown' -count=1`: ok (5 tests pass). These were also ok: |
| +- `TestHostedLimitEditor` and `TestHostedSetting*`; |
| +- the whole `./internal/equipo` once (87 s on a loaded docs-t1); |
| +- `./internal/equipo/chat -run 'TestLimits|TestHoldSpans|TestDelayedLaunch|TestSettleStays|TestNoProofKeepsHold|TestLimitCount|TestOwnerRaises|TestHosted'` (Task 20's limit tests over the `hostedCounted` split); |
| +- `./internal/equipo/hostedrun` (22 s); |
| +- `./internal/thintest -run 'Settings|Usage|Copy|Rail'`. |
| + |
| +`make budget build vet`: exit 0 after the records were raised. gofmt and `git diff --check`: clean. staticcheck v0.7.0 on `./internal/equipo` and `./internal/equipo/chat` reports only `preview_frames_fixture_test.go:5:7: const previewFramesFixture is unused (U1000)`, which predates this task. `python3 scripts/copy-status.py verify` (stdin `{"candidate": <worktree>}`) gives `{"valid": false}`, by design: these keys and the earlier tasks' keys are pending. |
| + |
| +Mutations. Each was an exact-string replace by a script under `mktemp -d` in `$TMPDIR`, one at a time. The named test was run, the file was restored from a copy, and `filecmp` compared it: identical each time. |
| +- **369** (brief) a failed total rendered as 0. In `hostedUsageOf`, `if err != nil {` became `if false && err != nil {`. `CGO_ENABLED=0 go test ./internal/equipo -run TestUsageUnknownStaysUnknown -count=1`: exit 1, `hosted_views_test.go:261: jobs: want three unknown figures in` (the page showed "0 of 0 allowed at once"). Restored. |
| +- **370** (brief, store side) the jobs read error read as zero. In `HostedUsage`, the `hostedCounted` error check became `if false && err != nil {`. Same command: exit 1, `hosted_views_test.go:256: jobs: totals read with no error: {Limits:{Running:2 DailySeconds:28800 MonthlyMicros:50000000} Running:0 DaySeconds:0 MonthMicros:0}`. Restored. |
| +- **371** the limits read error read as the defaults (`return err` became `limits = DefaultHostedLimits`). Same command: exit 1, `hosted_views_test.go:256: limits: totals read with no error: {Limits:{Running:2 ...} Running:1 DaySeconds:6000 MonthMicros:2066667}`. Restored. |
| +- **372** no hosted wait on the checks line (`w != ""` became `w != "" && false` in `taskLineOf`). `-run TestWaitingHostedChip`: exit 1, `hosted_views_test.go:62: waiting_hosted "" for owner@example.com: checks line "Running checks…", want "Waiting for a hosted machine to run the checks"`. Restored. |
| +- **373** a limit wait does not say which (the limit case became `case "never":`). `-run TestLimitChipSaysWhich`: exit 1, `hosted_views_test.go:89: running: checks line "Waiting for a hosted machine to run the checks", want "Waiting: the limit on hosted machines running at once is reached. …"`. Restored. |
| +- **374** no hosted wait on the timeline (in `timelineOf`). `-run 'TestWaitingHostedChip|TestLimitChipSaysWhich'`: exit 1, `hosted_views_test.go:65: waiting_hosted "" for owner@example.com: timeline "", want …` and `hosted_views_test.go:92: running: timeline "", want …`. Restored. |
| +- **375** a settled job counts its hold (`if j.SettledAt != nil {` became `if false && j.SettledAt != nil {` in `hostedCounted`). `-run TestUsageShowsHostedTotals`: exit 1, `hosted_views_test.go:202: usage {... Running:1 DaySeconds:18000 MonthMicros:6200001}`. Restored. |
| +- **376** the limit editor without its owner check (the `isOwner` block removed from `HostedLimitList`). `-run TestHostedLimitEditor`: exit 1, `hosted_views_test.go:320: a member's list: <nil>`. Restored. |
| +- **377** hosted reasons shown as the generic checks line (`false &&` before `hostedReasons[reason]` in `checksLine`). `-run TestWaitingHostedReasons`: exit 1, `hosted_views_test.go:116: pack_incomplete: step result "Checks can't run on this runner", want "Checks did not run: the hosted machine did not receive both commits it needed"`. Restored. |
| +- **378** the merge decision without the hosted reason (`false &&` in `decisionOf`). Same command: exit 1, `hosted_views_test.go:129: pack_incomplete: decision &{... Why:Review approved the change. Checks could not run here: this runner cannot run them. ...}, want "Review approved the change. Checks could not run here: the hosted machine did not receive both commits it needed."`. Restored. |
| +- **379** the limit list reads a lookup error as the defaults (`return err` became `l, revision = DefaultHostedLimits, 0`). `-run TestHostedLimitEditor`: exit 1, `hosted_views_test.go:326: a lookup error read as limits: [{Person:owner-a@example.com Limits:{Running:2 ...} Revision:0}]`. Restored. |
| + |
| +Not mutation-checked: |
| +- The Usage handler's flag gate and its log line. The block is built only when `a.hostedRunners` is set; `TestUsageShowsHostedTotals` checks only that a view without the block renders nothing. |
| +- The save handler `saveHostedLimits`. It adds no authority of its own: the session's address goes to `SetHostedLimits`, whose owner, roster and revision checks are Task 20's mutations 267 and 268. Its parsing is `parseHostedLimits`, which `TestHostedLimitEditor` tests. |
| + |
| +Budgets, each with its reason: `internal/equipo` 25304/8741 → 25478/9069; `internal/equipo/chat` 47123/21758 → 47210/21758. |
diff --git a/internal/equipo/chat/hosted_limits.go b/internal/equipo/chat/hosted_limits.go| index 027ba7e6..b3d5ecde 100644 |
| --- a/internal/equipo/chat/hosted_limits.go |
| +++ b/internal/equipo/chat/hosted_limits.go |
| @@ -180,13 +180,37 @@ func (t *txn) hostedAdmit(person string, size isolatedjob.Size, lifetime time.Du |
| if err != nil { |
| return false, "", err |
| } |
| + running, held, err := t.hostedCounted(person, now) |
| + if err != nil { |
| + return false, "", err |
| + } |
| + if running >= limits.Running { |
| + return false, HostedLimitRunning, nil |
| + } |
| + for day, s := range hold.Seconds { |
| + if held.Seconds[day]+s > limits.DailySeconds { |
| + return false, HostedLimitDaily, nil |
| + } |
| + } |
| + for m, v := range hold.Micros { |
| + if held.Micros[m]+v > limits.MonthlyMicros { |
| + return false, HostedLimitMonthly, nil |
| + } |
| + } |
| + return true, "", nil |
| +} |
| + |
| +// hostedCounted is what counts against person's limits at now: jobs not |
| +// ended or failed, and per UTC day and month a settled job's usage and |
| +// any other job's hold. A read or decode error is returned. |
| +func (t *txn) hostedCounted(person string, now time.Time) (int, HostedCharge, error) { |
| // A settled job's usage ends at its proof, so one that ended before |
| // this month cannot count against now's days or months; every live |
| // job is unsettled. |
| month := time.Date(now.UTC().Year(), now.UTC().Month(), 1, 0, 0, 0, 0, time.UTC) |
| var rows []HostedJob |
| if err := t.db.Where("person = ? AND (settled_at IS NULL OR ended_at >= ?)", person, month).Find(&rows).Error; err != nil { |
| - return false, "", err |
| + return 0, HostedCharge{}, err |
| } |
| running := 0 |
| held := HostedCharge{Seconds: map[string]int64{}, Micros: map[string]int64{}} |
| @@ -199,7 +223,7 @@ func (t *txn) hostedAdmit(person string, size isolatedjob.Size, lifetime time.Du |
| c, err = j.Used() |
| } |
| if err != nil { |
| - return false, "", err |
| + return 0, HostedCharge{}, err |
| } |
| for k, v := range c.Seconds { |
| held.Seconds[k] += v |
| @@ -208,20 +232,7 @@ func (t *txn) hostedAdmit(person string, size isolatedjob.Size, lifetime time.Du |
| held.Micros[k] += v |
| } |
| } |
| - if running >= limits.Running { |
| - return false, HostedLimitRunning, nil |
| - } |
| - for day, s := range hold.Seconds { |
| - if held.Seconds[day]+s > limits.DailySeconds { |
| - return false, HostedLimitDaily, nil |
| - } |
| - } |
| - for m, v := range hold.Micros { |
| - if held.Micros[m]+v > limits.MonthlyMicros { |
| - return false, HostedLimitMonthly, nil |
| - } |
| - } |
| - return true, "", nil |
| + return running, held, nil |
| } |
| // hostedSettle settles an ended or failed job that holds proof, once: the |
diff --git a/internal/equipo/chat/usage.go b/internal/equipo/chat/usage.go| index 580ff0a2..883756b6 100644 |
| --- a/internal/equipo/chat/usage.go |
| +++ b/internal/equipo/chat/usage.go |
| @@ -242,3 +242,79 @@ func (h *HTTP) adviceAction(w http.ResponseWriter, r *http.Request, p personapi. |
| } |
| writeJSON(w, 200, out) |
| } |
| + |
| +// HostedUsage is a person's hosted machines for the Usage page: their |
| +// limits, jobs running now, and what counts against this UTC day and |
| +// this UTC month, the same figures admission reads (a settled job what |
| +// it used, any other job its hold, at BurstHoldFactor times the |
| +// baseline). The day and month figures are the most it can have cost. |
| +type HostedUsage struct { |
| + Limits HostedLimits |
| + Running int |
| + DaySeconds int64 |
| + MonthMicros int64 // USD micros |
| +} |
| + |
| +// HostedUsage reads person's hosted usage at the store's now. Any read |
| +// error is returned: an unknown total is never a zero. |
| +func (s *Store) HostedUsage(ctx context.Context, person string) (out HostedUsage, err error) { |
| + now := s.now().UTC() |
| + err = s.tx(ctx, func(t *txn) error { |
| + if err := s.authority.CurrentPerson(ctx, t.db); err != nil { |
| + return err |
| + } |
| + limits, _, err := t.hostedLimits(person) |
| + if err != nil { |
| + return err |
| + } |
| + running, held, err := t.hostedCounted(person, now) |
| + if err != nil { |
| + return err |
| + } |
| + out = HostedUsage{Limits: limits, Running: running, DaySeconds: held.Seconds[now.Format(time.DateOnly)], MonthMicros: held.Micros[now.Format("2006-01")]} |
| + return nil |
| + }) |
| + if err != nil { |
| + return HostedUsage{}, err |
| + } |
| + return out, nil |
| +} |
| + |
| +// HostedLimitRow is one person's hosted limits in the owner's editor, at |
| +// the revision a save names. |
| +type HostedLimitRow struct { |
| + Person string |
| + Limits HostedLimits |
| + Revision int64 |
| +} |
| + |
| +// HostedLimitList is each of people's hosted limits, for an owner only |
| +// (the roster read in the transaction). Someone no longer a current |
| +// member is left out; any other lookup error is returned. |
| +func (s *Store) HostedLimitList(ctx context.Context, owner string, people []string) (out []HostedLimitRow, err error) { |
| + err = s.tx(ctx, func(t *txn) error { |
| + if err := s.authority.CurrentPerson(ctx, t.db); err != nil { |
| + return err |
| + } |
| + if err := t.isOwner(owner); err != nil { |
| + return err |
| + } |
| + for _, p := range people { |
| + if _, err := s.authority.Me(t.db, p); errors.Is(err, ErrForbidden) { |
| + continue |
| + } else if err != nil { |
| + return err |
| + } |
| + l, revision, err := t.hostedLimits(p) |
| + if err != nil { |
| + return err |
| + } |
| + out = append(out, HostedLimitRow{Person: p, Limits: l, Revision: revision}) |
| + } |
| + return nil |
| + }) |
| + if err != nil { |
| + return nil, err |
| + } |
| + return out, nil |
| +} |
diff --git a/internal/equipo/copy.go b/internal/equipo/copy.go| index 4548fca8..254220fe 100644 |
| --- a/internal/equipo/copy.go |
| +++ b/internal/equipo/copy.go |
| @@ -156,6 +156,27 @@ var pageCopy = map[string]string{ |
| "agent.equipo_task_get": "Read one task and its current details.", // COPY ACCEPTED BY DELEGATION (Luna, 2026-11-20) |
| "agent.equipo_needs_you": "Read this person's recent unfinished tasks with a decision.", // COPY ACCEPTED BY DELEGATION (Luna, 2026-11-20) |
| + // Hosted runners slice 2 Task 25: hosted waits, limits and usage. |
| + "hosted.limits": "Limits for each person", // COPY REVIEW PENDING |
| + "hosted.limits_help": "What each person’s hosted checks may use. Days and months follow UTC, and spend is estimated at four times the base price.", // COPY REVIEW PENDING |
| + "hosted.limits.running": "Machines at once", // COPY REVIEW PENDING |
| + "hosted.limits.hours": "VM hours a day", // COPY REVIEW PENDING |
| + "hosted.limits.spend": "Estimated spend a month, in US dollars", // COPY REVIEW PENDING |
| + "work.checks.waiting_hosted": "Waiting for a hosted machine to run the checks", // COPY REVIEW PENDING |
| + "work.checks.hosted_limit_running": "Waiting: the limit on hosted machines running at once is reached. The checks start when one of them stops", // COPY REVIEW PENDING |
| + "work.checks.hosted_limit_daily": "Waiting: today’s hosted machine hours are used up. The checks can start after midnight UTC", // COPY REVIEW PENDING |
| + "work.checks.hosted_limit_monthly": "Waiting: this month’s hosted machine spend limit is reached. The checks can start when the next month begins, at midnight UTC", // COPY REVIEW PENDING |
| + "work.checks.hosted_reason": "Checks did not run: %s", // COPY REVIEW PENDING |
| + "usage.hosted": "Hosted machines", // COPY REVIEW PENDING |
| + "usage.hosted.running": "Running now", // COPY REVIEW PENDING |
| + "usage.hosted.running_value": "%d of %d allowed at once", // COPY REVIEW PENDING |
| + "usage.hosted.hours": "VM hours today", // COPY REVIEW PENDING |
| + "usage.hosted.hours_value": "At most %s of %s hours allowed", // COPY REVIEW PENDING |
| + "usage.hosted.spend": "Estimated spend this month", // COPY REVIEW PENDING |
| + "usage.hosted.spend_value": "At most %s of %s allowed", // COPY REVIEW PENDING |
| + "usage.hosted.note": "These are estimates. Each machine counts at four times its base price, the most it can be billed, so the real cost is usually lower. Days and months follow UTC.", // COPY REVIEW PENDING |
| + "usage.hosted.unknown": "Unknown", // COPY REVIEW PENDING |
| + |
| "work.reason.preview_headers": "the preview host needs an update before it can apply the required security headers", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-19) |
| "autonomy.auto_merge_sensitive": "Auto-merge sensitive changes", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-19) |
| "autonomy.auto_merge_sensitive_help": "Allow changes to sensitive files to merge when trusted checks pass.", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-19) |
diff --git a/internal/equipo/hosted_settings.go b/internal/equipo/hosted_settings.go| index f23ceb0c..bb73c887 100644 |
| --- a/internal/equipo/hosted_settings.go |
| +++ b/internal/equipo/hosted_settings.go |
| @@ -2,6 +2,8 @@ package equipo |
| import ( |
| "context" |
| + "fmt" |
| + "math" |
| "net/http" |
| "strconv" |
| @@ -18,6 +20,7 @@ func (a *application) hostedRoutes(r chi.Router) { |
| } |
| r.Get("/conversation/settings/hosted", a.settingsSectionHandler("hosted")) |
| r.Post("/settings/hosted", a.saveHostedSetting) |
| + r.Post("/settings/hosted/limits", a.saveHostedLimits) |
| } |
| // hostedSection says whether the section may be served: the flag is on |
| @@ -44,3 +47,58 @@ func (a *application) saveHostedSetting(w http.ResponseWriter, r *http.Request) |
| return a.store.Chat().SetHostedChecks(ctx, person, r.FormValue("project"), r.FormValue("hosted_checks") == "on", revision) |
| }) |
| } |
| + |
| +// hostedLimitView is one person's row in the owner's limit editor: the |
| +// limits as the form shows them (hours a day, US dollars a month) and the |
| +// revision a save names. |
| +type hostedLimitView struct { |
| + Person, Running, Hours, Dollars string |
| + Revision int64 |
| +} |
| + |
| +func hostedLimitViews(rows []chat.HostedLimitRow) []hostedLimitView { |
| + var out []hostedLimitView |
| + for _, r := range rows { |
| + out = append(out, hostedLimitView{Person: r.Person, Running: strconv.Itoa(r.Limits.Running), Hours: hoursText(r.Limits.DailySeconds), Dollars: fmt.Sprintf("%.2f", float64(r.Limits.MonthlyMicros)/1e6), Revision: r.Revision}) |
| + } |
| + return out |
| +} |
| + |
| +// parseHostedLimits reads the editor's figures: a whole number of |
| +// machines, hours a day and US dollars a month, none negative, none past |
| +// what SetHostedLimits accepts once converted (it checks the bounds). |
| +func parseHostedLimits(running, hours, dollars string) (chat.HostedLimits, error) { |
| + n, err := strconv.Atoi(running) |
| + if err != nil || n < 0 { |
| + return chat.HostedLimits{}, chat.ErrInvalid |
| + } |
| + h, err := strconv.ParseFloat(hours, 64) |
| + if err != nil || math.IsNaN(h) || h < 0 || h > 1000*24 { |
| + return chat.HostedLimits{}, chat.ErrInvalid |
| + } |
| + d, err := strconv.ParseFloat(dollars, 64) |
| + if err != nil || math.IsNaN(d) || d < 0 || d > 1_000_000 { |
| + return chat.HostedLimits{}, chat.ErrInvalid |
| + } |
| + return chat.HostedLimits{Running: n, DailySeconds: int64(math.Round(h * 3600)), MonthlyMicros: int64(math.Round(d * 1e6))}, nil |
| +} |
| + |
| +// saveHostedLimits is the owner's save of one person's limits. |
| +// SetHostedLimits checks the owner, the person and the revision in its |
| +// transaction. |
| +func (a *application) saveHostedLimits(w http.ResponseWriter, r *http.Request) { |
| + a.chatActionTo(w, r, "/conversation/settings/hosted", func(ctx context.Context, owner string) error { |
| + if a.hostedSection(true) != nil { |
| + return chat.ErrForbidden |
| + } |
| + revision, err := strconv.ParseInt(r.FormValue("revision"), 10, 64) |
| + if err != nil || revision < 0 { |
| + return chat.ErrInvalid |
| + } |
| + l, err := parseHostedLimits(r.FormValue("running"), r.FormValue("hours"), r.FormValue("dollars")) |
| + if err != nil { |
| + return err |
| + } |
| + return a.store.Chat().SetHostedLimits(ctx, owner, r.FormValue("person"), l, revision) |
| + }) |
| +} |
diff --git a/internal/equipo/hosted_settings_test.go b/internal/equipo/hosted_settings_test.go| index 14ff4134..72b3c495 100644 |
| --- a/internal/equipo/hosted_settings_test.go |
| +++ b/internal/equipo/hosted_settings_test.go |
| @@ -72,7 +72,7 @@ func TestHostedSettingHiddenWithoutFlag(t *testing.T) { |
| t.Fatal("page served without the flag") |
| } |
| on := &application{store: &Store{}, hostedRunners: true} |
| - if got := strings.Join(hostedRoutesOf(t, on), ","); got != "GET /conversation/settings/hosted,POST /settings/hosted" { |
| + if got := strings.Join(hostedRoutesOf(t, on), ","); got != "GET /conversation/settings/hosted,POST /settings/hosted,POST /settings/hosted/limits" { |
| t.Fatalf("routes with the flag: %s", got) |
| } |
| if !on.settingsShown(hosted, true) || on.settingsShown(hosted, false) { |
diff --git a/internal/equipo/hosted_views_test.go b/internal/equipo/hosted_views_test.go| new file mode 100644 |
| index 00000000..3b1355c3 |
| --- /dev/null |
| +++ b/internal/equipo/hosted_views_test.go |
| @@ -0,0 +1,328 @@ |
| +package equipo |
| + |
| +import ( |
| + "bytes" |
| + "context" |
| + "errors" |
| + "fmt" |
| + "io" |
| + "log/slog" |
| + "strings" |
| + "testing" |
| + "time" |
| + |
| + "amadan.net/oficina/equipo/internal/equipo/chat" |
| + "amadan.net/oficina/equipo/internal/equipo/personapi" |
| + "amadan.net/oficina/equipo/internal/wire" |
| + "amadan.net/rastrillo/rastrillo/db" |
| + "amadan.net/rastrillo/rastrillo/dbtest" |
| +) |
| + |
| +const hostedCreator = "owner@example.com" |
| + |
| +// hostedTask is a task whose Engineering is done and whose checks step |
| +// is s. |
| +func hostedTask(s wire.Step) wire.Task { |
| + return wire.Task{ID: "t1", Creator: hostedCreator, Stage: wire.StageInProgress, CandidateSHA: "c1", Steps: []wire.Step{ |
| + {ID: "s0", Specialist: wire.SpecialistEngineering, State: wire.StepDone, Attempt: 1, CandidateSHA: "c1"}, |
| + s, |
| + }} |
| +} |
| + |
| +// queuedHeadline is the timeline's line under the waiting step. |
| +func queuedHeadline(t *testing.T, task wire.Task, v taskLine) string { |
| + t.Helper() |
| + for _, it := range timelineOf(task, v) { |
| + if it.Kind == "queued" { |
| + return it.Headline |
| + } |
| + } |
| + t.Fatal("no waiting step on the timeline") |
| + return "" |
| +} |
| + |
| +// TestWaitingHostedChip: checks waiting for a hosted machine say so on |
| +// the task page and its timeline, for the creator and for teammates, |
| +// never "Running checks". A limit wait without a known limit reads as |
| +// the plain hosted wait. |
| +func TestWaitingHostedChip(t *testing.T) { |
| + want := copyText("work.checks.waiting_hosted") |
| + if want == "" { |
| + t.Fatal("work.checks.waiting_hosted has no words") |
| + } |
| + for _, c := range []struct{ placement, reason string }{ |
| + {wire.PlacementHosted, ""}, |
| + {wire.PlacementHostedLimit, ""}, |
| + {wire.PlacementHostedLimit, "unheard_of"}, |
| + } { |
| + task := hostedTask(wire.Step{ID: "s1", Specialist: wire.SpecialistChecks, State: wire.StepQueued, Placement: c.placement, Reason: c.reason, Attempt: 1, CandidateSHA: "c1"}) |
| + for _, viewer := range []string{hostedCreator, "other@example.com"} { |
| + v := taskLineOf(task, viewer) |
| + if v.ChecksLine != want { |
| + t.Fatalf("%s %q for %s: checks line %q, want %q", c.placement, c.reason, viewer, v.ChecksLine, want) |
| + } |
| + if h := queuedHeadline(t, task, v); h != want { |
| + t.Fatalf("%s %q for %s: timeline %q, want %q", c.placement, c.reason, viewer, h, want) |
| + } |
| + } |
| + } |
| +} |
| + |
| +// TestLimitChipSaysWhich: a step held by a hosted limit names the limit |
| +// (machines at once, today's hours, this month's spend) and when it |
| +// frees, each in its own words, on the task page and its timeline. |
| +func TestLimitChipSaysWhich(t *testing.T) { |
| + seen := map[string]string{copyText("work.checks.waiting_hosted"): "waiting_hosted"} |
| + for _, reason := range []string{chat.HostedLimitRunning, chat.HostedLimitDaily, chat.HostedLimitMonthly} { |
| + key := "work.checks.hosted_limit_" + reason |
| + want := copyText(key) |
| + if want == "" { |
| + t.Fatalf("%s has no words", key) |
| + } |
| + if other, dup := seen[want]; dup { |
| + t.Fatalf("%s says the same as %s: %q", key, other, want) |
| + } |
| + seen[want] = key |
| + task := hostedTask(wire.Step{ID: "s1", Specialist: wire.SpecialistChecks, State: wire.StepQueued, Placement: wire.PlacementHostedLimit, Reason: reason, Attempt: 1, CandidateSHA: "c1"}) |
| + v := taskLineOf(task, hostedCreator) |
| + if v.ChecksLine != want { |
| + t.Fatalf("%s: checks line %q, want %q", reason, v.ChecksLine, want) |
| + } |
| + if h := queuedHeadline(t, task, v); h != want { |
| + t.Fatalf("%s: timeline %q, want %q", reason, h, want) |
| + } |
| + } |
| +} |
| + |
| +// TestWaitingHostedReasons: checks a hosted machine could not run say why |
| +// in the reason's own words: the step's result, the task's checks line |
| +// and the merge decision. A new or missing module still shows as needing |
| +// the network on the task (Task 24), and its step keeps its own words. |
| +func TestWaitingHostedReasons(t *testing.T) { |
| + for _, r := range []string{wire.ReasonPackIncomplete, wire.ReasonDepsConflict, wire.ReasonDepsNewModule, wire.ReasonDepsMissing, wire.ReasonDepsTooLarge, wire.ReasonTokenRenewalFailed, wire.ReasonHostedEnrolTimeout, wire.ReasonHostedVMLost, wire.ReasonHostedUnavailable} { |
| + words := copyText("work.reason." + r) |
| + if words == "" { |
| + t.Fatalf("%s has no words", r) |
| + } |
| + line := fmt.Sprintf(copyText("work.checks.hosted_reason"), words) |
| + presented := r |
| + if r == wire.ReasonDepsNewModule || r == wire.ReasonDepsMissing { |
| + presented = "needs_network" |
| + } |
| + task := hostedTask(wire.Step{ID: "s1", Specialist: wire.SpecialistChecks, State: wire.StepDone, Checks: wire.ChecksCannotRun, Reason: r, Attempt: 1, CandidateSHA: "c1"}) |
| + task.Checks, task.ChecksReason = wire.ChecksCannotRun, presented |
| + v := taskLineOf(task, hostedCreator) |
| + if got := v.Steps[1].Result; got != line { |
| + t.Fatalf("%s: step result %q, want %q", r, got, line) |
| + } |
| + if v.ChecksLine != line { |
| + t.Fatalf("%s: checks line %q, want %q", r, v.ChecksLine, line) |
| + } |
| + task.Stage, task.NeedsYou = wire.StageReadyToMerge, wire.NeedsMerge |
| + v = taskLineOf(task, hostedCreator) |
| + v.Card = &wire.Card{Options: []string{wire.ChoiceMerge}} |
| + why := fmt.Sprintf(copyText("work.decide.unchecked_why"), copyText("work.decide.reason.needs_network")) |
| + if presented == r { |
| + why = fmt.Sprintf(copyText("work.decide.unchecked_why"), words) |
| + } |
| + if d := decisionOf(task, v); d == nil || d.Why != why { |
| + t.Fatalf("%s: decision %+v, want %q", r, d, why) |
| + } |
| + } |
| +} |
| + |
| +// hostedStore is the instance's store with its production chat authority, |
| +// two owners, and the chat clock at now. |
| +func hostedStore(t *testing.T, now time.Time) (*Store, *db.DB) { |
| + t.Helper() |
| + schema := dbtest.FromSet(BootSchema) |
| + t.Cleanup(schema.Remove) |
| + d, err := db.Open(schema.Path(t), slog.New(slog.NewTextHandler(io.Discard, nil))) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + t.Cleanup(func() { d.Close() }) |
| + s := NewStore(d) |
| + if err := s.Bootstrap(context.Background(), []string{"owner-a@example.com", "owner-b@example.com"}); err != nil { |
| + t.Fatal(err) |
| + } |
| + s.Chat().SetClock(func() time.Time { return now }) |
| + return s, d |
| +} |
| + |
| +func hostedAs(who string) context.Context { |
| + return personapi.WithVerifiedPrincipal(context.Background(), personapi.PersonPrincipal{Address: who}) |
| +} |
| + |
| +// hostedJobRow writes a hosted job row as the dispatcher would leave it. |
| +func hostedJobRow(t *testing.T, d *db.DB, id, person, state, hold, holdMicros, used, usedMicros string, settled, ended *time.Time) { |
| + t.Helper() |
| + if _, err := d.Writer().Exec(`INSERT INTO hosted_jobs(attempt_id,step_id,step_attempt,person,size,lifetime,state,hold_seconds_json,hold_micros_json,used_seconds_json,used_micros_json,settled_at,ended_at,runner_id,code_hash,retries,revision) VALUES(?,?,1,?,'large',5400,?,?,?,?,?,?,?,'','',0,1)`, id, "st-"+id, person, state, hold, holdMicros, used, usedMicros, settled, ended); err != nil { |
| + t.Fatal(err) |
| + } |
| +} |
| + |
| +// renderUsage is the Usage page's content for v. |
| +func renderUsage(t *testing.T, v usageView) string { |
| + t.Helper() |
| + var buf bytes.Buffer |
| + if err := pages["usage"].ExecuteTemplate(&buf, "content", pageData{Usage: v, Address: "owner-a@example.com"}); err != nil { |
| + t.Fatal(err) |
| + } |
| + return buf.String() |
| +} |
| + |
| +// TestUsageShowsHostedTotals: the Usage page's "Hosted machines" block |
| +// is the person's own hosted jobs: machines running now, VM hours this |
| +// UTC day and the estimated spend this UTC month (holds for jobs not |
| +// settled, what was used for settled ones, never another person's or an |
| +// earlier month's), each against the person's limits, with the note |
| +// saying the figures are estimates. An owner's change of limits shows. |
| +func TestUsageShowsHostedTotals(t *testing.T) { |
| + now := time.Date(2026, 12, 1, 12, 0, 0, 0, time.UTC) |
| + s, d := hostedStore(t, now) |
| + const a = "owner-a@example.com" |
| + ended := now.Add(-time.Hour) |
| + nov := time.Date(2026, 11, 30, 10, 0, 0, 0, time.UTC) |
| + // Live: its hold counts. 6000 s today, $2.07 this month. |
| + hostedJobRow(t, d, "live", a, chat.HostedJobEnrolled, `{"2026-12-01":6000}`, `{"2026-12":2066667}`, "", "", nil, nil) |
| + // Settled today: what it used counts, not its hold. |
| + hostedJobRow(t, d, "settled", a, chat.HostedJobEnded, `{"2026-12-01":6000}`, `{"2026-12":2066667}`, `{"2026-12-01":2400}`, `{"2026-12":826667}`, &now, &ended) |
| + // Failed across midnight with no proof: its hold counts, today's part. |
| + hostedJobRow(t, d, "held", a, chat.HostedJobFailed, `{"2026-11-30":6000,"2026-12-01":6000}`, `{"2026-11":2066667,"2026-12":2066667}`, "", "", nil, &ended) |
| + // November's and another person's jobs do not count. |
| + hostedJobRow(t, d, "november", a, chat.HostedJobEnded, `{"2026-11-30":6000}`, `{"2026-11":2066667}`, `{"2026-11-30":3600}`, `{"2026-11":1240000}`, &nov, &nov) |
| + hostedJobRow(t, d, "theirs", "owner-b@example.com", chat.HostedJobEnrolled, `{"2026-12-01":6000}`, `{"2026-12":2066667}`, "", "", nil, nil) |
| + |
| + u, err := s.Chat().HostedUsage(hostedAs(a), a) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if u.Running != 1 || u.DaySeconds != 14400 || u.MonthMicros != 2066667+826667+2066667 || u.Limits != chat.DefaultHostedLimits { |
| + t.Fatalf("usage %+v", u) |
| + } |
| + v := usageView{Hosted: hostedUsageOf(u, nil)} |
| + html := renderUsage(t, v) |
| + for _, want := range []string{ |
| + copyText("usage.hosted"), |
| + copyText("usage.hosted.running"), fmt.Sprintf(copyText("usage.hosted.running_value"), 1, 2), |
| + copyText("usage.hosted.hours"), fmt.Sprintf(copyText("usage.hosted.hours_value"), "4", "8"), |
| + copyText("usage.hosted.spend"), fmt.Sprintf(copyText("usage.hosted.spend_value"), "$4.96", "$50"), |
| + copyText("usage.hosted.note"), |
| + } { |
| + if want == "" || !strings.Contains(html, want) { |
| + t.Fatalf("missing %q in\n%s", want, html) |
| + } |
| + } |
| + if strings.Contains(html, copyText("usage.hosted.unknown")) { |
| + t.Fatalf("known totals read as unknown:\n%s", html) |
| + } |
| + if err := s.Chat().SetHostedLimits(hostedAs("owner-b@example.com"), "owner-b@example.com", a, chat.HostedLimits{Running: 3, DailySeconds: 10 * 3600, MonthlyMicros: 75_500_000}, 0); err != nil { |
| + t.Fatal(err) |
| + } |
| + u, err = s.Chat().HostedUsage(hostedAs(a), a) |
| + if err != nil || u.Limits != (chat.HostedLimits{Running: 3, DailySeconds: 36000, MonthlyMicros: 75_500_000}) { |
| + t.Fatalf("after the owner's change: %+v %v", u, err) |
| + } |
| + html = renderUsage(t, usageView{Hosted: hostedUsageOf(u, nil)}) |
| + for _, want := range []string{fmt.Sprintf(copyText("usage.hosted.running_value"), 1, 3), fmt.Sprintf(copyText("usage.hosted.hours_value"), "4", "10"), fmt.Sprintf(copyText("usage.hosted.spend_value"), "$4.96", "$75.50")} { |
| + if !strings.Contains(html, want) { |
| + t.Fatalf("missing %q in\n%s", want, html) |
| + } |
| + } |
| + if html := renderUsage(t, usageView{}); strings.Contains(html, copyText("usage.hosted")) { |
| + t.Fatal("the block shows without hosted machines") |
| + } |
| +} |
| + |
| +// TestUsageUnknownStaysUnknown: when the totals cannot be read (the jobs, |
| +// the limits or a hold unreadable), the store says so with an error and |
| +// the page shows "unknown", never a zero. |
| +func TestUsageUnknownStaysUnknown(t *testing.T) { |
| + now := time.Date(2026, 12, 1, 12, 0, 0, 0, time.UTC) |
| + const a = "owner-a@example.com" |
| + for _, c := range []struct{ name, sql string }{ |
| + {"jobs", "ALTER TABLE hosted_jobs RENAME TO hosted_jobs_gone"}, |
| + {"limits", "ALTER TABLE hosted_limits RENAME TO hosted_limits_gone"}, |
| + {"hold", "UPDATE hosted_jobs SET hold_seconds_json = 'not json'"}, |
| + } { |
| + s, d := hostedStore(t, now) |
| + hostedJobRow(t, d, "live", a, chat.HostedJobEnrolled, `{"2026-12-01":6000}`, `{"2026-12":2066667}`, "", "", nil, nil) |
| + if _, err := d.Writer().Exec(c.sql); err != nil { |
| + t.Fatal(err) |
| + } |
| + u, err := s.Chat().HostedUsage(hostedAs(a), a) |
| + if err == nil { |
| + t.Fatalf("%s: totals read with no error: %+v", c.name, u) |
| + } |
| + html := renderUsage(t, usageView{Hosted: hostedUsageOf(u, err)}) |
| + unknown := copyText("usage.hosted.unknown") |
| + if unknown == "" || strings.Count(html, ">"+unknown+"<") != 3 { |
| + t.Fatalf("%s: want three unknown figures in\n%s", c.name, html) |
| + } |
| + for _, zero := range []string{"$0", fmt.Sprintf(copyText("usage.hosted.running_value"), 0, 0), fmt.Sprintf(copyText("usage.hosted.hours_value"), "0", "0")} { |
| + if strings.Contains(html, zero) { |
| + t.Fatalf("%s: an unknown total shown as %q in\n%s", c.name, zero, html) |
| + } |
| + } |
| + } |
| +} |
| + |
| +// TestHostedLimitEditor: owners see each current member's limits in the |
| +// hosted section with the revision a save names; a member is refused, |
| +// people no longer on the roster are left out, and a lookup error is an |
| +// error. The form's figures (hours, dollars) parse to the limits, and |
| +// anything out of range or not a number is refused. |
| +func TestHostedLimitEditor(t *testing.T) { |
| + now := time.Date(2026, 12, 1, 12, 0, 0, 0, time.UTC) |
| + s, d := hostedStore(t, now) |
| + const a, b = "owner-a@example.com", "owner-b@example.com" |
| + if err := s.Chat().SetHostedLimits(hostedAs(a), a, b, chat.HostedLimits{Running: 3, DailySeconds: 5400, MonthlyMicros: 75_500_000}, 0); err != nil { |
| + t.Fatal(err) |
| + } |
| + rows, err := s.Chat().HostedLimitList(hostedAs(a), a, []string{a, b, "gone@example.com"}) |
| + if err != nil || len(rows) != 2 || rows[0].Person != a || rows[0].Limits != chat.DefaultHostedLimits || rows[0].Revision != 0 || rows[1].Person != b || rows[1].Revision != 1 || rows[1].Limits.Running != 3 { |
| + t.Fatalf("owner's list %+v %v", rows, err) |
| + } |
| + var data pageData |
| + data.Settings.Section = "hosted" |
| + data.Settings.HostedLimits = hostedLimitViews(rows) |
| + var buf bytes.Buffer |
| + if err := pages["settings_hub"].ExecuteTemplate(&buf, "hosted-settings", data); err != nil { |
| + t.Fatal(err) |
| + } |
| + html := buf.String() |
| + for _, want := range []string{copyText("hosted.limits"), copyText("hosted.limits_help"), copyText("hosted.limits.running"), copyText("hosted.limits.hours"), copyText("hosted.limits.spend"), |
| + `action="/settings/hosted/limits"`, `name="person" value="owner-b@example.com"`, `name="revision" value="1"`, `name="running" value="3"`, `name="hours" value="1.5"`, `name="dollars" value="75.50"`, |
| + `name="person" value="owner-a@example.com"`, `name="revision" value="0"`, `name="running" value="2"`, `name="hours" value="8"`, `name="dollars" value="50.00"`} { |
| + if want == "" || !strings.Contains(html, want) { |
| + t.Fatalf("missing %q in\n%s", want, html) |
| + } |
| + } |
| + l, err := parseHostedLimits("4", "1.5", "75.50") |
| + if err != nil || l != (chat.HostedLimits{Running: 4, DailySeconds: 5400, MonthlyMicros: 75_500_000}) { |
| + t.Fatalf("parsed %+v %v", l, err) |
| + } |
| + for _, bad := range [][3]string{{"", "8", "50"}, {"2", "", "50"}, {"2", "8", ""}, {"-1", "8", "50"}, {"2", "-1", "50"}, {"2", "8", "-0.01"}, {"2", "NaN", "50"}, {"2", "8", "Inf"}, {"2", "1e300", "50"}, {"2", "8", "1e300"}, {"two", "8", "50"}, {"2.5", "8", "50"}} { |
| + if l, err := parseHostedLimits(bad[0], bad[1], bad[2]); err == nil { |
| + t.Fatalf("%q parsed as %+v", bad, l) |
| + } |
| + } |
| + // A member sees no editor. |
| + var revision int64 |
| + if err := d.Writer().QueryRow("SELECT revision FROM members WHERE address=?", b).Scan(&revision); err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := s.SetMember(hostedAs(a), Actor{Address: a}, b, RoleMember, true, revision); err != nil { |
| + t.Fatal(err) |
| + } |
| + if _, err := s.Chat().HostedLimitList(hostedAs(b), b, []string{a, b}); !errors.Is(err, chat.ErrForbidden) { |
| + t.Fatalf("a member's list: %v", err) |
| + } |
| + if _, err := d.Writer().Exec("ALTER TABLE hosted_limits RENAME TO hosted_limits_gone"); err != nil { |
| + t.Fatal(err) |
| + } |
| + if rows, err := s.Chat().HostedLimitList(hostedAs(a), a, []string{a}); err == nil { |
| + t.Fatalf("a lookup error read as limits: %+v", rows) |
| + } |
| +} |
diff --git a/internal/equipo/settings_hub.go b/internal/equipo/settings_hub.go| index e1a21bef..201820aa 100644 |
| --- a/internal/equipo/settings_hub.go |
| +++ b/internal/equipo/settings_hub.go |
| @@ -68,6 +68,8 @@ type settingsHubView struct { |
| // Hosted is "Run checks in a hosted VM" for each project (owners, |
| // EQUIPO_HOSTED_RUNNERS=1 only). |
| Hosted []chat.HostedSetting |
| + // HostedLimits is the owner's per-person hosted limits editor. |
| + HostedLimits []hostedLimitView |
| // Places are the Places page's lines, state first (read-only). |
| Places []placeView |
| Section string |
| @@ -157,6 +159,21 @@ func (a *application) settingsSection(w http.ResponseWriter, r *http.Request, se |
| return |
| } |
| data.Settings.Hosted = hosted |
| + var members []Member |
| + if err := a.store.db.G.WithContext(ctx).Where("active = ?", true).Order("address").Find(&members).Error; err != nil { |
| + a.failure(w, r, storeError(err)) |
| + return |
| + } |
| + people := make([]string, 0, len(members)) |
| + for _, m := range members { |
| + people = append(people, m.Address) |
| + } |
| + limits, err := a.store.Chat().HostedLimitList(ctx, address, people) |
| + if err != nil { |
| + a.failure(w, r, chatError(err)) |
| + return |
| + } |
| + data.Settings.HostedLimits = hostedLimitViews(limits) |
| case "thinking": |
| words, err := a.store.Chat().Thinking(ctx, address) |
| if err != nil { |
diff --git a/internal/equipo/templates/hosted_settings.html b/internal/equipo/templates/hosted_settings.html| index e427687f..abec0db5 100644 |
| --- a/internal/equipo/templates/hosted_settings.html |
| +++ b/internal/equipo/templates/hosted_settings.html |
| @@ -8,4 +8,15 @@ |
| </div> |
| <div equipo-copy-actions><button rst-btn="primary" type="submit">{{copy "form.save"}}</button></div> |
| </form></section>{{end}} |
| +{{with .Settings.HostedLimits}}<section equipo-sp-group><div equipo-sp-group-head><h2>{{copy "hosted.limits"}}</h2><p>{{copy "hosted.limits_help"}}</p></div> |
| +{{range $i, $l := .}}<form method="post" action="/settings/hosted/limits"> |
| +<input type="hidden" name="person" value="{{$l.Person}}"><input type="hidden" name="revision" value="{{$l.Revision}}"> |
| +<div equipo-sp-card> |
| +<div equipo-sp-row><div equipo-sp-label><span equipo-sp-title>{{$l.Person}}</span></div></div> |
| +<div equipo-sp-row><div equipo-sp-label><label equipo-sp-title for="hosted-running-{{$i}}">{{copy "hosted.limits.running"}}</label></div><span equipo-sp-control><input rst-input id="hosted-running-{{$i}}" type="number" min="0" max="1000" step="1" name="running" value="{{$l.Running}}" required></span></div> |
| +<div equipo-sp-row><div equipo-sp-label><label equipo-sp-title for="hosted-hours-{{$i}}">{{copy "hosted.limits.hours"}}</label></div><span equipo-sp-control><input rst-input id="hosted-hours-{{$i}}" type="number" min="0" max="24000" step="0.1" name="hours" value="{{$l.Hours}}" required></span></div> |
| +<div equipo-sp-row><div equipo-sp-label><label equipo-sp-title for="hosted-dollars-{{$i}}">{{copy "hosted.limits.spend"}}</label></div><span equipo-sp-control><input rst-input id="hosted-dollars-{{$i}}" type="number" min="0" max="1000000" step="0.01" name="dollars" value="{{$l.Dollars}}" required></span></div> |
| +</div> |
| +<div equipo-copy-actions><button rst-btn="primary" type="submit">{{copy "form.save"}}</button></div> |
| +</form>{{end}}</section>{{end}} |
| {{end}} |
diff --git a/internal/equipo/templates/usage.html b/internal/equipo/templates/usage.html| index c17c2c63..fb237c0f 100644 |
| --- a/internal/equipo/templates/usage.html |
| +++ b/internal/equipo/templates/usage.html |
| @@ -8,6 +8,9 @@ |
| <section equipo-usage-part aria-labelledby="usage-spend"><h2 id="usage-spend">{{copy "usage.spend"}}</h2> |
| <ul equipo-usage-list role="list">{{range .Spend}}<li equipo-usage-spend data-spend="{{.ID}}"><span equipo-usage-name><b>{{template "conn-label" .Tag}}</b>{{with .Paused}} <span equipo-conn-state data-s="limited">{{.}}</span>{{end}}</span><span equipo-usage-facts>{{with .Line}}<span data-spend-line>{{.}}</span>{{end}}{{with .Tail}}<span equipo-usage-age>{{.}}</span>{{end}}{{with .Source}}<span equipo-usage-age data-price-source>{{.}}</span>{{end}}{{with .UnderCount}}<span equipo-usage-age data-spend-undercount>{{.}}</span>{{end}}</span></li>{{end}}{{range .Plans}}<li equipo-usage-spend data-plan="{{.ID}}"><span equipo-usage-name><b>{{template "conn-label" .Tag}}</b>{{with .Plan}} <span equipo-usage-age>{{.}}</span>{{end}}</span><span equipo-usage-facts><span data-plan-tokens>{{.Tokens}}</span></span></li>{{end}}</ul> |
| {{if not .Spend}}<p equipo-usage-age data-empty-state="usage.spend_none">{{copy "usage.spend_none"}}</p>{{end}}</section> |
| +{{with .Hosted}}<section equipo-usage-part aria-labelledby="usage-hosted" data-hosted-usage{{if .Unknown}} data-unknown{{end}}><h2 id="usage-hosted">{{copy "usage.hosted"}}</h2> |
| +<ul equipo-usage-list role="list">{{range .Lines}}<li equipo-usage-spend data-hosted="{{.Key}}"><span equipo-usage-name><b>{{.Label}}</b></span><span equipo-usage-facts><span data-hosted-value>{{.Value}}</span></span></li>{{end}}</ul> |
| +<p equipo-usage-age>{{copy "usage.hosted.note"}}</p></section>{{end}} |
| <section equipo-usage-part aria-labelledby="usage-tokens"><h2 id="usage-tokens">{{copy "usage.tokens"}}</h2> |
| <nav equipo-usage-tabs aria-label="{{copy "usage.tokens"}}"><span role="list">{{range .Periods}}<a role="listitem" href="{{.Href}}" data-period="{{.Key}}"{{if .On}} aria-current="true"{{end}}>{{.Label}}</a>{{end}}</span><span role="list">{{range .By}}<a role="listitem" href="{{.Href}}" data-by="{{.Key}}"{{if .On}} aria-current="true"{{end}}>{{.Label}}</a>{{end}}</span></nav> |
| <div equipo-usage-table-wrap><table equipo-usage-table data-usage-table><thead><tr><th scope="col">{{.Column}}</th><th scope="col">{{copy "usage.col.input"}}</th><th scope="col">{{copy "usage.col.cached"}}</th><th scope="col">{{copy "usage.col.output"}}</th><th scope="col">{{copy "usage.col.estimate"}}</th></tr></thead> |
diff --git a/internal/equipo/usage_page.go b/internal/equipo/usage_page.go| index a96d2093..77793c4d 100644 |
| --- a/internal/equipo/usage_page.go |
| +++ b/internal/equipo/usage_page.go |
| @@ -37,6 +37,7 @@ type usageView struct { |
| Column string |
| Rows []usageRowView |
| LeftOut bool |
| + Hosted *hostedUsageBlock |
| } |
| // usageConn is one connection's availability: its state in words, the |
| @@ -306,6 +307,15 @@ func (a *application) usage(w http.ResponseWriter, r *http.Request) { |
| } |
| data.Title = "usage.title" |
| data.Usage = usagePage(conns, labels, totals, month, advice, c.Now().In(c.Zone(address))) |
| + if a.hostedRunners { |
| + // Unread, the block says unknown and the rest of |
| + // the page still shows. |
| + u, herr := c.HostedUsage(ctx, address) |
| + if herr != nil { |
| + a.logger.Warn("hosted_usage_unknown", "err", herr) |
| + } |
| + data.Usage.Hosted = hostedUsageOf(u, herr) |
| + } |
| render(w, "usage", data) |
| return |
| } |
| @@ -344,3 +354,39 @@ func planLabel(plan string) string { |
| } |
| return fmt.Sprintf(copyText("usage.plan"), strings.ToUpper(plan[:1])+plan[1:]) |
| } |
| + |
| +// hostedUsageBlock is the "Hosted machines" block (hosted runners slice |
| +// 2): machines running now, VM hours this UTC day and the estimated |
| +// spend this UTC month, each against the person's limit. A total that |
| +// could not be read is unknown, never a zero. |
| +type hostedUsageBlock struct { |
| + Lines []hostedUsageLine |
| + Unknown bool |
| +} |
| + |
| +type hostedUsageLine struct{ Key, Label, Value string } |
| + |
| +// hoursText is seconds as hours, to one decimal place, a whole number |
| +// without it. |
| +func hoursText(seconds int64) string { |
| + return strings.TrimSuffix(strconv.FormatFloat(float64(seconds)/3600, 'f', 1, 64), ".0") |
| +} |
| + |
| +func hostedUsageOf(u chat.HostedUsage, err error) *hostedUsageBlock { |
| + b := &hostedUsageBlock{Lines: []hostedUsageLine{ |
| + {Key: "running", Label: copyText("usage.hosted.running")}, |
| + {Key: "hours", Label: copyText("usage.hosted.hours")}, |
| + {Key: "spend", Label: copyText("usage.hosted.spend")}, |
| + }} |
| + if err != nil { |
| + b.Unknown = true |
| + for i := range b.Lines { |
| + b.Lines[i].Value = copyText("usage.hosted.unknown") |
| + } |
| + return b |
| + } |
| + b.Lines[0].Value = fmt.Sprintf(copyText("usage.hosted.running_value"), u.Running, u.Limits.Running) |
| + b.Lines[1].Value = fmt.Sprintf(copyText("usage.hosted.hours_value"), hoursText(u.DaySeconds), hoursText(u.Limits.DailySeconds)) |
| + b.Lines[2].Value = fmt.Sprintf(copyText("usage.hosted.spend_value"), chat.Money(u.MonthMicros, "USD"), chat.Money(u.Limits.MonthlyMicros, "USD")) |
| + return b |
| +} |
diff --git a/internal/equipo/work_pages.go b/internal/equipo/work_pages.go| index 044f46e7..234cc71c 100644 |
| --- a/internal/equipo/work_pages.go |
| +++ b/internal/equipo/work_pages.go |
| @@ -116,6 +116,9 @@ func checksLine(outcome, reason, gate string, code *int, sandbox string) string |
| case wire.ChecksNone: |
| return copyText("work.checks.none") |
| case wire.ChecksCannotRun: |
| + if hostedReasons[reason] { |
| + return fmt.Sprintf(copyText("work.checks.hosted_reason"), copyText("work.reason."+reason)) |
| + } |
| if s := copyText("work.checks." + reason); s != "" { |
| return s |
| } |
| @@ -124,6 +127,26 @@ func checksLine(outcome, reason, gate string, code *int, sandbox string) string |
| return "" |
| } |
| +// hostedReasons are the reasons a hosted machine's checks did not run; |
| +// each says why in its work.reason words. |
| +var hostedReasons = map[string]bool{wire.ReasonPackIncomplete: true, wire.ReasonDepsConflict: true, wire.ReasonDepsNewModule: true, wire.ReasonDepsMissing: true, wire.ReasonDepsTooLarge: true, wire.ReasonTokenRenewalFailed: true, wire.ReasonHostedEnrolTimeout: true, wire.ReasonHostedVMLost: true, wire.ReasonHostedUnavailable: true} |
| + |
| +// hostedWaitLine is a checks step waiting for a hosted machine: which |
| +// hosted limit holds it and when that frees, or the plain wait. "" for |
| +// any other step. |
| +func hostedWaitLine(s wire.Step) string { |
| + if s.Specialist != wire.SpecialistChecks || s.Placement != wire.PlacementHosted && s.Placement != wire.PlacementHostedLimit { |
| + return "" |
| + } |
| + if s.Placement == wire.PlacementHostedLimit { |
| + switch s.Reason { |
| + case chat.HostedLimitRunning, chat.HostedLimitDaily, chat.HostedLimitMonthly: |
| + return copyText("work.checks.hosted_limit_" + s.Reason) |
| + } |
| + } |
| + return copyText("work.checks.waiting_hosted") |
| +} |
| + |
| // outsideSandbox labels a checks result that ran outside the sandbox. |
| func outsideSandbox(line, sandbox string) string { |
| if sandbox != wire.SandboxNone { |
| @@ -223,6 +246,9 @@ func taskLineOf(t wire.Task, viewer string) taskLine { |
| if s.Placement == wire.PlacementMac { |
| v.ChecksLine = copyText("work.chip.waiting_mac") |
| } |
| + if w := hostedWaitLine(s); w != "" { |
| + v.ChecksLine = w |
| + } |
| case wire.SpecialistReview: |
| v.ReviewLine = copyText("work.review.running") |
| } |
diff --git a/internal/equipo/work_views.go b/internal/equipo/work_views.go| index 2b898a59..9a12a09a 100644 |
| --- a/internal/equipo/work_views.go |
| +++ b/internal/equipo/work_views.go |
| @@ -725,6 +725,9 @@ func decisionOf(t wire.Task, v taskLine) *decisionView { |
| d.Ask = copyText("work.decide.adopt_ask") |
| } else { |
| reason := copyText("work.decide.reason." + t.ChecksReason) |
| + if hostedReasons[t.ChecksReason] { |
| + reason = copyText("work.reason." + t.ChecksReason) |
| + } |
| switch { |
| case t.Checks == wire.ChecksNone: |
| reason = copyText("work.decide.no_gate") |
| @@ -1172,6 +1175,9 @@ func timelineOf(t wire.Task, v taskLine) []timelineItem { |
| // no Claude connection there) or the person (the limit). |
| it.Headline = copyText("work.design." + s.Reason) |
| } |
| + if w := hostedWaitLine(s); w != "" { |
| + it.Headline = w |
| + } |
| out = append(out, it) |
| continue |
| case wire.StepRunning: |