Backtestshugorun-20260930-140149#15207
panic: slice bounds out of range in contentNodeShifter.Delete when removing draft pages from a multilingual taxonomy
Our patch was judged better than the merged fix.
In this judgment, Patch A = our agent, Patch B = the merged fix.
The two production changes are essentially the same. Both change `Shifter.Delete` to return (updated, deleted, wasDeleted, isEmpty) and `DeleteFunc` to return (updated, isEmpty). Both stop mutating the slice in place while ranging over it, which was the source of the out-of-range panic when several entries in one `contentNodes` matched. Both also write the updated value back to the tree in `NodeShiftTree.delete` and `DeleteFuncRaw` when the node is not empty. The only logic difference is in the `contentNodes` branch: when a child is not deleted, A keeps the original child, while B keeps `updated` unless `isEmpty` is set. Every shifter case returns the original child when nothing was deleted, so the two behave the same apart from a trivial edge case (an already-empty nested map). Correctness is therefore a wash. The difference is in the tests. B's test only calls the shifter directly, covering multiple matches, delete-all and delete-none. A tests the shifter directly for both `Delete` and `DeleteFunc` with multiple matches. It also adds tree-level tests that insert a multi-site `contentNodes`, delete one language at a time through `Shape(...).Delete` and `DeleteFuncRaw`, and check the stored value after each step. That covers the second half of the root cause (the tree keeping a stale or corrupted slice between deletes across languages) and matches the issue's scenario of dropping pages in several languages. Scope and craft are comparable. A's more complete, integration-level tests make it the better patch.
The judge saw only the two patches, labelled A and B in random order, with issue links and version numbers removed. The reasoning above is shown verbatim.
Solve
25m 35s42 turns
Wall-clock time in the container
Full test suite
No new failures
3,700 passed · 99 skipped · 3,808 total
Contamination audit
Clean
No sign the agent saw the real fix
Patch size
251vs 161 merged
Changed lines, ours vs merged
The issue
View on GitHubWhat version of Hugo are you using?
Reproduced on both:
hugo v0.159.1-86c7d3afacab79dc53325602d77ef884b7570268+extended darwin/arm64
hugo v0.164.0+extended+withdeploy darwin/arm64
Does this issue reproduce with the latest release?
Yes (0.164.0).
What did you expect to see?
A production build (no -D) of a multilingual site containing draft pages completes.
What did you see instead?
panic: runtime error: slice bounds out of range [5:4]
goroutine 37 [running]:
github.com/gohugoio/hugo/hugolib.(*contentNodeShifter).Delete(0x..., {0x..., 0x...}, {0x2, 0x0, 0x0})
github.com/gohugoio/hugo/hugolib/content_map_page_contentnodeshifter.go:48 +0x5f4
github.com/gohugoio/hugo/hugolib/doctree.(*NodeShiftTree[...]).delete(0x..., {0x..., 0x35})
github.com/gohugoio/hugo/hugolib/doctree/nodeshifttree.go:165 +0x84
github.com/gohugoio/hugo/hugolib/doctree.(*NodeShiftTree[...]).Delete(...)
github.com/gohugoio/hugo/hugolib/doctree/nodeshifttree.go:107
github.com/gohugoio/hugo/hugolib.(*allPagesAssembler).createAllPages.func1-range1(...)
github.com/gohugoio/hugo/hugolib/content_map_page_assembler.go:106 +0xa4
github.com/gohugoio/hugo/hugolib.(*allPagesAssembler).createAllPages(...)
github.com/gohugoio/hugo/hugolib/content_map_page_assembler.go:138 +0x168
github.com/gohugoio/hugo/hugolib.(*HugoSites).assemble(...)
github.com/gohugoio/hugo/hugolib/hugo_sites_build.go:345 +0x41c
The 0x35 in delete(..., {…, 0x35}) is 53, exactly the byte length of the key being removed (/blog/ plus a 47-character slug).
Only on the page-removal path
hugo -D (drafts included) builds fine. The panic appears only when a page is removed from the tree, which makes it invisible in local preview and fatal only in production.
A future publishDate panics identically. Setting [_build] render = "never" / list = "never" on the same pages avoids it entirely — consistent with those pages never being added to the tree, so nothing is deleted.
What I ruled out
Site: 8 languages, ~1,490 pages per language, ~11,455 content files, categories taxonomy.
- Not a regression. 0.159.1 and 0.164.0 behave identically.
- Not the number of drafts. 96 draft pages build fine; 16 panic.
- Not slug length. The panicking key was 47 chars, but renaming an unrelated post to exactly 47 chars builds fine.
- Not the slug. Renaming the offending page does not help.
- Not byte layout. Deleting a front-matter line, or adding a blank one, still panics.
Swapping page content at a fixed path isolates it to front matter. Changing categories = ["Airport Operations"] on the offending page to any other value clears the panic — and so does moving a different page out of that same category while leaving the offending one alone. So the trigger is combinatorial: some particular set of pages being deleted from one taxonomy term corrupts the shifter, rather than any single page being malformed.
Reproducer
I have not managed to minimise it, and I want to be upfront about that. Synthetic multilingual sites (8 languages, 12 blog + 200 glossary pages sharing one taxonomy term, varying draft counts) do not reproduce, so something else in the real tree is required. The affected repository is private.
I am happy to run patches or instrumented builds against the real site and report back, which may be faster than guessing at a minimal case.
The two patches
hugolib/content_map_page_contentnodeshifter.goindex 04f632f75..dccdf3586 100644@@ -25,7 +25,7 @@ type contentNodeShifter struct { conf config.AllProvider // Used for logging/debugging. } -func (s *contentNodeShifter) Delete(n contentNode, vec sitesmatrix.Vector) (contentNode, bool, bool) {+func (s *contentNodeShifter) Delete(n contentNode, vec sitesmatrix.Vector) (contentNode, contentNode, bool, bool) { switch v := n.(type) { case contentNodesMap: deleted, wasDeleted := v[vec]@@ -33,49 +33,56 @@ func (s *contentNodeShifter) Delete(n contentNode, vec sitesmatrix.Vector) (cont delete(v, vec) resource.MarkStale(deleted) }- return deleted, wasDeleted, len(v) == 0+ return v, deleted, wasDeleted, len(v) == 0 case contentNodeForSite: if v.siteVector() != vec {- return nil, false, false+ return v, nil, false, false } resource.MarkStale(v)- return v, true, true+ return nil, v, true, true case contentNodes: var deleted contentNodes- for i, nn := range v {- if vv, ok, _ := s.Delete(nn, vec); ok {+ kept := make(contentNodes, 0, len(v))+ for _, nn := range v {+ if updated, vv, ok, isEmpty := s.Delete(nn, vec); ok { deleted = append(deleted, vv)- v = append(v[:i], v[i+1:]...)+ if !isEmpty {+ kept = append(kept, updated)+ }+ } else {+ kept = append(kept, nn) } } if len(deleted) == 0 {- return nil, false, false+ return n, nil, false, false }- return deleted, true, len(v) == 0+ return kept, deleted, true, len(kept) == 0 default: v = v.(contentNodeSingle) // Ensure single node. resource.MarkStale(v)- return v, true, true+ return nil, v, true, true } } -func (s *contentNodeShifter) DeleteFunc(v contentNode, f func(n contentNode) bool) bool {+func (s *contentNodeShifter) DeleteFunc(v contentNode, f func(n contentNode) bool) (contentNode, bool) { switch ss := v.(type) { case contentNodeSingle: if f(ss) { resource.MarkStale(ss)- return true+ return nil, true }- return false+ return ss, false case contentNodes:- for i, n := range ss {+ kept := make(contentNodes, 0, len(ss))+ for _, n := range ss { if f(n) { resource.MarkStale(n)- ss = append(ss[:i], ss[i+1:]...)+ } else {+ kept = append(kept, n) } }- return len(ss) == 0+ return kept, len(kept) == 0 case contentNodesMap: for k, n := range ss { if f(n) {@@ -83,7 +90,7 @@ func (s *contentNodeShifter) DeleteFunc(v contentNode, f func(n contentNode) boo delete(ss, k) } }- return len(ss) == 0+ return ss, len(ss) == 0 default: panic(fmt.Sprintf("DeleteFunc: unknown type %T", v)) }hugolib/content_map_page_contentnodeshifter_test.gonew file mode 100644index 000000000..7d0c065a2@@ -0,0 +1,175 @@+// Copyright 2025 The Hugo Authors. All rights reserved.+//+// Licensed under the Apache License, Version 2.0 (the "License");+// you may not use this file except in compliance with the License.+// You may obtain a copy of the License at+// http://www.apache.org/licenses/LICENSE-2.0+//+// Unless required by applicable law or agreed to in writing, software+// distributed under the License is distributed on an "AS IS" BASIS,+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+// See the License for the specific language governing permissions and+// limitations under the License.++package hugolib++import (+ "sort"+ "testing"++ qt "github.com/frankban/quicktest"+ "github.com/gohugoio/hugo/hugolib/doctree"+ "github.com/gohugoio/hugo/hugolib/sitesmatrix"+)++// testContentNodeForSite is a minimal contentNodeSingle/contentNodeForSite used+// to exercise the contentNodeShifter without building a site.+type testContentNodeForSite struct {+ name string+ vec sitesmatrix.Vector+}++func (n *testContentNodeForSite) Path() string { return "/p1" }++func (n *testContentNodeForSite) siteVector() sitesmatrix.Vector { return n.vec }++func (n *testContentNodeForSite) nodeCategorySingle() {}++func (n *testContentNodeForSite) forEeachContentNode(f func(sitesmatrix.Vector, contentNode) bool) bool {+ return f(n.vec, n)+}++var (+ _ contentNodeForSite = (*testContentNodeForSite)(nil)+ _ contentNodeSingle = (*testContentNodeForSite)(nil)+)++func newTestContentNodeForSite(name string, lang int) *testContentNodeForSite {+ return &testContentNodeForSite{name: name, vec: sitesmatrix.Vector{lang, 0, 0}}+}++// testContentNodeNames returns the sorted names of all test nodes in n.+func testContentNodeNames(n contentNode) []string {+ var names []string+ if n == nil {+ return names+ }+ n.forEeachContentNode(func(_ sitesmatrix.Vector, nn contentNode) bool {+ names = append(names, nn.(*testContentNodeForSite).name)+ return true+ })+ sort.Strings(names)+ return names+}++func newTestContentNodeTree() *doctree.NodeShiftTree[contentNode] {+ return doctree.New(doctree.Config[contentNode]{+ Shifter: &contentNodeShifter{},+ TransformerRaw: &contentNodeTransformerRaw{},+ })+}++func TestContentNodeShifterDeleteContentNodesMultipleMatches(t *testing.T) {+ c := qt.New(t)++ s := &contentNodeShifter{}+ nodes := contentNodes{+ newTestContentNodeForSite("a", 0),+ newTestContentNodeForSite("b", 1),+ newTestContentNodeForSite("c", 0),+ }++ updated, deleted, wasDeleted, isEmpty := s.Delete(nodes, sitesmatrix.Vector{0, 0, 0})+ c.Assert(wasDeleted, qt.IsTrue)+ c.Assert(isEmpty, qt.IsFalse)+ c.Assert(testContentNodeNames(deleted), qt.DeepEquals, []string{"a", "c"})+ c.Assert(testContentNodeNames(updated), qt.DeepEquals, []string{"b"})+}++func TestContentNodeShifterDeleteFuncContentNodesMultipleMatches(t *testing.T) {+ c := qt.New(t)++ s := &contentNodeShifter{}+ nodes := contentNodes{+ newTestContentNodeForSite("a", 0),+ newTestContentNodeForSite("b", 1),+ newTestContentNodeForSite("c", 0),+ }++ var deleted []string+ updated, isEmpty := s.DeleteFunc(nodes, func(n contentNode) bool {+ nn := n.(*testContentNodeForSite)+ if nn.vec[sitesmatrix.Language] == 0 {+ deleted = append(deleted, nn.name)+ return true+ }+ return false+ })+ sort.Strings(deleted)+ c.Assert(isEmpty, qt.IsFalse)+ c.Assert(deleted, qt.DeepEquals, []string{"a", "c"})+ c.Assert(testContentNodeNames(updated), qt.DeepEquals, []string{"b"})+}++// The tree must see the result of deleting one site's node from a contentNodes+// value, so that deleting other sites' nodes at the same key later works.+// This is what happens when a page is dropped (e.g. draft) in several languages.+func TestContentNodeShifterDeleteContentNodesInTree(t *testing.T) {+ c := qt.New(t)++ tree := newTestContentNodeTree()+ tree.InsertRaw("/p1", contentNodes{+ newTestContentNodeForSite("a", 0),+ newTestContentNodeForSite("b", 1),+ newTestContentNodeForSite("c", 2),+ })++ deleted, ok := tree.Shape(sitesmatrix.Vector{0, 0, 0}).Delete("/p1")+ c.Assert(ok, qt.IsTrue)+ c.Assert(testContentNodeNames(deleted), qt.DeepEquals, []string{"a"})+ v, found := tree.GetRaw("/p1")+ c.Assert(found, qt.IsTrue)+ c.Assert(testContentNodeNames(v), qt.DeepEquals, []string{"b", "c"})++ deleted, ok = tree.Shape(sitesmatrix.Vector{2, 0, 0}).Delete("/p1")+ c.Assert(ok, qt.IsTrue)+ c.Assert(testContentNodeNames(deleted), qt.DeepEquals, []string{"c"})+ v, found = tree.GetRaw("/p1")+ c.Assert(found, qt.IsTrue)+ c.Assert(testContentNodeNames(v), qt.DeepEquals, []string{"b"})++ deleted, ok = tree.Shape(sitesmatrix.Vector{1, 0, 0}).Delete("/p1")+ c.Assert(ok, qt.IsTrue)+ c.Assert(testContentNodeNames(deleted), qt.DeepEquals, []string{"b"})+ _, found = tree.GetRaw("/p1")+ c.Assert(found, qt.IsFalse)+}++func TestContentNodeShifterDeleteFuncContentNodesInTree(t *testing.T) {+ c := qt.New(t)++ tree := newTestContentNodeTree()+ tree.InsertRaw("/p1", contentNodes{+ newTestContentNodeForSite("a", 0),+ newTestContentNodeForSite("b", 1),+ newTestContentNodeForSite("c", 2),+ })++ isLang := func(lang int) func(n contentNode) bool {+ return func(n contentNode) bool {+ return n.(*testContentNodeForSite).vec[sitesmatrix.Language] == lang+ }+ }++ _, count := tree.DeleteFuncRaw("/p1", isLang(0))+ c.Assert(count, qt.Equals, 1)+ v, found := tree.GetRaw("/p1")+ c.Assert(found, qt.IsTrue)+ c.Assert(testContentNodeNames(v), qt.DeepEquals, []string{"b", "c"})++ _, count = tree.DeleteFuncRaw("/p1", isLang(2))+ c.Assert(count, qt.Equals, 1)+ v, found = tree.GetRaw("/p1")+ c.Assert(found, qt.IsTrue)+ c.Assert(testContentNodeNames(v), qt.DeepEquals, []string{"b"})+}hugolib/doctree/nodeshiftree_test.goindex 1d17a4129..a969b43fc 100644@@ -258,12 +258,15 @@ func (s *testShifter) Insert(old, new *testValue) (*testValue, *testValue, bool) return new, old, true } -func (s *testShifter) Delete(n *testValue, dimension sitesmatrix.Vector) (*testValue, bool, bool) {- return nil, true, true+func (s *testShifter) Delete(n *testValue, dimension sitesmatrix.Vector) (*testValue, *testValue, bool, bool) {+ return nil, n, true, true } -func (s *testShifter) DeleteFunc(v *testValue, f func(*testValue) bool) bool {- return f(v)+func (s *testShifter) DeleteFunc(v *testValue, f func(*testValue) bool) (*testValue, bool) {+ if f(v) {+ return nil, true+ }+ return v, false } func (s *testShifter) Shift(n *testValue, dimension sitesmatrix.Vector, fallback bool) (v *testValue, ok bool) {hugolib/doctree/nodeshifttree.goindex 0ccf3eba3..93ae5c9d5 100644@@ -49,12 +49,15 @@ type ( // and a bool indicating if an existing record is updated. Insert(old, new T) (T, T, bool) - // Delete deletes T from the given dimension and returns the deleted T and whether the dimension was deleted and if it's empty after the delete.- Delete(v T, dimension sitesmatrix.Vector) (T, bool, bool)+ // Delete deletes T from the given dimension.+ // It returns the updated T (to be stored back in the tree), the deleted T,+ // whether the dimension was deleted and if it's empty after the delete.+ Delete(v T, dimension sitesmatrix.Vector) (T, T, bool, bool) // DeleteFunc deletes nodes in v from the tree where the given function returns true.- // It returns true if it's empty after the delete.- DeleteFunc(v T, f func(n T) bool) bool+ // It returns the updated T (to be stored back in the tree) and+ // true if it's empty after the delete.+ DeleteFunc(v T, f func(n T) bool) (T, bool) // Shift shifts v into the given dimension, // if fallback is true, it will fall back a fallback match if found.@@ -118,7 +121,7 @@ func (r *NodeShiftTree[T]) DeleteFuncRaw(key string, f func(T) bool) (T, int) { return lastDeleted, count } - isEmpty := r.shifter.DeleteFunc(v, func(n T) bool {+ updated, isEmpty := r.shifter.DeleteFunc(v, func(n T) bool { if f(n) { count++ lastDeleted = n@@ -129,6 +132,8 @@ func (r *NodeShiftTree[T]) DeleteFuncRaw(key string, f func(T) bool) (T, int) { if isEmpty { r.tree.Delete(key)+ } else if count > 0 {+ r.tree.Insert(key, updated) } return lastDeleted, count@@ -161,10 +166,15 @@ func (r *NodeShiftTree[T]) delete(key string) (T, bool) { var wasDeleted bool var deleted T if v, ok := r.tree.Get(key); ok {- var isEmpty bool- deleted, wasDeleted, isEmpty = r.shifter.Delete(v, r.siteVector)+ var (+ updated T+ isEmpty bool+ )+ updated, deleted, wasDeleted, isEmpty = r.shifter.Delete(v, r.siteVector) if isEmpty { r.tree.Delete(key)+ } else if wasDeleted {+ r.tree.Insert(key, updated) } } return deleted, wasDeleted
hugolib/content_map_page_contentnodeshifter.goindex 04f632f75..2d8bfa105 100644@@ -25,7 +25,7 @@ type contentNodeShifter struct { conf config.AllProvider // Used for logging/debugging. } -func (s *contentNodeShifter) Delete(n contentNode, vec sitesmatrix.Vector) (contentNode, bool, bool) {+func (s *contentNodeShifter) Delete(n contentNode, vec sitesmatrix.Vector) (contentNode, contentNode, bool, bool) { switch v := n.(type) { case contentNodesMap: deleted, wasDeleted := v[vec]@@ -33,49 +33,53 @@ func (s *contentNodeShifter) Delete(n contentNode, vec sitesmatrix.Vector) (cont delete(v, vec) resource.MarkStale(deleted) }- return deleted, wasDeleted, len(v) == 0+ return v, deleted, wasDeleted, len(v) == 0 case contentNodeForSite: if v.siteVector() != vec {- return nil, false, false+ return v, nil, false, false } resource.MarkStale(v)- return v, true, true+ return nil, v, true, true case contentNodes:- var deleted contentNodes- for i, nn := range v {- if vv, ok, _ := s.Delete(nn, vec); ok {+ var deleted, remaining contentNodes+ for _, nn := range v {+ updated, vv, ok, isEmpty := s.Delete(nn, vec)+ if ok { deleted = append(deleted, vv)- v = append(v[:i], v[i+1:]...)+ }+ if !isEmpty {+ remaining = append(remaining, updated) } } if len(deleted) == 0 {- return nil, false, false+ return v, nil, false, false }- return deleted, true, len(v) == 0+ return remaining, deleted, true, len(remaining) == 0 default:- v = v.(contentNodeSingle) // Ensure single node.- resource.MarkStale(v)- return v, true, true-+ vv := v.(contentNodeSingle) // Ensure single node.+ resource.MarkStale(vv)+ return nil, vv, true, true } } -func (s *contentNodeShifter) DeleteFunc(v contentNode, f func(n contentNode) bool) bool {+func (s *contentNodeShifter) DeleteFunc(v contentNode, f func(n contentNode) bool) (contentNode, bool) { switch ss := v.(type) { case contentNodeSingle: if f(ss) { resource.MarkStale(ss)- return true+ return nil, true }- return false+ return ss, false case contentNodes:- for i, n := range ss {+ var remaining contentNodes+ for _, n := range ss { if f(n) { resource.MarkStale(n)- ss = append(ss[:i], ss[i+1:]...)+ } else {+ remaining = append(remaining, n) } }- return len(ss) == 0+ return remaining, len(remaining) == 0 case contentNodesMap: for k, n := range ss { if f(n) {@@ -83,7 +87,7 @@ func (s *contentNodeShifter) DeleteFunc(v contentNode, f func(n contentNode) boo delete(ss, k) } }- return len(ss) == 0+ return ss, len(ss) == 0 default: panic(fmt.Sprintf("DeleteFunc: unknown type %T", v)) }hugolib/content_map_page_contentnodeshifter_test.gonew file mode 100644index 000000000..f8d2c07bc@@ -0,0 +1,79 @@+// Copyright 2025 The Hugo Authors. All rights reserved.+//+// Licensed under the Apache License, Version 2.0 (the "License");+// you may not use this file except in compliance with the License.+// You may obtain a copy of the License at+// http://www.apache.org/licenses/LICENSE-2.0+//+// Unless required by applicable law or agreed to in writing, software+// distributed under the License is distributed on an "AS IS" BASIS,+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+// See the License for the specific language governing permissions and+// limitations under the License.++package hugolib++import (+ "testing"++ qt "github.com/frankban/quicktest"+ "github.com/gohugoio/hugo/hugolib/sitesmatrix"+)++type testContentNodeForSite struct {+ vec sitesmatrix.Vector+}++func (n *testContentNodeForSite) Path() string { return "/test" }+func (n *testContentNodeForSite) nodeCategorySingle() {}+func (n *testContentNodeForSite) siteVector() sitesmatrix.Vector { return n.vec }+func (n *testContentNodeForSite) forEeachContentNode(f func(sitesmatrix.Vector, contentNode) bool) bool {+ return f(n.vec, n)+}++// See issue 15207.+func TestContentNodeShifterDeleteMultipleFromNodes(t *testing.T) {+ c := qt.New(t)++ s := &contentNodeShifter{}+ vec := sitesmatrix.Vector{2, 0, 0}+ other := sitesmatrix.Vector{1, 0, 0}++ newNodes := func() contentNodes {+ return contentNodes{+ &testContentNodeForSite{vec: other},+ &testContentNodeForSite{vec: vec},+ &testContentNodeForSite{vec: other},+ &testContentNodeForSite{vec: other},+ &testContentNodeForSite{vec: vec},+ }+ }++ updated, deleted, wasDeleted, isEmpty := s.Delete(newNodes(), vec)+ c.Assert(wasDeleted, qt.IsTrue)+ c.Assert(isEmpty, qt.IsFalse)+ c.Assert(deleted.(contentNodes), qt.HasLen, 2)+ remaining := updated.(contentNodes)+ c.Assert(remaining, qt.HasLen, 3)+ for _, n := range remaining {+ c.Assert(n.(contentNodeForSite).siteVector(), qt.Equals, other)+ }++ // Delete all.+ updated, deleted, wasDeleted, isEmpty = s.Delete(contentNodes{+ &testContentNodeForSite{vec: vec},+ &testContentNodeForSite{vec: vec},+ }, vec)+ c.Assert(wasDeleted, qt.IsTrue)+ c.Assert(isEmpty, qt.IsTrue)+ c.Assert(deleted.(contentNodes), qt.HasLen, 2)+ c.Assert(updated, qt.IsNil)++ // Delete none.+ nodes := contentNodes{&testContentNodeForSite{vec: other}}+ updated, deleted, wasDeleted, isEmpty = s.Delete(nodes, vec)+ c.Assert(wasDeleted, qt.IsFalse)+ c.Assert(isEmpty, qt.IsFalse)+ c.Assert(deleted, qt.IsNil)+ c.Assert(updated.(contentNodes), qt.HasLen, 1)+}hugolib/doctree/nodeshiftree_test.goindex 1d17a4129..a969b43fc 100644@@ -258,12 +258,15 @@ func (s *testShifter) Insert(old, new *testValue) (*testValue, *testValue, bool) return new, old, true } -func (s *testShifter) Delete(n *testValue, dimension sitesmatrix.Vector) (*testValue, bool, bool) {- return nil, true, true+func (s *testShifter) Delete(n *testValue, dimension sitesmatrix.Vector) (*testValue, *testValue, bool, bool) {+ return nil, n, true, true } -func (s *testShifter) DeleteFunc(v *testValue, f func(*testValue) bool) bool {- return f(v)+func (s *testShifter) DeleteFunc(v *testValue, f func(*testValue) bool) (*testValue, bool) {+ if f(v) {+ return nil, true+ }+ return v, false } func (s *testShifter) Shift(n *testValue, dimension sitesmatrix.Vector, fallback bool) (v *testValue, ok bool) {hugolib/doctree/nodeshifttree.goindex 0ccf3eba3..f2cec9f26 100644@@ -49,12 +49,14 @@ type ( // and a bool indicating if an existing record is updated. Insert(old, new T) (T, T, bool) - // Delete deletes T from the given dimension and returns the deleted T and whether the dimension was deleted and if it's empty after the delete.- Delete(v T, dimension sitesmatrix.Vector) (T, bool, bool)+ // Delete deletes T from the given dimension.+ // It returns the updated T, the deleted T, whether anything was deleted+ // and whether T is empty after the delete.+ Delete(v T, dimension sitesmatrix.Vector) (T, T, bool, bool) - // DeleteFunc deletes nodes in v from the tree where the given function returns true.- // It returns true if it's empty after the delete.- DeleteFunc(v T, f func(n T) bool) bool+ // DeleteFunc deletes nodes in v where the given function returns true.+ // It returns the updated T and whether it's empty after the delete.+ DeleteFunc(v T, f func(n T) bool) (T, bool) // Shift shifts v into the given dimension, // if fallback is true, it will fall back a fallback match if found.@@ -118,7 +120,7 @@ func (r *NodeShiftTree[T]) DeleteFuncRaw(key string, f func(T) bool) (T, int) { return lastDeleted, count } - isEmpty := r.shifter.DeleteFunc(v, func(n T) bool {+ updated, isEmpty := r.shifter.DeleteFunc(v, func(n T) bool { if f(n) { count++ lastDeleted = n@@ -129,6 +131,8 @@ func (r *NodeShiftTree[T]) DeleteFuncRaw(key string, f func(T) bool) (T, int) { if isEmpty { r.tree.Delete(key)+ } else if count > 0 {+ r.tree.Insert(key, updated) } return lastDeleted, count@@ -161,10 +165,15 @@ func (r *NodeShiftTree[T]) delete(key string) (T, bool) { var wasDeleted bool var deleted T if v, ok := r.tree.Get(key); ok {- var isEmpty bool- deleted, wasDeleted, isEmpty = r.shifter.Delete(v, r.siteVector)+ var (+ updated T+ isEmpty bool+ )+ updated, deleted, wasDeleted, isEmpty = r.shifter.Delete(v, r.siteVector) if isEmpty { r.tree.Delete(key)+ } else if wasDeleted {+ r.tree.Insert(key, updated) } } return deleted, wasDeleted
What the agent reported
I fixed the panic and it's covered by new unit tests, but I couldn't reproduce it with a full site build, so no test builds a real site. The trigger in your site is still unidentified.
What was wrong. When one page path holds several nodes (for example one per language), those nodes sit in a list at that tree key. contentNodeShifter.Delete and DeleteFunc in hugolib/content_map_page_contentnodeshifter.go had two bugs in how they removed items from that list:
- They shortened the list while still looping over its original length. If more than one entry matched, the next removal went past the end, which is the
slice bounds out of range [5:4]panic. - The tree never received the shortened list. It kept the old length with the last entry duplicated. A production build drops a draft or future-dated page once per language, so the next delete at that key saw duplicates and panicked.
That fits what you saw: -D never drops anything, publishDate in the future fails the same way, _build never adds the pages, and the trigger looked like a combination of pages rather than one bad page. I checked this with a standalone copy of both loops: the old one panics on the 5th per-language delete of the same key, the new one doesn't.
What I changed:
content_map_page_contentnodeshifter.go:DeleteandDeleteFuncnow build a new list of the entries they keep instead of editing the list mid-loop, and return it.hugolib/doctree/nodeshifttree.go: the internalShifter.DeleteandDeleteFuncinterface now returns that updated value too.NodeShiftTree.deleteandDeleteFuncRawstore it back in the tree when something was deleted and entries remain. The publicNodeShiftTreemethods keep their signatures.hugolib/doctree/nodeshiftree_test.go: I only changed the signatures of the test shifter'sDeleteandDeleteFuncso it still compiles; no assertion changed.
Tests. There are four new tests in hugolib/content_map_page_contentnodeshifter_test.go:
- Two call
DeleteandDeleteFuncdirectly on a list where two entries match the language being deleted. - Two delete one language at a time at a single tree key, which is what happens when a draft is dropped in each language. They check what the tree holds after each step, down to the key being removed.
Test evidence. ./bt-test could not run: every run ended with [setup failed] because the module proxy is unreachable. I ran go test directly against the module cache at /bt/cache/go-mod instead.
- With the fix: all 4 new tests pass,
go vetis clean, and every package under./hugolib/...passes except 4 tests inhugolibitself. Those 4 areTestGitInfoFromGitModule*(3 tests) andTestModulePrivateRepo, and they fail the same way on the original code. - On the original code: both tree tests fail, with the tree holding
["b","c","c"]where["b","c"]was expected. That is the duplicated-entry bug. The two direct tests can't compile against the old signatures, so they have no before-run.
What's missing. I built multilingual sites with drafts in every language, page bundles, sites.matrix pages and a shared categories term. In every one, the node at a page key had already been reorganised into a per-site map before any deletion, so the list code never ran. Something else in your real site leaves the list form at /blog/<slug>, and I couldn't find what.
Your offer to test. Running a build of your private site with this patch applied is the check that's missing. Please do that and report whether it completes.
Requirements:
| Item | Status |
|---|---|
| Production multilingual build with drafts completes | Fixed at the panic site; covered by unit tests. No site-level test, since no synthetic site reproduces it. |
Future publishDate panics the same way | Same page-dropping path, so the same fix covers it. |
-D builds and _build never/never work | Consistent with the cause: nothing is deleted in those cases. No change needed. |
| Not a regression (0.159.1 and 0.164.0 match) | Consistent: the buggy loop is old code. |
| Depends on a combination of pages, not one bad page | Explained by the duplicated entries piling up across per-language deletes. |
The reviewer found no blocking problems.