fix(server): omit redundant tombstone reconciliation discards

This commit is contained in:
cabbage committed 2026-11-16 15:18:07 +00:00
1 parent 9e7c409ba7
commit 86a9cfdd72
9 files changed
+228 -3

No files matched your search

+7 -1
View File
@@ -183,7 +183,13 @@ func (store *Store) reconcileClientSnapshotAt(ctx context.Context, clientID stri
incidents = append(incidents, reconcileIncident{issue: parseIssueUnchecked(key), summary: "client and server command state disagree; local process must be terminated", dataLoss: true})
}
case domain.ReconcileDiscardLocalTerminal:
result.DiscardLocalTerminalIssueUuids = append(result.DiscardLocalTerminalIssueUuids, key)
// Tombstones already have no command body or outbox to discard.
// Keep validating their hash/revision and reconciling contradictions
// above, but do not echo the growing compact ledger on every reconnect.
// The redundant UUID list alone can exceed a legacy peer's read limit.
if !client.GetTombstoned() {
result.DiscardLocalTerminalIssueUuids = append(result.DiscardLocalTerminalIssueUuids, key)
}
case domain.ReconcileResumeDelivery:
if generation != 0 && row.target.Valid && uint64(row.target.Int64) != generation || generation != 0 && !row.target.Valid {
if _, err := tx.ExecContext(ctx, `UPDATE commands SET target_session_generation = ? WHERE issue_uuid = ? AND client_id = ? AND lifecycle BETWEEN 2 AND 4`, generation, row.issue[:], clientID); err != nil {
@@ -0,0 +1,73 @@
package store
import (
"context"
"crypto/sha256"
"path/filepath"
"testing"
"time"
rvboxv1 "github.com/rvbox/rvbox/gen/go/rvbox/v1"
)
func TestReconcileTombstonesStillValidateAndInterrupt_REC_RECONCILE_09(t *testing.T) {
for _, scenario := range []string{"missing", "terminal", "running", "hash-mismatch"} {
t.Run(scenario, func(t *testing.T) {
ctx := context.Background()
opened, err := Open(ctx, Options{DataDir: filepath.Join(t.TempDir(), "state"), BusyTimeout: time.Second})
if err != nil {
t.Fatal(err)
}
t.Cleanup(func() { _ = opened.Close() })
now := time.Now().UTC()
if _, err := opened.RegisterClientSession(ctx, ClientRegistration{ClientID: "tombstone-client", Platform: 3, Architecture: "amd64", DaemonVersion: "test", DaemonCWD: `C:\`, SupportedShells: []byte{1}, ClientInstanceID: [16]byte{1}, SessionID: [16]byte{2}, ConnectedAt: now}); err != nil {
t.Fatal(err)
}
issue := mustReconcileIssue(t, "019c46f1-1d02-7000-8000-0000000000d2")
hash := sha256.Sum256([]byte("terminal command"))
if scenario != "missing" {
if _, err := opened.QueueCommand(ctx, QueueCommandInput{IssueUUID: issue, ClientID: "tombstone-client", IssueTime: now, ReceiptTime: now, ImmutableSHA256: hash, ExecutionSpec: []byte("opaque")}); err != nil {
t.Fatal(err)
}
phase := rvboxv1.CommandLifecycle_COMMAND_SUCCEEDED
if scenario == "running" {
phase = rvboxv1.CommandLifecycle_COMMAND_RUNNING
}
// Seed only the metadata being reconciled; no execution is involved.
if _, err := opened.DB().ExecContext(ctx, `UPDATE commands SET lifecycle = ?, terminal_time = CASE WHEN ? >= 5 THEN ? ELSE NULL END WHERE issue_uuid = ?`, phase, phase, now.UnixNano(), issue[:]); err != nil {
t.Fatal(err)
}
}
if scenario == "hash-mismatch" {
hash[0] ^= 0xff
}
result, err := opened.ReconcileClientSnapshotForSession(ctx, "tombstone-client", 1, &rvboxv1.ReconcileSnapshot{RetainedCommands: []*rvboxv1.ReconcileCommandState{{
IssueUuid: issue.String(), CommandRevision: 1, Lifecycle: rvboxv1.CommandLifecycle_COMMAND_SUCCEEDED,
Tombstoned: true, ImmutableRequestSha256: hash[:],
}}})
if err != nil {
t.Fatal(err)
}
if len(result.GetDiscardLocalTerminalIssueUuids()) != 0 || len(result.GetTerminateLocalIssueUuids()) != 0 {
t.Fatalf("already compacted tombstone needs no local action: %v", result)
}
var incidents int
if err := opened.DB().QueryRowContext(ctx, `SELECT count(*) FROM storage_incidents`).Scan(&incidents); err != nil {
t.Fatal(err)
}
wantIncidents := 0
if scenario == "running" || scenario == "hash-mismatch" {
wantIncidents = 1
}
if incidents != wantIncidents {
t.Fatalf("incidents=%d, want %d", incidents, wantIncidents)
}
if scenario == "running" {
view, err := opened.GetCommandView(ctx, "tombstone-client", issue)
if err != nil || view.Lifecycle != uint32(rvboxv1.CommandLifecycle_COMMAND_INTERRUPTED) {
t.Fatalf("tombstone must still interrupt contradictory running state: %+v, %v", view, err)
}
}
})
}
}