Skip to content

fix(config): update() writes to existing config file instead of hardcoding config.json#16979

Closed
dibstern wants to merge 1 commit intoanomalyco:devfrom
dibstern:fix/config-update-respects-existing-filename
Closed

fix(config): update() writes to existing config file instead of hardcoding config.json#16979
dibstern wants to merge 1 commit intoanomalyco:devfrom
dibstern:fix/config-update-respects-existing-filename

Conversation

@dibstern
Copy link
Copy Markdown

Summary

  • Config.update() hardcoded config.json as the write target, ignoring the project's actual config file. Projects using opencode.jsonc got a spurious config.json created alongside their real config, and changes (e.g. persisted permission rules via PATCH /config) were effectively lost since config.json is not loaded as project config.
  • Adds localConfigFile() to resolve the existing project config file (opencode.jsonc > opencode.json), mirroring the existing globalConfigFile() pattern. Handles .jsonc files with patchJsonc() to preserve comments, matching updateGlobal().

Reproduction

  1. Create a project with opencode.jsonc as the config file
  2. Use PATCH /config (e.g. via "Always Allow" on a permission prompt)
  3. Observe: a new config.json is created instead of opencode.jsonc being updated
  4. The permission rule is silently lost on next startup since config.json is not a valid project config filename

Changes

  • packages/opencode/src/config/config.ts: Added localConfigFile() resolver; rewrote update() to use it with .jsonc support
  • packages/opencode/test/config/config.test.ts: Updated existing test; added new test verifying opencode.jsonc is updated and config.json is not created

Verification

  • All 66 config tests pass (bun test test/config/config.test.ts)
  • Typecheck passes across all 13 packages (pre-push hook)

…oding config.json

Config.update() always wrote to config.json regardless of which config file
the project actually used. Projects using opencode.jsonc got a spurious
config.json created alongside their real config file, and the changes were
effectively lost since config.json is not a valid project config filename.

Add localConfigFile() to resolve the existing project config file
(opencode.jsonc > opencode.json), mirroring globalConfigFile(). Handle
.jsonc files with patchJsonc() to preserve comments, matching the
updateGlobal() pattern.
@github-actions
Copy link
Copy Markdown
Contributor

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • PR description is missing required template sections. Please use the PR template.

Please edit this PR description to address the above within 2 hours, or it will be automatically closed.

If you believe this was flagged incorrectly, please let a maintainer know.

@github-actions github-actions bot added needs:compliance This means the issue will auto-close after 2 hours. needs:issue labels Mar 11, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions
Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

I found a potentially related PR:

PR #12347: fix: PATCH /config writes to correct project config file

This PR appears to address the same issue - fixing PATCH /config to write to the correct project config file instead of hardcoding config.json. It may already contain a solution to this problem or be related to the same underlying bug. You should check if this PR was already merged or if PR #16979 supersedes it with additional improvements.

@github-actions
Copy link
Copy Markdown
Contributor

This pull request has been automatically closed because it was not updated to meet our contributing guidelines within the 2-hour window.

Feel free to open a new pull request that follows our guidelines.

@github-actions github-actions bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Mar 11, 2026
@github-actions github-actions bot closed this Mar 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant