-
Notifications
You must be signed in to change notification settings - Fork 2.3k
3. add verified updates and rollback for compiled installs #2166
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
4164228
feat: retain compiled updates on restacked migration; refs #2166
kevinjosethomas 831198e
fix: bound compiled executable verification probes; fixes #2166
kevinjosethomas 5a70965
fix: retain update guidance for damaged managed installs; fixes #2166
kevinjosethomas c64beae
fix: clean up stalled probes during installer recovery; fixes #2166
kevinjosethomas dd43e70
fix: measure executable probe deadlines by elapsed time; fixes #2166
kevinjosethomas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| - Added verified updates and offline rollback for compiled Prime Agent installations, preserving sessions and restarting with the activated release. | ||
| - Fixed normal interruptions during rollback losing the release needed to undo that rollback. | ||
| - Fixed malformed compiled-release metadata causing unnecessary npm reinstalls and daemon restarts. | ||
| - Fixed interrupted compiled activation recovering the exact rollback target before another lifecycle change. | ||
| - Added conservative cleanup for abandoned installer staging and inactive managed releases while retaining live or uncertain releases. | ||
| - Fixed direct and planned rollback rejecting inconsistent release metadata, assets, paths, and executable versions before activation. | ||
| - Fixed failed activation recovery discarding the state needed to retry restoring the previous release. | ||
| - Fixed damaged compiled installations blocking repair and rollback to a healthy retained release. | ||
| - Fixed rollback planning after interrupted activation and provided repair guidance for older retained installers without recovery support. | ||
| - Fixed stalled executable checks holding the installer lock indefinitely during installation, rollback, or activation recovery. | ||
| - Fixed update guidance directing repairable compiled installations to a manual download instead of the update command. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| import { execFileSync } from "node:child_process"; | ||
| import { accessSync, constants, readFileSync } from "node:fs"; | ||
| import { join, relative } from "node:path"; | ||
| import { APP_NAME, type SelfUpdateCommand } from "../config.js"; | ||
| import { | ||
| getNativeInstallationTarget, | ||
| readNativeInstallation, | ||
| readNativeRollbackInstallation, | ||
| } from "../utils/native-installation.js"; | ||
| import { getLatestPiRelease, isNewerPackageVersion } from "../utils/version-check.js"; | ||
|
|
||
| export interface NativeUpdatePlan { | ||
| command?: SelfUpdateCommand; | ||
| targetVersion: string; | ||
| } | ||
|
|
||
| export async function getNativeUpdatePlan(options: { | ||
| force: boolean; | ||
| rollback: boolean; | ||
| executable?: string; | ||
| }): Promise<NativeUpdatePlan> { | ||
| const current = getNativeInstallationTarget(options.executable); | ||
| if (!current) | ||
| throw new Error( | ||
| "This compiled application is not owned by the Prime Agent installer. Update it using its original installer.", | ||
| ); | ||
|
kevinjosethomas marked this conversation as resolved.
|
||
| const active = readNativeInstallation(current.root); | ||
| const installation = active ?? readNativeInstallation(current.root, "previous"); | ||
| if (!installation || installation.platform !== current.platform) | ||
| throw new Error("The compiled installation is damaged. Run the published installer again to repair it."); | ||
| if ( | ||
| (options.rollback || !active) && | ||
| !/^# prime-agent-native-recovery-v1$/m.test(readFileSync(join(installation.releaseDir, "install.sh"), "utf8")) | ||
| ) | ||
| throw new Error( | ||
| "The retained installer does not support this recovery. Run the published installer at https://app.primeintellect.ai/prime-agent/install.sh again to repair it.", | ||
| ); | ||
| accessSync(installation.root, constants.W_OK); | ||
| accessSync(join(installation.root, "bin"), constants.W_OK); | ||
| let version: string; | ||
| let checksum: string | undefined; | ||
| let previousTarget: string | undefined; | ||
| const baseUrl = process.env.PRIME_AGENT_DOWNLOAD_BASE_URL?.trim() || installation.baseUrl; | ||
| if (options.rollback) { | ||
| const previous = readNativeRollbackInstallation(installation.root); | ||
| if (!previous || previous.executable === current.executable) | ||
| throw new Error("No valid previous compiled release is available."); | ||
| let reportedVersion: string; | ||
| try { | ||
| reportedVersion = execFileSync(previous.executable, ["--version"], { | ||
| encoding: "utf8", | ||
| timeout: 10000, | ||
| }); | ||
| } catch { | ||
| throw new Error("The previous compiled release executable could not be validated."); | ||
| } | ||
| if (reportedVersion !== previous.version && reportedVersion !== `${previous.version}\n`) | ||
| throw new Error("The previous compiled release executable reports a different version."); | ||
| try { | ||
| execFileSync(previous.executable, ["--help"], { stdio: "ignore", timeout: 10000 }); | ||
| } catch { | ||
| throw new Error("The previous compiled release executable failed its help probe."); | ||
| } | ||
| version = previous.version; | ||
| previousTarget = relative(join(installation.root, "bin"), previous.executable); | ||
|
kevinjosethomas marked this conversation as resolved.
|
||
| } else { | ||
| const release = await getLatestPiRelease(current.version, { baseUrl }); | ||
| if (!release || !/^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/.test(release.version)) | ||
| throw new Error("Could not resolve a compiled release. The installed version was kept."); | ||
| if (active && !options.force && !isNewerPackageVersion(release.version, current.version)) | ||
| return { targetVersion: current.version }; | ||
| const artifact = release.binaries?.find((entry) => entry.platform === current.platform); | ||
| if (!artifact) throw new Error(`No verified compiled archive is available for ${current.platform}.`); | ||
| version = release.version; | ||
| checksum = artifact.sha256; | ||
| } | ||
| const environment = { | ||
| PRIME_AGENT_INSTALL_METHOD: "binary", | ||
| PRIME_AGENT_INSTALL_DIR: installation.root, | ||
| PRIME_AGENT_DOWNLOAD_BASE_URL: baseUrl, | ||
| PRIME_AGENT_INSTALL_LINK: "0", | ||
| PRIME_AGENT_INSTALLER_NONINTERACTIVE: "1", | ||
| PRIME_AGENT_INSTALLER_PLAIN: "1", | ||
| PRIME_AGENT_BOOTSTRAP_KERNEL_ON_INSTALL: "0", | ||
| PRIME_AGENT_EXPECTED_CURRENT: relative(join(current.root, "bin"), current.executable), | ||
| ...(previousTarget ? { PRIME_AGENT_EXPECTED_PREVIOUS: previousTarget } : {}), | ||
| ...(checksum ? { PRIME_AGENT_EXPECTED_SHA256: checksum } : {}), | ||
| }; | ||
| return { | ||
| targetVersion: version, | ||
| command: { | ||
| command: "/usr/bin/env", | ||
| args: [ | ||
| ...Object.entries(environment).map(([name, value]) => `${name}=${value}`), | ||
| "sh", | ||
| join(installation.releaseDir, "install.sh"), | ||
| options.rollback ? "--rollback" : version, | ||
| ], | ||
| display: `${APP_NAME} update${options.rollback ? " --rollback" : options.force ? " --force" : ""}`, | ||
| }, | ||
| }; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.