Repository navigation
fix(app): confirm a mode change as soon as it is applied - #832
Conversation
mpc.SetMode replans before it returns, and the Python optimizer can take longer than the fifteen seconds the app waits for a command result. So a mode change that had already been applied, persisted and read back was reported "unconfirmed" — the truthful word for the wrong reason. The forced replan now runs off the command path, under a context that survives the session: the replan belongs to the mode change, not to the socket that asked for it. The app's side (srcfl/ftw-webapp#7) follows the plan until its revision moves, since the push that follows "applied" can still carry the old mode's plan. Co-Authored-By: Claude Opus 5 <[email protected]>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3fc1553e11
ℹ️ 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| // WithoutCancel: the replan belongs to the mode change, not to the | ||
| // session that asked for it. A phone that drops its socket right | ||
| // after tapping must not abort the planner mid-run. | ||
| go a.mpc.SetMode(context.WithoutCancel(ctx), mm) |
There was a problem hiding this comment.
Push the plan only after the async replan completes
When the Python optimizer is slow, this goroutine makes appModes.SetMode return before mpc.SetMode has updated s.last, but the app command handler immediately calls sendPlan(nil) after SetMode returns on an applied mode change. That means the app now receives the previous plan (or a stale/no-plan response on first run), and there is no later automatic app push from mpc.replan itself — the only sendPlan call sites are the command path and explicit plan.get. Please move the app plan push to run after this replan completes, or suppress the immediate stale push and add a real completion notification.
Useful? React with 👍 / 👎.
Found by the live test on beta.6:
set_modecame backunconfirmedeventhough the mode had been applied, persisted and read back.
mpc.SetModereplans before returning, and the Python optimizer can takelonger than the fifteen seconds the app waits for a command result. The
command path was paying for a computation it does not need: the mode is
already set in control and persisted before the planner is told.
The forced replan now runs in its own goroutine under
context.WithoutCancel— the replan belongs to the mode change, not tothe session that asked for it, and a phone dropping its socket right after
tapping must not abort the planner mid-run.
Trade: the plan pushed right after
appliedcan still be the old mode's.srcfl/ftw-webapp#7 handles that on the app side by following the plan
until its revision moves.
🤖 Generated with Claude Code