0115: Agent record layout and idle cost
Status: Proposed — design default, pending the maintainer's confirmation
Context
Agent density requires a bounded, measurable waiting cost without a thread, stack or transition arena per agent.
Decision
Allocate records in per-worker slabs. Each has a fixed 64-byte header containing id, parent id, status, home worker, version, budget slot, context-root reference and pending-action count, followed by a compiler-laid-out state block and a small pending-action ID table. Promote state out of the transition arena after each step using ADR-0037 carry promotion; reset the arena to a worker-local pool. Waiting agents retain no stack, thread or transition arena.
hrt_agent_stats counts header, state block,
pending table and the agent's share of slab overhead. Exclude and
separately report unique context: blobs referenced by only that
agent (refcount 1). Report RSS alongside deterministic counters,
not as a gate.
Consequences
The accounting makes the ADR-0010 idle target reproducible while exposing context and RSS separately. Layout and slab overhead must be included in measurements, and the M12 transition-arena assumptions require confirmation.
Alternatives
Per-agent threads or persistent arenas increase idle overhead. RSS-only accounting is sensitive to allocator and operating-system behavior and cannot provide a deterministic gate.
M13.1 step 5 addendum: ordered pool boundary
Limits interaction (M13.1/step 22): drain waiting actions FIFO
before the D1 snapshot; enqueue limited actions in
(tick, agent id, action index) merge order for the
next boundary. Admission, reservation and journal-failure cleanup
remain runner-only. Unlimited singletons retain the no-snapshot
fast path; merged agent-arena stats
139500196/17900103/3448 exactly match PR3 (no
batching delta).
Status: Proposed, pending maintainer
Snapshot one queued event per runnable agent at the earliest ready logical tick, in agent ID order (root first). Only pure Agent.step calls cross the M11 dispatch boundary; all ports, redaction, journal and budget operations remain on the runner. Reuse M11's transitive worker-effect closure over concrete calls. Conservatively reject every native and host-secret intrinsic for this optional optimization (including effects reached through generic/interface helpers). If any reachable Agent.step fails, silently keep the whole program serial. Fuel/deadline programs also stay serial, preserving their observable charge order.
Submit the whole snapshot through one hrt_par_run, with one
logical shard per worker (id % HRT_THREADS, M11's
default and limit). Each shard steps its agents in ID order into
disjoint per-agent result slots. Adopt worker result arenas before
serially applying transitions, journal entries, actions and output
in (tick, agent id, action index) order. Catch worker
traps per agent and report the lowest agent ID, not the lowest
shard. One-thread, impure and interpreter paths compute the same
complete snapshot serially before merging any actions. Settlement
and initial stream refill precede the snapshot; ports may refill
streams during the serial merge. Merge-time cancellation or finish
does not retract a transition already in the snapshot. New events
wait for the next batch, even when their timestamp equals the
current tick. No new native or runtime threading API is
introduced.
Alternatives: singleton ticks preserve the old drain-one-agent ordering but do not implement D1 (ADR-0114). Free-running workers expose completion order in ports and journals. Both are rejected in favor of bulk-synchronous batches. Consequence: all agents ready at the boundary step, including agents cancelled by an earlier ID's actions during that batch's merge (M13.1 step 5b ruling).
Step 5b integration measurement (M12.7 retry/journal runner):
the 100,000-step tests/reports/agent-arena fixture
now measures
allocated=137900164 copied=17900103 peak=3416 bytes
in both normal and parallel builds, exactly matching main (zero
residual). Before the singleton fast path it measured
263577929/20377876/5944. Removed allocation sites:
snapshot storage 87,277,765 bytes (including 2,477,773 copied),
result vectors 6,400,000, trap slots 23,200,000, and pooled
execution/adoption 8,800,000; together these explain the entire
125,677,765-byte regression.
Return ownership (M13.1 step 5b fix-up): the typed worker
writes directly into ret (pooled) or
hrt_ret (one thread). Its own return-boundary
promotions remain necessary when values borrow shorter-lived
scratch. hrt_par_execute preserves worker arena zero
as slot.result, releasing only other
colours/persistent storage; hrt_par_run adopts that
result arena into the caller before merge. Remove the adapter's
same-arena deep copy, not the worker's scratch-to-return
promotions or runtime adoption. Keeping that extra copy wastes
allocation; dropping return-boundary promotion/adoption would
expose reset storage. A regression test with an explicit wrapper
Promote rejects copies in both adapter paths, and poison
ASan/UBSan plus TSan cover the batch program.
Singleton batches (M13.1 allocation fix): count all runnable
owners at the boundary before stepping. Only when that count is
one, dequeue and step directly, without snapshot/result vectors,
trap slots or hrt_par_run; keep the event expression
borrowed until the call rather than promoting a mutable event
temporary. Multi-owner batches retain the full snapshot and
ordered merge, including cancellation semantics. Reject
unconditional singleton draining because it changes D1; defer
reusable batch buffers because their lifetime/reentrancy machinery
and runtime changes are unnecessary for this regression.
Consequence: singleton work stays on the runner; multi-owner
storage costs remain. Goldens, interpreter parity, bounded-memory
tests and batch/ticks determinism at 1/2/4/8 threads pass, as do
poison ASan/UBSan and batch TSan.