Skip to content

Java codegen: clean output directory before generating to prevent orphan accumulation#1623

Merged
stephentoub merged 1 commit into
mainfrom
edburns/ghcp-sdk-1619-java-codegen-stale-files
Jun 10, 2026
Merged

Java codegen: clean output directory before generating to prevent orphan accumulation#1623
stephentoub merged 1 commit into
mainfrom
edburns/ghcp-sdk-1619-java-codegen-stale-files

Conversation

@edburns

@edburns edburns commented Jun 10, 2026

Copy link
Copy Markdown
Collaborator

Summary

Add a clean step to java/scripts/codegen/java.ts that removes the entire generated output directory before writing new files. This ensures that when upstream schema types are renamed or removed, the previously-generated .java files are automatically deleted rather than silently accumulating as orphans.

Changes

  • java/scripts/codegen/java.ts — At the start of main(), recursively delete src/generated/java/com/github/copilot/generated/ and recreate the empty directory before invoking any generators.

  • java/src/generated/java/ — 204 orphan files removed (types no longer emitted by the current schema). These accumulated over multiple @github/copilot releases as types were renamed or removed upstream.

  • GeneratedRpcRecordsCoverageTest.java — Removed test methods that exercised deleted generated types (SessionWorkspaceCreateFileParams, SessionModeGetResult, SessionModeSetResult, DiscoveredMcpServerSource, and 16 others).

  • GeneratedRpcApiCoverageTest.java — Removed test method for the deleted SessionAgentDeselectResult type.

Why this works going forward

The CI workflow (java-codegen-check.yml) runs codegen and then checks git status --porcelain. Because codegen now cleans before writing, any future orphans will appear as deletions in the diff and the check will fail — preventing orphan accumulation without any additional workflow changes.

Fixes #1619

…rphan accumulation

## Summary

Add a clean step to `java/scripts/codegen/java.ts` that removes the entire
generated output directory before writing new files. This ensures that when
upstream schema types are renamed or removed, the previously-generated `.java`
files are automatically deleted rather than silently accumulating as orphans.

## Changes

- **`java/scripts/codegen/java.ts`** — At the start of `main()`, recursively
  delete `src/generated/java/com/github/copilot/generated/` and recreate the
  empty directory before invoking any generators.

- **`java/src/generated/java/`** — 204 orphan files removed (types no longer
  emitted by the current schema). These accumulated over multiple
  `@github/copilot` releases as types were renamed or removed upstream.

- **`GeneratedRpcRecordsCoverageTest.java`** — Removed test methods that
  exercised deleted generated types (`SessionWorkspaceCreateFileParams`,
  `SessionModeGetResult`, `SessionModeSetResult`, `DiscoveredMcpServerSource`,
  and 16 others).

- **`GeneratedRpcApiCoverageTest.java`** — Removed test method for the deleted
  `SessionAgentDeselectResult` type.

## Why this works going forward

The CI workflow (`java-codegen-check.yml`) runs codegen and then checks
`git status --porcelain`. Because codegen now cleans before writing, any future
orphans will appear as deletions in the diff and the check will fail —
preventing orphan accumulation without any additional workflow changes.

Fixes #1619
@edburns edburns changed the title # Java codegen: clean output directory before generating to prevent orphan accumulation Java codegen: clean output directory before generating to prevent orphan accumulation Jun 10, 2026
@edburns edburns marked this pull request as ready for review June 10, 2026 16:08
@edburns edburns requested a review from a team as a code owner June 10, 2026 16:08
@edburns edburns requested review from Copilot and stephentoub June 10, 2026 16:08
@github-actions

Copy link
Copy Markdown
Contributor

Cross-SDK Consistency Review ✅

All 207 changed files are in java/ — this PR is Java-only. No cross-SDK consistency issues found.

Why the clean-before-generate pattern is Java-specific

The orphan accumulation problem exists only in the Java codegen because Java conventionally writes one file per class. The other SDK codegens all write to a fixed set of monolithic files (always overwritten, so they cannot accumulate orphans):

SDK Codegen output files
TypeScript/Node.js session-events.ts, rpc.ts (2 fixed files)
C#/.NET SessionEvents.cs, Rpc.cs (2 fixed files)
Python session_events.py, rpc.py (2 fixed files)
Go zsession_events.go, zsession_encoding.go, zrpc.go, zrpc_encoding.go (4 fixed files)
Rust session_events.rs, api_types.rs, rpc.rs, mod.rs (4 fixed files)
Java One .java file per class → orphan accumulation possible ← fixed by this PR

The fix (clean the output directory before generating) is correctly scoped to Java. No equivalent change is needed in any other SDK.

Generated by SDK Consistency Review Agent for issue #1623 · sonnet46 1.7M ·

@edburns

edburns commented Jun 10, 2026

Copy link
Copy Markdown
Collaborator Author

I'm very sorry about this mistake, this PR is ready for review @stephentoub .

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 improves the Java SDK’s code generation workflow by cleaning the Java generated-sources output directory before regenerating from the upstream JSON schemas, preventing stale/orphaned .java files from accumulating when schema types are renamed or removed (fixes #1619).

Changes:

  • Add a “clean generated output dir” step at the start of java/scripts/codegen/java.ts so regeneration reflects the current schema exactly (including deletions).
  • Remove previously orphaned generated Java types that are no longer emitted by the current @github/copilot schemas.
  • Update Java generated-type coverage tests to stop referencing deleted generated types.
Show a summary per file
File Description
java/scripts/codegen/java.ts Adds a pre-generation clean step for src/generated/java/com/github/copilot/generated to prevent orphan accumulation.
java/src/test/java/com/github/copilot/generated/rpc/GeneratedRpcApiCoverageTest.java Removes a coverage test that exercised a generated type that is no longer emitted.
java/src/generated/java/com/github/copilot/generated/** Regenerated output: removes stale orphaned generated types no longer present in the schema.
java/src/generated/java/com/github/copilot/generated/rpc/** Regenerated output: removes stale orphaned generated RPC types no longer present in the schema.

Copilot's findings

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

Comment on lines +2062 to +2066
// Clean the generated output directory to remove orphaned files from previous runs
const generatedOutputDir = path.join(REPO_ROOT, "src/generated/java/com/github/copilot/generated");
console.log(`🧹 Cleaning output directory: ${generatedOutputDir}`);
await fs.rm(generatedOutputDir, { recursive: true, force: true });
await fs.mkdir(generatedOutputDir, { recursive: true });
@stephentoub stephentoub added this pull request to the merge queue Jun 10, 2026
Merged via the queue into main with commit f2e8469 Jun 10, 2026
31 checks passed
@stephentoub stephentoub deleted the edburns/ghcp-sdk-1619-java-codegen-stale-files branch June 10, 2026 16:31
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.

Java codegen leaves stale orphaned generated files (codegen does not clean its output dir)

3 participants