feat: autoscale Sprite memory via Resources Policy
Sprites have no size presets and CPU/storage are fixed (8 vCPU / 100 GB), so memory policy (limit + autoscale) is the sizing lever for bursty unknown workloads. ensureSprite now applies idempotently, non-failing: - memoryAutoscale (default true) lets the platform grow memory under pressure instead of thrashing at a fixed cap - memoryLimitMB (0 = Fly default ceiling 8192) is the peak ceiling - Settings UI exposes both controls
This commit is contained in:
1 parent
b2c8f4492d
commit
4ae69f54ce
3 files changed
+78
No files matched your search
@@ -440,6 +440,18 @@ export function FlySpritesSettingsScreen({ theme, layout, host }: PluginSurfaceP
|
|||||||
setDraft((prev) => ({ ...prev, defaultCpus: Number.isFinite(parsed) && parsed >= 0 ? parsed : 0 }));
|
setDraft((prev) => ({ ...prev, defaultCpus: Number.isFinite(parsed) && parsed >= 0 ? parsed : 0 }));
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
<SettingsInput
|
||||||
|
label="Memory ceiling (MB)"
|
||||||
|
hint="Peak memory the Sprite may grow to when autoscale is on. 0 uses the Fly default (8192 MB). Raise for bursty workloads — e.g. 16384 or 65536 (no published API max; constrained by host capacity)."
|
||||||
|
initialValue={String(draft.memoryLimitMB ?? 0)}
|
||||||
|
placeholder="0"
|
||||||
|
disabled={settings.saving}
|
||||||
|
onChangeText={(val) => {
|
||||||
|
const parsed = Number.parseInt(val.trim() || "0", 10);
|
||||||
|
setStatusMessage(null);
|
||||||
|
setDraft((prev) => ({ ...prev, memoryLimitMB: Number.isFinite(parsed) && parsed >= 0 ? parsed : 0 }));
|
||||||
|
}}
|
||||||
|
/>
|
||||||
</SettingsCard>
|
</SettingsCard>
|
||||||
</SettingsSection>
|
</SettingsSection>
|
||||||
|
|
||||||
@@ -456,6 +468,17 @@ export function FlySpritesSettingsScreen({ theme, layout, host }: PluginSurfaceP
|
|||||||
void saveDraft(next);
|
void saveDraft(next);
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
<SettingsSwitch
|
||||||
|
label="Autoscale Sprite memory"
|
||||||
|
hint="Lets the Fly platform grow Sprite memory under pressure (up to the memory ceiling). Sprites have no size presets and CPU/storage are fixed — this is the sizing lever for unknown/bursty workloads."
|
||||||
|
value={draft.memoryAutoscale !== false}
|
||||||
|
disabled={settings.saving}
|
||||||
|
onValueChange={(memoryAutoscale) => {
|
||||||
|
const next = { ...draft, memoryAutoscale };
|
||||||
|
setDraft(next);
|
||||||
|
void saveDraft(next);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
<SettingsSwitch
|
<SettingsSwitch
|
||||||
label="Inject sprite_* tools into Paseo agents"
|
label="Inject sprite_* tools into Paseo agents"
|
||||||
hint="Allows local agents to spawn parallel Fly Sprite workers and checkpoints."
|
hint="Allows local agents to spawn parallel Fly Sprite workers and checkpoints."
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import {
|
|||||||
type Sprite,
|
type Sprite,
|
||||||
type SpriteCommand,
|
type SpriteCommand,
|
||||||
type SpriteConfig,
|
type SpriteConfig,
|
||||||
|
type ResourcesPolicy,
|
||||||
type StreamMessage,
|
type StreamMessage,
|
||||||
} from "@fly/sprites";
|
} from "@fly/sprites";
|
||||||
import type {
|
import type {
|
||||||
@@ -268,6 +269,43 @@ export class SpritesManager {
|
|||||||
return Object.keys(config).length > 0 ? config : undefined;
|
return Object.keys(config).length > 0 ? config : undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ensure the Sprite's Resources Policy memory ceiling/autoscale match
|
||||||
|
* settings. Idempotent: only calls `updateResourcesPolicy` when the
|
||||||
|
* effective values differ, so repeated `ensureSprite` passes are cheap.
|
||||||
|
* Sprites have no size presets and no CPU/storage scaling — memory
|
||||||
|
* policy (limit + autoscale) is the sizing lever. `memoryLimitMB` of 0
|
||||||
|
* means the Fly default ceiling (8192 MB, matching sprite defaults).
|
||||||
|
*/
|
||||||
|
async applyMemoryResourcesPolicy(
|
||||||
|
sprite: Sprite,
|
||||||
|
settings?: FlySpritesSettings,
|
||||||
|
): Promise<{ limitMB: number; autoscale: boolean; changed: boolean }> {
|
||||||
|
const resolved = settings ?? (await this.getSettings());
|
||||||
|
const limitMB =
|
||||||
|
resolved.memoryLimitMB && resolved.memoryLimitMB > 0
|
||||||
|
? resolved.memoryLimitMB
|
||||||
|
: 8192;
|
||||||
|
// Missing key (settings stored before this field existed) means default: on.
|
||||||
|
const autoscale = resolved.memoryAutoscale !== false;
|
||||||
|
let current: ResourcesPolicy | null = null;
|
||||||
|
try {
|
||||||
|
current = await sprite.getResourcesPolicy();
|
||||||
|
} catch {
|
||||||
|
current = null;
|
||||||
|
}
|
||||||
|
const already =
|
||||||
|
current?.memory?.limitMB === limitMB &&
|
||||||
|
(current?.memory?.autoscale ?? false) === autoscale;
|
||||||
|
if (already) {
|
||||||
|
return { limitMB, autoscale, changed: false };
|
||||||
|
}
|
||||||
|
await sprite.updateResourcesPolicy({
|
||||||
|
memory: { limitMB, autoscale },
|
||||||
|
});
|
||||||
|
return { limitMB, autoscale, changed: true };
|
||||||
|
}
|
||||||
|
|
||||||
async generateSpriteName(prefixOverride?: string): Promise<string> {
|
async generateSpriteName(prefixOverride?: string): Promise<string> {
|
||||||
const settings = await this.getSettings();
|
const settings = await this.getSettings();
|
||||||
const prefix = prefixOverride ?? settings.spritePrefix ?? "paseo-worker-";
|
const prefix = prefixOverride ?? settings.spritePrefix ?? "paseo-worker-";
|
||||||
@@ -313,6 +351,19 @@ export class SpritesManager {
|
|||||||
this.remoteSpritesCache = null;
|
this.remoteSpritesCache = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const policyResult = await this.applyMemoryResourcesPolicy(sprite, settings);
|
||||||
|
options.onProgress?.(
|
||||||
|
`Memory policy ${policyResult.limitMB} MB (autoscale ${
|
||||||
|
policyResult.autoscale ? "on" : "off"
|
||||||
|
}) ${policyResult.changed ? "applied to" : "already on"} ${sprite.name}`,
|
||||||
|
sprite.name,
|
||||||
|
);
|
||||||
|
} catch (error) {
|
||||||
|
const msg = error instanceof Error ? error.message : String(error);
|
||||||
|
console.warn(`[fly-sprites] memory policy skipped for ${sprite.name}: ${msg}`);
|
||||||
|
}
|
||||||
|
|
||||||
let antigravityAuthChanged = false;
|
let antigravityAuthChanged = false;
|
||||||
if (settings.syncAntigravityAuth) {
|
if (settings.syncAntigravityAuth) {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -19,6 +19,8 @@ export const flySpritesSettingsSchema = z.object({
|
|||||||
defaultRegion: z.string().default(""),
|
defaultRegion: z.string().default(""),
|
||||||
defaultRamMB: z.number().int().nonnegative().default(0),
|
defaultRamMB: z.number().int().nonnegative().default(0),
|
||||||
defaultCpus: z.number().int().nonnegative().default(0),
|
defaultCpus: z.number().int().nonnegative().default(0),
|
||||||
|
memoryLimitMB: z.number().int().nonnegative().default(0),
|
||||||
|
memoryAutoscale: z.boolean().default(true),
|
||||||
defaultRemoteCwd: z.string().default("/workspace"),
|
defaultRemoteCwd: z.string().default("/workspace"),
|
||||||
defaultProviderMode: z.enum(["shell", "acp"]).default("acp"),
|
defaultProviderMode: z.enum(["shell", "acp"]).default("acp"),
|
||||||
acpCommand: z.string().default("claude-code-acp"),
|
acpCommand: z.string().default("claude-code-acp"),
|
||||||
@@ -56,6 +58,8 @@ export const defaultFlySpritesSettings: FlySpritesSettings = {
|
|||||||
defaultRegion: "",
|
defaultRegion: "",
|
||||||
defaultRamMB: 0,
|
defaultRamMB: 0,
|
||||||
defaultCpus: 0,
|
defaultCpus: 0,
|
||||||
|
memoryLimitMB: 0,
|
||||||
|
memoryAutoscale: true,
|
||||||
defaultRemoteCwd: "/workspace",
|
defaultRemoteCwd: "/workspace",
|
||||||
defaultProviderMode: "acp",
|
defaultProviderMode: "acp",
|
||||||
acpCommand: "claude-code-acp",
|
acpCommand: "claude-code-acp",
|
||||||
|
|||||||
Reference in new issue
Block a user