Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

docs: document that self-update checks out main and stashes local changes (#3913)

[._.]/ Adam Eivy8aebf3577979
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index 4f8902ecf4..bf3fa2062a 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -63,3 +63,4 @@
- Leaving the SongBook editor with unsaved edits now asks first. The editor holds every change — sheet text, practice notes, metadata — in an in-memory draft until an explicit Save, so clicking View, following the "All songs" link, or closing the tab dropped the work silently. The page now compares the draft against the saved song (numerically for capo, since the number input hands back a string and retyping the stored value would otherwise read as an edit) and defers those exits behind an inline "Discard your unsaved changes?" band under the header, with Discard resetting the draft and Keep editing leaving it intact; a tab close or reload arms the browser's own prompt. Saving clears an armed confirm, since the draft is no longer dirty.
- `client/src/utils/cityChronotype.js` now exports only `computeChronotypeEnergy`. Its six internal pieces — the two range constants, the neutral-modifier sentinel, and the `parseHour` / `computeEnergy` / `energyModifiers` steps — were exported purely so the unit tests could reach them, but the utils barrel re-exports every module flat, so generic names like `parseHour` and `computeEnergy` sat in the shared namespace waiting to collide with a future module. The tests now drive every one of those behaviors through the public entry point (an unparseable or out-of-range peak window yields the neutral no-op; the `:30` half-hour still lands the peak center at 11.25), plus one assertion that the module's export list stays a single name.
- An AI generate or refine started in the Story Builder now survives clicking another step on the left rail. The step panel is keyed by the active step, so navigating away unmounted it — which tore down the SSE progress stream and threw away the completion handlers, leaving the run to finish on the server with no phase updates, no success or failure toast, and a stale view until a manual refresh. Each run's stream, phase and handlers now live in a provider mounted above the rail (`client/src/hooks/useStoryStepRuns.jsx`), one slot per step id, so runs on different steps can be in flight at once and the panel picks its own run back up — including which character a refine targets — when the user navigates back to it.
+- `docs/SELF_UPDATE.md` now documents that `update.sh` / `update.ps1` check out `main` before pulling, stashing a dirty working tree first so the checkout can proceed. The doc described only the `git pull --rebase --autostash`, so anyone running an in-app or CLI update from a feature branch or a detached HEAD was surprised to find their checkout moved to `main` with their work parked in `git stash` — the scripts print the restore commands on completion, but nothing said so up front.
diff --git a/docs/SELF_UPDATE.md b/docs/SELF_UPDATE.md
index 517b225283..73844ca0bb 100644
--- a/docs/SELF_UPDATE.md
+++ b/docs/SELF_UPDATE.md
@@ -18,6 +18,21 @@ The release-notification poll **always queries the upstream `atomantic/PortOS`**
`update.sh` / `update.ps1` always `git pull --rebase --autostash` from **origin**. A fork user who has not merged upstream into their fork gets a silent no-op pull.
+### The update always lands on `main` first
+
+Before pulling, both scripts check the current branch and **switch to `main` if you are anywhere else** — a feature branch or a detached HEAD. This is deliberate: the rest of the script (install, build, restart) has to run on the revision the app will boot from, and pulling on a feature branch would leave the running app on a version the update never advanced.
+
+If the working tree is dirty at that point (unstaged, staged, or untracked files), the scripts **`git stash push -u`** first so the checkout can proceed, tagging the entry `portos-update-<timestamp>`. The stash is intentionally **not** popped afterwards — the remaining steps need `main`'s contents on disk. On completion the scripts print how to get back:
+
+```bash
+git checkout <your-branch> # or the recorded SHA, if you were on a detached HEAD
+git stash pop
+```
+
+The entry is at the top of `git stash list`. Nothing is stashed when the tree is clean, and nothing is checked out when you were already on `main`.
+
+**So: an in-app or CLI update run from a feature branch will leave your checkout on `main` with your work parked in the stash.** Commit or push before updating if you would rather not deal with that.
+
To prevent that confusion, `POST /api/update/execute` rejects fork runs with **412 `FORK_SYNC_REQUIRED`** unless either:
- the request body sets `acknowledgeFork: true`, or