From 529b25eadac1d838de935c984eddda6eb2da634c Mon Sep 17 00:00:00 2001 From: Sam Catlow Date: Tue, 28 Jul 2026 01:39:22 +1000 Subject: [PATCH] =?UTF-8?q?docs:=20phase=203a=20=E2=80=94=20nilerr=20revie?= =?UTF-8?q?w,=20all=2011=20sites=20were=20false=20positives=20(qa4)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 97 -> 85. Not one of the eleven nilerr findings was a bug. I called these "real bug candidates" when I planned the phases. I was wrong, and the reason is worth recording: every site is the same deliberate idiom, and a linter cannot see intent. - inprocess.go (5) and gateway.go (2) are handlers that report a problem as TEXT to their consumer. A tool handler returning a Go error aborts the tool call; returning "rejected: ..." lets the model read the feedback and retry with valid arguments. A chat handler returning a Go error surfaces as a gateway fault instead of a usage hint to the human. - worker.go carries runErr in the response envelope's Error field. Returning it as a Go error too would double-report and abort the NATS reply. - email.go returns nil when Accept fails because context cancellation closed the listener. That is a clean shutdown. - codesearch.go skips an unreadable entry and continues the walk. A best-effort index must not abort on one bad file. - skill.go is documented in the function comment already: a non-directory skills path means "no skills", not a fatal error. Annotated each with //nolint:nilerr and the specific reason rather than excluding the linter by path, so nilerr stays live everywhere else and the next reader wondering "why nil here?" gets an answer at the site. This is the phase I insisted on keeping single-session and out of the subagent fan-out. A worker told to "fix nilerr" would have converted all eleven to error returns: malformed tool arguments would hard-fail the agent loop instead of being correctable, chat typos would read as gateway faults, and shutdown would log spurious errors. Every test would still have passed. --- internal/agentexec/inprocess.go | 10 +++++----- internal/agentexec/worker.go | 2 +- internal/channels/email/email.go | 2 +- internal/gateway/gateway.go | 4 ++-- internal/indexing/codesearch.go | 2 +- internal/nats/client_test.go | 7 +++++++ internal/skill/skill.go | 2 +- internal/worktree/worktree.go | 1 + 8 files changed, 19 insertions(+), 11 deletions(-) diff --git a/internal/agentexec/inprocess.go b/internal/agentexec/inprocess.go index b38d642a6..b6e7dc137 100644 --- a/internal/agentexec/inprocess.go +++ b/internal/agentexec/inprocess.go @@ -171,7 +171,7 @@ func captureToolSet(specs []CaptureTool, captures map[string][]json.RawMessage) } var object map[string]json.RawMessage if err := json.Unmarshal(value, &object); err != nil { - return spec.Name + " rejected: arguments must be a JSON object", nil + return spec.Name + " rejected: arguments must be a JSON object", nil //nolint:nilerr // the agent loop must see malformed tool arguments as feedback it can correct, not as a failed tool call } for _, field := range spec.RequiredFields { if _, ok := object[field]; !ok { @@ -181,13 +181,13 @@ func captureToolSet(specs []CaptureTool, captures map[string][]json.RawMessage) for _, field := range spec.NonEmptyStrings { var text string if raw, ok := object[field]; !ok || json.Unmarshal(raw, &text) != nil || strings.TrimSpace(text) == "" { - return fmt.Sprintf("%s rejected: %s must be a non-empty string", spec.Name, field), nil + return fmt.Sprintf("%s rejected: %s must be a non-empty string", spec.Name, field), nil //nolint:nilerr // same: a rejection message lets the model retry with a valid argument } } for _, field := range spec.BooleanFields { var value bool if raw, ok := object[field]; !ok || json.Unmarshal(raw, &value) != nil { - return fmt.Sprintf("%s rejected: %s must be a boolean", spec.Name, field), nil + return fmt.Sprintf("%s rejected: %s must be a boolean", spec.Name, field), nil //nolint:nilerr // same: a rejection message lets the model retry with a valid argument } } captures[spec.Name] = append(captures[spec.Name], append(json.RawMessage(nil), value...)) @@ -215,11 +215,11 @@ func scriptToolSet(workspace string) core.ToolSet { Path string `json:"path"` } if err := json.Unmarshal([]byte(input), &args); err != nil || strings.TrimSpace(args.Path) == "" { - return "run_go_script rejected: arguments must be a JSON object with a non-empty path field", nil + return "run_go_script rejected: arguments must be a JSON object with a non-empty path field", nil //nolint:nilerr // same: a rejection message lets the model retry with a valid path } full := filepath.Join(workspace, args.Path) if rel, err := filepath.Rel(workspace, full); err != nil || strings.HasPrefix(rel, "..") { - return "run_go_script rejected: path escapes the workspace", nil + return "run_go_script rejected: path escapes the workspace", nil //nolint:nilerr // same: a rejection message lets the model retry with a valid path } out, err := skillscript.Run(full) if err != nil { diff --git a/internal/agentexec/worker.go b/internal/agentexec/worker.go index 844aa829a..d4a7e6194 100644 --- a/internal/agentexec/worker.go +++ b/internal/agentexec/worker.go @@ -108,7 +108,7 @@ func runStages(ctx context.Context, runner Runner, msg AgentRequestMessage, chan Error: runErr.Error(), Channel: channel, } - return resp, nil + return resp, nil //nolint:nilerr // runErr is reported to the caller in the response envelope's Error field; returning it here as well would double-report and abort the NATS reply } totalTokens += result.TokensUsed totalIter += result.Iterations diff --git a/internal/channels/email/email.go b/internal/channels/email/email.go index 0ff284279..81c83e24c 100644 --- a/internal/channels/email/email.go +++ b/internal/channels/email/email.go @@ -82,7 +82,7 @@ func (g *Gateway) Start(ctx context.Context, router *gateway.Router) error { conn, err := ln.Accept() if err != nil { if ctx.Err() != nil { - return nil + return nil //nolint:nilerr // Accept failed because the listener was closed by context cancellation, which is a clean shutdown, not a failure } g.log.Error("email accept", "err", err) continue diff --git a/internal/gateway/gateway.go b/internal/gateway/gateway.go index b23429cfd..08015ea9a 100644 --- a/internal/gateway/gateway.go +++ b/internal/gateway/gateway.go @@ -340,7 +340,7 @@ func (r *Router) handleApprove(ctx context.Context, rest string) (string, error) identity, arg := parseTaskControl(rest, r.Identity) id, err := parseTaskID(arg) if err != nil { - return "Usage: /approve [identity=name] ", nil + return "Usage: /approve [identity=name] ", nil //nolint:nilerr // chat commands report problems as text to the human, never as Go errors, which would surface as a gateway fault } if err := r.Controller.Approve(ctx, id, identity); err != nil { return fmt.Sprintf("Cannot approve task %d: %v", id, err), nil @@ -355,7 +355,7 @@ func (r *Router) handleCancel(ctx context.Context, rest string) (string, error) identity, arg := parseTaskControl(rest, r.Identity) id, err := parseTaskID(arg) if err != nil { - return "Usage: /cancel [identity=name] ", nil + return "Usage: /cancel [identity=name] ", nil //nolint:nilerr // chat commands report problems as text to the human, never as Go errors, which would surface as a gateway fault } if err := r.Controller.Cancel(ctx, id, identity); err != nil { return fmt.Sprintf("Cannot cancel task %d: %v", id, err), nil diff --git a/internal/indexing/codesearch.go b/internal/indexing/codesearch.go index daf246352..24be299a9 100644 --- a/internal/indexing/codesearch.go +++ b/internal/indexing/codesearch.go @@ -523,7 +523,7 @@ func WorkspaceFiles(ctx context.Context, root string) ([]string, error) { var files []string err = filepath.WalkDir(root, func(path string, entry os.DirEntry, walkErr error) error { if walkErr != nil { - return nil + return nil //nolint:nilerr // an unreadable entry skips that path and continues the walk; a best-effort index must not abort on one bad file } if path != root && strings.HasPrefix(entry.Name(), ".") { if entry.IsDir() { diff --git a/internal/nats/client_test.go b/internal/nats/client_test.go index 4e87db305..8b23e84be 100644 --- a/internal/nats/client_test.go +++ b/internal/nats/client_test.go @@ -189,24 +189,31 @@ type mockConsumer struct { func (m *mockConsumer) Fetch(int, ...jetstream.FetchOpt) (jetstream.MessageBatch, error) { return m.batch, nil } + func (m *mockConsumer) FetchBytes(int, ...jetstream.FetchOpt) (jetstream.MessageBatch, error) { panic("FetchBytes not implemented") } + func (m *mockConsumer) FetchNoWait(int) (jetstream.MessageBatch, error) { panic("FetchNoWait not implemented") } + func (m *mockConsumer) Consume(jetstream.MessageHandler, ...jetstream.PullConsumeOpt) (jetstream.ConsumeContext, error) { panic("Consume not implemented") } + func (m *mockConsumer) Messages(...jetstream.PullMessagesOpt) (jetstream.MessagesContext, error) { panic("Messages not implemented") } + func (m *mockConsumer) Next(...jetstream.FetchOpt) (jetstream.Msg, error) { panic("Next not implemented") } + func (m *mockConsumer) Info(context.Context) (*jetstream.ConsumerInfo, error) { panic("Info not implemented") } + func (m *mockConsumer) CachedInfo() *jetstream.ConsumerInfo { panic("CachedInfo not implemented") } diff --git a/internal/skill/skill.go b/internal/skill/skill.go index 2fad425db..87b25cfe3 100644 --- a/internal/skill/skill.go +++ b/internal/skill/skill.go @@ -52,7 +52,7 @@ func Catalog(dir string) ([]CatalogEntry, error) { if err != nil { // A file at .agents/skills (ENOTDIR) is not fatal -- treat as no skills. // Same for permission errors and other non-fatal ReadDir failures. - return nil, nil + return nil, nil //nolint:nilerr // documented above: a non-directory or unreadable skills path means no skills, not a fatal error } var names []string diff --git a/internal/worktree/worktree.go b/internal/worktree/worktree.go index 94d9c944d..245bfae79 100644 --- a/internal/worktree/worktree.go +++ b/internal/worktree/worktree.go @@ -275,6 +275,7 @@ func archieBranch(issue int, title, body, labels string) string { // branchPrefix derives a conventional-commit prefix from the issue // labels, then falls back to "feat". Maps: bug→fix, feature→feat, // enhancement→feat, docs→docs, chore→chore, test→test. +// FIXME - Unused parameters title and body where they should be used. - just a missing implementation by the looks of it. func branchPrefix(title, body, labels string) string { for l := range strings.SplitSeq(labels, ",") { switch strings.TrimSpace(strings.ToLower(l)) {