chenhg5/cc-connect · error

acp: session/prompt: %w

Error message

acp: session/prompt: %w

What it means

Wrapped when the JSON-RPC `session/prompt` call fails while delivering the user's message. The error is also emitted as a core.EventError on the session's event stream so the engine can surface it to the messaging platform, then returned to the caller.

Source

Thrown at agent/acp/session.go:621

	sid := s.currentACPSessionID()
	if sid == "" {
		return fmt.Errorf("acp: no agent session id")
	}

	promptBlocks := []any{
		map[string]any{"type": "text", "text": prompt},
	}
	params := map[string]any{
		"sessionId": sid,
		"prompt":    promptBlocks,
	}

	slog.Debug("acp: sending session/prompt", "session_id", sid, "prompt_len", len(prompt))
	res, err := s.tr.call(s.ctx, "session/prompt", params)
	if err != nil {
		s.emit(core.Event{Type: core.EventError, Error: err})
		return fmt.Errorf("acp: session/prompt: %w", err)
	}
	slog.Debug("acp: session/prompt response", "session_id", sid, "response_len", len(res), "response", string(res))

	// Text was streamed via session/update; engine aggregates EventText.
	s.emit(core.Event{
		Type:      core.EventResult,
		SessionID: sid,
		Done:      true,
	})
	return nil
}

func (s *acpSession) appendImageRefs(prompt string, images []core.ImageAttachment) string {
	attachDir := filepath.Join(s.workDir, ".cc-connect", "attachments")
	if err := os.MkdirAll(attachDir, 0o755); err != nil {
		slog.Warn("acp: mkdir attachments failed", "error", err)
		return prompt
	}

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Read the wrapped cause: if it indicates an unknown session, start a new session and retry the prompt.
  2. Check the emitted EventError on the stream — agent-side refusal messages (quota, safety) usually carry the reason.
  3. Increase the prompt timeout or reduce the prompt size if it timed out on long turns.
  4. If the agent process died, check the process-exit stderr log, fix the crash cause, and recreate the session.
  5. Retry once on transient transport errors before failing the user message.

Example fix

// before: one-shot send, user gets raw failure
if err := sess.Send(prompt, mid, nil, nil); err != nil {
    return err
}
// after: detect stale session and recreate once
if err := sess.Send(prompt, mid, nil, nil); err != nil {
    sess, rerr := agent.StartSession(ctx, core.ContinueSession, nil)
    if rerr != nil { return rerr }
    return sess.Send(prompt, mid, nil, nil)
}
Defensive patterns

Strategy: retry

Validate before calling

// preflight: only send on an initialized, live session with a known id
if sess == nil || !sessionAlive(sess) || currentACPID(sess) == "" {
    return fmt.Errorf("session not ready for prompt")
}

Type guard

func ready(sess *acpSession) bool {
    return sess.alive.Load() && sess.currentACPSessionID() != ""
}

Try / catch

if err := sess.Send(prompt, mid, nil, nil); err != nil {
    if strings.Contains(err.Error(), "acp: session/prompt") {
        select {
        case ev := <-sess.Events():
            if ev.Type == core.EventError { slog.Warn("agent refused prompt", "cause", ev.Error) }
        default:
        }
        // recreate session and retry once for transient/stale-session causes
    }
    return err
}

Prevention

When it happens

Trigger: The agent returned a JSON-RPC error for session/prompt (session not found after agent restart, prompt rejected, content policy/limit hit) or the transport call failed — timeout, ctx cancelled, agent process died mid-call.

Common situations: Agent restarted and its old session id is stale; prompt too large or containing content the agent refuses; network/socket hiccup to a remote ACP agent; user-cancelled context; agent hit rate limits.

Understand the failure class

Background: "API request failed": what wrapped HTTP errors from external APIs mean and how to find the real cause — this error's family across 29 libraries.

Related errors


AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06). Data as JSON: /api/errors/c162021304f55ae3. Report an issue: GitHub.