{"record":{"id":"5b4269665259aae3","repo":"github/copilot-sdk","slug":"sessionfs-initialworkingdirectory-is-required","errorCode":null,"errorMessage":"SessionFS.InitialWorkingDirectory is required","messagePattern":"SessionFS\\.InitialWorkingDirectory is required","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/client.go","lineNumber":87,"sourceCode":"\t\tcallbacks[defaultBearerTokenProviderName] = provider.BearerTokenProvider\n\t}\n\tfor i := range providers {\n\t\tif providers[i].BearerTokenProvider != nil {\n\t\t\tcallbacks[providers[i].Name] = providers[i].BearerTokenProvider\n\t\t}\n\t}\n\tif len(callbacks) == 0 {\n\t\treturn nil\n\t}\n\treturn callbacks\n}\n\nfunc validateSessionFSConfig(config *SessionFSConfig) error {\n\tif config == nil {\n\t\treturn nil\n\t}\n\tif config.InitialWorkingDirectory == \"\" {\n\t\treturn errors.New(\"SessionFS.InitialWorkingDirectory is required\")\n\t}\n\tif config.SessionStatePath == \"\" {\n\t\treturn errors.New(\"SessionFS.SessionStatePath is required\")\n\t}\n\tif config.Conventions != rpc.SessionFSSetProviderConventionsPosix && config.Conventions != rpc.SessionFSSetProviderConventionsWindows {\n\t\treturn errors.New(\"SessionFS.Conventions must be either 'posix' or 'windows'\")\n\t}\n\treturn nil\n}\n\n// validateEnvironmentOptions enforces the transport-specific rules for\n// per-client environment, working directory, and telemetry. It panics (fails\n// loud) on a misconfiguration, matching the other SDKs.\n//\n// The in-process transport loads the native runtime into this process, whose\n// single environment block and process-global working directory cannot carry\n// per-client values, and whose telemetry lowers to shared process-global env\n// vars — so options that depend on them are rejected there. Child-process","sourceCodeStart":69,"sourceCodeEnd":105,"githubUrl":"https://github.com/github/copilot-sdk/blob/cd8cf15dc3f9e762615790aaed0a771a0f392755/go/client.go#L69-L105","documentation":"NewClient calls validateSessionFSConfig when a SessionFSConfig is supplied. SessionFS requires at minimum an initial working directory; if InitialWorkingDirectory is empty this error is returned before the client is created. SessionStatePath and Conventions are validated immediately after.","triggerScenarios":"Passing &SessionFSConfig{} (or SessionFSConfig with InitialWorkingDirectory unset) in ClientOptions to NewClient, while leaving InitialWorkingDirectory as the empty string zero value.","commonSituations":"Constructing the config from environment variables or flags where the path is unset/empty; struct literal initialization that sets SessionStatePath and Conventions but forgets InitialWorkingDirectory; copy-pasting a config and deleting the working directory field.","solutions":["Set InitialWorkingDirectory to an absolute path of an existing directory before calling NewClient.","Populate it from an env var with a fallback and fail fast with a clearer message if empty.","Verify the other required fields too: SessionStatePath (non-empty) and Conventions (SessionFSSetProviderConventionsPosix or Windows)."],"exampleFix":"// before\nclient, err := NewClient(ctx, ClientOptions{\n    SessionFS: &SessionFSConfig{Conventions: rpc.SessionFSSetProviderConventionsPosix},\n})\n// after\nclient, err := NewClient(ctx, ClientOptions{\n    SessionFS: &SessionFSConfig{\n        InitialWorkingDirectory: \"/home/user/project\",\n        SessionStatePath:        \"/home/user/.copilot/session-state\",\n        Conventions:             rpc.SessionFSSetProviderConventionsPosix,\n    },\n})","handlingStrategy":"validation","validationCode":"func validateFS(cfg *SessionFSConfig) error {\n    if cfg == nil { return nil }\n    if cfg.InitialWorkingDirectory == \"\" { return errors.New(\"InitialWorkingDirectory must be set\") }\n    if cfg.SessionStatePath == \"\" { return errors.New(\"SessionStatePath must be set\") }\n    return nil\n}","typeGuard":null,"tryCatchPattern":"client, err := NewClient(ctx, opts)\nif err != nil {\n    if strings.Contains(err.Error(), \"SessionFS.\") {\n        return fmt.Errorf(\"invalid SessionFS config: %w\", err)\n    }\n    return err\n}","preventionTips":["Never construct SessionFSConfig with unset fields; set all of InitialWorkingDirectory, SessionStatePath, and Conventions.","Load paths from env/flags with explicit empty checks before building the config.","Use absolute, existing directories for InitialWorkingDirectory.","Write a table-driven unit test asserting NewClient rejects empty SessionFS fields."],"tags":["go","sessionfs","config-validation","client"],"backgroundTag":"missing-required-config-field","analyzedSha":"cd8cf15dc3f9e762615790aaed0a771a0f392755","analyzedAt":"2026-09-09T18:32:31.973Z","contentChangedAt":"2026-09-09T18:32:31.973Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}