mirror of
https://github.com/bitbaum/loki.git
synced 2026-12-04 05:37:19 +01:00
Found by a review of the merged fresh-session change (2026-11-12):
- A retry (automatic after a refusal, or from Watch) re-sent a one-off as an
ordinary message, into the shared session. It is retried as a one-off.
- /api/control closed the project's newest run from the SHARED session's
handoff without checking whether it was a lane run, so a one-off could be
closed with the shared session's summary, announced to its caller, and
left running. A lane run closes only from its own session file.
- A one-off's prompt carried the project's escalation note ("diagnose the
last failure") and, on the local runtime, the shared session's last
handoff and an instruction to update the shared session file.
- A one-off's close advanced or cleared the project's escalation ladder.
- On the local runtime the shared tab's prompt and handshake files were
written for a one-off, even when the request was then refused.
- OrangeCat's separateSession asked for a lane, which quietly queued in the
shared session when no lane was free. It is a fresh session now: a
session of its own, or a refusal with the reason.
scripts/test/one-off-stays.ts.
Claude-Session: https://claude.ai/code/session_019MDtmtHxn2FxY2x8pJ83Xj
Co-authored-by: Claude <noreply@anthropic.com>
124 lines
4.6 KiB
TypeScript
124 lines
4.6 KiB
TypeScript
/**
|
|
* The probe path: a read-only request sent through POST /api/inject or the MCP
|
|
* loki_dispatch, asking for the cloud builder, ends Done and creates no
|
|
* Needs you.
|
|
*
|
|
* Found by a review of the path end to end (2026-11-12):
|
|
* - every run's status went through the feedback-fix mapper, which calls a
|
|
* run that finished well with no pull request "Needs you, nothing shipped";
|
|
* - neither entry point could ask for the cloud builder (zod drops unknown
|
|
* keys, so `builderChannel` vanished without a word);
|
|
* - a fresh session refused for lack of a free lane counted as a failing run
|
|
* and could page the owner after four.
|
|
*
|
|
* Run: npx tsx scripts/test/probe-path.ts
|
|
*/
|
|
import { readFileSync } from "fs";
|
|
import { join } from "path";
|
|
import { CANONICAL_CAUSE, CANONICAL_STATE, canonicalStatus } from "@/lib/feedback/canonical-status";
|
|
import { FEEDBACK_WORK_PHASE, WAITING_ON, type FeedbackWorkView } from "@/lib/feedback/work-phase";
|
|
import { FIX_SHIP_STATE } from "@/lib/feedback/fix-shipping";
|
|
|
|
let failures = 0;
|
|
function check(name: string, fn: () => void) {
|
|
try {
|
|
fn();
|
|
console.log(` ✓ ${name}`);
|
|
} catch (err) {
|
|
failures++;
|
|
console.log(` ✗ ${name}`);
|
|
console.log(` ${err instanceof Error ? err.message : String(err)}`);
|
|
}
|
|
}
|
|
function assert(cond: boolean, msg: string) {
|
|
if (!cond) throw new Error(msg);
|
|
}
|
|
const read = (rel: string) => readFileSync(join(process.cwd(), rel), "utf8");
|
|
|
|
/** A run that closed well, and the ledger found nothing on GitHub. */
|
|
const finishedNothingPushed: FeedbackWorkView = {
|
|
phase: FEEDBACK_WORK_PHASE.NEEDS_VERIFY,
|
|
waitingOn: WAITING_ON.YOU,
|
|
label: "x",
|
|
detail: null,
|
|
ship: { state: FIX_SHIP_STATE.NO_EVIDENCE, checkedAt: "2026-11-12T05:00:00Z" },
|
|
};
|
|
|
|
check("the incident: a git status probe that finished well is Done, not Needs you", () => {
|
|
const got = canonicalStatus(finishedNothingPushed, { expectsChange: false });
|
|
assert(got.state === CANONICAL_STATE.DONE, `state ${got.state}`);
|
|
assert(got.cause === CANONICAL_CAUSE.FINISHED_NO_CHANGE, `cause ${got.cause}`);
|
|
assert(got.nextAction.who === WAITING_ON.NOBODY, `who ${got.nextAction.who}`);
|
|
assert(got.reason === null, "a Done carries a problem sentence");
|
|
});
|
|
|
|
check("a feedback fix with nothing shipped still needs you, as before", () => {
|
|
for (const opts of [{}, { expectsChange: true }]) {
|
|
const got = canonicalStatus(finishedNothingPushed, opts);
|
|
assert(got.state === CANONICAL_STATE.NEEDS_YOU, `state ${got.state}`);
|
|
assert(got.cause === CANONICAL_CAUSE.NOTHING_SHIPPED, `cause ${got.cause}`);
|
|
}
|
|
});
|
|
|
|
check(
|
|
"a run that is not a fix but pushed a branch without a pull request is still followed",
|
|
() => {
|
|
const got = canonicalStatus(
|
|
{ ...finishedNothingPushed, ship: { state: FIX_SHIP_STATE.PUSHED, checkedAt: "x" } },
|
|
{ expectsChange: false },
|
|
);
|
|
assert(got.state === CANONICAL_STATE.NEEDS_YOU, "a pushed branch with no PR was hidden");
|
|
},
|
|
);
|
|
|
|
check("the run's status loader asks whether the run is a feedback fix", () => {
|
|
const src = read("src/lib/run-track-load.ts");
|
|
assert(/expectsChange: Boolean\(feedbackFix\),/.test(src), "not passed");
|
|
assert(
|
|
/getFeedbackByRunId\(userId, run\.id\)\.then\(\s*\(row\) => row !== null,\s*\(\) => true,/.test(
|
|
src,
|
|
),
|
|
"a failed lookup must keep the old rule",
|
|
);
|
|
});
|
|
|
|
check("POST /api/inject can ask for the cloud builder", () => {
|
|
const src = read("src/app/api/inject/route.ts");
|
|
assert(/builderChannel: z\.enum\(BUILDER_CHANNELS\)\.optional\(\),/.test(src), "schema");
|
|
assert(/\.\.\.\(builderChannel \? \{ builderChannel \} : \{\}\),/.test(src), "not passed on");
|
|
});
|
|
|
|
check("MCP loki_dispatch can ask for the cloud builder", () => {
|
|
const tools = read("src/lib/mcp/tools.ts");
|
|
assert(/builder: z\s*\.enum\(\["cloud", "local"\]\)/.test(tools), "schema");
|
|
assert(
|
|
/args\.builder \? \{ builderChannel: args\.builder \} : \{\}/.test(tools),
|
|
"not passed on",
|
|
);
|
|
assert(
|
|
/opts\?\.builderChannel \? \{ builderChannel: opts\.builderChannel \} : \{\}/.test(
|
|
read("src/lib/mcp/services.ts"),
|
|
),
|
|
"the service drops it",
|
|
);
|
|
});
|
|
|
|
check("a fresh session refused for lack of a lane is not a failing run", () => {
|
|
const core = read("src/lib/inject-core.ts");
|
|
assert(
|
|
/ladder: \(result as \{ code\?: string \}\)\.code !== "fresh-session-unavailable",/.test(core),
|
|
"inject",
|
|
);
|
|
const q = read("src/db/queries/orchestration-runs.ts");
|
|
assert(
|
|
/opts\.ladder !== false &&\s*ladderEffectForClose\(closed\.outcome(, closed)?\)/.test(q),
|
|
"close",
|
|
);
|
|
});
|
|
|
|
if (failures) {
|
|
console.log(`\nprobe-path: ${failures} failed`);
|
|
process.exit(1);
|
|
}
|
|
console.log("\nprobe-path: all passed");
|