@quikit/quikpilot-runner 9.3.0-rc.65 → 9.3.0-rc.67

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -172,6 +172,10 @@ wrong (a field that arrives from a database row or a request), so it only warns
172
172
 
173
173
  **9.3.0-rc.62 - an approved test that is reported again is refused with what to do (QUIKTR-1951).** When a person has approved a change to an existing test and the AI reports that test again before the final test run (a second row of a table test that still expects the old behaviour), the answer was only `already_decided`: "Do not report it again". It now also says what the AI can do: finish the code first, and if rows of that test still fail in the final test run, the fix step that follows may report the test once more (QUIKTR-1844). Nothing about WHEN a test can be reported changes, so a person is still asked only when there is evidence; a test a person judged right, or reported in another file, keeps the bare refusal exactly. A new log event `codegen.conflict_refused_approved` (phase only) counts how often it happens. No change to the contract with the AI service. The AI Runtime's QUIKTR-1952 (a hung OpenRouter call is cut at 150 s for QuikPilot calls, so the backup model answers inside the runner's turn limit) ships with this version and needs no runner setting.
174
174
 
175
+ **9.3.0-rc.67 - before its tests are frozen, the AI is asked once to check WHY each bug test fails on the old code (QUIKTR-2058; off unless `QUIKPILOT_RED_REVIEW=on`).** Phase 1 ends only once each bug case's own test is seen failing on the code before any change (QUIKTR-1608), and any failure counted. In QuikIT run QTRIA-34 (3 Nov) two bug tests failed there with "expected 500 to be 409" because they never set up a mock the code needs, so the code crashed while the old code really answers 200; the check accepted them, the tests were frozen, and the code phase could never make them pass. In QTRIA-35 (same bug) the AI saw this in the failure text by itself and fixed its test. With the switch on, the first phase-1 DONE that gets past the red check (whatever that check found: in QTRIA-34 its one send-back went to a test that must keep working) is sent back once, as a refused turn with rule word `done_rule`, quoting the first line of each bug case's failure on the code as it is (`[id] fails on the code as it is with: ...`, the job's secrets scrubbed, at most 7 cases) and asking the AI to confirm each shows the bug, not a broken test (a missing mock or stub, an error in the test's own set-up, a crash the bug does not cause); a broken one is fixed and run again, otherwise the AI answers DONE again. It is never sent on a final turn, nor when no failure text is there to quote (`no_message`: a one-file run with no report, no baseline run), nor when no test run is left to show a corrected test failing (`no_runs_left`); a give-up with red tests is not reviewed. The red check and its own counter are unchanged. Logs (counts, never text): `codegen.red_check` `review_sent`, `review_skipped` (with `reason`), and `review_answered` (`testsChanged`, `rerun`, `linesChanged`, `linesSame`, `linesGone`) at the next answer; `red_review.on` once per job. Only with two phases; a fix and the review fix never get it. With the switch off every request is byte-for-byte what rc.66 sent. Nothing changes on the AI Runtime (it never reads a refused sentence's text) or in QuikProjects (the run record keeps rule words only). Also in rc.67: everything in rc.66.
176
+
177
+ **9.3.0-rc.66 - the early look's report is tried again when QuikProjects cannot take it (QUIKTR-1999).** On 2 Nov two early looks (QuikIT Q2, QuikSplit S5) finished their work and then logged `investigate.failed report_failed`: the one report to QuikProjects failed once, while several runs overlapped and its database was busy, and was never tried again, so the look was lost and the run waited out its 200 s. The report now follows the rule the main callback got in rc.43, with a longer wait: a server error (500/502/503/504) or a dropped connection is tried again, 6 tries in all, waiting 2, 5, 10, 20 and 30 s (about 67 s, because the database stalls seen on 2 Nov and in the stress test lasted over 75 s), sending the same bytes each time; any other answer (a refusal such as 403) is final. When it still fails, the job log says which status the server last answered (`status`) or which connection error it was (`error`), next to the same closed reason as before. The main callback (`reportBack`) is unchanged. Needs the QuikProjects change from the same ticket to be most useful (it answers a busy database with 503 + Retry-After instead of a bare 500 or a 403), but works without it. Also in rc.66: everything in rc.65.
178
+
175
179
  **9.3.0-rc.65 - the one correction of QuikPilot's own test now works on Python and Go (QUIKTR-2000).** When the code phase gives up because exactly one of the tests QuikPilot wrote itself still fails, it gets one chance to correct that test's expected value (QUIKTR-1608). Until now the runner recognised the failing test only by its file path, but pytest names a test by its module (`tests.test_grouping`) and gotestsum by its package, so on those languages the correction never ran: sqlparse run QTPY-15 (2 Nov) logged `frozenFailing: 0, amendFiles: 0` with exactly one of its own tests failing, and failed with no PR. Both places that match failing tests to the run's frozen tests (the amendment and the hand-over of a DONE whose own test still fails) now use the rule QUIKTR-1950 uses for the same names (`idPlaceMatches`); a path name is matched exactly as before. When several frozen files share the test's place (a Go or Java package), the one whose text defines the test is chosen, and when that is not exactly one file nothing is amended. The give-up log line also says how many failing tests the last run listed (`failingSeen`). Nothing changes on the AI Runtime or in QuikProjects; `QUIKPILOT_ROW_NAMES=js` gives back the old path-only matching. Also in rc.65: everything in rc.64.
176
180
 
177
181
  **9.3.0-rc.64 - every re-read of a file says why it happened, and (switched off by default) the files the AI is working in are no longer shrunk while it works on them (QUIKTR-1963).** In QuikIT bug 3 (31 Oct) the AI read the same 429-line test file 28 times in 40 turns and gave up. On the notes versions an answer older than the latest three turns is shrunk to a one-line stub on every turn, whatever the request's size, with no exception for the file being worked on; but some re-reads came one turn later, so paging through the file or indecision may be part of it. (1) Always on, log only: each `read_file` on the turn line now carries its line range, and a read of a file already read in the loop logs `codegen.reread` with the earlier read's turn and range, how the two ranges meet (`same`, `overlapping`, `disjoint`), what had become of the earlier answer (`whole`, `stubbed`, `dropped`, `after_write`) and whether it was answered as a repeat; `codegen.reread_summary` counts them at the loop's end. Paths and line numbers only, never file text. (2) `QUIKPILOT_KEEP_WORKING_FILES=on` (off by default; the workflow can set it): the newest answer per range of the files the AI is working in (a file it changed, or read in two different turns; at most three files and 40,000 characters, newest first) stays whole instead of shrinking, and only answers made after the file's latest change count, so a stale read is never kept; a repeat's copy of an earlier answer can then shrink like the answer itself. The hard ceiling's last-resort drop still drops anything, so a request never exceeds today's limit. With the switch off every request the AI Runtime receives is what it was. Nothing changes on the AI Runtime or in QuikProjects. Also in rc.64: everything in rc.63.
package/dist/index.js CHANGED
@@ -47297,6 +47297,40 @@ var ReadTracker = class {
47297
47297
  }
47298
47298
  };
47299
47299
 
47300
+ // src/redReview.ts
47301
+ var RED_REVIEW_ENV = "QUIKPILOT_RED_REVIEW";
47302
+ function redReviewOn(env2 = process.env) {
47303
+ return env2[RED_REVIEW_ENV]?.trim().toLowerCase() === "on";
47304
+ }
47305
+ var MAX_REVIEW_CASES = MAX_REFUSED_SENTENCES - 1;
47306
+ var REVIEW_MESSAGE = "Before your tests are frozen, check why each one fails on the code as it is. Each sentence but the last quotes the first line of a bug case's failure there. This check is made once.";
47307
+ var REVIEW_CLOSING = "For each one, confirm the failure shows the bug its case describes and not a broken test (a missing mock or stub, an error in the test's own set-up, a crash the bug does not cause). Fix and run again any test that fails for another reason; otherwise answer DONE again.";
47308
+ var MAX_QUOTE_CHARS = 200;
47309
+ var MIN_QUOTE_CHARS = 20;
47310
+ function failureFor(id, runs, covers) {
47311
+ for (let i3 = runs.length - 1; i3 >= 0; i3 -= 1) {
47312
+ const run3 = runs[i3];
47313
+ const messages = run3.answer?.messages;
47314
+ if (!messages) continue;
47315
+ for (const name2 of run3.failing) {
47316
+ if (!covers(name2, id)) continue;
47317
+ const text3 = messages[name2];
47318
+ if (typeof text3 === "string" && text3.trim().length > 0) return text3;
47319
+ }
47320
+ }
47321
+ return null;
47322
+ }
47323
+ function reviewLine(id, text3) {
47324
+ const prefix = `[${id}] fails on the code as it is with: `;
47325
+ const room = Math.min(MAX_QUOTE_CHARS, MAX_REFUSED_SENTENCE_CHARS - prefix.length);
47326
+ if (room < MIN_QUOTE_CHARS) return null;
47327
+ const line = firstLine(text3, void 0, room);
47328
+ return line.length > 0 ? `${prefix}${line}` : null;
47329
+ }
47330
+ function reviewAnswer(lines) {
47331
+ return { rules: ["done_rule"], violations: [...lines.slice(0, MAX_REVIEW_CASES), REVIEW_CLOSING], message: REVIEW_MESSAGE };
47332
+ }
47333
+
47300
47334
  // src/codegenLoop.ts
47301
47335
  var CODEGEN_LOOP_CONTRACT_VERSION = "codegen-loop-1";
47302
47336
  var CODEGEN_LOOP_2_CONTRACT_VERSION = "codegen-loop-2";
@@ -47544,6 +47578,9 @@ async function runCodegenLoop(args2, deps) {
47544
47578
  let proofSendBacks = 0;
47545
47579
  let giveUpRefusals = 0;
47546
47580
  let redUnproven;
47581
+ const reviewOn = harness && args2.phase === "tests" && args2.redReview === true && (args2.redCheckIds ?? []).length > 0;
47582
+ let reviewed = null;
47583
+ let reviewAnswered = false;
47547
47584
  const currentRedRuns = () => {
47548
47585
  const now2 = versionOfFiles(filesOnDisk());
47549
47586
  return redRuns.filter((r) => r.version === now2);
@@ -47583,6 +47620,36 @@ async function runCodegenLoop(args2, deps) {
47583
47620
  return declared2 !== null && sameFile(declared2, file);
47584
47621
  };
47585
47622
  const failsFor = (r, id) => r.failing.some((name2) => idCoversCase(name2, id)) || r.fileFailed === true && r.file !== void 0 && fileHolds(r.file, id);
47623
+ const reviewQuote = (id) => {
47624
+ const text3 = failureFor(id, currentRedRuns(), idCoversCase);
47625
+ return text3 === null ? null : reviewLine(id, scrub(text3));
47626
+ };
47627
+ const noteReviewAnswer = (turn, answer) => {
47628
+ if (reviewed === null || reviewAnswered) return;
47629
+ reviewAnswered = true;
47630
+ const current2 = versionOfFiles(filesOnDisk());
47631
+ let linesChanged = 0;
47632
+ let linesSame = 0;
47633
+ let linesGone = 0;
47634
+ for (const [id, line] of reviewed.quoted) {
47635
+ const again = reviewQuote(id);
47636
+ if (again === null) linesGone += 1;
47637
+ else if (again === line) linesSame += 1;
47638
+ else linesChanged += 1;
47639
+ }
47640
+ log({
47641
+ event: "codegen.red_check",
47642
+ turn,
47643
+ outcome: "review_answered",
47644
+ answer,
47645
+ afterTurns: turn - reviewed.turn,
47646
+ testsChanged: current2 !== reviewed.version,
47647
+ rerun: redRuns.slice(reviewed.runs).some((r) => r.version === current2),
47648
+ linesChanged,
47649
+ linesSame,
47650
+ linesGone
47651
+ });
47652
+ };
47586
47653
  const sentSteps = () => stepsOf(transcript.slice(0, sent.entries), toolResults.slice(0, sent.results));
47587
47654
  let turns = 0;
47588
47655
  let noProgressStreak = 0;
@@ -47831,6 +47898,7 @@ async function runCodegenLoop(args2, deps) {
47831
47898
  }
47832
47899
  if (body2.outcome === "CANNOT_COMPLETE") {
47833
47900
  log({ event: "codegen.loop_turn", turn, outcome: "cannot_complete", requestTokens, elapsedMs: now() - turnStarted, calls: [] });
47901
+ if (reviewOn) noteReviewAnswer(turn, "gave_up");
47834
47902
  const said = typeof body2.summary === "string" ? body2.summary.slice(0, MAX_SUMMARY_CHARS) : void 0;
47835
47903
  if (conflictTool && conflictTool.recorded().length > 0) {
47836
47904
  markNotChecked();
@@ -47855,6 +47923,7 @@ async function runCodegenLoop(args2, deps) {
47855
47923
  const last = lastTestAnswer;
47856
47924
  const redLeft = harness && args2.phase === "tests" ? redProblem() : null;
47857
47925
  if (harness && args2.phase === "tests" && currentRedRuns().some((r) => r.failing.length > 0) && handOverRefusal(turn, true) === null && (redLeft === null || redLeft.kind === "passing")) {
47926
+ if (reviewOn && reviewed === null) log({ event: "codegen.red_check", turn, outcome: "review_skipped", reason: "gave_up", cases: (args2.redCheckIds ?? []).length });
47858
47927
  log({ event: "codegen.red_check", turn, outcome: "gave_up_but_red", files: overlay.changedPaths().length, ...redLeft ? { unproven: redLeft.ids.length } : {} });
47859
47928
  const red = currentRedRuns().filter((r) => r.answer !== void 0).at(-1)?.answer;
47860
47929
  const kept = last ?? red;
@@ -47876,6 +47945,7 @@ async function runCodegenLoop(args2, deps) {
47876
47945
  addCaseTests(declaredTests);
47877
47946
  log({ event: "codegen.case_tests", turn, declared: declaredTests.length });
47878
47947
  }
47948
+ if (reviewOn) noteReviewAnswer(turn, "done");
47879
47949
  if (conflictTool && conflictTool.recorded().length > 0) {
47880
47950
  const said = typeof body2.summary === "string" ? body2.summary.slice(0, MAX_SUMMARY_CHARS) : void 0;
47881
47951
  if (args2.fixFirst !== true) throw new TestConflictStop(conflictTool.recorded(), new CodegenLoopFailure("cannot_complete", void 0, void 0, said, said));
@@ -47932,6 +48002,35 @@ async function runCodegenLoop(args2, deps) {
47932
48002
  if (red.kind === "passing") redUnproven = red.ids;
47933
48003
  log({ event: "codegen.red_check", turn, outcome: red.kind === "passing" ? "ended_unproven" : "ended_unrun", cases: red.ids.length });
47934
48004
  }
48005
+ if (reviewOn && reviewed === null) {
48006
+ const ids = args2.redCheckIds ?? [];
48007
+ const quoted2 = /* @__PURE__ */ new Map();
48008
+ for (const id of ids) {
48009
+ const line = reviewQuote(id);
48010
+ if (line !== null) quoted2.set(id, line);
48011
+ }
48012
+ const skip = isFinal ? "final_turn" : quoted2.size === 0 ? "no_message" : tests !== null && tests.runsLeft + tests.fileRunsLeft === 0 ? "no_runs_left" : null;
48013
+ if (skip !== null) {
48014
+ log({ event: "codegen.red_check", turn, outcome: "review_skipped", reason: skip, cases: ids.length, quoted: quoted2.size });
48015
+ } else {
48016
+ reviewed = { turn, version: versionOfFiles(filesOnDisk()), runs: redRuns.length, quoted: quoted2 };
48017
+ const answer = reviewAnswer([...quoted2.values()]);
48018
+ refusedStreak += 1;
48019
+ refusedTurns.push({ turn, rules: answer.rules });
48020
+ log({
48021
+ event: "codegen.red_check",
48022
+ turn,
48023
+ outcome: "review_sent",
48024
+ cases: Math.min(quoted2.size, MAX_REVIEW_CASES),
48025
+ unquoted: ids.length - quoted2.size,
48026
+ notShown: Math.max(0, quoted2.size - MAX_REVIEW_CASES)
48027
+ });
48028
+ transcript.push({ turn, toolCalls: [], refused: answer });
48029
+ if (refusedStreak >= REFUSED_STREAK_LIMIT) forced = "refused_repeatedly";
48030
+ forced = settleNextTurn(turn, forced);
48031
+ continue;
48032
+ }
48033
+ }
47935
48034
  if (harness && args2.phase !== "tests") {
47936
48035
  const onDisk = (p) => {
47937
48036
  if (matchesDeniedPath(p, args2.deniedPaths) !== null) return false;
@@ -48256,6 +48355,7 @@ async function runPhases(i3) {
48256
48355
  phase: "tests",
48257
48356
  lane: { kind: "tests", testPaths: i3.testPaths },
48258
48357
  redCheckIds: i3.redCheckIds,
48358
+ ...i3.redReview === true ? { redReview: true } : {},
48259
48359
  keepOnGiveUp: false,
48260
48360
  ...i3.previous ? { previousAttempt: i3.previous } : {}
48261
48361
  });
@@ -49502,6 +49602,7 @@ async function runCodegenStep(p) {
49502
49602
  ...resume ? { resume } : {},
49503
49603
  testPaths: testTargetPaths(p.targets, discoveredTestsOf(p.testDiscovery)),
49504
49604
  redCheckIds: checkableIds(args2.requiredAutomationIds, p.requiredTestTypes),
49605
+ ...p.redReview === true ? { redReview: true } : {},
49505
49606
  run: (a) => runCodegenLoop(a, loopDeps),
49506
49607
  ...args2.tests ? { onOldCode: oldCodeRunner(args2, log, now) } : {},
49507
49608
  log
@@ -51633,7 +51734,7 @@ var FAILURE_ARTIFACT_DIR = "quikpilot-failure";
51633
51734
  var REPORT_COPY = "final-test-report.xml";
51634
51735
  var MAX_REPORT_BYTES = 5 * 1024 * 1024;
51635
51736
  var MAX_FILES = 200;
51636
- var RUNNER_VERSION = true ? "9.3.0-rc.65" : "dev";
51737
+ var RUNNER_VERSION = true ? "9.3.0-rc.67" : "dev";
51637
51738
  function safeDestination(base, repoPath) {
51638
51739
  if (!repoPath || (0, import_node_path26.isAbsolute)(repoPath)) return null;
51639
51740
  const destination = (0, import_node_path26.resolve)(base, repoPath);
@@ -52438,6 +52539,8 @@ async function run2(env2) {
52438
52539
  const runScratch = runScratchWanted && runScratchCommand ? { root: process.cwd(), secrets: [runToken, packet.gateway.token].filter((s) => typeof s === "string" && s.length > 0) } : void 0;
52439
52540
  const twoPhaseWanted = codegenMode === "loop-tests" && process.env.QUIKPILOT_TWO_PHASE?.trim().toLowerCase() !== "off";
52440
52541
  const twoPhase = twoPhaseWanted && twoPhaseSkip === null;
52542
+ const redReview = twoPhase && redReviewOn();
52543
+ if (redReview) console.log(JSON.stringify({ event: "red_review.on" }));
52441
52544
  if (twoPhaseWanted && twoPhaseSkip !== null) {
52442
52545
  warnings.push(TWO_PHASE_SKIPPED_NOTE);
52443
52546
  console.log(JSON.stringify({ event: "two_phase.off", reason: twoPhaseSkip }));
@@ -52468,6 +52571,7 @@ async function run2(env2) {
52468
52571
  ...callFunction ? { callFunction } : {},
52469
52572
  ...runScratch ? { runScratch } : {},
52470
52573
  ...twoPhase ? { twoPhase: true, ...packet.requiredTestTypes ? { requiredTestTypes: packet.requiredTestTypes } : {} } : {},
52574
+ ...redReview ? { redReview: true } : {},
52471
52575
  tests: {
52472
52576
  root: process.cwd(),
52473
52577
  command: packet.commands.test,
@@ -53266,13 +53370,44 @@ async function postInvestigate(gateway, contextData, signal) {
53266
53370
  if (!res.ok) throw new TargetingHttpError(res.status, res.statusText);
53267
53371
  return noteSpend(await res.json(), "investigate");
53268
53372
  }
53269
- async function reportInvestigation(callbackUrl, runToken, body2) {
53270
- const res = await fetch(callbackUrl, {
53271
- method: "POST",
53272
- headers: { Authorization: `Bearer ${runToken}`, "Content-Type": "application/json" },
53273
- body: JSON.stringify(body2)
53274
- });
53275
- if (!res.ok) throw new Error(`Investigation callback failed: ${await describeQuikTrackFailure(res)}`);
53373
+ var INVESTIGATION_REPORT_RETRY_WAITS_MS = [2e3, 5e3, 1e4, 2e4, 3e4];
53374
+ var InvestigationReportError = class extends Error {
53375
+ constructor(message, status, networkCode) {
53376
+ super(message);
53377
+ this.status = status;
53378
+ this.networkCode = networkCode;
53379
+ this.name = "InvestigationReportError";
53380
+ }
53381
+ status;
53382
+ networkCode;
53383
+ };
53384
+ async function reportInvestigation(callbackUrl, runToken, body2, sleep = (ms) => new Promise((resolve6) => setTimeout(resolve6, ms))) {
53385
+ const payload = JSON.stringify(body2);
53386
+ const tries = INVESTIGATION_REPORT_RETRY_WAITS_MS.length + 1;
53387
+ for (let attempt2 = 1; ; attempt2++) {
53388
+ let failure;
53389
+ let status;
53390
+ let networkCode;
53391
+ try {
53392
+ const res = await fetch(callbackUrl, {
53393
+ method: "POST",
53394
+ headers: { Authorization: `Bearer ${runToken}`, "Content-Type": "application/json" },
53395
+ body: payload
53396
+ });
53397
+ if (res.ok) return;
53398
+ failure = await describeQuikTrackFailure(res);
53399
+ status = res.status;
53400
+ } catch (err2) {
53401
+ if (!isRetryableNetworkError(err2)) throw err2;
53402
+ networkCode = networkErrorCode(err2);
53403
+ failure = `the connection failed (${networkCode})`;
53404
+ }
53405
+ if (status !== void 0 && !REPORT_RETRY_STATUSES.has(status)) throw new InvestigationReportError(`Investigation callback failed: ${failure}`, status);
53406
+ if (attempt2 === tries) throw new InvestigationReportError(`Investigation callback failed: ${failure} after ${tries} tries`, status, networkCode);
53407
+ const waitMs = INVESTIGATION_REPORT_RETRY_WAITS_MS[attempt2 - 1];
53408
+ console.warn(`::warning::Investigation callback failed: ${failure}; trying again in ${waitMs / 1e3} s (try ${attempt2 + 1} of ${tries})`);
53409
+ await sleep(waitMs);
53410
+ }
53276
53411
  }
53277
53412
  function realDeps() {
53278
53413
  return {
@@ -53315,8 +53450,9 @@ async function runInvestigate(env2, deps = realDeps()) {
53315
53450
  try {
53316
53451
  await deps.report(env2.callbackUrl, runToken, body2);
53317
53452
  return { hardFailure: false };
53318
- } catch {
53319
- log({ event: "investigate.failed", reason: "report_failed" });
53453
+ } catch (err2) {
53454
+ const detail = err2 instanceof InvestigationReportError ? { ...err2.status !== void 0 ? { status: err2.status } : {}, ...err2.networkCode ? { error: err2.networkCode } : {} } : {};
53455
+ log({ event: "investigate.failed", reason: "report_failed", ...detail });
53320
53456
  return { hardFailure: true };
53321
53457
  }
53322
53458
  }