Skip to content

Defer file closes in pkg/cli workflow readers and logs cache writer#34372

Draft
Copilot wants to merge 2 commits into
mainfrom
copilot/lint-monster-fix-file-close-issues
Draft

Defer file closes in pkg/cli workflow readers and logs cache writer#34372
Copilot wants to merge 2 commits into
mainfrom
copilot/lint-monster-fix-file-close-issues

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 24, 2026

LintMonster flagged three os.Open/os.OpenFile call sites in pkg/cli where Close() was not deferred immediately after a successful open, leaving room for descriptor leaks on early returns.

  • Workflow file readers

    • Updated filterMarkdownFilesWithFrontmatter to read each file inside a narrow helper scope and defer fd.Close() immediately after os.Open.
    • Updated extractWorkflowNameFromFile to use a deferred close while preserving the existing close-error propagation.
  • MCP logs cache writer

    • Updated buildLogsFileResponse to write through a small scoped helper that defers f.Close() immediately after os.OpenFile.
    • Kept the existing distinction between open failures and write/close failures so cache-file cleanup and returned errors stay aligned with current behavior.
  • Error handling shape

    • Switched the touched paths to named-return/deferred-close handling where needed so close errors are still surfaced without relying on manual non-deferred Close() calls.

Example pattern applied:

f, err := os.Open(path)
if err != nil {
	return err
}
defer func() {
	if closeErr := f.Close(); closeErr != nil && err == nil {
		err = closeErr
	}
}()

// ... use f ...

Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix resource management for deferred file close Defer file closes in pkg/cli workflow readers and logs cache writer May 24, 2026
Copilot AI requested a review from gh-aw-bot May 24, 2026 05:41
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.

[lint-monster] [LintMonster] Fix Resource Management: Deferred File Close (3 findings)

2 participants