One-click Archive & Pending Archive
One-click Archive & Pending Archive
After "dev and tests are done, the review and the commit instruction are sent", tap the archive button in the composer toolbar, confirm, and close the page: the session is archived only after the run finishes normally plus a grace window — and if that run actually errored or was stopped, the deadline refuses to archive it, so an unnoticed error is never swept away.
1. Where it lives
Open any session: the control row under the composer (on phones, the bottom action area of the + panel) gains an archive button, placed right after the queue import/export button:
[compact] [stop] [sound] …extension buttons… [>_ command runtime] [⎇ timeline] [⬆ queue import] [🗃 archive]Desktop and mobile share one registration (composerTools slot), so behaviour is identical. It does not render on the welcome page (no session).
The session row carries a pending chip (sessionRowMeta slot): once armed, a small ⏱ pill appears after the message count in the sidebar (it shows the remaining minutes during the countdown). The countdown is server-side and keyed by session id — it does not depend on which session you have open: switch to another session or close the page and the archive still happens; the chip is how the armed session stays visible after you switch away.
2. Click semantics (same source as the sidebar archive)
Every click confirms first — there is no "tap and it happens" path:
| Session state | Confirmation | After confirming |
|---|---|---|
| Idle (pi session) | "Archive this session now? It moves into the archived group (restorable from there)." | archives now — the exact sidebar "archive directly" pipeline (archiveSessions → server runArchive), same guard, same .pwarc packaging, same failure copy |
| Running (pi session) | "Arm a pending archive? This session will be archived N minutes after the run finishes normally. Errors, stops or an unfinished run cancel it automatically." | arms a pending archive: the button turns into a clock state and the countdown starts when this run ends (3 minutes by default) |
| Pending | no confirmation (cancelling is safe) | cancels it |
| External-source session (zcode / cursor / claude …) | the menu is the confirmation | opens the sidebar's 📦 archive menu (remove from list / with children / true archive) — external agents run in another process, so there is no run terminal event to watch and no pending archive |
| Desktop right click | the menu is the confirmation | the full 📦 archive menu (resolved / unresolved / permanent delete …) |
Archiving the session you are looking at resets the view to a fresh composer in the same workspace (same as the "New session" button), so you never end up typing into an archived session.
3. Pending archive state machine
click while running ──confirm──► waiting for the run to end ──any outcome──► countdown (3 min default) ──► deadline verdict
│ │
└─ second click / manual archive ──────────► cancel / silent cleanup
│
deadline verdict ── still running ─────────────► back to waiting (re-arms on that run's end)
├─ file outcome = normal ─────► archived + "Session archived"
├─ file outcome = error ──────► **not archived** + "Run failed — not archived"
├─ file outcome = aborted ────► **not archived** + "Run stopped — not archived"
├─ file outcome = unfinished ► **not archived** + "Run did not finish — not archived"
└─ session gone ──────────────► not archived + "Session is gone"- Confirmation at click time, verdict at deadline time: the confirmation expresses "I want this archived"; "never archive an abnormal run" is the safety verdict at automatic execution, so a session whose error the user did not notice cannot be archived away. The two decisions never swap roles.
- Verdict source: at the deadline, the file-derived last run outcome (the last assistant
stopReason:stop/length= normal,error= failed,aborted= stopped, anything else = unfinished); the countdown itself is started by the server watchingagent_settled. - Three gates before archiving: the session is still indexed, its file-derived outcome is still "completed", and
runArchive's running guard lets it through. Otherwise nothing is archived; a still-running session goes back to waiting and re-arms on that run's end. - Configurable grace (extman): Extension manager → Session Manager → Features → Pending archive grace (minutes), default 3, fractions allowed. Changes apply immediately: the next countdown uses the new value and a countdown already running is restarted with it (no reload).
- Reliable: state lives in
state/pending-archive.json; extension reloads and process restarts resume it, and it keeps working with the page closed (server-side timers, no browser dependency). A dev/prod pair sharing the data dir is guarded by an atomic directory lock.
4. Notifications
- Archived: a toast "Session archived:
title". - Not archived at the deadline: the toast names the reason (run failed / stopped / did not finish / session gone / archive failed).
- Not lost when no page is open: events are persisted and replayed by sequence on the next page open (last 24 hours).
5. Edges and degradation
| Scenario | Behaviour |
|---|---|
| Session archived/deleted manually during the countdown | pending entry cleared silently (no double archive) |
| Another run during the countdown | re-arms when that run ends (judged by its outcome) |
| The run had already ended when you clicked | the deadline judges the file: normal → countdown → archived; failed/stopped → not archived, with a reason (never a silent archive at click time) |
| Extension reload / server restart | resumed from the state file; expired countdowns are verified immediately; "waiting" entries interrupted by a restart expire after 6 hours |
| Older host without event bus / toast service | state still comes from the API (button is correct); notifications fall back to replay on the next open |
| Switching sessions / closing the page | unaffected: the countdown is session-keyed on the server, archives on time, and never disturbs the view when the archived session is not the open one |
| The run ends in another process (no terminal event here) | waiting entries fall back to a probe (60 s, then 1/2/5 min backoff): once the session is no longer running the countdown starts and the deadline verdict still applies |
| External-source sessions | menu actions only, no pending archive |
6. Endpoints
| Method/path | Purpose |
|---|---|
GET pending-archive?since=seq | current pending list + events newer than since |
POST pending-archive/arm {sessionId, cwd?, title?} | arm (creates state only, never archives); running → wait for that run, idle → countdown from now |
POST pending-archive/cancel {sessionId} | cancel |
POST archive/run | the existing archive endpoint (sidebar source); clears pending entries for archived ids |
Event-bus topic: sm:pending-archive (full list + the triggering event).
7. See also
- Extension home: session-manager
.pwarcformat: .pwarc archive format