Skip to content

v2 review fixes: lifecycle cleanup and docs#62

Merged
znull merged 4 commits into
znull/stage-v2-cleanfrom
znull/v2-review-fixes
Jun 16, 2026
Merged

v2 review fixes: lifecycle cleanup and docs#62
znull merged 4 commits into
znull/stage-v2-cleanfrom
znull/v2-review-fixes

Conversation

@znull

@znull znull commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Fixes issues discovered doing a review of the latest stage-v2-clean state.

/cc @mhagger - these are the changes we discussed.

Copilot Summary

This PR applies small review-driven fixes on top of the v2 stage API branch:

  • Cancel the derived pipeline context on pre-start failures and include the offending stage name in invalid stream requirement errors.
  • Close an already-configured WithStdoutCloser destination before Output() replaces stdout with its capture buffer.
  • Expose WithStdinRequirement and WithStdoutRequirement so Function stages can participate in stream requirement negotiation without reimplementing Stage.
  • Document the known limitation for borrowed non-file stdin readers feeding command stages that can exit without draining stdin.

znull and others added 4 commits June 16, 2026 00:44
Ensure pre-start validation failures cancel the derived pipeline context,
and include the offending stage name in invalid stream-requirement errors.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Release any previously configured stdout stream before replacing it with
the buffer used by Output, preserving ownership of WithStdoutCloser.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add Function options for declaring stdin and stdout stream requirements,
so Function stages can participate in file-preference negotiation.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Explain the known deadlock risk for borrowed non-file stdin readers
feeding a command that exits without draining stdin.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@znull znull self-assigned this Jun 16, 2026
@znull znull marked this pull request as ready for review June 16, 2026 14:01
@znull znull requested a review from a team as a code owner June 16, 2026 14:01
Copilot AI review requested due to automatic review settings June 16, 2026 14:01

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR applies review-driven fixes to the v2 stage pipeline API, focusing on lifecycle cleanup, stream requirement negotiation, and clearer documentation/error reporting.

Changes:

  • Ensure the derived pipeline context is canceled on startup failures and improve invalid stream-requirement errors by including the stage name.
  • Make Pipeline.Output() close any previously configured WithStdoutCloser destination before switching to an internal capture buffer.
  • Expose WithStdinRequirement/WithStdoutRequirement for Function stages and document a known stdin limitation with non-file readers.
Show a summary per file
File Description
pipe/pipeline.go Adds lifecycle cleanup on pre-start failures, improves requirement validation errors, documents stdin limitation, and adjusts Output() stdout handling.
pipe/pipeline_test.go Adds/updates tests covering Output() closing behavior, Function stream requirements, and updated error messages.
pipe/function.go Exposes FunctionOptions for stdin/stdout stream requirements and refactors forbid options to reuse them.

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 3/3 changed files
  • Comments generated: 1

Comment thread pipe/pipeline.go

@mhagger mhagger left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left one change suggestion for you to consider.

Comment thread pipe/pipeline.go
Comment on lines +394 to +397
if err := p.stdout.Close(); err != nil {
return nil, fmt.Errorf("closing previous stdout: %w", err)
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ISTM that trying to call Output() after having already set stdout would always be a programming error: never a sensible thing to do, likely to happen every time the code is run (i.e., high chance of detecting it in CI), and possibly tricky to figure out if this kind of caller error slipped through. What would you think about making this case panic() instead of silently covering up the mistake?

For that matter, using WithStdout() or WithStderr()/WithStderrCloser() more than once could also panic for the same reason.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd support that, yeah. Making things impossible to misuse is good.

@znull znull merged commit 326a1a5 into znull/stage-v2-clean Jun 16, 2026
3 checks passed
@znull znull deleted the znull/v2-review-fixes branch June 16, 2026 22:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants