mirror of
https://github.com/stablyai/orca.git
synced 2026-11-19 04:23:57 +00:00
* fix(sandbox-control): read the orgRole claim that Orca Cloud auth mints (#29) Auth mints the live org role as orgRole on sandbox tokens (same claim as billing tokens, stablyai/orca-cloud#695); the verifier read org_role, so admins would never have been recognized. * wip(cloud): environment builds control plane * wip(cloud): environment build boot path, staleness, routes * wip(cloud): env build tests, anonymous staleness fallback * wip(cloud): migration 0008 (claimed), quieter recovered clone errors * fix(cloud): env build review: interrupted-snapshot recovery, bounded log reads, secret redaction, activation guard, hook/prelude fixes * fix(cloud): wait briefly for the build exit code after its log ends; print the base image and package manager * wip(desktop): org environments client, IPC, CLI, settings UI, orcad disk usage + low-disk banner * perf(cloud): smoke-boot each environment build before activating it; skip the redundant prelude fetch * fix(cloud): a GitHub token error fails the build as github_unavailable instead of cloning anonymously * perf(cloud): warm pool VMs per hot environment build, so a create from an org environment skips the provider boot * wip(desktop): cloud environment UI round-3 fixes * fix(cloud): pool-per-build review: smoke race safety, provider hiccups skip smoke, usage-based hot builds with caps, bounded boots, index * fix(desktop): Configure with an agent hands the prompt over at launch (trust dialog swallowed the pasted Enter); CLI builds table widths * polish(desktop): W10 P2s — InlineError action slot, shared focus-ring, copy * feat(cloud): build event stream heartbeat every 20 s * fix(desktop): FE review — stable virtualizer, shadow-buffer replays, heartbeat-aware build watch, CLI follower restarts, repo import path checks, poll races
78 lines
2.9 KiB
TypeScript
78 lines
2.9 KiB
TypeScript
// orcad's disk usage probe and the low-disk thresholds the desktop banner reads it against.
|
|
import { z } from 'zod'
|
|
|
|
/** orcad: free space on the filesystems holding workspaces, repos and $HOME. Read-only, no subprocess. */
|
|
export const ORCAD_DISK_USAGE_METHOD = 'orcad.diskUsage'
|
|
export const OrcadDiskUsageParamsSchema = z.object({}).strict()
|
|
|
|
export const OrcadDiskVolumeUsageSchema = z.object({
|
|
/** A probed path on this filesystem (the first one that resolved to it). */
|
|
path: z.string(),
|
|
totalBytes: z.number().nonnegative(),
|
|
freeBytes: z.number().nonnegative(),
|
|
/** Free bytes an unprivileged process may use (excludes root-reserved blocks). */
|
|
availableBytes: z.number().nonnegative(),
|
|
/** 0-100, from total and available, matching `df`'s Use%. */
|
|
usedPercent: z.number().min(0).max(100)
|
|
})
|
|
export type OrcadDiskVolumeUsage = z.infer<typeof OrcadDiskVolumeUsageSchema>
|
|
|
|
export const OrcadDiskUsageResultSchema = z.object({
|
|
/** One entry per distinct filesystem; the workspace root's comes first. */
|
|
volumes: z.array(OrcadDiskVolumeUsageSchema),
|
|
checkedAt: z.number()
|
|
})
|
|
export type OrcadDiskUsageResult = z.infer<typeof OrcadDiskUsageResultSchema>
|
|
|
|
const MIB = 1024 * 1024
|
|
const GIB = 1024 * MIB
|
|
|
|
/** Warn under 10% or 2 GiB available; critical under 500 MiB, where builds and git start failing. */
|
|
export const LOW_DISK_WARNING_FRACTION = 0.1
|
|
export const LOW_DISK_WARNING_BYTES = 2 * GIB
|
|
export const LOW_DISK_CRITICAL_BYTES = 500 * MIB
|
|
|
|
export type LowDiskLevel = 'ok' | 'warning' | 'critical'
|
|
|
|
export function lowDiskLevelForVolume(
|
|
volume: Pick<OrcadDiskVolumeUsage, 'totalBytes' | 'availableBytes'>
|
|
): LowDiskLevel {
|
|
// A zero-size filesystem (procfs-like mount, failed statfs) carries no signal.
|
|
if (volume.totalBytes <= 0) {
|
|
return 'ok'
|
|
}
|
|
if (volume.availableBytes < LOW_DISK_CRITICAL_BYTES) {
|
|
return 'critical'
|
|
}
|
|
if (
|
|
volume.availableBytes < LOW_DISK_WARNING_BYTES ||
|
|
volume.availableBytes < volume.totalBytes * LOW_DISK_WARNING_FRACTION
|
|
) {
|
|
return 'warning'
|
|
}
|
|
return 'ok'
|
|
}
|
|
|
|
const LEVEL_RANK: Record<LowDiskLevel, number> = { ok: 0, warning: 1, critical: 2 }
|
|
|
|
/** The most severe volume, ties broken by least available space; null when every volume is fine. */
|
|
export function worstLowDiskVolume(
|
|
volumes: readonly OrcadDiskVolumeUsage[]
|
|
): { level: Exclude<LowDiskLevel, 'ok'>; volume: OrcadDiskVolumeUsage } | null {
|
|
let worst: { level: LowDiskLevel; volume: OrcadDiskVolumeUsage } | null = null
|
|
for (const volume of volumes) {
|
|
const level = lowDiskLevelForVolume(volume)
|
|
if (level === 'ok') {
|
|
continue
|
|
}
|
|
if (
|
|
!worst ||
|
|
LEVEL_RANK[level] > LEVEL_RANK[worst.level] ||
|
|
(level === worst.level && volume.availableBytes < worst.volume.availableBytes)
|
|
) {
|
|
worst = { level, volume }
|
|
}
|
|
}
|
|
return worst && worst.level !== 'ok' ? { level: worst.level, volume: worst.volume } : null
|
|
}
|