Skip to content

fix(app): confirm a mode change as soon as it is applied - #832

Merged
frahlg merged 1 commit into
masterfrom
mode-ack-before-replan
Aug 5, 2026
Merged

frahlg merged 1 commit into
masterfrom
mode-ack-before-replan

Conversation

@frahlg

@frahlg frahlg commented Aug 5, 2026

Copy link
Copy Markdown
Member

Found by the live test on beta.6: set_mode came back unconfirmed even
though the mode had been applied, persisted and read back.

mpc.SetMode replans before returning, and the Python optimizer can take
longer 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 to
the 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 applied can 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

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]>
@frahlg
frahlg merged commit 55d7f37 into master Aug 5, 2026
13 checks passed
@frahlg
frahlg deleted the mode-ack-before-replan branch August 5, 2026 16:02

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread go/cmd/ftw/app_link.go
// 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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

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