Repository navigation
fix(web): Use the plan turns the planner on, and a new box plans from its first start - #2098
Merged
Merged
Conversation
frahlg
force-pushed
the
onboarding-plan-on
branch
from
November 28, 2026 06:02
fb3b01b to
1959b60
Compare
frahlg
force-pushed
the
onboarding-plan-on
branch
2 times, most recently
from
November 28, 2026 06:15
34a4504 to
12c5a29
Compare
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
force-pushed
the
onboarding-plan-on
branch
from
November 28, 2026 06:25
12c5a29 to
e1141c8
Compare
frahlg
marked this pull request as ready for review
November 28, 2026 06:51
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
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.
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
plannerblock). 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:DeriveBatteryExportturned every mode except the passive planner intounknown, so a new box inself_consumptionstoredunknown, and the upgrade banner shows for anyunknown. Before this PR the banner and the checkbox showed together, because.plan-export-rowsetsdisplay: flex, which beatshidden.Change
web/plan-use.js, new). When the planner is off it writesplanner.enabled: truethrough the samePOST /api/configthat Settings → Planner → Save uses, with the sameIf-MatchETag. The planner is built at start (config.RestartRequiredForlistsplanner.enabled), so it then callsPOST /api/restart, the same call the Settings restart dialog makes. Before the restart it sets the mode fromGET /api/planner/prefs → mapped_mode, as before, so the box starts in the planner mode. It waits until/api/mpc/plansays 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.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.POST /api/restartfails 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.DeriveBatteryExportanswersnot_allowedfor every mode exceptplanner_arbitrage, so a new box storesnot_allowedon its first start, whatever wrote its config. Web: when "Use the plan" turns the planner on from off and the box holdsunknown, it recordsnot_allowed, because a planner that was off sold nothing. A box upgraded from active arbitrage still storesunknownand 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_consumptionstill derivedunknown. It never writesallowed, and plan-use.js never names the selling mode (test)./api/loadmodelor/api/pvmodelreportslearning.statuscold_startorlearning, 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 reportsunavailablefor about 5 s, so an unknown stage is read again soon.capacity_wh: 0) no longer reads "Keep the battery steady" or "Expected charge 0 %", and gets no battery-export question.planner-disabledreason 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.seedPlannerMode(go/cmd/ftw/first_boot_mode.go): on its very first start, a box withplanner.enabledand no stored control mode starts in the planner mode its battery-export answer maps to (not_allowedgivesplanner_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 ownstartupevent (isFirstBoot). Every start of Core recordsstartupand 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 throughbootstrapConfig). 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 runningself_consumption. A stored mode is never changed. The guide piece (feat(setup): add devices the way Settings does, and test each one #2100) writesplanner: {enabled: true, battery_export: "not_allowed"}and relies on this.missing_plan_retrykeys 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 withinBatterySoCMaxAgefrom 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 touchgo/internal/mpc; themain.gohunks 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).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/loadmodelor/api/pvmodelreportscold_startorlearning, 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.web/app.jsloses 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 master655fcca3, 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 andrestartForPlanner; the restart wait); new cases inplan-brief.test.mjs;mode-picker.test.mjs(Restart FTW in place),plan-unavailable.test.mjsandplan-polling.test.mjsfollow 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_consumptionas today; existing box with a boot record, the planner on and no stored mode → staysself_consumption; storedself_consumption,idleor planner mode → unchanged),TestSeedPlannerModeOnlyOnce,TestFirstBootAfterTheWizardStoredSettingsandTestWizardBoxStartsInThePlannerMode(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) andTestPlanInputsReady(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 newTestFreshBatterySoCOnline(no battery, no health yet, too old, offline) andTestFreshBatterySoCOnlineSkipsCalibrating.New box, the guide piece's config (
planner: {enabled: true, battery_export: not_allowed}, no stored mode), fresh data dir, nobody taps anything:inputs_ready5.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; statusplanner_passive_arbitrage, fresh,as_planned, exportnot_allowed.inputs_ready,native / value_curve_rust).caution_offis true with the cold-start warning, and the badge reads "Plan active".startup,fleet_milp_rust). "Plan active · No change planned", forecast with the learning line, no Why row, no strategy box.self_consumptionand has no plan 90 s after start.self_consumption, restarted: first plan 5.1 s after start viainputs_ready, mode unchanged.self_consumption), then started on this branch: it staysself_consumption; it gets its plan viainputs_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 storedunknown), then started on this branch, as an existing box would be after an update. Headless Chrome tapped "Use the plan":battery_exportwent fromunknowntonot_allowed; no banner.Browser checks for the last round (source build, port 8132):
POST /api/restartmade 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 withscripts/package-linux.py arm64(Energyplan worker fromoptimizer/native/bundle), run from the tarball in adebian:trixie-slimarm64 container. A shell loop restarted Core after each exit, as systemd does, with no launcher. Fresh data dir, port 8132: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).esphome_dsmragainst a static JSON server):fleet_milp_rustplanned 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
nativeupdate.MarkCleanExit); I read that in the code and did not run it.Coordination
planner: {enabled: true, battery_export: "not_allowed"}; with this PR that box starts in the planner mode and plans about 5 s after its first start.planner_prefs.go.battery_exportunknownas "no answer" and show no upgrade banner, so the Core change needs nothing from them.Refs #968, #1991
🤖 Generated with Claude Code