carlos / platform Public

pageindex: Abort retries fill cleanup after Abort or a failed Finish

Pending.Abort returned once done was set, so a temporary the store could
not remove kept its file and reservation until restart. Abort now always
passes through to Fill.Abort, which retries the removal and is a no-op
after a commit, except while a Finish is running.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 005460f7ae08fd28b1c9214d9d8e649e2b440d49 parent a44017d
2 files changed, +67 −8
  • internal/pageindex/index_test.go +49 −0
  • internal/pageindex/pending.go +18 −8

CI failed — run details

Intent

Human

<task-notification> <task-id>a94e17e558f578c5f</task-id> <tool-use-id>toolu_01Sy5846j18Dm2yJ4fEySNLW</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/d79ef2b4-4291-4945-bd45-b3f16796c4ba/tasks/a94e17e558f578c5f.output</output-file> <status>completed</status> <summary>Agent "Implement Task 2: pageindex core" finished</summary> <note>A task-notification fires each time this agent stops with no live background children of its own. The user can send it another message and resume it, so the same task-id may notify more than once.</note> <result>**Status:** DONE. `internal/pageindex` is built and all 15 brief tests pass under `-race`. **Commit:** `a44017d5` pageindex: one index owns every page publish, clear, reset and lookup **Tests:** 15/15 pass with `go test ./internal/pageindex -count=1 -race` (39.9 s, no races); `-short` passes too. Every test failed first: a compile failure, then a stub, then 15 mutations on the real code, each caught by its test. Vet, gofmt and the windows/darwin builds are clean. **Concerns:** 1. `Sweep` lists the store with `Retain(keep everything)` rather than calling `Store.Get` on each record. `Get` would mark every page recently used every 5 minutes and shuffle the store's eviction order. It's a one-line swap if you want the brief's wording. 2. `Lookup` calls `Store.Get` outside the scope lock (it can delete expired objects), and drops the record only if it still names the same object. 3. Scopes are never removed, so Task 9's reload hook will repeat Reset and ClearOptIn on departed scopes. Both are cheap and idempotent. 4. `TestSweepBoundsRecords` takes about 37 s at 500 pages (fsync cost, about 70 ms per publish) and about 4 s under `-short` (60 pages). 5. The sandbox mounts `~/.cache/go-build` read-only, so I ran go commands outside the sandbox and left GOCACHE at its default. **Report:** /home/paulca/amadan.net/carlos/platform/.claude/worktrees/edge-page-cache-1/.superpowers/sdd/2026-11-08-edge-page-cache-plan-1-home/task-2-report.md</result> <usage><subagent_tokens>137233</subagent_tokens><tool_uses>33</tool_uses><duration_ms>765027</duration_ms></usage> </task-notification>

Human

<task-notification> <task-id>bpoxr8399</task-id> <tool-use-id>toolu_01CECmS5aNvknDxr8CGMQ6SQ</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/d79ef2b4-4291-4945-bd45-b3f16796c4ba/tasks/bpoxr8399.output</output-file> <status>completed</status> <summary>Background command "Run Astra review of Task 2" completed (exit code 0)</summary> </task-notification>

Attributed to this commit: 33.9 g CO₂e (4,410,816 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on edge-page-cache-1, never backward from it. A turn that produced more than one commit books all of its tokens to the last one, and a concurrent session on this branch can add to the same figure. Some of it was priced using the shared default rate, because no model-specific factor row exists yet for at least one model involved. The Carbon view has the repo total, which is never derived from this attribution.

diff --git a/internal/pageindex/index_test.go b/internal/pageindex/index_test.go
index d7b1737fd..5dfc85f10 100644
--- a/internal/pageindex/index_test.go
+++ b/internal/pageindex/index_test.go
@@ -510,3 +510,52 @@ func TestTooLargeAborts(t *testing.T) {
}
wantMiss(t, r.x, k, "b1", MissAbsent)
}
+
+// TestAbortRetriesCleanup: when the store cannot remove a fill's temporaries,
+// a later Abort retries, after an earlier Abort and after a failed Finish,
+// until the files are gone and nothing stays reserved.
+func TestAbortRetriesCleanup(t *testing.T) {
+ if os.Geteuid() == 0 {
+ t.Skip("root ignores directory permissions")
+ }
+ for _, name := range []string{"after Abort", "after a failed Finish"} {
+ t.Run(name, func(t *testing.T) {
+ r := newRig(t, 64<<20, nil)
+ p, err := r.x.Reserve(r.x.Begin(shop, "b1"), pageKey("/a", ""), 4)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if _, err := p.Write([]byte("abcd")); err != nil {
+ t.Fatal(err)
+ }
+ if err := os.Chmod(r.dir, 0o500); err != nil {
+ t.Fatal(err)
+ }
+ t.Cleanup(func() { os.Chmod(r.dir, 0o700) })
+ if name == "after Abort" {
+ p.Abort()
+ } else {
+ if _, err := p.Write([]byte("past the reservation")); err == nil {
+ t.Fatal("write past the reservation succeeded")
+ }
+ if ok, err := p.Finish(pageMeta(), nil); ok || err == nil {
+ t.Fatalf("Finish of a failed fill = %v, %v; want false and an error", ok, err)
+ }
+ }
+ if ents, _ := os.ReadDir(r.dir); len(ents) == 0 || r.store.Stats().Reserved == 0 {
+ t.Fatalf("the failed cleanup removed everything (%d files, %d reserved); the test does not bite", len(ents), r.store.Stats().Reserved)
+ }
+
+ if err := os.Chmod(r.dir, 0o700); err != nil {
+ t.Fatal(err)
+ }
+ p.Abort()
+ if ents, err := os.ReadDir(r.dir); err != nil || len(ents) != 0 {
+ t.Fatalf("store directory after the retry holds %d files (%v), want none", len(ents), err)
+ }
+ if got := r.store.Stats().Reserved; got != 0 {
+ t.Fatalf("Reserved after the retry = %d, want 0", got)
+ }
+ })
+ }
+}
diff --git a/internal/pageindex/pending.go b/internal/pageindex/pending.go
index 9d19c42d0..ddbd95042 100644
--- a/internal/pageindex/pending.go
+++ b/internal/pageindex/pending.go
@@ -18,8 +18,9 @@ type Pending struct {
phys assetcache.Key
fill *assetcache.Fill
- mu sync.Mutex
- done bool // finished or aborted
+ mu sync.Mutex
+ done bool // finished or aborted: Finish may not run
+ finishing bool // a Finish is running: Abort leaves the fill to it
}
// Reserve starts an attempt to publish k for the render that took t.
@@ -54,12 +55,15 @@ func (p *Pending) Write(b []byte) (int, error) {
return p.fill.Write(b)
}
-// Abort gives up the attempt and removes what it wrote. It does nothing
-// after Finish, and is safe to call twice.
+// Abort gives up the attempt and removes what it wrote. It may be called
+// any number of times, before or after Finish: when the store could not
+// remove a temporary, each call retries, until the files are gone and their
+// reservation released. After a Finish that committed it changes nothing.
+// While a Finish is running it does nothing, so it never interrupts one.
func (p *Pending) Abort() {
p.mu.Lock()
defer p.mu.Unlock()
- if p.done {
+ if p.finishing {
return
}
p.done = true
@@ -76,15 +80,21 @@ func (p *Pending) Abort() {
// later than the scope's, the clear log covers every sequence after it, and
// no clear among those matches the key. Otherwise Finish deletes its own
// object, and only that, and returns false. Finish after Finish or Abort
-// returns os.ErrClosed.
+// returns os.ErrClosed. If its commit fails and the store could not remove
+// every temporary, Abort retries the removal.
func (p *Pending) Finish(m assetcache.Meta, ignore []string) (published bool, err error) {
p.mu.Lock()
- if p.done {
+ if p.done || p.finishing {
p.mu.Unlock()
return false, os.ErrClosed
}
- p.done = true
+ p.finishing = true
p.mu.Unlock()
+ defer func() {
+ p.mu.Lock()
+ p.finishing, p.done = false, true
+ p.mu.Unlock()
+ }()
x := p.x
m.Key = p.phys