Skip to content

theme-set-claude/pi: clean up staged tmp file when settings update fails - #13713

Closed
kvnloo wants to merge 4 commits into
omacom:quattrofrom
kvnloo:muse/theme-set-settings-tmp-cleanup
Closed

kvnloo wants to merge 4 commits into
omacom:quattrofrom
kvnloo:muse/theme-set-settings-tmp-cleanup

Conversation

@kvnloo

@kvnloo kvnloo commented Sep 29, 2026

Copy link
Copy Markdown
Contributor

What

omarchy-theme-set-claude / omarchy-theme-set-pi staged the new settings.json through mktemp, then ran a bare jq ... > tmp; mv tmp settings.json under set -e. A hand-edited settings.json (JSONC comments, trailing commas) makes jq fail: the script died leaving a settings.json.XXXXXX litter file beside a settings.json it never updated.

Fix

Guard both staged writes the way theme-set-hermes's publish_skin already does: remove the temp file on failure, print a clear stderr message, exit nonzero. The settings file is never left half-written and no litter remains.

Evidence

  • New test/shell.d/theme-set-settings-tmp-cleanup-test.sh: fails on pristine base (litter assertion), 4/4 green on fix.
  • bash -n and bin-style-test.sh clean.

Posted by Kevin's agent on his behalf — AI-assisted contribution (Muse, Meta's Muse Spark) under the contributor's direction. The contributor reviewed the change and takes responsibility for it.

@sanjyay

sanjyay commented Sep 29, 2026

Copy link
Copy Markdown
Contributor

This is an independent community review and unaffiliated with the Omarchy team, intended to help prepare PRs for their review.

Tested commit b24ae437a60ded89d03f61e4c864342df82f94dc in a clean Omarchy test environment.

Verification Summary

  • Base behavior on quattro: omarchy-theme-set-claude and omarchy-theme-set-pi staged updates to settings.json and theme destinations using mktemp. If jq, cp, or mv failed under set -e (e.g. if a user edited settings.json with JSONC comments or trailing commas that jq rejects), the script exited immediately leaving behind uncleaned settings.json.XXXXXX or theme temp files.
  • PR behavior: Guards both staged operations with if ! ... || ! ...; then rm -f "$tmp"; ...; fi, removing intermediate temporary files and reporting a clear error message to stderr on failure.
  • Automated test suite:
    • test/shell.d/theme-set-settings-tmp-cleanup-test.sh passes on the PR branch (all 4/4 assertions pass).
    • When tested against base quattro, the new test suite accurately reproduces the abandoned temporary file defect (not ok - claude leaves no settings.json.XXXXXX litter when jq fails).
    • Whitespace checks, bash -n, and test/shell.d/bin-style-test.sh pass cleanly.
Test details
# Base quattro failure reproducing leaked temporary files:
$ bash test/shell.d/theme-set-settings-tmp-cleanup-test.sh
not ok - claude leaves no settings.json.XXXXXX litter when jq fails

# PR branch execution:
$ bash test/shell.d/theme-set-settings-tmp-cleanup-test.sh
ok - claude activate leaves no tmp litter and keeps settings.json on jq failure
ok - claude activate writes the theme on a valid settings.json
ok - pi activate leaves no tmp litter and keeps settings.json on jq failure
ok - pi activate writes the theme on a valid settings.json

$ bash test/shell.d/bin-style-test.sh
ok - bin commands use command helpers
ok - bin commands use the notification helper

$ git diff --check
$ bash -n bin/omarchy-theme-set-claude bin/omarchy-theme-set-pi test/shell.d/theme-set-settings-tmp-cleanup-test.sh

If you'd prefer not to receive these independent reviews on your PRs, reply to this comment and say so, and I won't review your future PRs.

@omarchybot omarchybot added the bug Something isn't working label Oct 1, 2026
omarchy-theme-set-claude honours CLAUDE_CONFIG_DIR, so with it exported the test activated the theme in the real Claude settings rather than the scratch home. Pass it explicitly, as test/cli does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@omarchybot omarchybot added the verified Omarchy Triage has verified that this issue is ready for final review label Oct 3, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

Reviewed and run on a disposable Omarchy worker. The bug is real and the fix holds.

Reproduction. With a settings.json jq cannot parse, omarchy-theme-set-claude --activate and omarchy-theme-set-pi --activate on quattro (a85e29a) exit non-zero and leave a settings.json.XXXXXX file beside the untouched settings. At this head both exit 1, name the file they could not update, leave no staged file behind, and still write the theme on a valid settings.json with other keys preserved. The new test fails on quattro's scripts and passes on the PR's.

Pushed 7e7ae7f. omarchy-theme-set-claude honours CLAUDE_CONFIG_DIR, and the new test set only HOME, so on a machine with CLAUDE_CONFIG_DIR exported it activated the Omarchy theme in the real Claude settings and wrote themes/omarchy.json there (seen on the worker). The test now passes CLAUDE_CONFIG_DIR="$test_home/.claude", as test/cli already does; with the variable exported it now passes and leaves that directory alone.

Tests. test/shell.d/theme-set-settings-tmp-cleanup-test.sh 4/4 and bin-style-test.sh pass. ./test/cli stops at vscode generated theme references current theme file, which fails the same way on quattro and has nothing to do with this change; the theme-set-claude and theme-set-pi checks before it pass.

Second opinion. Codex Medium reviewed the diff and the test fix. It agreed the production change is correct and proportionate and that the CLAUDE_CONFIG_DIR fix was the one test defect; it was shown that finding first, so treat that part as agreement rather than an independent result. It added that the four-line comments could be one line and that the stderr assertions check only "could not update", not the path; neither changes behaviour.

Nothing is needed from the author. This waits on the maintainer, and on the unrelated test/cli failure on quattro before the suite can be called green.

@greptile-apps

greptile-apps Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Low impact] The PR appears safe to merge; no actionable issues remain.

Summary

Claude and Pi theme sync now remove staged files when settings updates, theme copies, or theme renames fail.

  • Claude and Pi theme sync remove staged files when writes fail.

Reviews (3) · Last reviewed commit: "Merge quattro into theme-set-settings-tm..." · Reviewed by Greptile

@omarchybot omarchybot added verified Omarchy Triage has verified that this issue is ready for final review and removed verified Omarchy Triage has verified that this issue is ready for final review labels Oct 18, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

Re-reviewed at 080ce6b on a disposable Omarchy worker. The fix still holds, and the new failure cases test what they claim to.

Reproduction. On current quattro (0c93f61), a JSONC settings.json passed to --activate leaves a settings.json.XXXXXX file beside both the Claude and the Pi settings. At this head both commands exit 1, name the file they could not update and leave nothing behind. theme-set-settings-tmp-cleanup-test.sh passes 10/10 here and fails on quattro's scripts and with the fix reverted. Taking the theme-copy cleanup out of omarchy-theme-set-claude fails the new theme-cp case, so those cases are not vacuous.

Suite. ./test/cli at this head stops at vscode generated theme references current theme file, because the branch predates the fix for that on quattro. Merged with current quattro, ./test/cli passes, as do the new test and bin-style-test.sh.

Second opinion. Codex Medium reviewed commit 080ce6b and the overlap below. It found no defect in the new cases: the stub matches only the intended cp and mv calls, the marker proves the injected failure was reached, and the test stays inside its temp directories. Independence is not guaranteed, since it can read this session's working. It also suggested dropping or shortening the docs/testing.md bullet, because that section lists general conventions and this bullet catalogues one test. That is editorial and changes no behaviour.

Overlap with #13983. #13983 rewrites the same settings write in both scripts so that symlinked and permission-carrying settings.json files survive activation, and its exit trap also removes the staged settings file when jq fails. The two conflict in both scripts. This pull request is older and is the only one that cleans up a failed theme copy or rename. #13983 is the only one that preserves settings symlinks and metadata. Codex Medium would take #13983's settings write and keep this pull request's theme-stage cleanup. Which of them lands first, and how the other is reconciled, is the maintainer's call, so this one is labelled verified but not ready while #13983 carries ready.

Nothing is needed from the author now. This waits on the maintainer.

@omarchybot omarchybot removed the verified Omarchy Triage has verified that this issue is ready for final review label Oct 30, 2026
Resolves the docs/testing.md conflict: quattro replaced the "Migrations run directly" convention with "Migrations get no suite test", so that bullet takes quattro's text and the staged-write bullet stays beside it. The scripts and the test merge cleanly.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@omarchybot omarchybot added the verified Omarchy Triage has verified that this issue is ready for final review label Nov 1, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

This pull request had stopped merging into quattro, so I merged current quattro (7eedd17) into the branch as ba7a4e0. The only conflict was in docs/testing.md, where quattro replaced the "Migrations run directly" bullet with "Migrations get no suite test". The merge takes quattro's bullet and keeps this pull request's staged-write bullet next to it. Neither script changed upstream, so the fix itself is unchanged.

Re-verified on a disposable Omarchy worker at ba7a4e0. theme-set-settings-tmp-cleanup-test.sh passes 10/10. With quattro's two scripts swapped in, which is the same as reverting the fix, it fails on the first litter check. ./test/cli, bin-style-test.sh and theme-set-budget-test.sh pass. The full ./test/all was left to CI.

Second opinion. Codex Medium and muse-wonder (via pi, thinking high) reviewed the merge and the diff against quattro. Neither found a defect. Both say the conflict was resolved correctly, the test still fits base-test.sh as quattro has it now, and the problem is real. They agreed with my reading, and their independence is not guaranteed. Both called the 151-line test generous for an 8-line fix.

Fit with the test rules quattro has added since this was opened. quattro's AGENTS.md now asks that a test extend the area's existing file rather than add a new *-test.sh, and that tests stay in proportion to the change. test/cli already tests both scripts (around lines 520–560). So under those rules, the jq-failure litter cases would go there as a few lines, and the bullet in docs/testing.md, which describes this one test, would come out. I have not made that change, because what this pull request should keep depends on the decision below.

Overlap with #13983. That pull request is still open. It rewrites the same settings write in both scripts to keep settings symlinks and file metadata, and its EXIT trap already removes the staged settings file when jq or the rename fails. The two still conflict in both scripts. This pull request is the only one that cleans up a failed theme copy or rename. Both reviewers would land #13983's settings write and keep this pull request's theme-stage cleanup. If #13983 lands first, this one would shrink to the theme-stage cleanup and its test cases. Which goes first is the maintainer's call, so this one is labelled verified but not ready.

This waits on the maintainer.

Arash-Afshar added a commit to Arash-Afshar/omarchy that referenced this pull request Nov 6, 2026
…r's pick

omarchy-theme-set-pi wrote the theme and the theme setting into ~/.pi/agent
even when PI_CODING_AGENT_DIR moves Pi's agent tree, so Pi never saw either.
Its Claude and Hermes siblings already follow their agent's variable.

- The agent directory is ${PI_CODING_AGENT_DIR:-~/.pi/agent}, with a leading
  ~ expanded the way Pi expands it (pi 1.5.0 getAgentDir()).
- --activate, which install/user/theme.sh runs on every re-provision, only
  fills in an unset theme. A theme the user picked in Pi is kept.
- The settings write goes through a symlinked settings.json (dotfiles) to its
  target, keeps the file's mode, and leaves the file untouched with no temp
  litter when it is not valid JSON, reporting the failure.

test/shell.d/theme-set-pi-test.sh covers each case; it fails on the first
assertion against the previous script.

Fixes omacom#13691 (theme half). Supersedes omacom#13693, omacom#13718, omacom#13713 (Pi half) and
the Pi half of omacom#13983.
@kvnloo

kvnloo commented Nov 28, 2026

Copy link
Copy Markdown
Contributor Author

Closing this one, it's a minor edge case and not worth review time. Thanks to omarchybot for verifying it.

@kvnloo kvnloo closed this Nov 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working verified Omarchy Triage has verified that this issue is ready for final review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants