feat(dev): show a cached (N ready) hint on the lab AFK menu #79

Merged
dominik.polakovics merged 1 commit from afk/66 into main 2026-06-02 16:12:36 +02:00

Surfaces how many ready-for-agent issues a project has on the per-project ⋯ menu's Start AFK run control, using only the auto scheduler's in-memory cache so the per-poll render never blocks on tea.

What changed

  • Scheduler caches the count. scheduleAFKRuns already lists each auto-on project's ready queue every sweep but kept only a boolean; it now records len(ReadyIssues) in a new project-name-keyed, mutex-guarded map on the Server (afkReady), captured before the launch gate so the hint updates whether or not a run launches.
  • In-memory only. The count is never persisted (not added to projectState/the store JSON): it re-derives within one sweep after a restart, where a stale value carried across would mislead.
  • No tea on the render path. snapshot populates projectGroup.ReadyCount/ReadyKnown from the cache via a locked map read — no tea/Tracker call is added to the per-poll render.
  • Pure display helper. afkStartHint(autoEnabled, count, known) -> {suffix, greyed} (mirroring shouldLaunchAuto/classifyAFKRun) maps the three states: unknown → plain "Start AFK run"; cached N>0 → "Start AFK run (N ready)"; cached zero → "(0 ready)" greyed.
  • Greyed but clickable at zero. A cached zero greys the control as a hint (CSS color only, no pointer-events/disabled) yet stays a real submit button, so a stale zero never blocks the authoritative click — submitting an empty queue still flashes the existing "No ready-for-agent issues to start." notice (ADR-0007). The count shows only while the auto toggle is on, so cold auto-off projects show no count.

Tests

  • TestAFKStartHint — table-driven over unknown / N>0 / zero / auto-off.
  • TestScheduleAFKRuns_cachesReadyCount and ...EvenWhenNoLaunch — the sweep caches the count, including on a tick that launches nothing.
  • TestScheduleAFKRuns_readyCountNotPersisted — restart simulation proves the count is in-memory only while the persisted auto toggle survives.
  • TestLivePartial_afkStartReadyHint — renders the three states + auto-off gate through the template, asserting the zero state is greyed yet still a submit button (not the disabled span).

go build ./..., go vet ./..., and go test ./... all pass in the lab module; the repo pre-commit hook (eval-only) passed on commit.

Closes #66

Surfaces how many ready-for-agent issues a project has on the per-project ⋯ menu's *Start AFK run* control, using only the auto scheduler's in-memory cache so the per-poll render never blocks on `tea`. ## What changed - **Scheduler caches the count.** `scheduleAFKRuns` already lists each auto-on project's ready queue every sweep but kept only a boolean; it now records `len(ReadyIssues)` in a new project-name-keyed, mutex-guarded map on the `Server` (`afkReady`), captured *before* the launch gate so the hint updates whether or not a run launches. - **In-memory only.** The count is never persisted (not added to `projectState`/the store JSON): it re-derives within one sweep after a restart, where a stale value carried across would mislead. - **No tea on the render path.** `snapshot` populates `projectGroup.ReadyCount`/`ReadyKnown` from the cache via a locked map read — no `tea`/Tracker call is added to the per-poll render. - **Pure display helper.** `afkStartHint(autoEnabled, count, known) -> {suffix, greyed}` (mirroring `shouldLaunchAuto`/`classifyAFKRun`) maps the three states: *unknown* → plain "Start AFK run"; *cached N>0* → "Start AFK run (N ready)"; *cached zero* → "(0 ready)" greyed. - **Greyed but clickable at zero.** A cached zero greys the control as a hint (CSS `color` only, no `pointer-events`/`disabled`) yet stays a real submit button, so a stale zero never blocks the authoritative click — submitting an empty queue still flashes the existing "No ready-for-agent issues to start." notice (ADR-0007). The count shows only while the auto toggle is on, so cold auto-off projects show no count. ## Tests - `TestAFKStartHint` — table-driven over unknown / N>0 / zero / auto-off. - `TestScheduleAFKRuns_cachesReadyCount` and `...EvenWhenNoLaunch` — the sweep caches the count, including on a tick that launches nothing. - `TestScheduleAFKRuns_readyCountNotPersisted` — restart simulation proves the count is in-memory only while the persisted auto toggle survives. - `TestLivePartial_afkStartReadyHint` — renders the three states + auto-off gate through the template, asserting the zero state is greyed yet still a submit button (not the disabled span). `go build ./...`, `go vet ./...`, and `go test ./...` all pass in the lab module; the repo pre-commit hook (eval-only) passed on commit. Closes #66
The auto scheduler already lists each auto-on project's ready-for-agent queue every sweep but kept only a boolean. Cache the count in an in-memory, project-name-keyed map on the server and surface it on the per-project menu's Start AFK run control as "(N ready)", greying — but never disabling — the control at a cached zero.

- scheduler records len(ReadyIssues) per swept auto-on project, before the launch gate, so the hint updates whether or not a run launches
- count is in-memory only (not persisted): it re-derives within one sweep after a restart, where a stale value carried across would mislead
- the render path reads only the cache (a locked map lookup) — no tea call is added to the per-poll snapshot
- a cached zero greys the control as a hint but keeps it a real submit button, so the authoritative click is never blocked (ADR-0007)
- pure afkStartHint helper maps (autoEnabled, count, known) -> suffix + greyed, table-tested across unknown / N>0 / zero
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Cloonar/nixos!79
No description provided.