{"record":{"id":"38346dbc46878c0a","repo":"github/copilot-sdk","slug":"failed-to-apply-mode-specific-session-options-w","errorCode":null,"errorMessage":"failed to apply mode-specific session options: %w","messagePattern":"failed to apply mode-specific session options: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/mode_empty.go","lineNumber":298,"sourceCode":"\t\t\thasAny = true\n\t\t}\n\t\tif base.IncludedBuiltinSkills != nil {\n\t\t\tpatch.IncludedBuiltinSkills = base.IncludedBuiltinSkills\n\t\t\thasAny = true\n\t\t}\n\t}\n\tif !hasAny {\n\t\treturn nil\n\t}\n\tif _, err := session.RPC.Options.Update(ctx, patch); err != nil {\n\t\t// The runtime session exists but the post-create options patch\n\t\t// failed — best-effort disconnect so we don't leak it (in empty\n\t\t// mode it would otherwise keep running with permissive defaults).\n\t\t_ = session.Disconnect()\n\t\tc.sessionsMux.Lock()\n\t\tdelete(c.sessions, session.SessionID)\n\t\tc.sessionsMux.Unlock()\n\t\treturn fmt.Errorf(\"failed to apply mode-specific session options: %w\", err)\n\t}\n\treturn nil\n}\n\n// optBackInFields is the subset of SessionConfig / ResumeSessionConfig shared\n// by [Client.updateSessionOptionsForMode].\ntype optBackInFields struct {\n\tSkipCustomInstructions *bool\n\tCustomAgentsLocalOnly  *bool\n\tCoauthorEnabled        *bool\n\tManageScheduleEnabled  *bool\n\tIncludedBuiltinSkills  []string\n}\n","sourceCodeStart":280,"sourceCodeEnd":312,"githubUrl":"https://github.com/github/copilot-sdk/blob/cd8cf15dc3f9e762615790aaed0a771a0f392755/go/mode_empty.go#L280-L312","documentation":"updateSessionOptionsForMode applies mode-specific session options to a newly created or resumed session. If applying those options fails, the session is disconnected (best-effort) and removed from the client's session map to avoid leaking a session running with permissive defaults, and this wrapped error is returned.","triggerScenarios":"CreateSession or ResumeSessionWithOptions where the server rejects the mode-specific option update — e.g. an invalid opt-back-in field combination, an unsupported option for the mode, or a session/request error from the server.","commonSituations":"Config fields in SessionConfig/ResumeSessionConfig that are incompatible with the selected mode; server version that doesn't support a requested option; transient request failures during session setup.","solutions":["Inspect the wrapped inner error (via errors.Unwrap or %v) for the exact server-side rejection reason.","Compare your SessionConfig/ResumeSessionConfig fields (optBackInFields) against the allowed options for the selected mode.","Retry CreateSession/ResumeSessionWithOptions if the inner error indicates a transient transport failure.","Verify client and server versions both support the requested session options."],"exampleFix":"// before\nconfig.OptBackIn = []string{\"fs_write\", \"network\"} // unsupported for this mode\n// after\nconfig.OptBackIn = []string{\"fs_write\"} // only options valid for the mode","handlingStrategy":"try-catch","validationCode":"func validateModeOptions(cfg SessionConfig) error {\n    // ensure opt-back-in fields are permitted for cfg.Mode before calling CreateSession\n    return nil\n}","typeGuard":null,"tryCatchPattern":"sess, err := client.CreateSession(ctx, cfg)\nif err != nil {\n    var wrapped interface{ Unwrap() error }\n    if errors.As(err, &target) { /* inspect inner reason */ }\n    // cleanup is automatic; fix config and retry\n}","preventionTips":["Only set session options documented for the chosen mode","Keep client and server versions aligned","Log the unwrapped inner error for diagnosis"],"tags":["session","config","mode"],"backgroundTag":"invalid-config-value","analyzedSha":"cd8cf15dc3f9e762615790aaed0a771a0f392755","analyzedAt":"2026-09-09T18:32:31.973Z","contentChangedAt":"2026-09-09T18:32:31.973Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}