fix: recover reconnect after incomplete output capture

This commit is contained in:
cabbage committed 2026-10-27 14:36:06 +00:00
1 parent b52ca5a7c2
commit 6906ed52f2
9 files changed
+692 -3

No files matched your search

+23
View File
@@ -209,6 +209,12 @@ func runOnce(ctx context.Context, options RunnerOptions) (resultErr error) {
}
}
}
// Applying reconciliation can replace terminal rows with tombstones and
// terminate formerly active commands. Replay/capacity must use that new view.
snapshot, err = options.Store.ReconcileSnapshot(ctx)
if err != nil {
return fmt.Errorf("refresh reconciled client snapshot: %w", err)
}
sentEvents := make(map[domain.UUID]uint64)
if err := replayEvents(ctx, transport, options.Store, session, snapshot, limits, sentEvents); err != nil {
return fmt.Errorf("replay client events: %w", err)
@@ -294,6 +300,12 @@ func commandEventFromStored(event spool.Event) (*rvboxv1.CommandEvent, error) {
if err := proto.Unmarshal(event.Payload, &stored); err != nil || stored.Payload == nil {
return nil, fmt.Errorf("decode stored command event: %w", err)
}
if incomplete := stored.GetOutputIncomplete(); event.Kind == spool.EventKindOutputIncomplete && incomplete != nil && len(incomplete.Streams) == 0 {
// Early v1 writers omitted streams. Those events failed local wire
// validation before any server could accept their digest. Conservatively
// name both streams without changing persisted bytes, order, or reason.
incomplete.Streams = []rvboxv1.StreamKind{rvboxv1.StreamKind_STREAM_STDOUT, rvboxv1.StreamKind_STREAM_STDERR}
}
return &stored, nil
}
@@ -362,6 +374,11 @@ func serveActive(ctx context.Context, transport Transport, options RunnerOptions
continue
}
if err := flushEvents(ctx, transport, options.Store, session, issue, limits, sent); err != nil {
if errors.Is(err, spool.ErrUnknownCommand) {
// This internal wakeup can outlive a server-confirmed discard.
// It is a hint, not a new dispatch or an event acknowledgement.
continue
}
return fmt.Errorf("flush ready command %s events: %w", issue, err)
}
continue
@@ -391,6 +408,12 @@ func serveActive(ctx context.Context, transport Transport, options RunnerOptions
if err := ApplyEventAck(ctx, options.Store, envelope.GetEventAck()); err != nil {
return fmt.Errorf("apply event acknowledgement for %s: %w", envelope.GetEventAck().GetIssueUuid(), err)
}
issue, _ := domain.ParseUUIDv7(envelope.GetEventAck().GetIssueUuid())
// Released send-window credit must drain the durable tail even if no
// producer remains to emit another EventReady notification.
if err := flushEvents(ctx, transport, options.Store, session, issue, limits, sent); err != nil {
return fmt.Errorf("flush acknowledged command %s events: %w", issue, err)
}
case envelope.GetScriptChunk() != nil:
if err := handleScriptChunk(ctx, transport, options.Store, session, envelope.GetScriptChunk(), limits, options.Now, sent); err != nil {
return fmt.Errorf("apply script chunk for %s: %w", envelope.GetScriptChunk().GetIssueUuid(), err)