Skip to content

fix(sourcelist): take a middle click without a ui.Handle per row (B2) - #9

Merged
bketelsen merged 2 commits into
mainfrom
fix/sourcelist-handle-leak
Nov 11, 2026
Merged

bketelsen merged 2 commits into
mainfrom
fix/sourcelist-handle-leak

Conversation

@bketelsen

Copy link
Copy Markdown
Contributor

Summary

Fixes B2, the Blocking finding that #7 merged with: SourceList's middle click leaked a MyGo handle registration each time a row was built again.

  • Cause: with OnMiddleClick set, each row made a ui.Handle with ui.Local and bound it. ui.Local belongs to the element, so a row that scrolls out of view, or whose section or parent closes, loses it, and its next mount makes a new handle. Each new handle's first Bind appends a refState to the window's rt.refs. MyGo removes none until the window closes, and applyFocusRequests walks them all every build pass, so memory and per-frame work grew for the life of the window, even with no middle click. Frostnotes' Files pane sets OnMiddleClick.
  • Fix (the review's option 1, no handle at all): a middle press stores the row's key in SourceList. The row's ObserveInput marks a release that MyGo's own hit test puts over that row; it sees the release before the pressed row's handler does. The handler calls OnMiddleClick only when the release isn't canceled, the key matches, and the release came over the row, and it clears the press on every release. Because it uses the hit test, a release over a section header pinned above the row no longer counts as a click on the row; the old box check counted it.
  • Guards:
    • TestKitMakesNoHandleInAView in internal/repocheck parses the kit and fails when a source file makes a ui.Handle with ui.Local or in a view. TestHandleFixtures holds 10 fixtures that fail and pass.
    • TestSourceListMiddleClickSurvivesRowsBuiltAgain scrolls far and back and closes and reopens a section several times, then checks that a middle click fires once, and that a release outside the row or a canceled one doesn't.
    • AGENTS.md now says, under MyGo's rules, never to create a ui.Handle in a view or with ui.Local.
    • One line in .memory/corrections.jsonl.
  • sourcelist.go was the only instance: grepping the kit for ui.Local( and Bind( found no other.

The exported API is unchanged; OnMiddleClick's doc now says what counts as a click.

Risk tier

Level: L2, from internal/repocheck/** (a new guard and its fixtures) and the template governance files it touches. The guard only adds a failing check.

Risk tier: 3 — a risk:high PR. It fixes an unbounded memory and per-frame-work growth in a shipped widget.

Docs housekeeping

  • Conformance aliases and canonical symlinks are unchanged; canonical targets are edited instead

Verification

  • make verify green, and make ci BASE=origin/main green on this head: lint, js/wasm tests, the race detector and all 7 cross-targets.
  • Revert test: with the old sourcelist.go, TestKitMakesNoHandleInAView fails at sourcelist.go:623, and TestSourceListMiddleClickSurvivesRowsBuiltAgain fails on the pinned-header release.
  • Blocking review point fixed: guard added and 1 .memory/corrections.jsonl line added.

Not covered: no test can see rt.refs, so the leak itself is guarded by the source check rather than measured.

OnMiddleClick bound a ui.Handle made with ui.Local on each row. ui.Local
belongs to the element, so a row that stopped being built (scrolled out
of view, or its section or parent closed) lost it, and its next mount
made a new Handle. Each new Handle's first Bind appends a registration
to the window's refs, which nothing removes until the window closes and
which applyFocusRequests walks every build pass: memory and per-frame
work grew without a limit for the life of the window.

The list now keeps the middle press in its own fields (the row's key),
and the row's ObserveInput, which MyGo runs before the pressed row's
handler gets the release, records that the release is over that row by
MyGo's own hit test. The handler fires OnMiddleClick only for a release
that is not canceled, whose key matches and that came over the row, and
clears the press on every release. Using the hit test instead of the
row's box also stops a release over a section header pinned above the
row from clicking the row under it, which the old box check allowed.

The new test scrolls a 2000-note list far down and back and closes and
opens both sections, five times each, then checks that middle clicks
fire exactly once over their own row, and not over the next row, outside
the list, over the pinned header or when canceled.

Refs: #7 (review) (B2)
A test cannot see MyGo's per-window handle registrations, so the guard
for finding B2 reads the kit's source: TestKitMakesNoHandleInAView parses
every kit file, tests included, and fails on a ui.Handle (or Ref) made
in a view (a function or closure that takes the build's *ui.Context or a
ui.Element, and every closure inside one) as a literal, new, make or a
variable, and on a ui.Local that keeps one, by its type argument or its
init's result. TestHandleFixtures proves the check fails on the old
SourceList code and its variants and passes handles kept in structs.

AGENTS.md gains the rule under MyGo's rules: never create a ui.Handle in
a view or with ui.Local; keep handles in structs. The design docs say
the same, and .memory/corrections.jsonl records the correction.

Refs: #7 (review) (B2)
@github-actions github-actions Bot added level:L2 Read the diff risk:high Touches a path in .github/risk-paths.json (core ADR-0068) labels Nov 11, 2026

@frostyard-machines frostyard-machines left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Review of head 1de9b192ba4175821621339f314ec290c48a5687 (base 23f37ce): no findings. B2 from #7 is fixed.

  • The fix: sourcelist.go keeps the middle press in middle, middleSet and middleOver, and no row makes a ui.Handle. I checked the order of events in MyGo v0.9.0. pointerUp calls observePointer on the hit chain under the pointer first (ui/input.go:716), and then delivers the release to the pressed element (:750). So the row's ObserveInput sees a release over that row before its HandleInput decides.
  • A row that goes away while the button is down: endPress gives the pressed element's handler a canceled release (ui/input.go:629-636), so the stored press clears.
  • The pinned header: the hit test puts it above the row, so a release there does not count as a click on the row. This is more correct than the old box check.
  • The guards:
    • TestKitMakesNoHandleInAView parses the kit's views and ui.Local calls, and TestHandleFixtures holds 10 fixtures.
    • TestSourceListMiddleClickSurvivesRowsBuiltAgain scrolls the list and closes and opens its sections 5 times. Then it checks the click itself: a release over the same row fires once, and the next row, outside the list, a canceled press and the pinned header fire none.
    • The new AGENTS.md rule includes Handle in the MyGo bump check, and there is 1 corrections line with promoted_to set to the guard.
  • API: api.txt does not change.
  • Risk tier: the section names internal/repocheck/** (L2) and gives the reason.

Checks:

  • Local GOTOOLCHAIN=local make ci BASE=origin/main with go1.27.4 passes at this head.
  • Revert test: with sourcelist.go from main, TestKitMakesNoHandleInAView fails at sourcelist.go:623 (both the ui.Local and the Handle literal), and TestSourceListMiddleClickSurvivesRowsBuiltAgain fails at the pinned-header release. With this head, both pass.
  • GitHub: the 7 cross-build jobs are green, and verify is still running.

The next step is the independent cross-review. The label waits for a green verify.

@frostyard-machines frostyard-machines left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Cross-review at head 1de9b192ba4175821621339f314ec290c48a5687 (base 23f37ce2a71513b098d3ea747dd382dd785641a1). Reviewer: openai/gpt-6.1-sol, which reviewed all 8 changed paths. Result: Ready, Blocking: none.

It confirmed these points about the middle-click logic:

  • MyGo shows the release to the elements under the pointer before it gives the release to the row that holds the press.
  • A release over another row, outside the list or over a pinned header does not count as a click.
  • A canceled release clears the state, also when MyGo stops building the pressed row.
  • Each list has its own state.
  • A new middle press resets the state of a release that was lost.
  • The state clears before OnMiddleClick runs.
  • MyGo starts value drags only for the primary button.
  • No row makes a handle.

2 low findings, not blocking. A follow-up can take them:

  1. internal/repocheck/handles_test.go:70: the guard checks the syntax only. It does not see a ui.Handle inside a named struct that ui.Local initializes as a zero value (for example rowState{} with a field h ui.Handle, and then Bind(&state.h)). Fix: add a fixture for this case, and resolve such struct types, or say in the guard's comment that it checks direct syntax only.
  2. AGENTS.md:97: "one per item in a map pruned as items go" is not enough when items change all the time. Pruning the map removes only the kit's reference. The window keeps each registration until it closes, so items that are removed and added again still add registrations. Fix: say that pruning does not release the window's registration, and recommend stable handle identities with a bound, not a handle for each item of a set that changes without limit. (This option came from my B2 comment, so the correction is mine.)

Checks: the head, the base and CI have not changed since the review. CI is green (verify and the 7 cross-build jobs). The revert test is in my earlier review: both guards fail without the fix.

@frostyard-machines frostyard-machines added the ready-for-human Reviewed, CI green: ready for Brian to review and merge label Nov 11, 2026
@bketelsen
bketelsen merged commit cbba093 into main Nov 11, 2026
10 checks passed
@bketelsen
bketelsen deleted the fix/sourcelist-handle-leak branch November 11, 2026 13:24
bketelsen added a commit to frostyard/frostnotes that referenced this pull request Nov 11, 2026
frostyard/frostui#9 makes no handle per row: a middle click counts when
the release lands on the same row by MyGo's own hit test. The pin holds
until frostui v0.3.0. Files' middle click still opens a file in a new
tab, and a release over another row, or on a folder, opens nothing.
bketelsen added a commit to frostyard/frostnotes that referenced this pull request Nov 11, 2026
The tag is the merge of frostyard/frostui#9: the source list's middle
click is the same as at 1de9b19. Files has one untitled section, so a
release over a pinned section header cannot happen there.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

level:L2 Read the diff ready-for-human Reviewed, CI green: ready for Brian to review and merge risk:high Touches a path in .github/risk-paths.json (core ADR-0068)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants