{"record":{"id":"43be1691cb32116e","repo":"plandex-ai/plandex","slug":"failed-to-stat-stdin-v","errorCode":null,"errorMessage":"failed to stat stdin: %v","messagePattern":"failed to stat stdin: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"app/cli/lib/context_load.go","lineNumber":49,"sourceCode":"\t\t}\n\n\t\tterm.LongSpinnerWithWarning(\"🗺️  Building project map...\", \"🗺️  This can take a while in larger projects...\")\n\t} else if params.NamesOnly {\n\t\tterm.LongSpinnerWithWarning(\"🌳 Loading directory tree...\", \"🌳 This can take a while in larger projects...\")\n\t} else {\n\t\tterm.StartSpinner(\"📥 Loading context...\")\n\t}\n\n\tonErr := func(err error) {\n\t\tterm.StopSpinner()\n\t\tterm.OutputErrorAndExit(\"Failed to load context: %v\", err)\n\t}\n\n\tvar loadContextReq shared.LoadContextRequest\n\n\tfileInfo, err := os.Stdin.Stat()\n\tif err != nil {\n\t\tonErr(fmt.Errorf(\"failed to stat stdin: %v\", err))\n\t}\n\n\tvar authVars map[string]string\n\tvar openAIBase string\n\n\tif params.Note != \"\" || fileInfo.Mode()&os.ModeNamedPipe != 0 {\n\t\tauthVars = MustVerifyAuthVarsSilent(auth.Current.IntegratedModelsMode)\n\t}\n\n\tif params.Note != \"\" {\n\t\tloadContextReq = append(loadContextReq, &shared.LoadContextParams{\n\t\t\tContextType: shared.ContextNoteType,\n\t\t\tBody:        params.Note,\n\t\t\tApiKeys:     authVars,\n\t\t\tOpenAIBase:  openAIBase,\n\t\t\tOpenAIOrgId: os.Getenv(\"OPENAI_ORG_ID\"),\n\t\t\tSessionId:   params.SessionId,\n\t\t\tAutoLoaded:  params.AutoLoaded,","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/cli/lib/context_load.go#L31-L67","documentation":"MustLoadContext calls os.Stdin.Stat() to detect whether data is piped into the CLI (named pipe check); this error means the stat syscall on stdin failed. It exits via onErr with 'Failed to load context'. Without knowing stdin's mode the command cannot tell if piped data should be captured as context.","triggerScenarios":"os.Stdin.Stat() returns an error — stdin fd is closed, invalid, or the OS denies stat (e.g. detached process, restricted sandbox/container without a stdin fd).","commonSituations":"Running the CLI with stdin explicitly closed (`plandex ... 0<&-`); daemonized/scheduled invocation with no stdin attached; restricted container runtimes that don't provide standard fds.","solutions":["Ensure stdin is attached when running the command (run interactively or redirect from a source)","If scripting, redirect input explicitly: `plandex ... < /dev/null`","Check the sandbox/container for fd restrictions (ulimit, security profile)","Upgrade or fix the launcher/daemon that invokes the CLI if it closes fds"],"exampleFix":"// before\nfileInfo, err := os.Stdin.Stat()\nif err != nil {\n\tonErr(fmt.Errorf(\"failed to stat stdin: %v\", err))\n}\n// after\nfileInfo, err := os.Stdin.Stat()\nif err != nil {\n\tif errors.Is(err, os.ErrInvalid) { // stdin closed — treat as no piped data\n\t\tfileInfo = &os.FileInfo(nil)\n\t\t// proceed without piped input instead of exiting\n\t} else {\n\t\tonErr(fmt.Errorf(\"failed to stat stdin: %w\", err))\n\t}\n}","handlingStrategy":"fallback","validationCode":"// check stdin is usable before the load command\nif fi, err := os.Stdin.Stat(); err != nil {\n\tlog.Printf(\"stdin unavailable (%v); proceeding without piped input\", err)\n}","typeGuard":"// Go: classify stdin mode safely\nfunc stdinIsPipe() bool {\n\tfi, err := os.Stdin.Stat()\n\treturn err == nil && fi.Mode()&os.ModeNamedPipe != 0\n}","tryCatchPattern":"// Go: treat unstatable stdin as no-piped-input rather than fatal\nfileInfo, err := os.Stdin.Stat()\nhasPipe := err == nil && fileInfo.Mode()&os.ModeNamedPipe != 0\nif err != nil { log.Printf(\"stdin stat failed, assuming no piped data: %v\", err) }","preventionTips":["Don't launch the CLI with closed stdin fds (0<&-)","In containers, ensure standard fds are attached","Test scheduled/daemon invocations with explicit `< /dev/null`","Keep fd limits (ulimit -n) sane in sandboxed environments"],"tags":["stdin","os","cli","filesystem"],"backgroundTag":"stdin-stat-failed","analyzedSha":"e2d772072efadbe41d2946d97d79be55532dbab5","analyzedAt":"2026-09-05T20:56:53.631Z","contentChangedAt":"2026-09-05T20:56:53.631Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}