Files
loki/scripts/test/feedback-auto-reimplement.ts
CatoandClaude 5b0f93f117 feat(copy): the machine that runs the work is a runner, not a builder (#1482)
"Builder" meant three things on Loki's screens: the machine that runs
agent work ("Cloud builder", "Waiting for a builder"), the role on a
project, and the approved builder a customer books through Bitbaum. The
person keeps the word; the machine becomes a runner, the word the code
and the desktop app already use (box-runner, Fleet Runner, "Hosted
runner"). Not "engine": on screen that is already the model and
subscription a change is built with.

- every user-facing string where "builder" meant the machine, with
  EXECUTOR_COPY as the source, plus docs, quickstart, pricing and voice
- unchanged: the Builder role, "a builder or owner can start work",
  people who build ("App builders", "for one builder running Loki"),
  the site widget's "Send to builder" (the site's maker), stored
  transcript parsing, and internal codes and paths (needs-builder,
  cloud-builder-private, /api/builder/presence)
- tests that pin the wording follow it


Claude-Session: https://claude.ai/code/session_019MDtmw5m9WhdN77N2YeqDm

Co-authored-by: Claude <noreply@anthropic.com>
2026-10-30 22:30:16 +01:00

121 lines
4.5 KiB
TypeScript

// A feedback run refused at its last step gets one automatic second attempt —
// and only the failures a second attempt can answer.
import assert from "node:assert/strict";
import {
decideAutoReimplement,
autoRetryNotice,
} from "../../src/lib/feedback/auto-reimplement-policy";
import { deriveFeedbackWork, FEEDBACK_WORK_PHASE } from "../../src/lib/feedback/work-phase";
import { autoDispatchEnabledIn } from "../../src/lib/auto-dispatch";
// Nothing runs on the operator's quota unasked unless the box says so, exactly.
assert.equal(autoDispatchEnabledIn({}), false, "default is off");
assert.equal(autoDispatchEnabledIn({ LOKI_AUTO_DISPATCH: "true" }), false, "only the literal 1");
assert.equal(autoDispatchEnabledIn({ LOKI_AUTO_DISPATCH: "0" }), false);
assert.equal(autoDispatchEnabledIn({ LOKI_AUTO_DISPATCH: "1" }), true);
import { FEEDBACK_STATUS } from "../../src/lib/constants/statuses";
import { ORCH_STATE } from "../../src/lib/orchestration/contract";
const CAPACITY =
"Dispatch failed before the prompt reached the agent: claude cannot generate because its usage limit is exhausted. Switch this project to a provider with available capacity, then Retry.";
const NO_GEN =
"launched claude (pty) + injected, but Loki could not verify generation. claude opened on this computer, but produced no response after Loki submitted the prompt.";
const AUTH =
"claude is not authenticated (401 / login required) — the prompt was delivered but the agent can't run.";
const WORKSPACE =
'workspace for "petvity" is not materializable on this runner: /home/g/dev/petvity does not exist here and the project has no cloneable GitHub gitUrl.';
assert.deepEqual(decideAutoReimplement(CAPACITY, null), {
retry: true,
because: "the agent ran out of quota",
failover: true,
failoverWhy: "ran out of quota",
});
assert.deepEqual(decideAutoReimplement(NO_GEN, {}), {
retry: true,
because: "the agent opened but never accepted the prompt, so it runs on the next provider",
failover: true,
failoverWhy: "never accepted the prompt",
});
assert.equal(decideAutoReimplement(AUTH, null).retry, false, "dead credentials need a person");
assert.equal((decideAutoReimplement(AUTH, null) as { reason: string }).reason, "needs-auth");
assert.equal(
(decideAutoReimplement(WORKSPACE, null) as { reason: string }).reason,
"needs-workspace",
);
assert.deepEqual(
decideAutoReimplement("runner error", null),
{ retry: true, because: "the first attempt was refused by the runner" },
"an unclassified refusal earns exactly one more attempt",
);
assert.equal(
(
decideAutoReimplement("dispatch payload missing required string tab", null) as {
reason: string;
}
).reason,
"not-retryable",
"a command the runner could not read reads the same twice",
);
assert.equal(
(decideAutoReimplement("Bridge rejected token (HTTP 401)", null) as { reason: string }).reason,
"needs-auth",
);
assert.equal((decideAutoReimplement("", null) as { reason: string }).reason, "no-error");
assert.equal(
decideAutoReimplement(CAPACITY, { priorRunId: "abc" }).retry,
true,
"a quota wall chains to the next provider even on a retry",
);
assert.equal(
decideAutoReimplement(NO_GEN, { priorRunId: "abc" }).retry,
true,
"a prompt the agent never accepted chains to the next provider too",
);
assert.equal(
(decideAutoReimplement("runner error", { priorRunId: "abc" }) as { reason: string }).reason,
"already-retried",
"any other retry is never retried",
);
assert.equal(
(
decideAutoReimplement(CAPACITY, { feedbackAutoRetriedAt: "2026-09-28T06:35:00Z" }) as {
reason: string;
}
).reason,
"already-retried",
);
// The row says Loki acted, while the second run moves.
{
const now = Date.parse("2026-09-28T06:40:00Z");
const view = deriveFeedbackWork(
FEEDBACK_STATUS.DISPATCHED,
{
id: "r2",
state: ORCH_STATE.WAITING,
outcome: null,
startedAt: new Date(now - 10_000),
finishedAt: null,
deliveredAt: null,
lastProgressAt: null,
blocked: null,
injectVerified: null,
injectWarning: null,
error: null,
summaryDone: null,
autoRetriedBecause: "the agent hit its usage limit",
pendingUnclaimed: true,
cloudOnline: true,
localOnline: false,
builderChannel: "cloud",
},
now,
);
assert.equal(view.phase, FEEDBACK_WORK_PHASE.QUEUED);
assert.equal(view.detail, autoRetryNotice("the agent hit its usage limit"));
assert.match(view.detail!, /^Retried automatically/);
}
console.log("feedback-auto-reimplement: ok");