|
| 1 | +# Resource-aware lint execution |
| 2 | + |
| 3 | +The `ag-lint` executable and `@agcodeguidelines/oxlint-config/runner` subpath |
| 4 | +provide execution control without changing `createConfig()`, the configuration |
| 5 | +generator CLI, presets or rule ownership. Syntax-only execution needs neither |
| 6 | +an ESLint engine dependency nor the optional typed service. |
| 7 | + |
| 8 | +## Invocation |
| 9 | + |
| 10 | +```sh |
| 11 | +pnpm run lint -- --max-mem 8192 |
| 12 | +pnpm run lint -- --max-mem=2048 --threads=1 --profile .cache/lint-profile.json |
| 13 | +pnpm exec ag-lint --max-mem 8192 --command node tasks/lint.mjs |
| 14 | +``` |
| 15 | + |
| 16 | +`--max-mem` accepts a positive integer in **MiB**. Missing, duplicate, fractional, |
| 17 | +negative, unsafe or unit-suffixed values are rejected. The wrapper consumes its |
| 18 | +own flags, including pnpm's forwarding separator; they are not sent to Oxlint, |
| 19 | +ESLint, Lerna or the compiler. A later literal `--` preserves option-looking |
| 20 | +filenames. The default backend is the installed supported Oxlint Node CLI; |
| 21 | +there is no hardcoded private Rust binary path. |
| 22 | + |
| 23 | +Full root lint still uses the existing config and zero-warning contract. |
| 24 | +`lint:fix` is unchanged; parallel autofix is not introduced. |
| 25 | + |
| 26 | +## Budget policy |
| 27 | + |
| 28 | +At startup the wrapper computes effective observable availability from guest |
| 29 | +`MemAvailable`, meaningful platform/Node hints, and visible cgroup ancestor |
| 30 | +limits and their own current usage. It handles cgroup v1/v2 and namespace mount |
| 31 | +mapping, unlimited sentinels and soft `memory.high` pressure. Swap is not extra |
| 32 | +RAM budget. CPU admission also considers the visible quota and affinity count. |
| 33 | + |
| 34 | +The automatic budget is the floor of **80% of effective available bytes**, in |
| 35 | +whole MiB. This is capacity for useful work, not a request to preallocate memory |
| 36 | +until the machine is 80% occupied. Explicit `--max-mem` replaces the automatic |
| 37 | +fraction and can be larger or smaller, but cannot exceed an observable hard |
| 38 | +ceiling. It does not reserve physical memory from other applications; current |
| 39 | +pressure can still prevent admission or terminate the run with a resource error. |
| 40 | + |
| 41 | +The budget belongs to the **whole supervised command**, including its engines, |
| 42 | +workers, orchestration and caches. It is not assigned independently to each |
| 43 | +package or Node worker. Root commands create a temporary authenticated local |
| 44 | +coordinator. Participating package wrappers share reservations; nested work |
| 45 | +reuses its current package permit. Child options cannot raise the parent cap. |
| 46 | +Session sockets and permits are reclaimed at command completion/disconnection. |
| 47 | +Credentials are not included in profile JSON. |
| 48 | + |
| 49 | +Thread reservations are conservative startup estimates, not per-thread hard |
| 50 | +limits. One useful small native task can run with a smaller reservation under |
| 51 | +active monitoring. A very large JS-provider profile may need more memory even |
| 52 | +with one thread; insufficient limits must fail rather than silently omit checks. |
| 53 | + |
| 54 | +Visible VM RAM and container limits are honored. A guest cannot infer hidden |
| 55 | +physical-host constraints. Trusted launchers may provide |
| 56 | +`AG_LINT_HOST_LIMIT_MIB` and `AG_LINT_HOST_AVAILABLE_MIB`; without them the report |
| 57 | +states the visibility gap rather than probing outside its namespace. |
| 58 | + |
| 59 | +## Enforcement and failures |
| 60 | + |
| 61 | +Linux reports `monitored-process-tree`: the supervisor observes descendant RSS |
| 62 | +across Linux worker threads, restricts new work and terminates owned work on |
| 63 | +budget excess. This is **best-effort monitoring, not a portable kernel-enforced |
| 64 | +hard RSS limit**. Sampling can overshoot transiently and shared pages can be |
| 65 | +counted more than once. V8 old-space is not used as a substitute for total |
| 66 | +Node/native/process-tree memory. Existing pnpm/bootstrap memory before the |
| 67 | +supervisor starts is already reflected in available-memory observations, but is |
| 68 | +not claimed as an exact owned process-tree measurement. |
| 69 | + |
| 70 | +On other platforms the report says `admission-only`; it does not pretend that |
| 71 | +parent RSS includes every child. Use an external OS/container memory scope when |
| 72 | +a strict physical bound is required. Rootless container tests use actual kernel |
| 73 | +cgroup limits in addition to the wrapper's monitored budget. |
| 74 | + |
| 75 | +The wrapper preserves engine exit statuses, including lint violations (`1`). |
| 76 | +Invocation/spawn errors use `2`, resource/admission failures use `3`, and signals |
| 77 | +retain conventional statuses such as SIGINT `130`, SIGKILL `137` and SIGTERM |
| 78 | +`143`. Queued tasks have bounded idle-pressure admission waits, not an endless |
| 79 | +queue. Legitimate active work does not cause a false queue timeout. Cancellation |
| 80 | +terminates known owned process groups/descendants with escalation; Linux PID |
| 81 | +start identities protect against killing a reused PID. This is not a sandbox |
| 82 | +for adversarial programs that deliberately escape process ownership. |
| 83 | + |
| 84 | +## Profiling |
| 85 | + |
| 86 | +`--profile path.json` records the selected budget and sources, visibility |
| 87 | +warnings, sampled peak tree memory, engine resolution/execution timings, exit |
| 88 | +status and coordinator counts. Startup before module entry is not mislabelled |
| 89 | +as measured function time. Native child time is opaque initialization plus |
| 90 | +execution; Node CPU profiles alone cannot explain all native work. |
| 91 | + |
| 92 | +The monorepo pilot separately records engine load, enumeration, effective-config |
| 93 | +calculation, grouping, fallback lint, native config I/O and spawn counts through |
| 94 | +`AG_LINT_TRACE_DIR`. Equivalent fallback overrides reuse an ESLint instance; |
| 95 | +ESLint still resolves each file's complete original config. Exact equivalent |
| 96 | +native runtime configs coalesce into argv-byte-safe batches. No arbitrary |
| 97 | +hundred-file split, dropped path, shell quoting or changed ignore policy is |
| 98 | +used to manufacture speed. Config memoization is read-only. |
| 99 | + |
| 100 | +`scripts/benchmark.ts` keeps the previous manifest compatible and also accepts |
| 101 | +two or more safely named variants. `artifactsDirectory` streams complete raw |
| 102 | +stdout/stderr into artifacts instead of retaining large diagnostic buffers. |
| 103 | +Each variant may declare `resourceProfile` to attach its completed resource |
| 104 | +report to each sample. Separate tracing-on attribution runs from tracing-off |
| 105 | +timing comparisons. Full coverage, source/dependency parity and resource limits |
| 106 | +must match before claiming a speedup; a native subset is only a control. |
| 107 | + |
| 108 | +## Verified limits and progress |
| 109 | + |
| 110 | +Focused tests cover default80%, explicit overrides, nested cgroup headroom, |
| 111 | +soft pressure, sentinels, parser forwarding, impossible work, pressure recovery, |
| 112 | +long active tasks, cancellation, coordinator loss, child budget expansion, |
| 113 | +spawn/SIGKILL failure and cleanup of a detached child ignoring SIGTERM. |
| 114 | +Packed tarball tests exercise the public bin/subpath, TS5 declarations and |
| 115 | +pnpm symlink entry detection. No blanket lint or coverage exemptions are added. |
| 116 | + |
| 117 | +Rootless Node22.12 containers with kernel limits512/1024/2048MiB complete the |
| 118 | +native fixture with automatic startup budgets around399/809/1628MiB and sampled |
| 119 | +owned peaks around55MiB. An explicit value one MiB over each hard ceiling is |
| 120 | +rejected before engine startup. These small-fixture results are not evidence |
| 121 | +that a full legacy JS-provider configuration fits512MiB or1GiB. |
| 122 | + |
| 123 | +Paired single-run consumer stress attempts at1/2/4/8GiB are separate from the |
| 124 | +repeated timing study. With the result cache disabled, VPN fails explicitly |
| 125 | +at1GiB; at2GiB the current route fails and optimized completes in this sample; |
| 126 | +both complete at4/8GiB. The monorepo fails explicitly at1/2/4GiB and completes |
| 127 | +all14 chains at8GiB. Both optimized automatic80% lanes complete. These are |
| 128 | +observations, not minimum-memory guarantees: sampled RSS and current pressure |
| 129 | +vary. Cache-enabled stress attempts are not guaranteed primed after earlier |
| 130 | +failed or cache-disabled attempts. The1GiB monorepo root now rejects before |
| 131 | +starting Lerna rather than repeating a package admission timeout. Adapters |
| 132 | +report resource errors without an unhandled stack; external orchestrators such |
| 133 | +as Lerna can still aggregate a child's resource exit into their own exit1. |
| 134 | + |
| 135 | +The final packed-runtime check executes the installed `ag-lint` bin with an |
| 136 | +explicit512MiB budget and verifies its JSON report on Node22.12.0, |
| 137 | +pnpm10.33.4 and TypeScript5.9.3. The shared acceptance gate passes45,513 tests; |
| 138 | +VPN full lint/type checks and1,017 tests pass (one throttle timing failure |
| 139 | +passed both isolated and full-suite retries), and all14 monorepo full lint |
| 140 | +chains pass. Browser's public5.x ruleset test profile passes lint/type checks, |
| 141 | +but retains ten CWS diff-parser test failures; it does not validate private6.x |
| 142 | +ruleset compatibility. |
| 143 | + |
| 144 | +Consumer pilots and public ruleset substitutions are provisional local tests; |
| 145 | +absolute local tarball overrides are not a CI-ready distribution mechanism. |
| 146 | +Use exact approved package builds before publication/rollout. See |
| 147 | +[performance acceptance](performance.md) for the whole-command protocol and |
| 148 | +[consumer compatibility](compatibility.md) for unchanged fallback obligations. |
0 commit comments