Skip to content

fix(shell): keep last valid shell.json when the file truncates (#12990) - #12992

Closed
kvnloo wants to merge 2 commits into
omacom:quattrofrom
kvnloo:fix/12990-retain-shell-config-on-empty
Closed

kvnloo wants to merge 2 commits into
omacom:quattrofrom
kvnloo:fix/12990-retain-shell-config-on-empty

Conversation

@kvnloo

@kvnloo kvnloo commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #12990.

What changed

applyShellConfig() now tracks when a versioned user shell.json has been successfully applied (hasAppliedUserShellConfig). If a later reload sees empty/whitespace or unparseable user text after that, it retains the last valid in-memory shellConfig and logs a warn instead of replacing with builtin defaults.

Genuine first-load fallback to defaults is unchanged when nothing valid was ever loaded.

Why still needed

A runtime truncation of ~/.config/omarchy/shell.json (after a valid load) used to flip shellConfig to stock defaults. The next mutateShellConfig / persistShellConfig then permanently wrote that stock config (bar reset, third-party plugins disabled). Distinct from the #11349 startup race.

Tests

  • test/shell.d/shell-config-empty-retain-test.sh — source pin for the retain guard (flag, warn+return, no user || defaults clobber, first-load defaults still allowed)
  • Ran: bash test/shell.d/shell-config-empty-retain-test.sh → ok

Tip: d3cfd53b997f8bdcf776b8db68bf0d735e7a065d (upstream/quattro)

Credit / provenance

When ~/.config/omarchy/shell.json becomes empty or unparseable at runtime
after a valid user config was already applied, applyShellConfig retained
nothing and fell back to builtin defaults. The next mutateShellConfig then
persisted stock layout and wiped third-party plugins. Retain the last
valid in-memory user config (with a warn) while still allowing first-load
fallback when nothing valid was ever loaded.

Fixes omacom#12990.
@sanjyay

sanjyay commented Sep 23, 2026

Copy link
Copy Markdown
Contributor

Tested in the Omarchy VM running Omarchy 4.0.4-1 with Quickshell 0.3.1:

  • Ran bash test/shell.d/shell-config-empty-retain-test.sh: passed cleanly.
  • Tested live in Quickshell:
    • Initial startup with missing/empty shell.json correctly falls back to default config (hasAppliedUserShellConfig: false).
    • Loading a valid versioned shell.json sets hasAppliedUserShellConfig: true and applies the user config.
    • Simulating runtime file truncation (truncate -s 0) or corrupted/unparseable JSON logs shell.json empty or invalid after a prior valid load; retaining last valid config and keeps the active in-memory user configuration intact rather than reverting to defaults and overwriting user preferences on subsequent persistence.

Everything works as expected with no regressions.

@llstrk

llstrk commented Sep 23, 2026

Copy link
Copy Markdown

No actionable defect found in the inspected change at ef16ffa4c611.

Verified from source: after a valid version-1 user configuration has loaded, empty or invalid reloads leave the current configuration intact. Subsequent shell-side mutations therefore use that retained configuration rather than the defaults. A later valid configuration is still accepted.

Reload input Baseline This PR
Empty/invalid, before any valid user load Defaults Defaults
Empty/invalid, after a valid user load Defaults Retain current configuration
Valid version-1 object Apply user configuration Apply user configuration

Scope limits: retention is in memory, not an on-disk backup. Restarting while the file remains empty still takes the first-load defaults path. Separate disk-based writers, such as omarchy bar position, still start from defaults when the file is empty; that pre-existing path is unchanged.


Review information

Test scope: source inspection of the configuration reload/mutation paths and the added source-pattern test. No tests or Quickshell/FileView runtime behavior were executed; the original truncation was not reproduced.

Community review: Independent automated community review, unaffiliated with the Omarchy team, intended to help prepare PRs for their review.

Automated AI review: Astra Medium initial inspection, independent Opus 5.5 High and GPT 6 Sol Xhigh technical assessments, then Astra Medium synthesis checked against the pinned source.

The pin matched source strings, so it passed with shellConfig = defaults reinserted above the guard and failed on a reworded warning. This drives a live Quickshell instead: a valid load, an emptied file, a shell-side write, an unparseable file, then a later valid file, and it fails on quattro's applyShellConfig. Each retention check waits for the shell to log that it retained, so it cannot pass before the reload lands. It starts from a valid file because quattro's shell writes defaults into an empty one shortly after startup (omacom#11349), which would race the first write.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Codex Medium <noreply@openai.com>
@greptile-apps

greptile-apps Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 4/5

[Medium risk] Changes shell configuration reload logic to retain last valid state.

The PR appears safe to merge, with non-blocking feedback to test first-load fallback.

Findings

  1. P2 First-load fallback is untested ▶

Summary

applyShellConfig() now keeps the current user config when a later read of shell.json is empty or invalid.

  • Valid user config still replaces the current config.
  • Before any valid user config loads, the shell still falls back to defaults.
  • The new integration test checks retention, the next saved change, and recovery after a valid write.
  • Non-blocking feedback: add fresh-shell tests for empty and invalid user config.
Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Read shell.json] --> B{Valid versioned config?}
  B -->|Yes| C[Apply user config and remember success]
  B -->|No| D{Valid user config loaded before?}
  D -->|Yes| E[Warn and keep current config]
  D -->|No| F[Apply defaults]
Loading

Reviews (1) · Last reviewed commit: "Test the truncation fix by running it ra..."

@omarchybot omarchybot added the verified Omarchy Triage has verified that this issue is ready for final review label Oct 3, 2026
return 1
}

write_user_config first

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.

P2 First-load fallback is untested

The test always starts with a valid shell.json, so it never checks what happens when the file is empty or invalid before any valid config has loaded. A future change could break that fallback while this test still passes. Add fresh-shell cases for empty and invalid files, and check that the shipped defaults apply.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@omarchybot

Copy link
Copy Markdown
Collaborator

Reviewed, and the fix works. I reproduced #12990 on a disposable Omarchy VM with a live Quickshell: load a valid shell.json, truncate it to 0 bytes, then make a shell-side write (toggleBarTransparency). On quattro (821ae58), and on this branch with shell/shell.qml reverted, the running config dropped to the defaults and the write saved those defaults over the user's file. With this change the config stayed put and the write kept the user's layout.

I pushed one commit to your branch, fc6a7cd. It replaces test/shell.d/shell-config-empty-retain-test.sh with a test that actually runs the fix. The old test grepped shell.qml for strings, so it still passed with shellConfig = defaults put back above the guard, and it would fail if the warning were reworded. The new one launches Quickshell against a temporary HOME and walks through valid load → emptied file → shell-side write → unparseable file → later valid file. It passes on this head and on the head merged into quattro, and fails with the fix reverted. It starts from a valid file because quattro's shell writes defaults into an empty shell.json shortly after startup (#11349), which would race the test's first write.

./test/cli passes. ./test/shell fails in ascii, branding-about-animation, kernel-headers-migration and omarchy-kernel-migration, and those fail on quattro too. Nothing in the suite fails because of this change, but it isn't green either.

The second opinion was Codex Medium, over three rounds. It agreed the shell.qml change is correct and proportionate (independence not guaranteed). It found the weaknesses in the original test and three timing and cleanup holes in my first version of the new one. All of those are fixed, and its last round on fc6a7cd found nothing.

For the maintainer:

This is waiting on the maintainer.

@omarchybot

Copy link
Copy Markdown
Collaborator

This has stopped merging cleanly with quattro, and quattro has moved under it: #14534 now keeps a shell.json that fails to parse from being overwritten, and runs the shell on the defaults in memory until the file is fixed. What #12990 describes is still open on quattro, though: a file emptied to 0 bytes after a valid load still turns into the defaults, and the next shell-side change writes them over the user's layout.

#13104 fixes the same bug, and I've judged it the one to bring forward rather than this one. The project's default is that the older fix wins, but this one misses two cases #13104 handles:

#7723 retains the old config only when the JSON fails to parse, so it doesn't cover an emptied file.

This PR has something #13104 lacks: a test that runs a real shell through valid load, empty file, shell-side write, and checks what that write saved. I've asked for that check to be folded into #13104, in test/shell.d/runtime-smoke-test.sh, crediting @kvnloo. Either fix also has to narrow the retention to the empty-file case, because #14534's smoke test expects the defaults in memory for an unparseable file.

The second opinion, Codex Medium, was given all three PRs and #14534 without my conclusion, and also picked #13104, for the same two reasons. It did not run a shell. Its independence from this review is not guaranteed. I didn't push anything here or run it on a worker this time, since it isn't the fix being taken forward. Choosing between the two is the maintainer's call, and this one waits on that.

omarchybot added a commit to surim0n/omarchy that referenced this pull request Nov 1, 2026
…moke test

Empties the scratch shell's shell.json, waits for the shell to report it kept its config, then makes a bar change and requires the file to carry the loaded layout and the change. On quattro the reload drops to the defaults and the change writes them over the user's layout. The approach is omacom#12992's runtime test, moved into the existing smoke test.

Co-Authored-By: Kevin Rajan <7121943+kvnloo@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kvnloo

kvnloo commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

Closing in favour of #13104, which also handles a deleted shell.json and the CLI writers seeding an empty file. The real-shell regression here (valid load, empty file, shell-side write) is free for #13104 to fold into runtime-smoke-test.sh. Prepared by Claude Opus 5.5 via Hermes Agent; reviewed under kvnloo's account.

@kvnloo kvnloo closed this Nov 24, 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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Truncated shell.json falls back to builtin defaults; the next config write persists them (bar resets, third-party plugins disabled)

4 participants