Skip to content

Commit 2738278

Browse files
sjmiller609claude
andcommitted
Fail countTemplateForks on metadata load error instead of skipping
Silently continuing past an unreadable metadata file could undercount forks of a template, allowing DemoteTemplate or DeleteInstance to free a template whose pages are still mapped by a live fork. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 0d0ab12 commit 2738278

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

lib/instances/query.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -826,7 +826,9 @@ func (m *manager) listInstances(ctx context.Context) ([]Instance, error) {
826826
}
827827

828828
// countTemplateForks returns the number of instances with ForkOfTemplate==templateID.
829-
// Skips metadata files that fail to load (logged elsewhere on read).
829+
// Bubbles metadata load errors: this count guards DeleteInstance and
830+
// DemoteTemplate, and silently skipping an unreadable file would risk
831+
// undercounting forks and freeing a template whose pages are still mapped.
830832
func (m *manager) countTemplateForks(templateID string) (int, error) {
831833
files, err := m.listMetadataFiles()
832834
if err != nil {
@@ -837,7 +839,7 @@ func (m *manager) countTemplateForks(templateID string) (int, error) {
837839
id := filepath.Base(filepath.Dir(file))
838840
meta, err := m.loadMetadata(id)
839841
if err != nil {
840-
continue
842+
return 0, fmt.Errorf("load metadata for %s while counting forks of %s: %w", id, templateID, err)
841843
}
842844
if meta.ForkOfTemplate == templateID {
843845
count++

0 commit comments

Comments
 (0)