bridex-worker 0.1.3 → 0.1.5
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 +90 -5
- package/dist/cli.js +1021 -196
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -157,8 +157,15 @@ codex_transport: auto # exec
|
|
|
157
157
|
needs `plan` and `cli:<preset>` for each provider its plan uses; install
|
|
158
158
|
`loopai` and restart the worker to advertise it.
|
|
159
159
|
- **Slots and load.** A grant is refused when every slot is taken, free memory
|
|
160
|
-
|
|
161
|
-
above 1.5 — your own work on the machine comes first.
|
|
160
|
+
is below 700 MB, the cache disk has less than 3 GB free, or the load per
|
|
161
|
+
core is above 1.5 — your own work on the machine comes first. Free memory
|
|
162
|
+
is what the system can hand a run now: on Linux the kernel's available
|
|
163
|
+
memory, within the cgroup's limit when there is one; on macOS the free,
|
|
164
|
+
speculative, inactive and purgeable pages from `vm_stat`, whatever Node
|
|
165
|
+
version runs the worker. If `vm_stat` cannot run, the worker falls back to
|
|
166
|
+
Node's own reading without a log line, and on Node 20 and 22 that leaves
|
|
167
|
+
out the inactive pages macOS reclaims on demand (mostly file cache), so a
|
|
168
|
+
busy Mac shows a few hundred MB. Slots are shared by
|
|
162
169
|
every instance served: each sees the machine's free slots, capped by its
|
|
163
170
|
`max_slots`.
|
|
164
171
|
- **Cache.** `repos/` bare clones, `work/` one checkout per task, `templates/`
|
|
@@ -194,6 +201,79 @@ machine.
|
|
|
194
201
|
|
|
195
202
|
`jail: off` runs with your user's rights and says so on every start.
|
|
196
203
|
|
|
204
|
+
## What a run leaves running
|
|
205
|
+
|
|
206
|
+
Only a job started with `job_start` outlives its run. Anything else a run
|
|
207
|
+
starts in the background (`nohup … &`, a dev server, a headless browser)
|
|
208
|
+
ends with it, on every platform and with the jail on or off — a build
|
|
209
|
+
daemon the run started (Gradle's, say) too, even while a job of the run is
|
|
210
|
+
using it. Under bwrap
|
|
211
|
+
that was always so (the run has its own pid namespace); on macOS and with
|
|
212
|
+
`jail: off` the worker does it itself.
|
|
213
|
+
|
|
214
|
+
Every process of a run or a job carries `BRIDEX_WORKER_UNIT` in its
|
|
215
|
+
environment, inherited by everything it starts and kept when a process is
|
|
216
|
+
re-parented. The value names this worker install (a hash of the cache dir),
|
|
217
|
+
the worker process and the run or the job. The worker reads the
|
|
218
|
+
environments of the machine's processes (`/proc/<pid>/environ` on Linux,
|
|
219
|
+
`ps -E` on macOS) and ends the processes of one tag: SIGTERM, up to 5 s for
|
|
220
|
+
them to exit, then SIGKILL, with a few more SIGKILL passes shortly after
|
|
221
|
+
for what was still going down. It does this:
|
|
222
|
+
|
|
223
|
+
- when a run ends, after the agent CLI returns and before the work is
|
|
224
|
+
committed and pushed, so a leftover does not write into what is pushed.
|
|
225
|
+
The worker log and the run's transcript (a `(worker)` line) name what was
|
|
226
|
+
ended. The run's jobs carry their own tag and are not touched;
|
|
227
|
+
- when a job ends by itself or by its timeout, before its checkout is let
|
|
228
|
+
go and its folder goes up; when the instance cancels it, at once, as its
|
|
229
|
+
checkout is let go (a cancelled job's folder does not go up). A
|
|
230
|
+
timed-out or cancelled job's leftovers get no grace. Once the job's own
|
|
231
|
+
process has exited and its leftovers' grace is over, what is still in
|
|
232
|
+
its process group is ended too;
|
|
233
|
+
- at start, before connecting, for what an earlier worker process of this
|
|
234
|
+
install left: its runs' leftovers and what its ended jobs left. A job
|
|
235
|
+
that is still running is taken back and left alone, and so is a job
|
|
236
|
+
that is still starting (its record names no process yet), a job whose
|
|
237
|
+
record cannot be read, and everything of another worker process that is
|
|
238
|
+
still alive on the same cache dir. A job another worker process on the
|
|
239
|
+
same cache dir recorded while this one was starting is left alone too.
|
|
240
|
+
If that worker process has stopped by then, the job is taken back before
|
|
241
|
+
connecting; if the job has already ended, what it left is ended before
|
|
242
|
+
its folder goes up. When the jobs folder cannot be listed, only runs'
|
|
243
|
+
leftovers are ended, since any job may be one still running.
|
|
244
|
+
|
|
245
|
+
Processes without this install's tag — yours, another worker install's, an
|
|
246
|
+
instance's on the same machine — are never signalled. Before signalling, the
|
|
247
|
+
worker checks that each pid still belongs to the process it listed, by its
|
|
248
|
+
start time, so a pid handed to a new process meanwhile is not hit. On Linux
|
|
249
|
+
it reads `/proc/<pid>/stat` right before that pid's own signal; on macOS
|
|
250
|
+
one `ps -o lstart` call, accurate to the second, checks a whole pass's pids
|
|
251
|
+
right before that pass. A job started by an
|
|
252
|
+
earlier worker release carries no tag and ends as it did before. When the
|
|
253
|
+
processes cannot be listed the worker logs a warning and the run or job
|
|
254
|
+
goes on as usual. A listing that takes over 5 s counts as one that failed:
|
|
255
|
+
on Linux a process stuck on a hung mount can stop its `environ` from being
|
|
256
|
+
read, so the worker reads `/proc` from a short-lived child process it ends
|
|
257
|
+
at that limit.
|
|
258
|
+
|
|
259
|
+
Limits. This is housekeeping for well-behaved tools, not a fence:
|
|
260
|
+
|
|
261
|
+
- On macOS the environment of an Apple system binary (`/bin/sleep`, say)
|
|
262
|
+
cannot be read, so such a leftover of a run is not found. A job's are
|
|
263
|
+
still ended when they stayed in the job's process group — unless the
|
|
264
|
+
job was taken back from an earlier worker process: its group is not
|
|
265
|
+
ended then, as its pid may lead another group by now. The group is
|
|
266
|
+
watched from the job's exit until it is ended; once it is seen empty, or
|
|
267
|
+
the worker was too busy to look for a quarter of a second, it is let be,
|
|
268
|
+
as its number may be another group's by then.
|
|
269
|
+
- A process that clears or replaces its own environment is not found. On
|
|
270
|
+
Linux, one already found is still ended if its environment changes or
|
|
271
|
+
can no longer be read (it made itself non-dumpable): it stays in the
|
|
272
|
+
sweep while `/proc/<pid>/stat` shows the same start and it is not a
|
|
273
|
+
zombie.
|
|
274
|
+
- On macOS `ps -E` prints the variables on one line, so a tag-like token
|
|
275
|
+
inside another variable's value cannot be told from the variable itself.
|
|
276
|
+
|
|
197
277
|
## Artifacts
|
|
198
278
|
|
|
199
279
|
- `rest` — through the instance's API. Always works.
|
|
@@ -489,7 +569,9 @@ What the watchdog does not cover:
|
|
|
489
569
|
`zsh: killed` in zsh) with the stuck line as its last output; start it
|
|
490
570
|
again by hand. When the worker thread ended it (its main thread was
|
|
491
571
|
held), the processes of its runs are left running too, as no service
|
|
492
|
-
manager ends its process group
|
|
572
|
+
manager ends its process group; the next start on the same cache dir
|
|
573
|
+
ends those it can find (see
|
|
574
|
+
[What a run leaves running](#what-a-run-leaves-running)).
|
|
493
575
|
- A worker that loses only some of its pool threads goes on: the probe
|
|
494
576
|
passes while one thread is free.
|
|
495
577
|
- Ctrl-C and the other ordinary exits end the process with
|
|
@@ -497,8 +579,11 @@ What the watchdog does not cover:
|
|
|
497
579
|
hang there, and the watchdog cannot fire any more: end it with `kill -9`.
|
|
498
580
|
- When the worker thread ends a process whose main thread is held, a
|
|
499
581
|
run's helper that made a process group of its own and does not end with
|
|
500
|
-
its parent (a daemonized dev server, say) outlives it under launchd
|
|
501
|
-
|
|
582
|
+
its parent (a daemonized dev server, say) outlives it under launchd
|
|
583
|
+
until launchd starts the worker again: the start ends it, unless it is
|
|
584
|
+
one the worker cannot find (see
|
|
585
|
+
[What a run leaves running](#what-a-run-leaves-running)). systemd's
|
|
586
|
+
default `KillMode=control-group` ends it with the unit.
|
|
502
587
|
|
|
503
588
|
## Release
|
|
504
589
|
|