{"record":{"id":"a019b573464b8956","repo":"dagger/dagger","slug":"auto-compact-w","errorCode":null,"errorMessage":"auto-compact: %w","messagePattern":"auto-compact: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/cmd/dagger/llm.go","lineNumber":227,"sourceCode":"func (s *LLMSession) WithPrompt(ctx context.Context, input string) (*LLMSession, error) {\n\ts = s.Fork()\n\n\t// Resolve any @-path references in the prompt: paths already inside the\n\t// workspace are rewritten to workspace-relative paths, and the rest are\n\t// mounted read-only in the workspace with the prompt annotated with their\n\t// workspace locations.\n\tinput = s.attachReferences(s.plumbingCtx, input)\n\n\tresolvedModel, err := s.llm.Model(s.plumbingCtx)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\ts.model = resolvedModel\n\n\t// Check if we need to compact before adding the prompt\n\tcompacted, err := s.maybeAutoCompact(ctx)\n\tif err != nil {\n\t\treturn s, fmt.Errorf(\"auto-compact: %w\", err)\n\t}\n\n\tprompted := compacted.WithPrompt(input)\n\n\tfor {\n\t\t// update the sidebar after every step, not after the entire loop; step\n\t\t// is lazy, so sync to force it and re-root on the materialized state\n\t\tprompted, err = prompted.Step().Sync(ctx)\n\t\tif err != nil {\n\t\t\treturn s, err\n\t\t}\n\n\t\tif err := s.updateLLM(prompted); err != nil {\n\t\t\treturn s, err\n\t\t}\n\n\t\t// In --debug, surface how much this step grew the context, so spikes\n\t\t// (e.g. a tool dumping a huge result) are visible between steps.","sourceCodeStart":209,"sourceCodeEnd":245,"githubUrl":"https://github.com/dagger/dagger/blob/82ba2681dbe30d3547a1dc50ea495900ab5b6047/internal/cmd/dagger/llm.go#L209-L245","documentation":"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\".","triggerScenarios":"Calling WithPrompt on an LLMSession when the pre-prompt compaction check fails (LLM call error, context/engine failure) at the first maybeAutoCompact call.","commonSituations":"Long sessions near the context window; transient LLM API failures; engine connectivity issues mid-session.","solutions":["Inspect the wrapped cause for the real failure and retry WithPrompt","Clear or reduce the session history (start a fresh session) if compaction keeps failing","Check engine/LLM connectivity (dagger core functions, network)"],"exampleFix":"null","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"s, err := session.WithPrompt(ctx, input)\nif err != nil && strings.HasPrefix(err.Error(), \"auto-compact:\") {\n    s, err = retry.WithBackoff(func() (*llm.LLMSession, error) { return session.WithPrompt(ctx, input) }, 3)\n}","preventionTips":["Keep sessions short; compact proactively","Monitor LLM provider status before long runs","Handle rate limits with backoff in agent loops"],"tags":["llm","session","context-window"],"backgroundTag":"auto-compact-failed","analyzedSha":"82ba2681dbe30d3547a1dc50ea495900ab5b6047","analyzedAt":"2026-09-05T07:21:37.930Z","contentChangedAt":"2026-09-05T07:21:37.930Z","schemaVersion":2},"datasetVersion":"2026-09-12T12:17:11.808Z"}