oficina / equipo Public

Clone
git clone https://amadan.net/oficina/equipo

Plain git — no account needed to clone.

Download

Download this file

1# S3 progress: the scheduler
2
3Branch `connections-s3-scheduler` from main 379fe0d2 (S1 and S2 merged).
4Spec: `docs/superpowers/specs/2026-11-12-equipo-connectors-and-token-scheduling.md`
5revision 3.1 (on `connections-slice2-design`), §11 row S3: §0 decisions
65 and 6, §6, §7, §8, §10 (S3's wire, API and fixtures) and §15 round 3
7rows 4, 6 and 7. No real key, sign-in or provider: fakes only.
8
9## Done
10
111. `internal/schedule`: the pure `Decide(Input) Decision` (§7). Bars
12 (usable, not avoided, capable; metered: urgent or a release, slot
13 free, spend known, under both budgets), thresholds 0.60/0.80/1.0 on
14 the effective priority (a release is urgent), windows past their
15 reset not reported, the fixed room precedence for subscriptions and
16 for metered connections, the rules in order (kept session, preference,
17 subscription, metered, hold), the hold naming the subscription whose
18 reset comes first or the most actionable spending bar, wake-ups
19 strictly after now (every capable connection's resets, the next budget
20 day or month when the step has leave, the preference's end, `by`
21 minus 24 h unless `deadline_notified`), and Needs you (deadline, no
22 reset in 72 h, no_connection). Review's family rule is applied as
23 tiers: another family, then another account, then Engineering's own.
242. Wire, protocol 14 (`ProtocolScheduler`): dispatch `priority`, `by`,
25 `release`; a step report's `hold` (`StepHold`: reason, connection,
26 provider, resets_at, wake_at, needs_person, step_revision); frames
27 `release` and `priority` (durable); `Preferences.until` and
28 `PreferenceCommand.until`; record_task and start_task arguments
29 `priority` and `by`. Below 14 Encode refuses the two frames, a held
30 report and a preference with an end, and drops the dispatch fields and
31 the tool arguments. Fixtures `frames/release.json`,
32 `frames/priority.json`, `frames/step-held.json`,
33 `frames/preference-until.json`, `frames/dispatch-urgent.json`,
34 `api/task-held.json`, `api/card-held.json`, `api/priority-request.json`,
35 `api/run-now-request.json`, `api/run-now-accepted.json`; the secret
36 guards cover every new type and fixture.
373. The runner (`thin/schedule.go`): every Engineering, Review and
38 Research attempt, failover included, is admitted through Decide.
39 Readings are refreshed before the call (an unchecked connection is
40 checked; a reading over 15 minutes old goes through `Conns.Reading`,
41 at most once per 15 minutes). The admission is one thin.db transaction
42 that reads the facts again and decides again if they moved; a pending
43 release is consumed there and kept as a grant for (step,
44 step_revision); a metered admission commits in S1's guard transaction
45 (`Meter.RunAdmitted`). Holds are kept with `wake_at` (or until a
46 change), reported once per hold, woken at `wake_at` and on any reading,
47 step end, budget, Resume, preference, priority or release. The release
48 order (`nextStep`): urgent, earliest `by`, normal, low, oldest, step
49 id. Questions stay off Decide and keep S1's guard. A kept metered
50 session under a spending bar is held there; without leave it starts
51 afresh on a subscription (S2's rule, kept).
524. Leave to spend comes only from `urgent` or a grant. The test-build
53 seam (`testLeaveToSpend`, `EQUIPO_TEST_LEAVE_TO_SPEND`) is gone: the Pi
54 tests mark their tasks urgent; the release check no longer looks for a
55 marker nothing can contain.
565. The instance: `chat_tasks.priority`, `due_by`, `priority_set_by`;
57 `chat_steps.hold`; `chat_releases` (one per step revision); migration
58 0073. record_task (and start_task, only on a task recorded in that
59 turn with nothing set) take `low`/`normal` and `by`; `urgent` is
60 refused. `PUT /api/v1/tasks/{id}/priority` is the creator's tap
61 (actor from the session, roster in the transaction, revision, audit
62 `task.priority`) and sends a `priority` frame to the runner holding the
63 step. A held step stays queued with its hold; where the creator's input
64 changes the outcome it is Needs you `held` with a `held` card ("I'd
65 wait: Claude resets ..."), Wait or Run it now. `POST
66 /api/v1/tasks/{id}/run-now {step, step_revision}`: the creator's,
67 bound to the hold's revision, one release per revision (a second tap
68 answers the first), audited `task.run_now`, refused on a budget or
69 spend-unknown hold (409 `hold_bar`) and on a runner before 14 (409
70 `runner_too_old`). `PUT /connections/preference` takes `until` (a
71 runner before 14 is refused one). Dispatches carry the priority,
72 deadline and an open release; housekeeping's go as `low` with none.
736. Pages: the task card and page show the hold line with Run it now
74 anyway (headroom, busy, no_connection) or Raise the budget / Resume
75 (links to Connections), the priority line ("Low priority · By Fri 20
76 Nov · set from your message") with Mark urgent / Not urgent, and the
77 Needs you decision from the held card.
78
79## Tests
80
81- `internal/schedule`: `TestDecideRules` (a row per rule and bar),
82 `TestDecideReviewFamily`, `TestDecideWakeUps`, `TestDecideNeedsYou`,
83 `TestDecideInvariants` ((a) to (f) and wake-ups after now over 20,000
84 random inputs), `TestDecideOrderFree`.
85- `internal/wire`: `TestEncodeBelowProtocol14DropsScheduler`,
86 `TestEncodeBelowProtocol14DropsToolPriority`,
87 `TestSchedulerFramesStrict`, fixture round trips, secret guards.
88- `internal/runner/thin`: the finish line
89 `TestScheduleLowHoldsThenStartsAfterReset` (a low step holds at 0.61,
90 said once with a future wake-up, a normal step runs meanwhile, and the
91 low one starts by itself after the reset),
92 `TestScheduleReleaseOnceAndStaleRefused` (a stale, another person's
93 and a replayed release start nothing; the consumed one is a grant),
94 `TestScheduleFailoverInsideAGrant`, `TestSchedulePriorityChangeGivesLeave`,
95 `TestScheduleReleaseOrder`, `TestScheduleAdmissionRechecksFacts`,
96 `TestScheduleRefreshesStaleReadings`, `TestPreferenceUntilEnds`; the
97 Pi tests now give leave by an urgent task (`TestPiReviewStep` also
98 checks the admission row `metered_urgent`;
99 `TestPiReviewWithoutLeaveToSpend` the headroom hold).
100- `internal/thintest`: `TestContractScheduler`,
101 `TestContractSchedulerOlderRunner`; `internal/equipo/chat`:
102 `TestSchedulerWritesCheckCreatorAndRoster`.
103- Local runs were targeted (`-run`) on the changed packages, plus
104 gofmt, go vet, staticcheck on the changed packages, the darwin runner
105 build, `make budget` (budget lines updated; `internal/wire` gets an
106 exemption at 5032 lines) and the dead-reference scan.
107
108## Mutations, each observed failing
109
110### schedule mutations (all caught)
111- SM1 low threshold 0.70 -> TestDecideRules/low_holds_at_0.61
112- SM2 windows past reset still counted -> TestDecideRules/a_window_past_its_reset_is_not_reported
113- SM3 leave always granted -> TestDecideRules/kept_metered_without_leave_moves; TestDecideInvariants (b) #34 metered without leave
114- SM4 budget bar off -> TestDecideRules/kept_metered_over_budget_holds_there; TestDecideInvariants (d)
115- SM5 busy-slot bar off -> TestDecideRules/kept_metered_busy_holds_there; TestDecideInvariants (c)
116- SM5b spend-unknown bar off -> TestDecideInvariants (d)
117- SM6 kept metered under a spending bar moved instead of held -> TestDecideRules/kept_metered_busy_holds_there (ran on b)
118- SM7 wake-up allowed at now -> TestDecideWakeUps, TestDecideInvariants (#76 a wake-up not after now)
119- SM8 rule 4 removed -> TestDecideRules/metered_only_with_urgent; TestDecideInvariants (e) held though a candidate admits
120- SM9 reported-before-unreported key dropped -> TestDecideRules/reported_before_unreported
121- SM10 preference until ignored -> TestDecideRules/an_expired_preference_is_absent
122- SM11 deadline check fires again after deadline_notified -> TestDecideNeedsYou
123- SM12 Review family tiers removed -> TestDecideReviewFamily
124- SM13 kept subscription not sticky -> TestDecideRules/kept_stays_whatever_the_threshold
125- SM14 limited always usable -> TestDecideRules/limited_is_not_usable
126- SM15 no 72 h bound on reset -> TestDecideNeedsYou (a reset 73 h away)
127- SM16 threshold compare > instead of >= -> TestDecideInvariants (a) admitted at 0.60
128### wire mutations (TestEncodeBelowProtocol14DropsScheduler)
129- WM1 release frame not refused below 14 -> caught (release encoded at 13)
130- WM2 held step report not refused below 14 -> caught
131- WM3 dispatch priority kept below 14 -> caught (dispatch at 13)
132- WM4 preference with until not refused below 14 -> caught
133### runner mutations
134- RM1 release not consumed / no grant at admission -> TestScheduleReleaseOnceAndStaleRefused (release "pending", grants 0)
135- RM2 release accepted for a stale step revision -> TestScheduleReleaseOnceAndStaleRefused (a stale release was kept)
136- RM3 release not bound to the person -> TestScheduleReleaseOnceAndStaleRefused (another person's release was kept)
137- RM4 release kept for a revision that already holds a grant -> first MISSED (the replay arrived after the step ended, so the step check alone refused it); a case with the step still held and its revision granted was added, then caught
138- RM5 admission without the facts recheck -> TestScheduleAdmissionRechecksFacts (admitted on moved facts)
139- RM6 fact changes not waking held steps -> TestScheduleReleaseOnceAndStaleRefused, TestScheduleFailoverInsideAGrant (timed out)
140- RM7 hold said at every look -> first MISSED (nothing re-decided before the reset); the test now wakes the step three times, then caught (said 4 times)
141- RM8 stale readings never probed -> TestScheduleRefreshesStaleReadings (0 probes)
142- RM9 grant not read for later attempts -> TestScheduleFailoverInsideAGrant (the failover attempt held)
143- RM10 priority frame ignores its revision -> TestSchedulePriorityChangeGivesLeave (an older priority applied)
144- RM11 release order back to oldest first -> TestScheduleReleaseOrder
145- RM12 preference until ignored -> TestPreferenceUntilEnds
146- RM13 dispatch's scheduler facts not recorded -> TestScheduleLowHoldsThenStartsAfterReset (ran at 0.61 as normal)
147- RM14 runPi not writing the scheduler's admission in the guard's transaction -> TestPiReviewStep (no admission row)
148### instance mutations
149- IM1 coordinator allowed urgent -> TestContractScheduler (the coordinator set urgent)
150- IM2 coordinator priority changeable after creation (start_task) -> TestContractScheduler (dispatch / start_task changed it)
151- IM3 priority revision not checked -> TestContractScheduler (a stale revision accepted)
152- IM4 priority/Run now creator check removed -> first MISSED in thintest (the rig cannot make a second owner, and isOwner refused the teammate first); TestSchedulerWritesCheckCreatorAndRoster (chat store, two owners) added, then caught for both
153- IM5 roster check left out of SetPriority -> TestSchedulerWritesCheckCreatorAndRoster (a removed creator's priority)
154- IM6 priority audit left out -> TestSchedulerWritesCheckCreatorAndRoster (audits [])
155- IM7 priority frame not sent -> TestContractScheduler (no priority frame; timed out)
156- IM8 release not bound to the held step revision -> TestContractScheduler (a stale step revision accepted)
157- IM9 second tap writes a second release -> TestContractScheduler (a second tap)
158- IM10 Run now passes a spending bar -> TestContractScheduler (Run now past spend unknown)
159- IM11 Run now to a protocol 13 runner -> TestContractSchedulerOlderRunner
160- IM12 preference with an end to a protocol 13 runner -> TestContractSchedulerOlderRunner
161- IM13 dispatch without priority -> TestContractScheduler (dispatch)
162- IM14 a held step marked running -> TestContractScheduler (held: state running)
163- IM15 Needs you held dropped -> TestContractScheduler (needs "")
164- IM16 held card left open after Run now -> TestContractScheduler
165- IM17 page offers Run it now on a spending bar -> TestContractScheduler (spend unknown offers Run now)
166
167## Security round (Astra, read-only, on e38bc7e5)
168
169Verdict NOT READY, twelve findings: ten mechanical, fixed here, each
170with a test written first and a mutation observed; two design findings
171(#7 and #8) left to the controller unchanged.
172
1731. Cached urgency over a newer dispatch (Critical): the task's priority
174 has its own revision (`chat_tasks.priority_revision`), bumped by every
175 change; dispatches and priority frames carry it, and the runner keeps a
176 frame's value only while no dispatch carries a newer one, then keeps
177 the newer dispatch's as the task's.
1782. Housekeeping only "dispatched as low" (Critical): the attempt
179 housekeeping dispatched is kept on the step
180 (`chat_steps.housekeeping_attempt`), so a later placement is still
181 housekeeping's; the dispatch says `housekeeping`; the runner keeps it
182 per step and Decide treats it as low with no leave to spend whatever
183 its priority, a priority frame or a release; Run now on it is refused
184 and its held card offers Wait only.
1853. Recovery failed held, never-launched steps: a step with a hold and no
186 namespace recorded keeps its hold and wake-up across a restart.
1874. Duplicate admission was an UPSERT: an attempt admitted and launched
188 (its namespace recorded) is refused another admission (`errAdmitted`);
189 one that launched nothing may be admitted again, explicitly.
1905. Research skipped the scheduler's dispatch fields and holds: both
191 Research paths use the shared fields (`schedulerFields`) and hold
192 handling; a held Research step stays queued, is Needs you and takes
193 Run now.
1946. Review's failover launch ignored a guard hold: it is held there, as
195 the first attempt is.
1969. A repeated start_task could set the priority: the fields are written
197 only when the start would go ahead (`startable`).
19810. An overdue task could not change priority: an unchanged deadline is
199 kept; only a newly given one must be ahead.
20011. Frozen protocol 13 schemas: what is sent below 14 (a dispatch, a
201 preference, a step report, record_task's and start_task's
202 arguments) decodes strictly against the protocol 13 key sets.
20312. A hold after failover was written against the original attempt: it
204 is kept against the attempt the step moved to.
205
206Not changed (design, for the controller): #7, no production reading
207probe (see Open); #8, a kept metered session without leave starting
208afresh on a subscription (S2's rule).
209
210Mutations observed:
211
212- #11 each stripping guard below 14 removed (dispatch priority, by, release, housekeeping; record_task priority, by; start_task's arguments; the held report's refusal) -> TestEncodeBelowProtocol14AgainstFrozenSchemas (frozen protocol 13 key sets) or TestEncodeBelowProtocol14DropsScheduler, each caught
213- #2 (Decide) housekeeping given leave by urgent or a release -> TestDecideHousekeeping (housekeeping spent), TestDecideInvariants (b); housekeeping not counted as low -> TestDecideHousekeeping (above low's threshold)
214- #1 the cached priority taking precedence over a newer dispatch -> TestScheduleNewerDispatchBeatsCachedPriority ("urgent"); a newer dispatch's value not kept as the task's -> first MISSED (the stale frame shared the held revision, so it was refused anyway); the case now sends a frame between the two revisions, then caught
215- #2 (runner) the housekeeping flag not read -> TestScheduleHousekeepingNeverSpends (spent on TensorX)
216- #3 recovery failing a held, never-launched step -> TestScheduleHoldSurvivesRestart (state reported, 1 report)
217- #4 a launched attempt admitted again (the UPSERT) -> TestScheduleDuplicateAdmissionRefused
218- #12 the hold persisted against the original attempt -> TestScheduleHoldAfterFailover (the held step ran 2 times)
219- #6 a failover Review held by the guard -> TestPiReviewFailoverHeldByTheGuard (failed metered_held), observed before the fix (written first)
220- #1 (instance) the dispatch without its priority revision -> TestContractScheduler (dispatch); the priority frame carrying the task's revision, not the priority revision -> TestContractScheduler (priority frame Revision 5)
221- #2 (instance) housekeeping provenance not kept on the step -> TestContractSchedulerHousekeeping (retry not housekeeping); the dispatch not saying housekeeping -> same; Run now allowed on housekeeping's attempt -> same (Run now accepted); its held card offering Run it now -> same
222- #5 Research dispatch without the scheduler fields -> TestContractSchedulerResearch (research dispatch); its hold not kept -> same (Hold nil); a held Research step marked running -> same (state running); held Research not Needs you -> same (needs "")
223- #9 a repeated start_task in the same turn setting the priority -> TestContractScheduler (a second start_task set the priority)
224- #10 an unchanged past deadline refused -> TestSchedulerOverdueDeadlineKept
225
226## Decisions where the spec was open
227
228- The step revision is the attempt the instance dispatched (runner
229 column `steps.revision`); the runner's failover attempts keep it, a
230 Retry is a new revision. The hold carries it, Run now names it.
231- The held report is state `running` with `hold` (the instance keeps the
232 step queued until a report without it), not a new `deferred` state an
233 older instance would refuse; below 14 it is not sent.
234- `busy` is a hold reason too: a kept metered session whose slot is
235 taken (§7 rule 1) and an admission race.
236- The admission rechecks by reading the facts again inside its
237 transaction and comparing, not by per-row revision columns; the metered
238 slot, spend and budget are rechecked by S1's guard in that same
239 transaction.
240- A `priority` frame (not in §10) carries a priority change to a step
241 the runner already holds, so marking a held task urgent takes effect at
242 once.
243- Research steps go through Decide too (coordinator's family first, as
244 before; never metered). Coordinator turns do not (person turns are
245 never held). Housekeeping turns are not dispatched today
246 (`TurnHousekeeping` is never created); housekeeping's step dispatches
247 go as `low` with no release.
248- The preference stays one provider for every role (as built); `until`
249 is kept beside it, and an expired preference reads as Automatic on
250 both ends rather than being cleared by a write.
251- A deadline given as a date is the end of that day, UTC; at most a year
252 ahead. start_task's priority applies only to a task recorded in the
253 same turn with nothing set.
254- Run now is refused on a budget or spend-unknown hold (it never passes
255 a bar); those holds link to the Connections page for Raise the budget
256 and Resume, and their card offers Wait only.
257- The budget day and month boundaries are wake-ups only for a step with
258 leave and a capable metered connection. Spend unknown has no reset, so
259 it is Needs you.
260
261## Open, or not as the spec says
262
263- No reading probe exists that is not a model turn: Claude reports
264 headroom only on a turn, and Codex's `account/rateLimits/read` runs
265 only at sign-in. The refresh is built and tested with a fake
266 (`Conns.Reading`), but is nil in production, so a reading older than
267 15 minutes is used as last reported (a window past its reset counts as
268 not reported). A Codex probe over the app-server is the follow-up.
269- No browser test of the new forms (the pages are checked server-side).
270- The staging witness waits for a release (below).
271
272## New copy keys (in the Plan 3 inventory; see the delegated review below)
273
274- `work.hold.headroom`: Waiting for headroom on %s
275- `work.hold.headroom_reset`: Waiting for headroom on %s, resets %s
276- `work.hold.budget`: Waiting: %s has reached today’s budget
277- `work.hold.spend_unknown`: Waiting: %s spend unknown, check it, then Resume
278- `work.hold.busy`: Waiting: %s is running another step
279- `work.hold.no_connection`: Waiting: nothing you connected can run it without spending
280- `work.hold.run_now`: Run it now anyway
281- `work.hold.raise_budget`: Raise the budget
282- `work.hold.resume`: Resume
283- `work.priority.urgent`: Urgent
284- `work.priority.normal`: Normal priority
285- `work.priority.low`: Low priority
286- `work.priority.by`: By %s
287- `work.priority.from_message`: set from your message
288- `work.priority.mark_urgent`: Mark urgent
289- `work.priority.make_normal`: Not urgent
290- `chat.held.wait.before`: I’d wait: %s resets %s, before %s.
291- `chat.held.wait.reset`: I’d wait: %s resets %s.
292- `chat.held.run.after_by`: I’d run it now: %s resets %s, after %s.
293- `chat.held.run.no_reset`: I’d run it now: %s has no reset in the next three days.
294- `chat.held.run.no_connection`: I’d run it now: only a metered connection can run it.
295- `chat.held.spend_unknown`: %s spend is unknown. Check it, then Resume.
296- `chat.held.budget`: %s has reached its budget. Raise it, or wait for tomorrow.
297- `chat.card.wait_reset`: Wait
298- `chat.card.run_now`: Run it now
299
300## Copy: delegated review (Astra, 2026-11-12)
301
302The 25 strings went through Astra as the copy-review gate (Paul's
303delegation of 2026-10-25): 17 kept, 8 changed, applied verbatim, each
304now `COPY ACCEPTED BY DELEGATION (Astra, 2026-11-12)` in `copy.go` and in
305the Plan 3 inventory. The changes say what the person waits for in
306their own terms ("Waiting for your Claude allowance to reset Thu 10:00
307UTC"), drop "today's" from the budget hold (the month's budget holds
308too), say where to check spending and that Resume is a choice ("Check
309your spending at TensorX, then choose Resume"), say "no reported reset",
310name a per-token connection rather than "metered", and wait "for the
311budget to reset" rather than "tomorrow". The list above shows the texts
312as first written; the final texts are in `copy.go`. The one test that
313quotes a hold line is updated.
314
315## How Paul tries it
316
317On staging, once this is released (Pi is already installed on the
318owner runner):
319
3201. Settings, Connections, Add a connection, TensorX: tick "This key has
321 a spending limit at TensorX" (a small prepaid balance, no automatic
322 top-up), keep the $1 a day and $10 a month budget, paste the key and
323 pick `z-ai/glm-5.3`. The one-token probe makes it Ready and shows on
324 its spend line.
3252. Ask the coordinator for a small change on a test repository. On the
326 task page tap Mark urgent (or, when a step shows "Waiting for your
327 Claude allowance to reset", tap Run it now anyway). With Claude doing Engineering,
328 Review goes to another family first, so it runs on TensorX.
3293. What to see: the Review step on TensorX, family glm, label
330 other_family; the Connections spend line moved by that step's cost;
331 once today's spend reaches $1 the next step waits with "Waiting:
332 TensorX has reached its budget", Raise the budget, and the row says
333 "Paused until tomorrow". Ask the Review a question: it answers on TensorX,
334 charged. Mark the task Not urgent and a normal step never spends.
335