fix(shell): separate wait, idle, and runtime limits (#6228)
* fix(shell): separate wait, idle, and runtime limits * fix(shell): separate wait, idle, and runtime limits * fix(exec): preserve settings aliases and reclaim completed sessions * fix(webui): make shell runtime limits explicit
This commit is contained in:
1 parent
70ac000ad9
commit
6310a39bac
36 files changed
+2392
-564
No files matched your search
@@ -6,6 +6,7 @@ import { SettingsGroup, SettingsRow, SettingsSectionTitle, RestartRequiredNotice
|
||||
import { ProviderPicker } from "@/components/settings/shared/ModelControls";
|
||||
import { TimezonePicker } from "@/components/settings/shared/TimezonePicker";
|
||||
import { SettingsTextEditor } from "@/components/settings/shared/SettingsTextEditor";
|
||||
import { ShellRuntimeControl } from "@/components/settings/system/ShellRuntimeControl";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { RUNTIME_CONFIG_FIELDS, RUNTIME_CONFIG_GROUPS, type RuntimeConfigField, type RuntimeConfigPage } from "@/components/settings/system/runtime-config-fields";
|
||||
import { updateRuntimeConfigSettings } from "@/lib/api";
|
||||
@@ -59,6 +60,11 @@ export function useRuntimeConfigSettings(
|
||||
setErrors((prev) => ({ ...prev, [field.group]: "" }));
|
||||
setInvalidField(null);
|
||||
};
|
||||
const reject = (field: RuntimeConfigField, message: string) => {
|
||||
setSaved((prev) => ({ ...prev, [field.group]: false }));
|
||||
setErrors((prev) => ({ ...prev, [field.group]: message }));
|
||||
setInvalidField(field.path);
|
||||
};
|
||||
const save = async (group: string) => {
|
||||
if (!settings?.runtime_config) return;
|
||||
if (saving) {
|
||||
@@ -70,12 +76,13 @@ export function useRuntimeConfigSettings(
|
||||
const values: Record<string, RuntimeConfigValue> = {};
|
||||
for (const field of changed) {
|
||||
const raw = value(field.path);
|
||||
if (field.kind === "number") {
|
||||
if (field.kind === "number" || field.kind === "duration") {
|
||||
const maximum = field.kind === "duration" ? settings.advanced.exec_max_runtime_limit : field.max;
|
||||
const parsed = Number(raw);
|
||||
if (String(raw).trim() === "" || !Number.isFinite(parsed)
|
||||
|| (field.path !== "api.timeout" && !Number.isInteger(parsed))
|
||||
|| (field.min !== undefined && parsed < field.min)
|
||||
|| (field.max !== undefined && parsed > field.max)) {
|
||||
|| (maximum !== undefined && parsed > maximum)) {
|
||||
setErrors((prev) => ({ ...prev, [group]: t("settings.runtimeConfig.numberError") }));
|
||||
setInvalidField(field.path);
|
||||
return;
|
||||
@@ -124,7 +131,7 @@ export function useRuntimeConfigSettings(
|
||||
applyPayload(payload, { preserveAgentForm: true, preserveCapabilityForms: true });
|
||||
setSaved((prev) => ({ ...prev, [field.group]: true }));
|
||||
};
|
||||
return { value, visible, dirty, discard, change, save, saveList, saving, errors, invalidField, saved };
|
||||
return { value, visible, dirty, discard, change, reject, save, saveList, saving, errors, invalidField, saved };
|
||||
}
|
||||
|
||||
export type RuntimeConfigController = ReturnType<typeof useRuntimeConfigSettings>;
|
||||
@@ -160,6 +167,7 @@ export function RuntimeConfigSettings({
|
||||
const dirty = fields.filter(state.visible).some(state.dirty);
|
||||
const title = tr(`groups.${group.id}.title`);
|
||||
const errorId = `runtime-error-${group.id}`;
|
||||
const inlineError = fields.some((field) => field.kind === "duration" && state.invalidField === field.path);
|
||||
const section = (
|
||||
<section key={group.id} aria-label={title}>
|
||||
<SettingsSectionTitle>{title}</SettingsSectionTitle>
|
||||
@@ -195,6 +203,13 @@ export function RuntimeConfigSettings({
|
||||
<div className="w-full">
|
||||
{field.path === "agents.defaults.timezone" ? (
|
||||
<TimezonePicker {...common} value={String(current)} onChange={(next) => state.change(field, next)} />
|
||||
) : field.kind === "duration" ? (
|
||||
<ShellRuntimeControl value={String(current)} maximum={settings.advanced.exec_max_runtime_limit}
|
||||
controlProps={{ ...common, disabled: disabled || state.saving === group.id || isRestarting }}
|
||||
onChange={(next) => state.change(field, next)}
|
||||
error={state.invalidField === field.path && state.errors[group.id]
|
||||
? { id: errorId, message: state.errors[group.id] } : undefined}
|
||||
onReject={(message) => state.reject(field, message)} />
|
||||
) : field.kind === "list" ? (
|
||||
<SettingsTextEditor id={id} title={text} description={help} value={String(current)}
|
||||
disabled={disabled || state.saving !== null || isRestarting}
|
||||
@@ -227,7 +242,7 @@ export function RuntimeConfigSettings({
|
||||
onRestart={onRestart} isRestarting={isRestarting} />
|
||||
</SettingsGroup>
|
||||
</fieldset>
|
||||
{state.errors[group.id] ? <p id={errorId} role="alert" className="mt-2 break-words px-1 text-[12px] text-destructive">{state.errors[group.id]}</p> : null}
|
||||
{state.errors[group.id] && !inlineError ? <p id={errorId} role="alert" className="mt-2 break-words px-1 text-[12px] text-destructive">{state.errors[group.id]}</p> : null}
|
||||
</form>
|
||||
</section>
|
||||
);
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
import { useState, type ComponentProps } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
import { ProviderPicker } from "@/components/settings/shared/ModelControls";
|
||||
import { Input } from "@/components/ui/input";
|
||||
|
||||
const PRESETS = [900, 1800, 3600, 21600, 43200, 86400];
|
||||
|
||||
type ControlProps = Pick<ComponentProps<typeof Input>,
|
||||
"id" | "disabled" | "aria-label" | "aria-describedby" | "aria-invalid">;
|
||||
|
||||
function formatDuration(seconds: number, locale: string): string {
|
||||
const [unit, divisor] = seconds % 3600 === 0 ? ["hour", 3600] as const
|
||||
: seconds % 60 === 0 ? ["minute", 60] as const : ["second", 1] as const;
|
||||
return new Intl.NumberFormat(locale, { style: "unit", unit, unitDisplay: "long" }).format(seconds / divisor);
|
||||
}
|
||||
|
||||
export function ShellRuntimeControl({
|
||||
value, maximum, controlProps, error, onChange, onReject,
|
||||
}: {
|
||||
value: string;
|
||||
maximum?: number;
|
||||
controlProps: ControlProps;
|
||||
error?: { id: string; message: string };
|
||||
onChange: (value: string) => void;
|
||||
onReject: (message: string) => void;
|
||||
}) {
|
||||
const { t, i18n } = useTranslation();
|
||||
const [customSelected, setCustomSelected] = useState(false);
|
||||
const presets = PRESETS.filter((seconds) => maximum === undefined || seconds <= maximum);
|
||||
if (maximum !== undefined && !presets.includes(maximum)) presets.push(maximum);
|
||||
const custom = customSelected || controlProps["aria-invalid"] === true
|
||||
|| (value !== "0" && !presets.includes(Number(value)));
|
||||
const limitId = `${controlProps.id}-limit`;
|
||||
const describedBy = `${controlProps["aria-describedby"] ?? ""}${maximum === undefined ? "" : ` ${limitId}`}`.trim();
|
||||
const unit = new Intl.NumberFormat(i18n.language, {
|
||||
style: "unit", unit: "second", unitDisplay: "short",
|
||||
}).formatToParts(2).find((part) => part.type === "unit")?.value;
|
||||
return (
|
||||
<div className="w-full space-y-1.5">
|
||||
<ProviderPicker
|
||||
triggerProps={{ ...controlProps, id: custom ? `${controlProps.id}-preset` : controlProps.id,
|
||||
"aria-describedby": describedBy }}
|
||||
value={custom ? "custom" : value}
|
||||
emptyLabel={t("settings.runtimeConfig.commandRuntime.custom")}
|
||||
providers={[
|
||||
...presets.map((seconds) => ({ name: String(seconds), label: formatDuration(seconds, i18n.language) })),
|
||||
{ name: "0", label: t("settings.runtimeConfig.commandRuntime.noLimit") },
|
||||
{ name: "custom", label: t("settings.runtimeConfig.commandRuntime.custom") },
|
||||
]}
|
||||
onChange={(next) => {
|
||||
setCustomSelected(next === "custom");
|
||||
if (next !== "custom") onChange(next);
|
||||
}}
|
||||
/>
|
||||
{custom ? <div className="relative">
|
||||
<Input {...controlProps} aria-label={t("settings.runtimeConfig.commandRuntime.customLabel")}
|
||||
aria-describedby={describedBy} type="number" inputMode="numeric"
|
||||
min={1} max={maximum} step={1} autoComplete="off" value={value === "0" ? "" : value}
|
||||
className="h-9 rounded-full pr-12 text-[13px] aria-[invalid=true]:border-destructive [&::-webkit-inner-spin-button]:appearance-none"
|
||||
onChange={(event) => {
|
||||
const next = event.target.value;
|
||||
const seconds = Number(next);
|
||||
if (next !== "" && (!Number.isSafeInteger(seconds) || seconds < 1
|
||||
|| (maximum !== undefined && seconds > maximum))) {
|
||||
onReject(maximum === undefined ? t("settings.runtimeConfig.numberError")
|
||||
: t("settings.runtimeConfig.commandRuntime.rangeError", { max: maximum.toLocaleString(i18n.language) }));
|
||||
return;
|
||||
}
|
||||
onChange(next);
|
||||
}} />
|
||||
<span aria-hidden className="pointer-events-none absolute inset-y-0 right-3 flex items-center text-[12px] text-muted-foreground">{unit}</span>
|
||||
</div> : null}
|
||||
{maximum !== undefined ? <p id={limitId} className="text-[12px] leading-4 text-muted-foreground">
|
||||
{t("settings.runtimeConfig.commandRuntime.limit", { duration: formatDuration(maximum, i18n.language) })}
|
||||
</p> : null}
|
||||
{error ? <p id={error.id} role="alert" className="text-[12px] leading-4 text-destructive">{error.message}</p> : null}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
export interface RuntimeConfigField {
|
||||
group: string;
|
||||
path: string;
|
||||
kind: "toggle" | "text" | "nullable" | "number" | "boolean" | "select" | "list" | "preset";
|
||||
kind: "toggle" | "text" | "nullable" | "number" | "duration" | "boolean" | "select" | "list" | "preset";
|
||||
options?: string[];
|
||||
when?: { path: string; value: string | boolean | string[] };
|
||||
manual?: boolean;
|
||||
@@ -44,7 +44,7 @@ export const RUNTIME_CONFIG_FIELDS: RuntimeConfigField[] = [
|
||||
{ group: "web", path: "tools.web.enable", kind: "boolean" },
|
||||
{ group: "tools", path: "tools.my.enable", kind: "boolean" },
|
||||
{ group: "tools", path: "tools.my.allow_set", kind: "boolean", when: { path: "tools.my.enable", value: true } },
|
||||
{ group: "shell", path: "tools.exec.timeout", kind: "number", min: 0 },
|
||||
{ group: "shell", path: "tools.exec.timeout", kind: "duration", min: 0 },
|
||||
{ group: "shell", path: "tools.exec.path_prepend", kind: "text" },
|
||||
{ group: "shell", path: "tools.exec.path_append", kind: "text" },
|
||||
{ group: "shell", path: "tools.exec.sandbox", kind: "select", options: ["", "bwrap", "seatbelt"] },
|
||||
|
||||
Reference in new issue
Block a user