fix(client): tolerate script replay after command completion
This commit is contained in:
1 parent
6984a09486
commit
1b5c6dbf98
5 files changed
+180
-2
No files matched your search
@@ -416,11 +416,21 @@ func serveActive(ctx context.Context, transport Transport, options RunnerOptions
|
||||
}
|
||||
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)
|
||||
err = finishedScriptReplay(ctx, options.Store, envelope.GetScriptChunk().GetIssueUuid(), err)
|
||||
if err != nil {
|
||||
return fmt.Errorf("apply script chunk for %s: %w", envelope.GetScriptChunk().GetIssueUuid(), err)
|
||||
}
|
||||
options.incMetric("terminal_script_frame")
|
||||
continue
|
||||
}
|
||||
case envelope.GetScriptCommit() != nil:
|
||||
if err := handleScriptCommit(ctx, transport, options.Store, session, envelope.GetScriptCommit(), limits, options.Now, sent); err != nil {
|
||||
return fmt.Errorf("commit script for %s: %w", envelope.GetScriptCommit().GetIssueUuid(), err)
|
||||
err = finishedScriptReplay(ctx, options.Store, envelope.GetScriptCommit().GetIssueUuid(), err)
|
||||
if err != nil {
|
||||
return fmt.Errorf("commit script for %s: %w", envelope.GetScriptCommit().GetIssueUuid(), err)
|
||||
}
|
||||
options.incMetric("terminal_script_frame")
|
||||
continue
|
||||
}
|
||||
if options.OnScriptReady != nil {
|
||||
issue, err := domain.ParseUUIDv7(envelope.GetScriptCommit().GetIssueUuid())
|
||||
@@ -563,6 +573,27 @@ func boundedError(err error) string {
|
||||
return message
|
||||
}
|
||||
|
||||
// A reconnect can race the server's upload replay with the client's terminal
|
||||
// event replay. Leave the finished command unchanged and let its pending
|
||||
// events drain; no script acknowledgement or launch should be fabricated.
|
||||
func finishedScriptReplay(ctx context.Context, store *spool.Store, text string, transferErr error) error {
|
||||
if !errors.Is(transferErr, spool.ErrScriptTerminal) {
|
||||
return transferErr
|
||||
}
|
||||
issue, err := domain.ParseUUIDv7(text)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
command, err := store.GetCommand(ctx, issue)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !command.Terminal {
|
||||
return transferErr
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func handleScriptChunk(ctx context.Context, transport Transport, store *spool.Store, session Session, chunk *rvboxv1.ScriptChunk, limits agentproto.Limits, now func() time.Time, sent map[domain.UUID]uint64) error {
|
||||
status, err := ApplyScriptChunk(ctx, store, session, chunk, limits)
|
||||
if err != nil {
|
||||
|
||||
Reference in new issue
Block a user