Skip to content

fix(settings): reload settings when either settings.yaml or settings.json changes - #1157

Merged
cameri merged 1 commit into
cameri:mainfrom
Priyanshubhartistm:fix/settings-watch-all-config-files
Nov 16, 2026
Merged

cameri merged 1 commit into
cameri:mainfrom
Priyanshubhartistm:fix/settings-watch-all-config-files

Conversation

@Priyanshubhartistm

@Priyanshubhartistm Priyanshubhartistm commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator

Description

SettingsStatic.watchSettings() reloaded the cached settings only when the file named settings.<ext> changed, where <ext> was chosen once at startup from the first settings* file in the config directory. The loader (loadUserSettings) reads settings.yaml and falls back to the deprecated settings.json, and the admin console and the CLI always write settings.yaml. A worker that started while only settings.json existed therefore ignored every later write to settings.yaml and kept its old cached settings, including the NIP-98 admin allowlist, until it was restarted.

  • the directory watcher now reloads when either settings.yaml or settings.json changes (the names come from getSettingsFilePath and getLegacySettingsFilePath, the same ones the loader uses);
  • the startup settingsFileType() lookup in the watcher is gone, since the watched names no longer depend on it. The method itself is unchanged.

The reload still goes through createSettings(), which uses loadMergedSettings(), so the yaml-over-json precedence is the loader's and is not duplicated here.

Not in this PR: the issue also suggests that a successful admin policy update should refresh every worker directly. Workers already reload through this watcher once the file changes, so I kept the change to the watcher.

Related Issue

Fixes #1014

CodeRabbit's scan did not establish reachability, so I checked the code first. On main, watchSettings() compares the changed filename with settings.${fileType}, and saveSettings and the settings write path write settings.yaml. It affects relays that were started from a settings.json; for yaml installs the old behaviour was already correct.

Motivation and Context

A removed admin key or a changed limit should reach every worker, whichever of the two supported settings files the worker started from.

How Has This Been Tested?

Unit tests in test/unit/utils/settings.spec.ts (.watchSettings), using a temporary config directory and a stubbed fs.watch: a change to settings.yaml reloads; a change to settings.json reloads; settings.yaml written in a worker that started from settings.json reloads; other files (settings-audit.jsonl, .settings-write.lock) and a missing filename do not. Without the fix, the second and third tests fail.

Screenshots (if appropriate):

Types of changes

  • Non-functional change (docs, style, minor refactor)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my code changes.
  • I added a changeset, or this is docs-only and I added an empty changeset.
  • All new and existing tests passed.

Summary by CodeRabbit

  • Bug Fixes
    • Settings now reload when either settings.yaml or the legacy settings.json file changes, so updates are applied without needing to restart.
    • Renaming settings.yaml also triggers a reload when settings.json is present. Changes to unrelated files do not trigger a settings reload.

…json changes

Signed-off-by: Priyanshubhartistm <bhartipriyanshustm@gmail.com>
@changeset-bot

changeset-bot Bot commented Nov 16, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 8e90d9e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
nostream Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai

coderabbitai Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The settings watcher now monitors both the current and legacy settings filenames. Changes to either filename trigger a settings reload. Unit tests cover reloads for both filenames, a rename, and notifications that should not trigger a reload.

Changes: Settings file watching

Layer / File(s) Summary
Watch both settings filenames
src/utils/settings.ts, test/unit/utils/settings.spec.ts, .changeset/settings-watch-yaml-and-json.md
The watcher checks notifications against both settings filenames and reloads when either matches. Tests cover both filenames, a rename, unrelated filenames, and a null filename. The changeset declares a patch release.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Possibly related issues

  • Issue 1019 — Its description requests watching both settings filenames so a JSON-started worker reloads its cached blacklist after a YAML change. This PR adds that watcher behavior.
Merge Risk: Minimal · up to 8e90d

The settings watcher now reloads when either settings.yaml or settings.json changes, which fixes the case where a worker started from JSON misses YAML updates. No concrete merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title states that settings reload when either settings.yaml or settings.json changes. The changeset's main change is the watcher in SettingsStatic.watchSettings, which now watches both filenames i…
Linked Issues check Passed [#1014] The issue requires every worker to observe changes to both settings.yaml and settings.json, and to reload with the loader's YAML precedence. In src/utils/settings.ts, watchSettings() now build…
Out of Scope Changes check Passed All changed areas connect to #1014. src/utils/settings.ts changes only the watcher filename logic, the import of basename and getLegacySettingsFilePath, and the comment that explains the change. The u…
Full details: Title check

Explanation

The title states that settings reload when either settings.yaml or settings.json changes. The changeset's main change is the watcher in SettingsStatic.watchSettings, which now watches both filenames instead of selecting one by detected file type. The title matches this main change. The 81-character length is longer than ideal but does not affect clarity.

Full details: Linked Issues check

Explanation

[#1014] The issue requires every worker to observe changes to both settings.yaml and settings.json, and to reload with the loader's YAML precedence. In src/utils/settings.ts, watchSettings() now builds watchedFilenames from basename(getSettingsFilePath()) and basename(getLegacySettingsFilePath()). The startup settingsFileType() lookup is removed, so a JSON-started worker reacts to settings.yaml writes. The reload still calls createSettings(), which uses loadMergedSettings(), so YAML precedence comes from the existing loader. The null-filename case maps to '' and does not match. The PR's unit tests cover these cases, as described in the PR description; I did not run them. [#1014] The second requirement, that a successful admin policy update refreshes serving workers, is met through the same mechanism. The admin console and CLI write settings.yaml, and every worker's watcher now fires on that write. The PR does not add a direct refresh call, and the PR description states that this exclusion is intentional. The fs.watch path depends on platform file-event delivery, which this review did not verify. The core watcher requirement is met.

Full details: Out of Scope Changes check

Explanation

All changed areas connect to #1014. src/utils/settings.ts changes only the watcher filename logic, the import of basename and getLegacySettingsFilePath, and the comment that explains the change. The unit tests in test/unit/utils/settings.spec.ts cover the watcher behavior. The changeset is a patch note for the same fix. The diff inspected for src/utils/settings.ts shows no unrelated edits. settingsFileType() is unchanged, as the PR states.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

A rabbit checks the names in view
YAML hops, and JSON too
A change arrives; the settings renew
Strange file names pass right through
The rabbit thumps: “Both paths are true!”

Recent review info

Automatic approval policy

Commit: 8e90d9e7226c.

Setting Effective value Source
Automatic approvals Enabled Global configuration
Merge risk Minimal Global configuration
Security risk Not set Global configuration

Not set means no limit was configured after inheritance. Use @coderabbitai configuration to inspect the resolved settings and their sources.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: b37f7ba3-154c-4885-afb1-6a280887b026
Commits

Reviewing files that changed from the base of the PR and between 7bbbce9 and 8e90d9e.

Files selected for processing: 3

  • .changeset/settings-watch-yaml-and-json.md
  • src/utils/settings.ts
  • test/unit/utils/settings.spec.ts

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

@greptile-apps

greptile-apps Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge.

Summary

watchSettings() now reloads cached settings when either settings.yaml or settings.json changes.

  • Workers reload settings when either settings file changes.

Reviews (1) · Last reviewed commit: "fix(settings): reload settings when eith..." · Reviewed by Greptile

@coveralls

Copy link
Copy Markdown
Collaborator

Coverage Report for CI Build 43958206919

Coverage decreased (-0.007%) to 79.242%

Details

  • Coverage decreased (-0.007%) from the base build.
  • Patch coverage: 4 of 4 lines across 1 file are fully covered (100%).
  • 6 coverage regressions across 1 file.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

6 previously-covered lines in 1 file lost coverage.

File Lines Losing Coverage Coverage
src/utils/settings.ts 6 76.92%

Coverage Stats

Coverage Status
Relevant Lines: 13890
Covered Lines: 11473
Line Coverage: 82.6%
Relevant Branches: 7451
Covered Branches: 5438
Branch Coverage: 72.98%
Branches in Coverage %: Yes
Coverage Strength: 678.45 hits per line

💛 - Coveralls

@cameri
cameri merged commit 5496a7d into cameri:main Nov 16, 2026
17 of 20 checks passed
cameri added a commit that referenced this pull request Nov 17, 2026
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to main, this PR will
be updated.


# Releases
## nostream@3.16.0

### Minor Changes

- [#1088](#1088)
[`e1f92ad`](e1f92ad)
Thanks [@Ferryx349](https://github.com/Ferryx349)! - feat(peering):
deliver paid peering invoices and gate peer feeds

Configured peers can request their BOLT11 invoice as a signed `kind 402`
event
and pay it through Relay B's existing processor. Feed `REQ`, `COUNT` and
NIP-77
requests are refused with a payment-required reason until a paid period
is
active. Expired invoices are reissued after a cooldown, and a missed
webhook is
  rechecked before access is denied.

- [#1087](#1087)
[`1d5c473`](1d5c473)
Thanks [@Ferryx349](https://github.com/Ferryx349)! - feat(peering): add
the paid peering billing ledger

- [#1089](#1089)
[`15de73a`](15de73a)
Thanks [@Ferryx349](https://github.com/Ferryx349)! - feat(peering):
renew, lapse and expose paid peering access

The billing worker now issues renewal invoices before a period ends,
rechecks
pending payments before lapsing a peer, closes live peer sockets on
lapse, and
keeps stored events and sync state for a later resume. `GET
/admin/peering` and
the dashboard show billing status, access end, the open invoice and the
last
processor error. NEG-MSG rechecks paid access so an open NIP-77 session
cannot
  keep syncing after the paid period ends.

### Patch Changes

- [#1145](#1145)
[`afb381f`](afb381f)
Thanks [@Priyanshubhartistm](https://github.com/Priyanshubhartistm)! -
fix(admin): revoke the session token at logout, not only its cookie

`POST /admin/logout` deleted the browser cookie but the session token
itself stayed valid until it expired (24 hours by default), because the
token was only `<expiresAt>.<signature>` and nothing on the server
recorded a logout. A copy of the token kept elsewhere (a `Bearer`
client, a log, a proxy) could restore administrator access after
sign-out. The token now carries a random session id under the same
signature, logout records that id in Redis until the token would have
expired, and every admin request checks it, so a logout on one worker
ends the session on all of them and ends only that session. If Redis
cannot be read the token is refused, and a logout that cannot record the
id answers 500 (and still clears the cookie).

Tokens issued before this change have no session id and are refused, so
every administrator signs in once more after the upgrade.

- [#1091](#1091)
[`6b3db4d`](6b3db4d)
Thanks [@Priyanshubhartistm](https://github.com/Priyanshubhartistm)! -
fix(cli): reject a SECRET that cannot be saved to .env and read back
unchanged

- [#1156](#1156)
[`69197f7`](69197f7)
Thanks [@Priyanshubhartistm](https://github.com/Priyanshubhartistm)! -
fix(logging): do not write credential headers to debug logs

Debug logging of incoming requests printed every header, so the admin
session cookie, an `Authorization` bearer token, API keys and webhook
signatures could be read from the logs and reused. The rate-limit
middleware, the WebSocket connection log and the four payment callback
controllers now log the headers with the value of every
credential-bearing header replaced by `[redacted]`.

- [#1157](#1157)
[`8e90d9e`](8e90d9e)
Thanks [@Priyanshubhartistm](https://github.com/Priyanshubhartistm)! -
fix(settings): reload settings when either settings.yaml or
settings.json changes

A worker watched only the settings file whose extension existed when it
started. The loader reads `settings.yaml` first and falls back to the
deprecated `settings.json`, and the admin console and the CLI always
write `settings.yaml`, so a worker that started from `settings.json`
never reloaded after the yaml file was written. A change such as
removing a pubkey from the NIP-98 admin allowlist stayed unseen by that
worker until it restarted. The watcher now reloads on a change to either
file.

- [#1118](#1118)
[`5c4b4f0`](5c4b4f0)
Thanks [@Ferryx349](https://github.com/Ferryx349)! - fix(admin):
serialize every settings-file writer with the settings write lock

The lock records its owner hostname and refreshes a heartbeat, so a
relay in a
container no longer steals a live CLI lock just because the host PID
does not
exist in its own PID namespace. On the same host the lock checks the
owner's
process start time, so a reused PID is reclaimed without ever evicting a
slow
  writer, and async writers keep the lock until they settle.
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.

Security: authorization bypass in src/utils/settings.ts

3 participants