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

@@ -49,7 +49,7 @@ func TestWebSocketHelloWelcome_HP_SES_06(t *testing.T) {
terminalIssue := "019c46f1-1d02-7000-8000-000000000073"
reconciled, err := agent.Reconcile(ctx, transport, result, &rvboxv1.ReconcileSnapshot{RetainedCommands: []*rvboxv1.ReconcileCommandState{
{IssueUuid: activeIssue, Lifecycle: rvboxv1.CommandLifecycle_COMMAND_RUNNING, CommandRevision: 1, ImmutableRequestSha256: make([]byte, 32)},
{IssueUuid: terminalIssue, Lifecycle: rvboxv1.CommandLifecycle_COMMAND_SUCCEEDED, CommandRevision: 1, Tombstoned: true, ImmutableRequestSha256: make([]byte, 32)},
{IssueUuid: terminalIssue, Lifecycle: rvboxv1.CommandLifecycle_COMMAND_SUCCEEDED, CommandRevision: 1, ImmutableRequestSha256: make([]byte, 32)},
}}, agentproto.DefaultLimits())
if err != nil {
t.Fatal(err)
@@ -0,0 +1,84 @@
package clientagent_test
import (
"context"
"strings"
"testing"
"time"
"github.com/coder/websocket"
rvboxv1 "github.com/rvbox/rvbox/gen/go/rvbox/v1"
"github.com/rvbox/rvbox/internal/agentproto"
"github.com/rvbox/rvbox/internal/client/agent"
"github.com/rvbox/rvbox/internal/domain"
)
func TestLegacyReconnectWithTombstoneHistory_REC_WS_03(t *testing.T) {
t.Parallel()
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
defer cancel()
fixture := newFrameFixture(t)
snapshot := &rvboxv1.ReconcileSnapshot{}
for i := 0; i < 1100; i++ {
issue, err := domain.NewUUIDv7()
if err != nil {
t.Fatal(err)
}
snapshot.RetainedCommands = append(snapshot.RetainedCommands, &rvboxv1.ReconcileCommandState{
IssueUuid: issue.String(), Lifecycle: rvboxv1.CommandLifecycle_COMMAND_SUCCEEDED,
CommandRevision: 1, Tombstoned: true, ImmutableRequestSha256: make([]byte, 32),
})
}
// A genuinely retained terminal command still needs discard authorization.
terminal, err := domain.NewUUIDv7()
if err != nil {
t.Fatal(err)
}
snapshot.RetainedCommands = append(snapshot.RetainedCommands, &rvboxv1.ReconcileCommandState{
IssueUuid: terminal.String(), Lifecycle: rvboxv1.CommandLifecycle_COMMAND_SUCCEEDED,
CommandRevision: 1, ImmutableRequestSha256: make([]byte, 32),
})
// Repeat the full snapshot to model an interrupted/lost reconciliation
// response. No subprotocol or updated read-limit wrapper is used.
for attempt := 0; attempt < 2; attempt++ {
raw, _, err := websocket.Dial(ctx, "wss"+strings.TrimPrefix(fixture.server.URL, "https")+"/v1/agent", &websocket.DialOptions{HTTPClient: fixture.server.Client()})
if err != nil {
t.Fatal(err)
}
raw.SetReadLimit(32 << 10)
transport := tombstoneLegacyTransport{raw}
t.Cleanup(func() { _ = raw.CloseNow() })
if raw.Subprotocol() != "" {
t.Fatal("legacy client unexpectedly negotiated a subprotocol")
}
accepted, err := agent.Handshake(ctx, transport, fixture.hello, agentproto.DefaultLimits())
if err != nil {
t.Fatal(err)
}
result, err := agent.Reconcile(ctx, transport, accepted, snapshot, agentproto.DefaultLimits())
if err != nil {
t.Fatalf("legacy reconnect %d: %v", attempt, err)
}
if got := result.GetDiscardLocalTerminalIssueUuids(); len(got) != 1 || got[0] != terminal.String() || len(result.GetTerminateLocalIssueUuids()) != 0 {
t.Fatalf("unexpected reconciliation instructions: %v", result)
}
if err := transport.Close(); err != nil {
t.Fatal(err)
}
}
}
type tombstoneLegacyTransport struct{ connection *websocket.Conn }
func (transport tombstoneLegacyTransport) Read(ctx context.Context) ([]byte, error) {
_, payload, err := transport.connection.Read(ctx)
return payload, err
}
func (transport tombstoneLegacyTransport) Write(ctx context.Context, payload []byte) error {
return transport.connection.Write(ctx, websocket.MessageBinary, payload)
}
func (transport tombstoneLegacyTransport) Close() error {
return transport.connection.Close(websocket.StatusNormalClosure, "")
}
@@ -83,7 +83,7 @@ func TestLargeDispatchAndReconciliation_HP_WS_01(t *testing.T) {
}
snapshot.RetainedCommands = append(snapshot.RetainedCommands, &rvboxv1.ReconcileCommandState{
IssueUuid: issue.String(), Lifecycle: rvboxv1.CommandLifecycle_COMMAND_SUCCEEDED,
CommandRevision: 1, Tombstoned: true, ImmutableRequestSha256: make([]byte, 32),
CommandRevision: 1, ImmutableRequestSha256: make([]byte, 32),
})
}
transport, _ := fixture.connect(t, ctx, snapshot)