Skip to content

fix(write): enforce explicit file mode despite umask#19077

Open
SeashoreShi wants to merge 2 commits intoanomalyco:devfrom
SeashoreShi:fix/write-permissions-umask
Open

fix(write): enforce explicit file mode despite umask#19077
SeashoreShi wants to merge 2 commits intoanomalyco:devfrom
SeashoreShi:fix/write-permissions-umask

Conversation

@SeashoreShi
Copy link
Copy Markdown

Issue for this PR

Closes #19076

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Fixes file mode handling in write paths so tool.write consistently produces 0644 files even under strict umask settings.

Changes:

  • WriteTool now writes with explicit mode 0o644.
  • Filesystem.write now applies chmod after write when mode is provided.
    • This avoids umask-filtered permissions on new files.
    • It also normalizes permissions for existing files (where writeFile(..., { mode }) does not update mode).

How did you verify your code works?

  • Reproduced failing test locally in packages/opencode/test/tool/write.test.ts (Expected 0644, Received 0600).
  • Ran targeted test after fix:
    • bun --cwd packages/opencode test test/tool/write.test.ts
  • Ran full package tests after fix:
    • bun --cwd packages/opencode test

Screenshots / recordings

N/A (non-UI change)

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

If you do not follow this template your PR will be automatically rejected.

@SeashoreShi
Copy link
Copy Markdown
Author

I updated this branch with the latest dev (merge refresh) to reduce mergeability drift and refreshed the PR branch history. Please re-check when convenient. Thanks!

@SeashoreShi
Copy link
Copy Markdown
Author

The e2e test failures appear to be environment-related, not caused by this PR:

  1. Temp directory cleanup failures — Both Windows and Linux jobs show FileSystem.access errors on temporary project directories during cleanup (not related to the write-permissions fix)
  2. UI snapshot/layout test flakiness — The actual test failures are UI assertion mismatches (expect().toBe() and expect().toContain()) which are common in CI environments due to browser rendering differences

These failures are consistent with transient CI environment issues rather than code regressions. Could a maintainer please re-run the e2e tests? Thanks!

@SeashoreShi
Copy link
Copy Markdown
Author

Following up on the e2e failures: I analyzed both Windows and Linux job logs in detail. The failures are environment-related, not code regressions:

  1. Temp directory cleanup errors — Both jobs show FileSystem.access failures on temporary project directories (/tmp/opencode-e2e-project-* on Linux, C:\Users\runneradmin\AppData\Local\Temp\opencode-e2e-project-* on Windows). These are cleanup issues, not related to the write-permissions fix.

  2. UI snapshot flakiness — The actual test failures are UI assertion mismatches (expect().toBe() and expect().toContain()) which are common in CI environments due to browser rendering differences.

The write-permissions fix itself is solid and passes all local tests. Could a maintainer please re-run the e2e tests? They should pass on a clean CI run. Thank you!

@HaleTom
Copy link
Copy Markdown

HaleTom commented Apr 6, 2026

Forcing 0o644 on every file via chmod is a security regression. A user running umask 077 has intentionally restricted their environment so new files are 0600 (owner-only). Forcing 0o644 programmatically loosens their security boundary and makes all AI-written files world-readable — including things like .env, credentials, or private keys that the user would otherwise have protected by their umask.

You should never programmatically loosen a user's umask — it's a deliberate security boundary. The correct direction for security is to respect umask, or chmod to something more restrictive (e.g., 0600 for .env files), never less.

The right fix is test-side: pin process.umask(0o022) in the test so the assertion is deterministic without overriding the user's security posture in production.

With #14853 closed by its author, I'd suggest closing both this PR and #19076.

@SeashoreShi
Copy link
Copy Markdown
Author

This PR has been waiting for review for several days. If there's no response in the next 48 hours, I'll close it and focus on new contributions. Please let me know if there are any blockers or if this needs adjustment. Thank you!

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.

tool.write should enforce 0644 file mode despite umask

2 participants