Skip to content

Batch command: take rows, follow, stop and remove - #265

Merged
SimonHeybrock merged 2 commits into
mainfrom
262-command-act
Nov 23, 2026
Merged

SimonHeybrock merged 2 commits into
mainfrom
262-command-act

Conversation

@SimonHeybrock

Copy link
Copy Markdown
Member

Second part of #262, and Follow without a page (#151): essapps-batch can do what the batch page does besides reducing.

B="essapps-batch -w FOLDER -b pkg:BINDINGS -s pkg:SOURCES"
$B reduce t.yaml --source sample-runs --first 12345 -l water   # the rows from 12345 on
$B follow -l water             # add and reduce the rows that arrive, until Ctrl-C
$B follow -l water             # later: goes on with the rows that arrived meanwhile
$B stop                        # no batch follows
$B offered -l water            # the rows of the row source that the batch lacks
$B take -l water 12340 12341   # put them into the batch; reduces nothing
$B remove -l water             # remove the batch; its records stay

Each command is one call of Intake or BatchManager. Only follow has code of its own: the loop, and what it prints.

follow makes the batch follow and then does a step every --interval seconds. A step that did something writes one line (one JSON object with --json):

09:26:21 waiting 70009
09:27:36 added 70009 | reducing 70009
09:27:41 done 70009
  • The first Ctrl-C, SIGTERM or SIGHUP ends the steps and waits for the reductions that run. The batch still follows on disk, so the next follow, or a page, goes on.
  • A second signal exits at once. A reduction that was cut off then reads failed, "the workspace ended while it ran"; follow leaves it to a person, and reduce --remaining reduces it.
  • A step that raises is said once and the loop goes on, as on the page. The function that words it (ess.apps.errors.said) moved out of web/ so that the page and the command share it. It says a refusal as its text; the page formatted a pydantic ValidationError raised by application code more briefly before.
  • A workspace that stopped ends the loop with exit status 1. To tell that case, the workspace raises ess.apps.errors.Stopped, a RuntimeError, where it raised a plain RuntimeError.
  • --steps N does N steps, waits for the reductions it submitted and exits, for a script or an agent that cannot hold a process open.

Every table file is replaced in one step (files.replace_at_once). follow sees a run once files.csv lists it, so files -o files.csv is run again while follow runs. It wrote the file in place, and a follow that read the half-written table ended with an error.

Every command now opens the folder with ArrivingFiles, so that a long-running command sees a changed files.csv, and reads files.csv once at the start: a file listed twice, or a listed file that does not exist, is a message with exit status 2. A review ran the commands that existed before on main and on this branch side by side: the output, the exit status and the folder are the same for a valid files.csv.

Measured. A fresh agent (Claude Sonnet) got the command, the names of the bindings and row sources, and a LoKI folder into which a run arrived every 75 seconds. It was to reduce I(Q) from run 70007 on, keep up with the arrivals, and go on after its program was stopped. It was not allowed to read source or documentation. It ran about 15 commands, 4 of them to learn the command; its follow was ended twice by SIGTERM; each of the four sample runs was reduced once.

The same run showed a wrong pair made by LoKI's row source, not by the command: a sample run measured a second time under one name was reduced with the transmission run of the first measurement, because its own arrived 75 seconds later. The case is recorded in #221. The help now says that a row keeps the cells it was added with.

Not done here:

  • A step reads files.csv again whenever it changed. A table that changes faster than a step reads it stalls the steps (seen with an arrival every 0.25 s on 3,000 rows). One snapshot of the files per step would cure it.
  • A test covers one SIGINT. A second signal, SIGTERM and SIGHUP were tried on real processes by the review, and have no test.

To check by hand:

  • essapps-batch --help and essapps-batch follow --help read as a page one could work from.
  • follow on a folder into which a run arrives; Ctrl-C; follow again.

🤖 Generated with Claude Code

SimonHeybrock and others added 2 commits November 23, 2026 09:23
The command could discover, look and reduce, but not do what the page does
besides: take rows of the row source into a batch, follow the files, stop
following, remove a batch. Each new command is one call of Intake or
BatchManager:

    reduce --source NAME --first KEY / --last KEY / --later   Range as choose
    offered -l LABEL          intake.offered
    take -l LABEL KEY...      intake.take; writes the rows as show does
    remove -l LABEL           manager.remove; says how many records stay
    stop                      intake.stop; says which batch stopped
    follow -l LABEL           intake.follow, then a step every --interval s

follow is the second way to run Follow, after the page: whoever runs the
loop owns the timer. The loop, cli.follow, takes its pause and its "stop
asked" check as arguments, so tests run it without waiting or signals.
After a step that did something it writes one line (with --json, one JSON
object): rows added, rows submitted, the status of each row whose reduction
ended, why rows were refused, the rows that wait. A step that raises
ValueError is said on stderr once and the next step runs, as on the page.
The first SIGINT or SIGTERM ends the steps and waits for the reductions
that run; the batch still follows on disk, so the next follow or a page
goes on. A second signal ends the process with os._exit, since the worker
threads otherwise run their reductions to the end; the help says what such
a reduction reads after the next start. --steps N is for scripts and agents
that cannot hold a process open. Exit status 0 if every row is done, else 3.

The command opens the folder with ArrivingFiles, so follow finds the files
that arrive. To keep the help within about 120 lines, the one-line summary
per command is gone: the session in the help lists every command, and each
command's --help keeps its description.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A review ran real follow processes with signals, and an agent used the
commands on LoKI data. What it found:

- files -o wrote files.csv in place, so a follow that read it meanwhile
  saw half a table and ended with a KeyError. A table file is now written
  next to its name and renamed (files.replace_at_once), for write_table
  and write_files_table alike. files does not open the folder, so it runs
  while follow holds it, and the help says to run it again for new runs.
- Only a ValueError of a step was caught: a source that raised anything
  else ended follow with a traceback. A step that raises anything is said
  as the page says it; said() moves from the web layer to ess.apps.errors
  for both. A workspace that stopped raises Stopped (a RuntimeError), which
  ends the loop with exit status 1. With --json, a line carries "error".
- The signal handler wrote to stderr, which raises a reentrant call if the
  main thread writes at that moment. It only sets the flag; the loop says
  that it stops. SIGHUP is taken as SIGTERM.
- --steps must be 1 or more and --interval finite and 0 or more.
- A command that opens the folder reads files.csv once first, so a table of
  files in error (a file listed twice, a file that does not exist) is
  refused with a message, as before ArrivingFiles.
- The help says what the agent had to find out: reduce --source does not
  follow; KEY is the first column of rows; a row keeps the cells it was
  added with; --later; the exit statuses after one and after two signals;
  that the next command runs the reductions that a second signal cut off
  before they started.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant