Skip to content

feat(web): apply chosen server settings to every environment - #9

Merged
greaber merged 4 commits into
grant/mainfrom
grant/settings-sync
Nov 12, 2026
Merged

greaber merged 4 commits into
grant/mainfrom
grant/settings-sync

Conversation

@greaber

@greaber greaber commented Nov 12, 2026 •

Copy link
Copy Markdown
Owner

Some server settings change how agents behave, and each server keeps its own copy in its settings.json. Changing one under All environments only reached servers connected at that moment. Servers that were offline missed it, a new server started from its own defaults, and existing servers kept whatever value had been written into their file.

What changed

  • Preferences saved on the client. Client settings gain serverSettingPreferences, a struct of server-setting keys. It is saved with the other client settings (the desktop client-settings file, or localStorage on web) and defaults to {}. The keys covered now are idleCompaction (the global mode), sidebarAutoSettleOnMerge, and sidebarAutoSettleAfterDays. Covering another key takes one line in ServerSettingPreferences in packages/contracts/src/settings.ts.
  • When a preference is recorded. Changing a covered setting in Settings with All environments selected records the value. Restore defaults only updates preferences that are already set. A write at single-environment scope leaves out any field whose preference is set.
  • Applying on connect. startServerSettingPreferencesSync runs from appInit. It plans again whenever a connected server's config, its auth session, or the preferences change, and writes only the keys that differ. A new server gets every preference the first time it connects. The decision logic lives in the pure nextPreferenceWrites:
    • Each distinct patch goes to a server at most once per connection. A server's record is dropped when it stops being connected.
    • So a config cached from the previous connection is planned again when the fresh one arrives. A preference saved while a server is connecting is applied once it connects, and a supervisor whose connection count restarts is still written.
    • A failed or dropped write is not retried within the same connection.
    • A session that has not loaded, or failed to load, is waited on rather than treated as "no permission".
  • The write itself. It goes through persistScopedSettingsPatch, with idle compaction written by idleCompactionPatch in the form each server version reads. Keys locked by a server's managed policy are skipped, and so are connections without permission to write settings. A failed write shows a toast at most once per environment, server version and patch per app session, and the failure reason also appears in the row.
  • Under All environments. Covered rows are no longer locked because one connected environment is managed or this connection can't write settings there. The write goes to the other environments and the preference is recorded.
  • Settings UI. A covered row says it is applied to every environment and lists each connected environment whose value differs, with the reason: managed there, no permission to change settings, can't store Never (update T3 Code there), the save error, or not applied yet. It also offers Stop applying everywhere. Once a preference is set, the control is read-only with a single environment selected.
  • Idle compaction default. The new DEFAULT_IDLE_COMPACTION ("off", "Never") matches what servers without a saved choice use since Never compact idle threads unless the user chooses to #8. The server uses it, and DEFAULT_UNIFIED_SETTINGS and the row's built-in-default check use it too, so Reset no longer shows on every fresh server or records "When you return". DEFAULT_SERVER_SETTINGS and globalIdleCompaction are unchanged, so an old server's legacy compactIdleThreads: false still means "When you return".
  • Docs: docs/user/project-settings.md describes this.

Idle session release is not covered. On grant/main it is the T3CODE_PROVIDER_IDLE_TIMEOUT_MS environment variable, not a server setting.

Compatibility. Mobile is unchanged. An older desktop or web client drops serverSettingPreferences the next time it saves client settings, so after a downgrade the preferences have to be set again.

Checks

Check SHA Result
vp test run src/components/settings/serverSettingPreferences.test.ts src/components/settings/scopedSettings.test.ts 78b960076e pass (34 tests)
vp run check:changed: format, lint, knip, typecheck (37 packages), react compiler 78b960076e pass
vp run check:changed: tests beside changes 78b960076e fail: Sidebar.logic.browser.test.tsx, ChatView.logic.browser.test.ts, ChatView.browser.test.tsx fail to import (Cannot access 'twMerge' before initialization)
Same three browser test files on base 7fdbc2762e 7fdbc2762e same import failure, so it predates this change
vp test run src/components/settings/serverSettingPreferences.test.ts src/components/settings/scopedSettings.test.ts f14305b517 pass (42 tests)
vp test run src/serverSettings.test.ts (apps/server) f14305b517 pass (75 tests)
vp run check:changed: format, lint, knip, typecheck (37 packages), react compiler f14305b517 pass
vp run check:changed: tests beside changes f14305b517 fail: Sidebar.logic.browser.test.tsx and ChatView.logic.browser.test.ts, the same import failure that happens on base
vp test run serverSettingPreferences.test.ts, scopedSettings.test.ts 03ff9b8 (before a comment-only edit) 42 pass
vp run check:changed 03ff9b8 (before a comment-only edit) format, lint (after the comment edit), knip, typecheck, react compiler pass; tests fail only in Sidebar.logic.browser and ChatView.logic.browser, which fail to load the same way on base 7fdbc27

No real-client UI pass was run.

🤖 Generated with Claude Code

greaber and others added 2 commits November 12, 2026 02:25
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. size:L labels Nov 12, 2026
…lain gaps

Plan the writes again whenever a connected server's config, its session,
or the preferences change, and send each distinct patch at most once per
connection, so a cached config, a late session, a preference saved while
connecting, or a replaced connection no longer skips a server. Under All
environments, covered settings save where they can instead of locking the
row, and the row says why each differing server was not changed. Restore
defaults only updates preferences already set, a single-environment write
leaves them alone, and the client's default for idle compaction is Never,
matching what servers without a saved choice use.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added size:XL and removed size:L labels Nov 12, 2026
…lue is set back

Under All environments the idle compaction choice is saved for every
environment, so a connected server too old to store Never no longer
disables it; that server is listed with its reason. The docs and the
sync comment now match the once-per-connection rule: a value changed
elsewhere is set back at the latest on the next connection.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@greaber
greaber merged commit 72b7fcd into grant/main Nov 12, 2026
11 of 13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XL vouch:trusted PR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant