@nodii/dev 0.6.216 → 0.6.217
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 +29 -9
- package/dist/cli.js +12 -6
- package/dist/core.js +1 -1
- package/dist/drill.js +18 -5
- package/dist/harness.js +21 -0
- package/dist/heavy-slot.sh +115 -14
- package/dist/heavy.js +13 -5
- package/dist/machine-floor.js +10 -6
- package/dist/nodii-dev.js +5 -1
- package/dist/push-hook.sh +98 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -171,11 +171,11 @@ nodii-dev heavy status
|
|
|
171
171
|
- **The machine's floor (DEV-PROCESS-2).** Every job reads the floor before it queues and again when a slot is free (`src/machine-floor.js`). Available memory, after what running jobs hold back for their peaks, must be at least 10 GB (5 GB for a light job); swap used at most 24 GB; disk free at least 15 GB. A running job holds back its class's peak (7 GB heavy, 1 GB light) less what its process tree uses now. Under the floor a job exits 75 at once with `MACHINE_UNDER_FLOOR`, naming the reading, the figure and the five largest holders of memory. It is never queued and never let through: there is no exception for a lone job, a landing or a push (hub-490). The readings use the system tools' absolute paths (`/usr/bin/vm_stat`, `/usr/sbin/sysctl vm.swapusage`, `/bin/df -Pk /`), on the install's own node.
|
|
172
172
|
- **The floor file.** The floor, the class peaks, the ceilings (3 heavy slots, one of them only for a push forced heavy; 8 light slots) and the 10 s stagger live in `/etc/nodii/floor.env`. It counts only when root owns it and `/etc/nodii`, neither is group- or world-writable, and the lanes' user cannot write it; else the shipped defaults hold, and `heavy status` says why. Only the machine owner installs or changes it, with their password (`sudo install -d -o root -g wheel -m 755 /etc/nodii && sudo install -o root -g wheel -m 644 floor.env /etc/nodii/floor.env`). No variable moves it or the slot directory: `NODII_RESOURCE_LIMITS`, `HEAVY_SLOT_DIR`, `NODII_HEAVY_SLOT`, `NODII_HEAVY_SLOT_HELD` and `HEAVY_LANDING` are gone. `~/.config/nodii-resources/limits.env` keeps only the coordinator's `LANE_CAP`, `STACK_CAP`, `LIGHT_LANE_CAP` and `DEV_SERVER_CAP`.
|
|
173
173
|
- `--tighten memory=GB|swap=GB|disk=GB` (repeatable, or a comma list) makes one call stricter than the floor; a figure that would loosen it exits 2 (`USAGE`). `lane launch` and `lane resume` take it too.
|
|
174
|
-
- **
|
|
175
|
-
- The queue is `heavy-slot`
|
|
174
|
+
- **Heavy is end-to-end; light is a short list (MW2-51).** A heavy slot is for end-to-end, real-stack and browser-flow work: Playwright, Cypress and other browser drivers, an `e2e`, `integration`, real-stack or stack script, an image build and a detached stack start. A light slot (under the light floor, 5 GB, with no stagger) is for a typecheck or lint on the diff's files only (`tsc`, `tsgo`, `vue-tsc`, `eslint`, `biome` or `oxlint` naming the files it checks, or a package manager's `typecheck`, `lint` or `tsc` script scoped by its name: `:affected`, `:changed`, `:touched`, `:diff`, `:staged`; a whole-repository typecheck or lint counts heavy), a unit-test run naming at most 20 test files (`bun test`, `vitest`, `jest`, `mocha`, `node --test`; no globs, no compound commands) and `git push`. Anything else counts heavy (`sleep`, `true`, a whole suite, an install), and a command declared light with `--size light` that is none of those counts heavy and says so. `--size heavy` makes any job heavy. Light locks live in `/tmp/nodii-heavy-slots/light`.
|
|
175
|
+
- The queue is `heavy-slot` v30, shipped in this package (`src/heavy-slot.sh`, run by bash 3.2 or later): a slot cap, the floor, a stagger between admissions, a landing reserve only a push may use, FIFO order, reclaiming dead holders, and pass-through for teardowns (`compose down`, `stack:down`) and a single `pnpm validate:<name>`. It refuses dev servers (K02-7). A foreground `docker compose up` never exits, so it never takes a slot either. Locks live in `/tmp/nodii-heavy-slots`, the directory every older copy uses.
|
|
176
176
|
- A job waiting for a slot (above the floor) prints its queue place and its wait when it starts waiting and once a minute after.
|
|
177
177
|
- **No nested queuing (NODII-DEV-CLI-86, v29).** A `heavy run` whose process tree runs under a slot's holder runs in that slot and never queues for a second one (`lane check`'s gates, a reviewer, a push's hooks). It says so (`[heavy-slot] nested in slot N`). Nesting is proven by the process tree, never by a variable.
|
|
178
|
-
- **Every decision is logged.** Each admission, with the readings it was made on, and each refusal goes to `~/.config/nodii-resources/admissions.jsonl`. `heavy status` prints the floor file, memory available and after reservations, swap used and disk free beside the floor, each class's floor and peak, the ceilings, the held slots and the last hour's admissions, flagging any admission under the floor.
|
|
178
|
+
- **Every decision is logged.** Each admission, with the readings it was made on (the read under the admit lock that admitted it, without the job's own slot), and each refusal goes, once, to `~/.config/nodii-resources/admissions.jsonl`. `heavy status` prints the floor file, memory available and after reservations, swap used and disk free beside the floor, each class's floor and peak, the ceilings, the held slots and the last hour's admissions, flagging any admission under the floor.
|
|
179
179
|
- `lane launch` and `lane resume` read the floor first, before the coordinator, the governor, the cap and the account; `--preflight-only` then stops before anything is created or resumed.
|
|
180
180
|
- **Orphaned slots are reclaimed (NODII-DEV-CLI-86).** A slot records its lane, the agent session that took it, the job's worktree and its process group. A slot's holder (the `heavy run` that started the job) checks its own slot once a minute, and reclaims it only when all of these hold:
|
|
181
181
|
- it has been held at least 10 minutes;
|
|
@@ -1913,19 +1913,37 @@ are left alone; the repository's orchestrator runs `harness update` in a
|
|
|
1913
1913
|
|
|
1914
1914
|
### Push after every commit (O22)
|
|
1915
1915
|
|
|
1916
|
+
Rule basis (interim, recorded): DEV-PROCESS-13 (Objective O22) and the
|
|
1917
|
+
operator's words of 25 Nov 2026 (inputs.md §34, relayed), "Lanes push after
|
|
1918
|
+
every commit, so nothing lives only on this Mac". No MW clause states it yet.
|
|
1919
|
+
The planner (steward-dev-process) ruled on 26 Nov that this citation is the
|
|
1920
|
+
basis until the MW clause it is drafting is uploaded. The hook's shape follows
|
|
1921
|
+
the planner's done-check decisions on that page.
|
|
1922
|
+
|
|
1916
1923
|
`harness install` and `harness update` (not `--dry-run`) also write a git
|
|
1917
1924
|
hook, `push-hook.sh` from this package, as both `post-commit` and
|
|
1918
1925
|
`post-rewrite` in the directory `git rev-parse --git-path hooks` names, so a
|
|
1919
1926
|
`core.hooksPath` is respected. They do this first, from the CLI's own copy,
|
|
1920
|
-
so a checkout that cannot reach Dev still gets them.
|
|
1927
|
+
so a checkout that cannot reach Dev still gets them. That holds in a lane
|
|
1928
|
+
session too: when the lane's own checks refuse the command first (no sign-in,
|
|
1929
|
+
Dev out of reach, an amendment to acknowledge), the hooks still go in and the
|
|
1930
|
+
refusal lists them. A hook already there that
|
|
1921
1931
|
nodii-dev did not write is moved to `<hook>.nodii-chained` and keeps running
|
|
1922
1932
|
first, with the same arguments and input. When one is already chained, the new
|
|
1923
1933
|
one is left alone and the output says so. The hooks sit in the git directory,
|
|
1924
1934
|
not the working tree. Every worktree of the repository shares them, and they
|
|
1925
1935
|
are not harness files.
|
|
1926
1936
|
|
|
1927
|
-
After every commit, amend or rebase, the hook
|
|
1928
|
-
|
|
1937
|
+
After every commit, amend or rebase, the hook marks the branch dirty and
|
|
1938
|
+
returns at once. One worker per branch holds `<git-common-dir>/nodii-push/<branch>.lock`
|
|
1939
|
+
while it scans and pushes. It waits until no commit has marked the branch for
|
|
1940
|
+
2 s, pushes the tip, and pushes once more only if a commit marked it meanwhile,
|
|
1941
|
+
so a burst costs at most two scans and pushes. A lock is live while its pid
|
|
1942
|
+
runs (`kill -0`, which a sandbox allows) and it was touched within 8 minutes:
|
|
1943
|
+
the worker touches it before every wait, so a reused pid holds it at most that
|
|
1944
|
+
long. Where `ps` may run, the process's start time is also compared. A stale
|
|
1945
|
+
lock is taken over by the next commit, by an atomic rename, and that commit's
|
|
1946
|
+
worker pushes the tip. In the background, the worker:
|
|
1929
1947
|
|
|
1930
1948
|
- pushes the current branch's tip to `origin`, never with force and never
|
|
1931
1949
|
`main` or `master`. A commit on a detached HEAD is not pushed: an `INFO`
|
|
@@ -1942,9 +1960,11 @@ background:
|
|
|
1942
1960
|
retry: push by hand.
|
|
1943
1961
|
- retries any other failure, such as origin being unreachable, at 20 s,
|
|
1944
1962
|
doubling up to 5 minutes, for up to 24 h.
|
|
1945
|
-
- after a push lands, opens a draft PR against
|
|
1946
|
-
`main`) when the branch has no open PR, retried
|
|
1947
|
-
|
|
1963
|
+
- after a push lands and the push lock is released, opens a draft PR against
|
|
1964
|
+
main (`origin/HEAD`, else `main`) when the branch has no open PR, retried
|
|
1965
|
+
the same way under its own lock (`<branch>.pr`). A PR create that keeps
|
|
1966
|
+
failing (no token, GitHub down) never delays a later commit's push. A
|
|
1967
|
+
repository without draft PRs gets a ready one.
|
|
1948
1968
|
|
|
1949
1969
|
GitHub is reached at `GITHUB_API_URL` (default `https://api.github.com`), with
|
|
1950
1970
|
`GH_TOKEN`, `GITHUB_TOKEN` or `gh auth token`. On api.github.com, the PR list
|
package/dist/cli.js
CHANGED
|
@@ -26,7 +26,7 @@ import {
|
|
|
26
26
|
} from "./oauth.js";
|
|
27
27
|
import { FIGMA_HOOK_DENIALS, heartbeatFromHook, postHook, postHookFailure, preHook, settingsSnippet, workflowSuggestion } from "./hooks.js";
|
|
28
28
|
import { setupCommand } from "./setup.js";
|
|
29
|
-
import { harnessCommand, harnessWeekCommand } from "./harness.js";
|
|
29
|
+
import { harnessCommand, harnessWeekCommand, pushHooksDespiteRefusal } from "./harness.js";
|
|
30
30
|
import { readPolicy, repoCommand } from "./repo-policy.js";
|
|
31
31
|
import { repoDocsCheckCommand } from "./tooling-docs.js";
|
|
32
32
|
import { testCommand } from "./impact.js";
|
|
@@ -558,9 +558,11 @@ Usage: nodii-dev <command> [options] [--json]
|
|
|
558
558
|
# no variable changes them. --tighten memory=GB|swap=GB|disk=GB makes this
|
|
559
559
|
# one call stricter (a figure that would loosen the floor exits 2). A heavy
|
|
560
560
|
# run under a slot's holder (its process tree) runs in that slot (K02-6).
|
|
561
|
-
#
|
|
562
|
-
#
|
|
563
|
-
#
|
|
561
|
+
# End-to-end, real-stack and browser work takes a heavy slot; a typecheck,
|
|
562
|
+
# a lint, a unit test naming at most 20 files and a push take a light one;
|
|
563
|
+
# anything else counts heavy, and so does a command declared light (--size
|
|
564
|
+
# light) that is none of those (MW2-51). --size heavy forces heavy.
|
|
565
|
+
# A slot held 10 min whose lane is down in Dev and whose
|
|
564
566
|
# agent is gone is reclaimed and logged. In a lane the safety hook
|
|
565
567
|
# refuses unqueued heavy work (SAFETY_HEAVY_UNQUEUED; a heavy-slot.sh copy is
|
|
566
568
|
# no queue) and every-page checks, CI only (SAFETY_CI_ONLY)
|
|
@@ -1174,8 +1176,12 @@ export async function main(argv = process.argv.slice(2)) {
|
|
|
1174
1176
|
// DEV-PROCESS-5, row 29b: the retired lane-ask family is refused before anything reaches Dev.
|
|
1175
1177
|
refuseRetiredLaneAsk(argv);
|
|
1176
1178
|
if (runsBackstop(argv)) {
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
+
try {
|
|
1180
|
+
await amendmentGuard(argv);
|
|
1181
|
+
await showWaitingResults();
|
|
1182
|
+
} catch (error) {
|
|
1183
|
+
throw await pushHooksDespiteRefusal(argv, error);
|
|
1184
|
+
}
|
|
1179
1185
|
}
|
|
1180
1186
|
if (argv.length === 1 && ["--version", "-v"].includes(argv[0]))
|
|
1181
1187
|
return console.log(VERSION);
|
package/dist/core.js
CHANGED
|
@@ -4,7 +4,7 @@ import { chmod, lstat, mkdir, readFile, rename, rm, writeFile } from "node:fs/pr
|
|
|
4
4
|
import { homedir, platform } from "node:os";
|
|
5
5
|
import { basename, dirname, join } from "node:path";
|
|
6
6
|
|
|
7
|
-
export const VERSION = "0.6.
|
|
7
|
+
export const VERSION = "0.6.217";
|
|
8
8
|
export const configPath = () =>
|
|
9
9
|
process.env.NODII_DEV_CONFIG_PATH ??
|
|
10
10
|
join(homedir(), ".config/nodii-dev/config.json");
|
package/dist/drill.js
CHANGED
|
@@ -96,17 +96,29 @@ const must = (condition, message) => { if (!condition) throw new Failed(message)
|
|
|
96
96
|
|
|
97
97
|
// ---- Dev, as any CLI reads it ------------------------------------------------
|
|
98
98
|
|
|
99
|
-
function devClient(request, calls) {
|
|
99
|
+
export function devClient(request, calls) {
|
|
100
100
|
return async (method, path, body) => {
|
|
101
101
|
calls.push(`${method} ${path}`);
|
|
102
102
|
try {
|
|
103
|
-
|
|
103
|
+
const payload = await request(method, path, body);
|
|
104
|
+
// Dev envelopes every answer as { data } (S09-5) except its OpenAPI document, which is served as is.
|
|
105
|
+
return { ok: true, data: payload?.data ?? (payload?.openapi ? payload : undefined) };
|
|
104
106
|
} catch (error) {
|
|
105
107
|
return { ok: false, code: error?.code ?? "ERROR", message: String(error?.message ?? error) };
|
|
106
108
|
}
|
|
107
109
|
};
|
|
108
110
|
}
|
|
109
111
|
|
|
112
|
+
/** A refusal as the CLI prints it, `CODE: message` (cli.js fail()), --json or not; null when there is none. */
|
|
113
|
+
export function refusal(stderr) {
|
|
114
|
+
const lines = String(stderr ?? "").split("\n").map((line) => line.trim()).filter(Boolean);
|
|
115
|
+
for (const line of lines.reverse()) {
|
|
116
|
+
const match = /^([A-Z][A-Z0-9_]{2,}): ?(.*)$/.exec(line);
|
|
117
|
+
if (match) return { code: match[1], message: match[2] };
|
|
118
|
+
}
|
|
119
|
+
return null;
|
|
120
|
+
}
|
|
121
|
+
|
|
110
122
|
/** The CLI itself, from this release, under the caller's own config. */
|
|
111
123
|
export function cliRunner({ entry = ENTRY, execPath = process.execPath, env = process.env, calls, recorder = null }) {
|
|
112
124
|
return (args, { timeoutMs = 3 * MINUTE } = {}) => new Promise((resolve, reject) => {
|
|
@@ -123,7 +135,7 @@ export function cliRunner({ entry = ENTRY, execPath = process.execPath, env = pr
|
|
|
123
135
|
let json = null;
|
|
124
136
|
try { json = JSON.parse(stdout); } catch {}
|
|
125
137
|
if (!json) try { json = JSON.parse(stderr); } catch {}
|
|
126
|
-
const error = json?.error ?? null;
|
|
138
|
+
const error = json?.error ?? (code === 0 ? null : refusal(stderr));
|
|
127
139
|
resolve({ code, json, error, ok: code === 0, text: `${stdout}${stderr}`.trim().slice(0, 4000) });
|
|
128
140
|
});
|
|
129
141
|
});
|
|
@@ -339,7 +351,8 @@ async function registerStubAccount(ctx, name, usage = WARNING_USAGE) {
|
|
|
339
351
|
}
|
|
340
352
|
|
|
341
353
|
/** The account a run ran on, wherever Dev's run row keeps it. */
|
|
342
|
-
|
|
354
|
+
// Dev writes "" for a run with no account: that is no account, not an account named "".
|
|
355
|
+
export const runProfile = (run) => run?.profile || run?.launch?.profile || run?.metadata?.launch?.profileHome || run?.metadata?.launch?.profile || null;
|
|
343
356
|
|
|
344
357
|
/** This machine's account rows, as Dev lists them (the route `machine accounts list` reads). */
|
|
345
358
|
const machineAccounts = async (ctx) => ((await ctx.dev("GET", "/api/v1/runners?kind=account")).data ?? []).filter((runner) => runner.machineId === ctx.machineId);
|
|
@@ -369,7 +382,7 @@ async function checkBounds(ctx, say) {
|
|
|
369
382
|
const lane = await needStub(ctx, "bounds");
|
|
370
383
|
say(`stub lane ${lane.key}: admitted, lane ${lane.laneId}, run ${lane.runId}, runtime pid ${lane.launched?.pid}`);
|
|
371
384
|
const admitted = await laneRecord(ctx, lane.key);
|
|
372
|
-
const account = runProfile(lane.registered.data?.run)
|
|
385
|
+
const account = runProfile(lane.registered.data?.run) || admitted?.launch?.profile || admitted?.launch?.profileHome || null;
|
|
373
386
|
say(`the admitted stub lane's account: ${account ?? "none"}`);
|
|
374
387
|
must(account === null, `the admitted stub lane carries an account (${account})`);
|
|
375
388
|
const machine = await ctx.dev("GET", `/api/v1/machines/${encode(ctx.machineId)}`);
|
package/dist/harness.js
CHANGED
|
@@ -377,6 +377,27 @@ export async function repoContext(cwd = process.cwd()) {
|
|
|
377
377
|
return { root, repo: name.replace(/\.git$/, "").split(/[/:]/).filter(Boolean).at(-1).toLowerCase() };
|
|
378
378
|
}
|
|
379
379
|
|
|
380
|
+
/**
|
|
381
|
+
* O22: when the lane backstop refuses `harness install|update` before it
|
|
382
|
+
* starts (an unacknowledged amendment, or Dev or the sign-in out of reach),
|
|
383
|
+
* the git push hooks still go in, as they do when Dev's harness fetch fails,
|
|
384
|
+
* and the refusal says so. `--check`, `--dry-run` and `--system` write no
|
|
385
|
+
* hooks, and every other command is left alone. Returns the error to throw.
|
|
386
|
+
*/
|
|
387
|
+
export async function pushHooksDespiteRefusal(argv, error, { context = repoContext, pushHooks = installPushHooks } = {}) {
|
|
388
|
+
if (!(error instanceof CliError)) return error;
|
|
389
|
+
const [command, action] = argv.filter((token) => !token.startsWith("-"));
|
|
390
|
+
if (command !== "harness" || !["install", "update"].includes(action)) return error;
|
|
391
|
+
if (argv.some((token) => ["--check", "--dry-run", "--system"].includes(token.split("=")[0]))) return error;
|
|
392
|
+
const at = argv.findIndex((token) => token === "--root" || token.startsWith("--root="));
|
|
393
|
+
let root = at === -1 ? null : (argv[at].includes("=") ? argv[at].slice("--root=".length) : argv[at + 1]);
|
|
394
|
+
if (!root) root = await context().then((ctx) => ctx.root, () => null);
|
|
395
|
+
if (!root) return error;
|
|
396
|
+
const text = pushHooksLine(await pushHooks(root).catch(() => []));
|
|
397
|
+
if (text) error.message = `${error.message}\n${text}`;
|
|
398
|
+
return error;
|
|
399
|
+
}
|
|
400
|
+
|
|
380
401
|
const flagList = (value) => (value === undefined || value === true ? [] : [value].flat().flatMap((x) => String(x).split(",")).filter(Boolean));
|
|
381
402
|
const changeLine = (c) => `${{ create: "+", remove: "-" }[c.action] ?? "~"} ${c.path}${["create", "update", "remove"].includes(c.action) ? "" : ` (${c.action})`}`;
|
|
382
403
|
|
package/dist/heavy-slot.sh
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env bash
|
|
2
|
-
# heavy-slot (
|
|
2
|
+
# heavy-slot (v30, shipped with @nodii/dev): run a memory-heavy job (typecheck, build, full or affected test suite,
|
|
3
3
|
# a gate, `git push` and its pre-push hooks, an image build, a detached stack start) only when a machine-wide slot
|
|
4
4
|
# is free AND the machine clears its floor. Every session and lane on this machine shares one queue (MW2-51, K02-4).
|
|
5
5
|
#
|
|
@@ -19,9 +19,13 @@
|
|
|
19
19
|
# figure that would loosen the floor exits 2). Every decision is logged and `heavy status` lists the last hour.
|
|
20
20
|
# Nesting is proven by the process tree: a heavy-slot under a slot's holder runs in that slot.
|
|
21
21
|
#
|
|
22
|
-
# v27 (13 Nov, hub-401),
|
|
23
|
-
#
|
|
24
|
-
# floor and with no stagger.
|
|
22
|
+
# v27 (13 Nov, hub-401), v30 (MW2-51): slots are sized to the job. End-to-end, real-stack and browser-flow work is
|
|
23
|
+
# heavy. A typecheck, a lint, a unit-test run naming at most 20 test files and a push take a light slot: many run in
|
|
24
|
+
# parallel, under the light floor and with no stagger. Anything else counts heavy, and so does a command declared
|
|
25
|
+
# light that is none of those. Light slots are lock dirs under $D/light/<n> with their own queue $D/lq.
|
|
26
|
+
#
|
|
27
|
+
# v30: the admission log records the read that admitted the job (taken under the admit lock, without the job's own
|
|
28
|
+
# slot), once; a refusal is logged once by whichever read refused it.
|
|
25
29
|
#
|
|
26
30
|
# [TOOL GAP hub-86] MW5-19 places this helper as the `heavy-slot` util (MW5-26: the first util to publish).
|
|
27
31
|
# Until the util pipeline (`nodii-dev util run`, ~/.nodii/utils) exists, @nodii/dev ships it and its hooks enforce it
|
|
@@ -165,7 +169,7 @@ if [ "${1:-}" = "--status" ]; then
|
|
|
165
169
|
[ -d "$D" ] || mkdir -p "$D" 2>/dev/null
|
|
166
170
|
load_limits
|
|
167
171
|
local now held lheld q t tp o qd; now=$(date +%s); held=$(held_count "$D"); lheld=$(held_count "$D/light")
|
|
168
|
-
echo "heavy-slot
|
|
172
|
+
echo "heavy-slot v30 · slots in $D"
|
|
169
173
|
floor_js status 2>/dev/null || echo "floor unreadable (no node, or no $FLOOR_JS): every job is refused"
|
|
170
174
|
echo "slots ${held}/${SLOTS} held (landing reserve ${RESERVE}: other jobs use at most $(( SLOTS - RESERVE < 1 ? 1 : SLOTS - RESERVE ))) · light slots ${lheld}/${LSLOTS} held · reclaim after ${RECLAIM_MIN} min"
|
|
171
175
|
local lane why age
|
|
@@ -278,21 +282,116 @@ is_push() {
|
|
|
278
282
|
esac
|
|
279
283
|
done; return 1; }
|
|
280
284
|
is_push "$@" && IS_LANDING=1
|
|
281
|
-
#
|
|
282
|
-
#
|
|
283
|
-
#
|
|
284
|
-
#
|
|
285
|
-
# no stagger.
|
|
285
|
+
# v30 (MW2-51, DEV-PROCESS-2): a job's size. Heavy is end-to-end work: Playwright, Cypress and other browser drivers,
|
|
286
|
+
# an e2e, integration, real-stack or stack script, an image build and a detached stack start (the operator, 23 Nov
|
|
287
|
+
# about 20:05 IST: "NOTHING but E2E tests should require a heavy slot"). Light is a positive list: a typecheck, a lint,
|
|
288
|
+
# a unit-test run naming at most 20 test files, and a `git push`; it takes a light slot, under the light floor (5 GB)
|
|
289
|
+
# and with no stagger. Anything else counts heavy (`sleep`, `true`, a whole suite, an install, `tofu validate`), and a
|
|
290
|
+
# command declared light (`--size light`, HEAVY_SIZE=light) that is none of those counts heavy and says so.
|
|
291
|
+
# `--size heavy` (or HEAVY_SIZE=heavy) makes any job heavy; `--size light` never makes other work light.
|
|
286
292
|
e2e_job() {
|
|
287
293
|
printf ' %s ' "$*" | grep -Eiq '[^a-z0-9](playwright|cypress|puppeteer|selenium|webdriver|e2e|browser-flow|real-stack|integration)([^a-z0-9]|$)|test:stack|stack:up|stack-up|:real([^a-z0-9]|$)|docker( buildx)? build|docker( |-)compose[^|;&]* (up|build)( |$)'
|
|
288
294
|
}
|
|
295
|
+
# The one command a job runs, as words on stdout: `sh -c`/`bash -c` (or -lc) stripped, `2>&1`-style redirects and a
|
|
296
|
+
# trailing pipe to tail, head, grep or tee dropped. Fails for a compound command (&&, ||, ;, another pipe, &, a
|
|
297
|
+
# substitution, a redirect to or from a file, a second line): its parts are not one light job.
|
|
298
|
+
one_command() {
|
|
299
|
+
local s="$*" nl='
|
|
300
|
+
'
|
|
301
|
+
case "$s" in "/bin/sh -c "*|"sh -c "*|"/bin/bash -c "*|"bash -c "*) s="${s#* -c }";;
|
|
302
|
+
"/bin/sh -lc "*|"sh -lc "*|"/bin/bash -lc "*|"bash -lc "*) s="${s#* -lc }";; esac
|
|
303
|
+
s=$(printf '%s' "$s" | sed -E 's/[0-9]?>&[0-9]//g; s/[|][[:space:]]*(tail|head|grep|tee)([[:space:]][^|;&]*)?$//')
|
|
304
|
+
case "$s" in *"&&"*|*"||"*|*";"*|*"|"*|*"&"*|*'$('*|*'`'*|*"<"*|*">"*|*"$nl"*) return 1;; esac
|
|
305
|
+
printf '%s\n' "$s"
|
|
306
|
+
}
|
|
307
|
+
# v27 (hub-401), v30: a unit-test run naming 1..20 test files (`bun test a.test.ts`, `vitest run x.spec.ts`,
|
|
308
|
+
# `node --test t/a.test.js`, `npx jest a.test.tsx`), after any `env VAR=x` or `VAR=x`. A glob names no files. The
|
|
309
|
+
# figure is MW2-51's and fixed (limits.env no longer tunes it).
|
|
310
|
+
LIGHT_MAX_TEST_FILES=20
|
|
311
|
+
light_test_run() {
|
|
312
|
+
local s w n=0 runner=0 prev="" skip=0
|
|
313
|
+
s=$(one_command "$@") || return 1
|
|
314
|
+
set -f
|
|
315
|
+
for w in $s; do
|
|
316
|
+
if [ "$runner" = 0 ]; then
|
|
317
|
+
case "$w" in
|
|
318
|
+
vitest|*/vitest|jest|*/jest|mocha|*/mocha) runner=1;;
|
|
319
|
+
test) case "$prev" in bun|*/bun) runner=1;; esac;;
|
|
320
|
+
--test) case "$prev" in node|*/node) runner=1;; esac;;
|
|
321
|
+
esac
|
|
322
|
+
prev="$w"; continue
|
|
323
|
+
fi
|
|
324
|
+
# After the runner every word is a flag (with the value of one that takes the next word: `--import ./setup.mjs`,
|
|
325
|
+
# `--timeout 120000`), a subcommand or a named test file. Anything else (a directory, an unknown flag's separate
|
|
326
|
+
# value) may select more than the named files, so the run is not light (f-3b644bb0).
|
|
327
|
+
if [ "$skip" = 1 ]; then skip=0; continue; fi
|
|
328
|
+
case "$w" in
|
|
329
|
+
*'*'*|*'?'*|*'['*) set +f; return 1;;
|
|
330
|
+
--import|--require|-r|--loader|--experimental-loader|--env-file|--preload|--reporter|--test-reporter|\
|
|
331
|
+
--test-reporter-destination|--timeout|--test-timeout|--test-name-pattern|--testNamePattern|-t|--config|-c|\
|
|
332
|
+
--project|--grep|-g|--rerun-each|--seed) skip=1;;
|
|
333
|
+
-*) ;;
|
|
334
|
+
run|related) ;;
|
|
335
|
+
*.test.[cm][jt]s|*.test.[jt]s|*.test.[jt]sx|*.spec.[cm][jt]s|*.spec.[jt]s|*.spec.[jt]sx) n=$((n + 1));;
|
|
336
|
+
*) set +f; return 1;;
|
|
337
|
+
esac
|
|
338
|
+
done
|
|
339
|
+
set +f
|
|
340
|
+
[ "$runner" = 1 ] && [ "$n" -ge 1 ] && [ "$n" -le "$LIGHT_MAX_TEST_FILES" ]
|
|
341
|
+
}
|
|
342
|
+
# v30: a typecheck or a lint on the diff's files only (MW2-51: "Typecheck and lint run on the diff's files only"). One
|
|
343
|
+
# command that either runs a type checker or linter (tsc, tsgo, vue-tsc, eslint, biome, oxlint; also `npx tsc`,
|
|
344
|
+
# `pnpm exec eslint` or a path to one) naming the source files it checks (`pnpm exec tsc --noEmit a.ts`, `eslint
|
|
345
|
+
# src/a.ts`; no glob), or runs a package manager's typecheck, lint or tsc script scoped to the change by its name
|
|
346
|
+
# (`pnpm run lint:affected`, `typecheck:changed`, `:touched`, `:diff`, `:staged`). A whole-repository typecheck or
|
|
347
|
+
# lint (`pnpm typecheck`, `pnpm -r typecheck`, `tsc --noEmit`, `npx tsc -p .`, `eslint .`) is not light: it counts heavy.
|
|
348
|
+
check_job() {
|
|
349
|
+
local s w pm=0 checker=0 files=0 skip=0
|
|
350
|
+
s=$(one_command "$@") || return 1
|
|
351
|
+
set -f
|
|
352
|
+
for w in $s; do
|
|
353
|
+
if [ "$checker" = 0 ]; then
|
|
354
|
+
case "$w" in
|
|
355
|
+
*'*'*|*'?'*|*'['*) set +f; return 1;;
|
|
356
|
+
tsc|*/tsc|tsgo|*/tsgo|vue-tsc|*/vue-tsc|eslint|*/eslint|biome|*/biome|oxlint|*/oxlint) checker=1;;
|
|
357
|
+
pnpm|*/pnpm|npm|*/npm|yarn|*/yarn|bun|*/bun) pm=1;;
|
|
358
|
+
typecheck:affected|typecheck:changed|typecheck:touched|typecheck:diff|typecheck:staged|\
|
|
359
|
+
lint:affected|lint:changed|lint:touched|lint:diff|lint:staged|tsc:affected|tsc:changed|tsc:touched|tsc:diff|tsc:staged)
|
|
360
|
+
[ "$pm" = 1 ] && { set +f; return 0; };;
|
|
361
|
+
esac
|
|
362
|
+
continue
|
|
363
|
+
fi
|
|
364
|
+
# After the checker every word is a flag, a config or project flag's value, a subcommand or a named source file.
|
|
365
|
+
# Anything else (a directory such as `src/` or `.`, a flag's separate value) may check more than the diff's files,
|
|
366
|
+
# so the job is not light (review f-3b644bb0). A config flag's value is not a checked file either.
|
|
367
|
+
if [ "$skip" = 1 ]; then skip=0; continue; fi
|
|
368
|
+
case "$w" in
|
|
369
|
+
*'*'*|*'?'*|*'['*) set +f; return 1;;
|
|
370
|
+
-c|--config|-p|--project|--tsconfig|--config-path|--resolve-plugins-relative-to|--ignore-path) skip=1;;
|
|
371
|
+
-*) ;;
|
|
372
|
+
check|lint|format|ci) ;;
|
|
373
|
+
*.ts|*.tsx|*.mts|*.cts|*.js|*.jsx|*.mjs|*.cjs|*.vue|*.svelte) files=$((files + 1));;
|
|
374
|
+
*) set +f; return 1;;
|
|
375
|
+
esac
|
|
376
|
+
done
|
|
377
|
+
set +f
|
|
378
|
+
[ "$checker" = 1 ] && [ "$files" -ge 1 ]
|
|
379
|
+
}
|
|
380
|
+
# Light under MW2-51: a push (also as `sh -c 'git push'`), a unit-test run naming at most 20 files, a typecheck, a lint.
|
|
381
|
+
light_job() { local s
|
|
382
|
+
is_push "$@" && return 0
|
|
383
|
+
if s=$(one_command "$@"); then set -f; if is_push $s; then set +f; return 0; fi; set +f; fi
|
|
384
|
+
light_test_run "$@" || check_job "$@"; }
|
|
289
385
|
load_limits
|
|
290
386
|
if [ "$SIZE" = heavy ]; then :
|
|
291
387
|
elif e2e_job "$@"; then
|
|
292
388
|
[ "$SIZE" = light ] && echo "[heavy-slot] --size light does not apply to end-to-end, real-stack or browser work; this job takes a heavy slot: $*" >&2
|
|
293
389
|
SIZE=heavy
|
|
294
390
|
elif [ "$LSLOTS" -eq 0 ]; then SIZE=heavy
|
|
295
|
-
|
|
391
|
+
elif light_job "$@"; then SIZE=light
|
|
392
|
+
else
|
|
393
|
+
[ "$SIZE" = light ] && echo "[heavy-slot] declared light, but this is none of a typecheck, a lint, a unit test naming at most ${LIGHT_MAX_TEST_FILES} files or a push, so it counts heavy (MW2-51): $*" >&2
|
|
394
|
+
SIZE=heavy
|
|
296
395
|
fi
|
|
297
396
|
if [ "$SIZE" = light ]; then SD="$D/light"; mkdir -p "$SD" 2>/dev/null; fi
|
|
298
397
|
# v29 (DEV-PROCESS-2): every job reads the floor before it queues, and again when a slot is free. Under the floor it is
|
|
@@ -371,7 +470,9 @@ while :; do
|
|
|
371
470
|
# v29 (DEV-PROCESS-2): the floor is read again here, with every running job's expected peak held back (less
|
|
372
471
|
# what it already uses). Under it the job is refused, not queued: v24's lone-job and landing exceptions are gone.
|
|
373
472
|
if [ "$others" -lt "$LIMIT" ] && { [ "$others" -eq 0 ] || [ "$g" -ge "$STAGGER" ]; }; then
|
|
374
|
-
|
|
473
|
+
# v30: this read is the one that admits the job, so it is the one logged (--admit), once, admission or
|
|
474
|
+
# refusal, without the job's own slot (--self) and before the job starts.
|
|
475
|
+
frc=0; floor_gate --self "$l" --admit || frc=$?
|
|
375
476
|
if [ "$frc" -ne 0 ]; then rmdir "$D/.admit"; rm -rf "$l"; return "$frc"; fi
|
|
376
477
|
date +%s > "$SD/last-admit"; rmdir "$D/.admit"; slot="$l"; [ -n "$TICKET" ] && rm -f "$TICKET"; TICKET=""; break 2
|
|
377
478
|
fi
|
|
@@ -391,8 +492,8 @@ done
|
|
|
391
492
|
[ -n "$slot" ] && [ -d "$slot" ] || { echo "[heavy-slot] internal error: no slot acquired; refusing to run: $*" >&2; exit 70; }
|
|
392
493
|
LBL=""; [ "$SIZE" = light ] && LBL=" light"
|
|
393
494
|
echo "[heavy-slot] got $(basename "$slot")/${SLOTS}${LBL} after ${waited}s: $*" >&2
|
|
394
|
-
#
|
|
395
|
-
|
|
495
|
+
# v30: the admission was logged by the admitting read above. v28's background `record` here read the machine after the
|
|
496
|
+
# job had started and counted the job's own slot against it, so good admissions showed as under the floor.
|
|
396
497
|
# v26: who holds the slot, for the orphan reclaim, and the marker the job's own heavy work runs under.
|
|
397
498
|
date +%s > "$slot/since"
|
|
398
499
|
lane_key > "$slot/lane"
|
package/dist/heavy.js
CHANGED
|
@@ -291,13 +291,21 @@ function slotJob(words) {
|
|
|
291
291
|
return words.slice(i);
|
|
292
292
|
}
|
|
293
293
|
|
|
294
|
-
/**
|
|
294
|
+
/**
|
|
295
|
+
* The command a script would run when it is handed one, else null: a heavy-slot.sh copy under any name
|
|
296
|
+
* (`bash x/heavy-slot.sh CMD`, `bash o2-heavy-slot-copy.sh CMD`, `./q.sh CMD`) or any other script run by a shell
|
|
297
|
+
* or by its `.sh` path. Only the installed queue queues (DEV-PROCESS-2), and the text cannot tell a renamed copy
|
|
298
|
+
* from a wrapper, so the command after the script is judged as if run bare.
|
|
299
|
+
*/
|
|
295
300
|
function slotCopyJob(argv) {
|
|
296
301
|
const name = plainName(argv[0]);
|
|
297
|
-
if (
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
302
|
+
if (["bash", "sh", "zsh"].includes(name)) {
|
|
303
|
+
// `bash -c STRING` runs a string, judged command by command elsewhere; this is `bash [options] SCRIPT ARGS`.
|
|
304
|
+
if (argv.some((word, i) => i > 0 && /^-[a-z]*c[a-z]*$/.test(word))) return null;
|
|
305
|
+
const at = argv.findIndex((word, i) => i > 0 && !word.startsWith("-"));
|
|
306
|
+
return at !== -1 ? argv.slice(at + 1) : null;
|
|
307
|
+
}
|
|
308
|
+
return /heavy[-_]?slot/i.test(name) || /\.(?:ba|z)?sh$/.test(name) ? argv.slice(1) : null;
|
|
301
309
|
}
|
|
302
310
|
|
|
303
311
|
// Node's options that take the next word as their value, so the script is found after them.
|
package/dist/machine-floor.js
CHANGED
|
@@ -33,7 +33,7 @@ export const SLOT_DIR = "/tmp/nodii-heavy-slots";
|
|
|
33
33
|
* The shipped defaults (hub-377, 651; DEV-PROCESS-2 must-items 2-4): 10 GB available (light jobs 5), at most
|
|
34
34
|
* 24 GB swap used, 15 GB disk free; a running job holds back its class's peak (7 GB heavy, 1 GB light) less what it
|
|
35
35
|
* uses; 3 heavy slots, one of them only for landings; 8 light slots; a 10 s
|
|
36
|
-
* stagger between admissions while another job runs.
|
|
36
|
+
* stagger between admissions while another job runs. Light is a typecheck, a lint, a unit test naming at most 20 files or a push; anything else is heavy (heavy-slot.sh, MW2-51). Fixed numbers: no script tunes them.
|
|
37
37
|
*/
|
|
38
38
|
// One line, so a test's copy of this file can replace it whole.
|
|
39
39
|
export const DEFAULTS = Object.freeze({ minAvailGb: 10, lightMinAvailGb: 5, maxSwapGb: 24, minDiskGb: 15, heavyPeakGb: 7, lightPeakGb: 1, heavySlots: 3, landingReserve: 1, lightSlots: 8, staggerSec: 10 });
|
|
@@ -482,7 +482,7 @@ export async function statusLines({ home = homedir(), now = Date.now(), settings
|
|
|
482
482
|
`floor file: ${settings.why}`,
|
|
483
483
|
`memory available ${readings.availGb ?? "?"} GB, ${after} GB after ${reserved.gb} GB held back for ${reserved.jobs.length} running job(s) (floor ${f.minAvailGb} GB heavy, ${f.lightMinAvailGb} GB light)`,
|
|
484
484
|
`swap used ${readings.swapUsedGb ?? "?"} GB (ceiling ${f.maxSwapGb} GB) · disk free ${readings.diskFreeGb ?? "?"} GB (floor ${f.minDiskGb} GB)${failing.length ? ` · under the floor: ${failing.join("; ")}` : ""}`,
|
|
485
|
-
`classes: heavy floor ${f.minAvailGb} GB, peak ${settings.peaks.heavyGb} GB; light floor ${f.lightMinAvailGb} GB, peak ${settings.peaks.lightGb} GB (
|
|
485
|
+
`classes: heavy floor ${f.minAvailGb} GB, peak ${settings.peaks.heavyGb} GB; light floor ${f.lightMinAvailGb} GB, peak ${settings.peaks.lightGb} GB (MW2-51: light is a typecheck, a lint, a unit test naming at most 20 files or a push; end-to-end work and anything else is heavy)`,
|
|
486
486
|
`ceilings: ${c.heavySlots} heavy slots (${c.landingReserve} only for landings), ${c.lightSlots} light slots, ${settings.staggerSec} s stagger`,
|
|
487
487
|
...(reserved.jobs.length ? reserved.jobs.map((j) => ` reserved: slot ${j.slot} ${j.size} ${j.heldGb} GB (peak ${j.peakGb} less ${j.usedGb} used)${j.what ? `: ${j.what}` : ""}`) : []),
|
|
488
488
|
...admissionsLines(givenEntries ?? (await readAdmissions({ home, now })), admissionsLog(home)),
|
|
@@ -490,8 +490,9 @@ export async function statusLines({ home = homedir(), now = Date.now(), settings
|
|
|
490
490
|
}
|
|
491
491
|
|
|
492
492
|
/**
|
|
493
|
-
* `limits` (the ceilings as shell assignments), `check` (the floor, before a job queues
|
|
494
|
-
* --self SLOT:
|
|
493
|
+
* `limits` (the ceilings as shell assignments), `check` (the floor, before a job queues: refusals are logged; and again
|
|
494
|
+
* at admission with --self SLOT --admit: the decision is logged either way), `record` (v28-v29's post-start record of
|
|
495
|
+
* an admission) and `status`.
|
|
495
496
|
*/
|
|
496
497
|
export async function scriptMain(argv, { write = (t) => process.stdout.write(t), warn = (t) => process.stderr.write(t) } = {}) {
|
|
497
498
|
const [action, ...rest] = argv;
|
|
@@ -507,12 +508,15 @@ export async function scriptMain(argv, { write = (t) => process.stdout.write(t),
|
|
|
507
508
|
if (action === "limits") { write(`${shellLimits(await floorSettings())}\n`); return 0; }
|
|
508
509
|
if (action === "status") { write(`${(await statusLines()).join("\n")}\n`); return 0; }
|
|
509
510
|
if (action === "check") {
|
|
510
|
-
|
|
511
|
+
// --admit (heavy-slot v30): the read under the admit lock, with --self, whose verdict admits the job. It is logged
|
|
512
|
+
// whatever it decides, so an admission is logged once, on the readings it was made on, without the job's own slot.
|
|
513
|
+
const verdict = await checkFloor({ ...base, log: flags.admit ? "all" : "refusals" });
|
|
511
514
|
if (!verdict.ok) { warn(`[heavy-slot] ${UNDER_FLOOR}: ${verdict.message.replace(/\n/g, "\n[heavy-slot] ")}\n`); return 75; }
|
|
512
515
|
return 0;
|
|
513
516
|
}
|
|
517
|
+
// v28's post-start record, kept for a heavy-slot.sh v28-v29 run against this file; v30 logs through `check --admit`.
|
|
514
518
|
if (action === "record") { await checkFloor({ ...base, admitted: true, log: "all" }); return 0; }
|
|
515
|
-
warn("usage: machine-floor.js limits | status | check|record --class heavy|light [--what TEXT] [--landing] [--self SLOT] [--tighten READING=GB ...]\n");
|
|
519
|
+
warn("usage: machine-floor.js limits | status | check|record --class heavy|light [--what TEXT] [--landing] [--self SLOT] [--admit] [--tighten READING=GB ...]\n");
|
|
516
520
|
return 2;
|
|
517
521
|
} catch (error) {
|
|
518
522
|
warn(`[heavy-slot] ${error?.code ?? UNDER_FLOOR}: ${error?.message ?? error}\n`);
|
package/dist/nodii-dev.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { fail, main } from "./cli.js";
|
|
3
3
|
import { callSourceFor, setCallSource } from "./core.js";
|
|
4
4
|
import { regroundCurrentLane, shouldReground } from "./freeze.js";
|
|
5
|
+
import { pushHooksDespiteRefusal } from "./harness.js";
|
|
5
6
|
import { isHookDenial } from "./hooks.js";
|
|
6
7
|
import { laneReadCache } from "./read-cache.js";
|
|
7
8
|
import { drainStdout, routeStdout } from "./stdout.js";
|
|
@@ -25,7 +26,10 @@ async function run() {
|
|
|
25
26
|
// invocation re-grounds without adding hidden requests to library callers.
|
|
26
27
|
// cli-134: through the lane read cache, at most once per 15 seconds.
|
|
27
28
|
setCallSource(callSourceFor(argv));
|
|
28
|
-
|
|
29
|
+
// O22: a refusal here still leaves harness install's push hooks in place.
|
|
30
|
+
if (shouldReground(argv)) {
|
|
31
|
+
await regroundCurrentLane({}, { cache: laneReadCache() }).catch(async (error) => { throw await pushHooksDespiteRefusal(argv, error); });
|
|
32
|
+
}
|
|
29
33
|
await main(argv);
|
|
30
34
|
}
|
|
31
35
|
|
package/dist/push-hook.sh
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env bash
|
|
2
2
|
# nodii-dev:push-hook (O22, DEV-PROCESS-13). `nodii-dev harness install|update` copies this file from
|
|
3
3
|
# nodii-dev's src/push-hook.sh; change it there.
|
|
4
|
+
# Rule basis (interim, recorded): DEV-PROCESS-13 / Objective O22 and the operator's words of 25 Nov 2026
|
|
5
|
+
# (inputs.md §34, relayed by coordinator bb): "Lanes push after every commit, so nothing lives only on this
|
|
6
|
+
# Mac". No MW clause states it yet; the planner (steward-dev-process) ruled on 26 Nov that this citation is
|
|
7
|
+
# the basis until the MW clause it is drafting is uploaded. The shape follows the planner's done-check
|
|
8
|
+
# decisions on that page: a git hook installed by harness install, rewrites, 24 h retry, hooks path and
|
|
9
|
+
# chaining, PR whenever none, secret scan before push. One push worker per branch, a short debounce, and the
|
|
10
|
+
# PR opened outside the push lock follow the reviews of #539 and #542.
|
|
4
11
|
# Installed as both post-commit and post-rewrite where `git rev-parse --git-path hooks` points.
|
|
5
12
|
#
|
|
6
13
|
# After every commit or rewrite it returns at once and, in the background:
|
|
@@ -15,7 +22,9 @@
|
|
|
15
22
|
# - a refusal by the repository's own pre-push hook is logged and not retried (push it by hand);
|
|
16
23
|
# - any other failure (origin unreachable) is retried with backoff (20 s doubling, capped at 300 s)
|
|
17
24
|
# until it lands, for up to 24 h;
|
|
18
|
-
# -
|
|
25
|
+
# - a burst of commits is debounced (2 s quiet), so it costs at most two scans and pushes;
|
|
26
|
+
# - after a push lands and the push lock is released, opens a draft PR against main when the branch has
|
|
27
|
+
# none, retried the same way under its own lock, so a failing PR create never delays a later push.
|
|
19
28
|
# The GitHub API base is GITHUB_API_URL (default https://api.github.com). Token: GH_TOKEN, GITHUB_TOKEN,
|
|
20
29
|
# else `gh auth token`; on api.github.com, PR reads use `nodii-dev github research-token` when it works.
|
|
21
30
|
# Log: <git-common-dir>/nodii-push.log. Last state per branch: <git-common-dir>/nodii-push/<branch>.state,
|
|
@@ -48,6 +57,12 @@ url=$(git config --get remote.origin.url || true)
|
|
|
48
57
|
owner_repo=$(printf '%s\n' "$url" | sed -nE 's#^(https://([^@/]+@)?github\.com/|git@github\.com:|ssh://git@github\.com/)([^/]+/[^/]+)$#\3#p' | sed 's/\.git$//; s#/$##')
|
|
49
58
|
log() { printf '%s %s %s\n' "$(now)" "$br" "$*" >> "$LOG"; }
|
|
50
59
|
state() { mkdir -p "$STATE_DIR" 2>/dev/null && printf '%s %s\n' "$(now)" "$*" > "$STATE_FILE"; }
|
|
60
|
+
# The PR number goes on the state only while it still says "pushed": the PR step runs outside the push
|
|
61
|
+
# lock, so a later worker's "ahead of remote" or "push blocked" must not be overwritten.
|
|
62
|
+
pr_state() {
|
|
63
|
+
local cur; cur=$(cut -d' ' -f2- "$STATE_FILE" 2>/dev/null)
|
|
64
|
+
case $cur in pushed*) state "${cur%% pr #*} pr #$1" ;; esac
|
|
65
|
+
}
|
|
51
66
|
token=""
|
|
52
67
|
write_token() {
|
|
53
68
|
[ -n "$token" ] && return 0
|
|
@@ -89,7 +104,7 @@ open_pr_once() { # 0 = a PR is open for the branch now; 1 = try again
|
|
|
89
104
|
local nums code base body
|
|
90
105
|
nums=$(pr_list)
|
|
91
106
|
[ "$nums" = error ] && { log "pr-list failed"; read_token=""; return 1; }
|
|
92
|
-
[ "$nums" = none ] || { log "pr-exists #$nums";
|
|
107
|
+
[ "$nums" = none ] || { log "pr-exists #$nums"; pr_state "$nums"; return 0; }
|
|
93
108
|
write_token || { log "pr-create failed: no GitHub token (GH_TOKEN, GITHUB_TOKEN or gh auth)"; return 1; }
|
|
94
109
|
base=$(base_branch)
|
|
95
110
|
body="Opened by the nodii-dev push hook (O22): this lane's branch is pushed after every commit."
|
|
@@ -106,7 +121,7 @@ open_pr_once() { # 0 = a PR is open for the branch now; 1 = try again
|
|
|
106
121
|
# Read the result back in its own call (K03-16): the list, not the create's answer, says a PR exists.
|
|
107
122
|
if [ "$code" = 201 ]; then
|
|
108
123
|
nums=$(pr_list)
|
|
109
|
-
case $nums in none|error) log "pr-create read-back: list says $nums" ;; *) log "pr-exists #$nums (read back)";
|
|
124
|
+
case $nums in none|error) log "pr-create read-back: list says $nums" ;; *) log "pr-exists #$nums (read back)"; pr_state "$nums"; return 0 ;; esac
|
|
110
125
|
fi
|
|
111
126
|
return 1 # not created or not read back: the next list decides (a racing worker may have made it: 422)
|
|
112
127
|
}
|
|
@@ -116,7 +131,7 @@ open_pr() {
|
|
|
116
131
|
local wait=$RETRY_S start; start=$(now)
|
|
117
132
|
until open_pr_once; do
|
|
118
133
|
if [ $(( $(now) - start + wait )) -gt "$WINDOW_S" ]; then log "pr-gave-up; branch has no PR"; state "no PR: PR create kept failing"; return 1; fi
|
|
119
|
-
log "pr-retry in ${wait}s"; sleep "$wait"; wait=$((wait * 2)); [ "$wait" -gt "$RETRY_MAX_S" ] && wait=$RETRY_MAX_S
|
|
134
|
+
log "pr-retry in ${wait}s"; beat; sleep "$wait"; wait=$((wait * 2)); [ "$wait" -gt "$RETRY_MAX_S" ] && wait=$RETRY_MAX_S
|
|
120
135
|
done
|
|
121
136
|
}
|
|
122
137
|
|
|
@@ -159,7 +174,7 @@ work() {
|
|
|
159
174
|
rt=$(git ls-remote origin "refs/heads/$br" 2>/dev/null | cut -f1)
|
|
160
175
|
if [ "$rt" = "$sha" ] || { [ -n "$rt" ] && git merge-base --is-ancestor "$sha" "$rt" 2>/dev/null; }; then
|
|
161
176
|
log "pushed $sha attempt=$i (origin at $rt)"; state "pushed $sha"
|
|
162
|
-
|
|
177
|
+
PR_NEEDED=1; return 0
|
|
163
178
|
fi
|
|
164
179
|
err="push read-back: origin at ${rt:-nothing}, not $sha (connection)"
|
|
165
180
|
fi
|
|
@@ -181,9 +196,85 @@ work() {
|
|
|
181
196
|
if [ $(( $(now) - start + wait )) -gt "$WINDOW_S" ]; then log "gave-up $sha after $i attempts; ahead of remote"; state "ahead of remote: gave up after 24 h"; return 1; fi
|
|
182
197
|
log "push-failed $sha attempt=$i, retry in ${wait}s: $(errline "$err")"
|
|
183
198
|
state "ahead of remote: push failing since $start, retrying"
|
|
184
|
-
sleep "$wait"; wait=$((wait * 2)); [ "$wait" -gt "$RETRY_MAX_S" ] && wait=$RETRY_MAX_S
|
|
199
|
+
beat; sleep "$wait"; wait=$((wait * 2)); [ "$wait" -gt "$RETRY_MAX_S" ] && wait=$RETRY_MAX_S
|
|
185
200
|
done
|
|
186
201
|
}
|
|
187
202
|
|
|
188
|
-
|
|
203
|
+
# One push worker per branch, holding <branch>.lock while it scans and pushes. A commit marks the branch
|
|
204
|
+
# dirty; the worker waits until no commit has marked it for DEBOUNCE_S, pushes the tip, and pushes again
|
|
205
|
+
# only if a commit marked it meanwhile, so a burst costs at most two scans and pushes. The PR is opened
|
|
206
|
+
# AFTER the push lock is released, under its own <branch>.pr lock, so a PR create that keeps failing
|
|
207
|
+
# (no token, GitHub down) never holds up the next commit's push.
|
|
208
|
+
DEBOUNCE_S=2
|
|
209
|
+
SLUG=$(printf '%s' "$br" | tr '/' '~')
|
|
210
|
+
LOCK=$STATE_DIR/$SLUG.lock PRLOCK=$STATE_DIR/$SLUG.pr DIRTY=$STATE_DIR/$SLUG.dirty
|
|
211
|
+
PR_NEEDED=0 HELD=""
|
|
212
|
+
# The worker touches the lock it holds before every wait (the longest is RETRY_MAX_S), so a lock
|
|
213
|
+
# untouched for LOCK_STALE_MIN minutes belongs to no worker, even if its pid has been reused.
|
|
214
|
+
LOCK_STALE_MIN=8
|
|
215
|
+
beat() { [ -n "$HELD" ] && touch "$HELD" 2>/dev/null; return 0; }
|
|
216
|
+
# A lock directory holds its worker's pid and, where ps may run, that process's start time. It is live
|
|
217
|
+
# while it was touched within LOCK_STALE_MIN minutes AND its pid runs (kill -0; "not permitted" counts
|
|
218
|
+
# as running) AND, when both start times can be read, the process is the one that took it. Before the
|
|
219
|
+
# pid is written it is live for its first minute. ps is optional: a sandbox may refuse to run it.
|
|
220
|
+
lock_live() {
|
|
221
|
+
local pid started cur err
|
|
222
|
+
[ -z "$(find "$1" -maxdepth 0 -mmin +"$LOCK_STALE_MIN" 2>/dev/null)" ] || return 1
|
|
223
|
+
pid=$(cat "$1/pid" 2>/dev/null)
|
|
224
|
+
if [ -z "$pid" ]; then [ -z "$(find "$1" -maxdepth 0 -mmin +1 2>/dev/null)" ]; return; fi
|
|
225
|
+
if ! err=$(LC_ALL=C kill -0 "$pid" 2>&1); then
|
|
226
|
+
case $err in *"not permitted"*) ;; *) return 1 ;; esac
|
|
227
|
+
fi
|
|
228
|
+
started=$(cat "$1/started" 2>/dev/null)
|
|
229
|
+
cur=$(ps -o lstart= -p "$pid" 2>/dev/null) || cur=""
|
|
230
|
+
[ -z "$started" ] || [ -z "$cur" ] || [ "$started" = "$cur" ]
|
|
231
|
+
}
|
|
232
|
+
own() { echo "$2" > "$1/pid"; ps -o lstart= -p "$2" > "$1/started" 2>/dev/null; }
|
|
233
|
+
take_lock() {
|
|
234
|
+
local l=$1 stale="$1.stale.$$"
|
|
235
|
+
mkdir "$l" 2>/dev/null && return 0
|
|
236
|
+
lock_live "$l" && return 1
|
|
237
|
+
# Take a stale lock over by renaming it away: only one hook's rename succeeds. If what it moved
|
|
238
|
+
# turns out to be live (another hook took the lock over first), it goes back.
|
|
239
|
+
mv "$l" "$stale" 2>/dev/null || return 1
|
|
240
|
+
if lock_live "$stale"; then mv "$stale" "$l" 2>/dev/null || rm -rf "$stale"; return 1; fi
|
|
241
|
+
rm -rf "$stale"
|
|
242
|
+
mkdir "$l" 2>/dev/null
|
|
243
|
+
}
|
|
244
|
+
settle() { # until DIRTY has not grown for DEBOUNCE_S, at most 30 s
|
|
245
|
+
local a b t0; t0=$(now); a=$({ wc -c < "$DIRTY"; } 2>/dev/null)
|
|
246
|
+
while :; do
|
|
247
|
+
beat; sleep "$DEBOUNCE_S"; b=$({ wc -c < "$DIRTY"; } 2>/dev/null)
|
|
248
|
+
[ "$a" = "$b" ] && return 0
|
|
249
|
+
a=$b; [ $(( $(now) - t0 )) -ge 30 ] && return 0
|
|
250
|
+
done
|
|
251
|
+
}
|
|
252
|
+
worker() {
|
|
253
|
+
local me="" n=0
|
|
254
|
+
# The hook writes this worker's pid ($!) into the lock; bash 3.2 has no $BASHPID.
|
|
255
|
+
while [ -z "$me" ] && [ "$n" -lt 50 ]; do me=$(cat "$LOCK/pid" 2>/dev/null); n=$((n + 1)); [ -n "$me" ] || sleep 0.1; done
|
|
256
|
+
HELD=$LOCK
|
|
257
|
+
while :; do
|
|
258
|
+
settle
|
|
259
|
+
rm -f "$DIRTY"
|
|
260
|
+
work
|
|
261
|
+
[ -e "$DIRTY" ] && continue
|
|
262
|
+
HELD=""; rm -rf "$LOCK"
|
|
263
|
+
# A commit that marked the branch dirty just before the release still gets pushed.
|
|
264
|
+
if [ -e "$DIRTY" ] && take_lock "$LOCK"; then [ -n "$me" ] && own "$LOCK" "$me"; HELD=$LOCK; continue; fi
|
|
265
|
+
break
|
|
266
|
+
done
|
|
267
|
+
# The PR step: one opener per branch; one that is already retrying covers this push too.
|
|
268
|
+
[ "$PR_NEEDED" = 1 ] || return 0
|
|
269
|
+
take_lock "$PRLOCK" || return 0
|
|
270
|
+
[ -n "$me" ] && own "$PRLOCK" "$me"
|
|
271
|
+
HELD=$PRLOCK
|
|
272
|
+
open_pr
|
|
273
|
+
HELD=""; rm -rf "$PRLOCK"
|
|
274
|
+
}
|
|
275
|
+
mkdir -p "$STATE_DIR" 2>/dev/null
|
|
276
|
+
echo >> "$DIRTY"
|
|
277
|
+
take_lock "$LOCK" || exit 0
|
|
278
|
+
( worker ) </dev/null >>"$LOG" 2>&1 &
|
|
279
|
+
own "$LOCK" $!
|
|
189
280
|
exit 0
|