Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

review fixes: import_rate excuses nothing when the cost recurs; ubi-runner checks timeouts only where read; tree.json guards a files-less manifest

garrytan687e44d1d41d
diff --git a/scripts/ci-full-suite-tree.sh b/scripts/ci-full-suite-tree.sh
index b87e60bf57..8ab07bcbb9 100755
--- a/scripts/ci-full-suite-tree.sh
+++ b/scripts/ci-full-suite-tree.sh
@@ -7,7 +7,9 @@
# Input (environment): ARTIFACT_DIR, RUN_ID, RUN_ATTEMPT, WORKFLOW, EVENT, and
# optionally MANIFEST, the run's ci-manifest.json (scripts/ci-manifest.ts).
# Output: $ARTIFACT_DIR/tree.json and step-summary lines.
-# `files` (every test file the run executed, repo-relative) and `tests` (its
+# `files` (every test file the run loaded, repo-relative, across lanes and
+# arms; a file whose tests all skipped counts, because the remote gate's
+# inventory lists the same env- and platform-gated files) and `tests` (its
# executed test count) come only from a complete manifest of this run, attempt
# and commit. Otherwise both are left out with a warning: the record still says
# the full suite passed, but gstack cannot take it as run evidence.
@@ -29,8 +31,11 @@ else
elif .complete != true then "ci-manifest.json is incomplete: \(.problems | join("; "))"
else "" end' "$MANIFEST" 2>&1) || problem="ci-manifest.json is unreadable: $problem"
if [ -z "$problem" ]; then
- jq -c '{files: ([.files[].file | select(test("\\.test\\.[cm]?[jt]sx?$"))] | unique), tests: ([.files[].executed] | add // 0)}' "$MANIFEST" > "$evidence"
- [ "$(jq '.files | length' "$evidence")" -gt 0 ] || { problem="ci-manifest.json lists no test file"; echo '{}' > "$evidence"; }
+ if ! jq -c '{files: ([.files[].file | select(test("\\.test\\.[cm]?[jt]sx?$"))] | unique), tests: ([.files[].executed] | add // 0)}' "$MANIFEST" > "$evidence" 2>/dev/null; then
+ problem="ci-manifest.json has no readable files list"; echo '{}' > "$evidence"
+ elif [ "$(jq '.files | length' "$evidence")" -eq 0 ]; then
+ problem="ci-manifest.json lists no test file"; echo '{}' > "$evidence"
+ fi
fi
fi
jq -n --arg tree "$tree" --arg sha "$sha" --arg workflow "$WORKFLOW" --arg event "$EVENT" \
diff --git a/scripts/scale/README.md b/scripts/scale/README.md
index cdb4e5f4e9..041cf8c736 100644
--- a/scripts/scale/README.md
+++ b/scripts/scale/README.md
@@ -48,10 +48,13 @@ paused database container or a WAL checkpoint lands in one page's time and
once failed unrelated pull requests on its own. Each tenth is cut into ten
slices; the slice with the largest excess over its tenth's median slice is
lowered to the next-largest excess anywhere in the import, and its tenth
-never drops below the Theil-Sen line through the ten tenth means. Work that
-recurs (a rebuild every few hundred pages, or once per tenth) is kept at the
-plain measure's sensitivity; only the margin of its largest occurrence over
-the next one can be set aside. The gate message names the stall and the
+never drops below the Theil-Sen line through the ten tenth means. When the
+next-largest excess is over a quarter of the largest, the cost showed up
+twice and nothing is set aside, so work that recurs (a rebuild every few
+hundred pages, once per tenth, or twice in the import) is kept at the plain
+measure's sensitivity. A cost that lands only once (a rebuild every 5,000
+pages or more on a 10k import) looks like a stall; the 20k nightly tier sees
+it twice. The gate message names the stall and the
report's `import.<basis>.excused` records it. The report and its JSON
`import` section carry both bases for every engine: wall time (`elapsed_ms`) and the import process's main-thread CPU time
(`cpu_ms`, user + system, from each progress tick; in-process timing under
diff --git a/scripts/scale/gates.ts b/scripts/scale/gates.ts
index 85767a8061..55718f70c8 100644
--- a/scripts/scale/gates.ts
+++ b/scripts/scale/gates.ts
@@ -77,8 +77,9 @@ export function importProgressPerFile(stderr: string): { wallMs: number[]; cpuMs
* and only the part of it no other part of the import repeats:
*
* - Each tenth of the import is cut into ten slices. A slice's excess is its mean per-page cost above the median
- * slice of its tenth. The slice with the largest excess is lowered to the second-largest excess anywhere in the
- * import, so a cost that shows up twice (two rebuilds, two stalls) is set aside only by the margin between them.
+ * slice of its tenth. When the second-largest excess anywhere in the import is over a quarter of the largest, the
+ * cost showed up twice (two rebuilds, the second one larger because the brain grew) and nothing is set aside.
+ * Otherwise the slice with the largest excess is lowered to the second-largest.
* - The lowered tenth never drops below the Theil-Sen line through the ten tenth means, so a cost that lands once in
* every tenth and grows with the brain is kept in full: those tenth means rise on that line.
*
@@ -105,6 +106,7 @@ export function excusedStall(perPageMs: number[]): ExcusedStall | undefined {
return parts.map(s => ({ ...s, d, excess: s.mean - typical }));
}).sort((a, b) => b.excess - a.excess);
const [worst, next] = [slices[0]!, slices[1]!];
+ if (next.excess > worst.excess / 4) return undefined;
const means = tenths.map(t => t.mean);
const slopes = means.flatMap((a, i) => means.slice(i + 1).map((b, k) => (b - a) / (k + 1)));
const slope = median(slopes);
diff --git a/scripts/ubicloud/ubi-runner.sh b/scripts/ubicloud/ubi-runner.sh
index c2208b8a43..b23740bfd1 100755
--- a/scripts/ubicloud/ubi-runner.sh
+++ b/scripts/ubicloud/ubi-runner.sh
@@ -155,15 +155,12 @@ for v in IDLE_TIMEOUT RUN_TIMEOUT HEARTBEAT QUOTA_WAIT; do
[[ "${!v}" =~ ^[0-9]+$ ]] || die "UBI_$v must be a whole number of seconds (0 disables it)"
done
[ -z "$QUOTA_VCPUS" ] || [[ "$QUOTA_VCPUS" =~ ^[0-9]+$ ]] || die "UBI_QUOTA_VCPUS must be a whole number of vCPUs"
-for v in DOWN_TIMEOUT REAP_DOWN_TIMEOUT; do
- [[ "${!v}" =~ ^[1-9][0-9]*$ ]] || die "UBI_$v must be a whole number of seconds from 1"
-done
-# gbrain: UBI_REAP=false (or no/off) must not turn reaping on.
-case $(printf %s "$REAP" | tr '[:upper:]' '[:lower:]') in
- 0|false|no|off) REAP=0 ;;
- 1|true|yes|on) REAP=1 ;;
- *) die "UBI_REAP must be 1 or 0 (true/false, yes/no and on/off also work), not '$REAP'" ;;
-esac
+# check_seconds VAR: UBI_DOWN_TIMEOUT and UBI_REAP_DOWN_TIMEOUT are checked only
+# by the commands that read them (up and down, reap), so a stale value never
+# blocks list, usage or a teardown that does not read it.
+check_seconds() {
+ [[ "${!1}" =~ ^[1-9][0-9]*$ ]] || die "UBI_$1 must be a whole number of seconds from 1"
+}
owner_id() {
local raw=${UBI_OWNER:-} file="$STATE_ROOT/owner-id" tmp
@@ -393,6 +390,7 @@ mine_rows() {
# outside the prefix are never touched: only a TTL lets reap judge another lane's VM.
cmd_reap() {
local now rows loc name owner expires created n=0 failed=0
+ check_seconds REAP_DOWN_TIMEOUT
# cmd_down reads DOWN_TIMEOUT; a reap waits at most REAP_DOWN_TIMEOUT per VM.
local DOWN_TIMEOUT=$REAP_DOWN_TIMEOUT
[[ "$LEGACY_HOURS" =~ ^[1-9][0-9]{0,3}$ ]] || die "UBI_LEGACY_HOURS must be a whole number of hours from 1 to 9999 with no leading zero (how old a TTL-less ubirun-* VM must be before reap destroys it)"
@@ -572,6 +570,13 @@ UP_NAME=""
UP_READY=""
cmd_up() {
require_owner
+ check_seconds DOWN_TIMEOUT
+ # gbrain: UBI_REAP=false (or no/off) must not turn reaping on; only up reads it.
+ case $(printf %s "$REAP" | tr '[:upper:]' '[:lower:]') in
+ 0|false|no|off) REAP=0 ;;
+ 1|true|yes|on) REAP=1 ;;
+ *) die "UBI_REAP must be 1 or 0 (true/false, yes/no and on/off also work), not '$REAP'" ;;
+ esac
local size=$DEFAULT_SIZE location=$DEFAULT_LOCATION name="" storage="" image=ubuntu-noble ttl=""
while [ $# -gt 0 ]; do
case $1 in
@@ -1115,7 +1120,7 @@ case $cmd in
pack) cmd_pack "$@" ;;
unpack) cmd_unpack "$@" ;;
pull) cmd_pull "$@" ;;
- down) cmd_down "$@" ;;
+ down) check_seconds DOWN_TIMEOUT; cmd_down "$@" ;;
list) cmd_list "$@" ;;
usage) cmd_usage ;;
owner) echo "$OWNER" ;;
diff --git a/test/scripts/full-ci-workflow.test.ts b/test/scripts/full-ci-workflow.test.ts
index 524bfe37ed..d8ea751816 100644
--- a/test/scripts/full-ci-workflow.test.ts
+++ b/test/scripts/full-ci-workflow.test.ts
@@ -144,6 +144,7 @@ describe('full CI on pull requests', () => {
[manifest({ complete: false, problems: ['unit shard 3 has no receipt'] }), 'is incomplete: unit shard 3 has no receipt'],
[manifest({ schema: 'other/v0' }), 'has schema other/v0'],
[manifest({ files: [{ file: 'verify', lane: 'verify', arm: '', executed: 1, failed: 0, skipped: 0 }] }), 'lists no test file'],
+ [manifest({ files: null }), 'has no readable files list'],
] as const) {
const { tree, stdout } = record(doc);
expect(tree).toEqual(base);
diff --git a/test/scripts/scale-gates.test.ts b/test/scripts/scale-gates.test.ts
index 1f262578e2..32d4624602 100644
--- a/test/scripts/scale-gates.test.ts
+++ b/test/scripts/scale-gates.test.ts
@@ -209,6 +209,8 @@ describe('scale gates under --enforce', () => {
['a rebuild once per tenth (every 1,000 pages), one slice per tenth', 'fail', 'fail', rebuild(1000, 0.5)],
['the same rebuild half a tenth later', 'fail', 'fail', rebuild(1000, 0.5, 500)],
['two 12 s stalls in the last tenth', 'fail', 'fail', i => stall(9300, 12_000)(i) + stall(9700, 12_000)(i)],
+ ['a rebuild every 4,000 pages (twice) costing 10 ms x pages so far', 'fail', 'fail', rebuild(4000, 10)],
+ ['a rebuild every 2,000 pages costing 3 ms x pages so far', 'fail', 'fail', rebuild(2000, 3)],
['every page of the last tenth 60% slower', 'fail', 'fail', i => (i >= 9000 ? 3 : 0)],
];
test.each(CASES)('%s: before #7939 %s, now %s', (_name, before, now, extra) => {
@@ -236,6 +238,10 @@ describe('scale gates under --enforce', () => {
['a plain O(n) per-page cost', k => linear(k)],
['a rebuild once per tenth', k => rebuild(1000, k)],
['a rebuild once per tenth, half a tenth later', k => rebuild(1000, k, 500)],
+ ['a rebuild every 1,750 pages', k => rebuild(1750, k)],
+ ['a rebuild every 2,000 pages', k => rebuild(2000, k)],
+ ['a rebuild every 3,000 pages', k => rebuild(3000, k)],
+ ['a rebuild every 4,000 pages (twice)', k => rebuild(4000, k)],
];
test.each(RECURRING)('%s fails at the same size as under the plain measure', (_name, family) => {
const ratio = failsAt(rateMeasure, family) / failsAt(plainMeasure, family);
@@ -252,8 +258,16 @@ describe('scale gates under --enforce', () => {
});
test('at most one slice is set aside, and only by its margin over the next-largest excess', () => {
- const ms = series(i => stall(9300, 12_000)(i) + stall(2500, 5_000)(i), false);
- expect(rateMeasure(ms).excused).toEqual({ ms: 7_000, first_page: 9301, last_page: 9400 });
+ const ms = series(i => stall(9300, 12_000)(i) + stall(2500, 2_000)(i), false);
+ expect(rateMeasure(ms).excused).toEqual({ ms: 10_000, first_page: 9301, last_page: 9400 });
+ });
+
+ test('a second excess over a quarter of the largest is a recurrence: nothing is set aside', () => {
+ for (const extra of [(i: number) => stall(9300, 12_000)(i) + stall(2500, 5_000)(i), rebuild(4000, 10)]) {
+ const ms = series(extra, false);
+ expect(rateMeasure(ms).excused).toBeUndefined();
+ expect(rateMeasure(ms)).toMatchObject(plainMeasure(ms));
+ }
});
test('the gate message names the stall it set aside', () => {
diff --git a/test/scripts/ubi-runner-run.test.ts b/test/scripts/ubi-runner-run.test.ts
index 2934813a95..80aa9968b5 100644
--- a/test/scripts/ubi-runner-run.test.ts
+++ b/test/scripts/ubi-runner-run.test.ts
@@ -257,6 +257,23 @@ describe("down retries a failed destroy request", () => {
expect(api.vms.has("vm-a")).toBe(true);
}, 60_000);
+ it("UBI_REAP, UBI_DOWN_TIMEOUT and UBI_REAP_DOWN_TIMEOUT are checked only by the commands that read them", async () => {
+ const api = serve({ seed: [{ name: "vm-a" }] });
+ const stale = { UBI_REAP: "maybe", UBI_DOWN_TIMEOUT: "0", UBI_REAP_DOWN_TIMEOUT: "x" };
+ for (const args of [["list", "--mine"], ["usage"]]) expect((await run(args, stale)).code).toBe(0);
+ const badDown = await run(["down", "vm-a"], { UBI_DOWN_TIMEOUT: "0" });
+ expect(badDown.code).toBe(1);
+ expect(badDown.stderr).toContain("UBI_DOWN_TIMEOUT must be a whole number of seconds from 1");
+ expect(api.vms.has("vm-a")).toBe(true);
+ const down = await run(["down", "vm-a"], { UBI_REAP: "maybe", UBI_REAP_DOWN_TIMEOUT: "x", UBI_DOWN_TIMEOUT: "60" });
+ expect(down.code).toBe(0);
+ expect(api.vms.has("vm-a")).toBe(false);
+ const up = await run(["up"], { UBI_DOWN_TIMEOUT: "0" });
+ expect(up.code).toBe(1);
+ expect(up.stderr).toContain("UBI_DOWN_TIMEOUT must be a whole number of seconds from 1");
+ expect(creates()).toEqual([]);
+ }, 60_000);
+
it("reap waits at most UBI_REAP_DOWN_TIMEOUT per VM, not UBI_DOWN_TIMEOUT", async () => {
const api = serve({ seed: [{ name: "ubirun-other-1000000000-bbbb-t1" }, { name: "ubirun-peer-1000000000-cccc-t1" }] });
api.faults.destroy = true;