{"record":{"id":"08eb4ef2e13710dd","repo":"dagger/dagger","slug":"failed-to-marshal-session-data-w","errorCode":null,"errorMessage":"failed to marshal session data: %w","messagePattern":"failed to marshal session data: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/cmd/dagger/llm.go","lineNumber":808,"sourceCode":"\tsessionID := existingUUID\n\tif sessionID == \"\" {\n\t\tid, err := uuid.NewV7()\n\t\tif err != nil {\n\t\t\treturn \"\", fmt.Errorf(\"failed to generate session UUID: %w\", err)\n\t\t}\n\t\tsessionID = id.String()\n\t}\n\n\tmetadata := sessionMetadata{\n\t\tName:      initialPrompt,\n\t\tModel:     s.model,\n\t\tCreatedAt: time.Now().UTC().Format(time.RFC3339),\n\t\tLLMID:     string(llmID),\n\t}\n\n\tjsonData, err := json.MarshalIndent(metadata, \"\", \"  \")\n\tif err != nil {\n\t\treturn sessionID, fmt.Errorf(\"failed to marshal session data: %w\", err)\n\t}\n\n\tsessionFile := filepath.Join(sessionDir, sessionID+\".json\")\n\tif err := os.WriteFile(sessionFile, jsonData, 0600); err != nil {\n\t\treturn sessionID, fmt.Errorf(\"failed to write session file: %w\", err)\n\t}\n\t// WriteFile only applies the mode on creation; fix up files written more\n\t// openly by an older version.\n\tif err := os.Chmod(sessionFile, 0600); err != nil {\n\t\treturn sessionID, fmt.Errorf(\"failed to restrict session file permissions: %w\", err)\n\t}\n\n\tslog.Debug(\"auto-saved LLM session\", \"id\", sessionID, \"name\", initialPrompt, \"file\", sessionFile)\n\treturn sessionID, nil\n}\n\n// LoadSession loads an LLM session from disk by UUID. The message history is\n// replayed for telemetry against replayCtx (not ctx), so callers can surface","sourceCodeStart":790,"sourceCodeEnd":826,"githubUrl":"https://github.com/dagger/dagger/blob/82ba2681dbe30d3547a1dc50ea495900ab5b6047/internal/cmd/dagger/llm.go#L790-L826","documentation":"AutoSaveSession throws this when json.MarshalIndent of the sessionMetadata struct fails. Since sessionMetadata contains only plain strings and an RFC3339 timestamp, marshaling essentially cannot fail in practice; this is a defensive wrapper around the encoding/json error path.","triggerScenarios":"Calling AutoSaveSession when json.MarshalIndent(metadata) returns an error — theoretically only via unsupported values (not possible with the fixed string fields), e.g. if the struct gains unsupported field types in future versions.","commonSituations":"Practically unreachable with the current sessionMetadata fields; would appear only after code changes introduce non-serializable field types or a corrupted in-memory value.","solutions":["Verify the metadata fields are JSON-serializable (no channels, funcs, or unsupported types were added)","Update Dagger if a regression introduced non-serializable metadata","If hit, capture the wrapped error and report it; the fields are all strings so this indicates a library bug"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":"// sessionMetadata is all strings; a pre-check only matters after schema changes\nfunc serializable(m sessionMetadata) bool {\n    _, err := json.Marshal(m)\n    return err == nil\n}","typeGuard":"func marshalable(v any) bool {\n    _, err := json.Marshal(v)\n    return err == nil\n}","tryCatchPattern":"if _, err := session.AutoSaveSession(ctx, prompt, uuid); err != nil {\n    if strings.Contains(err.Error(), \"failed to marshal session data\") {\n        // impossible with current string fields; report as a library bug\n        return fmt.Errorf(\"bug: non-serializable session metadata: %w\", err)\n    }\n    return err\n}","preventionTips":["Keep sessionMetadata fields limited to JSON-native types (string, int)","Run unit tests covering AutoSaveSession marshaling after any metadata schema change","Update Dagger if this error appears — it indicates a regression"],"tags":["json","serialization","dagger"],"backgroundTag":"json-marshal-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"}