Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions docs/changes/unreleased/2643-recovering-heartbeat-owed-upload.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
kind: fixed
title: A quit while the sync service is down reports the local save again
pr: 2643
surface: [chat, engine]
invalidates:
- "After #2381, quitting while the sync service was unreachable could report a chat whose turns were saved on this computer as not saved, because the hold renewal tried before the upload returned its error unclassified. The renewal's failure is now the same owed upload a failed upload reports: saved here, upload pending."
---

The renewal is the upload's own first step after an outage, so it reports its
failure the same way.
6 changes: 5 additions & 1 deletion internal/cellsync/batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,11 @@ func (b *Batcher) publish(ctx context.Context, head string) error {
}
return b.resolve(ctx)
}
return err
// THE HEARTBEAT IS THIS PUBLISH'S RELAY STEP, so its failure is the
// same owed upload a failed advance reports: the turns are durable
// here and only their upload is pending. Returned bare, a quit with
// the relay down reported a confirmed local save as lost.
return syncwords.UploadFailure(err)
}
}
ex, err := b.Publisher.publish(ctx, &d, head, b.info())
Expand Down
20 changes: 20 additions & 0 deletions internal/cellsync/batch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/Agent-Field/codeaf/internal/cell"
"github.com/Agent-Field/codeaf/internal/cellstore"
"github.com/Agent-Field/codeaf/internal/directory"
"github.com/Agent-Field/codeaf/internal/syncwords"
"github.com/Agent-Field/codeaf/internal/wireauth"
)

Expand Down Expand Up @@ -248,6 +249,25 @@ func TestBatcherRecoversAfterOutageLongerThanLease(t *testing.T) {
}
}

// TestBatcherRecoveringHeartbeatFailureIsAnOwedUpload proves that a heartbeat
// failing while the batcher recovers reports the same owed upload a failed
// publish does. The heartbeat is the relay step of that publish: the turns are
// durable on this computer and only their upload is pending, which is how a
// quit with the relay down tells a confirmed local save from a lost one.
func TestBatcherRecoveringHeartbeatFailureIsAnOwedUpload(t *testing.T) {
r := newRig(t)
b := r.batcher()
r.publishFirst(map[string]string{"a": "0"})
note(b, r.seal(map[string]string{"a": "1"}))

r.dirA.set(directory.ErrUnreachable)
b.flush(context.Background())
err := b.Close(context.Background())
if err == nil || !syncwords.UploadPending(err) {
t.Fatalf("a recovering publish with the relay down returned %v, want an owed upload", err)
}
}

func TestSkewIsSurfacedOnce(t *testing.T) {
r := newRig(t)
b := r.batcher()
Expand Down
Loading