Skip to content

Agent layer, part 1: the command machinery - #99

Merged
kalidke merged 24 commits into
mainfrom
agent-commands
Dec 2, 2026
Merged

kalidke merged 24 commits into
mainfrom
agent-commands

Conversation

@kalidke

@kalidke kalidke commented Nov 29, 2026 •

Copy link
Copy Markdown
Member

First code change of the instrument-agent layer: a shared part of this package through which a Claude session can
operate a microscope. It reads state and runs a short, per-instrument list of approved actions only while a person
allows it, and proposes anything else for a person to confirm. This change adds only the command machinery the rest
builds on; the body that holds a person's grant and STOP, the call surface, the transports and the workspace follow in
later pull requests.

What it adds

A new submodule, MicroscopeControl.Agent, declared public and not exported, so using MicroscopeControl gains no
name from it.

  • Commands an instrument declares. CommandTable, CommandArg, CommandPlan, Command, register_command!,
    describe_commands: each instrument owns its table; each command, immutable once made, has a pure plan (what it
    would move, and whether light leaves the instrument) and an execute. The layer's own :abort and :agent_may_act
    come only from register_abort_command! and register_grant_command!; register_command! refuses both names.
  • The trust boundary. What a mind (a Claude session) sends is untrusted, and the layer defends against anything
    it can send. The instrument's own code (its plans, executes, hooks and command_core) is trusted but may fail: the
    layer survives its throws and interrupts, and the docs state each hook's obligations.
  • Arguments are values. A declared argument type is one of a closed set: Bool, Int, Float64, String,
    Symbol, a concrete Tuple or Vector of these, or Union{Nothing,T} of one. Registration refuses anything else
    and says what to use, and refuses two arguments of one name. convert_arg converts by a closed rule (a Bool is
    never a number, at any level; an Int becomes a Float64 only exactly; a Float64 is finite; a vector is read by
    iteration, whatever its indices), and the layer holds each argument in a canonical immutable form.
  • One path. run_command is the only way a command runs, and it asks the system for its CommandCore once per
    call. Every system holds one and implements command_core and make_safe!; what an instrument adds goes through
    hooks with defaults, dispatched on its type: after_execute (after the result is classified; may throw Aborted)
    and is_aborted (an abort reported by a result; side-effect free). The docs page shows them on an instrument with
    a focusing phase, and says which outputs its inhibit covers.
  • Confirmations bind what executes. The layer sets a plan's command, arguments and their declared types from the
    request and the declaration, refuses a plan function that names another command or a table entry held under another
    name, and binds every confirmation (free commands' too) to an immutable form of the plan it was given: the command,
    the arguments by type and value at every level, their declared types (so a re-declared command's old confirmations
    bind nothing once a bound field changes, a declared argument type included; re-registering with the same bound
    fields keeps them valid), the moves and the emits flag. Every Confirmation constructor reads the plan once and
    derives both what it shows and what it binds from that one read.
  • STOP and admission. STOP is checked before any confirmation is asked for. A serialized command claims the
    slot, in one atomic step that is also the busy check, and only then reads the STOP latch, on sequentially
    consistent atomics, so a STOP on another thread either refuses it or finds it in the slot and stops it at its next
    checkpoint. While STOP is latched, only the layer's :abort, its grant turning off, and reads run (the two
    exemptions known by identity, not by name); an unserialized command whose plan emits is always refused.
  • An abort is part of the slot. request_abort! and the layer's :abort mark the command in the slot in one
    atomic step (both return its name), and the command's end takes that mark in another, its ordering point, after
    which no abort reaches it. So an abort either reaches the command before its end, which then makes the instrument
    safe (or latches STOP when make_safe! fails), or finds it ended and says so; an abort sent while nothing runs
    reaches nothing, and none is ever left over to be cleared as stale; one that marks a command STOP then refuses at
    admission is recorded. The slot is freed only after the end's cleanup. The :abort's on_abort runs only for a
    command it reached, its arrival is recorded first, and while the :abort is counted (the API page's "STOP, abort
    and the body thread" defines the span once) the command's slot is not freed to another command and, the checks
    running in order (STOP, then confirmation, then the count), AbortInFlight refuses an unserialized movement that
    passed the earlier checks (a serialized command is refused CommandBusy, since the slot is held), while a latched
    STOP refuses it Stopped first; the count refuses none of unserialized reads, the :abort and the grant turning
    off. An on_abort may act on a whole actuator, and the layer cannot know which, so an
    unserialized movement whose run overlaps one in the other order (admitted before it was counted) is treated as
    reached by it: whatever its execute returned, it is recorded :command_aborted ("an abort's on_abort was counted
    (begun, or about to begin) while it moved") and the caller gets Aborted, or a Ctrl-C that arrived while its end
    ran; one whose execute threw keeps its failure record, with the overlap noted. The movement reads a change counter
    (on_aborts) at admission, then checks the slot; at its end it reads the slot, then the counter. The :abort
    changes the counter in its finally, before the uncount. The comment at _watches_on_abort states which step
    covers which window: the admission check refuses an on_abort already counted; the slot read at the end sees one
    still counted, including one a forced interrupt left counted for good; and the counter sees one uncounted before the
    end. A movement's run ends where its execute returns, so the Command docs require a movement to return only when
    its motion has ended, and to check the driver's status and throw when completion is unknown (the N-472 move waits
    until every axis is on target, but returns FALSE when its on-target query fails while the motion may continue).
    Without an on_abort (the keyword left out), :abort counts nothing, refuses no movement and treats none as
    reached; supplying one, even one that does nothing, selects the counted path.
  • Made safe at every abnormal end. A serialized command runs make_safe! on any exception from execute or
    after_execute, interrupts included (first, before anything is classified or logged), on an aborted result (the
    layer's own Aborted counts whatever is_aborted says and is recognized with interrupts still deferred,
    after_execute cannot undo it, that result is what run_command returns, and a later abnormal end, an interrupt in
    after_execute say, keeps the classification), on a classifier that throws, and on an abort or STOP that reached it
    before its end. So if it throws after its execute began and before its end settled its cleanup, make_safe! has
    run, or STOP is latched. make_safe! returns nothing once the instrument is safe; one that fails, does not
    return, or returns anything else (a pending Task) latches STOP, is not called again, and no record then claims the
    instrument was made safe.
  • Interrupts. From the claim to the release step, interrupts are deferred except inside execute and the hooks
    that classify or follow it (an unserialized command, the layer's :abort included, is deferred the same way from
    its final admission checks to its terminal record, so an admitted command always leaves its record), so a Ctrl-C
    cannot land between a failure and its cleanup, or between a failed cleanup and the STOP latch. A deferred interrupt
    stays pending until the first reopening for the instrument's code (where the layer takes it as that step's failure)
    or the end of the layer's steps (an ordinary throw, on a throw as well as a return: Base.disable_sigint alone
    would deliver it past the caller's catch); at a yield, another task may receive it first, while the command runs
    on. One still pending as interrupts reopen for execute takes effect there, and execute never runs: the command
    fails, with its cleanup. Once the end has decided its cleanup, no new cleanup is made, so which task receives the
    interrupt no longer matters to the instrument; the terminal event's kind still comes from classification (the layer
    classifies its own Aborted, and the instrument's is_aborted classifies anything else); an interrupt that escapes
    the classification of an exception records the command as failed. An interrupt that escapes into the layer (from
    execute, a hook, make_safe! or a report) is thrown to the caller: caught, saved (_End.held) and thrown after
    the release step on a serialized command, rethrown as it is on an unserialized one; instrument code that catches its
    own interrupt decides what follows. make_safe! runs deferred, so it must return promptly. The API page states the
    delivery rule once, in "Where an interrupt lands", and the other passages point to it: the layer guarantees the
    cleanup and the record, not which task receives an interrupt or when relative to a record. A host must make Ctrl-C
    catchable (Base.exit_on_sigint(false)); the body's startup will.
  • The release. The claim is taken inside the region whose finally runs the release step, once the end has
    settled its cleanup (none needed, make_safe! returned, or it did not and STOP is latched), whatever the event
    log's reporting does: a tee or a logger that fails cannot strand the slot. The slot is free then, unless the layer's
    :abort for the command is still counted; the last of those frees it. A forced interrupt (a Ctrl-C pressed
    repeatedly) fails closed, by the rule the API page states once, in its "Forced interrupts" section; among its cases,
    an abort that reached a claim whose admission it cut short latches STOP, since request_abort! had acknowledged it.
    The section also says to restart Julia after a forced interrupt: in plain Julia 1.13, with no package loaded, a
    later Ctrl-C ends the process with a segmentation fault when the forced interrupt landed in running Julia code
    (reproduced; not when it landed in a blocking C call; no Julia issue reports it).
  • Records. One terminal event per admitted execution (:command_done, :command_aborted or :command_failed)
    where the log can be written (a refusal by an admission rule, STOP and the emit rule, confirmation, busy or
    AbortInFlight, records :command_refused; a dry run records nothing, and so does a call that fails before those
    rules decide, for its reentry, thread, name or arguments, say, or for a plan or confirm function that fails); an
    exception whose showerror fails or is interrupted is recorded by its type's name. A STOP the layer latches says
    why: :make_safe_failed only when make_safe! was called and failed, :stop_latched for an end or an admission
    cut short, and "STOP refused" only when STOP refused.
  • on_abort. It returns only when its action has completed or can no longer affect a later command, and returns
    nothing (the docs show sys -> (stopmotion(sys.stage); nothing): a driver call may return a status). From inside
    its call until it has returned nothing its action counts as outstanding: one that throws or returns anything else
    (a Task) latches STOP before its failure is formatted and before its count is undone, and is logged; a
    throw(nothing) is a throw. The outstanding mark is the last step before on_abort is entered: an interrupt
    delivered as :abort reopens interrupts, before it, is recorded as what it is and latches nothing; one at or after
    the call that comes before the layer read on_abort's return is recorded as "was interrupted before the layer saw
    it return nothing", never as a throw, and latches STOP, since the layer cannot tell. A failure is recorded before
    the uncount, a success after it, so a slow success report cannot hold the slot.
  • No command from inside the layer's steps. run_command refuses, before anything else, a call from inside the
    layer's own deferred steps (make_safe!, or a report of the event log: its tee, or a logger an @error reaches)
    with ReentryRefused, since a command started there would run with the layer's deferral still in force and one
    Ctrl-C would not stop it. A per-task flag in task-local storage marks those steps; _interruptible clears it for an
    execute and the hooks, so an execute may run another command, and a task spawned from inside the steps inherits
    neither the flag nor the deferral (Julia keeps the deferral per task). The flag is set inside the try whose
    finally restores it. The runtime refusal applies only inside those steps: a reporter of a refusal made before them
    (STOP before a confirmation, a confirmation required or not matching) is not checked by it, and the API page keeps
    the rule for instrument authors there too. make_safe! and on_abort call the instrument's drivers directly.
  • Abort from any thread. request_abort! and check_abort are atomic operations, safe from any thread, given a
    command_core that is a non-blocking read. The layer's :abort arms the abort before its on_abort runs and
    before anything is logged; any unserialized command runs before anything on its path is logged.
  • One thread for the body. run_command (dry runs too: plan functions read the instrument's state), log_event!
    and start_job! run only on thread 1 in a sticky task; elsewhere they throw OffThread.
  • EventLog (tab-separated, escaped so no message can forge a line; a record, not an interlock: a failure to write
    it is reported and never stops a command), CommandRunner and start_job! (a busy listener that throws rolls a
    start back; start_job! returns the task it created), JobRecord.

Until the body exists (next pull request), :agent_may_act throws "no body holds this system".

Tests (simulated devices only)

test/agent_fixture.jl holds two systems on simulated devices, both on the one path: one with a camera, a stage and
a light and only the required contract, and one with a laser, a lamp and a focusing phase that exercises the hooks
(and can be set to misbehave: a classifier that throws, is interrupted or knows only its own records, an
after_execute that drops the result, a make_safe! that fails or is interrupted). Light leaves either only while
its source is on and its inhibit, an atomic that make_safe! sets from any thread and no command clears, is clear;
a person's reset turns the source off before it clears the inhibit. A test holds a running command at a known point
with events, never a sleep.

test/agent_commands.jl, in its own module, covers:

  • the closed set of argument types and the conversion rule, offset and non-finite inputs included; frozen
    declarations; the canonical argument form;
  • confirmation binding, its single read of the plan, and a re-declared schema;
  • the STOP rules, with STOP latched before a checkpoint and after one (from another thread, checked to be another
    thread where there is one), at admission, and by a failed make_safe! or one that returns a task;
  • make_safe! on each abnormal end, interrupts included, and on an abort that reached a command that ended normally;
  • an abort on each side of a command's claim and of its end's ordering point;
  • the slot after an event log whose tee and logger both fail;
  • a forced interrupt at each of the layer's own steps (stood in for by an internal test point the tests redefine, a
    no-op inlined away in normal use), including after the claim with an abort already acknowledged, after the end's
    decision, after the count of the :abort's on_abort and after on_abort returns, each with the record it
    leaves;
  • an interrupt during a command's terminal report, which makes no new cleanup, and one thrown by the report of an
    abort STOP refused, which is saved and reaches the caller;
  • the layer's :abort: two on_aborts held and released in either order; an on_abort that returns a task, throws,
    throws nothing or is interrupted, one whose exception is shown only after STOP is latched, and ones whose failure
    report is interrupted; on_abort held at a wait while its command ends, with an unserialized movement refused
    meanwhile and a read, a second :abort and the grant turning off let through; its final admission check made inside
    its deferred region;
  • a movement whose run overlaps an on_abort in the other order: admitted and paused before its stage call, then an
    on_abort that is still outstanding at the movement's end, or that begins and returns while it is paused (both end
    Aborted); one whose execute throws during the overlap (its failure kept, the overlap noted); a read paused
    across an on_abort (done); a movement admitted after the on_abort returned (done); a forced interrupt between
    the :abort's slot count and its raise of the count (the movement still ends Aborted); an interrupt that each of
    a movement's three terminal records meets (the record kept, the interrupt after it); a slow :abort success report
    (the slot already free, a movement admitted); and the default on_abort (nothing counted, the movement done);
  • a returned Aborted ended abnormally by an interrupt in after_execute, still recorded :command_aborted;
  • reentry from inside the layer's steps: a reporter's run_command refused on the unserialized path, the serialized
    path and the :abort, and from make_safe! (STOP latched, recorded); an execute that runs another command, and a
    task spawned from a reporter, unaffected; an error while an unserialized command's arguments are prepared
    (recorded); a forced interrupt just after the per-task flag is set, at the set that opens the layer's steps (the
    task left unmarked) and at the one that opens an execute (the steps around it still marked as they unwind);
  • real SIGINTs, in a child process with the parent's flags, project and threads (Unix only; at its deadline it gets
    SIGTERM, then SIGKILL after ten seconds): in execute, as it fails before its cleanup, inside make_safe!
    (completing, failing, and after execute threw the layer's own Aborted, which is still recorded as an abort), in
    the last steps of a command that needed no cleanup, as the :abort records its arrival (recorded as the interrupt,
    with STOP clear), as an overlapping movement's end decides its overlap (its :command_aborted record kept, the
    interrupt after it), as a reporter of an unserialized command calls run_command for a confirmed light-on (refused;
    the light never comes on), as an unserialized command passes its final admission checks (its record kept, the
    interrupt after it), and three on the :abort with a command held and a writable tee: immediately before it reads
    the STOP latch in its final admission check (chosen by its role, the first STOP read inside the layer's steps), with
    the default on_abort and with one of the instrument's, and after the instrument's on_abort returned. Each time
    the abort arms the command's abort and records its arrival and its end (a failure where the interrupt arrives as
    interrupts reopen for on_abort), the tee receives both records, the interrupt comes after, and the command stops.
    A real forced interrupt is not sent: Julia throws it from its signal handler at whatever instruction runs, which can
    deadlock the process;
  • the hooks, misbehaving ones included; the aborted result reaching the caller; one terminal record per admitted
    execution, and an exception whose showerror fails;
  • the layer's :abort arming its abort before its instrument's code; one core per call; the latch and the slot being
    sequentially consistent atomics;
  • the event log failing open; the thread rule (another thread, sticky or not, and a non-sticky task on thread 1, with
    no instrument callback run there); the job runner; and showerror of every exception.

The Interface Contract testset gains an "Agent layer" check: the submodule is public and not exported, its exports
resolve beside MicroscopeControl's with no clash, there are no method ambiguities, the required contract functions
throw, the hooks have defaults, and run_command has one method.

Beyond the committed tests, a statement-boundary sweep (an interrupt thrown before each of 164 statements of the
layer's end, abort, admission and flag functions, singly and in pairs, in 16 scenarios, one judged by the overlap
rule's letter) found no boundary at which the layer admitted a command with a needed cleanup missing, or let an
overlapping movement end with a success record. Committing such a sweep is listed for the next pull request.

Each safety check has a test that fails when that check alone is removed: a sweep of 159 mutations in a scratch copy
(tried, not committed), one full pass on the code as it now stands (round 16 changed only comments, docstrings and
tests, and every row still finds its anchor), failed at least one test for 146 of the 147 meant to fail (the other 12,
ten correct rewrites and two named limits, are expected to pass, and they do), including mutations of the interrupt
deferral and its delivery (for unserialized commands and the :abort too, from their admission), of the refusal of a
command from inside the layer's own steps and of the flag behind it being set inside its try, of the end's ordering
point and its decision, of the release rule, of an abort owed at a cut-short admission, of the movement refusal while
the :abort is counted and of a movement overlapping one, of the change counter and the slot read that cover that
overlap, of the make_safe! and on_abort return and throw rules, and of the count of the :abort's on_abort. The
one that passes, freezing a vector by making a tuple from a generator over it rather than reading it into dense
storage first, is equivalent in this process: OffsetArrays, which MicroscopeControl loads through Makie, already gives
such a tuple the vector's values. The order of admission (the claim, then the STOP read) and of the end (the ordering
point, the cleanup and the terminal event, then the release; in a release, a claim never admitted read before it is
freed; in an abnormal end, the STOP latch for a make_safe! that did not return before anything else) is held by a
source-order check, since no task can run between those steps. The :abort's final STOP read is guarded at the read:
a test point in _check_stopped, immediately before the latch is read, where the child process sends a real SIGINT on
the :abort's final check (chosen by its role, the first STOP read inside the layer's steps), with the default
on_abort and with one of the instrument's; a third child check sends it after the instrument's on_abort returned,
and each compares the event kinds in a writable tee, read after the writer is closed. These run three cases: the
default on_abort, and an instrument's that returns nothing, with the SIGINT at the final STOP read or after that
on_abort returned; the failure branch of an instrument's on_abort is not run with a pending signal (owed by the
next pull request); code moved ahead of its test point (the latch read cached in a local before the point) is outside
what any one test point can see. A parent test at :abort_admitted is the fallback where the child is skipped. The
reentry flag's write holds its test point inside _mark_layer_step!, and the forced stand-in there selects the first
write that clears the flag. Round 16's own run: sixteen defects fail these checks (among them interrupts reopened only
when the instrument registered an on_abort, around the uncount, around reading on_abort's return, and for the
success report's tee write), twelve correct rewrites pass (among them the :abort's pre-confirmation check skipped,
or split into a helper without the point), and three named limits pass, as expected: a restore made conditional on
something set between the flag's write and its point, an extra write of the flag outside _mark_layer_step! (both
closed by the next pull request's committed sweep), and the latch read cached ahead of its point.

Other

  • docs/src/api/agent.md: an API page with an example run on simulated devices and a worked example of the hooks;
    the docs' coverage check passes.
  • New dependency: Observables (already loaded through Makie).
  • Not breaking: additions only. The version stays 0.2.7-DEV, with no tag.
  • Owed by the next pull request, which adds the body: refusing, when it attaches a system, a method of run_command
    of the instrument's own and a command_core that returns another core at a second call (Julia cannot seal a
    function, so this part can only document both rules); clear_stop!, a person's clear of the latch (there is no
    abort flag to clear); a stop! that latches STOP and then calls request_abort!; Base.exit_on_sigint(false) at
    the body's startup, so a Ctrl-C is catchable; a close that reports a nothing from request_abort! as an abort
    that reached nothing; a person's way to clear a slot held after its call unwound (after make_safe!); the body's
    other tasks (the heartbeat, the hop drainer, the transport) surviving a Ctrl-C, or SIGINT routed to stop!; the
    heartbeat's count of event-log write failures; and a committed statement-boundary sweep (a forced interrupt before
    each statement of the layer's functions, one at a time, in the child process, including the two transitions of the
    per-task flag behind ReentryRefused: one inside the finally that restores it, which leaves the task marked, and
    one in the restore that ends an interruptible step, which leaves it clear while the outer steps unwind; it also
    closes what one test point after the flag's write cannot see: a restore made conditional on something set between
    the write and the point, or an extra write of the flag outside _mark_layer_step!), so the tests cover the whole
    class of forced-interrupt windows rather than named points.
    Also owed, from the round 17 reviews:
    • a fourth child case for the failure branch of an instrument's on_abort: a SIGINT at :returned with an
      on_abort that returns a value, expecting [:abort_requested, :command_failed] in the log and the tee, STOP
      latched, and the slot freed once the command has ended;
    • a tee check that reads the whole line through a separate reader while the writer is still open, so an incomplete
      or late line fails it;
    • a STOP-read selector that cannot pick the preliminary read when that read is wrapped in a deferred region of its
      own;
    • wording that tells an interrupt's first delivery (to the layer, as interrupts reopen for on_abort) from its
      delivery to the caller, on both paths, and on the unserialized path that an interrupt from execute is rethrown
      directly, while one from a report is saved and thrown after the record;
    • the three named limits closed: a restore conditional on something set between the flag's write and its point
      (M164), an extra write of the flag outside _mark_layer_step! (M165), and the latch read cached ahead of
      :stop_read (M172).

Checked: the full local suite and the docs build on Julia 1.13, the agent tests at --threads=1,0, 2,1 and
4,1 (results in the comment below), and the lab test record on Julia 1.13 and on the 1.11 floor (the lab/tests
status on the head), where the child-process SIGINT checks run too.

🤖 Generated with Claude Code

kalidke and others added 3 commits November 29, 2026 00:00
Adds MicroscopeControl.Agent, a public submodule that is not exported, so
`using MicroscopeControl` gains no name from it. It holds what lets an
instrument declare its commands and run them one serialized command at a
time, with an abort and a STOP latch that act from any thread:

- CommandTable, CommandArg, CommandPlan, Command, register_command! and
  describe_commands: an instrument's own table of commands, each with a pure
  plan (what it would move, and whether light leaves the instrument) and an
  execute. register_abort_command! and register_grant_command! add the
  layer's own :abort and :agent_may_act.
- run_command dry-runs a command to its plan, refuses a confirm-class
  command without a Confirmation, and binds every confirmation, of free
  commands too, to the requested command, its arguments, moves and emits
  flag as they are now, so a confirmation of a plan that has since changed
  is refused. Arguments convert by a closed rule (convert_arg; a Bool is
  never a number).
- AbortFlags holds two atomics, abort and the STOP latch, so request_abort!
  and check_abort work from any thread with no lock. check_stopped refuses
  an unserialized command whose plan emits (it would run beside another
  command), and, while STOP is latched, everything but :abort, the grant
  turning off and reads.
- EventLog, CommandRunner and start_job! belong to the body thread, thread 1
  in a sticky task: a non-dry run_command, log_event! and start_job! throw
  OffThread anywhere else, including in a spawned task that happens to run
  on thread 1, since it can move to another thread at its next yield.
- The system contract: a system holds a CommandCore, or has its own
  run_command and implements abort_flags; either way it implements
  make_safe!, whose fallback throws.

The body that holds the operator's grant and STOP is not part of this
change; until it exists, :agent_may_act throws. Adds Observables as a direct
dependency (already loaded through Makie). The version stays 0.2.7-DEV:
additions only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
test/agent_fixture.jl holds two systems, one per mode of the system
contract: SimScope (a SimCamera, a SimStage2d and a SimLight behind a
CommandCore) and OwnScope (a SimLight, its own run_command and its own
AbortFlags).

test/agent_commands.jl checks, in both modes where the mode matters:
- the unserialized rule and the STOP latch: an emitting unserialized
  command is refused; while latched, a read, :abort and the grant turning
  off get through and everything else is refused, and the stale-abort clear
  is never reached;
- a command that turns light on stops at its next checkpoint once STOP
  latches from another thread;
- confirmations bound to the plan as it is now, for confirm-class and free
  commands, its emits flag, and the requested command name;
- ArgError kinds, and convert_arg's rule that a Bool is never a number;
- one serialized command at a time, the abort, and the stale-abort clear;
- OffThread from another thread and from a non-sticky task on thread 1;
- request_abort! from another thread beside logging on thread 1;
- the grant toggle running beside a job, the path a revoke takes;
- the event log's tee and escaping, the job runner, and showerror of every
  exception.

The Interface Contract testset gains an "Agent layer" check: the submodule
is public and not exported, its exports resolve beside MicroscopeControl's
with no clash, it has no method ambiguities, and the contract's required
functions throw.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
docs/src/api/agent.md introduces the command machinery with an example on
simulated devices, names every exported and public name of the submodule,
and takes its other docstrings in an Internals section, so the build's
docstring coverage check passes. CHANGELOG.md: one Added entry under
Unreleased.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kalidke

kalidke commented Nov 29, 2026

Copy link
Copy Markdown
Member Author

Local checks on b6ee818 (Julia 1.13):

  • Full suite, xvfb-run -a julia --project -e 'using Pkg; Pkg.test()': all tests pass, with the same 3 known broken
    tests as main; "Instrument agent: commands" adds 217 checks and the contract's "Agent layer" 13.
  • The agent and contract tests also pass with --threads=1,0, 2,1, 4,1 and auto (at 1,0, the 3 checks that
    need a second thread are skipped).
  • Docs build, xvfb-run -a julia --project=docs docs/make.jl: passes; the coverage check finds every docstring on a
    built page.

The command machinery's checks are tightened so that none depends on an
instrument getting something else right:

- make_safe! runs whenever a serialized command ends abnormally: by any
  exception (an abort, or a failure such as a camera timeout after a light
  came on) or by a result is_aborted reports, before that end is logged.
  An unserialized command, which can never emit, never calls it.
- An abort is never lost: the layer's :abort sets the flag before it logs,
  and a failure to write the event log is reported with @error and never
  stops a command, its abort or its make_safe!. A stale abort is cleared
  before a command is published as running, so an abort aimed at the
  running command is kept for its first checkpoint.
- A confirmation binds what executes: the layer sets the plan's command and
  arguments from the request (the converted arguments execute receives)
  and refuses a plan function that names another command, or a table entry
  held under another name. The plan shown is a snapshot (Confirmation and
  the plan constructor copy it; execute gets a copy of the caller's values),
  and arguments compare by type and value at every level, so true is not 1
  and 0.0 is not -0.0.
- The thread rule holds in both modes: run_command checks the body thread
  first, dry runs included, since plan and confirm functions read the
  instrument's state; check_stopped starts with the same check, so a
  system with its own run_command gets it too.
- check_stopped runs before a confirmation is asked for, so nothing invites
  a confirmation of a command that cannot run; under STOP the grant turning
  on is refused whatever its plan's moves.
- convert_arg's Bool rule holds inside a tuple or array that is already of
  the declared type.
- An argument may not be named dry_run or confirmed, run_command's own
  keywords.
- start_job! rolls a start back when a busy listener throws, keeps the slot
  free when one throws as a job ends, and returns the task it created.

Tests: each of these checks has a test that fails when that check alone is
removed (shown by a mutation sweep of 27 mutations in a scratch copy). The
cross-thread STOP test holds the command at a known point with events
instead of a sleep and checks which thread latched STOP; the fixture's
make_safe! closes a shutter held in an atomic, the channel independent of
the light the command switches. The test file runs in its own module.
Checked on simulated devices at --threads=1,0, 2,1 and 4,1.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kalidke

kalidke commented Nov 29, 2026

Copy link
Copy Markdown
Member Author

Round 1 fixes in 140b5a2 (both reviews; every blocking and should-fix finding). Local checks on 140b5a2 (Julia
1.13): the full suite passes, with the same 3 known broken tests as main; the agent and contract tests pass at
--threads=1,0, 2,1 and 4,1 (at 1,0 the checks that need a second thread are skipped); the docs build passes
with every docstring on a built page. A mutation sweep removing each safety check in turn (27 mutations, in a scratch
copy) failed at least one test for 26; the 27th is explained in the description.

A system with its own run_command had to copy safety rules the layer
keeps internal, and the copies drifted. That mode is gone: every system
holds a CommandCore, run_command is the layer's one method, and an
instrument changes what happens around its commands through hooks with
defaults, dispatched on its system type:

- after_execute(sys, c, args, result) runs after execute returns, while
  the command holds the slot; it may throw Aborted for an abort that
  arrived after the last checkpoint (stop a focusing phase first).
- is_aborted(sys, x) classifies a result or an exception.
- make_safe!(sys), required, as before.

abort_flags, check_stopped and AbortFlags are internal now. The docs page
shows the hooks on an instrument with a focusing phase.

Arguments are values of a closed set of types: Bool, Int, Float64,
String, Symbol, a concrete Tuple or Vector of these, or Union{Nothing,T}
of one. Registration refuses anything else and says what to use;
convert_arg converts by a closed rule in which a Bool is never a number
at any level and an Int becomes a Float64 only exactly. Plans hold each
argument in a canonical immutable form, and each callback gets its own
value of the declared type.

Also:
- A confirmation binds an immutable form of the plan (command, arguments
  by type and value, moves, emits), made by every constructor and
  independent of c.plan, its display copy.
- STOP is checked again at admission, after the confirmation is bound,
  with nothing that can yield between that check and the claim.
- An unserialized command, :abort included, runs before anything on its
  path is logged, so an abort reaches its flag first.
- A serialized command that ends abnormally (any exception from execute
  or after_execute, an aborted result, a classifier that throws) runs
  make_safe! before anything is classified or logged; a late abort is
  logged as such only after a normal end.
- The event log's write guard never swallows an interrupt; a failed write
  is still a record failure that never stops a command.

Tests: the second fixture is an instrument with a focusing phase on the
one path; the fixtures' make_safe! sets an inhibit no light-on step can
clear, tested with STOP latched before and after a checkpoint. A
mutation sweep of 38 mutations in a scratch copy fails at least one test
for every check. Checked on simulated devices at --threads=1,0, 2,1 and
4,1.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kalidke

kalidke commented Nov 29, 2026

Copy link
Copy Markdown
Member Author

Round 2 fixes in 607b6a9. Most round 2 findings came from one class: a system with its own run_command had to copy
safety rules the layer keeps internal, and the copies drifted. That mode is gone; every command runs through the
layer's run_command, and instruments add behavior through hooks (after_execute, is_aborted, make_safe!).
Arguments are now values of a closed set of types. On a failed write of a command's start event, every command still
runs (the event log is a record, not an interlock); the reviewers differed on this, and it is decided here.

Local checks on 607b6a9 (Julia 1.13): the full suite passes, with the same 3 known broken tests as main; the agent
and contract tests pass at --threads=1,0, 2,1 and 4,1; the docs build passes with every docstring on a built
page. A mutation sweep removing each safety check in turn (38 mutations, in a scratch copy) fails at least one test
for every one.

…very end

The layer now states its trust boundary: what a mind sends is untrusted, and the
instrument's own code (plans, executes, hooks, command_core) is trusted but may
fail. Against that:

- Admission is publish, then check. A serialized command clears a stale abort,
  claims the slot and only then reads the STOP latch, so a STOP on another
  thread either refuses it or finds it running and stops it at its next
  checkpoint. The abort and STOP flags and the running slot are sequentially
  consistent atomics: a Threads.Atomic's acquire and release orders let a store
  and a later load of the other flag pass each other.
- run_command asks the system for its core once and uses that core throughout;
  no instrument code runs between the busy check and the claim.
- The layer owns :abort and :agent_may_act. register_command! refuses both
  names, the abort command sets the abort flag itself before it calls the
  instrument's on_abort, and STOP's exemptions recognize the layer's two
  commands by what they are, not by their names.
- The layer counts its own Aborted whatever is_aborted says, classifies a
  result before after_execute runs (so the hook cannot undo an abort), and runs
  make_safe! at any end where the abort or STOP flag is still set, so a command
  that honors an abort by returning partial work leaves the instrument safe.
- A make_safe! that fails, or is interrupted, latches STOP.
- If a serialized command throws after its execute began, make_safe! has run,
  interrupts included (during completion logging, classification, or make_safe!
  itself), and a terminal event is recorded where it can be.
- A Confirmation reads its plan once and derives both what it shows and what it
  binds from that read. Commands are immutable, with a Tuple of arguments; the
  binding includes each argument's declared type, so the old confirmations of a
  re-declared command bind nothing; two arguments of one name are refused.
- Vector inputs are read by iteration into dense one-based storage, so arrays
  with other indices convert and bind as their values; non-finite Float64
  arguments are refused.
- The test fixture's reset turns the source off before it clears the inhibit.
- The docs page and the module docstring state the trust boundary and the hook
  obligations: classifiers have no side effects, hooks leave the core's flags
  alone, an instrument defines no run_command method and returns the same core
  at every call, and a plan that depends on state binds an absolute target or
  re-checks it at the hardware action. The worked example says which outputs
  its inhibit covers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kalidke

kalidke commented Nov 29, 2026

Copy link
Copy Markdown
Member Author

Round 3 fixes in 4ec016a. The layer now states a trust boundary: what a mind sends is untrusted, and the
instrument's own code (plans, executes, hooks, command_core) is trusted but may fail. Admission is publish, then
check, on sequentially consistent atomics; run_command takes the system's core once per call; the layer owns
:abort and :agent_may_act (it sets the abort flag itself, and STOP's exemptions know its two commands by
identity); its own Aborted counts whatever is_aborted says, a result is classified before after_execute, and
an abort or STOP pending at a normal end makes the instrument safe; a failed or interrupted make_safe! latches STOP;
and if a serialized command throws after its execute began, make_safe! has run, interrupts included. A
Confirmation reads its plan once, declarations are immutable and bind their argument types, vector inputs are read
by iteration, and non-finite numbers are refused.

Local checks on 4ec016a (Julia 1.13): the full suite passes (5683 passed, the same 3 known broken tests as main); the
agent and contract tests pass at --threads=1,0 (1353), 2,1 (1370) and 4,1 (1370); the docs build passes with
all 556 docstrings on a built page. A mutation sweep removing each safety check in turn (63 mutations, in a scratch
copy) fails at least one test for 62; the 63rd, freezing a vector through a tuple of a generator instead of dense
storage, is equivalent in this process, since OffsetArrays (loaded through Makie) already gives that tuple the
vector's values.

…slot

A real Ctrl-C (an OS SIGINT) could land between a command's failure and its
cleanup, or inside the handling of a failed cleanup before STOP latched, and an
abort sent just as a command ended could later be cleared as stale. Now:

- Interrupts are deferred (Base.disable_sigint) from the moment a serialized
  command claims the slot until it frees it, except inside its execute and the
  hooks that classify or follow it. An interrupt in the layer's own steps (the
  cleanup, the STOP latch after a failed cleanup, the terminal event, the
  release) is delivered once they are done; one that arrives after the end of
  a command that needed no cleanup makes the layer run make_safe! (logged
  :interrupted) before it is let through. make_safe! itself runs deferred, so
  an instrument's make_safe! must return promptly.
- An abort is part of the slot: request_abort! and the layer's :abort mark the
  command in the slot in one atomic step, and the command's end takes that
  mark in another, after which no abort reaches it. An abort either reaches the
  command before its end, which then makes the instrument safe, or finds it
  ended (request_abort! returns nothing; :abort logs that it arrived after the
  end). An abort sent while nothing runs reaches nothing, so no abort is ever
  left over for a later command. Admission claims the slot in one atomic step
  that is also the busy check, then reads the STOP latch. The slot is freed
  only after the end's cleanup.
- When execute returns an aborted result, run_command returns that result,
  whatever after_execute returns.
- The records are truthful: one terminal event per call where the log can be
  written; an abort the command did not report is noted with whether the
  instrument was made safe; an exception whose showerror throws or is
  interrupted is recorded by its type's name.
- The docs say command_core must be a non-blocking, thread-safe read (a const
  field in a mutable system), that the abort is armed before on_abort runs,
  that an unserialized command admitted just before STOP still runs, and the
  introductory example shows an independent inhibit that only a person's reset
  clears.

Tests send a real SIGINT to the test process at each point of a command's end:
in execute, as it fails before its cleanup, inside a make_safe! that then
fails, and in the last steps of a command that needed no cleanup.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kalidke

kalidke commented Nov 29, 2026

Copy link
Copy Markdown
Member Author

Round 4 fixes in e0f2ed0. Interrupts are now deferred (Base.disable_sigint) from a serialized command's claim of
the slot to its release, except inside its execute and the hooks that classify or follow it, so a Ctrl-C cannot
land between a failure and its cleanup or between a failed cleanup and the STOP latch; make_safe! runs deferred,
and an interrupt that arrives after the end of a command that needed no cleanup makes the layer run make_safe!
before it is let through. An abort is now part of the slot: request_abort! and :abort mark the command in one
atomic step and the end takes that mark in another, so an abort either reaches the command before its end or finds
it ended, and none is left over to be cleared as stale; the slot is freed only after the cleanup. An aborted result
reaches the caller whatever after_execute returns, each call records one terminal event, and no record claims the
instrument was made safe when make_safe! failed.

Local checks on e0f2ed0 (Julia 1.13): the full suite passes (5721 passed, the same 3 known broken tests as main); the
agent and contract tests pass at --threads=1,0 (1391), 2,1 (1408) and 4,1 (1408), including tests that send a
real SIGINT to the test process at each point of a command's end; the docs build passes with all 558 docstrings on
a built page. A mutation sweep removing each safety check in turn (75 mutations, in a scratch copy, the interrupt
deferral and the end's ordering point among them) fails at least one test for 74; the 75th is the equivalent
mutation reported before (freezing a vector through a tuple of a generator, which OffsetArrays, loaded through
Makie, already reads by value).

A reporting failure at a command's end could leave its slot held forever, a
forced interrupt (Julia's repeated Ctrl-C, which passes Base.disable_sigint)
could skip the cleanup or the STOP latch, and the layer's :abort could run its
instrument action after its command had ended, reaching the next one. Now:

- The slot is released in a finally once the end's cleanup step is settled (no
  cleanup was needed, make_safe! returned, or it failed and STOP is latched),
  whatever the event log's reporting does. A logger that fails while reporting
  a failed tee write is ignored. If a forced interrupt cuts the end short
  before its cleanup is settled, the release latches STOP first; at every step
  before that the slot is still held. A forced interrupt can leave the
  instrument unsafe, but never leaves the layer accepting commands. An
  abnormal end calls a make_safe! that was cut short again.
- The layer's :abort marks the command and counts its on_abort in one atomic
  step on the slot, records the arrival, runs on_abort only for a command it
  reached, and uncounts it in a finally. The slot is freed by whichever
  finishes last, the command's end or its on_abort, so an on_abort cannot act
  on a later command; a blocking on_abort keeps the layer refusing commands.
  run_command(sys, :abort) returns what request_abort! returns: the name of the
  command reached, or nothing.
- An abort that marks a command which STOP then refuses at admission is
  recorded.
- The docs say what the after-end interrupt recovery covers (an interrupt
  delivered to the command's own task), that a host process must make Ctrl-C
  catchable, that after_execute must not change how execute's result
  classifies, and that each device call in make_safe! needs its own timeout.

The real-SIGINT tests now run in a child Julia process with the parent's flags,
project and threads, killed after a timeout, on Unix only, and add one as the
:abort records its arrival. A forced interrupt at each of the layer's own steps
is stood in for by an internal test point, a no-op inlined away in normal use,
that the tests redefine; a real forced interrupt is not sent, since Julia
throws it from its signal handler at whatever instruction runs, which can
deadlock the process.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kalidke

kalidke commented Nov 29, 2026

Copy link
Copy Markdown
Member Author

Round 5 fixes in 579489f. The slot is now released in a finally once the end's cleanup step is settled (no cleanup
needed, make_safe! returned, or it failed and STOP is latched), whatever the event log's reporting does; a logger
that fails while reporting a failed tee write is ignored. A forced interrupt (Julia's repeated Ctrl-C, which passes
Base.disable_sigint) that cuts an end short before its cleanup is settled makes the release latch STOP first, and
before that step the slot is still held: it can leave the instrument unsafe, never the layer accepting commands. The
layer's :abort counts its on_abort against the command's slot in the same atomic step that marks the command,
runs it only for a command it reached, records the arrival first, and returns the name it reached; the slot is freed
by whichever finishes last, the command's end or its on_abort. An abort that marks a command STOP then refuses at
admission is recorded. The docs state the after-end recovery's scope (the command's own task), the host's
Base.exit_on_sigint(false), the after_execute classification obligation and the timeouts make_safe!'s device
calls need.

Local checks on 579489f (Julia 1.13): the full suite passes (5762 passed, the same 3 known broken tests as main); the
agent and contract tests pass at --threads=1,0 (1432), 2,1 (1449) and 4,1 (1449). The real-SIGINT checks now
run in a child Julia process with the parent's flags, project and threads, on Unix only, each check reported in the
parent's results (15, all passing at the three settings). A forced interrupt at each of the layer's own steps is
tested by a stand-in, an internal test point the tests redefine to throw there; a real forced SIGINT is not sent,
since Julia throws it from its signal handler at whatever instruction runs, and in trials under load it left the
child deadlocked. The docs build passes with all 559 docstrings on a built page. A mutation sweep removing each safety
check in turn (88 mutations, in a scratch copy, the release rule and the on_abort count among them) fails at least
one test for 87; the 88th is the equivalent mutation reported before.

Each recovery step added for an interrupt opened a new window for a forced
interrupt (Julia's repeated Ctrl-C, which passes Base.disable_sigint): a
command whose end needed no cleanup could be given one by a late report and
then released without it, the recovery after a command's end began with the
slot already free, and a cleanup retried after a failed make_safe! could
clear its record. The layer now keeps one rule for a forced interrupt: at
every instruction boundary of its own code the slot is held, or STOP is
latched, or the cleanup the command needed has returned. It can leave the
instrument unsafe, or a slot held after its call has unwound; inside the
instrument's own code it is the instrument's. Now:

- Once a command's end has decided its cleanup (none needed, make_safe!
  returned, or it did not and STOP is latched), nothing after it creates a
  new one: the terminal event is reported by a step that never throws, a held
  interrupt is rethrown after the release, and the command's result stands,
  as for an abort that arrives after the end. Only a throw before the
  decision makes the end call make_safe!.
- The recovery that ran make_safe! for an interrupt delivered after a
  command's end is removed. Such an interrupt reaches the caller.
- The end marks a make_safe! attempt before calling it. An end that finds an
  attempt that did not return latches STOP before anything else, records it,
  and does not call make_safe! again, so no retry can settle the end as
  clean.
- The release records why it latched STOP when an end was cut short.
- The command's claim, and the :abort's count of its on_abort, are taken
  inside the region whose finally undoes them; only the one instruction
  between the atomic step and its record is left, and an interrupt there
  leaves the slot held.
- on_abort must return only once its action has completed or can no longer
  affect a later command, and must return nothing. From its call until it
  has returned nothing its action counts as outstanding: one that throws (an
  acknowledgement timeout), returns anything else (a task still running), or
  whose return a forced interrupt kept the layer from reading latches STOP,
  in the finally that undoes its count and before that step, and is logged.
  An interrupt held while reporting an on_abort failure reaches the caller.

Tests: two :abort calls whose on_aborts are held and released in either
order, an on_abort that returns a task or throws, forced-interrupt stand-ins
after the claim, after a failed make_safe! at a normal end, after the end's
decision, after the :abort's count and after on_abort returns, and an
interrupt during the terminal report that makes no new cleanup. The child process that runs the real-SIGINT checks is sent SIGKILL
if it is still running ten seconds after SIGTERM at its deadline, so a stuck
child fails the test instead of hanging the suite.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kalidke

kalidke commented Nov 29, 2026

Copy link
Copy Markdown
Member Author

Round 6 fixes, on top of 579489f. They make one rule for a forced interrupt (Julia's repeated Ctrl-C, which passes
Base.disable_sigint) the standard: at every instruction boundary of the layer's own code, the slot is held, or STOP
is latched, or the cleanup the command needed has returned. A forced interrupt can leave the instrument unsafe, or a
slot held after its call has unwound; inside the instrument's own code it is the instrument's. Recovery steps were
removed rather than guarded:

  • Once an end has decided its cleanup, nothing after it creates a new one. The terminal event is a step that never
    throws, a held interrupt is rethrown after the release, and the command's result stands.
  • The recovery that ran make_safe! for an interrupt delivered after a command's end is deleted; such an interrupt
    reaches the caller.
  • A make_safe! attempt is marked before the call. An end that finds one that did not return latches STOP before
    anything else, records it, and does not retry.
  • The release records why it latched STOP.
  • The claim and the :abort's count are taken inside the region whose finally undoes them.
  • An on_abort counts as outstanding from its call until it has returned nothing. One that throws, returns
    anything else, or whose return a forced interrupt kept the layer from reading latches STOP before its count is
    undone, and that is recorded.
  • An interrupt held while reporting an on_abort failure reaches the caller.
  • At its deadline, the child that runs the real-SIGINT checks gets SIGTERM, then SIGKILL ten seconds later.

Local checks on the final code (Julia 1.13):

  • Full suite: 5798 passed, plus the same 3 known broken tests as main.
  • Agent and contract tests: 1468 at --threads=1,0, 1485 at 2,1 and 1485 at 4,1, the 15 child SIGINT checks
    among them.
  • Docs build: passes, with all 559 docstrings on a built page.
  • Mutation sweep: one full pass on the final code, removing each safety check in turn (102 mutations in a scratch
    copy, among them each check this round adds). 101 fail at least one test. The 102nd is the equivalent mutation
    reported before. Every testset the table names is in the current tests.

…records

Two abort paths broke the layer's promises. An abort that request_abort!
had acknowledged could be dropped when a forced interrupt (Julia's repeated
Ctrl-C) cut the command's admission short: the release freed the slot,
recorded the abort as one STOP refused although STOP was clear, and the next
command ran with no cleanup. And while the layer's :abort waited for its
on_abort (an actuator stop, say), an unserialized movement could start, and
the stop then reached it. Now:

- A claim never admitted is closed to aborts and its mark read while the
  slot is still held. An abort that reached it is recorded as STOP refused
  only when STOP is latched; otherwise the release latches STOP and records
  that the abort reached a command whose admission was cut short.
- An unserialized command whose plan moves is refused, with the new
  AbortInFlight, while an on_abort is outstanding. Reads, the :abort and the
  grant turning off still run. A failing on_abort latches STOP before its
  exception or return value is formatted.
- The layer recognizes its own Aborted itself, with interrupts still
  deferred, so a Ctrl-C cannot turn a known abort into a failure record.
- Interrupts are now deferred by a helper that ends the deferral in a
  finally. Base.disable_sigint leaves an exceptional exit to the handler
  that catches it, which delivers a pending interrupt as it is entered,
  past the caller's catch.
- An interrupt held while the release reports reaches the caller on every
  path, a refused claim's included.
- make_safe! must return nothing. Any other return (a pending Task) latches
  STOP and is recorded, never as "made safe".
- An interrupt delivered as the :abort reopens interrupts, before on_abort
  is entered, no longer marks on_abort outstanding. It is recorded as the
  interrupt, and STOP stays clear.
- A STOP the release latches for an end cut short is logged :stop_latched
  unless make_safe! was called and did not return.
- The forced-interrupt rule is stated once, in a "Forced interrupts"
  section of the API page, and the docstrings point to it. The docs show an
  on_abort that ends with nothing, since a driver call may return a status.
  _make_safe!'s unused Bool return is gone.

Tests cover each change. The real-SIGINT child process adds a check for an
Aborted interrupted in make_safe!, and its check of an :abort interrupted at
its arrival now expects STOP clear and a record of the interrupt.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kalidke

kalidke commented Nov 29, 2026

Copy link
Copy Markdown
Member Author

Round 7 fixes, on top of a769616. They close two abort paths.

  • An abort that request_abort! acknowledged, on a claim whose admission a forced interrupt cut short, now latches
    STOP and is recorded. Before, it was recorded as "STOP refused" with STOP clear. "STOP refused" now appears only
    when STOP refused.
  • While an on_abort is outstanding, an unserialized command whose plan moves is refused with the new
    AbortInFlight, so the abort's action cannot stop a later movement. Reads, the :abort and the grant turning off
    still run.

Smaller fixes, from both reviews:

  • The failing on_abort's STOP. It now has one latch, in the finally, before anything formats the failure.
  • Aborted. The layer recognizes it itself, with interrupts still deferred.
  • make_safe!'s return. It must return nothing; a pending Task latches STOP and is recorded.
  • Interrupts held while reporting. One held by the release's report reaches the caller on every path.
  • The :abort arrival record. An interrupt delivered as the :abort reopens interrupts is recorded as itself,
    with STOP clear.
  • Event kinds. The release logs :stop_latched unless make_safe! was called and did not return.

One more change, beyond the brief. Interrupts are now deferred by a helper that ends the deferral in a finally.
Base.disable_sigint leaves an exceptional exit to the handler that catches it. That handler delivers a pending
interrupt as it is entered, past the caller's catch. A new child check found this: an Aborted interrupted in
make_safe!.

The forced-interrupt rule is stated once, in the API page's "Forced interrupts" section.

Local checks on the final code (Julia 1.13):

  • Full suite: 5824 passed, plus the same 3 known broken tests as main.
  • Agent and contract tests: 1494 at --threads=1,0, 1511 at 2,1 and 1511 at 4,1, with the 17 child SIGINT
    checks among them.
  • Docs build: passes, with all 560 docstrings on a built page.
  • Mutation sweep: one full pass on the final code, 116 mutations in a scratch copy, among them each check this
    round adds. 115 fail at least one test; the 116th is the equivalent mutation reported before. Every testset the
    table names is in the current tests.
  • The reviewer's statement-boundary sweep: an interrupt before each of 112 statements of the layer's six
    end-and-abort functions, singly and in pairs, in ten scenarios. It finds no violation.

…ecords

An abort's on_abort (a stage stop, say) may act on a whole actuator. The
layer already refused a movement admitted while an on_abort was
outstanding. But a movement admitted just before could yield inside its
execute, issue its move while the on_abort ran, be stopped by it, and still
end with a success record. Now:

- Every unserialized command whose plan moves, and whose run overlaps an
  on_abort, is treated as reached by it. Whatever its execute returned,
  run_command throws Aborted for it and records :command_aborted, saying an
  abort's on_abort ran while it moved. One whose execute throws keeps its
  failure record, with the overlap noted. Reads, the grant and the layer's
  :abort are unaffected.
- The mechanism is a count of on_abort calls begun, kept in the
  CommandCore. A movement reads it at admission, before its slot check, and
  compares it at its end, together with the slot's outstanding count. The
  :abort counts its call in the slot, then raises the count, both before
  on_abort is entered. A comment states the order.
- on_abort's outstanding mark is now the last step before it is entered.
  The call is prepared first, and on_abort is called directly rather than
  through the command's execute. An interrupt in the window left, or inside
  on_abort, is recorded as interrupted as it was called or while it ran,
  never as a throw. It latches STOP, since the layer cannot tell whether
  the action is done.
- A result execute returned that the layer classified as aborted keeps
  that classification. A later abnormal end (an interrupt in
  after_execute) is recorded :command_aborted, not :command_failed.
- on_abort's throw is tracked apart from the value thrown. A
  throw(nothing) is a throw: STOP latched, recorded, and an interrupt held
  while reporting it reaches the caller. The two rethrows of a held
  interrupt in the :abort are now one.
- The API page's "Forced interrupts" section says to restart Julia after a
  forced interrupt. In plain Julia 1.13, with no package loaded, a later
  Ctrl-C ends the process with a segmentation fault.
- Comments say that _is_abort runs only inside a deferral, and which Base
  internals _deferred relies on.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kalidke

kalidke commented Nov 29, 2026

Copy link
Copy Markdown
Member Author

Round 8 fixes, on top of 60a2dc6.

The blocking case. An abort's on_abort may act on a whole actuator. So an unserialized movement whose run
overlaps one is now treated as reached by it, in either order, the order Codex found included: a movement admitted
before the on_abort began, which yields and moves while it runs.

  • Whatever such a movement's execute returns, run_command throws Aborted and records :command_aborted,
    saying an abort's on_abort ran while it moved.
  • One whose execute throws keeps its failure record, with the overlap noted.
  • Reads, the grant and the layer's :abort are unaffected.
  • The mechanism is a count of on_abort calls begun, kept in the CommandCore. A movement reads it at admission and
    compares it at its end. A comment states the order of the atomic steps.

The should-fix items.

  • on_abort's outstanding mark is the last step before it is entered. An interrupt there is recorded as
    "interrupted as it was called or while it ran", never as a throw.
  • A returned Aborted keeps its classification through a later abnormal end.
  • A throw(nothing) from on_abort counts as a throw. Its held interrupt reaches the caller, and the :abort now
    rethrows a held interrupt from one place.

Verification note. After a caught forced interrupt, a later Ctrl-C ends plain Julia 1.13 with a segmentation
fault, with no package loaded. It reproduced every time in a child process (6 of 6), and the process survives when no
later SIGINT comes. The "Forced interrupts" section now says to restart Julia after one. No Julia issue reports this
case; the section cites the open issue on asynchronous exceptions (JuliaLang/julia#52291).

Local checks on the final code (Julia 1.13):

  • Full suite: 5849 passed, plus the same 3 known broken tests as main.
  • Agent and contract tests: 1519 at --threads=1,0, 1536 at 2,1 and 1536 at 4,1.
  • Docs build: passes, with all 560 docstrings on a built page.
  • Mutation sweep: one full pass on the final code, 125 mutations in a scratch copy, among them each check this
    round adds. 124 fail at least one test; the 125th is the equivalent mutation reported before. Every testset the
    table names is in the current tests.
  • The reviewer's statement-boundary sweep (inject_r8.jl): an interrupt before each of 120 statements, singly and
    in pairs, in 13 scenarios. It finds no violation.
  • The reviewer's stress runs (stress_r8, r8b, r8c): at all three thread settings, no on_abort beside a
    later command and nothing bad. The final slot is free and STOP clear.
  • A further stress run: movements that yield inside execute. At each thread setting, between 834 and 903
    movements overlapped an on_abort and ended Aborted. None that saw an on_abort ended done.
  • inflight_r8.jl, the in-progress movement: its second step runs while the on_abort is in flight, and it now
    ends Aborted at all three thread settings.

One ordinary Ctrl-C after a movement's execute returned, while the layer
decided its overlap with an abort's on_abort or logged its end, could leave
no record of the movement at all. And a forced interrupt (a repeated
Ctrl-C) between the :abort's slot count and its raise of the count of
on_abort calls begun could erase a counted overlap. Now:

- An unserialized command runs with interrupts deferred except inside its
  execute, as a serialized command's end does. Its overlap decision and its
  one terminal record (:command_done, :command_aborted or :command_failed)
  always happen. An interrupt that arrived meanwhile, or that the record's
  report met, reaches the caller after the record.
- The :abort raises the count of on_abort calls begun again in its finally,
  before the uncount. Any movement whose run overlaps the slot count then
  sees a change; an interrupt between that raise and the uncount leaves the
  slot counted, which fails closed. The comment at _watches_on_abort states
  what carries the order: run_command runs only on the body thread, with no
  yield between the paired steps, and the slot clause is a second defense.
- The :abort records its success after the uncount, so a slow report no
  longer holds the slot. Failure records stay before it.
- Records say what the layer saw. A movement's overlap record says an
  abort's on_abort was counted (begun, or about to begin) while it moved.
  An interrupt before the layer read on_abort's return says it "was
  interrupted before the layer saw it return nothing", also when a second
  forced interrupt cut the catch short.
- With the default on_abort, which has no action, the :abort counts
  nothing, refuses no movement and treats none as reached.
- The Command docstring and the API page say that a movement's execute
  returns only when its motion has ended (or has been stopped), as the
  N-472 move does by waiting until every axis is on target. The overlap
  rule's window ends there.
- The unused call method of the :abort's execute is gone; the layer calls
  on_abort directly.

Tests: an interrupt at each of a movement's terminal records; a real SIGINT
in the child process as an overlapping movement decides its overlap; a
forced-interrupt stand-in between the :abort's slot count and its count
raise; a slow :abort success report; and the default on_abort beside a
movement.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kalidke

kalidke commented Nov 29, 2026

Copy link
Copy Markdown
Member Author

Round 9 fixes, on top of acfd77a.

The blocking case. An unserialized command now runs with interrupts deferred except inside its execute, as a
serialized command's end does. Its overlap decision and its one terminal record always happen, and an interrupt that
arrived meanwhile, or that the record's report met, reaches the caller after the record.

The should-fix items.

  • The count of on_abort calls begun. The :abort raises it again in its finally, before the uncount, so no
    forced interrupt erases a counted overlap.
  • The :abort's records. Its success is recorded after the uncount, so a slow report no longer holds the slot.
    Failure records stay before it.
  • What the records say. A movement's overlap record says the on_abort was counted (begun, or about to begin)
    while it moved. An interrupt before the layer read on_abort's return is recorded as "interrupted before the layer
    saw it return nothing", also after a second forced interrupt at the catch.

The rest.

  • The default on_abort. It has no action, so with it the :abort counts nothing and treats no movement as
    reached.
  • Movements. The Command docs say a movement's execute returns only when its motion has ended, as the N-472
    move does.
  • Comments. The comment at _watches_on_abort says what carries the order of the atomic steps.
  • Removed. The unused call method of the :abort's execute is gone.

Local checks on the final code (Julia 1.13):

  • Full suite: 5867 passed, plus the same 3 known broken tests as main.
  • Agent and contract tests: 1537 at --threads=1,0, 1554 at 2,1 and 1554 at 4,1, with the 19 child SIGINT
    checks among them. One of those is a real SIGINT as an overlapping movement decides its overlap: its
    :command_aborted record is kept, and the interrupt reaches the caller after it.
  • Docs build: passes, with all 560 docstrings on a built page.
  • Mutation sweep: one full pass on the final code, 130 mutations in a scratch copy, among them each check this
    round adds. 129 fail at least one test; the 130th is the equivalent mutation reported before. Every testset the
    table names is in the current tests.
  • The reviewer's statement-boundary sweep (inject_r9.jl): an interrupt before each of 145 statements, singly and
    in pairs, in 15 scenarios, including a movement paused across an :abort. It finds no violation.
  • Stress runs: the reviewer's three scripts, and the one whose movements yield inside execute, at all three
    thread settings. Nothing bad, the final slot free and STOP clear. Between 827 and 886 movements overlapped an
    on_abort and ended Aborted; none that saw one in flight ended done.
  • The reviewer's inflight_r9.jl: the movement ends Aborted. Its fire-and-forget asyncmove_r9.jl is still
    recorded done, which is the documented obligation of item 5 and has no code guard.

A reporter (the event log's tee, or the logger an @error reaches) that
called run_command from inside an unserialized command's deferred end
started a serialized command whose execute ran with the outer deferral
still in force. One Ctrl-C did not stop it: the light stayed on, it
recorded done, and the next command ran. Now:

- run_command refuses, before it does anything else, a call from inside
  the layer's own deferred steps (make_safe!, or a report of the event
  log), with the new ReentryRefused. A per-task flag in task-local storage
  marks those steps. _deferred sets it and _interruptible clears it for
  its body, so an execute (and the hooks that classify or follow it, and
  on_abort) may run another command. Julia keeps the interrupt deferral
  per task, and a task spawned from inside those steps inherits neither
  the deferral nor the flag. The docs say make_safe! and on_abort call the
  instrument's drivers directly and a reporter never runs a command.
- An unserialized command's final admission checks (STOP, the read of the
  on_abort change counter and the AbortInFlight slot check) now run inside
  its deferred region, in the same order, and its arguments are prepared
  inside the try that records a failure. An admitted command always leaves
  its record.
- on_aborts is now described as a change counter. The :abort changes it
  once, in its finally, before the uncount. Its first raise, before
  on_abort, was redundant and is gone. A movement's end reads the slot
  before the counter, so the argument holds on any thread. The comment at
  _watches_on_abort states which step covers which window.
- The movement docs give the same task qualification as the serialized
  section: a Ctrl-C reaches the task running then. They also say that a
  movement's execute checks the driver's status and throws when completion
  is unknown. The N-472 move returns FALSE when its on-target query fails
  while the motion may continue.

Tests: reentry from a reporter refused on the unserialized path, the
serialized path and the :abort, and from make_safe! (STOP latched); an
execute that runs another command, and a task spawned from a reporter,
unaffected; an error while arguments are prepared, recorded. Two
real-SIGINT checks in the child: a reporter's run_command for a confirmed
light-on, which is refused and the light never comes on, and a SIGINT at
an unserialized command's final admission checks, after which its record
is kept. Three tests that observed the slot by reentering from a reporter
or from make_safe! now read the state directly or act from another task.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kalidke

kalidke commented Nov 29, 2026

Copy link
Copy Markdown
Member Author

Round 10 fixes, on top of 3f23dbf.

The blocking case. run_command now refuses, before anything else, a call from inside the layer's own deferred
steps, with the new ReentryRefused. Those steps are make_safe! and a report of the event log (its tee, or a
logger an @error reaches). A command started there would run with the layer's deferral still in force, so one Ctrl-C
would not stop it.

  • The mechanism. A per-task flag in task-local storage marks the steps. _deferred sets it, and _interruptible
    clears it for an execute, the hooks and on_abort.
  • What a spawned task inherits. Julia keeps the interrupt deferral per task, so a task spawned from inside the
    steps inherits neither the deferral nor the flag.
  • What the docs say. make_safe! and on_abort call the instrument's drivers directly, and a reporter never runs a
    command.

The should-fix items.

  • Admission. An unserialized command's final admission checks now run inside its deferred region, and its
    arguments are prepared inside the try that records a failure. An admitted command always leaves its record.
  • Task delivery. The movement docs give the same qualification as the serialized ones: a Ctrl-C reaches the task
    running then.
  • The N-472 example. It is qualified: a movement checks the driver's status and throws when completion is unknown.
  • The counter. on_aborts is described as a change counter. It is now changed once, before the uncount; the first
    raise was redundant and is gone, which the reviewer's sweep, judged by the rule's letter, confirms. A movement's end
    reads the slot before the counter, and the comment at _watches_on_abort states which step covers which window.

Local checks on the final code (Julia 1.13):

  • Full suite: 5888 passed, plus the same 3 known broken tests as main.
  • Agent and contract tests: 1558 at --threads=1,0, 1575 at 2,1 and 1575 at 4,1, with the 22 child SIGINT
    checks among them. One is Codex's case with a real SIGINT: the reporter's run_command for a confirmed light-on is
    refused, and the light never comes on. Another is a SIGINT at an unserialized command's final admission checks,
    after which its record is kept.
  • Docs build: passes, with all 561 docstrings on a built page.
  • Mutation sweep: one full pass on the final code, 135 mutations in a scratch copy, among them each check this
    round adds. 134 fail at least one test; the 135th is the equivalent mutation reported before. Every testset the
    table names is in the current tests.
  • The reviewer's statement-boundary sweep (inject_r10.jl): an interrupt before each of 151 statements, singly and
    in pairs, in 16 scenarios, one judged by the overlap rule's letter. It finds no violation.
  • Stress runs: the reviewer's three scripts, and the one whose movements yield inside execute, at all three
    thread settings. Nothing bad, the final slot free and STOP clear. Between 891 and 976 movements overlapped an
    on_abort and ended Aborted; none that saw one in flight ended done.

…ts try

The layer's :abort made its final STOP check before it entered its
deferred region, so one ordinary Ctrl-C between the two could erase an
abort with no record: the command it was sent for ran on, unaborted.
The check now runs inside the region, as an unserialized command's
admission already does. An admitted :abort always takes its step and
records its arrival, and an interrupt that arrived meanwhile reaches the
caller after that record.

The per-task flag behind ReentryRefused is now set inside the try whose
finally restores it, so a forced interrupt (a repeated Ctrl-C) just
after the set no longer leaves the task marked. The two windows left,
inside that finally and in the restore that ends an interruptible step,
are the forced-interrupt limit, and the API page states them.

Docs:
- an interrupt can reach another task before a movement's record exists
  when formatting a failure, or a report, yields before the record is
  appended;
- ReentryRefused is enforced only inside the layer's deferred steps. A
  reporter of a refusal made before them (a confirmation required, say)
  is not checked by it, and the rule that a reporter never runs a
  command still holds for instrument authors;
- the comment at _watches_on_abort names the window the slot read also
  covers: a forced interrupt in the :abort's finally before the counter
  changes.

Tests, on simulated devices:
- the :abort's admission point lies inside its deferred region;
- a real SIGINT there, in the child process: the command's abort is
  armed and recorded, the interrupt comes after the records, and the
  command stops;
- a stand-in forced interrupt just after each of the flag's two sets
  leaves the task unmarked, and the steps around an execute still marked
  as they unwind.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kalidke

kalidke commented Nov 29, 2026

Copy link
Copy Markdown
Member Author

Round 11 fixes, on top of 4521157. Both round 11 reviews found nothing blocking; this commit takes their should-fix
items and notes.

The :abort's admission. The layer's :abort made its final STOP check before it entered its deferred region, so
one ordinary Ctrl-C between the two could erase the abort with no record. The check now runs inside the region, as an
unserialized command's admission already did in round 10. An admitted :abort always takes its step and records its
arrival, and the interrupt reaches the caller after that record.

The reentry flag. The per-task flag behind ReentryRefused is now set inside the try whose finally restores
it. A forced interrupt just after the set therefore no longer leaves the task marked. Two windows are left: one inside
that finally, and one in the restore that ends an interruptible step. Both are the forced-interrupt limit, and the
"Forced interrupts" section states them. The list owed by the next pull request adds both transitions to its committed
statement-boundary sweep.

Docs and comment.

  • Movement records. The movement text is qualified: when formatting a failure, or a report, yields before the
    record is appended, an interrupt can reach another task before the record exists.
  • Where ReentryRefused applies. The API page says the refusal is enforced only inside the layer's deferred
    steps. A reporter of a refusal made before them (STOP before a confirmation, a confirmation required or not
    matching) is not checked by it, and the rule that a reporter never runs a command holds there all the same.
  • The comment at _watches_on_abort. It now also names the window the slot read covers: a forced interrupt in
    the :abort's finally before the counter changes.

The N-472 move defect Codex noted is left for a separate pull request, as the brief says.

Local checks on the final code (Julia 1.13):

  • Full suite: 5895 passed, plus the same 3 known broken tests as main.
  • Agent and contract tests: 1565 at --threads=1,0, 1582 at 2,1 and 1582 at 4,1, with the 24 child SIGINT
    checks among them. The two new ones send a real SIGINT as the :abort passes its final admission check with a
    command held. The abort still arms that command's abort and records it, the interrupt arrives after its records,
    and the command stops.
  • Docs build: passes, with all 561 docstrings on a built page.
  • Mutation sweep: one full pass on the final code, 137 mutations in a scratch copy. Two are new this round: the
    :abort's admission check moved back before its region (3 tests fail), and the flag set before its try (2
    fail). 136 fail at least one test; the 137th is the equivalent mutation reported before. Every testset the table
    names is in the current tests.
  • The reviewer's statement-boundary sweep (inject_r11.jl): an interrupt before each of 164 statements, singly and
    in pairs, in 16 scenarios, one of them judged by the overlap rule's letter. It finds no violation. Runs that left
    the main task flagged fell from 1424 to 700: the window before the try is closed, and what remains lies inside
    the restoring finally.
  • Its four mutations of the overlap rule (inject_r11m.jl): the same pattern as the reviewer's round 11 run (this round adds
    statements, so the paired counts differ a little).
    • Removing the slot clause: 3 single and 69 paired violations, and 4 and 150 judged by the rule's letter.
    • Removing the counter clause: 13 and 101, and 27 and 412 by the letter.
    • Removing the raise: 13 and 101, and 27 and 412 by the letter.
    • The old read order: none, as before; it matters only to the argument for any thread.

… flag

The tests added for the :abort's admission and the reentry flag checked
the test point beside each operation, not the operation itself. Moving
only the :abort's final STOP read out of its deferred region, or only
the flag's set out of the try whose finally restores it, passed every
test. Two source-order checks now hold the real positions, as the tests
already do for the order of admission and of a command's end:
- the :abort's STOP read lies inside its deferred region, before the
  step that arms the abort;
- the flag's set lies inside that try, before its finally.

Docs and comments, no code change:
- an interrupt that arrives at the :abort's admission is delivered
  after its arrival record. When a report of the arrival yields, it can
  reach another task, and the :abort runs on: its on_abort may still
  start and run, and the caller gets its result. The unserialized
  command's comment gets the same qualification;
- a forced interrupt that leaves the reentry flag clear while the outer
  steps unwind matters only to code that also breaks its own rule and
  runs a command there. That is a reporter, or a make_safe! the
  unwinding reaches.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kalidke

kalidke commented Nov 30, 2026

Copy link
Copy Markdown
Member Author

Round 12 fixes, on top of 1b816b0. Both round 12 reviews found nothing blocking. This commit is two docs corrections
and two tests; no code line changes, only comments.

Tests tied to the real positions. The round 11 tests checked the test point beside each operation, not the
operation itself. Moving only the :abort's final STOP read out of its deferred region, or only the reentry flag's
set out of its try, passed every test. Two source-order checks now hold the real positions, like the existing checks
on the order of admission and of a command's end:

  • the :abort's STOP read lies inside its deferred region, before the step that arms the abort;
  • the flag's set lies inside the try whose finally restores it.

The :abort's interrupt. The API page and the comment on the implementation now guarantee the arrival record. When
a report of the arrival yields, the interrupt can reach another task. The :abort then runs on: its on_abort may
still start and run, and the caller gets its result. The comment on the unserialized path is qualified the same way.

The forced-interrupt wording. A flag left clear while the outer steps unwind matters only to code that also breaks
its own rule and runs a command there. Both cases are named: a reporter, or a make_safe! the unwinding reaches.

Local checks on the final code (Julia 1.13):

  • Full suite: 5897 passed, plus the same 3 known broken tests as main.

  • Agent and contract tests: 1567 at --threads=1,0, 1584 at 2,1 and 1584 at 4,1, with the 24 child SIGINT
    checks among them.

  • Docs build: passes, with all 561 docstrings on a built page.

  • Mutations (no code line changed, so no full pass), failed of 1584:

    Mutation What it moves Failed
    M140 the :abort's STOP check and its test point, out of the region 4
    M141 the flag's set and its test point, before the try 3
    M142 (new) only the :abort's STOP check; the test point stays in the region 1
    M143 (new) only the flag's set; the test point stays in the try 1

    M142 and M143 are the two defects the round 12 review restored, and each now fails its source-order check.

Docs and comments, no code change. The API page gains a section, "Where
an interrupt lands", that states the rule once. Wherever the layer's
own steps call code that may yield (the event log's tee, a logger, an
exception's showerror, any report), an interrupt held there may be
delivered in another task, before the record that step writes exists.
The layer guarantees the cleanup and the record, not which task receives
the interrupt or when it arrives relative to a record.

Three reviews in a row had each found one more place this happens, and
each fix named only that place. The passages that named those places
(the :abort's guarantee, the movement text, the forced-interrupt
sentence about code that breaks its rule and runs a command) now give
examples and refer to the section. The run_command docstring and the
comments on the serialized, unserialized and :abort paths no longer
promise delivery after the record. The rule that code the layer calls
never runs a command now names an exception's showerror beside the
reporters.

The two source-order checks added for the :abort's admission and the
reentry flag matched source text. A harmless edit (a renamed local, a
trailing comment) broke them, and two real defects passed them:
interrupts reopened just around the STOP read, and an earlier try that
holds the flag's set outside the restoring one. They now check the
parsed code, matching only function names and the flag's key:
- the :abort's STOP check sits in the body of the function passed to
  _deferred, inside no call that reopens interrupts;
- every assignment to the flag's key other than the restore sits in the
  protected block of the try whose finally holds the restore, and in no
  other try.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kalidke

kalidke commented Nov 30, 2026

Copy link
Copy Markdown
Member Author

Round 13 fixes, on top of ccf00dd. Both round 13 reviews found nothing blocking. This commit changes docs, comments
and two tests; no code line changes.

One rule for where an interrupt lands. The API page has a new section, "Where an interrupt lands", that states the
rule once. Wherever the layer's own steps call code that may yield (the event log's tee, a logger, an exception's
showerror, any report), an interrupt held there may be delivered in another task, before the record that step
writes exists. The layer guarantees the cleanup and the record, not which task receives the interrupt or when it
arrives relative to a record.

The passages that named such places now give examples and refer to the section:

  • the :abort's guarantee: a yielding report of its arrival or of its end;
  • the movement text;
  • the forced-interrupt sentence about code that breaks its rule and runs a command: a reporter, a make_safe! the
    unwinding reaches, or an exception's showerror.

The run_command docstring and the comments on the serialized, unserialized and :abort paths no longer promise
delivery after the record. The rule that such code never runs a command now names an exception's showerror beside
the reporters.

Structural checks instead of text checks. The round 12 source-order checks matched source text. A renamed local or
a trailing comment broke them, and two real defects passed them. They now read the parsed code, matching only function
names and the flag's key:

  • the :abort's STOP check sits in the body of the function passed to _deferred, inside no call that reopens
    interrupts;
  • every assignment to the flag's key other than the restore sits in the protected block of the try whose finally
    holds the restore, and in no other try.

Local checks on the final code (Julia 1.13):

  • Full suite: 5897 passed, plus the same 3 known broken tests as main.

  • Agent and contract tests: 1567 at --threads=1,0, 1584 at 2,1 and 1584 at 4,1, with the 24 child SIGINT
    checks among them.

  • Docs build: passes, with all 561 docstrings on a built page.

  • Mutations (no code line changed, so no full pass), failed of 1584:

    Mutation What it does Failed
    M142 defect: the :abort's STOP check alone moved before its region, the test point left inside 1
    M143 defect: the flag's set alone moved before the try, the test point left inside 1
    M144 defect: interrupts reopened just around the :abort's STOP read 1
    M145 defect: an earlier try ... catch holds the flag's set, outside the restoring try 1
    M146 harmless: the locals step and was renamed 0
    M147 harmless: a trailing comment after the flag's try 0

    Each defect fails its structural check, and both harmless edits pass every test.

kalidke and others added 2 commits November 29, 2026 20:01
… audited

Two regression tests guard the :abort's final STOP read (it must run with
interrupts deferred) and the reentry flag's write (a finally sure to
restore it must cover it). Their test points sat beside each operation,
so moving the operation alone left them behind. The structural checks
that replaced them could be fooled, and they failed on correct code. Each
operation is now a small function that holds its test point:
- _admit_abort makes the :abort's final admission check, then hits the
  point;
- _mark_layer_step! writes the flag, then hits the point.

The existing behavioral checks at those points now go wherever the
operation goes: a parent test and two real-SIGINT child checks at the
read, and a forced stand-in just after the write. The structural checks
and their helpers are deleted. Seven defects fail the behavioral checks:
- either operation moved on its own;
- interrupts reopened around the read through _interruptible, through a
  closure defined in the region, or by raw sigatomic calls;
- an earlier try ... catch holding the write;
- a restore made conditional on a flag set after the write.
Four correct rewrites pass.

Every statement in the API page, the docstrings, the comments,
CHANGELOG.md and the pull request text about where or when an interrupt
arrives, or about a result that stands, now agrees with "Where an
interrupt lands":
- only an interrupt thrown in the command's own task while it runs,
  which the layer catches and saves, is sure to reach the caller. One
  delivered in the layer's steps may reach another task, and the caller
  may then return normally;
- a result stands only once the end has decided its cleanup. An
  interrupt between the claim and execute takes effect as interrupts
  reopen for execute, which then never runs, and the command fails, with
  its cleanup;
- the release step is distinct from the slot becoming free: the slot
  stays held while an on_abort for the command still runs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… at debug level

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kalidke

kalidke commented Nov 30, 2026

Copy link
Copy Markdown
Member Author

Round 14 fixes, on top of 853a6fe. Both round 14 reviews found nothing blocking. This commit closes the two
remaining classes whole: what two regression tests guard, and what the text says about interrupt delivery.

Test points inside the guarded operations. Each operation is now a small function that holds its own test point:

  • _admit_abort makes the :abort's final admission check, then hits :abort_admitted;
  • _mark_layer_step! writes the reentry flag, then hits :flag_set.

The existing behavioral checks at those points (a parent test and two real-SIGINT child checks at the read, a forced
stand-in just after the write) now go wherever the operation goes. The structural checks and their helpers are
deleted.

One audit of every statement about delivery and results. I checked the API page, the docstrings, the comments in
src/agent/, CHANGELOG.md and the pull request text against "Where an interrupt lands", and changed each statement
that disagreed:

  • Who gets the interrupt. Only an interrupt thrown in the command's own task while it runs, which the layer
    catches and saves, is sure to reach the caller. One delivered in the layer's steps may reach another task, and the
    caller may then return normally.
  • When the result stands. A result stands only once the end has decided its cleanup. An interrupt between the
    claim and execute takes effect as interrupts reopen for execute, which then never runs, and the command fails,
    with its cleanup.
  • Release and a free slot. The release step is distinct from the slot becoming free: the slot stays held while an
    on_abort for the command still runs.

Main merged in. After this commit, main is merged into the branch (f041459), bringing in pull request 98: the
simulated stages now write their status lines to the debug log instead of printing them. The merge needed no hand
edits.

Local checks (Julia 1.13):

  • Full suite on the merged head, f041459: 5976 passed, plus the same 3 known broken tests as main. The 81 more
    than round 14's commit are pull request 98's checks that the simulated stages print nothing.

  • Full suite on the round 14 commit, 63bc206: 5895 passed, plus the same 3 known broken tests.

  • Agent and contract tests: 1565 at --threads=1,0, 1582 at 2,1 and 1582 at 4,1, with the 24 child SIGINT
    checks among them. The two structural checks are gone.

  • Docs build: passes, with all 561 docstrings on a built page.

  • The round's mutations, failed of 1582:

    Mutation What it does Failed
    M142 defect: the :abort's admission call moved before its region 3
    M143 defect: the flag's write moved before the try 2
    M144 defect: _interruptible around the admission check 3
    M145 defect: an earlier try ... catch holds the write 2
    M148 defect: the check in a closure defined in the region, called through _interruptible 3
    M149 defect: raw sigatomic_end/sigatomic_begin around the check 2
    M151 defect: the restore conditional on a flag set after the write 2
    M146 correct: locals step and was renamed 0
    M147 correct: a comment after the flag's try 0
    M150 correct: the check's closure defined before the region, called inside it 0
    M152 correct: the write spelled setindex! 0
  • Full mutation pass: the calls to the two new functions changed code lines, so I ran one on the final code. It has
    146 mutations: the earlier table, plus this round's rows (round 11's M140 and M141 are now the same as M142 and
    M143, so they are dropped). Of the 142 that must fail, 141 do; the other is the equivalent mutation reported
    before. The four correct rewrites pass. Every testset the table names is in the current tests.

…antees

The regression test for the :abort's final admission check put its
interrupt after the whole check. Interrupts reopened around the check
inside its helper, or only around the latch read, therefore passed every
test, although one Ctrl-C there erases the abort. A test point now sits
in _check_stopped immediately before the latch is read. The child
process sends a real SIGINT there on the :abort's final check, so the
signal is pending before the read. Correct code defers it until the
abort's region ends, so a reopening anywhere from the read to the end
delivers it early and fails the check. The parent test at the old point
stays as the fallback where the child process cannot run.

The flag test's forced interrupt now selects the write that clears the
flag, not the second write, so a correct nested deferred scope passes.
A restore made conditional on something set between the write and the
test point, or an extra write of the flag outside _mark_layer_step!, is
left to the statement-boundary sweep the next pull request commits; the
test comment says so.

The AbortInFlight message no longer claims the abort's on_abort "has
not returned". The refusal holds while the abort is counted, which
includes its reports.

The API page, docstrings, comments, CHANGELOG and pull request text now
state what is guaranteed and point to "Where an interrupt lands" for
delivery:
- an interrupt still pending as interrupts reopen for execute takes
  effect there, and execute never runs; one delivered earlier, at a
  yield, may reach another task while the command runs on;
- only an interrupt that escapes into the layer is caught, saved and
  thrown to the caller;
- once the end has decided its cleanup, no new cleanup is made, though
  an interrupt during classification still records the command as
  failed;
- the slot stays held while the layer's :abort for the command is
  counted, from before its arrival report until after its on_abort and
  its reports end.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kalidke

kalidke commented Nov 30, 2026

Copy link
Copy Markdown
Member Author

Round 15 fixes, on top of f041459 (63bc206 plus the merge of main). Both round 15 reviews found nothing blocking and
no code defect. This commit fixes the one regression test that did not guard the read it names, and cuts the
sentences that promised more than the code guarantees.

The :abort's STOP read, guarded at the read.

  • The new point. A test point sits in _check_stopped immediately before the STOP latch is read.
  • The child check. It sends a real SIGINT at that point on the :abort's final check, its second STOP check, so
    the signal is pending before the read.
  • What correct code does. It defers the signal until the abort's region ends. A reopening anywhere from the read
    to the region's end delivers it early, with no record, and the check fails.
  • The parent test. The parent test at :abort_admitted stays, and its comment now says it is the fallback where
    the child process is skipped.

The flag test.

  • Which write. The forced interrupt now selects the first write that clears the flag, not the second write, so a
    correct nested deferred scope passes.
  • The limit. One test point after the write cannot see a restore made conditional on something set between the
    write and the point, or an extra write of the flag outside _mark_layer_step!. The test comment and the owed list
    say the next pull request's committed statement-boundary sweep closes that class.
  • The comment at the write. It now says every write of the flag goes through _mark_layer_step! inside the
    restoring try.

Promises cut to guarantees. The API page, docstrings, comments, CHANGELOG and pull request text now state only
what is guaranteed, and point to "Where an interrupt lands" for delivery:

  • Before execute. An interrupt still pending as interrupts reopen for execute takes effect there, and execute
    never runs. One delivered earlier, at a yield, may reach another task while the command runs on.
  • To the caller. Only an interrupt that escapes into the layer is caught, saved and thrown to the caller.
    Instrument code that catches its own interrupt decides what follows.
  • After the cleanup decision. No new cleanup is made. An interrupt during classification still records the command
    as failed.
  • The slot. It stays held while the layer's :abort for the command is counted, from before its arrival report
    until after its on_abort and its reports end.
  • The AbortInFlight message. It no longer says the on_abort "has not returned"; it now says the abort has not
    finished.

Local checks on the final code (Julia 1.13):

  • Full suite: 5976 passed, plus the same 3 known broken tests as main, which matches the merge's count.

  • Agent and contract tests: 1565 at --threads=1,0, 1582 at 2,1 and 1582 at 4,1, with the 24 child SIGINT checks among them.

  • Docs build: passes, with all 561 docstrings on a built page.

  • The brief's mutations, failed of 1582:

    Mutation Expected What it does Failed
    M142 fail (Claude A) the :abort's admission call moved before its deferred region 3
    M143 fail (Claude B) the flag's write moved before the try 2
    M144 fail (Claude A2) interrupts reopened around the :abort's admission check 3
    M145 fail (Claude B2) an earlier try ... catch holds the flag's write, outside the restoring try 2
    M146 pass the locals step and was renamed 0
    M147 pass a trailing comment after the flag's try 0
    M148 fail (Codex CX1) the admission check in a closure defined inside the region, called through _interruptible 3
    M149 fail (Claude A4) raw sigatomic_end and sigatomic_begin around the :abort's admission check 2
    M150 pass (Codex CXok1) the admission check in a closure defined before the region, called inside it 0
    M151 fail (Codex CX2) the restore made conditional on a boolean set after the flag's write 2
    M152 pass (Codex CXok2) the flag's write spelled setindex! 0
    M153 fail (Claude A5) interrupts reopened around the check inside _admit_abort, its test point left after it 2
    M154 fail (Codex round 15) interrupts reopened only around the latch read, inside the layer's steps 2
    M155 fail (Claude A3) reenable_sigint around the admission call 2
    M156 fail (Claude A6) the final check moved before the region, the helper no longer called 3
    M157 fail (Claude B4) the flag's write moved after f() 12
    M158 pass (Codex) a nested deferred scope around the unserialized command's already-deferred STOP check 0
    M159 pass (Claude Aok2) a named region function passed to _deferred 0
    M160 pass (Claude Aok3) the helper inlined into the region, its test point kept after the check 0
    M161 pass (Claude CXok3) _mark_layer_step! inlined into the try 0
    M162 pass (Claude Bok3) comments only, on the try and the restore 0
    M163 pass (Claude Bok4) restored by a catch-and-rethrow plus the normal path, no finally 0
    M164 pass (limit) (Codex) the restore conditional on a boolean set between the write and the test point 0
    M165 pass (limit) (Claude B5) an extra write of the flag before the try, the guarded write kept 0
  • Full mutation pass: the AbortInFlight message is a changed code line, so I ran one on the final code: 159
    mutations (the round 14 table, every row still finding its anchor, plus the rows above).

    • Of the 147 that must fail, 146 do; the other is the equivalent mutation reported before.
    • All 12 expected to pass do, the two named limits among them.
    • M109's first run did not load the package, through a precompile-cache race between the parallel jobs; run again
      alone, 6 tests fail on it.
    • Every testset the table names is in the current tests.

…fined once

The child-process checks for the :abort now cover both on_abort paths
and look past the terminal report:
- the SIGINT before the final STOP read is chosen by the read's role,
  the first STOP read inside the layer's steps, not by its position;
- a second check sends it with an on_abort of the instrument's;
- a third sends it after that on_abort returned;
- a writable tee must receive the abort's terminal record before the
  interrupt arrives.
Edits that reopen interrupts only when the instrument registered an
on_abort, around the uncount, around reading on_abort's return, or for
the success report's tee write now fail them. Code moved ahead of its
test point, such as the latch read cached in a local before the point,
is outside what any one test point can see; the test comment names this
limit.

This corrects two claims in the previous commit's message. The STOP-read
check did not catch every reopening up to the region's end: it covered
only the default on_abort, and nothing looked after the terminal report.
The abort's count does not last until its reports end: it is undone
before the success report.

Docs and comments, no code change:
- the count's span is defined once, on the API page: the slot is held
  from before the :abort's arrival report until its on_abort has
  returned and any failure is recorded, and it is free during the
  success report. The other places point there. The comment that said a
  slow report cannot hold the slot now says this holds for the success
  report only;
- a yield is a point where another task may receive an interrupt, not a
  point where it is delivered;
- an interrupt that escapes into the layer reaches the caller: saved and
  thrown after the release step for a serialized command, rethrown as it
  is for an unserialized one. Nothing promises that an interrupt in
  execute ends the command abnormally;
- an overlapped movement is recorded :command_aborted, and its caller
  gets Aborted, or a Ctrl-C that arrived while its end ran;
- the terminal event's kind comes from the instrument's classification;
  only an interrupt that escapes the classification of an exception
  records the command as failed;
- before the slot is released, cleanup has succeeded or STOP is latched.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kalidke

kalidke commented Nov 30, 2026

Copy link
Copy Markdown
Member Author

Round 16 fixes, on top of eafd9c9. Both round 16 reviews found nothing blocking and no code defect. This commit
changes tests, docs and comments; no code line changes.

The :abort's child checks.

  • Which read. The SIGINT before the final STOP read is now chosen by the read's role, the first STOP read inside
    the layer's steps, not by position. A correct rewrite that skips the pre-confirmation check, or splits it into a
    helper, passes.
  • Both on_abort paths. One check sends the SIGINT with the default on_abort, one with an instrument's
    on_abort. A third sends it after the instrument's on_abort returned.
  • After the terminal report. Each check gives the log a writable tee and requires the abort's terminal record in
    it before the interrupt arrives.
  • What fails now. Edits that reopen interrupts only when the instrument registered an on_abort, around the
    uncount, around reading on_abort's return, or for the success report's tee write.
  • The named limit. Code moved ahead of its test point, such as the latch read cached in a local before
    :stop_read, is outside what any one test point can see.

The count, defined once. The API page now defines the span once. The slot is held from before the :abort's
arrival report until its on_abort has returned and any failure is recorded; the count is undone before the success
report. The docstrings, the other API passage, CHANGELOG and the pull request text point there. The comment that said
a slow report cannot hold the slot now says this holds for the success report only.

Promises cut to the guarantees.

  • CHANGELOG. Before the slot is released, cleanup has succeeded or STOP is latched.
  • Yields. A yield is a point where another task may receive an interrupt, not a point where it is delivered.
  • The caller. An interrupt that escapes into the layer is thrown to the caller: saved and thrown after the
    release step for a serialized command, rethrown as it is for an unserialized one. Nothing promises that an
    interrupt in execute ends the command abnormally.
  • Overlapped movements. One is recorded :command_aborted, and its caller gets Aborted, or a Ctrl-C that
    arrived while its end ran.
  • Classification. The terminal event's kind comes from the instrument's classification. Only an interrupt that
    escapes the classification of an exception records the command as failed.
  • The flag. Every entry write goes through _mark_layer_step!.
  • eafd9c9's message. This commit's message corrects two of its claims: that the STOP-read check caught every
    reopening up to the region's end, and that the count lasts until the reports end.

Local checks on the final code (Julia 1.13):

  • Full suite: 5980 passed, plus the same 3 known broken tests as main.

  • Agent and contract tests: 1569 at --threads=1,0, 1586 at 2,1 and 1586 at 4,1, with the 28 child SIGINT checks among them (4 more).

  • Docs build: passes, with all 561 docstrings on a built page.

  • Mutations (no code line changed, so no full pass; every row of the round 15 full table still finds its anchor):

    Mutation Expected What it does Failed
    M142 fail the :abort's admission call moved before its deferred region 3 of 1586
    M143 fail the flag's write moved before the try 2 of 1586
    M144 fail interrupts reopened around the :abort's admission check 3 of 1586
    M145 fail an earlier try ... catch holds the flag's write, outside the restoring try 2 of 1586
    M146 pass the locals step and was renamed 0 of 1586
    M147 pass a trailing comment after the flag's try 0 of 1586
    M148 fail the admission check in a closure defined inside the region, called through _interruptible 3 of 1586
    M149 fail raw sigatomic_end and sigatomic_begin around the :abort's admission check 4 of 1586
    M150 pass the admission check in a closure defined before the region, called inside it 0 of 1586
    M151 fail the restore made conditional on a boolean set after the flag's write 2 of 1586
    M152 pass the flag's write spelled setindex! 0 of 1586
    M153 fail (Claude A5) interrupts reopened around the check inside _admit_abort, its test point left after it 4 of 1586
    M154 fail (Codex round 15) interrupts reopened only around the latch read, inside the layer's steps 4 of 1586
    M155 fail (Claude A3) reenable_sigint around the admission call 4 of 1586
    M156 fail (Claude A6) the final check moved before the region, the helper no longer called 3 of 1586
    M157 fail (Claude B4) the flag's write moved after f() 14 of 1586
    M158 pass (Codex) a nested deferred scope around the unserialized command's already-deferred STOP check 0 of 1586
    M159 pass (Claude Aok2) a named region function passed to _deferred 0 of 1586
    M160 pass (Claude Aok3) the helper inlined into the region, its test point kept after the check 0 of 1586
    M161 pass (Claude CXok3) _mark_layer_step! inlined into the try 0 of 1586
    M162 pass (Claude Bok3) comments only, on the try and the restore 0 of 1586
    M163 pass (Claude Bok4) restored by a catch-and-rethrow plus the normal path, no finally 0 of 1586
    M164 pass (limit) (Codex) the restore conditional on a boolean set between the write and the test point 0 of 1586
    M165 pass (limit) (Claude B5) an extra write of the flag before the try, the guarded write kept 0 of 1586
    M166 fail (Claude C1) interrupts reopened around the counter's change and the uncount 2 of 1586
    M167 fail (Claude C2) interrupts reopened around reading on_abort's return 2 of 1586
    M168 fail (Codex round 16) admission reopened only when the instrument registered its own on_abort 2 of 1586
    M169 fail (Codex round 16) the success report reopened after its in-memory append, before the tee write 6 of 1575
    M170 pass (Claude Aok4) the :abort's pre-confirmation STOP check skipped (it passes STOP; its plan never emits) 0 of 1586
    M171 pass (Codex round 16) the pre-confirmation check split into its own helper, with no test point 0 of 1586
    M172 pass (limit) (Codex round 16) the latch read cached in a local, interrupts open, ahead of :stop_read 0 of 1586

    Sixteen defects fail, twelve correct rewrites pass, and the three named limits pass as expected. M169 also breaks
    other tests, but its two tee checks are among the failures.

Docs, docstrings, comments and test comments only. With comments and
docstrings removed, the code is the same as in the previous commit.

What a caller reads now matches what the code does:
- Abnormal end. The instrument is made safe, or STOP is latched when
  make_safe! fails. The module docstring, the API page's trust-boundary
  summary and its account of an abort reaching a command no longer
  promise successful cleanup alone.
- The slot. Undoing an abort's count is one condition of the slot
  becoming free; the command must also have ended. The _Run docstring
  says the slot is freed only once both have finished.
- While an abort is counted, STOP is still checked first. With STOP
  latched, a movement is refused Stopped whatever the count, and reads
  pass. The registration docstring now lists reads among what runs
  under STOP.
- on_abort. The signature no longer shows sys -> nothing as a default.
  Leaving the keyword out selects no extra action and no count.
  Supplying any on_abort, even one that does nothing, selects the
  counted path, so a movement it overlaps is treated as reached by it.
- The record. One terminal event is recorded per admitted execution. A
  dry run or an unknown command records nothing, and a refusal records
  :command_refused. An overlapped movement is recorded :command_aborted,
  or :command_failed with the overlap noted when its execute throws.
  The Aborted docstring says what the unserialized path does with an
  Aborted: it is not classified, it is recorded :command_failed when
  thrown and :command_done when returned, and no make_safe! runs.
- Classification. The layer classifies its own Aborted, and the
  instrument's is_aborted classifies anything else.
- Re-registration. A re-declared command's old confirmations bind
  nothing once a bound field changes; re-registering with the same bound
  fields keeps them valid.

This corrects two claims in the previous commit's message:
- The slot is not free during an abort's success report unless the
  command has also ended.
- The child checks do not cover both on_abort paths whole. They run the
  default on_abort and an instrument's that returns nothing. The failure
  branch of an instrument's on_abort is not run with a pending signal.

The test comments and the pull request text now say the same. The list
of work owed by the next pull request gains that fourth case, a stricter
tee check, a selector that cannot pick the preliminary STOP read,
wording that tells an interrupt's first delivery from its delivery to
the caller, and the three named limits.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kalidke

kalidke commented Nov 30, 2026

Copy link
Copy Markdown
Member Author

Round 17 fixes, on top of efc9ea7: text only. Both round 17 reviews found nothing blocking. This commit corrects the
statements a caller could be misled by in ordinary use, narrows two coverage claims, and extends the list of work
owed by the next pull request.

What a caller reads now matches the code.

  • Abnormal end. The instrument is made safe, or STOP is latched when make_safe! fails. This now appears in the
    module docstring, the API page's trust-boundary summary, and its account of an abort reaching a command.
  • The slot. Undoing an abort's count is one condition of the slot becoming free; the command must also have
    ended. The _Run docstring now says the slot is freed only once both have finished. The pull request text points
    to the count's one definition instead of restating it.
  • STOP while an abort is counted. STOP is checked first: with it latched, a movement is refused Stopped
    whatever the count, and reads pass. The count paragraph says so, and the registration docstring lists reads among
    what runs under STOP.
  • on_abort. The signature shows the keyword as optional, with no default shown. Leaving it out means no count;
    supplying any on_abort, even one that does nothing, selects the counted path.
  • The record. One terminal event per admitted execution. A dry run or an unknown command records nothing, and a
    refusal records :command_refused.
  • The overlap entry. The CHANGELOG now gives :command_aborted, or :command_failed with the overlap noted
    when execute throws.
  • Aborted. Its docstring says what the unserialized path does with one: it is not classified, it is recorded
    :command_failed when thrown and :command_done when returned, and no make_safe! runs.
  • Classification. The layer classifies its own Aborted, and the instrument's is_aborted classifies anything
    else.
  • Re-registration. Old confirmations bind nothing once a bound field changes; the same bound fields keep them
    valid.

Coverage claims. The test comments and the pull request text now name the cases the child checks run: the default
on_abort, and an instrument's that returns nothing. The failure branch of an instrument's on_abort is not run
with a pending signal.

The owed list gains these items:

  • that fourth child case;
  • a tee check that reads the whole line through a separate reader while the writer is open;
  • a STOP-read selector that cannot pick the preliminary read when that read is in a deferred region of its own;
  • wording that tells an interrupt's first delivery from its delivery to the caller;
  • the three named limits (M164, M165, M172).

Local checks on the final code (Julia 1.13):

  • Full suite: 5980 passed, plus the same 3 known broken tests as main.
  • Agent and contract tests: 1569 at --threads=1,0, 1586 at 2,1 and 1586 at 4,1, with the 28 child SIGINT
    checks among them.
  • Docs build: passes, with all 561 docstrings on a built page.
  • The code is unchanged. With docstrings and comments removed, every changed Julia file (src/agent/Agent.jl,
    src/agent/commands.jl, test/agent_commands.jl, test/agent_sigint_child.jl) is identical to efc9ea7, so no
    mutation pass was run.

Docs, docstrings and comments only. With comments and docstrings
removed, the code is the same as in the previous commit.

- Cleanup on an abnormal end applies to serialized commands: the
  instrument is made safe, or STOP is latched when make_safe! fails. An
  unserialized command has no cleanup. Corrected in the module docstring
  and the API page's trust-boundary summary.
- The slot is nothing only when no serialized command runs and no
  counted :abort for an ended one is still outstanding (_Run docstring).
- Under STOP only the :abort, the grant turning off and unserialized
  reads run; every serialized command is refused Stopped. The admission
  checks run in order: STOP, then confirmation, then the count. So
  AbortInFlight refuses a movement that passed the earlier checks, while
  a latched STOP refuses it Stopped first.
- What a call that does not run records. A refusal by an admission
  rule records :command_refused: STOP or the emit rule, confirmation,
  busy, or AbortInFlight. A dry run records nothing, and so does a call
  that fails before those rules decide, for its reentry, thread, name or
  arguments, or for a plan or confirm function that fails.
- An unserialized execute that returns Aborted is recorded :command_done
  and returned, unless a counted on_abort overlapped the movement. Then
  it is recorded :command_aborted and run_command throws Aborted.

This corrects the previous commit's message. Besides a dry run and an
unknown command, every call that fails before the admission rules
decide records nothing. An unserialized Aborted that execute returns is
recorded :command_aborted when a counted on_abort overlapped the
movement.

The pull request text no longer says the child checks see the record
reach the tee before the interrupt: they compare the event kinds in the
tee after the writer is closed. The list of work owed by the next pull
request adds the unserialized path's distinction between an interrupt
from execute, rethrown directly, and one from a report, saved and thrown
after the record.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kalidke

kalidke commented Nov 30, 2026

Copy link
Copy Markdown
Member Author

Round 18 fixes, on top of b7af798: text only, and only in the sentences the brief named. Both round 18 reviews found
nothing blocking and confirmed the code unchanged.

  • Cleanup on an abnormal end. It applies to serialized commands: the instrument is made safe, or STOP is latched
    when make_safe! fails. An unserialized command has no cleanup. Fixed in the module docstring and the API page's
    trust-boundary summary.
  • The slot. It is nothing only when no serialized command runs and no counted :abort for an ended one is
    outstanding (_Run docstring).
  • Under STOP. Only the :abort, the grant turning off and unserialized reads run; every serialized command is
    refused Stopped (registration docstring).
  • The order of the checks. STOP, then confirmation, then the count. So AbortInFlight refuses a movement that
    passed the earlier checks, while a latched STOP refuses it Stopped first, and unserialized reads pass (CHANGELOG,
    pull request text).
  • What a call that does not run records. A refusal by an admission rule records :command_refused: STOP or the
    emit rule, confirmation, busy, or AbortInFlight. A dry run records nothing, and so does a call that fails before
    those rules decide, for its reentry, thread, name or arguments, say, or for a plan or confirm function that fails
    (API page, pull request text).
  • An unserialized Aborted. One that execute returns is recorded :command_done and returned, unless a counted
    on_abort overlapped the movement. Then it is recorded :command_aborted and run_command throws Aborted
    (Aborted docstring).
  • The tee claim. The child compares the event kinds in the tee after the writer is closed; the text no longer says
    the record reaches the tee before the interrupt.
  • The owed list. The first-delivery entry adds the unserialized path's distinction: an interrupt from execute is
    rethrown directly, while one from a report is saved and thrown after the record.

The commit message corrects b7af798's on the records of calls that do not run and on an unserialized returned
Aborted.

Local checks on the final code (Julia 1.13):

  • Full suite: 5980 passed, plus the same 3 known broken tests as main.
  • Agent and contract tests: 1569 at --threads=1,0, 1586 at 2,1 and 1586 at 4,1, with the 28 child SIGINT
    checks among them.
  • Docs build: passes, with all 561 docstrings on a built page.
  • The code is unchanged. With docstrings and comments removed, src/agent/Agent.jl and src/agent/commands.jl
    are identical to b7af798; no other Julia file changed.

kalidke and others added 2 commits November 30, 2026 01:03
…ments

While the layer's :abort for a command is counted, AbortInFlight refuses an
unserialized movement that passed STOP and confirmation; a serialized command is
refused CommandBusy instead, since the slot is still held, and the count refuses
no unserialized read. The entry said "a movement" without the distinction.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The child process copied the parent's thread counts as --threads=N,M. Under
Julia 1.11 the parent has no interactive thread (M = 0), and 1.11 refuses an
interactive count of 0, so the child never started and the test failed. On
1.11 the child now gets --threads=N, which there means N,0; 1.12 and later
keep --threads=N,M, since there --threads=N adds an interactive thread.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kalidke
kalidke merged commit 669d852 into main Dec 2, 2026
5 checks passed
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