Skip to content

feat(studio): keep the Studio history server-side per user - #12991

Open
coffeerunhobby wants to merge 10 commits into
mudler:masterfrom
coffeerunhobby:feat/studio-history
Open

coffeerunhobby wants to merge 10 commits into
mudler:masterfrom
coffeerunhobby:feat/studio-history

Conversation

@coffeerunhobby

Copy link
Copy Markdown
Contributor

Description

The Studio keeps the record of every generation (prompt, model, parameters, result URLs, lineage) in
localStorage only. The files are on the server, but the history is lost with a cleared browser, does not
follow the user to another device, and is invisible to a second browser of the same account.

This PR persists it per user on the server, the way chat history already is (#12663):

  • Store (core/services/studiohistory): a GORM table studio_history_entries in the shared auth
    database, keyed by (user_id, entry_id). The Studio's record is stored opaquely, with a server-assigned
    version, tombstones so a deletion reaches every browser, a cap of 1000 entries per type (the oldest become
    tombstones) and an import that never deletes. Specs run on SQLite and PostgreSQL.
  • API (/api/studio/history): list (with tombstones and an opaque per-account cacheKey), get, upsert,
    delete, clear per type, and import. Registered when auth is on and the WebUI enabled, behind a new
    studio_history feature that is on by default like chat_history. Without auth, only the list is
    registered and answers 200 {"enabled": false}: a 404 would be logged by the browser as an error on every
    Studio load.
  • Studio add-on: probes the list once per load and, when the server keeps the history, merges with the
    same rules as the chat page, uploads new results and sends deletes. Add-ons are not told who is signed in,
    so the browser cache is kept per account under the cacheKey.

Shared browsers and offline

  • The entries kept under the old plain keys are imported once, into the first account that signs in on that
    browser, and then removed from the plain keys, so a second account never receives them.
  • A browser that has held an account's history shows and keeps nothing while the server cannot say whose it
    is (signed out, permission revoked, offline), so one person never sees another's prompts.
  • Deletes are queued by id while offline and sent on the next sync, which fetches the list again before
    merging. A Clear that fails is queued as the ids it removed, never as "delete the workspace", so a replay
    cannot delete results made on another device in between.

Notes for Reviewers

  • Without auth nothing changes for the user: the Studio keeps using localStorage.
  • Favourites and 3D stay in the browser for now. A 3D entry holds the GLB itself and its input thumbnail as
    IndexedDB blobs, not URLs, so syncing only its record would show it elsewhere without the model. The
    server already accepts threed entries for when the 3D page keeps its models as files.
  • Docs: docs/content/features/studio-history.md (new), studio.md, api-discovery.md. Swagger
    regenerated with swag v1.16.6 (additions only).

Tests

  • go test -tags auth ./core/services/studiohistory/ (store specs, SQLite and PostgreSQL)
  • go test -tags auth ./core/http/routes/ -run '^TestRoutes$' -args -ginkgo.focus="Studio history endpoints" (16 specs: auth, per-user isolation, the feature gate, no store)
  • cd addons/studio/ui && npm test (merge rules, legacy import, delete queue)
  • Playwright e2e/studio-history-sync.spec.js (7 tests: save and another browser, delete and reload, Clear,
    two accounts on one browser, a refused server, the one-time import, no accounts against the real route
    with no console error), plus every existing studio-* and media-history spec: 174/174.
  • Also tested live on a LocalAI with accounts (API and Studio GUI: install, save, delete across windows).

Signed commits

  • Yes, I signed my commits.
  • Documentation updated (docs/content/) for user-facing changes, or not applicable

coffeerunhobby added 3 commits October 31, 2026 09:46
The Studio keeps the record of every generation (prompt, model, params,
result URLs, lineage) in localStorage only. The files are on the server,
but the history is lost with a cleared browser, does not follow the user
to another device, and never shows results made through the API.

Persist it the way chat history is persisted (mudler#12663):

- core/services/studiohistory: a GORM table studio_history_entries in the
  shared auth database, keyed by (user_id, entry_id), with the Studio's
  record stored opaquely, a server-assigned version, tombstones so a
  deletion reaches every browser, a cap of 1000 entries per type (the
  oldest become tombstones) and an import that never deletes.
- /api/studio/history: list (with tombstones and an opaque per-account
  cacheKey), get, upsert, delete, clear per type, and import. Registered
  only when auth is on and the WebUI enabled; gated by a new
  studio_history feature, on by default like chat_history.
- Studio add-on: probe the server once per load and, when it answers,
  merge with the same rules as the chat page, upload new results and send
  deletes. The browser cache is kept per account under the cacheKey,
  since add-ons are not told who is signed in.
- Shared browsers: the entries kept under the old plain keys are imported
  once, into the first account that signs in, and then removed from the
  plain keys. A browser that has held an account's history shows and
  keeps nothing while the server cannot say whose it is (an error other
  than 404), so one account never sees another's prompts.
- Offline: deletes are queued by id and sent on the next sync, which
  fetches the list again before merging, so a deleted entry does not come
  back. A Clear that fails is queued as the ids it removed, never as
  "delete the workspace", so a replay cannot delete results made on
  another device in between.

Without auth nothing changes for the user: the list answers 200 with
enabled: false (a 404 would be logged as an error by the browser on every
Studio load) and the Studio keeps using localStorage. Favourites and 3D
(IndexedDB) stay in the browser for now; the server already accepts
threed entries.

Docs: features/studio-history. Tests: store specs on SQLite and
PostgreSQL, route and auth specs, Studio unit tests for the merge, the
legacy import and the delete queue, and a Playwright spec
(e2e/studio-history-sync.spec.js) that drives the Studio bundle against a
stand-in server: save, delete, Clear, two accounts on one browser, a
refused server, the one-time import, and no accounts (against the real
route, with no console error).

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: coffeerunhobby <294crhwtf@mozmail.com>
master replaced the WebUI chat history (core/services/chathistory,
/api/conversations, the chat_history feature) with server-side chats
(mudler#12918). Studio history keeps its own store, routes and the
studio_history feature, now next to FeatureChats instead of
FeatureChatHistory. The comments and the docs page no longer point at
the removed chat history, and the docs link to the deleted
features/chat-history page is gone.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: coffeerunhobby <294crhwtf@mozmail.com>
useMediaHistory put back every entry made on the page that the synced
cache lacked, for as long as the page lived: one deleted on another
device came back on the next sync, and entries made under one account
were carried into the next verified account's cache.

Entries now count as pending only until saveRemote answers (an answer of
"deleted elsewhere" also removes the entry). A sync never restores an id
it saw deleted (deletedInLastSync), and nothing is kept when the cache
key moves to another account. The rule is a pure function, keepPending,
covered by the sync tests.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: coffeerunhobby <294crhwtf@mozmail.com>
@coffeerunhobby

Copy link
Copy Markdown
Contributor Author

Addressed in 948e98e: entries stay pending only until the server confirms them, tombstones from a sync are never restored, and nothing carries over when the account changes; two new tests cover the reviewer's scenario.

coffeerunhobby added 7 commits November 3, 2026 11:32
One conflict, in core/application/application.go: master reworded the
studioFilesIndex comment and this branch added studioHistoryStore to the
same struct block. Both kept.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: coffeerunhobby <294crhwtf@mozmail.com>
…studio-history

# Conflicts:
#	core/application/application.go
The three swagger files conflicted because both sides added paths and
definitions. They are regenerated with swag v1.16.6 and hold master's
output plus the Studio history routes and schemas, with nothing else
changed.

Master raised the instruction count to 32 and this branch adds
studio-history, so the instructions spec now expects 33.
Master's docs reorganisation (mudler#13178) moved the Studio, authentication
and API discovery pages. The Studio History page moves next to Studio,
under addons/catalogue/models-and-media, without a url field; its links
use the new paths and its URL is added to docs/redirects.txt, as the
docs README asks for a new page.

The swagger files merged cleanly and equal master's output plus the
Studio history routes and schemas.
master added the remotes routes (mudler#13235) at the end of
core/http/routes/localai.go, where this branch adds
RegisterStudioHistoryRoutes. Both functions are kept.

master also added the remotes API instruction, so there are now 34
instructions; the count in api_instructions_test.go is raised from 33.
Signed-off-by: coffeerunhobby <294crhwtf@mozmail.com>
# Conflicts:
#	core/http/endpoints/localai/api_instructions_test.go
@coffeerunhobby
coffeerunhobby force-pushed the feat/studio-history branch 2 times, most recently from e7c7ed7 to c7024da Compare November 21, 2026 16:49
{"POST", "/api/pii/redact", FeaturePIIFilter},

// Studio History (server-side persistence of the Studio's generations)
{"GET", "/api/studio/history", FeatureStudioHistory},

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure how do I feel about this. What I'd do instead of having this in the core, is the addon to actually store the data ( in the addon storage ) per-user/generation.

This branch has not been deployed

No deployments
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