Skip to content

The agent that grows with you

refactor: keep the rollback wiring inside the code-health caps (#137714)

Teknium812bb55ac636
diff --git a/apps/desktop/src/app/shell/hooks/use-statusbar-items.tsx b/apps/desktop/src/app/shell/hooks/use-statusbar-items.tsx
index 095e8c58e0a..ca3ce5deb2b 100644
--- a/apps/desktop/src/app/shell/hooks/use-statusbar-items.tsx
+++ b/apps/desktop/src/app/shell/hooks/use-statusbar-items.tsx
@@ -99,6 +99,29 @@ interface StatusbarItemsOptions {
toggleCommandCenter: () => void
}
+/** The statusbar row for one update target: the client, or the connected backend. */
+function versionItem(
+ target: 'backend' | 'client',
+ status: ReturnType<typeof resolveVersionStatus>,
+ applying: boolean,
+ toggleLabel: string
+): StatusbarItem {
+ return {
+ className: status.hasUpdate ? 'text-primary hover:text-primary' : undefined,
+ hidden: status.unknown,
+ icon: applying ? <Loader2 className="size-3 animate-spin" /> : <Hash className="size-3" />,
+ id: `version-${target}`,
+ label: status.label,
+ // Update state is not a preference: hiding it is how a user misses that
+ // they are behind. Listed in the menu, but locked on.
+ lockedVisible: true,
+ onSelect: () => openUpdateOverlayFor(target),
+ title: status.tooltip,
+ toggleLabel,
+ variant: 'action'
+ }
+}
+
export function useStatusbarItems({
agentsOpen,
changeSessionCwd,
@@ -378,6 +401,8 @@ export function useStatusbarItems({
? 'text-amber-600 hover:text-amber-600'
: 'text-destructive hover:text-destructive'
+ const rollbackBody = t.settings.about.channel.rollbackBody
+
const clientVersionItem = useMemo<StatusbarItem>(() => {
const applying = updateApply.applying || updateApply.stage === 'restart'
@@ -390,31 +415,15 @@ export function useStatusbarItems({
copy,
latestTag: updateStatus?.latestTag,
remote: connection?.mode === 'remote',
- rollback: rollbackSentence(
- { rollback: updateStatus?.rollback, sourceVersion: updateStatus?.sourceVersion },
- t.settings.about.channel.rollbackBody
- ),
restarting: updateApply.stage === 'restart',
+ rollback: rollbackSentence(updateStatus, rollbackBody),
sha: updateStatus?.currentSha?.slice(0, 7) ?? null,
target: 'client',
updateAvailable: updateStatus?.updateAvailable,
version: desktopVersion?.appVersion
})
- return {
- className: status.hasUpdate ? 'text-primary hover:text-primary' : undefined,
- hidden: status.unknown,
- icon: applying ? <Loader2 className="size-3 animate-spin" /> : <Hash className="size-3" />,
- id: 'version-client',
- label: status.label,
- // Update state is not a preference: hiding it is how a user misses that
- // their client is behind. Listed in the menu, but locked on.
- lockedVisible: true,
- onSelect: () => openUpdateOverlayFor('client'),
- title: status.tooltip,
- toggleLabel: copy.toggleVersion,
- variant: 'action'
- }
+ return versionItem('client', status, applying, copy.toggleVersion)
}, [
desktopVersion?.appVersion,
connection?.mode,
@@ -422,15 +431,8 @@ export function useStatusbarItems({
updateApply.applying,
updateApply.message,
updateApply.stage,
- updateStatus?.behind,
- updateStatus?.branch,
- updateStatus?.channel,
- updateStatus?.currentSha,
- updateStatus?.latestTag,
- updateStatus?.rollback,
- updateStatus?.sourceVersion,
- updateStatus?.updateAvailable,
- t.settings.about.channel.rollbackBody
+ updateStatus,
+ rollbackBody
])
const backendVersionItem = useMemo<StatusbarItem | null>(() => {
@@ -447,35 +449,18 @@ export function useStatusbarItems({
copy,
remote: true,
restarting: backendUpdateApply.stage === 'restart',
- rollback: rollbackSentence(
- { rollback: backendUpdateStatus?.rollback, sourceVersion: backendUpdateStatus?.sourceVersion },
- t.settings.about.channel.rollbackBody
- ),
+ rollback: rollbackSentence(backendUpdateStatus, rollbackBody),
target: 'backend',
updateAvailable: backendUpdateStatus?.updateAvailable,
version: statusSnapshot?.version
})
- return {
- className: status.hasUpdate ? 'text-primary hover:text-primary' : undefined,
- hidden: status.unknown,
- icon: applying ? <Loader2 className="size-3 animate-spin" /> : <Hash className="size-3" />,
- id: 'version-backend',
- label: status.label,
- lockedVisible: true,
- onSelect: () => openUpdateOverlayFor('backend'),
- title: status.tooltip,
- toggleLabel: copy.toggleBackendVersion,
- variant: 'action'
- }
+ return versionItem('backend', status, applying, copy.toggleBackendVersion)
}, [
connection?.mode,
statusSnapshot?.version,
- backendUpdateStatus?.behind,
- backendUpdateStatus?.rollback,
- backendUpdateStatus?.sourceVersion,
- t.settings.about.channel.rollbackBody,
- backendUpdateStatus?.updateAvailable,
+ backendUpdateStatus,
+ rollbackBody,
backendUpdateApply.applying,
backendUpdateApply.message,
backendUpdateApply.stage,
diff --git a/apps/desktop/src/components/update-status.tsx b/apps/desktop/src/components/update-status.tsx
index 677f8e93b84..2a79ecb245a 100644
--- a/apps/desktop/src/components/update-status.tsx
+++ b/apps/desktop/src/components/update-status.tsx
@@ -87,6 +87,22 @@ export function deriveUpdateStatus(input: UpdateStatusInput): UpdateStatusView {
return ordinaryUpdateStatus(input)
}
+/** The waiting update, or the older stable release it would move back to. */
+function availableLine(
+ status: DesktopUpdateStatus | null,
+ behind: number,
+ u: Translations['updates'],
+ rollback?: (version: string) => string
+): string {
+ const back = rollbackRelease(status)
+
+ if (rollback && back) {
+ return rollback(back)
+ }
+
+ return behind > 0 ? u.updateReady(behind) : u.updateReadyUnknown
+}
+
function ordinaryUpdateStatus({
apply,
checking,
@@ -123,11 +139,9 @@ function ordinaryUpdateStatus({
}
if (updateAvailable) {
- const back = rollback ? rollbackRelease(status) : null
-
return {
applying,
- line: back && rollback ? rollback(back) : behind > 0 ? u.updateReady(behind) : u.updateReadyUnknown,
+ line: availableLine(status, behind, u, rollback),
supported,
tone: 'available',
updateAvailable
diff --git a/apps/desktop/src/lib/version-status.ts b/apps/desktop/src/lib/version-status.ts
index 33ddd9fdd18..621ebf5eb29 100644
--- a/apps/desktop/src/lib/version-status.ts
+++ b/apps/desktop/src/lib/version-status.ts
@@ -68,6 +68,39 @@ export interface VersionStatusResult {
unknown: boolean
}
+interface PendingLinesInput {
+ available: boolean
+ behind: number
+ branch?: string
+ copy: VersionStatusCopy
+ latestTag: null | string
+ rollback?: string
+ stable: boolean
+}
+
+/** The tooltip lines naming what is waiting: a rollback, a newer release, or commits behind. */
+function pendingLines({ available, behind, branch, copy, latestTag, rollback, stable }: PendingLinesInput): string[] {
+ if (rollback) {
+ return available ? [rollback] : []
+ }
+
+ const lines: string[] = []
+
+ if (available && stable && latestTag) {
+ lines.push(copy.releaseAvailable(latestTag))
+ }
+
+ if (!stable && behind > 0) {
+ lines.push(copy.commitsBehind(behind, branch || '...'))
+ }
+
+ if (available && (stable ? !latestTag : behind <= 0)) {
+ lines.push(copy.update)
+ }
+
+ return lines
+}
+
export function resolveVersionStatus({
applyMessage,
applying,
@@ -114,10 +147,7 @@ export function resolveVersionStatus({
const tooltip = [
busy && (applyMessage || copy.updateInProgress),
- !busy && available && rollback,
- !busy && available && !rollback && stable && latestTag && copy.releaseAvailable(latestTag),
- !busy && !stable && behind > 0 && copy.commitsBehind(behind, (client ? branch : 'main') || '...'),
- !busy && available && !rollback && (stable ? !latestTag : behind <= 0) && copy.update,
+ ...(busy ? [] : pendingLines({ available, behind, branch: client ? branch : 'main', copy, latestTag, rollback, stable })),
version && (client ? copy.desktopVersion(version) : copy.backendVersion(version)),
client && sha && copy.commit(sha),
// The branch line is main-channel vocabulary; a stable checkout sits on
diff --git a/apps/desktop/src/store/updates.ts b/apps/desktop/src/store/updates.ts
index 9ce2014e8b4..3c4196b23dd 100644
--- a/apps/desktop/src/store/updates.ts
+++ b/apps/desktop/src/store/updates.ts
@@ -514,8 +514,8 @@ export function mapBackendCheck(res: BackendUpdateCheckResponse): DesktopUpdateS
error: checkFailed ? 'check-failed' : undefined,
message: res.message ?? undefined,
updateAvailable: res.update_available,
- rollback: res.rollback,
- sourceVersion: res.source_version ?? undefined,
+ rollback: Boolean(res.rollback_to),
+ sourceVersion: res.rollback_to ?? undefined,
behind: behind === null || behind < 0 ? null : behind,
currentVersion: res.current_version,
targetSha: res.update_available ? `backend:${res.current_version}` : undefined,
diff --git a/apps/desktop/src/types/hermes.ts b/apps/desktop/src/types/hermes.ts
index a0fe2caf10a..6b2b7d73df6 100644
--- a/apps/desktop/src/types/hermes.ts
+++ b/apps/desktop/src/types/hermes.ts
@@ -1597,8 +1597,7 @@ export interface BackendUpdateCheckResponse {
behind: number | null
update_available: boolean
/** A stable release this build already contains: applying it moves back. */
- rollback?: boolean
- source_version?: null | string
+ rollback_to?: null | string
can_apply: boolean
update_command: string | null
message: string | null
diff --git a/hermes_cli/web_routers/actions.py b/hermes_cli/web_routers/actions.py
index a702a4a329e..cfec1d08549 100644
--- a/hermes_cli/web_routers/actions.py
+++ b/hermes_cli/web_routers/actions.py
@@ -342,7 +342,7 @@ async def check_hermes_update(force: bool = False, profile: Optional[str] = None
payload["update_available"] = True
if status.get("rollback"):
# A stable release this build already contains: applying it moves back.
- payload.update(rollback=True, source_version=status.get("sourceVersion"),
+ payload.update(rollback_to=status.get("sourceVersion"),
message=f"This build is newer than stable release v{status.get('sourceVersion')}. "
"Updating moves it back to that release.")
# "What's changed" for the desktop's remote update overlay; best-effort
diff --git a/web/src/lib/api.ts b/web/src/lib/api.ts
index 2c7ef2d84a5..629c886378c 100644
--- a/web/src/lib/api.ts
+++ b/web/src/lib/api.ts
@@ -1906,13 +1906,10 @@ export interface HookCreate {
export interface UpdateCheckResponse {
install_method: string;
current_version: string;
- // commits behind: >=1 known count, 0 up to date, -1 behind by unknown
- // count (nix/pypi), or null when the check could not run.
+ // commits behind: >=1 known, 0 up to date, -1 unknown count (nix/pypi), null = check could not run.
behind: number | null;
update_available: boolean;
- /** A stable release this build already contains: applying it moves back. */
- rollback?: boolean;
- source_version?: string | null;
+ rollback_to?: string | null; // a stable release this build already contains: applying it moves back
can_apply: boolean;
update_command: string;
message: string | null;
diff --git a/web/src/pages/SystemPage.tsx b/web/src/pages/SystemPage.tsx
index b11d463bf9f..a66fd4334b5 100644
--- a/web/src/pages/SystemPage.tsx
+++ b/web/src/pages/SystemPage.tsx
@@ -107,6 +107,19 @@ function backupFileName(path: string | null): string {
* backup, import, skills update, checkpoints prune, gateway start/stop).
* Polls /api/actions/<name>/status until the process exits.
*/
+/** Badge for an available update; a rollback names the release it returns to. */
+function updateBadge(info: UpdateCheckResponse): string {
+ if (info.rollback_to) return `newer than v${info.rollback_to}`;
+ return info.behind && info.behind > 0 ? `${info.behind} behind` : "update available";
+}
+
+function updateToast(info: UpdateCheckResponse): string {
+ if (info.rollback_to && info.message) return info.message;
+ return info.behind && info.behind > 0
+ ? `Update available — ${info.behind} commit${info.behind === 1 ? "" : "s"} behind`
+ : "Update available";
+}
+
function ActionLogViewer({
action,
onClose,
@@ -583,15 +596,8 @@ export default function SystemPage() {
const info = await api.checkHermesUpdate(force);
setUpdateInfo(info);
if (force) {
- if (info.update_available && info.rollback && info.message) {
- showToast(info.message, "success");
- } else if (info.update_available) {
- showToast(
- info.behind && info.behind > 0
- ? `Update available — ${info.behind} commit${info.behind === 1 ? "" : "s"} behind`
- : "Update available",
- "success",
- );
+ if (info.update_available) {
+ showToast(updateToast(info), "success");
} else if (info.behind === 0) {
showToast("You're on the latest version", "success");
} else if (info.message) {
@@ -932,11 +938,7 @@ export default function SystemPage() {
updateInfo &&
(updateInfo.update_available ? (
<Badge tone="warning">
- {updateInfo.rollback
- ? `newer than v${updateInfo.source_version}`
- : updateInfo.behind && updateInfo.behind > 0
- ? `${updateInfo.behind} behind`
- : "update available"}
+ {updateBadge(updateInfo)}
</Badge>
) : updateInfo.behind === 0 ? (
<Badge tone="success">latest</Badge>