Skip to content

Read the diff once for walkthrough-file launches - #188

Closed
matchai wants to merge 8 commits into
nkzw-tech:mainfrom
matchai:walkthrough-file-single-read
Closed

matchai wants to merge 8 commits into
nkzw-tech:mainfrom
matchai:walkthrough-file-single-read

Conversation

@matchai

@matchai matchai commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

A walkthrough-file launch reads the repository diff twice: once for the launch check (#187) and again when the window loads the walkthrough. The window's first walkthrough load now reuses the state the check already read, so the diff is read once.

 openLaunchWindow
   read repository state
   check walkthrough file
   focusOrCreateWindow(…, state)
+  windowWalkthroughFileStates.set(window, state)
 codiff:getNarrativeWalkthrough
-  readRepositoryStateWithConfig()
+  use the launch's state on the window's first walkthrough load

The state is dropped after one use and when the window closes, so later loads, including forced reloads, read the diff as before. The first load needs no force or source check: the renderer never forces it and always asks for the source the window opened with. createWindow now returns its window so the launch can record it.

Timings

5 cold launches of codiff -w --walkthrough-file <valid file> per version, alternating between main (da35d91) and this PR (442e51f) so both ran under the same load. The later simplification (c899c9b) only removes guards that never fired, so the read pattern is unchanged. Times are medians from the command's start, traced in Electron's main process on dev builds.

Milestone main This PR
Repository reads 2 1
CLI exits (launch check done) 500 ms 550 ms
Window visible 838 ms 824 ms
Walkthrough IPC, request to response 429 ms 1 ms
Walkthrough loaded 1,154 ms 755 ms

The walkthrough now loads about 0.4 s sooner, about 35% faster. The rest of startup is unchanged within run-to-run noise. The first main run was a 5.7 s cold-cache outlier, which the median absorbs.

Merge danger: two-way door, walkthrough-file launches only. The first walkthrough load trusts that it asks for the launch's source; a future caller that first loads a different source would get the launch's diff.

This PR was written primarily with fx, a coding agent. I reviewed the change; the agent traced the launch, wrote the change, and measured it against main.

banana banana banana

codiff -w --walkthrough-file exited 0 even when the app could not apply the walkthrough, and the app silently dropped any stop with an unresolved hunk id. The app now checks a CLI launch's walkthrough file against the diff before opening a window, opens nothing when it cannot be applied, and reports the outcome through a result file that both launchers wait on. --share runs the same check, and the skill and guide describe the new behavior.
The packaged launcher read the JSON result with plutil, which only exists on macOS, so the reason was lost on Linux CI. A status line followed by the reason needs only head and tail.
The app checks the walkthrough file at launch whether or not -w is set, so the launchers wait whenever a walkthrough file is given.
@matchai
matchai force-pushed the walkthrough-file-single-read branch from d3deb73 to ff8d947 Compare October 26, 2026 03:16
codiff-app runs with set -e, so reading the result file before the app wrote it ended the launcher with exit 1 and no message. Check that the file has content first, as the plan loop does, and test a result that arrives after the launcher starts waiting.
The window's first walkthrough load reuses the repository state the launch check read instead of reading the diff again, and window identity resolves while that read runs. createWindow now returns its window so the launch can record it.
It saved about 20 ms at the cost of an extra focusOrCreateWindow parameter; this PR is only about reusing the checked state.
@matchai
matchai force-pushed the walkthrough-file-single-read branch from ff8d947 to f3a9ad8 Compare October 26, 2026 04:39
@matchai
matchai marked this pull request as ready for review October 26, 2026 05:12
The map only holds state from a launch check that passed, so it stores the resolved state. The first walkthrough load never forces and always asks for the source the window was opened with, so the force and source guards are dropped.
@cpojer

cpojer commented Oct 26, 2026

Copy link
Copy Markdown
Member

Your other PR fixed this, too.

@cpojer cpojer closed this Oct 26, 2026
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.

2 participants