Skip to content

🤖 fix: a config edit refuses an in-place rewrite of config.json that keeps its stat - #8086

Open
ThomasK33 wants to merge 7 commits into
mainfrom
fix/config-unchanged-content-check
Open

ThomasK33 wants to merge 7 commits into
mainfrom
fix/config-unchanged-content-check

Conversation

@ThomasK33

@ThomasK33 ThomasK33 commented Nov 10, 2026 •

Copy link
Copy Markdown
Member

Summary

A config edit now refuses to save, and an edit that changes nothing refuses to report success, when config.json no longer holds the bytes that the edit read. Before, assertConfigFileUnchanged compared only config.json's stat key (device, inode, size and mtime). Another writer that skips Xum's lock (a manual editor, an older Xum) can rewrite the file in place at the same size: that keeps the inode and the size, and within one tick of a coarse filesystem clock the mtime too. Then a save replaced that writer's bytes, and a settings clear that found no legacy value to clear (#8035) reported success while config.json carried a legacy enable of the server.

Background

Implementation

  1. Each edit records the stat key just before its fresh read and the bytes that read got (ConfigFileRead). readConfigBytes hands the bytes over through a readBytes option.
  2. assertConfigFileUnchanged checks the stat key as before. Then it reads config.json and compares the bytes with the edit's. When both reads found no file, it has nothing to compare. An edit whose read got no bytes while the file exists refuses: the lenient read treats ENOENT as a fresh install and hands the transform defaults, and a save on those defaults would replace the registry.
  3. Both callers use it: the save's check right before its rename, and an edit whose transform returns CONFIG_UNCHANGED.

Validation

  • Five new tests fail on main c4f4003 and pass here. Four rewrite config.json in place at the same size and restore the mtime with utimes, so they need no timing:
    • config.test.ts, write path: on main the edit saved and replaced the other writer's bytes.
    • config.test.ts, editConfigIfChanged that returns CONFIG_UNCHANGED: on main it resolved.
    • workspaceMcpOverridesService.test.ts, a settings clear (🤖 perf: an MCP settings save leaves config.json alone when it has no legacy value to clear #8035's skip path): on main it reported "saved", and a fresh reader saw consent-sensitive enabled.
    • workspaceMcpOverridesService.test.ts, a settings write: on main it reported "saved".
    • The fifth makes the edit's read fail with ENOENT once while config.json stays in place. On main the save went through on the defaults that the lenient read handed the transform.
  • Two more tests fail on main 6c3cc3d and pass here. One rewrites config.json in place, keeping its stat, right after the edit's read and before the parse and the transform: on main the edit saved over it. In the other, the check's own read of config.json fails with EIO: on main the check never reads the file.
  • Each piece of the check has a mutant that turns a test red (7 of 7): no byte compare, a failed read that passes, no "both missing" return, no byte capture, a write path that compares with fresh bytes, a check whose own failed read returns instead of refusing, and bytes taken after the parse instead of at the read.
  • Existing tests that count config.json reads (src/node/config/snapshot.test.ts) now count one more read per edit.
  • On fd3c51f, merged with main 6c3cc3d, with a 120 s test limit: config.test.ts 314 pass, src/node/config/snapshot.test.ts 25 pass, workspaceMcpOverridesService.test.ts 191 pass, 0 fail. typecheck, static-check, lint-eslint, fmt-check, crap-check and dry-check pass there.
  • On b2049e1, 502 test files under src/ reach config/index.ts. Run 8 at a time (one load sample: 144), 459 passed. One at a time with a 120 s test limit, 39 of the other 43 passed. Of the last 4: src/node/config/snapshot.test.ts counted the new read (now updated, 25 pass); historyService.statusSuffix.test.ts passed on its own run; src/cli/workflow.test.ts did not run, since it needs dist/cli/index.js (make build-main), and the same 2 tests fail that way on main. goalAdvancement.test.ts is flaky on main too: an independent verifier saw it fail 5 of 8 runs on b2049e1 and 4 of 8 on main. The 156 suites under tests/ run in CI.

Read cost of the check, measured on this host (Bun 1.4.3, 1-minute load 67-110 from other jobs): 2,000 reads of config.json plus the byte compare, and 200 editConfig saves, per size.

Workspaces config.json read + compare (median) whole save (median), main / this PR
40 16,518 bytes 29-31 µs 91 ms / 97 ms
400 156,000 bytes 44-45 µs 102 ms / 106 ms

The save times differ by less than the noise at this load.

Risks

  • Every save and every unchanged edit reads config.json once more (table above). A file of several MB costs more in proportion.
  • A rewrite between this check and the rename still lands unseen, as with the stat check.
  • A save now refuses where its read of config.json failed while the file stayed in place. That read handed the transform defaults, so the save would have replaced the file with them.

Generated with xum • Model: anthropic:claude-opus-5-5 • Thinking: xhigh • Cost: $356.33

…fail the edit

A rewrite of the same size keeps config.json's inode and size, and within one tick of a
coarse filesystem clock its mtime too. The tests restore the mtime with utimes, so the stat
key cannot tell the rewrite apart. A write's save then replaced the other writer's bytes,
and an edit that changed nothing (a settings clear's legacy clear) reported success while
the file carried a legacy enable.

---
_Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_
assertConfigFileUnchanged checked only config.json's stat key (device, inode, size, mtime)
before a save's rename and before an edit that writes nothing returned. It now also reads
the file and compares it with the bytes the edit read: one more read per save, and none
when both reads found no file.

---
_Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_
Keeps readConfigOrDefault's complexity where it was (CRAP floor), and the service test
asserts the outcome and the server state without asymmetric matchers.

---
_Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_
Each edit now reads config.json once more, right before its rename, to compare its bytes.

---
_Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_
…e file stays refuses to save

The lenient read hands the transform defaults for ENOENT, and the file's stat did not change,
so the stat check alone let the save replace the registry with them.

---
_Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_
@ThomasK33

Copy link
Copy Markdown
Member Author

@codex review

Head: b2049e1

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-10T15:50:34.382589Z fd3c51f Manual request
🔒 Security Review ✅ Completed 2026-11-10T15:52:43.223877Z fd3c51f Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 👍

Reviewed commit: b2049e144a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review · Automatically triggered

Security review completed. No security issues were found in this pull request.

Reviewed commit: b2049e144a

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@github-actions

github-actions Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

🟢 e2e stories (Haiku): 14 passed

22 agent steps · 7 replayed from cache · 15 model calls · 47.2k tokens (27% cached)
Spend: $0.09 of the $1.00 cap (proxy ledger)

All 14 tests in 9 files
Test Agent Time
🟢 chatRestart.e2e.ts · 1 passed 1 step · 1 call 6.2s
🟢 a chat survives a restart of the server 1 step · 1 call 6.2s
🟢 compaction.e2e.ts · 1 passed 1 step · 1 call 5.1s
🟢 /compact replaces the old chat with a summary 1 step · 1 call 5.1s
🟢 pluginTrustRestart.e2e.ts · 1 passed 4 steps · 2 calls 11.3s
🟢 a trusted plugin hook stays trusted after the server restarts 4 steps · 2 calls 11.3s
🟢 settingsRoundTrip.e2e.ts · 1 passed 2 steps · 1 call 10.1s
🟢 a chat survives trips through Settings 2 steps · 1 call 10.1s
🟢 sidebarPerWorkspace.e2e.ts · 1 passed 4 steps · 1 call 5.5s
🟢 a new workspace starts with its right sidebar collapsed while another keeps it open 4 steps · 1 call 5.5s
🟢 smoke.e2e.ts · 1 passed 2 steps · 1 call 3.8s
🟢 the agent opens the playground workspace 2 steps · 1 call 3.8s
🟢 streamErrors.e2e.ts · 1 passed 1 step · 1 call 7.6s
🟢 stream errors show in the chat, and the chat recovers 1 step · 1 call 7.6s
🟢 todoNudge.e2e.ts · 1 passed 1 step · 1 call 3.5s
🟢 the agent finishes open TODO items after the turn-end nudge 1 step · 1 call 3.5s
🟢 touchAlignment.e2e.ts · 6 passed 6 steps · 6 calls 25.7s
🟢 the Settings close button is level with the title on a touch screen 390px wide 1 step · 1 call 4.1s
🟢 the Settings close button is level with the title on a touch screen 768px wide 1 step · 1 call 4.5s
🟢 Backup settings checkboxes are small and level with their labels on a touch phone 1 step · 1 call 4.9s
🟢 the heartbeat checkbox is small and level with its label on a touch phone 1 step · 1 call 4.2s
🟢 a reply's model and time stay on one line on a touch phone 1 step · 1 call 4.1s
🟢 the workspace actions menu stays on the title row on a touch phone 1 step · 1 call 3.8s

e2e 0.20.0 · 1m 23s · web · run artifacts

🟢 e2e Electron stories (Haiku): 3 passed

3 agent steps · 3 model calls · 7.9k tokens (33% cached)
Spend: $0.01 of the $1.00 cap (proxy ledger)

All 3 tests in 3 files
Test Agent Time
🟢 electron/deepLink.e2e.ts · 1 passed 1 step · 1 call 7.6s
🟢 a deep link of a second launch starts a chat in the running app 1 step · 1 call 7.6s
🟢 electron/menuBar.e2e.ts · 1 passed 1 step · 1 call 7.4s
🟢 the workspace menu bar is the desktop title bar 1 step · 1 call 7.4s
🟢 electron/smoke.e2e.ts · 1 passed 1 step · 1 call 6.6s
🟢 Xum Electron opens the playground workspace 1 step · 1 call 6.6s

e2e 0.20.0 · 24.5s · electron · run artifacts

🟢 e2e agent repros (Haiku): no tests selected

Spend: $0.00 of the $1.00 cap (proxy ledger)

e2e 0.20.0 · 7.2s · 2 targets (web, phone) · run artifacts

@ThomasK33

Copy link
Copy Markdown
Member Author

@codex review

Head: fd3c51f

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

Reviewed commit: fd3c51fb3a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review · Automatically triggered

Security review completed. No security issues were found in this pull request.

Reviewed commit: fd3c51fb3a

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

This branch has not been deployed

No deployments
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.

1 participant