Skip to content

fix(web): Use the plan turns the planner on, and a new box plans from its first start - #2098

Merged
frahlg merged 5 commits into
masterfrom
onboarding-plan-on
Nov 28, 2026
Merged

frahlg merged 5 commits into
masterfrom
onboarding-plan-on

Conversation

@frahlg

@frahlg frahlg commented Nov 28, 2026 •

Copy link
Copy Markdown
Member

Problem

Row 4 of the onboarding review (27 Nov) and the "learns your home" part of row 13.

After the setup guide the planner is off (no planner block). The Plan tab's "Use the plan" was greyed out, and the card sent the owner to Settings → Planner → Enabled → Save, then a restart. The style picker and "Manual…" showed before any plan existed. The box also asked "FTW used to sell from the battery on high-price hours. Allow that to continue?" on a new box that never sold: DeriveBatteryExport turned every mode except the passive planner into unknown, so a new box in self_consumption stored unknown, and the upgrade banner shows for any unknown. Before this PR the banner and the checkbox showed together, because .plan-export-row sets display: flex, which beats hidden.

Change

  • "Use the plan" turns the planner on (web/plan-use.js, new). When the planner is off it writes planner.enabled: true through the same POST /api/config that Settings → Planner → Save uses, with the same If-Match ETag. The planner is built at start (config.RestartRequiredFor lists planner.enabled), so it then calls POST /api/restart, the same call the Settings restart dialog makes. Before the restart it sets the mode from GET /api/planner/prefs → mapped_mode, as before, so the box starts in the planner mode. It waits until /api/mpc/plan says the planner runs, then reads again every 3 s until the plan shows. Errors show under the button. If prices or a battery are missing, it stops before the mode and the restart and says what is missing.
  • Waits for the first plan. The style picker and battery export show once a plan exists. Manual… is the only way off the planner on the Plan card, so a battery home in a planner mode always has it, plan or not (no prices for hours, battery offline); a battery in the settings counts while its driver is offline. Manual… waits only on a box that has never planned and runs the default self_consumption. A manual mode other than the default keeps Manual… in reach so its button is on screen. An empty strategy box hides. Manual… shows closed once the plan has taken over.
  • A failed restart can be retried in place. If POST /api/restart fails after the planner setting and mode are saved, the card says "FTW did not restart: … The planner starts after a restart." and shows a "Restart FTW" button, which restarts and waits for the planner as before. The button clears once the planner runs, also when FTW was restarted another way.
  • No sell question for a box that never sold. Core: DeriveBatteryExport answers not_allowed for every mode except planner_arbitrage, so a new box stores not_allowed on its first start, whatever wrote its config. Web: when "Use the plan" turns the planner on from off and the box holds unknown, it records not_allowed, because a planner that was off sold nothing. A box upgraded from active arbitrage still stores unknown and is still asked, as feat(planner): persist forecast trust and battery export permission #968 and fix(control): boot legacy planner modes into passive arbitrage #1991 intended. fix(control): boot legacy planner modes into passive arbitrage #1991 handled the legacy planner modes only; self_consumption still derived unknown. It never writes allowed, and plan-use.js never names the selling mode (test).
  • Learning line. While /api/loadmodel or /api/pvmodel reports learning.status cold_start or learning, the plan's forecast cell adds "FTW learns your home over the first days." Read every 10 min while the planner runs. Right after a start a model reports unavailable for about 5 s, so an unknown stage is read again soon.
  • Right after the owner starts the plan, the box's first try fails with "Waiting for an online battery with capacity and charge level" and retries about 5 s later. For 2 minutes after the tap, that page shows "Preparing the first plan" with that reason instead of "Cannot plan". It also shows a new plan as "Plan ready" until the control loop takes it on its next tick, instead of "Fallback active".
  • A home without a battery (plan capacity_wh: 0) no longer reads "Keep the battery steady" or "Expected charge 0 %", and gets no battery-export question.
  • Copy: the planner-disabled reason says "Use the plan turns it on" instead of pointing to Settings. A manual mode with no prices or no battery shows the blocked brief ("Set a price zone in Settings → Price") instead of "Use the plan to create a schedule" over a disabled button.
  • Planner on from the start drives, on a new box only. seedPlannerMode (go/cmd/ftw/first_boot_mode.go): on its very first start, a box with planner.enabled and no stored control mode starts in the planner mode its battery-export answer maps to (not_allowed gives planner_passive_arbitrage), and stores it like the other first-boot values. What decides "new": the event log in state.db is empty when the box starts, read just before this start records its own startup event (isFirstBoot). Every start of Core records startup and nothing prunes the log; the setup wizard, which stores the settings and house password in a new state.db before the first start, writes no events (tested through bootstrapConfig). A box that ran before, or was restored from a backup, has events, so an existing box with the planner on and no stored mode keeps running self_consumption. A stored mode is never changed. The guide piece (feat(setup): add devices the way Settings does, and test each one #2100) writes planner: {enabled: true, battery_export: "not_allowed"} and relies on this.
  • First plan as soon as the inputs are in. The startup replan runs 2 s after start, usually before the first battery reading and the price fetch, and fails. Only a box in a planner mode retried a missing plan (missing_plan_retry keys on a planner mode with a stale plan), so a box in a manual mode waited for the 15-minute replan; that is what feat(setup): add devices the way Settings does, and test each one #2100 saw. firstPlanWhenReady (go/cmd/ftw/first_plan.go) runs once per process in the existing startup goroutine. It checks every second whether there is a current plan; once prices for the slot in progress and, for a site with a battery, a fresh charge level are in, it asks for one replan (inputs_ready) and ends. The charge level is read through a new health-gated accessor, telemetry.Store.FreshBatterySoCOnline (a charge level within BatterySoCMaxAge from a driver that is online and not calibrating, the planner's own gates), so no direct telemetry read is added. It stops after 15 minutes, when the scheduled replan takes over. It does not touch go/internal/mpc; the main.go hunks are at the boot prefs (~659) and the startup goroutine (~1970), away from feat(planner): count the energy tax refund on battery energy sent back #1956 (1685) and feat(planner): plan each battery within what it has shown it can do #2072 (1737).
  • "Plan without extra forecast margin" on a first plan. Cause, from the warning on a new box: "forecast caution requires extra house load to obey site policy: slot 8 violates mode passive_arbitrage: baseline_grid_w=1720 grid_w=-204 battery_w=-1925". Until FTW has its own measured forecast errors, caution adds load from a prior band (forecast_tracking.go, the non-empirical path). The cautious plan covers that extra load from the battery. Replayed at the point forecast, that battery energy would be sold, which passive mode forbids, so Core drops the cautious plan and runs the point plan. The plan that runs passes every check; no limit is breached. It is a cold-start effect: wide prior bands make it likely. It can still happen later in a slot where caution adds load at night, but it is rarer once measured errors set the band. So while /api/loadmodel or /api/pvmodel reports cold_start or learning, the card shows the plan as usual, with no warning badge and no margin text; the learning line covers that time. After learning, the warning shows as before.
  • A home without a battery: no planning style, battery export or Manual… (their modes are all battery modes; a manual mode someone picked still shows). No "Why" row for a quiet step; the next step reads "No change planned". The planner-off brief says "The planner is off".
  • web/app.js loses the old "Use the plan" handler and its visibility lines; plan.js owns the button now, because only plan.js knows whether the planner runs. No other app.js hunks.

Changeset: patch. A new box that starts in the planner mode is a visible change to how a box behaves; if you count that or the new-box export default as needing your sign-off, say so and I make it minor.

Evidence

Tests:

  • npm test: 1052 pass, 0 fail on the final head (rebased on master 655fcca3, with feat(setup): add devices the way Settings does, and test each one #2100 and fix(web): the overview names a device that does not answer #2097). New: web/plan-use.test.mjs (the card view, including Manual… in a planner mode without a plan; the start flow with a fake box, including a failed restart and restartForPlanner; the restart wait); new cases in plan-brief.test.mjs; mode-picker.test.mjs (Restart FTW in place), plan-unavailable.test.mjs and plan-polling.test.mjs follow the move to plan.js.
  • go test ./internal/config/ -run 'Planner|Derive|Export|Resolve', go test -race ./cmd/ftw/ -run 'SeedPlannerMode|FirstBoot|WizardBox|FirstPlan|PlanInputsReady|RestoreStoredMode|MissingPlan|Charge|Bootstrap': pass. New: TestResolvePlannerPrefsNewBoxDoesNotAsk; TestSeedPlannerModeOnlyOnABrandNewBox (brand-new box with the planner on → planner mode; planner off or no planner block → self_consumption as today; existing box with a boot record, the planner on and no stored mode → stays self_consumption; stored self_consumption, idle or planner mode → unchanged), TestSeedPlannerModeOnlyOnce, TestFirstBootAfterTheWizardStoredSettings and TestWizardBoxStartsInThePlannerMode (the wizard's save path, then the first start); TestFirstPlanWhenReady* (one replan once the inputs are ready; none over a current plan or a replan in flight; none without inputs; replaces an outdated restored plan) and TestPlanInputsReady (prices; a fresh charge level when a battery is planned; a too-old one does not count).
  • make verify (nice, GOFLAGS=-p=3) on the final head: "verify: vet + test + build clean", 88 Go packages ok. TELEMETRY_READS_BASE_SHA=origin/master bash .github/scripts/check-telemetry-reads.sh origin/master: "133, none added". go test -race ./internal/telemetry/ passes, with new TestFreshBatterySoCOnline (no battery, no health yet, too old, offline) and TestFreshBatterySoCOnlineSkipsCalibrating.

New box, the guide piece's config (planner: {enabled: true, battery_export: not_allowed}, no stored mode), fresh data dir, nobody taps anything:

  • Source build: "no stored control mode and the planner is on: starting in the planner mode", then the plan from inputs_ready 5.2 s after the first start (06:57:38.8 → 06:57:44.0). The page shows "Plan active · Charge battery at 5.0 kW" and the learning line; "Use the plan" is hidden; status planner_passive_arbitrage, fresh, as_planned, export not_allowed.
  • Release build with Energyplan: first plan 5.1 s after the first start (inputs_ready, native / value_curve_rust). caution_off is true with the cold-start warning, and the badge reads "Plan active".
  • Release build, home without a battery: first plan 2.1 s after the first start (startup, fleet_milp_rust). "Plan active · No change planned", forecast with the learning line, no Why row, no strategy box.
  • Master with the same config: the box stays in self_consumption and has no plan 90 s after start.
  • A box with the planner on and a stored self_consumption, restarted: first plan 5.1 s after start via inputs_ready, mode unchanged.
  • An existing box: started on master with the guide's config (no stored mode, runs self_consumption), then started on this branch: it stays self_consumption; it gets its plan via inputs_ready, ready but not driving. The same config on a fresh data dir: planner mode, first plan 5.2 s after the first start.

Source build (macOS, Core DP), in-tree sim-sungrow, Core on port 8132, fresh data dir, supervised so a restart exits and starts again as systemd does. The box was made by the master build (planner off, export stored unknown), then started on this branch, as an existing box would be after an update. Headless Chrome tapped "Use the plan":

  • the config write and restart took about 1.1 s; the box planned 6.4 s after the write; the page showed the plan 7.7–8.0 s after the tap, at 1280×900 and 390×844.
  • battery_export went from unknown to not_allowed; no banner.
  • A box with no price zone: the tap shows "Planning needs electricity prices. Set a price zone in Settings → Price." under the button, and the mode is not changed.

Browser checks for the last round (source build, port 8132):

  • Planner mode with no price zone: "Cannot plan", the hint names the price zone, and Manual… shows.
  • POST /api/restart made to fail in the page (fetch wrapped to answer 503): the error and "Restart FTW" show under the briefing, "Use the plan" hides; with the wrap removed, "Restart FTW" restarted the box and the plan showed 7.5 s later.

Release build: VERSION=v0.169.1-beta.900 scripts/build-core.sh linux arm64, packed with scripts/package-linux.py arm64 (Energyplan worker from optimizer/native/bundle), run from the tarball in a debian:trixie-slim arm64 container. A shell loop restarted Core after each exit, as systemd does, with no launcher. Fresh data dir, port 8132:

  • Battery home (sim-sungrow): the plan came from Energyplan (native / value_curve_rust, status optimal) and showed 7.7–7.8 s after the tap. Core restarted in 1.1 s and planned 6.4 s after the config write. The first plan reads "Plan without extra forecast margin" (see questions).
  • Home without a battery (meter only: esphome_dsmr against a static JSON server): fleet_milp_rust planned at once; the page showed "Plan active · No change planned" 1.7 s after the tap. The forecast cell says "Published prices · Plan until Sat 24:00 · FTW learns your home over the first days." There is no battery export question. The planning style still shows, with battery words.

Screenshots (before, after, release, new box): before-*, after-*, release-bat-*, release-nobat-*, newbox-plan-*, release-newbox-*, 1280×900 and 390×844. They were taken on a local machine and are not attached.

Not tested

  • Real hardware, a Raspberry Pi, amd64.
  • The Home Assistant app, which re-execs on restart instead of exiting.
  • The native launcher with systemd. A Settings restart marks a clean exit for the launcher's probation (nativeupdate.MarkCleanExit); I read that in the code and did not run it.
  • LAN password on: sessions are restored from state, so polls should carry on after the restart; not run.
  • Measurement-only mode.

Coordination

Refs #968, #1991

🤖 Generated with Claude Code

@frahlg
frahlg force-pushed the onboarding-plan-on branch from fb3b01b to 1959b60 Compare November 28, 2026 06:02
@frahlg frahlg changed the title fix(web): Use the plan turns the planner on fix(web): Use the plan turns the planner on, and a new box plans from its first start Nov 28, 2026
@frahlg
frahlg force-pushed the onboarding-plan-on branch 2 times, most recently from 34a4504 to 12c5a29 Compare November 28, 2026 06:15
frahlg and others added 5 commits November 28, 2026 07:20
On a box the setup guide made, the planner was off and "Use the plan"
was greyed out; the card sent the owner to Settings → Planner → Enabled
→ Save and a restart. The button now does that itself: it saves the
same setting through the Settings write, restarts FTW when the planner
has to start, hands the house to the plan and reads again every 3 s
until the plan shows. An error shows under the button.

The planning style, battery export and Manual… wait for the first plan,
and a home without a battery no longer reads about a battery. While
the forecast models still learn, the plan's forecast says "FTW learns
your home over the first days."

A box that never sold from the battery no longer asks whether selling
may continue. DeriveBatteryExport answers not_allowed for every mode
but active arbitrage, so a new box stores not_allowed. Turning the
planner on from off records not_allowed for a box that stored unknown.
An upgrade from active arbitrage is still asked, as #968 and
#1991 intended.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Fredrik Ahlgren <fredrik@sourceful-labs.com>
Planner on from the start now means the plan drives. A box with the
planner on in its config and no stored control mode starts in the
planner mode its battery-export answer maps to, and stores it like the
other first-boot values. A stored mode is kept.

The startup replan runs 2 s after start, often before the first
battery reading and prices, and failed. Only a planner mode retried a
missing plan, so any other box waited for the 15-minute replan. Core
now replans once as soon as prices and, for a site with a battery, a
fresh charge level are in. On a test box the first plan came 5 s after
the first start; master gave none in 90 s.

While the forecast models still learn, caution takes its margin from
priors, its alternative fails replay on a first plan and the box runs
the valid point plan. The card no longer shows that as "Plan without
extra forecast margin"; the learning line covers that time.

A home without a battery gets no planning style, battery export or
manual modes, and no "Why: Idle".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Fredrik Ahlgren <fredrik@sourceful-labs.com>
An existing box with the planner on in its config that never stored a
mode has run self_consumption all along. The seed would have handed it
to the planner on its next start without its owner choosing that.

The seed now needs a first start too. Core records a "startup" event at
every start and never prunes the event log, and the setup wizard writes
none, so an empty log read before this start records its own marks a
new box. A box that ran before, or was restored from a backup, has
events and keeps its mode.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Fredrik Ahlgren <fredrik@sourceful-labs.com>
Manual… is the only way off the planner on the Plan card. It waited for
a plan, so a battery home in a planner mode with no plan (no prices for
hours, or the battery offline) could not leave the planner from there.
It now shows in a planner mode with a battery, plan or not, and waits
only on a box that has never planned and runs the default mode. A
battery in the settings counts while its driver is offline.

When the restart after "Use the plan" fails, the planner setting and
the mode are already saved. The card says so in place and offers
"Restart FTW", which restarts and waits for the planner as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Fredrik Ahlgren <fredrik@sourceful-labs.com>
…cessor

The first-plan wait read battery readings straight from the telemetry
cache, which the telemetry-read check refuses. telemetry gains
FreshBatterySoCOnline: a charge level within BatterySoCMaxAge from a
driver that is online and not calibrating, the planner's own gates on
its starting charge. The wait uses it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Fredrik Ahlgren <fredrik@sourceful-labs.com>
@frahlg
frahlg force-pushed the onboarding-plan-on branch from 12c5a29 to e1141c8 Compare November 28, 2026 06:25
@frahlg
frahlg marked this pull request as ready for review November 28, 2026 06:51
@frahlg
frahlg merged commit 4b95589 into master Nov 28, 2026
22 checks passed
@frahlg
frahlg deleted the onboarding-plan-on branch November 28, 2026 06:51
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 28, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-28T06:53:37.415378Z e1141c8 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant