Skip to content

Move refresh coordination, snapshots and folder watches out of WidgetRuntime - #298

Merged
jiunbae merged 5 commits into
mainfrom
refactor/refresh-coordinator
Nov 16, 2026
Merged

jiunbae merged 5 commits into
mainfrom
refactor/refresh-coordinator

Conversation

@jiunbae

@jiunbae jiunbae commented Nov 16, 2026

Copy link
Copy Markdown
Member

The rest of the refresh path out of WidgetRuntime, one commit per piece, each a behavior-preserving move — then one commit fixing two defects the move made visible.

  • WorkflowWatchRegistry (host: 2): the per-widget folder watches.
  • finishRefresh split into "does this result still count" and "apply it".
  • NativeRefreshCoordinator (host: 7): in-flight set, waiting manual requests, the gate and the task table. Applying an outcome stays in the runtime.
  • SnapshotStore (host: 2): snapshots, the card models and the single write path. No @Published property moved; a runtime test pins "one model publish, no runtime publish".

Fixes (last commit, each with tests that fail without it):

  • A folder watch stayed open after its widget was turned off or removed.
  • A manual refresh that waited for a script load cancelled by a rescan was left behind and fired after a later, unrelated refresh.

Two statement reorders in loadWidgets / removeWidgetState (gate reload before runActions.cancel; card-model cleanup before forgetCards); neither reads the other's state.

Wiring is covered by runtime-level tests that fail under 13 mutations (host unset, stale result applied, rerun/coalescing removed, cancel on stop removed, fan-out removed…). Full suite: Core 941 / App 1005 / CLI 86, 0 failures.

🤖 Generated with Claude Code

jiunbae and others added 5 commits November 16, 2026 18:37
…gistry

The fs.directory sources with watch: true kept their watchers in a
dictionary on WidgetRuntime. WorkflowWatchRegistry owns them now: one
watch per widget, replaced by the next listing. It asks the runtime two
things through WorkflowWatchRegistryHost: whether a change refreshes the
widget now (its card is on the open shelf), and the refresh.

No behavior change.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…ng the outcome

finishRefresh did two things in one body: decide whether the result of a
native refresh still counts (the gate, the task table, the in-flight
set), and apply it (snapshot, scheduler, ledger, cache). They are two
functions now, called in the same order.

No behavior change.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Which refresh is running for each widget, and whether its result still
counts when it ends, was spread over four properties of WidgetRuntime:
the in-flight set, the manual requests waiting for a running refresh,
the native refresh gate and the task table. NativeRefreshCoordinator
owns all four now.

The runtime keeps starting refreshes and applying their outcome; it asks
the coordinator whether a request joins a running refresh, takes its
token from it, and hears back through NativeRefreshCoordinatorHost when
an outdated refresh has to run again or a waiting manual request is due.
The script path shares the in-flight set through the runtime's
endInFlight, as before.

No behavior change. A rescan now updates the gate before it cancels the
run actions instead of after; neither reads the other.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The renders, the card models the popup observes and the single write
path between them lived on WidgetRuntime. SnapshotStore owns them now,
in the manner of CardOverlayStore: it refuses a write while the host
does (a staged preview), suppresses an unchanged snapshot, publishes on
the affected widget's card model only, and reports each change once
through SnapshotStoreHost.

What a change sets off stays the runtime's, in the same order: the
attention, the reading history, the menu bar promoter. So do the disk
cache and the desktop mirror, which the runtime writes from many other
places.

No behavior change: WidgetCardModel publishes at the same moments, and
nothing that was published on the runtime moved.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…h their widget

A workflow folder watch stayed open until the widget's next listing replaced
it, which never came for a widget that was turned off or removed. It is now
cancelled when the widget stops, goes away, or its code changes.

A manual refresh that waited for a script load cancelled by a rescan stayed
behind and fired after a later, unrelated refresh. It now runs when the load
is released, or is dropped with a widget that is gone.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@jiunbae
jiunbae enabled auto-merge November 16, 2026 09:39
@jiunbae
jiunbae added this pull request to the merge queue Nov 16, 2026
Merged via the queue into main with commit 7886dc2 Nov 16, 2026
6 checks passed
@jiunbae
jiunbae deleted the refactor/refresh-coordinator branch November 16, 2026 10:06
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