forgedock 1.52.0 → 1.53.0
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/bin/engine/outcome-codes.mjs +3 -0
- package/bin/engine/telemetry-seam.mjs +4 -2
- package/bin/engine-cli.mjs +53 -16
- package/bin/experiment.mjs +58 -6
- package/bin/forge-utils.mjs +6 -2
- package/bin/forgedock.mjs +15 -1
- package/bin/lean/account-watch.mjs +28 -0
- package/bin/lean/account-watch.test.mjs +30 -0
- package/bin/lean/activation.mjs +20 -0
- package/bin/lean/activation.test.mjs +14 -1
- package/bin/lean/basered.mjs +115 -0
- package/bin/lean/basered.test.mjs +66 -0
- package/bin/lean/batch-health.mjs +40 -6
- package/bin/lean/batch-health.test.mjs +34 -1
- package/bin/lean/batch.mjs +41 -2
- package/bin/lean/batch.test.mjs +104 -2
- package/bin/lean/checkpoint-reconcile.mjs +43 -0
- package/bin/lean/checkpoint-reconcile.test.mjs +95 -0
- package/bin/lean/conformance.e2e.test.mjs +1 -1
- package/bin/lean/conformance.mjs +195 -22
- package/bin/lean/conformance.test.mjs +152 -5
- package/bin/lean/effects.mjs +8 -4
- package/bin/lean/execution.mjs +19 -3
- package/bin/lean/execution.test.mjs +39 -0
- package/bin/lean/findinglabel.mjs +16 -0
- package/bin/lean/findinglabel.test.mjs +39 -0
- package/bin/lean/issuewatch-release.mjs +6 -2
- package/bin/lean/issuewatch-release.test.mjs +16 -0
- package/bin/lean/issuewatch.mjs +11 -1
- package/bin/lean/lanelock.mjs +14 -0
- package/bin/lean/lean.mjs +165 -34
- package/bin/lean/lean.test.mjs +289 -9
- package/bin/lean/light.mjs +48 -7
- package/bin/lean/light.test.mjs +37 -3
- package/bin/lean/limits.test.mjs +142 -9
- package/bin/lean/orchestrate-cancel.test.mjs +143 -0
- package/bin/lean/orchestrate.mjs +96 -26
- package/bin/lean/postdeploy-check.test.mjs +39 -0
- package/bin/lean/prompts.mjs +8 -7
- package/bin/lean/quota.mjs +39 -0
- package/bin/lean/recovery.test.mjs +10 -0
- package/bin/lean/relaxation.mjs +73 -0
- package/bin/lean/relaxation.test.mjs +54 -0
- package/bin/lean/release-postmerge.mjs +119 -0
- package/bin/lean/release-rehearsal.mjs +63 -0
- package/bin/lean/release-rehearsal.test.mjs +93 -0
- package/bin/lean/release-review.e2e.test.mjs +77 -0
- package/bin/lean/release-review.mjs +198 -0
- package/bin/lean/release-review.test.mjs +180 -0
- package/bin/lean/release.mjs +228 -0
- package/bin/lean/release.test.mjs +292 -0
- package/bin/lean/rotator.mjs +150 -31
- package/bin/lean/rotator.test.mjs +105 -2
- package/bin/lean/sandbox-remote.mjs +9 -2
- package/bin/lean/schedd.mjs +49 -4
- package/bin/lean/schedd.test.mjs +87 -6
- package/bin/lean/verifier.mjs +3 -2
- package/bin/lean/verify.mjs +2 -1
- package/bin/lean/verify.test.mjs +6 -0
- package/bin/pool/agent.mjs +18 -4
- package/bin/pool/router.mjs +66 -24
- package/bin/review-staging.mjs +23 -0
- package/bin/stats/conformance-outcomes.mjs +208 -0
- package/bin/stats/conformance-outcomes.test.mjs +188 -0
- package/bin/stats/depth.mjs +218 -0
- package/bin/stats/depth.test.mjs +133 -0
- package/bin/stats/experiment.mjs +7 -5
- package/bin/stats/github-source.mjs +2 -2
- package/bin/stats/index.mjs +64 -2
- package/bin/stats/local-source.mjs +11 -0
- package/bin/stats/query.mjs +69 -0
- package/bin/stats/selffiled.mjs +52 -0
- package/bin/stats/selffiled.test.mjs +71 -0
- package/commands/orchestrate.md +1 -1
- package/commands/review-pr-agents/security.md +4 -0
- package/commands/review-pr-staging.md +2 -0
- package/commands/work-on/build.md +4 -6
- package/docs/CONFIG.md +65 -8
- package/docs/ISSUE-WATCH.md +2 -0
- package/docs/OUTCOME-CODES.md +3 -0
- package/docs/STATS.md +44 -0
- package/docs/TELEMETRY.md +1 -1
- package/package.json +1 -1
- package/pool/README.md +1 -1
- package/pool/image/cs-cred +14 -1
- package/scripts/backfill-finding-labels.mjs +50 -0
- package/scripts/backfill-finding-labels.test.mjs +36 -0
- package/scripts/doctor-pipeline-state.sh +21 -6
- package/scripts/file-deferred-followups.sh +59 -251
- package/scripts/file-deferred-followups.test.sh +85 -206
- package/scripts/followup-route.mjs +12 -0
- package/scripts/owner-route-parity.test.sh +17 -1
- package/scripts/review-pr-side-effects.test.sh +40 -0
|
@@ -37,6 +37,7 @@ export const OUTCOME_CODES = Object.freeze({
|
|
|
37
37
|
BASE_CONFLICT: "base.conflict",
|
|
38
38
|
RATE_LIMITED: "rate_limited",
|
|
39
39
|
BACKEND_AUTH: "backend.auth", // forge#5168: the claude CLI login failed ("Failed to authenticate"); deferred under the account hold, never engine-error, never the breaker
|
|
40
|
+
QUOTA_EXHAUSTED: "quota.exhausted", // forge#5236: no account has capacity (every login at its ceiling); deferred until the earliest reset, never backend.auth
|
|
40
41
|
HOST_BUSY: "host.busy",
|
|
41
42
|
GH_UNAVAILABLE: "gh.unavailable", // forge#4157: `gh` unreachable after retries during the --repo identity check; run deferred, nothing posted
|
|
42
43
|
GH_AUTH: "gh.auth", // forge#4662: gh answered HTTP 401 and one token refresh did not fix it; run deferred, a rerun resumes
|
|
@@ -47,6 +48,7 @@ export const OUTCOME_CODES = Object.freeze({
|
|
|
47
48
|
PATH_SWITCH_CONFLICT: "path.switch_conflict",
|
|
48
49
|
ENGINE_ERROR: "engine.error",
|
|
49
50
|
ENGINE_DCO_REWRITE: "engine.dco_rewrite", // forge#4997: the DCO sign-off rewrite of unpushed commits failed (git filter-branch); mechanical engine-error (not needs-human), relaunched by the batch runner
|
|
51
|
+
ENGINE_PUSH_DIVERGED: "engine.push_diverged", // forge#5202: the lane-branch push was rejected non-fast-forward, no other lane owns the branch, and the divergence is not the lane's own reconcilable checkpoints; mechanical engine-error (not needs-human), relaunched by the batch runner
|
|
50
52
|
ENGINE_VALIDATE_RESULT_LOST: "engine.validate_result_lost", // forge#4708: a validate result recorded before a CI fix round is missing after it and could not be carried forward
|
|
51
53
|
INFRA_DISK_QUOTA: "infra.disk_quota",
|
|
52
54
|
INFRA_CLI_SPAWN_TRANSIENT: "infra.cli_spawn_transient",
|
|
@@ -59,6 +61,7 @@ export const OUTCOME_CODES = Object.freeze({
|
|
|
59
61
|
ENV_LANE_LIMIT: "env.lane_limit", // forge#4690: the lane hit its own scope limit (TasksMax or MemoryMax) and was stopped; an environment error, never an engine-error, so the breaker ignores it
|
|
60
62
|
ENV_CAPABILITY_REMOTE: "env.capability_remote", // forge#4542: a remote sandbox lane blocked only on a host-only capability (SOPS key, ops credentials, prod monitor SSH) the dispatching host has; recovered locally
|
|
61
63
|
SANDBOX_START_FAILED: "sandbox.start_failed", // forge#4254: a lane sandbox could not start (a non-auth 4xx/config error or a non-HTTP start failure); needs-human, not relaunched
|
|
64
|
+
BASE_RED: "base.red", // forge#5239: a verify.invariants guard fails on the base too; the lane is deferred behind the introducing issue, never needs-human
|
|
62
65
|
SANDBOX_CAPACITY: "sandbox.capacity", // forge#4254: the sandbox provider had no capacity; deferred with backoff
|
|
63
66
|
SANDBOX_TRANSIENT: "sandbox.transient", // forge#5095: the sandbox provider answered a 5xx on launch (router/agent infrastructure); deferred with backoff, capped by max_deferrals, never needs-human
|
|
64
67
|
SANDBOX_AUTH: "sandbox.auth", // forge#4685: the sandbox provider refused or lacked the credential (HTTP 401/403, no token); deferred, never needs-human
|
|
@@ -37,6 +37,8 @@ const prOf = (rec) => (Number.isSafeInteger(rec.pr) && rec.pr > 0 ? { pr: rec.pr
|
|
|
37
37
|
/** "a:b,c:d" from [{from,to}] (forge#4165); undefined for a non-array so compact() drops it. An empty list is "". */
|
|
38
38
|
const pairs = (v) => (Array.isArray(v) ? v.map((e) => `${e?.from}:${e?.to}`).join(",") : undefined);
|
|
39
39
|
const nonEmpty = (v) => (v === "" ? "none" : v);
|
|
40
|
+
/** forge#5206: an experiment arm's applied overrides (`k=v,...`); "" (none applied) is "none" so compact() keeps it. */
|
|
41
|
+
const armOv = (v) => (typeof v === "string" ? nonEmpty(v) : undefined);
|
|
40
42
|
/** Lean's forge#4165 extras of a STRUCTURE_DELTA record; {} for the implement-time counts-only shape. */
|
|
41
43
|
function structureLists(rec) {
|
|
42
44
|
if (!Array.isArray(rec.decisions) && !Array.isArray(rec.new_edges) && !Array.isArray(rec.deps_added)) return {};
|
|
@@ -61,7 +63,7 @@ export function mapRecord(rec, wallMs) {
|
|
|
61
63
|
cost_usd_session: Number.isFinite(rec.cost_usd_session) ? Math.round(rec.cost_usd_session * 1e6) / 1e6 : undefined,
|
|
62
64
|
input_tokens: tok(rec.usage, "input_tokens"), output_tokens: tok(rec.usage, "output_tokens"),
|
|
63
65
|
cache_read_tokens: tok(rec.usage, "cache_read_input_tokens"), cache_creation_tokens: tok(rec.usage, "cache_creation_input_tokens"),
|
|
64
|
-
baseline_tokens: rec.baseline_tokens, lane_profile: rec.lane_profile, experiment: rec.experiment, arm: rec.arm, // #4629
|
|
66
|
+
baseline_tokens: rec.baseline_tokens, lane_profile: rec.lane_profile, experiment: rec.experiment, arm: rec.arm, arm_overrides: armOv(rec.arm_overrides), // #4629, #5206
|
|
65
67
|
}) };
|
|
66
68
|
}
|
|
67
69
|
if (rec.event === "RUN_TERMINAL") {
|
|
@@ -69,7 +71,7 @@ export function mapRecord(rec, wallMs) {
|
|
|
69
71
|
milestone: rec.milestone, conformance_mode: rec.conformance_mode, shadow_would: rec.shadow_would,
|
|
70
72
|
builder_tier: rec.builder_tier, builder_class: rec.builder_class, builder_model: rec.builder_model, // #4394: the model per merge
|
|
71
73
|
builder_escalated: typeof rec.builder_escalated === "boolean" ? Number(rec.builder_escalated) : undefined,
|
|
72
|
-
experiment: rec.experiment, arm: rec.arm }) }; // #4629
|
|
74
|
+
experiment: rec.experiment, arm: rec.arm, arm_overrides: armOv(rec.arm_overrides) }) }; // #4629, #5206
|
|
73
75
|
}
|
|
74
76
|
if (rec.event === "SANDBOX_USAGE") {
|
|
75
77
|
return { event: "sandbox_usage", phase: null, payload: compact({ provider: rec.provider, sandbox_id: rec.sandbox_id, minutes: rec.minutes,
|
package/bin/engine-cli.mjs
CHANGED
|
@@ -13,7 +13,7 @@ import { localLaneCap } from "./lean/admission.mjs";
|
|
|
13
13
|
import { memAvailableMb } from "./lean/heavy.mjs";
|
|
14
14
|
import { liveOverload, formatOverload, formatHostLoad } from "./lean/hostload.mjs";
|
|
15
15
|
import { join, resolve as resolvePath } from "node:path";
|
|
16
|
-
import { runIssue, DEFAULT_MAX_ATTEMPTS, sanitizeLeaseHost } from "./engine.mjs";
|
|
16
|
+
import { runIssue, DEFAULT_MAX_ATTEMPTS, sanitizeLeaseHost, ENGINE_VERSION } from "./engine.mjs";
|
|
17
17
|
import { makeProjector } from "./engine/projector.mjs";
|
|
18
18
|
import { decomposedSubissues, isDecomposedRecord, isTrustedActor, parseDependsOn } from "./engine/phases.mjs";
|
|
19
19
|
import { readLog, readLogFile, deriveState, runLogPath, migrateRunLogs } from "./engine/runlog.mjs";
|
|
@@ -27,9 +27,9 @@ import { parseVerify } from "./lean/verify.mjs";
|
|
|
27
27
|
import { normalizeKindModes } from "./lean/conformance.mjs";
|
|
28
28
|
import { parseEnforceDomains } from "./lean/review-trigger.mjs";
|
|
29
29
|
import { viewIssue } from "./lean/gh-assoc.mjs";
|
|
30
|
-
import { otherLaneOwner } from "./lean/lanelock.mjs";
|
|
30
|
+
import { otherLaneOwner, clearLease } from "./lean/lanelock.mjs";
|
|
31
31
|
import { parseExecution, detectNeeds, placementText } from "./lean/execution.mjs";
|
|
32
|
-
import { openRotator } from "./lean/rotator.mjs";
|
|
32
|
+
import { openRotator, rotatorKind } from "./lean/rotator.mjs";
|
|
33
33
|
import { relayPrefetchCommands } from "./lean/relay.mjs";
|
|
34
34
|
import { parseTurnBudgets, formatTurnSummary, TURN_BUDGET_DEFAULTS } from "./lean/budget.mjs";
|
|
35
35
|
import { writeAtomic as writeResultAtomic } from "./lean/batch.mjs";
|
|
@@ -418,7 +418,7 @@ export function readMergeWait(cwd = process.cwd()) {
|
|
|
418
418
|
/**
|
|
419
419
|
* forge.yaml `verify:` section (#4167, block style: `verify:` then ` mode: ci`, ` workflow: verify.yml`, ` paths_input`,
|
|
420
420
|
* ` skip_paths` comma-separated, ` max_rounds`, ` check_run: true` (#4270)) for the core path; undefined when the
|
|
421
|
-
* section is absent or unreadable.
|
|
421
|
+
* section is absent or unreadable. ` guard_block: false` (#5239) lets verify.invariants fail without blocking the merge.
|
|
422
422
|
*/
|
|
423
423
|
export function readVerify(cwd = process.cwd()) {
|
|
424
424
|
try {
|
|
@@ -998,7 +998,7 @@ export async function runFromCli(argv, deps = {}) {
|
|
|
998
998
|
let lres;
|
|
999
999
|
try {
|
|
1000
1000
|
lres = await runCore({ issue, repo: leanRepo, ...(lane ? { lane } : {}), laneOverride, branches: readBranches(), cwd: process.cwd(), dir, io: leanIo, path: enginePath, onProgress,
|
|
1001
|
-
...(readExecution(process.cwd())
|
|
1001
|
+
...(rotatorKind({ execution: readExecution(process.cwd()), env }) ? { accountRotator: rotatorKind({ execution: readExecution(process.cwd()), env }) } : {}), // #5094, #5205: detected
|
|
1002
1002
|
onTeardown: (fn) => { teardown = fn; }, ...(env.FORGEDOCK_BATCH_ID ? { batchId: env.FORGEDOCK_BATCH_ID } : {}), ...(placement ? { placement } : {}), ...(recover ? { recover } : {}),
|
|
1003
1003
|
emitTelemetry: deps.emitTelemetry ?? composeEmit(makeEmitTelemetry({ repo: leanRepo }), makeEventEmitter({ repo: leanRepo, config: readEvents() }).emit),
|
|
1004
1004
|
admission: readAdmission(), heavy: readHeavy(), ...readCoreLimits(), ...readEnvConfig(), ...(readMergeWait() ? { mergeWait: readMergeWait() } : {}), ...(readConformanceMode() ? { conformance: readConformanceMode() } : {}), ...(readConformanceKinds() ? { conformanceKinds: readConformanceKinds() } : {}), ...(readConformanceMutation() ? { conformanceMutation: "report" } : {}), ...(readContextPack() ? { contextPack: readContextPack() } : {}), ...(readReviewIncomplete() ? { reviewIncomplete: readReviewIncomplete() } : {}), ...(readLaneInstructions() ? { laneInstructions: readLaneInstructions() } : {}), ...(readReproTest() ? { reproTest: readReproTest() } : {}), ...(readExplore() ? { explore: readExplore() } : {}), ...(readExperiment() ? { experiment: readExperiment() } : {}), light: readLight(), ...(readCloseParent() ? { closeParent: true } : {}), ...(readReviewTrigger() ? { reviewTrigger: readReviewTrigger() } : {}), ...(readVerify() ? { verify: readVerify() } : {}), ...readPrecheckOptions(), ...(model ? { builderModel: model } : {}), ...(readLeanSetting("reviewer_model") ? { reviewerModel: readLeanSetting("reviewer_model") } : {}), ...(readFixModel() ? { fixModel: readFixModel() } : {}), ...(readBuilderRouting() ? { builderRouting: readBuilderRouting() } : {}), ...(readVerifier() ? { verifier: readVerifier() } : {}), ...(readHostCaps() ? { hostCaps: readHostCaps() } : {}), ...readRelayCaps(), ...(readSequenceRegenerate() ? { sequenceRegenerate: readSequenceRegenerate() } : {}), ...(readBaseMerge() ? { baseMerge: readBaseMerge() } : {}), ...(readFollowupsDefaultMilestone() ? { followupsDefaultMilestone: readFollowupsDefaultMilestone() } : {}), ...(readFollowupsRollupLabel() ? { followupsRollupLabel: readFollowupsRollupLabel() } : {}) });
|
|
@@ -1201,6 +1201,7 @@ function flag(argv, name) { const i = argv.indexOf(name); return i >= 0 ? argv[i
|
|
|
1201
1201
|
* `--add <id> N...` (#4408) adds issues to that batch instead of starting a second one: they run under its K and DAG
|
|
1202
1202
|
* (a running batch picks them up on its next pass, a stopped one on its next `--resume`); `--resume <id> N...` adds N too.
|
|
1203
1203
|
* `--requeue <id> N... [--reason]` (#4550) returns a terminal issue (and the dependents skipped behind it) to pending after an operator decision.
|
|
1204
|
+
* #5203: it also releases a quota-paused pending issue (`paused (quota) until <ISO>`): its notBefore and the pool hold are cleared.
|
|
1204
1205
|
* `--cancel <id>` (#4376) stops that one batch, never the shared daemon: it admits nothing more, its running local lanes get
|
|
1205
1206
|
* SIGTERM (their teardown saves the work), remote lanes run to their result and the rest end `held`; `--resume <id>` continues it.
|
|
1206
1207
|
*/
|
|
@@ -1306,7 +1307,7 @@ async function addedEdges({ added, records, io, repo }) {
|
|
|
1306
1307
|
*/
|
|
1307
1308
|
/** #5000: what happened to the batch after an add/requeue; never implies a run when no daemon hosts it. */
|
|
1308
1309
|
const hostedLine = (id, res) => res.reopened ? `batch ${id}: finished batch reopened and hosted by the schedd`
|
|
1309
|
-
: res.hosted ? `batch ${id}: hosted by the schedd; the runner picks it up on its next pass`
|
|
1310
|
+
: res.hosted ? `batch ${id}: hosted by the schedd; the runner picks it up on its next pass (within ~5s while lanes run; if it is finishing, the schedd re-hosts the batch)`
|
|
1310
1311
|
: `batch ${id}: queued but NOT hosted (no schedd hosts it); run: forgedock orchestrate --resume ${id}`;
|
|
1311
1312
|
|
|
1312
1313
|
async function addToBatch({ id, tokens, root, io, viaDaemon = null, print = (l) => console.log(l) }) {
|
|
@@ -1373,7 +1374,7 @@ function baseWaitOf(waits, { io, leanIo, cwd, now = () => Date.now() }) {
|
|
|
1373
1374
|
* when none runs) or directly. A held issue is not admitted (a running lane is not stopped); `--release` (or a `--resume` that
|
|
1374
1375
|
* names it) lets it run again. @returns {{ok, batch, changed:number[]}}
|
|
1375
1376
|
*/
|
|
1376
|
-
async function holdBatch({ op, id, tokens, root, viaDaemon = null, print = (l) => console.log(l) }) {
|
|
1377
|
+
async function holdBatch({ op, id, tokens, root, viaDaemon = null, takeover = null, print = (l) => console.log(l) }) {
|
|
1377
1378
|
const issues = tokens.filter((t) => /^#?\d+$/.test(String(t))).map((t) => parseInt(String(t).replace("#", ""), 10));
|
|
1378
1379
|
if (!id || String(id).startsWith("--") || !issues.length) throw new Error(ORCH_USAGE);
|
|
1379
1380
|
let res = viaDaemon ? await viaDaemon(op, issues) : null;
|
|
@@ -1382,6 +1383,11 @@ async function holdBatch({ op, id, tokens, root, viaDaemon = null, print = (l) =
|
|
|
1382
1383
|
if (!b.exists()) throw new Error(`no batch ${id} in ${root}`);
|
|
1383
1384
|
res = { changed: op === "hold" ? b.holdIssues(issues) : b.releaseIssues(issues) };
|
|
1384
1385
|
}
|
|
1386
|
+
if (op === "release" && takeover) { // #5241: a released issue deferred on a cancelled batch's lease is requeued at once
|
|
1387
|
+
const batchMod = await import("./lean/batch.mjs"), b = batchMod.openBatch(root, id), st = b.store.load(), repo = b.readPlan()?.repo ?? null;
|
|
1388
|
+
const dead = issues.filter((n) => st?.pending?.includes(n) && st?.results?.[n] === undefined && Number.isFinite(st?.notBefore?.[n]) && batchMod.cancelledOwners(root, repo, n, id).length);
|
|
1389
|
+
if (dead.length) await takeover(dead);
|
|
1390
|
+
}
|
|
1385
1391
|
const list = (res.changed ?? []).map((n) => `#${n}`).join(" ") || "(none)";
|
|
1386
1392
|
print(op === "hold" ? `batch ${id}: held ${list}; forgedock orchestrate --release ${id} <issue...> (or --resume ${id} <issue...>) re-admits them`
|
|
1387
1393
|
: `batch ${id}: released ${list}`);
|
|
@@ -1412,6 +1418,11 @@ async function requeueBatch({ id, tokens, reason, root, io, viaDaemon = null, pr
|
|
|
1412
1418
|
else if ((v.labels ?? []).some((l) => (l?.name ?? l) === "needs-human")) refused.push({ issue: n, reason: "still labelled needs-human: record the decision and remove the label first" });
|
|
1413
1419
|
else open.push(n);
|
|
1414
1420
|
}
|
|
1421
|
+
// #5241: an issue deferred on a lease a cancelled batch's lane holds: the lease goes, so the requeue takes over at once
|
|
1422
|
+
for (const n of open) {
|
|
1423
|
+
if (!batchMod.cancelledOwners(root, repo, n, id).length || !b.store.load()?.pending?.includes(n)) continue;
|
|
1424
|
+
try { await clearLease({ projector: makeProjector(io, { repo: repo ?? undefined }), issue: n }); } catch { /* the lease expires */ }
|
|
1425
|
+
}
|
|
1415
1426
|
const why = reason || "operator decision", by = "operator";
|
|
1416
1427
|
let res = { requeued: [], refused: [] };
|
|
1417
1428
|
if (open.length) {
|
|
@@ -1512,7 +1523,9 @@ async function orchestrateClient(argv, deps = {}) {
|
|
|
1512
1523
|
}
|
|
1513
1524
|
for (const op of ["hold", "release"]) if (argv.includes(`--${op}`)) {
|
|
1514
1525
|
const id = flag(argv, `--${op}`);
|
|
1515
|
-
|
|
1526
|
+
const root = await batchRootOf(), io = deps.io ?? makeIo();
|
|
1527
|
+
return holdBatch({ op, id, tokens: operandsOf(argv.slice(argv.indexOf(`--${op}`) + 2)), root, viaDaemon: holdVia(id),
|
|
1528
|
+
takeover: (ns) => requeueBatch({ id, tokens: ns, reason: "--release: lease held by a cancelled batch", root, io, viaDaemon: requeueVia(id) }) });
|
|
1516
1529
|
}
|
|
1517
1530
|
if (argv.includes("--add")) {
|
|
1518
1531
|
const i = argv.indexOf("--add"), id = argv[i + 1];
|
|
@@ -1615,7 +1628,9 @@ export async function runBatch({ argv, cwd: callerCwd = process.cwd(), env: call
|
|
|
1615
1628
|
return requeueBatch({ id: argv[i + 1], tokens: operandsOf(argv.slice(i + 2)), reason: flag(argv, "--reason"), root, io: deps.io ?? makeIo(), print: (l) => sink.line(l) });
|
|
1616
1629
|
}
|
|
1617
1630
|
for (const op of ["hold", "release"]) if (argv.includes(`--${op}`)) {
|
|
1618
|
-
|
|
1631
|
+
const hid = flag(argv, `--${op}`);
|
|
1632
|
+
return holdBatch({ op, id: hid, tokens: operandsOf(argv.slice(argv.indexOf(`--${op}`) + 2)), root, print: (l) => sink.line(l),
|
|
1633
|
+
takeover: (ns) => requeueBatch({ id: hid, tokens: ns, reason: "--release: lease held by a cancelled batch", root, io: deps.io ?? makeIo(), print: (l) => sink.line(l) }) });
|
|
1619
1634
|
}
|
|
1620
1635
|
if (argv.includes("--add")) {
|
|
1621
1636
|
const i = argv.indexOf("--add");
|
|
@@ -1639,7 +1654,7 @@ export async function runBatch({ argv, cwd: callerCwd = process.cwd(), env: call
|
|
|
1639
1654
|
// #5031: a resume (operator or schedd restart) keeps the base waits recorded at start; a landed commit releases on the first check
|
|
1640
1655
|
for (const [n, l] of Object.entries(plan.baseWaits ?? {})) if (Array.isArray(l) && l.length) baseWaits.set(Number(n), l.filter((w) => w && typeof w.sha === "string" && typeof w.base === "string"));
|
|
1641
1656
|
}
|
|
1642
|
-
|
|
1657
|
+
let issues = issuesOf(argv);
|
|
1643
1658
|
if (!issues.length) throw new Error(ORCH_USAGE);
|
|
1644
1659
|
const parallel = parallelOf(argv);
|
|
1645
1660
|
// The lanes' env: a resumed daemon batch uses the env its plan kept, over the daemon's own.
|
|
@@ -1685,6 +1700,21 @@ export async function runBatch({ argv, cwd: callerCwd = process.cwd(), env: call
|
|
|
1685
1700
|
throw refusal;
|
|
1686
1701
|
}
|
|
1687
1702
|
}
|
|
1703
|
+
// #5241: an issue already pending or running in another active batch of the repo is skipped (naming it), unless --force <reason>
|
|
1704
|
+
if (!force) {
|
|
1705
|
+
const taken = new Map(issues.map((n) => [n, batchMod.activeBatchOf(root, repo, n)]).filter(([, b]) => b));
|
|
1706
|
+
for (const [n, b] of taken) sink.line(`skipped: #${n} is already in active batch ${b}; --force "<reason>" starts it here anyway`);
|
|
1707
|
+
if (taken.size) {
|
|
1708
|
+
if (taken.size === issues.length) throw new Error(`every issue is already in an active batch (${[...new Set(taken.values())].join(", ")}); pass --force "<reason>" to start them anyway`);
|
|
1709
|
+
const out = []; // drop the skipped operands, keeping each valued flag with its value
|
|
1710
|
+
for (let i = 0; i < argv.length; i++) {
|
|
1711
|
+
if (ORCH_VALUED.includes(argv[i])) { out.push(argv[i], argv[++i]); continue; }
|
|
1712
|
+
if (/^#?\d+$/.test(argv[i]) && taken.has(parseInt(argv[i].replace("#", ""), 10))) continue;
|
|
1713
|
+
out.push(argv[i]);
|
|
1714
|
+
}
|
|
1715
|
+
argv = out; issues = issuesOf(argv);
|
|
1716
|
+
}
|
|
1717
|
+
}
|
|
1688
1718
|
const base = deps.batchId ?? batchMod.newBatchId();
|
|
1689
1719
|
batch = batchMod.openBatch(root, base);
|
|
1690
1720
|
for (let i = 2; batch.exists(); i++) batch = batchMod.openBatch(root, `${base}.${i}`); // never resume by accident
|
|
@@ -1745,7 +1775,7 @@ export async function runBatch({ argv, cwd: callerCwd = process.cwd(), env: call
|
|
|
1745
1775
|
const { runCore } = deps.leanModule;
|
|
1746
1776
|
const emitTelemetry = deps.emitTelemetry ?? makeEmitTelemetry({ repo });
|
|
1747
1777
|
lanes = { adopt: null, runOne: (n, ln, ctx = {}) => runCore({ issue: n, repo, lane: ln, laneOverride, ...(ctx.placement ? { placement: { ...ctx.placement, mode: execMode() } } : {}), ...(ctx.recover ? { recover: ctx.recover } : {}), branches, cwd, dir, io: leanIo, agentId: `orch_${process.pid}_${n}`, emitTelemetry, batchId: batch.id,
|
|
1748
|
-
...(readExecution(cwd)
|
|
1778
|
+
...(rotatorKind({ execution: readExecution(cwd), env }) ? { accountRotator: rotatorKind({ execution: readExecution(cwd), env }) } : {}), // #5094, #5205: detected
|
|
1749
1779
|
admission: readAdmission(cwd), heavy: readHeavy(cwd), ...readCoreLimits(cwd), ...readEnvConfig(cwd), ...(readMergeWait(cwd) ? { mergeWait: readMergeWait(cwd) } : {}), ...(readConformanceMode(cwd) ? { conformance: readConformanceMode(cwd) } : {}), ...(readConformanceKinds(cwd) ? { conformanceKinds: readConformanceKinds(cwd) } : {}), ...(readConformanceMutation(cwd) ? { conformanceMutation: "report" } : {}), ...(readContextPack(cwd) ? { contextPack: readContextPack(cwd) } : {}), ...(readReviewIncomplete(cwd) ? { reviewIncomplete: readReviewIncomplete(cwd) } : {}), ...(readLaneInstructions(cwd) ? { laneInstructions: readLaneInstructions(cwd) } : {}), ...(readReproTest(cwd) ? { reproTest: readReproTest(cwd) } : {}), ...(readExplore(cwd) ? { explore: readExplore(cwd) } : {}), ...(readExperiment(cwd) ? { experiment: readExperiment(cwd) } : {}), light: readLight(cwd), ...(readCloseParent(cwd) ? { closeParent: true } : {}), ...(readReviewTrigger(cwd) ? { reviewTrigger: readReviewTrigger(cwd) } : {}), ...(readVerify(cwd) ? { verify: readVerify(cwd) } : {}), ...readPrecheckOptions(cwd), ...(model ? { builderModel: model } : {}), ...(readLeanSetting("reviewer_model", cwd) ? { reviewerModel: readLeanSetting("reviewer_model", cwd) } : {}), ...(readFixModel(cwd) ? { fixModel: readFixModel(cwd) } : {}), ...(readBuilderRouting(cwd) ? { builderRouting: readBuilderRouting(cwd) } : {}), ...(readVerifier(cwd) ? { verifier: readVerifier(cwd) } : {}), ...(readHostCaps(cwd) ? { hostCaps: readHostCaps(cwd) } : {}), ...readRelayCaps(), ...(readSequenceRegenerate(cwd) ? { sequenceRegenerate: readSequenceRegenerate(cwd) } : {}), ...(readBaseMerge(cwd) ? { baseMerge: readBaseMerge(cwd) } : {}), ...(readFollowupsDefaultMilestone(cwd) ? { followupsDefaultMilestone: readFollowupsDefaultMilestone(cwd) } : {}), ...(readFollowupsRollupLabel(cwd) ? { followupsRollupLabel: readFollowupsRollupLabel(cwd) } : {}) }) };
|
|
1750
1780
|
} else {
|
|
1751
1781
|
const laneScript = deps.laneScript ?? fileURLToPath(new URL("./forgedock.mjs", import.meta.url));
|
|
@@ -1842,7 +1872,9 @@ export async function runBatch({ argv, cwd: callerCwd = process.cwd(), env: call
|
|
|
1842
1872
|
// #4376: a cancel stops detached host lanes by SIGTERM to their group (pid-reuse checked by the result path); sandboxes run on unless `--cancel --stop-remote` (#4612).
|
|
1843
1873
|
const { killLedgerPid } = await import("./lean/effects.mjs");
|
|
1844
1874
|
const stopLane = deps.stopLane ?? ((n, rec) => (rec?.remote || rec?.handle ? remoteStop?.(n, rec) ?? false : rec?.pid ? killLedgerPid(rec.pid, batch.resultFile(n)) : false));
|
|
1845
|
-
|
|
1875
|
+
// #5241: a cancelled lane that ended gives its issue lease back, unless a live lane of another batch runs the issue.
|
|
1876
|
+
const releaseLease = deps.releaseLease ?? (leanIo?.projector ? async (n) => { await clearLease({ projector: leanIo.projector, issue: n, shouldClear: () => !batchMod.batchesOwning(root, repo, n, { exceptId: batch.id }).some((o) => !o.cancelled && o.running) }); } : null);
|
|
1877
|
+
lanes = { ...lanes, stopLane, releaseLease };
|
|
1846
1878
|
}
|
|
1847
1879
|
const orch = deps.orchestration ?? readOrchestration(cwd);
|
|
1848
1880
|
// #4965: --auto-children overrides forge.yaml; it is part of plan.argv, so --resume keeps it
|
|
@@ -1856,7 +1888,7 @@ export async function runBatch({ argv, cwd: callerCwd = process.cwd(), env: call
|
|
|
1856
1888
|
const limitsMod = await import("./lean/limits.mjs");
|
|
1857
1889
|
const limits = deps.limits ?? limitsMod.openLimits(limitsMod.limitsFile(env));
|
|
1858
1890
|
// #5094: with an account rotator the identity is its current account, and admissions hold only when every account is exhausted.
|
|
1859
|
-
const rotator = deps.rotator !== undefined ? deps.rotator : openRotator({ kind: readExecution(cwd)
|
|
1891
|
+
const rotator = deps.rotator !== undefined ? deps.rotator : openRotator({ kind: rotatorKind({ execution: readExecution(cwd), env }), env }); // #5205: detected
|
|
1860
1892
|
const identity = deps.identity ?? (() => limitsMod.laneBackendId(env, rotator));
|
|
1861
1893
|
const maint = deps.maintenance !== undefined ? deps.maintenance : readMaintenance(cwd);
|
|
1862
1894
|
const schedMod = await import("./lean/sched.mjs");
|
|
@@ -1971,6 +2003,7 @@ export async function runBatch({ argv, cwd: callerCwd = process.cwd(), env: call
|
|
|
1971
2003
|
}
|
|
1972
2004
|
let rows, childFields = null; // #4965: the host gh's accepted `issue list --json` fields, read once from its help
|
|
1973
2005
|
const healthCheck = (checkpoint) => batchHealth.runCheck({ batch, checkpoint, config: healthConf, repo, now: healthNow,
|
|
2006
|
+
resolve: (cands) => batchHealth.resolvedOnGithub(cands, (a) => leanIo.gh(a), repo),
|
|
1974
2007
|
alert: (text, health) => batchHealth.deliverAlert({ text, batchId: batch.id, health, sink, gh: (a) => leanIo.gh(a), repo, config: healthConf, epics: epicsOf(argv), ...(deps.notify ? { notify: deps.notify } : {}) }) });
|
|
1975
2008
|
let healthTimers = { cancel: () => {} };
|
|
1976
2009
|
try { healthTimers = batchHealth.scheduleChecks({ batch, created: healthCreated, config: healthConf, now: healthNow, ...(deps.healthTimer ? { setTimer: deps.healthTimer.set, clearTimer: deps.healthTimer.clear } : {}), check: healthCheck }); } catch { /* health is advisory */ }
|
|
@@ -2000,6 +2033,10 @@ export async function runBatch({ argv, cwd: callerCwd = process.cwd(), env: call
|
|
|
2000
2033
|
relabelNeedsHuman: deps.relabelNeedsHuman ?? makeRelabelNeedsHuman({ gh: (a) => leanIo.gh(a), repo }),
|
|
2001
2034
|
// #4481: a requeued or resumed issue that was closed or whose lane PR merged meanwhile is not run again
|
|
2002
2035
|
dispatchCheck: deps.dispatchCheck !== undefined ? deps.dispatchCheck : makeDispatchCheck({ gh: (a) => leanIo.gh(a), repo }),
|
|
2036
|
+
// #5204: the engine version is saved with the batch state, so a resume after an upgrade names it on each interrupted lane
|
|
2037
|
+
version: ENGINE_VERSION,
|
|
2038
|
+
// #5204: an interrupted, requeued lane runs nothing until it is dispatched again: workflow:building comes off (best effort)
|
|
2039
|
+
onInterrupted: deps.onInterrupted ?? (async (n) => leanIo.gh(["issue", "edit", String(n), "-R", repo, "--remove-label", "workflow:building"]).catch(() => {})),
|
|
2003
2040
|
// #4387: an out-of-set dependency labelled needs-human is not pulled into the batch
|
|
2004
2041
|
issueLabels: labelNames,
|
|
2005
2042
|
// #4725: a closed (completed) dependency is satisfied even when it still carries a stale needs-human label
|
|
@@ -2077,7 +2114,7 @@ export async function runBatch({ argv, cwd: callerCwd = process.cwd(), env: call
|
|
|
2077
2114
|
const ok = rows.every((r) => ["merged", "invalid", "decomposed"].includes(r.outcome));
|
|
2078
2115
|
// #4917: a batch with any pending issue is not finished: no report, so a resume or the daemon picks it up
|
|
2079
2116
|
let unfinished = false;
|
|
2080
|
-
try { unfinished = batch.pendingIssues().length > 0 && !batch.readCancel(); } catch { unfinished = false; } // a cancel ends the batch for good
|
|
2117
|
+
try { unfinished = (batch.pendingIssues().length > 0 || batch.unrunAdds().length > 0 || batch.unrunRequeues().length > 0) && !batch.readCancel(); } catch { unfinished = false; } // a cancel ends the batch for good
|
|
2081
2118
|
if (!unfinished) try { batch.writeReport({ rows, crossLane, ok, reclaimed, report: report.join("\n") }); } catch { /* the report is a cache of the rows */ }
|
|
2082
2119
|
try { await healthCheck("end"); } catch { /* #5167: health never fails a batch */ }
|
|
2083
2120
|
return { rows, crossLane, batch: batch.id, reclaimed, ok };
|
|
@@ -2302,7 +2339,7 @@ export async function poolFromCli(argv, deps = {}) {
|
|
|
2302
2339
|
export async function limitsFromCli(argv, deps = {}) {
|
|
2303
2340
|
const limitsMod = await import("./lean/limits.mjs");
|
|
2304
2341
|
const limits = deps.limits ?? limitsMod.openLimits(limitsMod.limitsFile());
|
|
2305
|
-
const rotator = deps.rotator !== undefined ? deps.rotator : openRotator({ kind: readExecution(process.cwd())
|
|
2342
|
+
const rotator = deps.rotator !== undefined ? deps.rotator : openRotator({ kind: rotatorKind({ execution: readExecution(process.cwd()), env: process.env }) }); // #5094, #5205: detected
|
|
2306
2343
|
const current = (deps.identity ?? (() => limitsMod.laneBackendId(process.env, rotator)))();
|
|
2307
2344
|
const usage = "usage: forgedock limits show | forgedock limits clear <id>|--all";
|
|
2308
2345
|
const [sub, arg] = argv;
|
|
@@ -2310,7 +2347,7 @@ export async function limitsFromCli(argv, deps = {}) {
|
|
|
2310
2347
|
const holds = limits.list();
|
|
2311
2348
|
if (!holds.length) console.log(`no usage-limit holds (this account: ${current})`);
|
|
2312
2349
|
for (const h of holds) console.log(`${h.id === current ? "*" : " "} ${h.id} until ${new Date(h.until).toISOString()} source ${h.source ?? "-"}`);
|
|
2313
|
-
for (const a of rotator?.accounts ?? []) console.log(` ${rotator.kind} account ${a.n} (${rotator.accountIdentity(a.n)}): 5h ${a.fiveHourPct}
|
|
2350
|
+
for (const a of rotator?.accounts ?? []) console.log(` ${rotator.kind} account ${a.n} (${rotator.accountIdentity(a.n)}): 5h ${a.stale ? "(stale)" : `${a.fiveHourPct}%`} resets ${new Date(a.fiveHourResetMs).toISOString()}`); // #5205: a passed reset is unknown, not its old %
|
|
2314
2351
|
return { holds, current };
|
|
2315
2352
|
}
|
|
2316
2353
|
if (sub === "clear") {
|
package/bin/experiment.mjs
CHANGED
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
* metrics: usd_median,wall_p50_ms,first_pass_rate,needs_human_rate (default all)
|
|
7
7
|
* targets: light.usd_median<=1.2xfull,light.first_pass_rate>=0.8 min_n: 10
|
|
8
8
|
* The arm is a hash of (id, issue), so a re-run or resume keeps its arm. Pure; the stats report is bin/stats/experiment.mjs.
|
|
9
|
+
* forge#5206: `<arm>.<key>: <value>` overrides a lane-shaping key for that arm only (ARM_OVERRIDE_KEYS); any other dotted
|
|
10
|
+
* key or an invalid value makes the whole declaration invalid (null, reason warned), never a partial apply.
|
|
9
11
|
*/
|
|
10
12
|
import { createHash } from "node:crypto";
|
|
11
13
|
import { readFileSync } from "node:fs";
|
|
@@ -16,10 +18,23 @@ export const EXPERIMENT_METRICS = ["usd_median", "wall_p50_ms", "first_pass_rate
|
|
|
16
18
|
export const BENCH_SCHEMA = "forge.bench.v1";
|
|
17
19
|
const NAME = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
|
|
18
20
|
const TARGET = /^([A-Za-z0-9][A-Za-z0-9._-]*)\.([a-z_0-9]+)(<=|>=)(\d+(?:\.\d+)?)(?:x([A-Za-z0-9][A-Za-z0-9._-]*))?$/;
|
|
21
|
+
const MODEL = /^[A-Za-z0-9._:[\]-]+$/;
|
|
22
|
+
const oneOf = (...vals) => (v) => vals.includes(v);
|
|
23
|
+
/** forge#5206: the keys an arm may override, each with its value check. `context_pack` excludes `ab` (its own arm hash). */
|
|
24
|
+
export const ARM_OVERRIDE_KEYS = Object.freeze({
|
|
25
|
+
"lean.explore": oneOf("on", "off"),
|
|
26
|
+
"lean.explore_model": (v) => MODEL.test(v),
|
|
27
|
+
"lean.light_mode": oneOf("off", "shadow", "on"),
|
|
28
|
+
"context_pack": oneOf("shadow", "on", "off"),
|
|
29
|
+
"review.verifier": oneOf("off", "shadow", "enforce"),
|
|
30
|
+
});
|
|
19
31
|
const list = (v) => String(v ?? "").split(",").map((s) => s.trim()).filter(Boolean);
|
|
20
32
|
|
|
21
|
-
/**
|
|
22
|
-
|
|
33
|
+
/**
|
|
34
|
+
* Parsed declaration {id, arms, ratio, metrics, targets, minN, overrides: {arm: {key: value}}}, or null when absent or
|
|
35
|
+
* invalid. An invalid arm override calls `warn(reason)`.
|
|
36
|
+
*/
|
|
37
|
+
export function parseExperiment(sec, { defaultMinN = 10, warn = () => {} } = {}) {
|
|
23
38
|
if (!sec || typeof sec !== "object") return null;
|
|
24
39
|
const id = String(sec.id ?? "").trim(), arms = list(sec.arms);
|
|
25
40
|
if (!NAME.test(id) || arms.length < 2 || new Set(arms).size !== arms.length || !arms.every((a) => NAME.test(a))) return null;
|
|
@@ -35,12 +50,49 @@ export function parseExperiment(sec, { defaultMinN = 10 } = {}) {
|
|
|
35
50
|
}
|
|
36
51
|
const mn = String(sec.min_n ?? "").trim();
|
|
37
52
|
if (mn && !/^\d+$/.test(mn)) return null;
|
|
38
|
-
|
|
53
|
+
const overrides = Object.fromEntries(arms.map((a) => [a, {}]));
|
|
54
|
+
for (const [k, raw] of Object.entries(sec)) {
|
|
55
|
+
if (!k.includes(".")) continue;
|
|
56
|
+
const arm = arms.filter((a) => k.startsWith(`${a}.`) && Object.hasOwn(ARM_OVERRIDE_KEYS, k.slice(a.length + 1))).sort((a, b) => b.length - a.length)[0];
|
|
57
|
+
if (!arm) { warn(`${k}: not <arm>.<key> with a declared arm and an allowed key (${Object.keys(ARM_OVERRIDE_KEYS).join(", ")})`); return null; }
|
|
58
|
+
const key = k.slice(arm.length + 1), v = String(raw ?? "").trim();
|
|
59
|
+
if (!ARM_OVERRIDE_KEYS[key](v)) { warn(`${k}: invalid value "${v}"`); return null; }
|
|
60
|
+
overrides[arm][key] = v;
|
|
61
|
+
}
|
|
62
|
+
return { id, arms, ratio, metrics, targets, minN: mn ? Number(mn) : defaultMinN, overrides };
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** forge#5206: the {key: value} overrides of one arm ({} for none, an unknown arm or no experiment). */
|
|
66
|
+
export const armOverrides = (exp, arm) => ({ ...(exp?.overrides?.[arm] ?? {}) });
|
|
67
|
+
|
|
68
|
+
/** forge#5206: the recorded form of an arm's overrides, sorted `k=v` joined by `,` ("" when none). */
|
|
69
|
+
export const overridesText = (ov) => Object.keys(ov ?? {}).sort().map((k) => `${k}=${ov[k]}`).join(",");
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* forge#5206: the lane options of `issue` with its arm's overrides applied, and the run tag {experiment, arm, arm_overrides}.
|
|
73
|
+
* Without `opts.experiment` the very same options object and an empty tag (no change to today's lane).
|
|
74
|
+
*/
|
|
75
|
+
export function applyArmOverrides(opts, issue) {
|
|
76
|
+
const exp = opts?.experiment;
|
|
77
|
+
if (!exp) return { options: opts, tag: {} };
|
|
78
|
+
const arm = assignArm(exp, issue), ov = armOverrides(exp, arm), has = (k) => Object.hasOwn(ov, k);
|
|
79
|
+
const options = { ...opts };
|
|
80
|
+
if (has("lean.explore") || has("lean.explore_model")) {
|
|
81
|
+
options.explore = { ...(opts.explore ?? {}), ...(has("lean.explore") ? { mode: ov["lean.explore"] } : {}), ...(has("lean.explore_model") ? { model: ov["lean.explore_model"] } : {}) };
|
|
82
|
+
}
|
|
83
|
+
if (has("lean.light_mode")) options.light = { ...(opts.light ?? {}), mode: ov["lean.light_mode"] };
|
|
84
|
+
if (has("context_pack")) options.contextPack = { ...(opts.contextPack ?? {}), mode: ov.context_pack };
|
|
85
|
+
if (has("review.verifier")) options.verifier = { ...(opts.verifier ?? {}), mode: ov["review.verifier"] };
|
|
86
|
+
return { options, tag: { experiment: exp.id, arm, arm_overrides: overridesText(ov) } };
|
|
39
87
|
}
|
|
40
88
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
89
|
+
const warned = new Set();
|
|
90
|
+
const stderrWarn = (m) => { if (!warned.has(m)) { warned.add(m); process.stderr.write(`forge.yaml experiment: ${m}; experiment ignored\n`); } };
|
|
91
|
+
/** forge.yaml `experiment:` of `cwd`, or null; an invalid arm override is warned (#5206). */
|
|
92
|
+
export function readExperiment(cwd = process.cwd(), warn = stderrWarn) {
|
|
93
|
+
let raw;
|
|
94
|
+
try { raw = readFileSync(join(cwd, "forge.yaml"), "utf8"); } catch { return null; }
|
|
95
|
+
try { return parseExperiment(parseForgeYaml(raw, { dottedSections: ["experiment"] })?.experiment, { warn }); } catch { return null; }
|
|
44
96
|
}
|
|
45
97
|
|
|
46
98
|
/** Deterministic arm of an issue: sha1(id:issue) mod the ratio total, walked over the arms in declared order. */
|
package/bin/forge-utils.mjs
CHANGED
|
@@ -43,9 +43,11 @@
|
|
|
43
43
|
* YAML features. Intended only for the flat key-value structure of forge.yaml.
|
|
44
44
|
*
|
|
45
45
|
* @param {string} raw - Raw string content of a forge.yaml file.
|
|
46
|
+
* @param {{dottedSections?: string[]}} [opts] - forge#5206: sections whose nested keys may also contain `.` and `-`
|
|
47
|
+
* after the first character (e.g. `experiment:` arm overrides `on.lean.explore: on`); other sections are unchanged.
|
|
46
48
|
* @returns {Record<string, string | Record<string, string>>}
|
|
47
49
|
*/
|
|
48
|
-
export function parseForgeYaml(raw) {
|
|
50
|
+
export function parseForgeYaml(raw, { dottedSections = [] } = {}) {
|
|
49
51
|
const result = {};
|
|
50
52
|
let currentSection = null;
|
|
51
53
|
|
|
@@ -78,7 +80,9 @@ export function parseForgeYaml(raw) {
|
|
|
78
80
|
// Nested scalar under current section: ` key: value`
|
|
79
81
|
if (currentSection && /^\s+/.test(line)) {
|
|
80
82
|
const nestedMatch = line.match(
|
|
81
|
-
|
|
83
|
+
dottedSections.includes(currentSection)
|
|
84
|
+
? /^\s+([a-zA-Z_][a-zA-Z0-9_.-]*):\s+"([^"]*)"(?:\s*#.*)?$|^\s+([a-zA-Z_][a-zA-Z0-9_.-]*):\s+([^#\n]+?)(?:\s*#.*)?$/
|
|
85
|
+
: /^\s+([a-zA-Z_][a-zA-Z0-9_]*):\s+"([^"]*)"(?:\s*#.*)?$|^\s+([a-zA-Z_][a-zA-Z0-9_]*):\s+([^#\n]+?)(?:\s*#.*)?$/,
|
|
82
86
|
);
|
|
83
87
|
if (nestedMatch) {
|
|
84
88
|
const key = nestedMatch[1] ?? nestedMatch[3];
|
package/bin/forgedock.mjs
CHANGED
|
@@ -3428,7 +3428,11 @@ function help() {
|
|
|
3428
3428
|
["npx forgedock review-staging [<PR>] [--thorough] [--json]", "Staging->main review pre-dispatch: route marker, open-finding gate, scope, prepare, roster; writes one reviewer brief per domain"],
|
|
3429
3429
|
["npx forgedock review-staging [<PR>] --finalize --test-gate-output <file>", "Staging->main review post-dispatch: delivery, test-gate verdict, extract/classify/file-prepare; prints the findings to file"],
|
|
3430
3430
|
["npx forgedock review-staging [<PR>] --summary [--filed <N>]...", "Staging->main review Phase 8: verdict and summary comment with the FORGE:GATE_PASS / FORGE:GATE_FAILURE marker"],
|
|
3431
|
+
["npx forgedock release [--repo owner/repo] [--merge] [--watch] [--resume <id>]", "Staging->default release as one resumable job: preflight, release PR, review, fixes, promotion (stops at GATE_PASS unless --merge or release.auto_merge), post-merge"],
|
|
3431
3432
|
["npx forgedock stats [--since <ver|date>] [--repo owner/repo] [--json] [--refresh]", "Version-over-version cost/time/flow/review/gate report from GitHub telemetry (no model)"],
|
|
3433
|
+
["npx forgedock stats --self-filed [--repo R] [--since D]", "Share of new issues the pipeline filed itself, by kind, against the 15% target (#5207)"],
|
|
3434
|
+
["npx forgedock stats --conformance-outcomes [--repo owner/repo] [--since <date>] [--window-days 7]", "Read-only: do conformance blocks predict post-merge defects (2x2 per repo and failure kind)"],
|
|
3435
|
+
["npx forgedock stats --depth [--since <ver|date>] [--min-n N] [--offline] [--repo owner/repo] [--json]", "Light-eligible vs ineligible lane outcomes, by reason/signal, and the #5052 light-lane promotion verdict"],
|
|
3432
3436
|
["npx forgedock doctor", "Check installation health"],
|
|
3433
3437
|
["npx forgedock doctor --fix", "Auto-fix deterministic issues (symlinks, hook, labels, legacy block) and reclaim ForgeDock-owned leftovers (forge.yaml hygiene TTLs)"],
|
|
3434
3438
|
["npx forgedock doctor --lanes", "Lane preflight: pool token, pool agent version, PATH shim loops, gh --json fields; prints every check pass/fail"],
|
|
@@ -4003,7 +4007,7 @@ async function watch() {
|
|
|
4003
4007
|
const SPLASH_COMMANDS = new Set(["run", "bootstrap", "run-issue", "orchestrate", "triage", "probe", "gc", "resume-stalled", "demo", "doctor", "watch", "help", "--help", "-h"]);
|
|
4004
4008
|
const KNOWN_COMMANDS = new Set([
|
|
4005
4009
|
"install", "init", "enable", "disable", "status", "uninstall", "update",
|
|
4006
|
-
"run", "bootstrap", "backend-check", "run-issue", "orchestrate", "milestone", "milestone-sync", "fix-close-reasons", "guards", "triage", "probe", "review-staging", "gc", "resume-stalled", "demo", "doctor", "watch", "issue-watch", "prod-watch", "selftest", "labels", "config", "stats", "limits", "decisions", "sched", "schedd", "pool", "check", "guide", "help", "--help", "-h",
|
|
4010
|
+
"run", "bootstrap", "backend-check", "run-issue", "orchestrate", "milestone", "milestone-sync", "fix-close-reasons", "guards", "triage", "probe", "review-staging", "release", "gc", "resume-stalled", "demo", "doctor", "watch", "issue-watch", "prod-watch", "selftest", "labels", "config", "stats", "limits", "decisions", "sched", "schedd", "pool", "check", "guide", "help", "--help", "-h",
|
|
4007
4011
|
"version", "--version", "-v",
|
|
4008
4012
|
]);
|
|
4009
4013
|
if (SPLASH_COMMANDS.has(command) || !KNOWN_COMMANDS.has(command)) splash(command);
|
|
@@ -4268,6 +4272,16 @@ switch (command) {
|
|
|
4268
4272
|
}
|
|
4269
4273
|
break;
|
|
4270
4274
|
}
|
|
4275
|
+
case "release": {
|
|
4276
|
+
const { releaseFromCli } = await import("./lean/release.mjs");
|
|
4277
|
+
try {
|
|
4278
|
+
exitCode = await releaseFromCli(restArgs);
|
|
4279
|
+
} catch (err) {
|
|
4280
|
+
process.stderr.write(`${RED}${err.message}${RESET}\n`);
|
|
4281
|
+
exitCode = 1;
|
|
4282
|
+
}
|
|
4283
|
+
break;
|
|
4284
|
+
}
|
|
4271
4285
|
case "issue-watch": {
|
|
4272
4286
|
const { issueWatchFromCli } = await import("./lean/issuewatch.mjs");
|
|
4273
4287
|
try {
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
3
|
+
/**
|
|
4
|
+
* Late account capture for a lane (#5268). The tokenbaton shim exports the chosen account and then execs claude with
|
|
5
|
+
* the same pid, so a single /proc read at spawn sees the shim's env and finds no account. `watchAccount` keeps
|
|
6
|
+
* reading while the child is alive until an account shows up, so a usage limit can exclude the limited account.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Polls `read()` (a number or null) every `intervalMs` for up to `maxMs` until it returns a value, then calls `onFound`.
|
|
11
|
+
* Reads once at once. Returns `{stop, current}`; `current()` is the account found so far (or null). Timers are unref'd.
|
|
12
|
+
*/
|
|
13
|
+
export function watchAccount(read, { intervalMs = 200, maxMs = 15000, setTimer = setTimeout, clearTimer = clearTimeout, onFound = () => {} } = {}) {
|
|
14
|
+
let found = null, timer = null, stopped = false, waited = 0;
|
|
15
|
+
const probe = () => { try { const v = read(); return v ?? null; } catch { return null; } };
|
|
16
|
+
const stop = () => { stopped = true; if (timer !== null) { clearTimer(timer); timer = null; } };
|
|
17
|
+
const tick = () => {
|
|
18
|
+
timer = null;
|
|
19
|
+
if (stopped) return;
|
|
20
|
+
const v = probe();
|
|
21
|
+
if (v !== null) { found = v; stopped = true; onFound(v); return; }
|
|
22
|
+
waited += intervalMs;
|
|
23
|
+
if (waited >= maxMs) { stopped = true; return; }
|
|
24
|
+
timer = setTimer(tick, intervalMs); timer?.unref?.();
|
|
25
|
+
};
|
|
26
|
+
tick();
|
|
27
|
+
return { stop, current: () => found, refresh: () => { if (found === null) { const v = probe(); if (v !== null) { found = v; onFound(v); } } return found; } };
|
|
28
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
3
|
+
import { describe, it } from "node:test";
|
|
4
|
+
import assert from "node:assert/strict";
|
|
5
|
+
import { watchAccount } from "./account-watch.mjs";
|
|
6
|
+
|
|
7
|
+
const fakeTimers = () => { const q = []; return { q, setTimer: (fn) => { const t = { fn, cleared: false }; q.push(t); return t; }, clearTimer: (t) => { t.cleared = true; }, run: () => { const t = q.shift(); if (t && !t.cleared) t.fn(); } }; };
|
|
8
|
+
|
|
9
|
+
describe("#5268 watchAccount", () => {
|
|
10
|
+
it("resolves once the shim has exec'd (null reads first), then stops polling", () => {
|
|
11
|
+
const ft = fakeTimers(); let n = 0, got = null;
|
|
12
|
+
const w = watchAccount(() => (++n >= 3 ? 2 : null), { setTimer: ft.setTimer, clearTimer: ft.clearTimer, onFound: (a) => { got = a; } });
|
|
13
|
+
assert.equal(w.current(), null);
|
|
14
|
+
ft.run(); assert.equal(w.current(), null);
|
|
15
|
+
ft.run(); assert.equal(w.current(), 2); assert.equal(got, 2);
|
|
16
|
+
assert.equal(ft.q.length, 0, "no further timer");
|
|
17
|
+
});
|
|
18
|
+
it("gives up after maxMs and never throws on a failing read", () => {
|
|
19
|
+
const ft = fakeTimers();
|
|
20
|
+
const w = watchAccount(() => { throw new Error("gone"); }, { intervalMs: 100, maxMs: 300, setTimer: ft.setTimer, clearTimer: ft.clearTimer });
|
|
21
|
+
for (let i = 0; i < 10; i++) ft.run();
|
|
22
|
+
assert.equal(w.current(), null); assert.equal(ft.q.length, 0);
|
|
23
|
+
});
|
|
24
|
+
it("stop() clears the pending timer; refresh() re-reads once", () => {
|
|
25
|
+
const ft = fakeTimers(); let v = null;
|
|
26
|
+
const w = watchAccount(() => v, { setTimer: ft.setTimer, clearTimer: ft.clearTimer });
|
|
27
|
+
const t = ft.q[0]; w.stop(); assert.equal(t.cleared, true);
|
|
28
|
+
v = 3; assert.equal(w.refresh(), 3); assert.equal(w.current(), 3);
|
|
29
|
+
});
|
|
30
|
+
});
|
package/bin/lean/activation.mjs
CHANGED
|
@@ -74,3 +74,23 @@ export async function dormancyReport({ introduced = [], flagState, decisions = [
|
|
|
74
74
|
}
|
|
75
75
|
return out.sort((a, b) => b.days - a.days);
|
|
76
76
|
}
|
|
77
|
+
|
|
78
|
+
const LIVE_MODES = /^(?:on|true|1|enforce|enforced|live|treated|active)$/i;
|
|
79
|
+
const MODE_LINE_RE = /^["']?([A-Za-z_][\w.-]*)["']?\s*[:=]\s*["']?([A-Za-z0-9_]+)["']?\s*,?;?\s*(?:#.*|\/\/.*)?$/;
|
|
80
|
+
/**
|
|
81
|
+
* #5240: the current mode of every rollout flag (declared in the forge.yaml `rollouts` registry files) that a changed file
|
|
82
|
+
* names, `[{flag, mode, live}]`; `live` is false for shadow/off/cohort-less modes, i.e. the change is inert in production.
|
|
83
|
+
* `read(path)` returns file text or throws; unreadable files and an absent registry give [].
|
|
84
|
+
*/
|
|
85
|
+
export function rolloutModes(cfg, changedFiles, read) {
|
|
86
|
+
if (!cfg?.files?.length) return [];
|
|
87
|
+
const modes = new Map();
|
|
88
|
+
for (const f of cfg.files) {
|
|
89
|
+
let text; try { text = String(read(f)); } catch { continue; }
|
|
90
|
+
for (const l of text.split("\n")) { const m = MODE_LINE_RE.exec(l.trim()); if (m) modes.set(m[1], m[2]); }
|
|
91
|
+
}
|
|
92
|
+
if (!modes.size) return [];
|
|
93
|
+
const texts = [];
|
|
94
|
+
for (const f of changedFiles ?? []) { if (inRegistry(cfg, f)) continue; try { texts.push(String(read(f))); } catch { /* deleted or unreadable */ } }
|
|
95
|
+
return [...modes].filter(([flag]) => texts.some((t) => flagRe(flag).test(t))).map(([flag, mode]) => ({ flag, mode, live: LIVE_MODES.test(mode) })).sort((a, b) => a.flag.localeCompare(b.flag));
|
|
96
|
+
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
3
3
|
import { describe, it } from "node:test";
|
|
4
4
|
import assert from "node:assert/strict";
|
|
5
|
-
import { readRollouts, detectNewOffKeys, activationFailures, dormancyReport, coversFlag } from "./activation.mjs";
|
|
5
|
+
import { readRollouts, detectNewOffKeys, activationFailures, dormancyReport, coversFlag, rolloutModes } from "./activation.mjs";
|
|
6
6
|
import { precheck } from "./conformance.mjs";
|
|
7
7
|
|
|
8
8
|
const cfg = { files: ["config/rollouts.json"], days: 14 };
|
|
@@ -73,3 +73,16 @@ describe("dormancy report (#4769)", () => {
|
|
|
73
73
|
assert.deepEqual(r.map((x) => x.flag), ["egress_country_exploration", "clearance_exit_routing"]);
|
|
74
74
|
});
|
|
75
75
|
});
|
|
76
|
+
|
|
77
|
+
describe("#5240 rolloutModes", () => {
|
|
78
|
+
const files = { "config/rollouts.json": '{\n "t4_retry_byte_gate": "shadow",\n "other_flag": "on",\n "unused": "off"\n}', "svc/retry.py": "if rollout('t4_retry_byte_gate'):\n pass\nother_flag_x = 1", "svc/b.py": "other_flag()" };
|
|
79
|
+
const read = (f) => { if (!(f in files)) throw new Error("ENOENT"); return files[f]; };
|
|
80
|
+
it("reports the mode of flags a changed file names; shadow/off are not live", () => {
|
|
81
|
+
assert.deepEqual(rolloutModes(cfg, ["svc/retry.py", "svc/b.py"], read), [{ flag: "other_flag", mode: "on", live: true }, { flag: "t4_retry_byte_gate", mode: "shadow", live: false }]);
|
|
82
|
+
});
|
|
83
|
+
it("is empty without a registry, an unreadable registry, or a change that names no flag", () => {
|
|
84
|
+
assert.deepEqual(rolloutModes(null, ["svc/retry.py"], read), []);
|
|
85
|
+
assert.deepEqual(rolloutModes(cfg, ["svc/retry.py"], () => { throw new Error("x"); }), []);
|
|
86
|
+
assert.deepEqual(rolloutModes(cfg, ["gone.py"], read), []);
|
|
87
|
+
});
|
|
88
|
+
});
|