Compare commits

...
6 Commits
Author SHA1 Message Date
tbenandClaude Opus 5.5 c072e9c0bc Bump version to 0.28.22
CI / check (push) Canceled after 0s
Release image / image (release) Canceled after 0s
Release image / computer-image (release) Canceled after 0s
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-12-04 15:14:03 +01:00
tbenandClaude Opus 5.5 e01114ce63 Close bot_tasks rows left active with no open job at boot
Rows from before a failed run closed its own row stayed active for months
and kept their conversations polling for progress that never came.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-12-04 15:14:03 +01:00
tbenandClaude Opus 5.5 d9ac0daf45 Reflow describeSkillProposal
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-12-04 15:14:03 +01:00
tbenandClaude Opus 5.5 99622e620d Hold a failed job's retry to the model rest and show it waiting
A quota resetting in nine days held a routine's retry a full day while its
models were benched for 30 seconds, with the face still on working and the
next day's run skipped behind it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-12-04 15:09:25 +01:00
tbenandClaude Opus 5.5 54ba0e845d Bump version to 0.28.21
CI / check (push) Canceled after 0s
Release image / image (release) Canceled after 0s
Release image / computer-image (release) Canceled after 0s
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-30 11:40:27 +01:00
tbenandClaude Opus 5.5 1da980e243 Look for a hook runner's folder in the owner's ~ first, and show runner faults in error colours
A relative runner_dir is now tried in users/<owner> inside the bot's
folder (the run's ~, where a bot builds a bridge) and then in the bot's
folder, so "whatsapp" finds ~/whatsapp and folders given the old way
still work. The keeper script takes the candidates in order (version 3).
Runner down, Down, Check failed and Last error now use the error colour.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-30 11:40:27 +01:00
25 changed files with 344 additions and 67 deletions
+3 -3
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "cobble",
"version": "0.28.20",
"version": "0.28.22",
"module": "index.ts",
"type": "module",
"private": true,
+19 -2
View File
@@ -16,6 +16,8 @@ import recordBotHookFailure from "@/src/functions/backend/db/bot-hooks/record-bo
import isUnattendedHookSession from "@/src/functions/backend/db/bot-hooks/is-unattended-hook-session";
import recordCronJobFailure from "@/src/functions/backend/db/cron-jobs/record-cron-job-failure";
import scheduledRunRetryAt from "@/src/utils/scheduled-run-retry-at";
import providerRetryAt from "@/src/utils/provider-retry-at";
import grabModelRestMs from "@/src/harness/resolve/grab-model-rest-ms";
import {
BotComputerBusyStatusLine,
BotReplyJobTitle,
@@ -488,7 +490,10 @@ export default async function processBotJob({
}
/**
* A retry no sooner than the provider said to come back.
* A retry no sooner than the provider said to come back, but no
* later than the model rest: its models are benched no longer
* than that, and a quota reset days away would otherwise hold the
* job for `AppData.HarnessMaxCooldownMs`.
*/
if (
failed?.status == "pending" &&
@@ -496,7 +501,19 @@ export default async function processBotJob({
error.retryable &&
error.retry_at
) {
await deferBotJob({ job_id, worker, until: error.retry_at });
await deferBotJob({
job_id,
worker,
until: providerRetryAt({ retry_at: error.retry_at, rest_ms: await grabModelRestMs() }),
});
}
/**
* Waiting for its retry, the bot isn't working: a face left on
* `working` read as a run stuck mid-step until the retry came.
*/
if (failed?.status == "pending") {
await setFace({ face: "asleep", status_line: BotWaitingStatusLine }).catch(() => {});
}
} finally {
clearInterval(heartbeat);
+16 -5
View File
@@ -1,4 +1,5 @@
import { useState } from "react";
import Tag from "@moduletrace/twui/elements/Tag";
import Button from "@moduletrace/twui/layout/Button";
import Link from "@moduletrace/twui/layout/Link";
import Row from "@moduletrace/twui/layout/Row";
@@ -99,12 +100,18 @@ export default function HookDetailModal({ hook, can_manage = false, onClose, onE
{runner?.configured ? (
<>
<TaskFactRow label="Runner">
{runner.running
? `Up since ${relativeTime({ at: Number(hook.runner_started_at) || Date.now() })}`
: "Down"}
{runner.running ? (
`Up since ${relativeTime({ at: Number(hook.runner_started_at) || Date.now() })}`
) : (
<Tag color="error" variant="outlined" className="px-1.5 py-0 text-[11px] font-bold leading-4">
Down
</Tag>
)}
</TaskFactRow>
{runner.error ? (
<TaskFactRow label="Check failed">{runner.error}</TaskFactRow>
<TaskFactRow label="Check failed">
<Span className="text-error break-words min-w-0">{runner.error}</Span>
</TaskFactRow>
) : null}
<TaskFactRow label="Last checked">
{hook.runner_checked_at
@@ -136,7 +143,11 @@ export default function HookDetailModal({ hook, can_manage = false, onClose, onE
<TaskFactRow label="Last called">
{hook.last_called_at ? relativeTime({ at: Number(hook.last_called_at) }) : "Never"}
</TaskFactRow>
{hook.last_error ? <TaskFactRow label="Last error">{hook.last_error}</TaskFactRow> : null}
{hook.last_error ? (
<TaskFactRow label="Last error">
<Span className="text-error break-words min-w-0">{hook.last_error}</Span>
</TaskFactRow>
) : null}
</Stack>
{hook.instructions ? <HookCallAnswer label="Brief" text={hook.instructions} boxed /> : null}
{status ? <SettingsStatus status={status} /> : null}
+1 -1
View File
@@ -289,7 +289,7 @@ export default function HookForm({
autoComplete="off"
placeholder="whatsapp"
defaultValue={hook?.runner_dir || ""}
info={`Where it starts, relative to the bot's folder (/home/cb-<bot>/workspace), not to a run's ~: "whatsapp" is /home/cb-<bot>/workspace/whatsapp, while a folder a bot made at ~/whatsapp is "users/<user>/whatsapp". Empty starts in the bot's folder itself.`}
info={`Where it starts, relative: "whatsapp" is looked for in your own folder in the bot's (/home/cb-<bot>/workspace/users/<you>, a run's ~) first, then in the bot's folder (/home/cb-<bot>/workspace), and the first one there is used. Empty starts in the bot's folder itself.`}
onChange={(e) => setRunnerDir(e.target.value)}
/>
<Select
+1
View File
@@ -59,6 +59,7 @@ export default function HookRow({ hook, busy, onOpen, onToggle, onEdit, onCalls,
title={title}
onOpen={onOpen}
badge={badge}
badge_tone={badge == "Runner down" ? "error" : undefined}
subtitle={hookSubtitle({ hook, show_bot: !compact, show_workspace: !compact })}
>
<SettingsRowMenu title={`${title} menu`} disabled={busy}>
+5 -4
View File
@@ -9,7 +9,7 @@ export const HookRunnerProtocol = 1;
* Bump with every change to `HookRunnerScript`: every runner restarts once
* with the new script.
*/
export const HookRunnerVersion = "2";
export const HookRunnerVersion = "3";
/**
* The process keeper the app runs on a computer for a hook's runner
@@ -134,14 +134,15 @@ def stop(runner_id, state, stop_ms):
def start(runner, env, log_max):
runner_id = runner["id"]
cwd = runner["cwd"]
if not os.path.isdir(cwd):
cwds = runner.get("cwds") or [runner["cwd"]]
cwd = next((folder for folder in cwds if os.path.isdir(folder)), None)
if cwd is None:
return {
"id": runner_id,
"pid": None,
"running": False,
"started_at": None,
"error": "Its folder isn't there: %s" % cwd,
"error": "Its folder isn't there: %s" % " or ".join(cwds),
}
log = log_path(runner_id)
try:
@@ -8,7 +8,7 @@ import composeComputerEnvFiles from "@/src/harness/tools/computer/compose-comput
import type { HookRunnerSync } from "@/src/types";
import computerNotReadyMessage from "@/src/utils/computer-not-ready-message";
import computerRunDirs from "@/src/utils/computer-work-dirs";
import hookRunnerDir, { hookRunnerBaseDir, hookRunnerFile } from "@/src/utils/hook-runner-paths";
import { hookRunnerBaseDir, hookRunnerDirs, hookRunnerFile } from "@/src/utils/hook-runner-paths";
import hookRunnerVersion from "@/src/utils/hook-runner-version";
import type { ComputerAddress } from "../computers/grab-computer-target";
import grabComputerTarget from "../computers/grab-computer-target";
@@ -189,7 +189,7 @@ async function runGroup({
workspace_id,
});
const base = hookRunnerBaseDir({ dirs });
const runners: { id: number; command: string; cwd: string; version: string }[] = [];
const runners: { id: number; command: string; cwd: string; cwds: string[]; version: string }[] = [];
const wanted = new Set<number>();
for (const hook of group.hooks) {
@@ -203,7 +203,7 @@ async function runGroup({
user_id: hook.user_id,
workspace_id: hook.workspace_id,
});
const cwd = hookRunnerDir({ dirs: hook_dirs, runner_dir: hook.runner_dir });
const cwds = hookRunnerDirs({ dirs: hook_dirs, runner_dir: hook.runner_dir });
const envs = await grabComputerEnvs({
computer_id: group.computer_id,
bot_id: hook.bot_id,
@@ -213,7 +213,7 @@ async function runGroup({
const version = hookRunnerVersion({
script_version: HookRunnerVersion,
command: hook.runner_command,
dir: cwd,
dir: cwds.join("\n"),
computer_id: group.computer_id,
workspace_id: hook.workspace_id,
envs,
@@ -227,7 +227,7 @@ async function runGroup({
run_as: hook_dirs.run_as,
});
runners.push({ id: Number(hook.id), command: hook.runner_command, cwd, version });
runners.push({ id: Number(hook.id), command: hook.runner_command, cwd: cwds[0]!, cwds, version });
wanted.add(Number(hook.id));
} catch (error) {
await recordRunnerFailure({
@@ -0,0 +1,32 @@
import { Database } from "bun:sqlite";
import { expect, test } from "bun:test";
import closeOrphanBotTasksSql from "./close-orphan-bot-tasks-sql";
/**
* Only an active row whose job is gone or closed is closed. Run against
* real SQLite.
*/
test("closes active rows with no open job", () => {
const db = new Database(":memory:");
db.run(`CREATE TABLE bot_tasks (id INTEGER PRIMARY KEY, status TEXT, updated_at INTEGER)`);
db.run(`CREATE TABLE bots_queue (id INTEGER PRIMARY KEY, task_id INTEGER, status TEXT)`);
db.run(`INSERT INTO bot_tasks VALUES (1, 'active', 10), (2, 'active', 10), (3, 'active', 10),
(4, 'active', 10), (5, 'done', 10), (6, 'active', 500)`);
db.run(`INSERT INTO bots_queue (task_id, status) VALUES (2, 'failed'), (3, 'pending'), (4, 'processing')`);
const { sql, values } = closeOrphanBotTasksSql({ before: 100 });
db.query(sql).run(...values);
const rows = db.query(`SELECT id, status FROM bot_tasks ORDER BY id`).all();
expect(rows).toEqual([
{ id: 1, status: "done" },
{ id: 2, status: "done" },
{ id: 3, status: "active" },
{ id: 4, status: "active" },
{ id: 5, status: "done" },
{ id: 6, status: "active" },
]);
});
@@ -0,0 +1,27 @@
type Params = {
/**
* Rows touched after this (Unix ms) are left alone: a run being queued
* creates its row before its job.
*/
before: number;
};
/**
* Closes every `bot_tasks` row still `active` with no open job behind it.
* A failed run closes its own row now (`notifyBotJobFailed`), but rows
* from before that stayed `active` for months (production: a Morning
* Digest run failed on Nov 20 and a row from Oct 23 whose job was long
* pruned), and an active row keeps its conversation polling for progress
* that never comes.
*/
export default function closeOrphanBotTasksSql({ before }: Params) {
return {
sql: `UPDATE bot_tasks SET status = 'done', updated_at = ?
WHERE status = 'active' AND updated_at < ?
AND NOT EXISTS (
SELECT 1 FROM bots_queue q
WHERE q.task_id = bot_tasks.id AND q.status IN ('pending', 'processing')
)`,
values: [Date.now(), before],
};
}
@@ -0,0 +1,10 @@
import BunSQLite from "@moduletrace/bun-sqlite";
import closeOrphanBotTasksSql from "./close-orphan-bot-tasks-sql";
/**
* Closes `bot_tasks` rows left `active` with no open job, safe on every
* start (`closeOrphanBotTasksSql`).
*/
export default async function closeOrphanBotTasks() {
await BunSQLite.sql(closeOrphanBotTasksSql({ before: Date.now() - 10 * 60 * 1000 }));
}
@@ -58,6 +58,7 @@ export default async function grabHookProposalView({ proposal_id, user_id }: Par
computers: new Map((computers?.payload || []).map((c) => [Number(c.id), c.name || ""])),
bot_id: proposal.bot_id,
bot_kind: bot.payload?.[0]?.kind || null,
user_id: proposal.user_id,
}),
reason: proposal.reason,
};
@@ -68,8 +68,7 @@ export default function proposeHookTool({
onPropose,
}: Params): HarnessTool<Args> {
const dirs = computerRunDirs({ bot_id, bot_kind: is_coordinator ? "coordinator" : null, user_id, workspace_id });
const home_relative = dirs.cwd.slice(dirs.bot_dir.length + 1);
const runner_folder = `relative to your bot folder ${dirs.bot_dir}, NOT to your ~ (${dirs.cwd}): a folder you made at ~/whatsapp is "${home_relative}/whatsapp", and "whatsapp" alone is ${dirs.bot_dir}/whatsapp. Empty: ${dirs.bot_dir} itself`;
const runner_folder = `relative: the app looks in your ~ (${dirs.cwd}) first, then in your bot folder (${dirs.bot_dir}), and starts in the first one that exists, so a folder you made at ~/whatsapp is just "whatsapp". Empty: ${dirs.bot_dir} itself`;
const listed = computers.map((computer) => `${computer.id} (${computer.name || computer.kind})`).join(", ");
return {
@@ -5,6 +5,8 @@ import Row from "@moduletrace/twui/layout/Row";
import Span from "@moduletrace/twui/layout/Span";
import Stack from "@moduletrace/twui/layout/Stack";
import Checkbox from "@moduletrace/twui/form/Checkbox";
import Tag from "@moduletrace/twui/elements/Tag";
import { twMerge } from "tailwind-merge";
type Props = {
avatar: ReactNode;
@@ -21,6 +23,11 @@ type Props = {
* A word beside the title, e.g. "Default" or "You".
*/
badge?: string;
/**
* `error`: the badge is a fault (a runner that is down), drawn as an
* outlined error tag instead of a quiet word.
*/
badge_tone?: "error";
/**
* A mark right after the title, e.g. a workspace admin's shield.
*/
@@ -48,6 +55,7 @@ export default function SettingsListRow({
href,
onOpen,
badge,
badge_tone,
title_icon,
subtitle,
selected,
@@ -58,7 +66,17 @@ export default function SettingsListRow({
<Span className="block text-sm font-bold leading-5 text-ink truncate w-full">
{title}
{title_icon ? <Span className="ml-1.5 inline-flex align-middle">{title_icon}</Span> : null}
{badge ? <Span className="ml-2 text-[11px] font-bold leading-4 text-ink-secondary">{badge}</Span> : null}
{badge && badge_tone == "error" ? (
<Tag
color="error"
variant="outlined"
className={twMerge("ml-2 inline-flex align-middle", "px-1.5 py-0 text-[11px] font-bold leading-4")}
>
{badge}
</Tag>
) : badge ? (
<Span className="ml-2 text-[11px] font-bold leading-4 text-ink-secondary">{badge}</Span>
) : null}
</Span>
);
+4
View File
@@ -12,6 +12,7 @@ import enableForeignKeys from "./functions/backend/db/enable-foreign-keys";
import migrateBotTypes from "./functions/backend/db/bot-types/migrate-bot-types";
import migrateLlmLogs from "./functions/backend/db/logs/migrate-llm-logs";
import clearImplicitSessionLinks from "./functions/backend/db/bot-sessions/clear-implicit-session-links";
import closeOrphanBotTasks from "./functions/backend/db/bots-queue/close-orphan-bot-tasks";
import migrateChatroomsToAsks from "./functions/backend/db/bot-sessions/migrate-chatrooms-to-asks";
import migrateHookSilence from "./functions/backend/db/bot-hooks/migrate-hook-silence";
import migrateFaceWorkspaces from "./functions/backend/db/bots/migrate-face-workspaces";
@@ -53,6 +54,9 @@ await migrateLlmLogs().catch((error) =>
await clearImplicitSessionLinks().catch((error) =>
logError({ title: "Could not clear implicit session links", error }).catch(() => {}),
);
await closeOrphanBotTasks().catch((error) =>
logError({ title: "Could not close orphaned bot tasks", error }).catch(() => {}),
);
await migrateChatroomsToAsks().catch((error) =>
logError({ title: "Could not delete the sessions of old chatrooms", error }).catch(() => {}),
);
@@ -9,6 +9,7 @@ describe("describeHookProposalDetails", () => {
workspace_name: "Launch",
computers: new Map([[3, "Main"]]),
bot_id: 4,
user_id: 1,
});
expect(details).toEqual([
@@ -26,6 +27,7 @@ describe("describeHookProposalDetails", () => {
data: { title: "Slack", instructions: "Answer.", source: "browser_notifications", watch_computer_id: 2 },
computers: new Map([[2, "Desk"]]),
bot_id: 4,
user_id: 1,
});
expect(details.find((d) => d.label == "Called by")?.value).toBe("Browser notifications on Desk (#2)");
@@ -41,6 +43,7 @@ describe("describeHookProposalDetails", () => {
current: { id: 7, title: "GitHub pushes", instructions: "Old brief.", enabled: 0 },
computers: new Map(),
bot_id: 4,
user_id: 1,
});
expect(details.map((d) => d.label)).toEqual(["Hook", "Brief now", "New brief", "Switch on"]);
@@ -61,6 +64,7 @@ describe("describeHookProposalDetails", () => {
},
computers: new Map([[1, "Main"]]),
bot_id: 4,
user_id: 1,
});
expect(details.map((d) => d.label)).toEqual([
@@ -78,7 +82,7 @@ describe("describeHookProposalDetails", () => {
value: "python3 bridge.py",
block: true,
});
expect(details.find((d) => d.label == "Starts in")?.value).toBe("/home/cb-4/workspace/whatsapp");
expect(details.find((d) => d.label == "Starts in")?.value).toBe("/home/cb-4/workspace/users/1/whatsapp, else /home/cb-4/workspace/whatsapp");
expect(details.find((d) => d.label == "Runs it on")?.value).toContain("Main (#1)");
});
@@ -89,26 +93,28 @@ describe("describeHookProposalDetails", () => {
current: { id: 7, title: "WhatsApp", instructions: "Answer.", enabled: 1 },
computers: new Map([[1, "Main"]]),
bot_id: 4,
user_id: 1,
});
expect(details.map((d) => d.label)).toEqual(["Hook", "Runner now", "New runner", "Will start in", "Runs it on"]);
expect(details[1]?.value).toBe("None");
expect(details[2]?.value).toBe("python3 bridge.py");
expect(details[3]?.value).toBe("/home/cb-4/workspace/whatsapp");
expect(details[3]?.value).toBe("/home/cb-4/workspace/users/1/whatsapp, else /home/cb-4/workspace/whatsapp");
expect(details[4]?.value).toBe("Main (#1)");
});
test("a runner moved to another folder shows both absolute paths", () => {
const details = describeHookProposalDetails({
action: "change",
data: { runner_command: "./run.sh", runner_dir: "users/1/whatsapp" },
data: { runner_command: "./run.sh", runner_dir: "bridge" },
current: { id: 2, title: "WhatsApp", enabled: 1, runner_command: "./run.sh", runner_dir: "whatsapp", runner_computer_id: 1 },
computers: new Map([[1, "Main"]]),
bot_id: 4,
user_id: 1,
});
expect(details.find((d) => d.label == "Starts in now")?.value).toBe("/home/cb-4/workspace/whatsapp");
expect(details.find((d) => d.label == "Will start in")?.value).toBe("/home/cb-4/workspace/users/1/whatsapp");
expect(details.find((d) => d.label == "Starts in now")?.value).toBe("/home/cb-4/workspace/users/1/whatsapp, else /home/cb-4/workspace/whatsapp");
expect(details.find((d) => d.label == "Will start in")?.value).toBe("/home/cb-4/workspace/users/1/bridge, else /home/cb-4/workspace/bridge");
});
test("the coordinator's runner starts in its folder in the computer's workspace", () => {
@@ -118,9 +124,10 @@ describe("describeHookProposalDetails", () => {
current: { id: 2, title: "Bridge", enabled: 1 },
computers: new Map(),
bot_id: 1,
user_id: 1,
bot_kind: "coordinator",
});
expect(details.find((d) => d.label == "Will start in")?.value).toBe("/home/gem/workspace/bots/1/bridge");
expect(details.find((d) => d.label == "Will start in")?.value).toBe("/home/gem/workspace/bots/1/users/1/bridge, else /home/gem/workspace/bots/1/bridge");
});
});
+6 -1
View File
@@ -25,6 +25,10 @@ type Params = {
*/
bot_id: number | string;
bot_kind?: string | null;
/**
* Whose hook it is: a runner looks in their folder first.
*/
user_id: number | string;
};
/**
@@ -41,9 +45,10 @@ export default function describeHookProposalDetails({
computers,
bot_id,
bot_kind,
user_id,
}: Params): ExtensionProposalDetail[] {
const computer = (id?: number | null) => (id ? `${computers.get(Number(id)) || "Computer"} (#${id})` : "");
const folder = (dir?: string | null) => hookRunnerStartPath({ bot_id, bot_kind, runner_dir: dir }) || dir || "";
const folder = (dir?: string | null) => hookRunnerStartPath({ bot_id, bot_kind, user_id, runner_dir: dir }) || dir || "";
if (action == "create") {
const watching = data.source == "browser_notifications";
+4 -4
View File
@@ -28,7 +28,7 @@ describe("describeHookRunner", () => {
},
});
expect(text).toContain("runner `./run.sh` starts in \"whatsapp\" inside the bot's folder (not your ~) on computer 1");
expect(text).toContain("runner `./run.sh` starts in \"whatsapp\" inside your ~ or the bot's folder on computer 1");
expect(text).toContain("NOT RUNNING, the check failed (last checked 2026-11-30T08:05:00.000Z)");
expect(text).toContain("Its folder isn't there: /home/cb-4/workspace/whatsapp");
expect(text).toContain("propose_hook");
@@ -46,16 +46,16 @@ describe("describeHookRunner", () => {
},
}),
).toBe(
"runner `./run.sh` starts in the bot's folder (not your ~): running since 2026-11-30T08:00:00.000Z, last checked 2026-11-30T08:05:00.000Z",
"runner `./run.sh` starts in the bot's folder: running since 2026-11-30T08:00:00.000Z, last checked 2026-11-30T08:05:00.000Z",
);
});
test("gives the absolute folder when it knows the bot", () => {
const text = describeHookRunner({
hook: { ...base, bot_id: 4, bot_kind: "worker", runner_command: "./run.sh", runner_dir: "whatsapp", runner_last_error: "x" },
hook: { ...base, bot_id: 4, user_id: 1, bot_kind: "worker", runner_command: "./run.sh", runner_dir: "whatsapp", runner_last_error: "x" },
});
expect(text).toContain('starts in /home/cb-4/workspace/whatsapp (runner_dir "whatsapp", relative to the bot\'s folder, not your ~)');
expect(text).toContain('starts in /home/cb-4/workspace/users/1/whatsapp, else /home/cb-4/workspace/whatsapp (runner_dir "whatsapp": your ~ first, else the bot\'s folder)');
});
test("is part of the hook a bot lists", () => {
+11 -6
View File
@@ -8,8 +8,8 @@ type Params = {
/**
* A hook's runner as a bot reads it, from what the last check stored
* (`syncHookRunners`): the command, the folder it starts in (inside the
* bot's folder, which is not a run's `~`), whether it is up, and when it
* (`syncHookRunners`): the command, the folder it starts in (the owner's
* `~` first, else the bot's folder), whether it is up, and when it
* isn't, why the check failed. Empty when the hook keeps no runner.
*
* A failed check says the fix is the runner itself, through a proposal:
@@ -21,13 +21,18 @@ export default function describeHookRunner({ hook }: Params) {
if (!state.configured) return "";
const folder = hook.bot_id
? hookRunnerStartPath({ bot_id: hook.bot_id, bot_kind: hook.bot_kind, runner_dir: hook.runner_dir })
const folder = hook.bot_id && hook.user_id
? hookRunnerStartPath({
bot_id: hook.bot_id,
bot_kind: hook.bot_kind,
user_id: hook.user_id,
runner_dir: hook.runner_dir,
})
: null;
const where = [
folder
? `starts in ${folder} (runner_dir "${hook.runner_dir || ""}", relative to the bot's folder, not your ~)`
: `starts in ${hook.runner_dir ? `"${hook.runner_dir}" inside the bot's folder` : "the bot's folder"} (not your ~)`,
? `starts in ${folder} (runner_dir "${hook.runner_dir || ""}": your ~ first, else the bot's folder)`
: `starts in ${hook.runner_dir ? `"${hook.runner_dir}" inside your ~ or the bot's folder` : "the bot's folder"}`,
hook.runner_computer_id ? `on computer ${hook.runner_computer_id}` : "",
]
.filter(Boolean)
+63 -15
View File
@@ -17,32 +17,80 @@ type Params = {
* anything about secrets), for a change what's different from the saved
* one, then the whole runbook as plain text.
*/
export default function describeSkillProposal({ data, current }: Params): ExtensionProposalDetail[] {
const found = findSkillMentions({ text: [data.description, data.body].join("\n") });
const changed = ({ now, was }: { now: string; was?: string }) => (current && was != now ? `${now} (was: ${was || "empty"})` : now);
export default function describeSkillProposal({
data,
current,
}: Params): ExtensionProposalDetail[] {
const found = findSkillMentions({
text: [data.description, data.body].join("\n"),
});
const changed = ({ now, was }: { now: string; was?: string }) =>
current && was != now ? `${now} (was: ${was || "empty"})` : now;
return [
{ label: "Name", value: changed({ now: data.name, was: current?.name }) },
{ label: "Slug", value: changed({ now: data.slug, was: current?.slug }) },
{ label: "When it applies", value: changed({ now: data.description, was: current?.description }) },
{ label: "Links in it", value: found.urls.join("\n") || "none", block: found.urls.length > 0 },
{ label: "Hosts", value: found.hosts.join(", ") || "none" },
{ label: "Tool names", value: found.tools.join(", ") || "none" },
{ label: "About secrets", value: found.secrets.join(", ") || "nothing" },
{
label: "Name",
value: changed({ now: data.name, was: current?.name }),
},
{
label: "Slug",
value: changed({ now: data.slug, was: current?.slug }),
},
{
label: "When it applies",
value: changed({
now: data.description,
was: current?.description,
}),
},
{
label: "Links in it",
value: found.urls.join("\n") || "none",
block: found.urls.length > 0,
},
{
label: "Hosts",
value: found.hosts.join(", ") || "none",
},
{
label: "Tool names",
value: found.tools.join(", ") || "none",
},
{
label: "About secrets",
value: found.secrets.join(", ") || "nothing",
},
...(current
? [
{
label: "Runbook changes",
value: diffLines({ before: current.body, after: data.body }) || "None: the runbook is the same",
value:
diffLines({
before: current.body,
after: data.body,
}) || "None: the runbook is the same",
block: current.body != data.body,
},
mardown: true,
} as ExtensionProposalDetail,
]
: []),
{ label: "Runbook", value: data.body, block: true, markdown: true },
{ label: "Starts", value: data.enabled ? "On" : "Off" },
{
label: "Runbook",
value: data.body,
block: true,
markdown: true,
},
{
label: "Starts",
value: data.enabled ? "On" : "Off",
},
{
label: "Who gets it",
value: data.all_bots ? "Every bot, now and new" : current ? "As it is now" : "No bot until it's given to some",
value: data.all_bots
? "Every bot, now and new"
: current
? "As it is now"
: "No bot until it's given to some",
},
];
}
+30 -2
View File
@@ -1,7 +1,7 @@
import { describe, expect, test } from "bun:test";
import { BotHookRunnerDir } from "@/src/dict/bot-hook-dict";
import type { ComputerRunDirs } from "@/src/utils/computer-work-dirs";
import hookRunnerDir, { hookRunnerBaseDir, hookRunnerFile } from "./hook-runner-paths";
import hookRunnerDir, { hookRunnerBaseDir, hookRunnerDirs, hookRunnerFile } from "./hook-runner-paths";
const dirs = {
bot_dir: "/home/gem/workspace/bots/3",
@@ -69,4 +69,32 @@ describe("hookRunnerDir", () => {
test("refuses a null byte", () => {
expect(() => hookRunnerDir({ dirs, runner_dir: "whats\0app" })).toThrow("null byte");
});
});
});
/**
* A runner looks in its owner's `~` first (where a bot builds a bridge it
* was asked for), then in the bot's folder, so "whatsapp" finds
* `~/whatsapp` and a folder given the old way still works.
*/
describe("hookRunnerDirs", () => {
test("a relative folder is tried in the owner's ~, then in the bot's folder", () => {
expect(hookRunnerDirs({ dirs, runner_dir: "whatsapp" })).toEqual([
"/home/gem/workspace/bots/3/users/1/whatsapp",
"/home/gem/workspace/bots/3/whatsapp",
]);
});
test("a folder given from the bot's folder still resolves there", () => {
expect(hookRunnerDirs({ dirs, runner_dir: "users/1/whatsapp" })).toEqual([
"/home/gem/workspace/bots/3/users/1/users/1/whatsapp",
"/home/gem/workspace/bots/3/users/1/whatsapp",
]);
});
test("empty is the bot's folder alone", () => {
expect(hookRunnerDirs({ dirs, runner_dir: "" })).toEqual([dirs.bot_dir]);
});
test("refuses what hookRunnerDir refuses", () => {
expect(() => hookRunnerDirs({ dirs, runner_dir: "../x" })).toThrow("has to stay inside the bot's folder");
});
});
+19
View File
@@ -44,4 +44,23 @@ export default function hookRunnerDir({ dirs, runner_dir }: { dirs: ComputerRunD
}
return parts.length ? path.posix.join(dirs.bot_dir, ...parts) : dirs.bot_dir;
}
/**
* The folders a runner may start in, in the order the keeper tries them
* (it starts in the first one there): the hook owner's own folder in the
* bot's (`users/<user>`, the run's `~`, where a bot builds what it was
* asked for), then the bot's folder. So "whatsapp" finds a bridge a bot
* made at `~/whatsapp`, and a folder given from the bot's folder
* (`users/1/whatsapp`, as hooks were set before) still works. Empty is
* the bot's folder alone. Refused the same way as `hookRunnerDir`.
*/
export function hookRunnerDirs({ dirs, runner_dir }: { dirs: ComputerRunDirs; runner_dir?: string | null }) {
const in_bot = hookRunnerDir({ dirs, runner_dir });
if (in_bot == dirs.bot_dir || dirs.cwd == dirs.bot_dir) return [in_bot];
const in_home = path.posix.join(dirs.cwd, path.posix.relative(dirs.bot_dir, in_bot));
return [in_home, in_bot];
}
+14 -9
View File
@@ -1,5 +1,5 @@
import computerRunDirs from "./computer-work-dirs";
import hookRunnerDir from "./hook-runner-paths";
import { hookRunnerDirs } from "./hook-runner-paths";
type Params = {
bot_id: number | string;
@@ -8,22 +8,27 @@ type Params = {
* a worker's is `/home/cb-<id>/workspace`.
*/
bot_kind?: string | null;
/**
* The hook's owner: the runner looks in their folder (`users/<user>`)
* first.
*/
user_id: number | string;
runner_dir?: string | null;
};
/**
* The absolute folder a hook's runner starts in, as the bot's account sees
* it, the same way `syncHookRunners` works it out: `runner_dir` is relative
* to the bot's folder, which is not a run's `~` (that is `users/<user>`
* inside it), so a card or a bot reading only "whatsapp" can't tell which
* folder it means. Null when the folder would be refused (absolute, `~`,
* climbing out), so the caller shows what was given instead.
* it, the same way `syncHookRunners` works it out (`hookRunnerDirs`): the
* owner's folder (the run's `~`) first, else the bot's folder, written as
* "A, else B" so a card or a bot reading only "whatsapp" knows where it
* looks. Null when the folder would be refused (absolute, `~`, climbing
* out), so the caller shows what was given instead.
*/
export default function hookRunnerStartPath({ bot_id, bot_kind, runner_dir }: Params) {
export default function hookRunnerStartPath({ bot_id, bot_kind, user_id, runner_dir }: Params) {
try {
const dirs = computerRunDirs({ bot_id, bot_kind, user_id: 0 });
const dirs = computerRunDirs({ bot_id, bot_kind, user_id });
return hookRunnerDir({ dirs, runner_dir });
return hookRunnerDirs({ dirs, runner_dir }).join(", else ");
} catch {
return null;
}
+16
View File
@@ -0,0 +1,16 @@
import { describe, expect, test } from "bun:test";
import providerRetryAt from "./provider-retry-at";
describe("providerRetryAt", () => {
test("caps a far reset at the model rest", () => {
expect(providerRetryAt({ retry_at: 9 * 86_400_000, rest_ms: 30_000, now: 0 })).toBe(30_000);
});
test("keeps a provider time sooner than the rest", () => {
expect(providerRetryAt({ retry_at: 5_000, rest_ms: 30_000, now: 0 })).toBe(5_000);
});
test("follows the provider when the rest is unlimited", () => {
expect(providerRetryAt({ retry_at: 86_400_000, rest_ms: Infinity, now: 0 })).toBe(86_400_000);
});
});
+23
View File
@@ -0,0 +1,23 @@
type Params = {
/**
* When the provider said to come back (`HarnessError.retry_at`).
*/
retry_at: number;
/**
* The install's model rest, in ms (`grabModelRestMs`; `Infinity` when
* unlimited).
*/
rest_ms: number;
now?: number;
};
/**
* When a failed job may be retried after a provider named a time to come
* back: no later than the model rest, the same cap its models are benched
* under. A quota that resets in nine days once held a routine's retry for
* a full day (`AppData.HarnessMaxCooldownMs`) while its other model was
* free again in 30 seconds, and the next day's run was skipped behind it.
*/
export default function providerRetryAt({ retry_at, rest_ms, now = Date.now() }: Params) {
return Math.min(retry_at, now + rest_ms);
}