Skip to content

Add daily dead code removal workflow#19111

Merged
dsyme merged 3 commits intomainfrom
copilot/create-dead-code-assessment-workflow
Mar 1, 2026
Merged

Add daily dead code removal workflow#19111
dsyme merged 3 commits intomainfrom
copilot/create-dead-code-assessment-workflow

Conversation

Copy link
Contributor

Copilot AI commented Mar 1, 2026

Automates incremental removal of unreachable Go functions via a daily agentic workflow that runs deadcode static analysis, selects a batch of up to 10 dead functions, applies safety checks, and opens a PR with verified removals.

Workflow design

  • Schedule: daily (fuzzy-scattered) + workflow_dispatch; skip-if-match prevents stacking when a prior PR is still open
  • Pre-step: installs golang.org/x/tools/cmd/deadcode before the agent runs
  • Batch size: ≤10 functions per run to keep PRs reviewable
  • Cache-memory: tracks processed functions across runs for incremental progress

Safety checks encoded in the agent prompt

  • Test-only callers don't make a function live — deadcode-flagged functions are deleted even if only *_test.go files call them; exclusive test functions are removed alongside
  • WASM binary exemption: checks cmd/gh-aw-wasm/main.go before deleting from pkg/workflow/ or pkg/console/
  • console_wasm.go stub check for any pkg/console/ deletion
  • Three exempted functions in compiler_test_helpers.go (containsInNonCommentLines, indexInNonCommentLines, extractJobSection) — shared test infrastructure, never deleted
  • Constant/embed rescue before removing files that become empty

Verification before PR creation

go build ./...go vet ./...go vet -tags=integration ./...make fmt → targeted go test ./pkg/.... Reverts and calls noop on any failure.

Copilot AI and others added 2 commits March 1, 2026 20:08
Co-authored-by: dsyme <7204669+dsyme@users.noreply.github.com>
@dsyme dsyme marked this pull request as ready for review March 1, 2026 20:35
Copilot AI review requested due to automatic review settings March 1, 2026 20:35
@dsyme dsyme merged commit 67e762b into main Mar 1, 2026
44 of 45 checks passed
@dsyme dsyme deleted the copilot/create-dead-code-assessment-workflow branch March 1, 2026 20:35
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a new scheduled agentic workflow to incrementally remove unreachable Go functions using golang.org/x/tools/cmd/deadcode, applying safety checks and opening small PRs with verification.

Changes:

  • Introduces a new gh-aw workflow prompt for a “Dead Code Removal Agent” with batching, safety checks, verification, and cache-memory tracking.
  • Adds the compiled .lock.yml workflow generated from the markdown source.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
.github/workflows/dead-code-remover.md Defines the workflow frontmatter and the agent instructions for finding/removing dead Go functions and opening PRs.
.github/workflows/dead-code-remover.lock.yml Generated GitHub Actions workflow implementing the scheduled agent run, safe-outputs handling, and cache-memory persistence.

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

Comment on lines +63 to +71
## Phase 2: Check Cache for Previously Processed Functions

Read `/tmp/gh-aw/cache-memory/dead-code-processed.jsonl` to find functions already processed in previous runs. Each line has the form:

```json
{"function": "FuncName", "file": "pkg/workflow/foo.go", "processed_at": "2026-03-01", "action": "deleted"}
```

Build a set of `"file:FuncName"` keys to skip — this ensures each function is only processed once.
Copy link

Copilot AI Mar 1, 2026

Choose a reason for hiding this comment

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

Phase 2 instructs reading /tmp/gh-aw/cache-memory/dead-code-processed.jsonl but doesn’t say what to do when the file is absent (which will be the case on the first run, or after cache misses). Please explicitly handle the “file not found” case (treat as empty / create an empty file) so the agent doesn’t fail early when bootstrapping the cache-memory state.

Copilot uses AI. Check for mistakes.
Comment on lines +90 to +97
### 4.1 Caller grep

```bash
grep -rn "FunctionName" --include="*.go" .
```

- Callers **only in `*_test.go` files** → function is dead. Proceed with deletion AND mark its exclusive test functions for removal.
- Callers in **any non-test file** → **skip** (possible false positive from `deadcode`).
Copy link

Copilot AI Mar 1, 2026

Choose a reason for hiding this comment

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

The caller check grep -rn "FunctionName" --include="*.go" . will always match the function’s own definition (and can match comments/strings), which makes the “callers only in *_test.go” decision ambiguous and error-prone. Consider tightening this check to search specifically for call sites and/or explicitly ignore the defining func FunctionName line and comment-only matches so the workflow doesn’t mistakenly skip or delete functions based on self-matches.

Copilot uses AI. Check for mistakes.
Run targeted package tests for every package you modified:

```bash
go test ./pkg/... 2>&1
Copy link

Copilot AI Mar 1, 2026

Choose a reason for hiding this comment

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

Phase 6 says to run targeted tests “for every package you modified”, but the command given is go test ./pkg/..., which won’t execute tests for changes in cmd/..., internal/..., or other module directories that may be edited as part of deadcode removals. To match the stated intent, either run go test ./... (simplest) or derive the exact set of modified packages and test those.

Suggested change
go test ./pkg/... 2>&1
go test ./... 2>&1

Copilot uses AI. Check for mistakes.
Comment on lines +227 to +233
## Important

You **MUST** always end by calling exactly one of these safe output tools before finishing:

- **`create_pull_request`**: When changes were made and the build passes
- **`noop`**: When no changes were made (nothing to remove, all skipped, or build failure)

Copy link

Copilot AI Mar 1, 2026

Choose a reason for hiding this comment

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

The “Important” section requires ending with exactly one of create_pull_request or noop, but the compiled workflow also provides missing_tool/missing_data safe outputs (and upstream gh-aw automation expects those to be usable when needed). This restriction could prevent the agent from reporting missing capabilities/data in a structured way. Recommend either allowing those safe outputs in the rule, or removing them from the prompt/tooling so the guidance and available tools stay consistent.

Copilot uses AI. Check for mistakes.
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