plandex-ai/plandex · error

failed to read piped data: %v

Error message

failed to read piped data: %v

What it means

In MustLoadContext, when stdin is a named pipe, io.ReadAll on a bufio.Reader over os.Stdin fails while consuming piped input. The pipe writer closed with an error or the read was interrupted, so the piped content cannot be loaded as context.

Source

Thrown at app/cli/lib/context_load.go:75

	}

	if params.Note != "" {
		loadContextReq = append(loadContextReq, &shared.LoadContextParams{
			ContextType: shared.ContextNoteType,
			Body:        params.Note,
			ApiKeys:     authVars,
			OpenAIBase:  openAIBase,
			OpenAIOrgId: os.Getenv("OPENAI_ORG_ID"),
			SessionId:   params.SessionId,
			AutoLoaded:  params.AutoLoaded,
		})
	}

	if fileInfo.Mode()&os.ModeNamedPipe != 0 {
		reader := bufio.NewReader(os.Stdin)
		pipedData, err := io.ReadAll(reader)
		if err != nil {
			onErr(fmt.Errorf("failed to read piped data: %v", err))
		}

		if len(pipedData) > 0 {
			loadContextReq = append(loadContextReq, &shared.LoadContextParams{
				ContextType: shared.ContextPipedDataType,
				Body:        string(pipedData),
				ApiKeys:     authVars,
				OpenAIBase:  openAIBase,
				OpenAIOrgId: os.Getenv("OPENAI_ORG_ID"),
				SessionId:   params.SessionId,
				AutoLoaded:  params.AutoLoaded,
			})
		}
	}

	var inputUrls []string
	var inputFilePaths []string

View on GitHub (pinned to e2d772072e)

Solutions

  1. Re-run the upstream command and confirm it exits successfully before piping
  2. Check for broken pipe messages and disk/fd limits (ulimit)
  3. Test with a small known payload: `echo hi | plandex ...`
  4. If data comes over ssh/network, verify connection stability

Example fix

// before
pipedData, err := io.ReadAll(reader)
if err != nil {
	onErr(fmt.Errorf("failed to read piped data: %v", err))
}
// after
pipedData, err := io.ReadAll(reader)
if err != nil {
	onErr(fmt.Errorf("failed to read piped data after %d bytes: %w", len(pipedData), err))
}
Defensive patterns

Strategy: try-catch

Validate before calling

// verify the upstream producer exits 0 before piping
some_cmd > /tmp/out.txt && plandex load /tmp/out.txt || echo "producer failed"

Type guard

// Go: ensure reader is non-nil and stdin is a live pipe
func pipeReadable() bool {
	fi, err := os.Stdin.Stat()
	return err == nil && fi.Mode()&os.ModeNamedPipe != 0 && fi.Size() != 0
}

Try / catch

// Go: read with error context including bytes captured
pipedData, err := io.ReadAll(reader)
if err != nil {
	return fmt.Errorf("failed to read piped data after %d bytes: %w", len(pipedData), err)
}

Prevention

When it happens

Trigger: io.ReadAll(reader) returns an error while reading piped stdin — writer closed abruptly, pipe broken (reader process killed), or I/O error on the stdin fd.

Common situations: `some_cmd | plandex load ...` where the producing command crashed or was killed mid-stream; reading from a pipe over an interrupted ssh/session; extremely large pipe payloads hit an fd/stream error.

Related errors


AI-assisted analysis of plandex-ai/plandex@e2d772072e (2026-09-05). Data as JSON: /api/errors/fcac482cf0e9342f. Report an issue: GitHub.