Skip to content

feat(studio): back the chat list with the daemon's session store - #615

Closed
jtenniswood wants to merge 3 commits into
feat/studio-enterprise-uifrom
feat/studio-session-persistence
Closed

jtenniswood wants to merge 3 commits into
feat/studio-enterprise-uifrom
feat/studio-session-persistence

Conversation

@jtenniswood

Copy link
Copy Markdown
Contributor

The problem

Studio kept every chat in one browser key, mecatl-studio-tasks (studio/app/page.tsx:375). mecated persisted the same sessions the whole time, and Studio called none of the endpoints that expose them — GET /v1/sessions, GET /v1/sessions/{id}/transcript, POST …/rename, POST …/delete.

Every symptom followed from that one gap:

  • another browser or machine saw nothing;
  • rename renamed a local label; reload from a different browser profile and the old title was back;
  • delete dropped Studio's copy and left the session in the store for ever — the daemon has no client-driven GC, so "delete" quietly meant "hide";
  • a reload during a run orphaned it, and the notice claimed the task "was interrupted" when the daemon had very likely finished it.

The persistence was never missing. It was unused.

What this does

The daemon's session store is now the record of which chats exist, what each is called, and what was said in each.

Action Before After
Chat list localStorage only bounded walk of GET /v1/sessions, merged on connect and on a 20s poll
Rename local label POST …/rename, optimistic, rolled back on refusal, adopts the title the daemon stored
Delete local hide POST …/delete — snapshot and sidecars removed; a refusal keeps the row
Open a chat local messages GET …/transcript when the row has no cached history, or when the daemon reports it advanced elsewhere
Rename/delete availability always offered driven by each row's capabilities + its closed reason code

Two continuity fixes fall out of the same work:

  • A failed turn no longer discards the session id. Only a 404 does. Previously any error cleared it, so the next prompt silently opened a fresh, context-free session; now the chat continues, because mecated recovers a completed/cancelled/failed session at its run entry.
  • A reload does not claim the run stopped. The chat is marked as still working on the daemon, and its transcript is read back once the run ends.

Design notes that carry their reasoning in the code:

  • A row is dropped only once it has been observed present in a COMPLETE inventory walk and then absent. Absence is proof of deletion only for something previously proven to exist — otherwise a session created seconds ago gets pruned as though someone deleted it.
  • Eligibility is the daemon's. Studio renders the reason (active_elsewhere, awaiting_approval, storage_unsupported, …); it does not re-derive who may rename or delete what.
  • Detached sessions are remembered. Changing provider/router/gateway config restarts mecated and detaches chats from their sessions, but those sessions still exist — remembering the retired ids stops them reappearing as duplicate chats.
  • localStorage stays as a cache and as the home for unsent drafts, which exist nowhere else.

Verification

Built bin/mecated, ran it offline (--mock, --store-dir), and drove Studio in external mode against it:

  • rename → daemon reports title_provenance: operator and the new title;
  • a 200-character title comes back clamped to 121 — hence adopting the server's echo rather than the requested string;
  • delete → 204, gone from GET /v1/sessions, and both .session.jsonl and .events.jsonl removed from disk; a second delete is 204 (idempotent);
  • prompting a deleted session → 404, which is exactly the one path that detaches a chat;
  • clearing localStorage entirely and reloading brought the list back from the daemon with the rename applied and the deleted chat still gone;
  • a chat deleted from outside the UI disappeared from the open page on the next poll, without a reload.

Gates: npm run typecheck, npm run lint, npm test (14/14) all clean; task docs clean (0 broken links, 0 orphans, 0 unreachable). No Go code changed.

Known gaps, stated rather than hidden

  • Reattaching to a LIVE run is still not possible. Studio can see a run is in flight and read the transcript once it ends, but cannot resume the stream. GET /v1/sessions/{id}/events is a finite replay of the durable log, and the live per-session subscription (Service.Subscribe) is reachable only over gRPC StreamSessionLive, which the ordinary run relay does not publish to. Closing that is a daemon change, not a client one.
  • A rehydrated transcript is not identical to the live one. The transcript endpoint returns the model's conversation, which includes the harness's own synthetic continuations (the no-progress nudge, background-completion notices) as user-role messages with no provenance. Reopening a chat therefore shows text the operator never typed. The fix is a provenance field on ConversationMessage, not string-sniffing in the client.
  • The list reorders on rename, because a rename is a write and the daemon's mtime is the only ordering every client can agree on. Studio previously pinned a renamed row in place; pinning locally would now just disagree with the next browser to open.

Notes for review

  • Based on feat/studio-enterprise-ui, so review the diff against that branch rather than main.
  • ADR: docs/adr/0227-studio-server-backed-chats.md. studio/CLAUDE.md gains four invariants; user-docs/what-you-get/studio.md gains two sections.
  • Several sibling Studio branches are in flight (event rendering, markdown/diff rendering, schedules authoring, plan-mode approval). Ownership was agreed with them: this branch owns the session state and the /v1/sessions call sites; the conversation render block and lib/transcript.ts belong to the others. Expect small, additive merges in app/page.tsx, lib/protocol.ts, and the test file. Once lib/transcript.ts lands, transcriptToMessages should move there and get its own test.

🤖 Generated with Claude Code

jtenniswood and others added 2 commits August 18, 2026 09:15
Studio kept every chat in one browser key, `mecatl-studio-tasks`, while
mecated persisted the same sessions the whole time. The endpoints were
already there and Studio called none of them, so a second browser saw
nothing, "rename" renamed a local label that the next reload discarded,
and "delete" hid a session that stayed in the store for ever.

The daemon's store is now the record of which chats exist, what each is
called, and what was said in each:

- the chat list is a bounded walk of GET /v1/sessions, merged on connect
  and on a slow poll, so a change made in another client shows up here
- rename is POST /v1/sessions/{id}/rename, optimistic and rolled back if
  the daemon refuses, adopting the title it actually stored (it clamps)
- delete is POST /v1/sessions/{id}/delete; a refusal keeps the row,
  because hiding a chat that still exists is the bug being fixed
- opening a chat reads GET /v1/sessions/{id}/transcript
- rename/delete eligibility comes from each row's `capabilities` and its
  closed reason code, rather than the client re-deriving server policy

A row is dropped only once it has been observed present in a COMPLETE
walk and then absent, so a session created seconds ago is never pruned
as though someone had deleted it.

Two continuity fixes fall out. A failed turn no longer throws away the
session id — only a 404 does — so the next prompt continues the same
chat instead of silently starting a fresh, context-free one. And a
reload during a run no longer claims the task "was interrupted": the
chat is marked as still working on the daemon and its transcript is read
back when the run ends.

localStorage stays as a cache and as the home for unsent drafts.

Verified against a real offline mecated: rename and delete persist, a
chat deleted from another client disappears here without a reload, and
the list survives clearing browser storage entirely.

Co-Authored-By: Claude Opus 5 <[email protected]>
The panel called itself the oversight surface for scheduled tasks but
covered only half the daemon's API: list, pause, resume, fire, delete. A
schedule had to be created outside the UI, could not be changed once
armed, and its past fires were invisible — so the one place an operator
looks to understand unattended work could not tell them what it had done.

It now covers the rest of the surface:

- Create (POST /v1/schedules) and edit (PUT /v1/schedules/{name}) through
  one form. The name is fixed on an edit because a schedule is addressed
  by name — renaming would arm a second one and drop the firing history.
- Fire history per schedule (GET …/fires), newest first, with each fire's
  stop reason, its error when it failed, and the sched-- session it ran
  as. An in-flight fire re-reads on its own (GET …/fires/{id}) rather
  than refetching the log.

Two rules the UI has to respect, both now documented in studio/CLAUDE.md
and pinned by tests:

- An update REPLACES the spec, so any field the form omits is DELETED.
  ScheduleRow.carried carries the settings this form has no control for
  (provider selector, misfire policy, singleton, carried context, per-fire
  deadline, multimodal parts) and encodeScheduleSpec puts them back.
- A request body is not a response body: requests decode with protojson,
  responses encode with stdlib encoding/json, and the two disagree on
  every well-known type (Timestamp, Duration). The encoder is that
  conversion, which is why the edit path decodes to a view model first.

The mutating/mode pair is coupled in the form because the daemon rejects a
non-mutating schedule with a write-capable posture, so an invalid pair is
not constructible rather than being caught by a 400. Everything else the
create-seam enforces — cron grammar, the cadence floor, the selector
inventory, name collisions — is surfaced verbatim rather than re-guessed.

Verified against a real offline mecated (--mock, --store-dir): an
out-of-band schedule carrying a misfire policy, carried context, a 900s
fire timeout and per-fire limits survives a prompt-only edit from the UI
with its firing state intact, and both trigger arms create, fire, and
render their log.

Co-Authored-By: Claude Opus 5 <[email protected]>
Brings feat/studio-schedule-authoring (create, edit, and fire history for
the Schedules panel) onto the server-backed chat list, at the repository
owner's direction, so both land as one change.

Five files needed a hand resolution — the two branches append to the same
regions of studio/lib/protocol.ts, studio/app/page.tsx and
studio/tests/rendered-html.test.mjs, and both edit the lib/protocol.ts
Shape bullet in studio/CLAUDE.md and add a section at the same anchor in
user-docs/what-you-get/studio.md. Notes on the three that are not a plain
union:

- the import lists in page.tsx and the test file both name
  decodeScheduleRows and parseMecatlEvent, so keeping both sides
  duplicates the specifier and tsc fails;
- the test-file conflict boundary cuts through the last schedule test,
  leaving its closing brace after the appended session tests — a plain
  union yields "SyntaxError: Unexpected end of input";
- the CLAUDE.md bullet now names the chat inventory and transcript
  envelopes AND the schedule-spec encoder and fire-log decoder, because
  picking either side understates what protocol.ts holds.

Verified on the merged tree: studio test suite 17/17 (8 schedules + 9
session inventory/transcript), ESLint, and tsc all clean.

Co-Authored-By: Claude Opus 5 <[email protected]>
@jtenniswood

Copy link
Copy Markdown
Contributor Author

Added the Schedules panel work (previously PR #616, now closed) to this branch at the repository owner's direction, so both Studio changes land together. This PR now covers two things: the server-backed chat list, and the Schedules panel gaining create, edit, and fire history.

What the schedules half does: the panel could only list, pause, resume, fire, and delete, so a schedule had to be created outside the UI, could not be changed once armed, and its past fires were invisible. It now covers POST /v1/schedules, PUT /v1/schedules/{name}, GET …/fires, and GET …/fires/{id}.

Two invariants it adds to studio/CLAUDE.md, both pinned by tests: an update REPLACES the spec, so ScheduleRow.carried round-trips the fields the form has no control for (provider selector, misfire policy, singleton, carried context, per-fire deadline, parts) or a prompt edit would delete them; and a request body is not a response body — requests decode with protojson, responses encode with stdlib encoding/json, and they disagree on Timestamp and Duration, which is what encodeScheduleSpec exists to convert.

The merge needed a hand resolution in five files. Three points worth knowing if this is ever re-done: the import lists in page.tsx and the test file both name decodeScheduleRows and parseMecatlEvent, so keeping both sides duplicates the specifier and tsc fails; the test-file conflict boundary cuts through the last schedules test, leaving its closing brace after the appended session tests, which surfaces as SyntaxError: Unexpected end of input rather than as a merge problem; and the lib/protocol.ts Shape bullet in studio/CLAUDE.md was rewritten by both sides, so it now names the chat inventory and the schedule encoder rather than either alone.

Verified on the merged tree: studio suite 17/17 (9 session inventory/transcript + 8 schedules), ESLint, tsc, matlatl check --strict, and task site:build all clean. The schedules half was also driven against a real offline mecated through the browser UI — an out-of-band schedule carrying a misfire policy, carried context, a 900s fire timeout and per-fire limits survived a prompt-only edit with its firing state and every unexposed field intact.

Reviewers: the two halves are separate commits (a6057a34 and af4d9df8) if you would rather read them one at a time.

🤖 Generated with Claude Code

@jtenniswood
jtenniswood deleted the feat/studio-session-persistence branch August 18, 2026 09:35
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.

1 participant