Skip to content

fix(repos): allow explicitly empty file content - #3884

Open
Elon-Jiang wants to merge 1 commit into
github:mainfrom
Elon-Jiang:fix/empty-file-content
Open

Elon-Jiang wants to merge 1 commit into
github:mainfrom
Elon-Jiang:fix/empty-file-content

Conversation

@Elon-Jiang

Copy link
Copy Markdown

Summary

Allow create_or_update_file to create empty files and intentionally clear existing files when content: "" is explicitly supplied.

Why

Fixes #3883. Agents cannot currently create empty package markers (__init__.py, .gitkeep) or clear a file: an empty string is treated as a missing parameter before any request reaches GitHub. The Contents API accepts base64 file content, and the tool schema does not impose a minimum length.

What changed

  • When the decoded content is empty, distinguish an explicitly supplied string from absent/null content. Keep the existing exported Go input type and public JSON schema.
  • Exercise empty-file creation, clearing an existing ordinary file, and absent/null content through the public tool handler and real go-github request serialization. Existing nonempty create/update, stale SHA and symlink protection cases remain in the same test table.
  • Document intentionally empty writes in the bundled repository-content-changes skill.

MCP impact

  • Tool schema or behavior changed: explicit empty strings now reach the Contents API. Missing/null values still fail; SHA and symlink validation are unchanged. No schema or tool renaming.

Prompts tested (tool changes only)

The tests invoke tool arguments directly; no LLM prompt execution is claimed. The corresponding use cases are “create an empty package marker on this branch” and “clear this ordinary file using its current blob SHA.” The HTTP transport substitutes GitHub's service; the public tool handler, validation and REST serialization run normally. No live account file write was used in testing.

Security / limits

  • Auth / permissions considered: existing permissions, SHA and symlink guards remain in place. Missing content cannot silently erase a file.

Tool renaming

  • I am not renaming tools as part of this PR.

Lint & tests

  • ./script/lint (Go 1.27.3, pinned golangci-lint 2.14.0): passed.
  • ./script/test (go test -race ./...): passed.
  • UPDATE_TOOLSNAPS=true go test ./...: passed; no snapshot changes.

Baseline: the two empty-write cases fail; 15 existing controls pass. After the fix, all 19 cases pass, including the two new absent/null controls.

Docs

  • Updated the bundled skill. ./script/generate-docs passed without README changes.

Skills

  • Updated the repository-content-changes skill; catalog coverage is exercised by the full suite.

Prepared with AI assistance. No claim of independent human review is made.

@Elon-Jiang
Elon-Jiang requested a review from a team as a code owner November 18, 2026 09:43
Copilot AI adaptive review requested due to automatic review settings November 18, 2026 09:43

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.

🟢 Approval recommended

No active review issues block the change enabling intentionally empty file writes.

No open issues 🎉

What changed in this PR

Fixes #3883 by allowing create_or_update_file to create empty files or intentionally clear existing files without changing its public input type or schema.

Changes:

  • Accepts explicit content: "" while continuing to reject missing or null content.
  • Adds regression cases for empty creation, clearing existing files, and missing/null content.
  • Documents empty writes and the current-SHA requirement for clearing existing files.
File Description
pkg/​skills/​catalog/​skills/​repository-content-changes/​SKILL.md Documents intentionally empty writes.
pkg/​github/​repositories.go Distinguishes explicit empty content from missing or null values.
pkg/​github/​repositories_test.go Adds empty-write and missing/null regression cases.

Review effort: Balanced (adaptive)

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.

create_or_update_file rejects explicitly empty file content

2 participants