#22099·meshery

Rejected preference updates change Local Provider settings

Author: doraem-onCreated Sep 26, 2026Updated Sep 28, 2026

Description

With the Local Provider, POST /api/user/prefs can reject an invalid preference update with HTTP 400 while still modifying the stored in-memory preferences. The response indicates that the update failed, but the rejected data remains available to subsequent requests.

This also affects later updates to unrelated settings. In the verified test, an invalid QPS value replaces the previously valid value, and a subsequent update to anonymousUsageStats fails because validation encounters the rejected QPS value left in the stored object.

Expected and actual behavior

A rejected request should leave the saved preferences unchanged. Later valid updates should be evaluated against the last successfully saved state.

The regression test observed:

Check Expected Actual
Invalid QPS update HTTP 400 HTTP 400
Stored QPS after rejection Original value: 5 Rejected value: -1
Subsequent unrelated preference update HTTP 200 HTTP 400

The impact is that a failed update changes server state and causes otherwise valid preference updates to fail until the invalid setting is corrected. The confirmed scope is the Local Provider's in-memory preferences; disk persistence and Remote Provider behavior are not claimed here.

Root cause

MapPreferencePersister.ReadFromPersister returns the pointer held in the preference store. UserPrefsHandler decodes the request body into that object before validating its fields.

Consequently, decoding changes the stored object immediately. Returning HTTP 400 before calling RecordPreferences does not undo that mutation. Validation should operate on independent data, and saved state should change only after the update is accepted.

Verified test evidence

Tests were executed against commit 4d20eed4ad399dfdaac988ddc17efd87ef66f009, with production files unchanged. A new regression test, TestAuditRejectedPreferenceUpdateDoesNotPoisonStoredPreference, invokes the real UserPrefsHandler, DefaultLocalProvider, and MapPreferencePersister using Go's httptest request/response utilities. The preference store and validation behavior are not mocked.

The test file was supplied through a Go overlay. Running the regression with -count=3 -v failed all three runs, with exit status 1. The assertions check both saved state after rejection and the response to the subsequent unrelated update. This excerpt is copied from the captured test output:

=== RUN   TestAuditRejectedPreferenceUpdateDoesNotPoisonStoredPreference
    audit_preference_repro_test.go:39: rejected request status=400; subsequent read QPS=-1
    audit_preference_repro_test.go:41: rejected update changed persisted preference: got QPS=-1, want 5
    audit_preference_repro_test.go:47: subsequent unrelated update status=400
    audit_preference_repro_test.go:49: unrelated valid update failed: got HTTP 400, want 200
--- FAIL: TestAuditRejectedPreferenceUpdateDoesNotPoisonStoredPreference (0.00s)

Existing model preference tests were also executed:

bash
go test ./server/models -run 'Test.*Preference' -count=1 -v

They passed with exit status 0. This confirms the observed failure is exposed by the added regression test while the existing preference tests remain green.

Testing covers the handler and persister directly, not a live UI session or the complete middleware stack. The full repository test suite was not run.

Related reports

No matching issue or PR was found in the duplicate searches. Related reports #5174 (missing-preference nil-pointer crash), #20971 (Performance Profile UI validation), and PR #17274 (request-body-close error handling) concern different behavior.