fix: deliver long CLI passthrough prompts intact (#3894)

Co-authored-by: Carlos Florencio <carlosmflorencio@gmail.com>
This commit is contained in:
Dmitry Koryakov
2026-09-24 15:45:00 +02:00
committed by GitHub
parent d602745281
commit 5cb908e4ad
28 changed files with 1129 additions and 143 deletions
@@ -724,8 +724,8 @@ func (e *Executor) promptPassthrough(ctx context.Context, taskID string, session
zap.Error(err))
}
for _, chunk := range agents.PlanPassthroughStdinChunks(promptWithAttachments, pt) {
if chunk.DelayBefore > 0 {
time.Sleep(chunk.DelayBefore)
if err := waitPassthroughChunkDelay(ctx, chunk.DelayBefore); err != nil {
return nil, err
}
if err := e.agentManager.WritePassthroughStdin(ctx, sessionID, chunk.Data); err != nil {
return nil, fmt.Errorf("failed to write to passthrough stdin: %w", err)
@@ -734,6 +734,20 @@ func (e *Executor) promptPassthrough(ctx context.Context, taskID string, session
return &PromptResult{StopReason: stopReasonPassthrough}, nil
}
func waitPassthroughChunkDelay(ctx context.Context, delay time.Duration) error {
if delay <= 0 {
return nil
}
timer := time.NewTimer(delay)
defer timer.Stop()
select {
case <-ctx.Done():
return ctx.Err()
case <-timer.C:
return nil
}
}
func (e *Executor) buildPassthroughPromptWithAttachments(ctx context.Context, session *models.TaskSession, prompt string, attachments []v1.MessageAttachment) (string, error) {
if len(attachments) == 0 {
return prompt, nil
@@ -588,6 +588,37 @@ func TestExecutor_Prompt_PassthroughSubmitDelaySplitsWrites(t *testing.T) {
}
}
func TestExecutor_Prompt_PassthroughCancellationStopsDelayedSubmit(t *testing.T) {
repo := newMockRepository()
ctx, cancel := context.WithCancel(context.Background())
agentManager := &mockAgentManager{
isPassthroughSessionFunc: func(_ context.Context, _ string) bool { return true },
resolvePassthroughConfigFunc: func(_ context.Context, _ string) (agents.PassthroughConfig, error) {
return agents.PassthroughConfig{
Supported: true,
SubmitSequence: "\r",
DisableBracketedPaste: true,
SubmitDelay: time.Second,
}, nil
},
writePassthroughStdinFunc: func(_ context.Context, _ string, data string) error {
if data == "hello agent" {
cancel()
}
return nil
},
}
seedPassthroughSession(t, repo, agentManager, "task-1", "sess-1", "exec-1")
exec := newTestExecutor(t, agentManager, repo)
if _, err := exec.Prompt(ctx, "task-1", "sess-1", "hello agent", nil, false); !errors.Is(err, context.Canceled) {
t.Fatalf("Prompt error = %v, want context cancellation", err)
}
if got := len(agentManager.writePassthroughStdinCalls); got != 1 {
t.Fatalf("stdin calls after cancellation = %d, want 1", got)
}
}
func TestExecutor_Prompt_ACPPathUnchanged(t *testing.T) {
repo := newMockRepository()
agentManager := &mockAgentManager{