Skip to content

refactor(remotefs): split multiStat instead of suppressing cyclop - #459

Merged
kke merged 1 commit into
mainfrom
fix/454-posixfs-multistat-complexity
Sep 7, 2026
Merged

kke merged 1 commit into
mainfrom
fix/454-posixfs-multistat-complexity

Conversation

@kke

@kke kke commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Fixes #454

multiStat carried //nolint:cyclop // TODO refactor: one function held the batching loop, the scan loop and the error classification, and the three were only related by sharing a result slice.

Two of them move out. statBatch quotes names into one command line and returns where to continue, which is also the natural place to say why empty names are skipped -- stat reads a missing operand as a failure of the whole batch. statScanError explains the single-name versus batch split: a lone name is answered like the os package would, where a command that ran and exited non-zero means the path is gone, while a batch cannot pin the failure on one of its names. appendStatLines takes the scan.

No behavior change intended, and the suppression is gone rather than moved.

The batching loop turned out to be untested, which a refactor of it should not be able to say: only a directory with more than a kilobyte of names reaches a second batch. TestPosixMultiStatBatching covers it with 200 entries, asserts more than one stat invocation so the test cannot pass vacuously, and answers only for the names each invocation actually asked about. It catches the class of mistake this refactor can make -- dropping whole batches rather than failing -- which is what a shadowed result slice did on the first attempt here.

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.

🟡 Changes recommended

There are confirmed issues in the new batching/error-path logic (batch size cap not enforced as documented, and batch error reporting uses the full input list instead of the failing batch).

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR refactors PosixFS.multiStat in remotefs by splitting batching, scanning, and error classification into smaller helpers and removing the prior cyclomatic-complexity suppression, while adding a regression test to cover multi-batch behavior.

Changes:

  • Introduces statBatch, statScanError, and appendStatLines to separate batching, scan parsing, and error mapping from multiStat.
  • Reworks multiStat to use the new helpers and avoid running stat with empty operands.
  • Adds TestPosixMultiStatBatching to ensure results from multiple stat invocations are preserved.
File summaries
File Description
remotefs/posixfs.go Refactors multiStat into helpers for batching, scanning, and error handling; removes cyclop suppression.
remotefs/posixfs_test.go Adds a batching regression test to ensure multi-batch results aren’t dropped.
Review details

Suppressed comments (1)

remotefs/posixfs.go:427

  • statScanError is meant to describe the failing stat invocation, but multiStat currently passes the full names slice, which can include paths not included in the batch that actually ran (and can make the error message extremely large). Capture the batch slice and pass that to statScanError so the error accurately reflects the command that failed.
		var batch string
		batch, idx = statBatch(names, idx)
		if batch == "" {
			// Every name in this batch was empty. Running stat with no operands
			// would only fail, and Stat turns the missing result into ErrNotExist
  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread remotefs/posixfs.go Resolved
@kke
kke requested a lite review from Copilot September 2, 2026 12:06

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.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

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.

🟢 Approval recommended

The refactor is behavior-preserving with added test coverage for the previously untested batching path, and only minor doc-comment clarifications remain.

Review details

Suppressed comments (1)

remotefs/posixfs.go:363

  • The statBatch doc says it stops "once the batch is full", but the implementation appends a name whenever batch.Len() < statBatchBytes at loop entry, so a batch can end up slightly over the limit after adding the last quoted name. Clarify the comment so it matches the actual batching behavior.
// statBatch quotes names into one command line, starting at idx and stopping
// once the batch is full or the names run out. It returns the batch and the
// index to continue from, which always advances, so a caller looping until the
// names are exhausted terminates.
//
  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Lite

Comment thread remotefs/posixfs.go Resolved
multiStat carried //nolint:cyclop // TODO refactor: one function held the
batching loop, the scan loop and the error classification, and the three
were only related by sharing a result slice.

Two of them move out. statBatch quotes names into one command line and
returns where to continue, which is also the natural place to say why empty
names are skipped -- stat reads a missing operand as a failure of the whole
batch. statScanError explains the single-name versus batch split: a lone
name is answered like the os package would, where a command that ran and
exited non-zero means the path is gone, while a batch cannot pin the failure
on one of its names. appendStatLines takes the scan.

No behavior change intended, and the suppression is gone rather than moved.

The batching loop turned out to be untested, which a refactor of it should
not be able to say: only a directory with more than a kilobyte of names
reaches a second batch. TestPosixMultiStatBatching covers it with 200
entries, asserts more than one stat invocation so the test cannot pass
vacuously, and answers only for the names each invocation actually asked
about. It catches the class of mistake this refactor can make -- dropping
whole batches rather than failing -- which is what a shadowed result slice
did on the first attempt here.

Fixes #454

Signed-off-by: Kimmo Lehto <klehto@mirantis.com>
@kke
kke force-pushed the fix/454-posixfs-multistat-complexity branch from b0c27d2 to 6b5592f Compare September 7, 2026 07:34
@kke
kke requested a lite review from Copilot September 7, 2026 07:38

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.

🟡 Changes recommended

The added test currently does not compile, and there is also an incorrect fmt.Errorf format string that produces malformed error messages.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 2
  • Review effort level: Lite

Comment thread remotefs/posixfs_test.go Resolved
Comment thread remotefs/posixfs.go Resolved
@kke
kke merged commit d4d9487 into main Sep 7, 2026
16 of 17 checks passed
@kke
kke deleted the fix/454-posixfs-multistat-complexity branch September 7, 2026 07:47
kke added a commit that referenced this pull request Sep 8, 2026
* docs: add AGENTS.md for coding agents

AGENTS.md existed only in local working copies, so no agent working
through GitHub ever saw it, and the copy that did exist had drifted: it
documented protocol.ErrAbort (never existed under that name), omitted
cmd.Runner.Explain, CommandGate, Client.Capabilities, Clone and Reboot,
and still claimed v2 was unreleased and free to break.

Most of that rot came from the file's shape. Roughly 380 of its 533
lines were a hand-maintained mirror of the exported API, which go doc
already reports accurately and which cannot be kept current by hand. The
API reference is gone, replaced by a pointer to go doc and to docs/.

What remains is the part agents cannot derive from the source: the
branch and API-stability policy, package layout, the make targets, the
code style .golangci.yml actually enforces, the shell quoting and error
sentinel conventions, and the DCO sign-off requirement. Claims that
would rot on their own — released versions, per-package implementation
lists, specific lint thresholds — are deliberately left out and
delegated to go doc, ls and .golangci.yml.

It also asks for prose written for the human who reads it: explain the
why, don't re-narrate the diff or paste a validation transcript, and
don't pad for the appearance of thoroughness. Agents are asked to
identify themselves rather than blend in, and to follow their pull
requests through review and CI instead of firing and forgetting — or to
hand that duty to their operator explicitly when they cannot return.

Signed-off-by: Kimmo Lehto <klehto@mirantis.com>

* docs: add Copilot review instructions

Copilot reviews every pull request here, and its output has a consistent
shape worth steering. It is at its most useful when it catches a doc
comment or a docs/ table that contradicts the implementation, a %s applied
to an error or a []string, or a code path that honours only the first
element of a list — and it is the only automated reviewer that reads test
files at all, since .golangci.yml sets run.tests: false.

It also spends comments on things this repository has deliberately turned
off in .golangci.yml (line length, magic numbers, interface returns),
on grammar preferences, and occasionally on plain mistakes: on #459 it
reported that "for i := range entries" could not compile, which has been
valid since Go 1.22 and this module is on 1.27.

There is also a section on inline comments, since a reviewer that asks for
explanatory comments on readable code works against the codebase: narration
that restates the next line is noise, and a comment asserting what another
function does rots when that function changes. A comment contradicting the
code stays a bug worth reporting.

The file states the review context, what to prioritise, what to leave
alone, and asks for one concrete failure scenario per comment. Conventions
themselves stay in AGENTS.md so there is a single copy to keep current.

Signed-off-by: Kimmo Lehto <klehto@mirantis.com>

* chore(docs): Update agent instructions

Signed-off-by: Kimmo Lehto <klehto@mirantis.com>

---------

Signed-off-by: Kimmo Lehto <klehto@mirantis.com>
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.

remotefs/posixfs.go has a lint-suppressed function flagged as needing a refactor

2 participants