dagger/dagger · error

auto-compact: %w

Error message

auto-compact: %w

What it means

Before appending a new prompt, the LLM session may auto-compact its history to stay within context limits. If maybeAutoCompact fails (underlying LLM/engine error), WithPrompt wraps it as "auto-compact: %w".

Source

Thrown at internal/cmd/dagger/llm.go:227

func (s *LLMSession) WithPrompt(ctx context.Context, input string) (*LLMSession, error) {
	s = s.Fork()

	// Resolve any @-path references in the prompt: paths already inside the
	// workspace are rewritten to workspace-relative paths, and the rest are
	// mounted read-only in the workspace with the prompt annotated with their
	// workspace locations.
	input = s.attachReferences(s.plumbingCtx, input)

	resolvedModel, err := s.llm.Model(s.plumbingCtx)
	if err != nil {
		return nil, err
	}
	s.model = resolvedModel

	// Check if we need to compact before adding the prompt
	compacted, err := s.maybeAutoCompact(ctx)
	if err != nil {
		return s, fmt.Errorf("auto-compact: %w", err)
	}

	prompted := compacted.WithPrompt(input)

	for {
		// update the sidebar after every step, not after the entire loop; step
		// is lazy, so sync to force it and re-root on the materialized state
		prompted, err = prompted.Step().Sync(ctx)
		if err != nil {
			return s, err
		}

		if err := s.updateLLM(prompted); err != nil {
			return s, err
		}

		// In --debug, surface how much this step grew the context, so spikes
		// (e.g. a tool dumping a huge result) are visible between steps.

View on GitHub (pinned to 82ba2681db)

Solutions

  1. Inspect the wrapped cause for the real failure and retry WithPrompt
  2. Clear or reduce the session history (start a fresh session) if compaction keeps failing
  3. Check engine/LLM connectivity (dagger core functions, network)

Example fix

null
Defensive patterns

Strategy: retry

Try / catch

s, err := session.WithPrompt(ctx, input)
if err != nil && strings.HasPrefix(err.Error(), "auto-compact:") {
    s, err = retry.WithBackoff(func() (*llm.LLMSession, error) { return session.WithPrompt(ctx, input) }, 3)
}

Prevention

When it happens

Trigger: Calling WithPrompt on an LLMSession when the pre-prompt compaction check fails (LLM call error, context/engine failure) at the first maybeAutoCompact call.

Common situations: Long sessions near the context window; transient LLM API failures; engine connectivity issues mid-session.

Related errors


AI-assisted analysis of dagger/dagger@82ba2681db (2026-09-05). Data as JSON: /api/errors/a019b573464b8956. Report an issue: GitHub.