Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@draftcode
Copy link
Contributor

Previously, av sync was using message passing to signal subcomponent
results. By sending out a special message to the bubbletea message bus,
the parent component can tell if a subcomponent finishes its process.
For example, sequencerui had three messages, Conflict, Abort, and Done,
to indicate its processing result.

While this works, it becomes complicated to handle those messages. As we
add more subcomponents, we need to handle the messages in a central
message handling function.

Instead of using message passing for signaling the results, use
continuation passing style to handle the results. This style is already
employed in the official API such as ExecProcess
(https://pkg.go.dev/github.com/charmbracelet/bubbletea#ExecProcess).

The benefit of the continuation passing style in av is that we can
write the processing flow from top to bottom. The passed continuation
indicates what will be done after one step. This reduces the number of
messages that we need to handle in the message handler.

Also, because av is doing processing step-by-step, it turned out that
we just can forward most of the messages to the last subcomponent. This
greatly simplifies the message handling code as well as the rendering
code.

Overall, this reduces the complexity of the implementation structure.

Previously, `av sync` was using message passing to signal subcomponent
results. By sending out a special message to the bubbletea message bus,
the parent component can tell if a subcomponent finishes its process.
For example, sequencerui had three messages, Conflict, Abort, and Done,
to indicate its processing result.

While this works, it becomes complicated to handle those messages. As we
add more subcomponents, we need to handle the messages in a central
message handling function.

Instead of using message passing for signaling the results, use
continuation passing style to handle the results. This style is already
employed in the official API such as ExecProcess
(https://pkg.go.dev/github.com/charmbracelet/bubbletea#ExecProcess).

The benefit of the continuation passing style in `av` is that we can
write the processing flow from top to bottom. The passed continuation
indicates what will be done after one step. This reduces the number of
messages that we need to handle in the message handler.

Also, because `av` is doing processing step-by-step, it turned out that
we just can forward most of the messages to the last subcomponent. This
greatly simplifies the message handling code as well as the rendering
code.

Overall, this reduces the complexity of the implementation structure.
@draftcode draftcode requested a review from a team as a code owner October 1, 2025 08:05
@aviator-app
Copy link
Contributor

aviator-app bot commented Oct 1, 2025

Current Aviator status

Aviator will automatically update this comment as the status of the PR changes.
Comment /aviator refresh to force Aviator to re-examine your PR (or learn about other /aviator commands).

This PR was merged using Aviator.


See the real-time status of this PR on the Aviator webapp.
Use the Aviator Chrome Extension to see the status of your PR within GitHub.

@aviator-app
Copy link
Contributor

aviator-app bot commented Oct 1, 2025

✅ FlexReview Status

Common Owner: aviator-co/engineering (expert-load-balance assignment)
Owner and Assignment:

  • aviator-co/engineering (expert-load-balance assignment)
    Owned Files
    • 🔒 cmd/av/commit_common.go
    • 🔒 cmd/av/reparent.go
    • 🔒 cmd/av/restack.go
    • 🔒 cmd/av/sync.go
    • 🔒 internal/gh/ghui/fetch.go
    • 🔒 internal/gh/ghui/push.go
    • 🔒 internal/git/gitui/prune.go
    • 🔒 internal/sequencer/sequencerui/ui.go

Review SLO: 7 business hours if PR size is <= 200 LOC for the first response.
❕ This PR modifies 620 lines, which is larger than the Review SLO threshold.

@aviator-app aviator-app bot requested a review from simsinght October 1, 2025 08:05
@gemini-code-assist
Copy link

Summary of Changes

Hello @draftcode, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a significant architectural refactoring to the av sync command and its underlying UI components, transitioning from a message-passing paradigm to a continuation-passing style. This change aims to reduce complexity, improve code readability, and centralize the flow of execution by allowing subcomponents to directly trigger the next logical step in a sequence, rather than relying on a global message bus. The refactoring impacts how UI models are initialized, updated, and how their completion or state changes are communicated, leading to a more explicit and manageable control flow.

Highlights

  • Refactored UI Control Flow: The primary change is a shift from message passing to continuation passing style for signaling subcomponent results within the av sync command and related UI components. This simplifies the overall control flow and reduces the need for a central message handling function.
  • Simplified Message Handling: By adopting continuation passing, many explicit message types (e.g., RestackConflict, GitHubFetchDone) have been removed. Subcomponents now directly invoke callbacks provided by their parent, streamlining the Update logic in syncViewModel.
  • Centralized Subcomponent Management: The syncViewModel now uses a views []tea.Model slice to manage active subcomponents, forwarding messages to the currently active view. This replaces individual model fields and associated boolean flags, making the UI state management more modular.
  • Enhanced sequencerui.RestackModel: The RestackModel now accepts a RestackStateOptions struct, allowing callers to define OnConflict, OnAbort, and OnDone callbacks directly. This makes the restack process more flexible and integrates better with the new continuation passing style.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request is a great refactoring that simplifies the application's architecture by using continuation-passing style instead of message passing for subcomponent results. This makes the code flow more linear and easier to understand. The changes are consistently applied across all relevant components. My review includes a few suggestions to further improve maintainability by reducing some minor code duplication that was introduced.

Comment on lines 37 to 65
func (vm *postCommitRestackViewModel) Init() tea.Cmd {
state, err := vm.createState()
var err error
vm.state, err = vm.createState()
if err != nil {
return uiutils.ErrCmd(err)
}
vm.restackModel = sequencerui.NewRestackModel(vm.repo, vm.db)
vm.restackModel.State = state
vm.restackModel = sequencerui.NewRestackModel(vm.repo, vm.db, vm.state, sequencerui.RestackStateOptions{
OnConflict: func() tea.Cmd {
if err := vm.writeState(vm.state); err != nil {
return uiutils.ErrCmd(err)
}
vm.quitWithConflict = true
return tea.Quit
},
OnAbort: func() tea.Cmd {
if err := vm.writeState(nil); err != nil {
return uiutils.ErrCmd(err)
}
return tea.Quit
},
OnDone: func() tea.Cmd {
if err := vm.writeState(nil); err != nil {
return uiutils.ErrCmd(err)
}
return tea.Quit
},
})
return vm.restackModel.Init()
}

Choose a reason for hiding this comment

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

medium

The OnAbort and OnDone handlers are identical. To reduce code duplication and improve maintainability, you can define a shared function for this logic within the Init method.

func (vm *postCommitRestackViewModel) Init() tea.Cmd {
	var err error
	vm.state, err = vm.createState()
	if err != nil {
		return uiutils.ErrCmd(err)
	}
	onFinish := func() tea.Cmd {
		if err := vm.writeState(nil); err != nil {
			return uiutils.ErrCmd(err)
		}
		return tea.Quit
	}
	vm.restackModel = sequencerui.NewRestackModel(vm.repo, vm.db, vm.state, sequencerui.RestackStateOptions{
		OnConflict: func() tea.Cmd {
			if err := vm.writeState(vm.state); err != nil {
				return uiutils.ErrCmd(err)
			}
			vm.quitWithConflict = true
			return tea.Quit
		},
		OnAbort: onFinish,
		OnDone:  onFinish,
	})
	return vm.restackModel.Init()
}

Comment on lines 69 to 97
func (vm *reparentViewModel) Init() tea.Cmd {
state, err := vm.createState()
var err error
vm.state, err = vm.createState()
if err != nil {
return uiutils.ErrCmd(err)
}
vm.restackModel = sequencerui.NewRestackModel(vm.repo, vm.db)
vm.restackModel.State = state
vm.restackModel = sequencerui.NewRestackModel(vm.repo, vm.db, vm.state, sequencerui.RestackStateOptions{
OnConflict: func() tea.Cmd {
if err := vm.writeState(vm.state); err != nil {
return uiutils.ErrCmd(err)
}
vm.quitWithConflict = true
return tea.Quit
},
OnAbort: func() tea.Cmd {
if err := vm.writeState(nil); err != nil {
return uiutils.ErrCmd(err)
}
return tea.Quit
},
OnDone: func() tea.Cmd {
if err := vm.writeState(nil); err != nil {
return uiutils.ErrCmd(err)
}
return tea.Quit
},
})
return vm.restackModel.Init()
}

Choose a reason for hiding this comment

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

medium

The OnAbort and OnDone handlers are identical. To reduce code duplication and improve maintainability, you can define a shared function for this logic within the Init method.

func (vm *reparentViewModel) Init() tea.Cmd {
	var err error
	vm.state, err = vm.createState()
	if err != nil {
		return uiutils.ErrCmd(err)
	}
	onFinish := func() tea.Cmd {
		if err := vm.writeState(nil); err != nil {
			return uiutils.ErrCmd(err)
		}
		return tea.Quit
	}
	vm.restackModel = sequencerui.NewRestackModel(vm.repo, vm.db, vm.state, sequencerui.RestackStateOptions{
		OnConflict: func() tea.Cmd {
			if err := vm.writeState(vm.state); err != nil {
				return uiutils.ErrCmd(err)
			}
			vm.quitWithConflict = true
			return tea.Quit
		},
		OnAbort: onFinish,
		OnDone:  onFinish,
	})
	return vm.restackModel.Init()
}

Comment on lines +78 to +102
vm.restackModel = sequencerui.NewRestackModel(vm.repo, vm.db, vm.state, sequencerui.RestackStateOptions{
Abort: restackFlags.Abort,
Continue: restackFlags.Continue,
Skip: restackFlags.Skip,
DryRun: restackFlags.DryRun,
OnConflict: func() tea.Cmd {
if err := vm.writeState(vm.state); err != nil {
return uiutils.ErrCmd(err)
}
vm.quitWithConflict = true
return tea.Quit
},
OnAbort: func() tea.Cmd {
if err := vm.writeState(nil); err != nil {
return uiutils.ErrCmd(err)
}
return tea.Quit
},
OnDone: func() tea.Cmd {
if err := vm.writeState(nil); err != nil {
return uiutils.ErrCmd(err)
}
return tea.Quit
},
})

Choose a reason for hiding this comment

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

medium

The OnAbort and OnDone handlers in the RestackStateOptions are identical. To reduce code duplication, you can define a shared function for this logic.

	onFinish := func() tea.Cmd {
		if err := vm.writeState(nil); err != nil {
			return uiutils.ErrCmd(err)
		}
		return tea.Quit
	}
	vm.restackModel = sequencerui.NewRestackModel(vm.repo, vm.db, vm.state, sequencerui.RestackStateOptions{
		Abort:    restackFlags.Abort,
		Continue: restackFlags.Continue,
		Skip:     restackFlags.Skip,
		DryRun:   restackFlags.DryRun,
		OnConflict: func() tea.Cmd {
			if err := vm.writeState(vm.state); err != nil {
				return uiutils.ErrCmd(err)
			}
			vm.quitWithConflict = true
			return tea.Quit
		},
		OnAbort: onFinish,
		OnDone:  onFinish,
	})

Comment on lines +285 to +313
func (vm *syncViewModel) continueWithState(state *savedSyncState) tea.Cmd {
vm.state = state.SyncState
vm.restackState = state.RestackState
return vm.addView(sequencerui.NewRestackModel(vm.repo, vm.db, state.RestackState, sequencerui.RestackStateOptions{
Command: "av sync",
Abort: syncFlags.Abort,
Continue: syncFlags.Continue,
Skip: syncFlags.Skip,
OnConflict: func() tea.Cmd {
if err := vm.writeState(vm.restackState); err != nil {
return uiutils.ErrCmd(err)
}
vm.quitWithConflict = true
return tea.Quit
},
OnAbort: func() tea.Cmd {
if err := vm.writeState(nil); err != nil {
return uiutils.ErrCmd(err)
}
return tea.Quit
},
OnDone: func() tea.Cmd {
if err := vm.writeState(nil); err != nil {
return uiutils.ErrCmd(err)
}
return vm.initPushBranches()
},
}))
}

Choose a reason for hiding this comment

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

medium

The OnAbort and OnDone handlers share common logic for clearing the state. You can extract this into a helper function within continueWithState to reduce duplication and make the intent clearer.

func (vm *syncViewModel) continueWithState(state *savedSyncState) tea.Cmd {
	vm.state = state.SyncState
	vm.restackState = state.RestackState
	clearStateAndContinue := func(next tea.Cmd) tea.Cmd {
		if err := vm.writeState(nil); err != nil {
			return uiutils.ErrCmd(err)
		}
		return next
	}
	return vm.addView(sequencerui.NewRestackModel(vm.repo, vm.db, state.RestackState, sequencerui.RestackStateOptions{
		Command:  "av sync",
		Abort:    syncFlags.Abort,
		Continue: syncFlags.Continue,
		Skip:     syncFlags.Skip,
		OnConflict: func() tea.Cmd {
			if err := vm.writeState(vm.restackState); err != nil {
				return uiutils.ErrCmd(err)
			}
			vm.quitWithConflict = true
			return tea.Quit
		},
		OnAbort: func() tea.Cmd {
			return clearStateAndContinue(tea.Quit)
		},
		OnDone: func() tea.Cmd {
			return clearStateAndContinue(vm.initPushBranches())
		},
	}))
}

@aviator-app aviator-app bot merged commit 45d7d25 into master Oct 8, 2025
5 checks passed
@aviator-app aviator-app bot deleted the continuation_passing branch October 8, 2025 00:57
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.

3 participants