Skip to content

Resubscribe dependents when a dependency controller is replaced#11

Merged
Damirados merged 6 commits into
mainfrom
fix/track-source-pid
Jul 8, 2026
Merged

Resubscribe dependents when a dependency controller is replaced#11
Damirados merged 6 commits into
mainfrom
fix/track-source-pid

Conversation

@ken-kost

@ken-kost ken-kost commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator

No description provided.

ken-kost added 6 commits July 7, 2026 12:19
The %{target: _, subscription_ref: _} clause could never match: the
function is only called with single-kind binding states, which carry
:child_target rather than :target.
put_collection_binding_subscription fell back to a bare map without
:kind/:source/:filter, and that shape is what actually got persisted
for every non-empty collection binding. Those states fell through
cleanup_binding_state's silent catch-all, so collection subscriptions
were never explicitly unsubscribed when a dependent stopped — process
monitors happened to mask it. Use default_collection_binding_state as
the fallback and drop the catch-all so shape drift fails loudly.
Binding state only recorded the source controller's name, so after a
params change replaced a controller, reconcile considered dependents'
bindings live even though their subscriptions died with the old
process. Updates from the new instance stopped flowing entirely.

Track the pid each subscription was made in and treat a binding as
live only when that pid still runs the source. Applies to singleton
dependencies and to collection items replaced under the same id.
A stale binding's subscription died with its process, so resolving the
source name to the current pid just hands the replacement process a
ref it has never seen — a wasted synchronous call during replacement
reconciliation. Thread the stored pid through and only unsubscribe
when it still matches the running process.
Its only caller reaches it through the validate_or_normalize_dependencies
clause that requires dependency_bindings != [], so the empty-list clause
can never match — the type checker now proves and reports this. The
is_list/1 clause already handles [] identically.
Controllers declared with events: [] compiled the lookup down to
Map.fetch!(%{}, event), which the type checker proves always raises and
reports on every such module — including in downstream applications.
Emit one clause per declared event plus an explicit KeyError fallback,
preserving the previous behavior for undeclared events.
@ken-kost ken-kost requested a review from Damirados July 7, 2026 10:40

@Damirados Damirados left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Remove Co-Autored-By lines from the commits.

@ken-kost ken-kost force-pushed the fix/track-source-pid branch from 8d91324 to cac6b74 Compare July 7, 2026 11:24
@ken-kost ken-kost requested a review from Damirados July 7, 2026 11:24

@Damirados Damirados left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Add a proper PR name and description.

@Damirados Damirados changed the title fix: track source pid Resubscribe dependents when a dependency controller is replaced Jul 8, 2026
@Damirados Damirados merged commit 147604d into main Jul 8, 2026
1 check passed
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