templates: reconcile fork refcounts and sweep orphans on boot#215
Draft
sjmiller609 wants to merge 1 commit intohypeship/fork-shared-memfilefrom
Draft
templates: reconcile fork refcounts and sweep orphans on boot#215sjmiller609 wants to merge 1 commit intohypeship/fork-shared-memfilefrom
sjmiller609 wants to merge 1 commit intohypeship/fork-shared-memfilefrom
Conversation
Drift between the templates registry and the actual fork population can
appear after a crash, an out-of-band fork delete, or any path that
bypassed the increment/decrement pair. The new Registry.Reconcile takes
a map of observed fork counts and rewrites every template's ForkCount
in place.
The instances manager wires this in two ways:
- On NewManager, walks instance metadata, sums ForkOfTemplate, and
calls Reconcile so a restart heals stale counts.
- Sweeps orphaned registry entries whose source instance no longer
exists and that have zero live forks; entries with live forks are
left alone because the forks still hold the mem-file open via the
shared symlink.
Exposes ReconcileTemplateState on the manager so a host process can
schedule periodic GC ticks alongside other sweepers.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on: #214 (shared mem-file) — review #213 → #214 first.
Summary
Registry.Reconcile(ctx, observed map[string]int)that walks every template and rewritesForkCountto match the observed map.reconcileTemplateStatethat scans every instance's metadata, sumsForkOfTemplatereferences, callsRegistry.Reconcile, then sweeps registry entries whose source instance is gone andForkCountis 0.ReconcileTemplateStatefor callers that want to re-run it.TestFileRegistry_Reconcileexercises 3 templates with starting counts 5/0/7 reconciled to 2/3/0.Why
ForkCountdrifts when forks are deleted out from under hypeman (crash, SIGKILL, on-disk surgery). Without reconciliation a template can be permanently "in use" and refuse delete. Reconciling on boot keeps the registry honest and letsDeleteblock on actual live forks instead of stale counters.Test plan
go test ./lib/templates/...go test ./lib/instances/...Reconcilerepaired the count and the template can be deleted🤖 Generated with Claude Code