fix(companion): move step detection from Init() to NewModel()#65
Merged
xlanor merged 1 commit intoJul 25, 2026
Merged
Conversation
bubbletea uses value receivers — Init() receives a copy of the model and any mutations to that copy are silently discarded. Only the returned tea.Cmd is used; the modified model is never seen by the runtime. Because of this, the step-detection logic placed in Init() had no effect: the app always started at StepDUID even when a valid DUID and unexpired tokens were already saved in state.json. Moving the same logic into NewModel() fixes the initialization so the app opens directly at StepServer when credentials are already complete, or at StepLogin when only the DUID is present. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Owner
|
Can you provide a repro scenario of what led you to this bug? |
Contributor
Author
|
Repro steps:
Expected: the app opens directly at Step 3 (Server) since Actual: the app always opens at Step 1 (DUID) regardless of saved state, forcing the user to navigate through steps they already completed. Root cause: bubbletea calls |
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.
Bug
In bubbletea,
Init()uses a value receiver — it receives a copy of the model. Any mutations made insideInit()are silently discarded; only the returnedtea.Cmdis used by the runtime.The step-detection logic was placed in
Init():Because the mutations are discarded, the app always starts at StepDUID regardless of saved state — even when a valid DUID and unexpired tokens are already present in
state.json.Fix
Move the step-detection logic into
NewModel()where it can set the field on the struct value being returned:Result
The companion app now opens directly at the correct step:
🤖 Generated with Claude Code