Skip to content

feat(lite): make Lite mode a server-wide setting - #999

Closed
HoloNova wants to merge 1 commit into
agegr:mainfrom
HoloNova:pr/lite-config
Closed

HoloNova wants to merge 1 commit into
agegr:mainfrom
HoloNova:pr/lite-config

Conversation

@HoloNova

Copy link
Copy Markdown
Contributor

What

Lite mode was a per-device preference (a localStorage flag). What it changes
are resources the server shares: which model catalogue gets loaded, how long
an idle session is kept warm, how much memory the service aims to stay under. A
per-device switch meant two browsers talking to one Pi-Web could disagree about
the same process, and the server had no way to know its own mode.

Lite mode is now one server-wide configuration, owned by Pi-Web.

How

  • One Pi-Web-owned file, ~/.pi/agent/pi-web-settings.json:

    { "version": 1, "lite": { "enabled": false, "idleMinutes": 5, "memoryTargetMiB": 1800 } }

    It is deliberately not pi's settings.json, models.json, agents/settings.json
    or any plugin config: those belong to other runtimes and are rewritten wholesale
    by them. Reads are tolerant — a missing, damaged or hand-edited file falls back
    to the defaults per field, because these values are policy — while a write is
    minimal-edit (unknown fields preserved), validates its ranges, and refuses to
    overwrite a file it could not parse.

  • GET /api/lite reports the configuration plus the bounds each value is
    validated against ({ idleMinutes: {min, max, default}, memoryTargetMiB: {...} }),
    so a client does not have to duplicate the ranges. It is observation only: it
    never writes, reclaims or closes anything.

  • PUT /api/lite takes a partial update ({ "enabled": true } changes only
    that field) and goes through the same lib/request-security.ts check every
    other mutating route uses — there is no Lite-specific authentication.

  • Settings → General → Session lifetime edits it through a small client store:
    one read per page instead of one per component, re-read when the page becomes
    visible again, and the server's answer is what the UI shows after a save. The
    copy says it is a server-wide setting, since it now affects every device.

What does not change

Nothing acts on the stored values yet — the switch and the numbers are stored and
reported. The three things the configuration drives arrive as follow-ups that read
it: session lifetime (idle window, presence, reclaim), the Lite model catalogue,
and the memory target with its reclaim policy. Normal-mode behaviour, session
reclaim, model loading and the systemd limits are all untouched by this PR, which
is why the memory target is stored here but not yet exposed in the UI.

Verified

node --experimental-strip-types --test lib/lite-config.test.mjs app/api/lite/route.test.mjs

15 tests pass: defaults for a missing/damaged/partially-written file, coercion of
anything that is not a stored configuration, whole-number ranges, merge-on-write
preserving fields Pi-Web does not own, a refused out-of-range write leaving the
file untouched, an unreadable file never overwritten, and the route side — read
creates nothing, a partial write keeps the other fields, invalid or empty bodies
and non-JSON content types are refused with the range in the message, and an
untrusted Host or cross-site request cannot change the configuration.
tsc --noEmit and eslint clean.

Lite mode is not a browser preference. What it changes — which model catalogue
gets loaded, how long an idle session is kept warm, how much memory the service
aims to stay under — are resources the server shares, so a per-device switch
meant two browsers on one Pi-Web disagreed about the same process.

Lite mode now lives in one Pi-Web-owned file, ~/.pi/agent/pi-web-settings.json
({version, lite: {enabled, idleMinutes, memoryTargetMiB}}), read and written by
the server and shared by every client. GET /api/lite reports the configuration
with the bounds each value is validated against; PUT changes it as a partial
update through the same request-security check every other mutating route uses.
General settings gains the Session lifetime section that edits it, and a client
that reads the shared value no longer keeps a copy of its own in localStorage.

The stored values are policy, so a missing, damaged or hand-edited file falls
back to the defaults instead of failing a read, and a file that cannot be parsed
is never overwritten. Nothing changes how the service behaves yet: the switch
and the numbers are stored and reported, and the session-lifetime, model and
memory work that acts on them arrives in the follow-ups.
@agegr

agegr commented Sep 30, 2026

Copy link
Copy Markdown
Owner

Thanks @HoloNova. Splitting #984 into reviewable pieces and writing down what was deliberately left out made this much easier to evaluate. After reading the series, though, I'm closing the Lite mode feature PRs (#999, #1000, #1002, #1004):

Focused fixes like #997 and #1003 are very welcome. Thanks again for the depth of the work here.


Generated by Claude Code

@agegr agegr closed this Sep 30, 2026
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.

2 participants