oficina / equipo Public

equipo: Task 25 review 1, limit floor, handler tests, precision

Limits below one checks job (1 machine, 100 minutes a day, one Large
hold a month) are refused, in plain pending words on the editor. The
limit chips say when the limit frees, shown true through admission.
Handler tests for the Usage block and the limit save (flag, unknown
totals, session actor, target, revision, member). A figure saved as
shown keeps its stored value. Trailing whitespace removed.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 379bf0983823bcd5b737faa383be13e837446c4f parent 51aa644
12 files changed, +425 −25
  • .rastrillo/budgets.txt +2 −2
  • docs/superpowers/plans/2026-11-30-hosted-slice-2-copy.json +13 −6
  • docs/superpowers/plans/CONTROLLER-REPORT-plan-3.md +4 −3
  • docs/superpowers/plans/HOSTED-SLICE2-PROGRESS.md +73 −1
  • internal/equipo/chat/hosted_limits.go +17 −3
  • internal/equipo/chat/hosted_limits_floor_test.go +94 −0
  • internal/equipo/chat_page.go +3 −0
  • internal/equipo/copy.go +4 −3
  • internal/equipo/handlers.go +4 −0
  • internal/equipo/hosted_settings.go +41 −3
  • internal/equipo/hosted_views_test.go +168 −2
  • internal/equipo/templates/hosted_settings.html +2 −2

CI failed — run details

CI log
=== prepare ===
ci-box: machine: aarch64, 32 CPUs, 62 GiB memory, kernel 7.0.0-1017-aws
ci-box: python 3.12.3; Docker version 29.1.3, build 29.1.3-0ubuntu3~24.04.2
ci-box: user namespaces allowed: 233151
ci-box: cgroup: cgroup2fs
ci-box: disk /home/ci/work/repos/oficina__equipo/wt/hosted-runners-2: Type  Size Avail | ext4   96G   84G
ci-box: disk /home/ci/.cache/equipo-ci-box: Type  Size Avail | ext4   96G   84G
ci-box: bwrap: fetched and verified in 0.3s
ci-box: claude: fetched and verified in 2.3s
ci-box: codex: fetched and verified in 4.5s
ci-box: codex-code-mode-host: fetched and verified in 1.5s
ci-box: libwrap: fetched and verified in 0.3s
ci-box: socat: fetched and verified in 0.3s
npm warn deprecated node-domexception@1.0.0: Use your platform's native DOMException instead
ci-box: image pulled in 9.8s
ci-box: pi: installed and verified in 7.5s
ci-box: opencode: installed and verified in 2.2s
ci-box: chromium 156.0.8078.79-1~deb13u1: 76 packages fetched, verified and unpacked in 8.6s
ci-box: clone deepened in 5.8s
ci-box: file times set from content: 3914 files, 272 directories
ci-box: ready in 20.5s
=== copy ===
EQUIPO_RELEASE_COPY_CHECK=1 CGO_ENABLED=0 go test ./internal/equipotest -run '^TestReleaseCopyReviewed$' -count=1
--- FAIL: TestReleaseCopyReviewed (0.09s)
    task_pages_test.go:236: COPY REVIEW REQUIRED: copy-status.py verify found copy pending review or stale bookkeeping
FAIL
rastrillo-budget/v1 ran 87ms
FAIL	amadan.net/oficina/equipo/internal/equipotest	0.237s
FAIL
make: *** [Makefile:273: copy-release-check] Error 1

amadan: step copy failed: exit status 2

amadan: job failed at step copy — its output is above, not at the tail of this log
diff --git a/.rastrillo/budgets.txt b/.rastrillo/budgets.txt
index 761305f0..1b6bb56f 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 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/equipo 25524 9235 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. Task 25 review round 1: the limit save keeps a stored figure submitted as shown (hostedLimitsFrom), refuses limits below one checks run in their own words (hosted.limits.too_low), and handler tests for the Usage block and the save (flag, unknown totals, session actor, target, revision, member); 25524/9235.
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 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.
+size internal/equipo/chat 47224 21852 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. Task 25 review round 1: HostedMinLimits and ErrHostedLimitTooLow (SetHostedLimits refuses limits that could never admit one checks job) and hosted_limits_floor_test.go (the floor, and each limit chip's promise through admission); 47224/21852.
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 62775d27..42cab81b 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
@@ -134,22 +134,22 @@
},
{
"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",
+ "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; reworded in review round 1 to say when the limit frees, which TestHostedLimitChipsComeTrue shows is true)",
+ "draft": "Waiting: the limit on hosted machines running at once is reached. It frees 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",
+ "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; reworded in review round 1 to say when the limit frees, which TestHostedLimitChipsComeTrue shows is true)",
+ "draft": "Waiting: today’s hosted machine hours are used up. A new day’s hours start at 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",
+ "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; reworded in review round 1 to say when the limit frees, which TestHostedLimitChipsComeTrue shows is true)",
+ "draft": "Waiting: this month’s hosted machine spend limit is reached. A new month’s limit starts at midnight UTC on the 1st",
"paul_sees": true,
"reviewed": ""
},
@@ -222,5 +222,12 @@
"draft": "Unknown",
"paul_sees": true,
"reviewed": ""
+ },
+ {
+ "key": "hosted.limits.too_low",
+ "where": "Error page after saving per-person hosted limits below one checks run (fewer than 1 machine, 100 minutes a day or $2.07 a month; Task 25 review round 1 ruling)",
+ "draft": "Each limit must leave room for one checks run: at least 1 machine at once, 100 minutes a day and $2.07 a month.",
+ "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 bb20e500..6f2ae231 100644
--- a/docs/superpowers/plans/CONTROLLER-REPORT-plan-3.md
+++ b/docs/superpowers/plans/CONTROLLER-REPORT-plan-3.md
@@ -7238,9 +7238,9 @@ records remain unchanged.
| `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_limit_running` | Waiting: the limit on hosted machines running at once is reached. It frees when one of them stops | Copy specialist | COPY REVIEW PENDING |
+| `work.checks.hosted_limit_daily` | Waiting: today’s hosted machine hours are used up. A new day’s hours start at midnight UTC | Copy specialist | COPY REVIEW PENDING |
+| `work.checks.hosted_limit_monthly` | Waiting: this month’s hosted machine spend limit is reached. A new month’s limit starts at midnight UTC on the 1st | 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 |
@@ -7251,6 +7251,7 @@ records remain unchanged.
| `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 |
+| `hosted.limits.too_low` | Each limit must leave room for one checks run: at least 1 machine at once, 100 minutes a day and $2.07 a month. | 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 4a98cc39..9a6912b0 100644
--- a/docs/superpowers/plans/HOSTED-SLICE2-PROGRESS.md
+++ b/docs/superpowers/plans/HOSTED-SLICE2-PROGRESS.md
@@ -2010,7 +2010,7 @@ Tests (`internal/equipo/hosted_views_test.go`):
- 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.
@@ -2042,3 +2042,75 @@ Not mutation-checked:
- 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.
+
+### Task 25 review round 1 (t25-r1.md: two Important and two Minor findings, all fixed; the coordinator's ruling on finding 1)
+
+**Finding 1 (limits that never free).** Ruling: an owner cannot set a limit that could never admit one job.
+- `chat.HostedMinLimits` is 1 machine, 6,000 s a day (`HostedLaunchWindow` + `HostedChecksLifetime`) and 2,066,667 micros a month (one Large job's whole hold at 4x).
+- `SetHostedLimits` refuses anything lower with `ErrHostedLimitTooLow`, which wraps `ErrInvalid`. The upper bounds are still plain `ErrInvalid`.
+- On the editor, the refusal is the page's `errHostedLimitTooLow`. The error page shows `hosted.limits.too_low` (pending): "Each limit must leave room for one checks run: at least 1 machine at once, 100 minutes a day and $2.07 a month." Its Back link goes to the hosted section, and the machine count field has `min="1"`.
+- The three limit chips now say when the limit frees, which the admission tests show is true:
+ - running: "It frees when one of them stops";
+ - daily: "A new day’s hours start at midnight UTC";
+ - monthly: "A new month’s limit starts at midnight UTC on the 1st".
+
+ The earlier wording promised that the checks would start then. That is not always true: another limit can bind next, or a job that ran across midnight can have used the new day's hours.
+
+**Finding 2 (handler coverage).** The new tests drive the handlers themselves: `a.usage` and `a.saveHostedLimits`, on an `application` over the production store, with the session set by `identity.With`.
+
+**Finding 3 (stored precision).** The editor's form now carries hidden fields: `hours_shown` and `dollars_shown` (what was displayed) and `daily_seconds` and `monthly_micros` (the stored values). `hostedLimitsFrom` keeps the stored value of any figure submitted exactly as it was shown. A changed figure is read as typed.
+
+**Finding 4 (whitespace).** The trailing space in the Task 25 notes is gone, and `git diff --check 0318d11c..` is clean.
+
+Red:
+1. `CGO_ENABLED=0 go test ./internal/equipo/chat -run 'TestHostedLimitsFloor|TestHostedLimitChipsComeTrue' -count=1` with HEAD's `hosted_limits.go` failed to build (`undefined: HostedMinLimits`, `undefined: ErrHostedLimitTooLow`).
+2. With the names but no floor check: exit 1, `hosted_limits_floor_test.go:35: {Running:0 DailySeconds:6000 MonthlyMicros:2066667}: <nil>, want too low`. `TestHostedLimitChipsComeTrue` passed: it shows behaviour that already held, and mutations 392 and 393 are its failing evidence.
+3. `CGO_ENABLED=0 go test ./internal/equipo -run 'TestUsageShowsHostedHandler|TestHostedLimitSaveHandler|TestHostedLimitTooLow|TestHostedLimitEditor' -count=1` failed to build (`v.DailySeconds undefined`, `v.MonthlyMicros undefined`).
+
+Tests:
+- `TestHostedLimitsFloor` (chat): the minimums, and a refusal for one below each limit and for all three negative. The minimum is accepted, and an empty day then admits a job.
+- `TestHostedLimitChipsComeTrue` (chat). Each limit is at its minimum and the others at the defaults:
+ - running: refused while one job runs, admitted once it stops;
+ - daily: refused for the rest of the day after the job stopped, admitted at 00:00;
+ - daily, still running: yesterday's unended job does not hold today, so a job is admitted at 00:00;
+ - daily across midnight: a job admitted at 23:00 used the next day too, so that day is refused and the day after admits;
+ - monthly: refused through 30 November 23:59, admitted at 1 December 00:00.
+
+ The chips' words are tested by `TestLimitChipSaysWhich`.
+- `TestUsageShowsHostedHandler`: through `a.usage`, the flag off shows no block. With the flag on, the block shows "1 of 2". With the jobs table gone, the response is 200 with exactly three "Unknown", `data-unknown`, no "0 of 0", and the token-use section still rendered.
+- `TestHostedLimitSaveHandler`: B has 3 machines, 6,000 s and 2,066,667 micros, shown as "1.7" and "2.07". Changing only the machine count saves {4, 6000, 2066667} at revision 2, and the audit actor is the session's owner, although the form also carries an `actor` field naming B. A changed figure is read as typed ({4, 7200, 3500000}). Each of these is refused and leaves the limits unchanged:
+ - a stale revision (303 back);
+ - limits too low (422 with the too-low words);
+ - the flag off (403);
+ - B as a member (403).
+- `TestHostedLimitTooLowWords`: the words name the minimum minutes and money, computed from `HostedMinLimits`.
+- `TestHostedLimitEditor`: now uses 6,000 s and checks the hidden fields.
+
+Green: all the commands above, ok. Also ok:
+- the brief's command;
+- `./internal/equipo -run 'TestWaitingHosted|TestLimitChip|TestUsageShowsHosted|TestUsageUnknown|TestHostedLimit|TestHostedSetting|Copy|StepReasons|Settings'`;
+- chat `-run 'TestLimits|TestHoldSpans|TestDelayedLaunch|TestSettleStays|TestNoProofKeepsHold|TestLimitCount|TestOwnerRaises|TestHosted'`;
+- `./internal/equipo/hostedrun`;
+- thintest `Settings|Usage|Copy|Rail`.
+
+`make budget build vet`: exit 0 after the records were raised. gofmt and `git diff --check` are clean. staticcheck reports only the earlier `preview_frames_fixture_test.go` U1000. Copy verify gives `{"valid": false}`, because the keys are pending. `work.checks.hosted_limit_*` and `hosted.limits.too_low` were re-marked with `copy-status.py pending`, and their drafts were updated in the slice copy JSON.
+
+Mutations used the same method: an exact-string replace from a script under `mktemp -d`, one at a time, the named test run, then the file restored from a copy and checked identical with `filecmp`.
+- **380** no floor (all three comparisons with `false &&`). `CGO_ENABLED=0 go test ./internal/equipo/chat -run TestHostedLimitsFloor -count=1`: exit 1, `hosted_limits_floor_test.go:35: {Running:0 DailySeconds:6000 MonthlyMicros:2066667}: <nil>, want too low`. Restored.
+- **381** no daily floor. Same command: exit 1, `hosted_limits_floor_test.go:35: {Running:1 DailySeconds:5999 MonthlyMicros:2066667}: <nil>, want too low`. Restored.
+- **382** too low shown as the generic refusal (`false &&` before the `ErrHostedLimitTooLow` check in `saveHostedLimits`). `CGO_ENABLED=0 go test ./internal/equipo -run TestHostedLimitSaveHandler -count=1`: exit 1, `hosted_views_test.go:464: too low: 422 <!doctype html>…` (without the words). Restored.
+- **383** (coordinator) the Usage flag condition: `if a.hostedRunners {` became `if true || a.hostedRunners {`. `-run TestUsageShowsHostedHandler`: exit 1, `hosted_views_test.go:368: the block shows with the flag off:`. Restored.
+- **384** (coordinator) nil passed instead of the error: `hostedUsageOf(u, herr)` became `hostedUsageOf(u, nil)`. Same: exit 1, `hosted_views_test.go:380: a failed total through the handler:` (the page showed "0 of 0"). Restored.
+- **385** (coordinator) success without saving: the `SetHostedLimits` call became `err = nil`. `-run TestHostedLimitSaveHandler`: exit 1, `hosted_views_test.go:436: after the save: {Running:3 DailySeconds:6000 MonthlyMicros:2066667} at 1`. Restored.
+- **386** a submitted actor: the owner argument became `r.PostFormValue("actor")`. Same: exit 1, `hosted_views_test.go:440: audited as "owner-b@example.com" <nil>, want the session's owner-a@example.com`. Restored.
+- **387** the wrong target: the person argument became `owner`. Same: exit 1, `hosted_views_test.go:436: after the save: {Running:3 DailySeconds:6000 MonthlyMicros:2066667} at 1`. Restored.
+- **388** the save takes the current revision, not the one the form names (the revision check became `revision = current`). Same: exit 1, `hosted_views_test.go:460: a stale revision changed the limits: {Running:9 DailySeconds:32400 MonthlyMicros:9000000} at 4`. Restored.
+ - A first spelling (`if false && current != revision`) exited 0, and is not counted. The conditional update's `revision = ?` also refuses a stale write, so that spelling removed only one of two guards.
+- **389** no owner check in `SetHostedLimits`. Same: exit 1, `hosted_views_test.go:481: member: 303`. Restored.
+- **390** the save served with the flag off (the `hostedSection` check removed). Same: exit 1, `hosted_views_test.go:469: flag off: 303`. Restored.
+- **391** an unchanged figure rounded to what was shown (`if true || form.Get(field) != form.Get(shown) {`). Same: exit 1, `hosted_views_test.go:436: after the save: {Running:4 DailySeconds:6120 MonthlyMicros:2070000} at 2`. Restored.
+- **392** a stopped job still counts as running (`if j.Live() {` became `if true {` in `hostedCounted`). `CGO_ENABLED=0 go test ./internal/equipo/chat -run TestHostedLimitChipsComeTrue -count=1`: exit 1, `hosted_limits_floor_test.go:56: admit st-c at 2026-11-08 12:31:00 +0000 UTC: "running" <nil>`. Restored.
+- **393** a hold reaches the day after its window (`!d.After(end)` became `!d.After(end.Add(24*time.Hour))` in `hostedHoldFor`). Same: exit 1, `hosted_limits_floor_test.go:73: admit st-c at 2026-11-09 00:00:00 +0000 UTC: "daily" <nil>`. Restored.
+ - Before the `daily_still_running` case was added, this mutation exited 0: in every daily case, the earlier job had settled before midnight.
+
+Budgets, with reasons: `internal/equipo` 25478/9069 → 25524/9235; `internal/equipo/chat` 47210/21758 → 47224/21852.
diff --git a/internal/equipo/chat/hosted_limits.go b/internal/equipo/chat/hosted_limits.go
index b3d5ecde..13605a54 100644
--- a/internal/equipo/chat/hosted_limits.go
+++ b/internal/equipo/chat/hosted_limits.go
@@ -41,6 +41,16 @@ const (
HostedLimitMonthly = "monthly"
)
+// HostedMinLimits are the least an owner may set (Task 25 review ruling):
+// room for one Large checks job's whole hold, its launch window and
+// lifetime at BurstHoldFactor times the baseline. Lower, a limit could
+// never admit a job, and its chip's promise of when it frees would be
+// false.
+var HostedMinLimits = HostedLimits{Running: 1, DailySeconds: int64((HostedLaunchWindow + HostedChecksLifetime) / time.Second), MonthlyMicros: hostedMicros(int64((HostedLaunchWindow+HostedChecksLifetime)/time.Second), RateLargeMicrosPerHour)}
+
+// ErrHostedLimitTooLow refuses limits below HostedMinLimits.
+var ErrHostedLimitTooLow = fmt.Errorf("%w: hosted limits below one checks job", ErrInvalid)
+
// hostedMaxLifetime bounds the lifetime admission accepts, and
// hostedMaxLimits what an owner may set, so no sum can overflow.
const hostedMaxLifetime = 24 * time.Hour
@@ -264,7 +274,8 @@ func (t *txn) hostedSettle(attempt string) (bool, error) {
return t.settleHostedJob(attempt, HostedCharge{Seconds: days, Micros: months}, t.now())
}
-// SetHostedLimits sets a current member's hosted limits. owner is the
+// SetHostedLimits sets a current member's hosted limits, none below
+// HostedMinLimits (ErrHostedLimitTooLow). owner is the
// verified session's address, never a submitted actor, and must be a
// current owner; the roster is read in the transaction and a lookup error
// denies. The write names the revision the owner saw (0 for the
@@ -280,10 +291,13 @@ func (s *Store) SetHostedLimits(ctx context.Context, owner, person string, l Hos
if _, err := s.authority.Me(t.db, person); err != nil {
return err
}
- m := hostedMaxLimits
- if l.Running < 0 || l.DailySeconds < 0 || l.MonthlyMicros < 0 || l.Running > m.Running || l.DailySeconds > m.DailySeconds || l.MonthlyMicros > m.MonthlyMicros {
+ m, least := hostedMaxLimits, HostedMinLimits
+ if l.Running > m.Running || l.DailySeconds > m.DailySeconds || l.MonthlyMicros > m.MonthlyMicros {
return fmt.Errorf("%w: hosted limits", ErrInvalid)
}
+ if l.Running < least.Running || l.DailySeconds < least.DailySeconds || l.MonthlyMicros < least.MonthlyMicros {
+ return ErrHostedLimitTooLow
+ }
_, current, err := t.hostedLimits(person)
if err != nil {
return err
diff --git a/internal/equipo/chat/hosted_limits_floor_test.go b/internal/equipo/chat/hosted_limits_floor_test.go
new file mode 100644
index 00000000..b324a4b5
--- /dev/null
+++ b/internal/equipo/chat/hosted_limits_floor_test.go
@@ -0,0 +1,94 @@
+package chat
+
+import (
+ "errors"
+ "testing"
+
+ "amadan.net/oficina/equipo/internal/isolatedjob"
+ "gorm.io/gorm"
+)
+
+// TestHostedLimitsFloor (Task 25 review ruling): an owner cannot set a
+// limit that could never admit one checks job: no machine at once, fewer
+// than the 100-minute window a day, or less than one Large job's whole
+// hold a month. The least that can admit one is accepted.
+func TestHostedLimitsFloor(t *testing.T) {
+ r, _ := hostedRig(t)
+ // The owner's write audits in its own transaction, not a job move's.
+ r.s.authority.Audit = func(tx *gorm.DB, _, _, _ string) error {
+ if _, inTx := tx.Statement.ConnPool.(gorm.TxCommitter); !inTx {
+ return errors.New("audit outside the transaction")
+ }
+ return nil
+ }
+ if HostedMinLimits != (HostedLimits{Running: 1, DailySeconds: 6000, MonthlyMicros: 2_066_667}) {
+ t.Fatalf("minimums %+v", HostedMinLimits)
+ }
+ least := HostedMinLimits
+ for _, bad := range []HostedLimits{
+ {Running: 0, DailySeconds: least.DailySeconds, MonthlyMicros: least.MonthlyMicros},
+ {Running: least.Running, DailySeconds: least.DailySeconds - 1, MonthlyMicros: least.MonthlyMicros},
+ {Running: least.Running, DailySeconds: least.DailySeconds, MonthlyMicros: least.MonthlyMicros - 1},
+ {Running: -1, DailySeconds: -1, MonthlyMicros: -1},
+ } {
+ if err := r.s.SetHostedLimits(r.ctx, hkOwner, hkOwner, bad, 0); !errors.Is(err, ErrHostedLimitTooLow) || !errors.Is(err, ErrInvalid) {
+ t.Fatalf("%+v: %v, want too low", bad, err)
+ }
+ }
+ r.must(r.s.SetHostedLimits(r.ctx, hkOwner, hkOwner, least, 0))
+ // At the least, an empty day admits one job.
+ r.mustAdmit("st-a", isolatedjob.SizeLarge, at(8, 12, 0))
+}
+
+// TestHostedLimitChipsComeTrue: with each limit at its least and the
+// others at the defaults, the refusal frees as its chip says. Machines
+// at once: when the running one stops. Hours: a new UTC day's start at
+// midnight (the first day nothing earlier holds or used). Spend: a new
+// UTC month's at midnight on the 1st.
+func TestHostedLimitChipsComeTrue(t *testing.T) {
+ d, least := DefaultHostedLimits, HostedMinLimits
+ t.Run("running", func(t *testing.T) {
+ r, _ := hostedRig(t)
+ r.setLimits(HostedLimits{Running: least.Running, DailySeconds: d.DailySeconds, MonthlyMicros: d.MonthlyMicros})
+ a := r.mustAdmit("st-a", isolatedjob.SizeLarge, at(8, 12, 0))
+ r.refused("st-b", at(8, 12, 10), HostedLimitRunning)
+ r.stopAt(a.AttemptID, at(8, 12, 30))
+ r.mustAdmit("st-c", isolatedjob.SizeLarge, at(8, 12, 31))
+ })
+ t.Run("daily", func(t *testing.T) {
+ r, _ := hostedRig(t)
+ r.setLimits(HostedLimits{Running: d.Running, DailySeconds: least.DailySeconds, MonthlyMicros: d.MonthlyMicros})
+ a := r.mustAdmit("st-a", isolatedjob.SizeLarge, at(8, 12, 0))
+ r.refused("st-b", at(8, 12, 10), HostedLimitDaily)
+ r.stopAt(a.AttemptID, at(8, 12, 20))
+ r.refused("st-c", at(8, 23, 59), HostedLimitDaily)
+ r.mustAdmit("st-d", isolatedjob.SizeLarge, at(9, 0, 0))
+ })
+ t.Run("daily_still_running", func(t *testing.T) {
+ // Yesterday's job, not yet ended, holds only its own window.
+ r, _ := hostedRig(t)
+ r.setLimits(HostedLimits{Running: d.Running, DailySeconds: least.DailySeconds, MonthlyMicros: d.MonthlyMicros})
+ r.mustAdmit("st-a", isolatedjob.SizeLarge, at(8, 12, 0))
+ r.refused("st-b", at(8, 23, 59), HostedLimitDaily)
+ r.mustAdmit("st-c", isolatedjob.SizeLarge, at(9, 0, 0))
+ })
+ t.Run("daily_across_midnight", func(t *testing.T) {
+ r, _ := hostedRig(t)
+ r.setLimits(HostedLimits{Running: d.Running, DailySeconds: least.DailySeconds, MonthlyMicros: d.MonthlyMicros})
+ a := r.mustAdmit("st-a", isolatedjob.SizeLarge, at(8, 23, 0))
+ // The 9th was held from the start, then used: its hours are used up.
+ r.refused("st-b", at(9, 0, 10), HostedLimitDaily)
+ r.stopAt(a.AttemptID, at(9, 0, 20))
+ r.refused("st-c", at(9, 0, 30), HostedLimitDaily)
+ r.mustAdmit("st-d", isolatedjob.SizeLarge, at(10, 0, 0))
+ })
+ t.Run("monthly", func(t *testing.T) {
+ r, _ := hostedRig(t)
+ r.setLimits(HostedLimits{Running: d.Running, DailySeconds: d.DailySeconds, MonthlyMicros: least.MonthlyMicros})
+ a := r.mustAdmit("st-a", isolatedjob.SizeLarge, at(8, 12, 0))
+ r.refused("st-b", at(8, 12, 10), HostedLimitMonthly)
+ r.stopAt(a.AttemptID, at(8, 12, 20))
+ r.refused("st-c", at(30, 23, 59), HostedLimitMonthly)
+ r.mustAdmit("st-d", isolatedjob.SizeLarge, at(31, 0, 0))
+ })
+}
diff --git a/internal/equipo/chat_page.go b/internal/equipo/chat_page.go
index e79fe688..70cfc6ce 100644
--- a/internal/equipo/chat_page.go
+++ b/internal/equipo/chat_page.go
@@ -883,6 +883,9 @@ func (a *application) chatNotebookReset(w http.ResponseWriter, r *http.Request)
}
func chatError(err error) error {
+ if errors.Is(err, errHostedLimitTooLow) {
+ return err
+ }
for from, to := range map[error]error{chat.ErrBusy: ErrConflict, chat.ErrInvalid: ErrInvalid, chat.ErrConflict: ErrConflict, chat.ErrNotFound: ErrNotFound, chat.ErrForbidden: ErrForbidden, chat.ErrNotAllowed: ErrInvalid, chat.ErrTaskEnded: ErrConflict, chat.ErrNotRetryable: ErrConflict, chat.ErrMerging: ErrConflict, chat.ErrNotMergeable: ErrConflict, chat.ErrNotAskable: ErrConflict, chat.ErrRevision: ErrConflict, chat.ErrAlreadyReleased: ErrAlreadyRunning} {
if errors.Is(err, from) {
return to
diff --git a/internal/equipo/copy.go b/internal/equipo/copy.go
index 254220fe..af14ff14 100644
--- a/internal/equipo/copy.go
+++ b/internal/equipo/copy.go
@@ -162,10 +162,11 @@ var pageCopy = map[string]string{
"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
+ "hosted.limits.too_low": "Each limit must leave room for one checks run: at least 1 machine at once, 100 minutes a day and $2.07 a month.", // 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_limit_running": "Waiting: the limit on hosted machines running at once is reached. It frees when one of them stops", // COPY REVIEW PENDING
+ "work.checks.hosted_limit_daily": "Waiting: today’s hosted machine hours are used up. A new day’s hours start at midnight UTC", // COPY REVIEW PENDING
+ "work.checks.hosted_limit_monthly": "Waiting: this month’s hosted machine spend limit is reached. A new month’s limit starts at midnight UTC on the 1st", // 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
diff --git a/internal/equipo/handlers.go b/internal/equipo/handlers.go
index d6c50131..51fab7e1 100644
--- a/internal/equipo/handlers.go
+++ b/internal/equipo/handlers.go
@@ -143,6 +143,8 @@ func (a *application) failure(w http.ResponseWriter, r *http.Request, err error)
status, key = 403, "form.last-owner"
case errors.Is(err, ErrAccountLabelExists):
status, key = 409, "form.account-label-exists"
+ case errors.Is(err, errHostedLimitTooLow):
+ status, key = 422, "hosted.limits.too_low"
case errors.Is(err, ErrInvalid), errors.Is(err, team.ErrInvalid):
status, key = 422, "form.invalid"
case errors.Is(err, ErrConflict), errors.Is(err, team.ErrConflict), errors.Is(err, team.ErrRevision), errors.Is(err, team.ErrState):
@@ -167,6 +169,8 @@ func (a *application) failure(w http.ResponseWriter, r *http.Request, err error)
back = "/people"
case strings.HasPrefix(r.URL.Path, "/specialists/"):
back = r.URL.Path
+ case strings.HasPrefix(r.URL.Path, "/settings/hosted"):
+ back = "/conversation/settings/hosted"
}
navKey := ""
for _, item := range Navigation() {
diff --git a/internal/equipo/hosted_settings.go b/internal/equipo/hosted_settings.go
index bb73c887..53017ce5 100644
--- a/internal/equipo/hosted_settings.go
+++ b/internal/equipo/hosted_settings.go
@@ -2,9 +2,11 @@ package equipo
import (
"context"
+ "errors"
"fmt"
"math"
"net/http"
+ "net/url"
"strconv"
"amadan.net/oficina/equipo/internal/equipo/chat"
@@ -51,19 +53,48 @@ func (a *application) saveHostedSetting(w http.ResponseWriter, r *http.Request)
// 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.
+//
+// DailySeconds and MonthlyMicros are the stored values, sent back beside
+// what was shown: a field saved as shown keeps them exactly.
type hostedLimitView struct {
Person, Running, Hours, Dollars string
Revision int64
+ DailySeconds, MonthlyMicros 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})
+ 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, DailySeconds: r.Limits.DailySeconds, MonthlyMicros: r.Limits.MonthlyMicros})
}
return out
}
+// errHostedLimitTooLow is chat.ErrHostedLimitTooLow on the page: its own
+// words (hosted.limits.too_low), still a refusal of invalid input.
+var errHostedLimitTooLow = &refusal{"hosted.limits.too_low", ErrInvalid}
+
+// hostedLimitsFrom reads the editor's form. A figure submitted exactly as
+// it was shown keeps the stored value it was shown for, so saving one
+// field never rounds another.
+func hostedLimitsFrom(form url.Values) (chat.HostedLimits, error) {
+ l, err := parseHostedLimits(form.Get("running"), form.Get("hours"), form.Get("dollars"))
+ if err != nil {
+ return l, err
+ }
+ keep := func(field, shown, stored string, into *int64) {
+ if form.Get(field) != form.Get(shown) {
+ return
+ }
+ if v, err := strconv.ParseInt(form.Get(stored), 10, 64); err == nil {
+ *into = v
+ }
+ }
+ keep("hours", "hours_shown", "daily_seconds", &l.DailySeconds)
+ keep("dollars", "dollars_shown", "monthly_micros", &l.MonthlyMicros)
+ return l, nil
+}
+
// 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).
@@ -95,10 +126,17 @@ func (a *application) saveHostedLimits(w http.ResponseWriter, r *http.Request) {
if err != nil || revision < 0 {
return chat.ErrInvalid
}
- l, err := parseHostedLimits(r.FormValue("running"), r.FormValue("hours"), r.FormValue("dollars"))
+ if err := r.ParseForm(); err != nil {
+ return chat.ErrInvalid
+ }
+ l, err := hostedLimitsFrom(r.PostForm)
if err != nil {
return err
}
- return a.store.Chat().SetHostedLimits(ctx, owner, r.FormValue("person"), l, revision)
+ err = a.store.Chat().SetHostedLimits(ctx, owner, r.PostFormValue("person"), l, revision)
+ if errors.Is(err, chat.ErrHostedLimitTooLow) {
+ return errHostedLimitTooLow
+ }
+ return err
})
}
diff --git a/internal/equipo/hosted_views_test.go b/internal/equipo/hosted_views_test.go
index 3b1355c3..4a9d8fd6 100644
--- a/internal/equipo/hosted_views_test.go
+++ b/internal/equipo/hosted_views_test.go
@@ -5,15 +5,22 @@ import (
"context"
"errors"
"fmt"
+ "html"
"io"
"log/slog"
+ "net/http"
+ "net/http/httptest"
+ "net/url"
+ "strconv"
"strings"
"testing"
"time"
"amadan.net/oficina/equipo/internal/equipo/chat"
+ "amadan.net/oficina/equipo/internal/equipo/identity"
"amadan.net/oficina/equipo/internal/equipo/personapi"
"amadan.net/oficina/equipo/internal/wire"
+ "amadan.net/rastrillo/rastrillo/auth"
"amadan.net/rastrillo/rastrillo/db"
"amadan.net/rastrillo/rastrillo/dbtest"
)
@@ -277,7 +284,7 @@ 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 {
+ if err := s.Chat().SetHostedLimits(hostedAs(a), a, b, chat.HostedLimits{Running: 3, DailySeconds: 6000, MonthlyMicros: 75_500_000}, 0); err != nil {
t.Fatal(err)
}
rows, err := s.Chat().HostedLimitList(hostedAs(a), a, []string{a, b, "gone@example.com"})
@@ -293,7 +300,7 @@ func TestHostedLimitEditor(t *testing.T) {
}
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"`,
+ `action="/settings/hosted/limits"`, `name="person" value="owner-b@example.com"`, `name="revision" value="1"`, `name="running" value="3"`, `name="hours" value="1.7"`, `name="hours_shown" value="1.7"`, `name="daily_seconds" value="6000"`, `name="monthly_micros" value="75500000"`, `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)
@@ -326,3 +333,162 @@ func TestHostedLimitEditor(t *testing.T) {
t.Fatalf("a lookup error read as limits: %+v", rows)
}
}
+
+// hostedHandlerApp is the application over s as the router builds it,
+// with or without EQUIPO_HOSTED_RUNNERS=1.
+func hostedHandlerApp(s *Store, on bool) *application {
+ return &application{store: s, hostedRunners: on, logger: slog.New(slog.NewTextHandler(io.Discard, nil))}
+}
+
+// signedIn is r with who's verified browser session.
+func signedIn(r *http.Request, who string) *http.Request {
+ return identity.With(r, auth.Identity{Address: who, At: time.Now()})
+}
+
+// usageHTML is GET /usage through the handler for who.
+func usageHTML(t *testing.T, a *application, who string) string {
+ t.Helper()
+ w := httptest.NewRecorder()
+ a.usage(w, signedIn(httptest.NewRequest("GET", "/usage", nil), who))
+ if w.Code != http.StatusOK {
+ t.Fatalf("usage page: %d %s", w.Code, w.Body)
+ }
+ return w.Body.String()
+}
+
+// TestUsageShowsHostedHandler: through the page handler, the block shows
+// only with EQUIPO_HOSTED_RUNNERS=1, and a total that cannot be read is
+// unknown while the rest of the page still renders.
+func TestUsageShowsHostedHandler(t *testing.T) {
+ now := time.Date(2026, 12, 1, 12, 0, 0, 0, time.UTC)
+ const a = "owner-a@example.com"
+ s, d := hostedStore(t, now)
+ hostedJobRow(t, d, "live", a, chat.HostedJobEnrolled, `{"2026-12-01":6000}`, `{"2026-12":2066667}`, "", "", nil, nil)
+ if html := usageHTML(t, hostedHandlerApp(s, false), a); strings.Contains(html, "data-hosted-usage") || strings.Contains(html, copyText("usage.hosted.note")) {
+ t.Fatalf("the block shows with the flag off:\n%s", html)
+ }
+ html := usageHTML(t, hostedHandlerApp(s, true), a)
+ if !strings.Contains(html, "data-hosted-usage") || !strings.Contains(html, fmt.Sprintf(copyText("usage.hosted.running_value"), 1, 2)) {
+ t.Fatalf("the block is missing with the flag on:\n%s", html)
+ }
+ if _, err := d.Writer().Exec("ALTER TABLE hosted_jobs RENAME TO hosted_jobs_gone"); err != nil {
+ t.Fatal(err)
+ }
+ html = usageHTML(t, hostedHandlerApp(s, true), a)
+ unknown := copyText("usage.hosted.unknown")
+ if strings.Count(html, ">"+unknown+"<") != 3 || !strings.Contains(html, "data-unknown") || strings.Contains(html, fmt.Sprintf(copyText("usage.hosted.running_value"), 0, 0)) || !strings.Contains(html, copyText("usage.tokens")) {
+ t.Fatalf("a failed total through the handler:\n%s", html)
+ }
+}
+
+// saveLimits posts the limit editor's form for who.
+func saveLimits(a *application, who string, form url.Values) *httptest.ResponseRecorder {
+ q := httptest.NewRequest("POST", "/settings/hosted/limits", strings.NewReader(form.Encode()))
+ q.Header.Set("Content-Type", "application/x-www-form-urlencoded")
+ w := httptest.NewRecorder()
+ a.saveHostedLimits(w, signedIn(q, who))
+ return w
+}
+
+// limitsOf is person's stored limits and revision.
+func limitsOf(t *testing.T, s *Store, person string) (chat.HostedLimits, int64) {
+ t.Helper()
+ rows, err := s.Chat().HostedLimitList(hostedAs("owner-a@example.com"), "owner-a@example.com", []string{person})
+ if err != nil || len(rows) != 1 {
+ t.Fatalf("limits of %s: %+v %v", person, rows, err)
+ }
+ return rows[0].Limits, rows[0].Revision
+}
+
+// TestHostedLimitSaveHandler: the editor's save goes through the
+// session: the session's owner is the actor (a submitted actor is
+// ignored), the form's person is the target, and its revision is named.
+// A stale revision, a member, the flag off and limits below one checks
+// job are refused and change nothing; too low says so in plain words. A
+// field left as shown keeps its exact stored value (6,000 seconds and
+// 2,066,667 micros do not become 1.7 hours and $2.07).
+func TestHostedLimitSaveHandler(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"
+ app := hostedHandlerApp(s, true)
+ odd := chat.HostedLimits{Running: 3, DailySeconds: 6000, MonthlyMicros: 2_066_667}
+ if err := s.Chat().SetHostedLimits(hostedAs(a), a, b, odd, 0); err != nil {
+ t.Fatal(err)
+ }
+ rows, err := s.Chat().HostedLimitList(hostedAs(a), a, []string{b})
+ if err != nil {
+ t.Fatal(err)
+ }
+ v := hostedLimitViews(rows)[0]
+ if v.Hours != "1.7" || v.Dollars != "2.07" {
+ t.Fatalf("shown %+v", v)
+ }
+ form := func(running, hours, dollars string, revision int64) url.Values {
+ return url.Values{"person": {b}, "revision": {strconv.FormatInt(revision, 10)}, "running": {running}, "hours": {hours}, "dollars": {dollars},
+ "hours_shown": {v.Hours}, "daily_seconds": {strconv.FormatInt(v.DailySeconds, 10)}, "dollars_shown": {v.Dollars}, "monthly_micros": {strconv.FormatInt(v.MonthlyMicros, 10)}, "actor": {b}}
+ }
+ // Only the machine count changed: the hours and dollars stay exact.
+ if w := saveLimits(app, a, form("4", v.Hours, v.Dollars, 1)); w.Code != http.StatusSeeOther {
+ t.Fatalf("save: %d %s", w.Code, w.Body)
+ }
+ if l, rev := limitsOf(t, s, b); l != (chat.HostedLimits{Running: 4, DailySeconds: 6000, MonthlyMicros: 2_066_667}) || rev != 2 {
+ t.Fatalf("after the save: %+v at %d", l, rev)
+ }
+ var actor string
+ if err := d.Writer().QueryRow("SELECT actor FROM audit_events WHERE kind='hosted.limits' ORDER BY rowid DESC LIMIT 1").Scan(&actor); err != nil || actor != a {
+ t.Fatalf("audited as %q %v, want the session's %s", actor, err, a)
+ }
+ // A changed field is read as typed.
+ if w := saveLimits(app, a, form("4", "2", "3.5", 2)); w.Code != http.StatusSeeOther {
+ t.Fatalf("save: %d %s", w.Code, w.Body)
+ }
+ if l, rev := limitsOf(t, s, b); l != (chat.HostedLimits{Running: 4, DailySeconds: 7200, MonthlyMicros: 3_500_000}) || rev != 3 {
+ t.Fatalf("after the second save: %+v at %d", l, rev)
+ }
+ want, _ := limitsOf(t, s, b)
+ unchanged := func(what string) {
+ t.Helper()
+ if l, rev := limitsOf(t, s, b); l != want || rev != 3 {
+ t.Fatalf("%s changed the limits: %+v at %d", what, l, rev)
+ }
+ }
+ // A stale revision.
+ if w := saveLimits(app, a, form("9", "9", "9", 1)); w.Code != http.StatusSeeOther {
+ t.Fatalf("stale: %d", w.Code)
+ }
+ unchanged("a stale revision")
+ // Too low: plain words, nothing saved.
+ w := saveLimits(app, a, form("0", "9", "9", 3))
+ if w.Code != http.StatusUnprocessableEntity || !strings.Contains(w.Body.String(), html.EscapeString(copyText("hosted.limits.too_low"))) {
+ t.Fatalf("too low: %d %s", w.Code, w.Body)
+ }
+ unchanged("too low")
+ // The flag off.
+ if w := saveLimits(hostedHandlerApp(s, false), a, form("9", "9", "9", 3)); w.Code != http.StatusForbidden {
+ t.Fatalf("flag off: %d", w.Code)
+ }
+ unchanged("the flag off")
+ // A member.
+ 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 w := saveLimits(app, b, form("9", "9", "9", 3)); w.Code != http.StatusForbidden {
+ t.Fatalf("member: %d", w.Code)
+ }
+ unchanged("a member")
+}
+
+// TestHostedLimitTooLowWords: the refusal names the least an owner can
+// set, from the limits themselves.
+func TestHostedLimitTooLowWords(t *testing.T) {
+ words := copyText("hosted.limits.too_low")
+ minutes := strconv.FormatInt(chat.HostedMinLimits.DailySeconds/60, 10)
+ if words == "" || !strings.Contains(words, minutes+" minutes") || !strings.Contains(words, chat.Money(chat.HostedMinLimits.MonthlyMicros, "USD")) {
+ t.Fatalf("too low says %q, want %s minutes and %s", words, minutes, chat.Money(chat.HostedMinLimits.MonthlyMicros, "USD"))
+ }
+}
diff --git a/internal/equipo/templates/hosted_settings.html b/internal/equipo/templates/hosted_settings.html
index abec0db5..16ff92a6 100644
--- a/internal/equipo/templates/hosted_settings.html
+++ b/internal/equipo/templates/hosted_settings.html
@@ -10,10 +10,10 @@
</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}}">
+<input type="hidden" name="person" value="{{$l.Person}}"><input type="hidden" name="revision" value="{{$l.Revision}}"><input type="hidden" name="hours_shown" value="{{$l.Hours}}"><input type="hidden" name="daily_seconds" value="{{$l.DailySeconds}}"><input type="hidden" name="dollars_shown" value="{{$l.Dollars}}"><input type="hidden" name="monthly_micros" value="{{$l.MonthlyMicros}}">
<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-running-{{$i}}">{{copy "hosted.limits.running"}}</label></div><span equipo-sp-control><input rst-input id="hosted-running-{{$i}}" type="number" min="1" 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>