feat(bin): show the Ollama Cloud reserve on the Pi worker footer - #2682
Open
Kallas95 wants to merge 4 commits into
Open
feat(bin): show the Ollama Cloud reserve on the Pi worker footer#2682Kallas95 wants to merge 4 commits into
Kallas95 wants to merge 4 commits into
Conversation
Pi's own footer already renders the working directory, the branch, context consumed against its ceiling, tokens exchanged, and the model, and a live capture of a running Pi worker confirmed all four are visible in the captain's view rather than hidden or truncated. So the gap was never visibility: it was the one number Pi cannot know, the Ollama Cloud reserve, which quota-axi does not model. Pi exposes an additive hook for exactly this. ctx.ui.setStatus(key, text) appends a keyed line BELOW Pi's own footer lines instead of replacing them, so none of the four existing segments is reproduced or maintained here. Verified live on Pi 0.84.2 with the extension fm-spawn actually generates. The reserve comes from the probe file the home's own usage check already writes; it is never measured a second time. The displayed figure is the smaller of the session and weekly free fractions, floored, because the tighter window is the one that stops work and a reserve must not read larger than it is. A reading that is absent, unreadable, malformed, or past an hour old renders "olla ?" instead of a figure, including one stamped in the future, which is a clock disagreement rather than freshness. An idle worker re-reads on a timer so a number cannot outlive its shelf life on screen. The module loads lazily behind a guard: a footer nicety must never keep the busy-state and turn-end wiring supervision depends on from registering. Tests colocated in tests/fm-pi-ollama-reserve.test.sh drive the real fm-spawn and its generated artifact; tests/fm-pi-footer-live-e2e.test.sh is the opt-in guard that re-proves the append-not-replace placement after a Pi upgrade, since only Pi decides where a status entry lands.
…nce with fm-spawn header
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Intent
Add the Ollama Cloud reserve to the status line of Pi worker agents, and reimplement nothing that already exists.
Context established before the work started (as of 2026-08-19): Pi already renders, at the bottom of its panel, the working directory, the branch, context consumed against its ceiling (e.g. "18.9%/128k"), tokens exchanged, and the model (e.g. "glm-5.2:cloud"). FOUR of the five elements the captain asked for are already there and MUST NOT be reimplemented.
First required check: the captain asked for this line "like claude code", so he may simply not be seeing it. Establish whether the existing line is visible in his view (herdr backend) or hidden/truncated. If the real defect were masking, fixing that would have been the whole job, with the Ollama reserve as a bonus if the surface allowed it easily. FINDING: a live capture of a running Pi worker's pane shows the existing footer fully visible and untruncated in the captain's view, so masking was not the defect and the real gap was only the missing reserve. This finding is an explicit acceptance criterion and must appear in the PR.
What was missing: the Ollama reserve. quota-axi does not model this provider. The fleet already reads this reserve through the private srv-ollama-usage-watch probe, which writes state/ollama-usage.json with fields session_free, weekly_free, and fetched_at. The implementation must LEAN ON THAT EXISTING SOURCE and must not invent a second measurement that would diverge from it.
Hook surface to establish: pi --help exposes no statusline option. The serious lead was the auto-discovered extension system, since bin/fm-spawn.sh already passes a per-task extension to pi and pi-signed workers via -e state/.pi-ext.ts. The task required establishing whether that surface allows ADDING a segment to the line or only rewriting the line entirely.
ARBITRATION RULE given up front: if the only available route were rewriting the whole line - and therefore reproducing and maintaining the four existing elements at every Pi release - the worker must NOT do it, must post a needs-decision with the finding, and must stop, because that would be a bad trade and the decision belongs to firstmate. FINDING: the arbitration rule does not trigger. Pi's ctx.ui.setStatus(key, text) is a keyed, purely additive surface: it appends an extra footer line BELOW Pi's own lines and never replaces them. This was proven live against Pi 0.84.2 using the extension bin/fm-spawn.sh actually generates, not a hand-written stand-in. Therefore no existing segment is reproduced or maintained by this change.
Display requirements for the reserve, all mandatory:
Acceptance criteria:
Deliberate implementation decisions made while doing the work, which a reviewer reading only the diff would not know:
This work touches firstmate's own shared, tracked material, so the firstmate-coding-guidelines skill was loaded before editing, and its rules were applied: one owner per contract, inline-stub discipline, AGENTS.md size discipline, one sentence per line in tracked Markdown, plain dash instead of em dash, no agent co-author, shellcheck-clean bin scripts via bin/fm-lint.sh, and colocated tests that assert behavior through executable interfaces rather than implementation-source bytes.
What Changed
bin/fm-spawn.shnow embeds an Ollama Cloud reserve segment in the Pi worker extension it generates: it reads the existingsrv-ollama-usage-watchprobe output (state/ollama-usage.json) instead of measuring the quota a second time, and publishes through Pi's keyedctx.ui.setStatus, which appends a line below Pi's own footer, so the working directory, branch, context, tokens, and model Pi already renders are neither replaced nor reproduced. The rendering module is imported lazily behind a shared caught promise so a failed load degrades to no segment without stopping the safety-critical busy-state and turn-end wiring, and the reserve refreshes onsession_start,agent_start, andturn_endplus a once-armed unref'd 60-second timer that republishes only when the rendered text changes..pi/extensions/lib/fm-ollama-reserve.tsowns parsing and formatting: it renders the floored smaller ofsession_freeandweekly_freeas a compactolla 96%, and renders an explicitolla ?when the reading is absent, unreadable, malformed, or stale (staleness is judged in both directions, so a future-stamped reading from a clock disagreement is never presented as fresh; the reason stays in the returned value for diagnostics).tests/fm-pi-ollama-reserve.test.shruns the realfm-spawnand drives the generated extension in a plain Node host, asserting among other things that it touches nothing but its own keyed status entry, while the env-gated, self-skippingtests/fm-pi-footer-live-e2e.test.sh(registered inbin/fm-test-run.sh's live-e2e family) launches real Pi and reads the rendered footer back.docs/verification/runtime-backends.mdrecords the dated live evidence against Pi 0.84.2, including the visibility finding that a running Pi worker's existing footer is fully visible and untruncated in the captain's view, so the only missing element was the reserve;docs/architecture.mdand the harness-adapters skill record the display-vs-supervision boundary of the generated extension.Risk Assessment
✅ Low: Both accepted fix-round changes are correctly applied at the prescribed shared boundary (session_start resets the publish cache; the test settle wait is now bounded polling), the new regression test provably fails before the fix and cannot false-pass, and a full re-pass over all seven changed files surfaced no new issues or intent violations.
Testing
Round 2 : le fix documentaire du round 1 est vérifié appliqué à HEAD conformément aux instructions, puis les deux couches de test ont été re-exécutées - la régression portable (8/8) et la garde live env-gated contre le vrai Pi 0.84.2 (2/2), cette dernière prouvant en bout en bout que le segment « olla NN% » lu depuis la sonde s'ajoute sous le footer intact de Pi et qu'une lecture absente ou périmée rend « olla ? » ; les preuves visuelles du round 1 (PNG/HTML/panes) restent valides car seul le doc a changé depuis, et l'arbre de travail est resté propre.
Evidence: Rendu HTML des trois panes avec annotations
Source: Rendu HTML des trois panes avec annotations
Evidence: Transcription pane - sonde fraîche (olla 85%)
Source: Transcription pane - sonde fraîche (olla 85%)
Evidence: Transcription pane - sonde absente (olla ?)
Source: Transcription pane - sonde absente (olla ?)
Evidence: Transcription pane - sonde périmée de 3 h (olla ?)
Source: Transcription pane - sonde périmée de 3 h (olla ?)
Evidence: Sortie de la garde live re-exécutée à HEAD (Pi 0.84.2)
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
🔧 **Review** - 2 issues found → auto-fixed ✅
bin/fm-spawn.sh:2473- The generated Pi extension's publish-on-change guard (reserveText) survives Pi in-process session replacement while Pi clears its extension-status store, so the reserve segment silently disappears after /new, /resume, or fork. Proven against installed Pi 0.84.2 source: teardownCurrent -> beforeSessionInvalidate -> resetExtensionUI() -> footerDataProvider.clearExtensionStatuses() empties the footer store; the replacement runtime reuses the module-level extensionCache factory (same cwd and generation, loader.js), so the same module instance keeps reserveText; the re-emitted session_start (agent-session.js:1761) then renders unchanged text and renderReserve returns before setStatus, leaving the segment absent for the whole new session until the percentage changes or goes stale (possibly hours). Minimal durable fix at the shared boundary: reset reserveText = null in the session_start handler before renderReserve(ctx), keeping the timer's no-redraw optimization intact.tests/fm-pi-ollama-reserve.test.sh:324- drive_ext waits a fixed 400ms for the lazy module import to settle before reading the recorded calls. Under machine saturation (a failure mode the author already observed on a sibling suite) the import can exceed 400ms and the assertions would flake. Polling the recorded calls for the expected setStatus/register entries with a bounded deadline (e.g. up to 5s) is a mechanical, strictly more robust replacement.🔧 Fix: republish reserve on session_start and poll test settle
✅ Re-checked - no issues remain.
🔧 **Test** - 1 issue found → auto-fixed ✅
docs/verification/runtime-backends.md:947- docs/verification/runtime-backends.md:947 tells the reader to refresh 'this harness-dependent proof before accepting a Pi upgrade' but the command it gives runs the portable regression (bin/fm-test-run.sh tests/fm-pi-ollama-reserve.test.sh), which drives a stub Node host and cannot detect a Pi rendering change. The actual harness-dependent guard is the env-gated live test, and every other section of that file follows the env-gated convention. The command should be: FM_PI_FOOTER_LIVE_E2E=1 bin/fm-test-run.sh tests/fm-pi-footer-live-e2e.test.sh. Doc-only fix, outside the test phase, so reported instead of applied.bash tests/fm-pi-ollama-reserve.test.sh(régression portable : 8 cas, vrai fm-spawn + artefact généré piloté dans un hôte Node enregistreur)FM_PI_FOOTER_LIVE_E2E=1 bash tests/fm-pi-footer-live-e2e.test.sh(garde live : vrai Pi 0.84.2 + vrai tmux, footer relu depuis le pane rendu)Vérification manuelle live : 3 panes Pi 0.84.2 réels (sonde fraîche →olla 85%, sonde absente →olla ?, sonde datée de 3 h →olla ?sans le chiffre périmé) avec l'extension réellement générée parbin/fm-spawn.sh, captures conservées en évidenceContrôle visuel que les quatre segments existants de Pi (cwd + branche, contexte %/plafond, tokens, modèle) restent rendus par Pi au-dessus de la réserve dans les trois panesgit status --porcelainpropre après les runs, répertoires temporaires des tests nettoyés par leurs traps🔧 Fix: point Pi footer refresh command at env-gated live guard
✅ Re-checked - no issues remain.
bin/fm-test-run.sh tests/fm-pi-ollama-reserve.test.sh- régression portable : fm-spawn réel + artefact généré piloté dans un hôte Node avec contexte Pi enregistreur, 8/8 ok (plus petite des deux fenêtres avec plancher, rendu « olla ? » pour absent/malformé/périmé/horodaté dans le futur, la clé de statut propre est la seule chose touchée, le câblage de supervision survit à un module d'affichage qui ne charge pas)FM_PI_FOOTER_LIVE_E2E=1 bin/fm-test-run.sh tests/fm-pi-footer-live-e2e.test.sh- garde live env-gated contre le vrai Pi 0.84.2 via tmux : 2/2 ok, la réserve s'ajoute SOUS les lignes de footer propres de Pi (répertoire, branche, contexte/tokens/modèle conservés) et une sonde absente ou périmée rend « olla ? »Vérification manuelle du diff de 65cea37 contre les instructions user_chose_to_fix du round 1 : édition doc uniquement, commande de rafraîchissement pointée sur la garde live, phrase de justification conservée, rôles des deux tests désambiguïsés, convention env-gated identique aux autres sections (lignes 87, 732, 915 du même fichier)Vérification que les preuves visuelles du round 1 (PNG, HTML, 3 transcriptions de pane) restent représentatives de HEAD : seul un changement de 3 lignes de doc a atterri depuis la capture, le code produit est identiqueContrôles de propreté :git status --porcelainvide, aucun processus pi orphelin, aucun serveur tmux vivant après les tests✅ **Document** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.