Skip to content

Commit b280b94

Browse files
authored
feat(upgrade): ship qualified runtimes with resumable, observable updates (#7656)
* feat(upgrade): preserve owners and qualify resumable prebuilt updates Signed-off-by: huangruiteng <huangrt01@163.com> * fix(upgrade): qualify packaged assets and preserve activation readback Signed-off-by: huangruiteng <huangrt01@163.com> * test(upgrade): retire disposable runtimes before cleanup Signed-off-by: huangruiteng <huangrt01@163.com> * fix(upgrade): retain the original Windows console update guard Signed-off-by: huangruiteng <huangrt01@163.com> * test(upgrade): verify installed Chat delivery over HTTP Signed-off-by: huangruiteng <huangrt01@163.com> * fix(upgrade): bind metadata to the qualified runtime and retain TLS Signed-off-by: huangruiteng <huangrt01@163.com> * fix(packaging): retain license notices in runtime snapshots Signed-off-by: huangruiteng <huangrt01@163.com> * fix(release): keep main runtimes outside product release history Signed-off-by: huangruiteng <huangrt01@163.com> --------- Signed-off-by: huangruiteng <huangrt01@163.com>
1 parent 17cda56 commit b280b94

28 files changed

Lines changed: 1944 additions & 71 deletions

‎.github/workflows/frontstage-pages.yml‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ on:
4848
- "scripts/render-star-history.py"
4949
- "scripts/fetch-github-stargazers.sh"
5050
- "scripts/install-from-github.sh"
51+
- "loopx/cli_commands/update_artifact.py"
5152
push:
5253
branches:
5354
- main
@@ -91,6 +92,7 @@ on:
9192
- "scripts/render-star-history.py"
9293
- "scripts/fetch-github-stargazers.sh"
9394
- "scripts/install-from-github.sh"
95+
- "loopx/cli_commands/update_artifact.py"
9496

9597
permissions:
9698
actions: read
@@ -193,6 +195,14 @@ jobs:
193195
LOOPX_SITE_RESOLVE_DESKTOP_RELEASE: "1"
194196
run: npm run export:frontstage-share -- --base /loopx/ --out-dir ../../../output/frontstage-pages
195197

198+
- name: Require stable runtime before publishing its bootstrap
199+
if: github.event_name != 'pull_request'
200+
run: |
201+
python - <<'PY'
202+
from loopx.cli_commands.update_artifact import resolve_artifact
203+
resolve_artifact("loopx-project/loopx", "stable")
204+
PY
205+
196206
- name: Fetch complete GitHub stargazer history
197207
if: github.event_name != 'pull_request'
198208
env:

‎.github/workflows/release-artifacts.yml‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ on:
1616
- "scripts/verify_installed_chat.py"
1717
- "README.md"
1818
- "scripts/release_artifacts.py"
19+
- "scripts/runtime_artifact.py"
20+
- "scripts/qualify_runtime_artifact.py"
1921
- "tsconfig.control-plane.json"
2022
release:
2123
types: [published]
@@ -390,6 +392,11 @@ jobs:
390392
identity.write_text(json.dumps(record, indent=2) + "\n")
391393
PY
392394
395+
- name: Build and qualify the stable snapshot runtime
396+
run: |
397+
python scripts/runtime_artifact.py --channel stable
398+
python scripts/qualify_runtime_artifact.py dist/runtime > dist/runtime/qualification.json
399+
393400
- name: Attest release packages and checksum manifest
394401
if: github.event_name != 'pull_request'
395402
uses: actions/attest@v4
@@ -398,6 +405,7 @@ jobs:
398405
dist/packages/*
399406
dist/SHA256SUMS
400407
dist/RELEASE-SOURCES.json
408+
dist/runtime/*
401409
402410
- name: Upload validated release bundle
403411
uses: actions/upload-artifact@v7
@@ -443,6 +451,7 @@ jobs:
443451
dist/packages/* \
444452
dist/SHA256SUMS \
445453
dist/RELEASE-SOURCES.json \
454+
dist/runtime/* \
446455
--repo "${GITHUB_REPOSITORY}"
447456
448457
publish-pypi:
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
name: Runtime snapshots
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
paths:
8+
- ".github/workflows/runtime-snapshots.yml"
9+
- "scripts/runtime_artifact.py"
10+
- "scripts/qualify_runtime_artifact.py"
11+
- "scripts/install*.sh"
12+
- "loopx/cli_commands/update*.py"
13+
- "loopx/cli_commands/support_control_update*.py"
14+
- "loopx/self_update*.py"
15+
workflow_dispatch:
16+
17+
permissions:
18+
contents: read
19+
20+
concurrency:
21+
group: runtime-snapshot-${{ github.event_name == 'pull_request' && github.ref || 'main' }}
22+
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
23+
24+
jobs:
25+
build:
26+
if: github.repository == 'loopx-project/loopx'
27+
runs-on: ubuntu-latest
28+
timeout-minutes: 20
29+
permissions:
30+
contents: read
31+
id-token: write
32+
attestations: write
33+
steps:
34+
- uses: actions/checkout@v7
35+
with:
36+
fetch-depth: 0
37+
- uses: actions/setup-python@v6
38+
with:
39+
python-version: "3.11"
40+
- uses: actions/setup-node@v6
41+
with:
42+
node-version: "24"
43+
- name: Prepare test environment
44+
run: python -m pip install -e '.[test]'
45+
- name: Qualify update transport and ownership
46+
run: python -m pytest -q tests/test_update_artifact.py tests/test_update_operation.py tests/test_self_update_runtime_activation.py tests/test_archive_installer_commit_response.py
47+
- name: Build qualified frontend
48+
run: python scripts/chat_bundle.py ensure
49+
- name: Build immutable runtime and resource inventory
50+
run: python scripts/runtime_artifact.py --channel main
51+
- name: Qualify clean installation and upgrade
52+
run: python scripts/qualify_runtime_artifact.py dist/runtime > dist/runtime/qualification.json
53+
- name: Freeze revision-addressed metadata
54+
shell: bash
55+
run: |
56+
set -euo pipefail
57+
revision="$(python -c 'import json; print(json.load(open("dist/runtime/loopx-runtime.json"))["source_revision"])')"
58+
cp dist/runtime/loopx-runtime.json "dist/runtime/loopx-runtime-${revision}.json"
59+
mv dist/runtime/runtime-inventory.json "dist/runtime/runtime-inventory-${revision}.json"
60+
mv dist/runtime/qualification.json "dist/runtime/qualification-${revision}.json"
61+
- name: Attest exact runtime bytes and inventory
62+
if: github.event_name != 'pull_request'
63+
uses: actions/attest@v4
64+
with:
65+
subject-path: dist/runtime/*
66+
- uses: actions/upload-artifact@v7
67+
with:
68+
name: loopx-runtime
69+
path: dist/runtime
70+
if-no-files-found: error
71+
72+
publish:
73+
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main'
74+
needs: build
75+
runs-on: ubuntu-latest
76+
timeout-minutes: 10
77+
permissions:
78+
contents: write
79+
steps:
80+
- uses: actions/download-artifact@v7
81+
with:
82+
name: loopx-runtime
83+
path: runtime
84+
- name: Publish immutable snapshot then channel pointer
85+
env:
86+
GH_TOKEN: ${{ github.token }}
87+
shell: bash
88+
run: |
89+
set -euo pipefail
90+
revision="$(python -c 'import json; print(json.load(open("runtime/loopx-runtime.json"))["source_revision"])')"
91+
# One dedicated channel release keeps developer snapshots out of
92+
# product release history and bounded stable-predecessor discovery.
93+
tag=runtime-main
94+
if ! gh release view "$tag" --repo "$GITHUB_REPOSITORY" >/dev/null 2>&1; then
95+
gh release create "$tag" --repo "$GITHUB_REPOSITORY" --target "$revision" --prerelease --title "Latest qualified main runtime" --notes "Mutable channel metadata; revision-addressed archives and manifests are immutable. Stable users continue with PyPI or the stable runtime."
96+
fi
97+
# A retry reuses immutable bytes. Never clobber an immutable asset.
98+
mkdir -p existing
99+
for file in runtime/*; do
100+
name="$(basename "$file")"
101+
if [[ "$name" == loopx-runtime.json ]]; then continue; fi
102+
if gh release download "$tag" --repo "$GITHUB_REPOSITORY" --pattern "$name" --dir existing >/dev/null 2>&1; then
103+
cmp "$file" "existing/$name"
104+
else
105+
gh release upload "$tag" "$file" --repo "$GITHUB_REPOSITORY"
106+
fi
107+
done
108+
# Publication is serialized. A qualified ancestor is usable while a
109+
# newer main is still building; never publish a non-main revision.
110+
relation="$(gh api "repos/${GITHUB_REPOSITORY}/compare/${revision}...main" --jq .status)"
111+
if [[ "$relation" != ahead && "$relation" != identical ]]; then exit 1; fi
112+
# Rerunning an older successful workflow may retain its immutable
113+
# assets, but must not move the qualified main channel backwards.
114+
current="$(gh api "repos/${GITHUB_REPOSITORY}/commits/runtime-main" --jq .sha)"
115+
promotion="$(gh api "repos/${GITHUB_REPOSITORY}/compare/${current}...${revision}" --jq .status)"
116+
if [[ "$promotion" == behind ]]; then exit 0; fi
117+
if [[ "$promotion" != ahead && "$promotion" != identical ]]; then exit 1; fi
118+
gh api --method PATCH "repos/${GITHUB_REPOSITORY}/git/refs/tags/runtime-main" -f sha="$revision" -F force=false >/dev/null
119+
gh release upload runtime-main runtime/loopx-runtime.json --repo "$GITHUB_REPOSITORY" --clobber

‎apps/presentation/dashboard/src/features/personal-workspace/desktop-update.tsx‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { ChevronUp, Download, RefreshCw, X } from "lucide-react";
22
import { useEffect, useRef, useState } from "react";
33
import { useWorkspaceI18n } from "./i18n";
4+
import { observeTransfer, transferText, type TransferSample } from "./update-progress";
45

56
type Phase = "idle" | "runtime_required" | "runtime_pairing_required" | "connecting" | "service_error" | "checking" | "available" | "up_to_date" | "downloading" | "installing_app" | "installing_runtime" | "restart_required" | "ready" | "error";
67
type UpdateState = { phase: Phase; details?: { version?: string; channel?: string; received?: number; total?: number; code?: string; background?: boolean; prepared?: boolean } };
@@ -45,6 +46,8 @@ export function DesktopUpdate() {
4546
const [rollbackAvailable, setRollbackAvailable] = useState(false);
4647
const [runtimeSelection, setRuntimeSelection] = useState<RuntimeSelection>();
4748
const busy = useRef(false);
49+
const [transfer, setTransfer] = useState<TransferSample | null>(null);
50+
const [now, setNow] = useState(Date.now);
4851
const statusGeneration = useRef(0);
4952
const selectedChannel = useRef<string | null>(null);
5053
const invoke = (window as DesktopWindow).__TAURI__?.core.invoke;
@@ -53,6 +56,15 @@ export function DesktopUpdate() {
5356
const repairAvailable = runtimeSelection?.explicit !== true && runtimeSelection?.bundled_repair_available !== false;
5457
const restoreInPlace = state.phase === "error" && state.details?.code === "app_install_incomplete" && rollbackAvailable;
5558

59+
useEffect(() => {
60+
setTransfer((previous) => observeTransfer(previous, state.phase, state.details?.received, Date.now()));
61+
}, [state.phase, state.details?.received]);
62+
useEffect(() => {
63+
if (!observing) return;
64+
const timer = window.setInterval(() => setNow(Date.now()), 1000);
65+
return () => window.clearInterval(timer);
66+
}, [observing]);
67+
5668
function readStatus(value: UpdateStatus, includeState = true) {
5769
setVersion(value.app_version);
5870
setPlatform(value.platform ?? "");
@@ -195,6 +207,7 @@ export function DesktopUpdate() {
195207
{state.details?.version ? <p>{zh ? "目标版本:" : "Target: "}{state.details.version}</p> : null}
196208
<p role="status" aria-live="polite">{observing ? <RefreshCw className="is-spinning" size={14} aria-hidden="true" /> : null}{message[state.phase]}</p>
197209
{state.phase === "downloading" && state.details?.total ? <progress aria-label={zh ? "下载进度" : "Download progress"} max={state.details.total} value={state.details.received ?? 0} /> : null}
210+
{state.phase === "downloading" && transfer ? <p className="personal-update-transfer" role="status">{transferText(transfer, state.details?.total, now, zh)}</p> : null}
198211
{invoke ? <div className="personal-update-actions">
199212
{state.phase === "restart_required" ? <button type="button" onClick={() => void run("restart")}>{zh ? "重启完成更新" : "Restart to finish"}</button> : <>
200213
{restoreInPlace ? <button type="button" onClick={() => void run("rollback")}>{zh ? "恢复上个版本" : "Restore previous version"}</button> : null}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Presentation-only observations. The updater remains the authority for bytes,
2+
// phase and outcome; missing totals never become a fabricated percentage.
3+
export type TransferSample = {
4+
phase: string; received: number | null; startedAt: number; changedAt: number;
5+
sampledAt: number; bytesPerSecond: number | null;
6+
};
7+
8+
export function observeTransfer(previous: TransferSample | null, phase: string, bytes: number | undefined, now: number): TransferSample {
9+
const received = typeof bytes === "number" && Number.isFinite(bytes) && bytes >= 0 ? bytes : null;
10+
if (!previous || previous.phase !== phase || (received !== null && previous.received !== null && received < previous.received)) {
11+
return { phase, received, startedAt: now, changedAt: now, sampledAt: now, bytesPerSecond: null };
12+
}
13+
if (received === previous.received) return previous;
14+
const elapsed = (now - previous.sampledAt) / 1000;
15+
return { ...previous, received, sampledAt: now, changedAt: now,
16+
bytesPerSecond: received !== null && previous.received !== null && elapsed > 0 ? (received - previous.received) / elapsed : null };
17+
}
18+
19+
export function transferText(sample: TransferSample, total: number | undefined, now: number, zh: boolean): string {
20+
const amount = sample.received === null ? (zh ? "等待下载数据" : "Waiting for download data") : `${(sample.received / 1048576).toFixed(1)} MiB`;
21+
const length = typeof total === "number" && total > 0 ? `${(total / 1048576).toFixed(1)} MiB` : (zh ? "总量未知" : "size unknown");
22+
const rate = sample.bytesPerSecond === null ? "" : ` · ${((now - sample.changedAt >= 5_000 ? 0 : sample.bytesPerSecond) / 1024).toFixed(0)} KiB/s`;
23+
const elapsed = Math.max(0, Math.floor((now - sample.startedAt) / 1000));
24+
const waiting = now - sample.changedAt >= 10_000 ? (zh ? " · 10 秒内无新进展" : " · no new progress for 10s") : "";
25+
return `${amount} / ${length}${rate} · ${elapsed}s${waiting}`;
26+
}

‎docs/guides/installing-loopx.md‎

Lines changed: 99 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,110 @@ Choose one installation owner and keep it authoritative:
1818
| Isolated CLI on an externally managed machine | `pipx` | `pipx install loopx` | `pipx upgrade loopx`, then refresh LoopX host material |
1919
| Existing uv tool environment | `uv` | `uv tool install loopx` | `uv tool upgrade loopx`, then refresh LoopX host material |
2020
| Contributor or source qualification | Git checkout | clone/fetch plus `scripts/install-local.sh` | update the checkout explicitly, rerun the installer, validate `loopx-canary` before promotion |
21-
| No-clone recovery fallback | LoopX archive snapshot | published archive installer | `loopx update apply` |
21+
| No-clone CLI or main preview | LoopX runtime snapshot | published installer with a prebuilt runtime | `loopx update apply` |
2222

2323
PyPI is the canonical source for normal releases. A source checkout is a
2424
development and qualification surface, not a second implicit package channel.
2525
The archive snapshot remains a recovery path rather than a competing default.
2626

27+
### Stable, main and source builds
28+
29+
`loopx update apply` and `loopx upgrade` preserve the installation owner. pip
30+
and pipx continue to use their own environment and configured package index;
31+
they do not become archive installs. Stable PyPI wheels already contain Chat's
32+
frontend. Node is needed for the TypeScript runtime described below, but npm
33+
and a local frontend build are not part of a normal package upgrade.
34+
35+
Managed snapshots inherit their recorded repo and ref, including a pinned SHA.
36+
New snapshots default to stable. Stable snapshots use the runtime attached to
37+
the latest stable release; main uses the latest **qualified** main snapshot,
38+
which can lag the branch while CI runs. The plan records its exact revision,
39+
version, size and SHA-256 before downloading. Missing metadata or a missing
40+
artifact stops the update without starting a source build. An older, diverged
41+
or unverified target requires explicit `--allow-downgrade` intent.
42+
43+
```bash
44+
loopx update plan
45+
loopx upgrade --ref main # snapshot installs only
46+
loopx update apply --ref stable --allow-downgrade
47+
loopx upgrade --ref main --source # explicit source download + local build
48+
```
49+
50+
To acquire a main snapshot without a checkout, use the published installer
51+
with `LOOPX_REF=main`. To build another ref, set
52+
`LOOPX_BUILD_FROM_SOURCE=1 LOOPX_REF=<ref>` before running that installer, or
53+
use the existing checkout installer. `LOOPX_ARCHIVE_URL` remains an explicit
54+
developer archive path. These choices never silently replace a pip/pipx or
55+
live-checkout owner. App updates continue through the native signed updater;
56+
a CLI-only installation does not install a Desktop App.
57+
58+
Updates run in an owned background worker even when the caller waits for the
59+
result. A terminal/Agent disconnect does not cancel it. Repeating apply while
60+
that installation's update is running observes the existing operation. To
61+
return immediately and read back later:
62+
63+
```bash
64+
loopx --format json upgrade --background
65+
loopx --format json update status
66+
loopx --format json update status --operation-id <returned-id>
67+
```
68+
69+
Windows console launchers retain their existing self-uninstall protection in
70+
the original process. Follow the printed `python -m loopx.entrypoint` retry
71+
to update safely and use the durable worker; a worker never hides a locked
72+
console executable from that guard.
73+
74+
JSON stdout contains the final result (or background operation descriptor).
75+
Progress is NDJSON on stderr: operation id, phase, downloaded bytes, total
76+
(`null` when unknown), observed rate, elapsed time and last progress time.
77+
The worker refreshes observation every five seconds and marks ten seconds
78+
without progress explicitly; a heartbeat is not a new byte or completed stage.
79+
Native App downloads show bytes, unknown totals, rate and stalled observation
80+
in **LoopX updates**, with existing check/install/recovery actions unchanged.
81+
82+
Runtime downloads cache hash-verified bytes across invocations. Partial data
83+
is appended only with a matching strong ETag, origin, exact Content-Range and
84+
length; ignored/rejected Range restarts within the bounded budget. A complete
85+
cache hit is verified again before use. `LOOPX_UPDATE_CACHE` selects the cache;
86+
`LOOPX_UPDATE_STATE_DIR` selects private operation readback. Failed or killed
87+
workers remain failed/interrupted, and status reads never replay installation.
88+
Normal HTTP(S) proxy environment variables remain authoritative. Optional
89+
`LOOPX_DOWNLOAD_MIRRORS` is a comma-separated list of operator-trusted HTTPS
90+
base URLs serving identical filenames; publisher-listed sources are also
91+
supported. Timeouts or sustained low throughput can switch sources, always
92+
with the same expected revision/hash/size. This is not a claim that regional
93+
mirrors have been deployed or that any country's latency has been measured.
94+
95+
The prebuilt runtime retains CLI/runtime code, skills and references, text
96+
documentation, developer smokes and the verified frontend. Named presentation
97+
videos/screenshots and frontend development sources are in the accompanying
98+
optional resource archive; illustrations remain available in versioned online
99+
docs. The release inventory lists every retained
100+
and optional file. Installers validate a candidate before activation and restore
101+
owned executable links on activation failure. Data-format migrations retain
102+
their independent receipts/backups; restoring an executable does not reverse
103+
migrated data. Existing managed-service ownership and pending-work restart
104+
guards still apply.
105+
106+
中文:普通 stable 用户继续使用 PyPI;pip/pipx 保留原环境和索引。snapshot 沿用
107+
既有 main/stable/固定 SHA,默认取带前端的预构建包。main 指最新通过 CI 的快照;
108+
源码构建须显式 `--source`,不会静默降级到整仓下载。旧版本或无法核实的目标须
109+
明确 `--allow-downgrade`。`--background` 返回 operation id,断线后用
110+
`update status` 回读原升级;JSON 结果在 stdout,持续进度在 stderr。下载缓存、
111+
续传和可选可信镜像都校验同一制品;代理沿用用户配置。恢复旧可执行文件不回滚
112+
已迁移的数据。无 Node 时无需构建前端,但运行控制平面仍需下面要求的 Node。
113+
114+
Release rollout: publish and qualify the stable runtime before deploying the
115+
new public bootstrap. The Pages lane checks this dependency and retains the
116+
previous deployed site if it is unavailable. `runtime-snapshots.yml` builds
117+
main artifacts; `release-artifacts.yml` reuses the release frontend/wheel lane
118+
for stable. Main archives and revision-addressed metadata share one dedicated
119+
`runtime-main` release, keeping product release history and stable-predecessor
120+
discovery intact; only the latest-channel metadata is replaced. Clean
121+
install/upgrade, package contents, byte size, provenance and
122+
phase timings are release evidence. A 20 MiB runtime is an evaluation target,
123+
not a waived dependency check or a global p50/p95 promise.
124+
27125
LoopX's Effect Program core runs in a managed, idle-exiting TypeScript runtime
28126
and requires Node.js 22.22.3 or later; Node.js 24 LTS is the recommended primary
29127
runtime. LoopX starts and reuses that local runtime automatically; users do not

0 commit comments

Comments
 (0)