docs: TASK-01 in the implementation guide; dated amendments (2026-09-29) to legacy-gameboy-v1 sections 10, 11, 14 and 15, step-v1 sections 2 and 3, workers-v1 sections 4 and 5

This commit is contained in:
acamilo 2026-09-29 18:11:30 +00:00
parent 851b4f85c4
commit 1a6e064e4f
4 changed files with 149 additions and 0 deletions

View file

@ -344,6 +344,53 @@ CUT-01 shadow need.
the executor over `ImageReader::new(&O[k], &cartridge)` in Phase B and over O[k+1] in Phase C, the executor over `ImageReader::new(&O[k], &cartridge)` in Phase B and over O[k+1] in Phase C,
retaining O[k] until then. The `Cartridge` comes from `Cartridge::verified(rom, contentDigest)`. retaining O[k] until then. The `Cartridge` comes from `Cartridge::verified(rom, contentDigest)`.
### TASK-01 — The `pokered-macros-v1` task and executor (port slice)
**2026-09-29: built** on `port/task-01` off `port/integration` (main v0.6.5 + AGENT-01 + MEM-01 +
ENV-01) and awaiting review. It changes no live behaviour: `flysim` is only a library dependency of
the new crate, nothing in the service calls it, and the compatibility string is unchanged. With it
the live fly's whole composition -- agent, world, task and executor -- runs on the session
framework, from a fresh start or from a FLYSIM01 checkpoint.
- **The object** (`fly-legacy-session::task::PokeredTask`). The task and the executor are one
object with two faces, `Task` and `ActionExecutor`, which the coordinator holds where it holds
any task and executor (legacy-gameboy-v1 section 10). Phase B runs flysim's `MacroLayer::decide`
over `ImageReader(O[k], cartridge)` at the agent's brain time. Phase C runs
`PokemonRedReward::sample`, `MacroLayer::observe`, the location, the progress and the ratchet's
decision over `ImageReader(O[k+1])`. A rollback runs `clear_transient`, `cancel` and `observe`
over `ImageReader(O'[k+1])`. These are the legacy engine's own calls in `LegacyFrame`'s order;
there is no port of a rule. The cartridge is `Cartridge::verified(rom, contentDigest)`, and O[k] is
retained until Phase C has read it.
- **The coordinator** (fly-session). A task declares the inspection attachments it reads, and the
coordinator holds them and hands over their bytes (`task::Inspection`). The executor's clock is the
agent's brain time after Prepare. `Evaluation.slot_saves` asks for `Environment.SaveSlot`. A
declared rollback policy now runs itself: `Ready(e, k) -> RollingBack(e', k) -> Ready(e', k)`, with
`RestoreSlot`, then `Task::rollback`, then `Agent.Rollback` on every agent. Composition setters
cover the backend and task config, the media, the decision schema, the world's state format and
per-agent model versions. The admission queue (`AdmissionQueue`) is cut into each Prepare's
`preStepStimulations` and reports every admission applied or aborted. `Coordinator::import`
installs a checkpoint of another format as a session's start. Step details (`StepDetails`) are
kept for a parity run.
- **FLYSIM01 as the start** (`fly-legacy-session::import`). This is the import AGENT-01 and ENV-01
left open. The world, agent and task halves go into each participant's own capture format, and
the ordinary group restore installs them: stage, validate, activate, `Paused(k)`, resume. The
world is replaced by a fresh one first, because ENV-01 stages only on a replacement. The context
the agent resumes with is computed from the checkpoint's own memory image, and the coordinator
holds the task to it after the install (`Task::restored`).
- **Sugar** (`fly-legacy-session::admission`). flysim's `RateLimiter` and clamp run unchanged,
against the last commit's `stimulusRemainingMs` (one commit stale). An admission waits for the
next cut.
- **The operator reward pulse is refused.** See the legacy-gameboy-v1 section 15 amendment.
**Parity** (`fly-legacy-session/tests/session_trace.rs`, rom-env). A whole new-runtime session
writes its own `FLY_TRACE` line per transition (`fly-legacy-session::trace`). Each line is built
from what crossed its boundaries: `Agent.Prepare`, `Agent.Commit`'s rates and spike bitset, the
executor's batch, the view, the image and the boundary actions. It is compared field by field with
the legacy loop's. The decision is compared as a set, because `gameboy-channels-v1` carries no list
order. Where the legacy side runs in the test, the ledgers are compared after every boundary as
well: adapter export, ratchet state, and the executor's scene, bound channels, running macro,
counts and "nearer". Results: see the TASK-01 run report and the amendment below.
### STATE-01 — Coherent all-participant checkpoint/recovery ### STATE-01 — Coherent all-participant checkpoint/recovery
**Depends on:** SESSION-02, MEDIA-01; validate with fake agents first, then AGENT-01/ENV-01. **Depends on:** SESSION-02, MEDIA-01; validate with fake agents first, then AGENT-01/ENV-01.

View file

@ -288,6 +288,27 @@ signal. The object serves exactly one agent on one port.
- **Cancel.** `cancel(ms)` abandons a running macro. It is followed by `observe` on the world - **Cancel.** `cancel(ms)` abandons a running macro. It is followed by `observe` on the world
the fly now stands in. the fly now stands in.
**Amendment, 2026-09-29 (TASK-01).** Choices the section above leaves open, fixed as built by
`fly-legacy-session::task`:
- *The ratchet's slot.* The ratchet ledger stays in the task. Its snapshot lives in the environment
as the slot `best`. The ratchet only asks whether one exists: its budget test is "no snapshot".
So the task holds a marker snapshot in its place, and a task ledger records `slot: bool`. A slot
save is asked for exactly when the legacy capture closure runs: safe, and rank above best.
- *The palette seed.* The legacy loop seeds the palette from the brain's RNG state after boot.
`MacroMachine` never reads its generator: no macro has a random step, and flybrain-gb's macro
tests show two seeds press the same buttons. The executor therefore uses a constant, and nothing
about it crosses to the agent.
- *The clock of the first observation.* A fresh start's layer observes O[0] at the end of the
warm-up, `warmupMs` = 2500 ms, which the profile pins. That is the same time the legacy loop's
`Sim::boot` observes at, although the agent is initialized after the task bootstraps. After a
restore the layer observes at the restored brain time.
- *A reward event with `stimulation_ms` = 0* is one `Reward` and no `Stimulus`, because
`Stimulus.durationMs` is positive. The legacy `stimulate(0)` changes nothing.
- *Executor events.* Macro starts and finishes are not `executionEvents`. They are reported as
`FLY_TRACE` `macroEvents` (phases `execute`, `evaluate`, `rollback`). Reward events are the
task's `TaskEvent`s.
## 11. Episode policy `legacy-ratchet-rollback-v1` ## 11. Episode policy `legacy-ratchet-rollback-v1`
The ratchet's game-only rollback is a declared episode policy. When the ratchet fires during The ratchet's game-only rollback is a declared episode policy. When the ratchet fires during
@ -331,6 +352,14 @@ the adapter's persistent state. The first audio chunk after the rollback marks a
discontinuity. This is the legacy `recover_game` sequence with the neural half moved into the agent. discontinuity. This is the legacy `recover_game` sequence with the neural half moved into the agent.
Each half touches only its own state, so the order between the halves does not matter. Each half touches only its own state, so the order between the halves does not matter.
**Amendment, 2026-09-29 (TASK-01).** The coordinator applies the policy itself, as the section
describes. The phase is `RollingBack(k)`. The new epoch is the session's epoch root plus `.rb<n>`,
which is deterministic, so two runs of one session name the same epochs. A composition that
declares the policy refuses to start unless every agent advertises `legacy-ratchet-rollback-v1`.
The task's rollback request carries `{slotId: best, trigger}`. The world must advertise
`gameboy-slots-v1` before anything is saved or restored. Service traces with a ratchet slot save
and a ratchet rollback reproduce as described in the implementation guide's TASK-01 entry.
## 12. Composition declaration and digest ## 12. Composition declaration and digest
```ts ```ts
@ -500,6 +529,23 @@ Resume tests compare against the legacy restore outcome, not against an uninterr
unstick procedure depends on: restarting the service clears the ledger-shaped traps and keeps unstick procedure depends on: restarting the service clears the ledger-shaped traps and keeps
the rung. the rung.
**Amendment, 2026-09-29 (TASK-01): a FLYSIM01 checkpoint as the start.** A new-runtime session
starts from the live fly's own save through the ordinary group restore
(`Coordinator::import`, `fly-legacy-session::import`):
- The world is ENV-01's `WorldState::from_flysim01` at `k = emulatorFrame - 1`, staged on a
replacement world.
- The agent is the checkpoint's agent state in the worker's own capture: AGENT-01's
`legacy_state_payload`, with `learning.updates` started at `plasticity.updates` and the
checkpoint id and boundary written in.
- The task is the adapter state and the ratchet state.
This section's resets then apply, and nothing else. The executor is fresh and observes the restored
image once, at the restored brain time. The agent's readout transient is a fresh process's. The
decision context is computed from the checkpoint's memory image before the install, and the
coordinator refuses the install if the task, re-observing the restored world, derives another
context.
## 15. Sugar admission ## 15. Sugar admission
The coordinator owns admission, with the legacy rules: the per-minute limiter, and "no overlap The coordinator owns admission, with the legacy rules: the per-minute limiter, and "no overlap
@ -523,6 +569,20 @@ applies it never commits, the admission is reported aborted and the edge refunds
bridge's fulfil path and refund path both get tests in the slice that wires them bridge's fulfil path and refund path both get tests in the slice that wires them
([workers-v1](workers-v1.md) section 5 amendment). ([workers-v1](workers-v1.md) section 5 amendment).
**Amendment, 2026-09-29 (TASK-01).** As built:
- *Admission.* The coordinator's `AdmissionQueue` is cut at the top of each Prepare. It reports
every admission `applied` at the boundary its Prepare committed at, or `aborted` when the epoch
fails first. The legacy rules run on the edge side, unchanged: flysim's `RateLimiter` and the
clamp. They read `stimulusRemainingMs` from the last `Agent.Commit` or `Agent.Rollback` reply.
After a restore the pulse is unknown and a request is refused with a retry of one frame.
- *The operator's `POST /reward` pulse is refused (declared).* In the legacy loop it is off unless
an operator sets `control.allow_reward`. Every shipped configuration leaves it off, and the API
answers 403. The session runtime has no counterpart to turn on, because a reinforcement outside
`Agent.Commit` is not a session-framework operation. `LegacyAdmission::reward` therefore always
refuses. A legacy trace that carries a reward pulse cannot be reproduced; FND-01's checker
refuses one as well.
## 16. Checkpoint format of record ## 16. Checkpoint format of record
**Order at a boundary (amended 2026-09-23, review round 1).** A slot save due at `Ready(k)` **Order at a boundary (amended 2026-09-23, review round 1).** A slot save due at `Ready(k)`

View file

@ -65,6 +65,19 @@ amendment). The boundary number does not change; the epoch does. A pause request
lands on `Ready(e', k)`; any failure inside it is `Failed → Restoring(new epoch)`. Capture is lands on `Ready(e', k)`; any failure inside it is `Failed → Restoring(new epoch)`. Capture is
not allowed in `RollingBack`. not allowed in `RollingBack`.
**Amendment, 2026-09-29 (TASK-01).** Two edges are implemented as written above (`fly-session`
`phase.rs`): `Ready(k) -> RollingBack(k) -> Ready(k)`, where the epoch is the coordinator's and
the boundary stays the same. One edge is added for a checkpoint of another format installed as a
session's start (the legacy composition's FLYSIM01 import):
```text
Ready(0), no transition taken -> Restoring(k) -> Paused(k)
```
The install is the group restore of [state-media-v1](state-media-v1.md) section 6, unchanged. Only
a session that has not advanced may take the edge; the coordinator enforces this, because the phase
alone cannot tell a fresh `Ready(0)` from a reset one.
## 3. Transaction sequence ## 3. Transaction sequence
### Phase A: prepare all agents concurrently ### Phase A: prepare all agents concurrently
@ -111,6 +124,12 @@ and returns StepResult for `k+1`. It MUST NOT advance another interval while wai
the next request. Transport/control scaffolding may have a measured fixed latency; it must the next request. Transport/control scaffolding may have a measured fixed latency; it must
be declared in its descriptor and conformance tests. be declared in its descriptor and conformance tests.
*Amendment, 2026-09-29 (TASK-01):* as built, the clock the executor is handed is
`brainTicks x tickDuration` from the agent's `PreparedDecision`, exact in `RationalNs`. For the
legacy profile this is the legacy `network.ms` in nanoseconds. An artifact-backed inspection reaches
the executor and the task as bytes: the coordinator holds each attachment the task declares
(`inspection.memory`) from the world's reply until the transition that reads it has been evaluated.
### Phase C: observe and evaluate the task ### Phase C: observe and evaluate the task
The coordinator receives the environment result and verifies batch identity, boundary, The coordinator receives the environment result and verifies batch identity, boundary,

View file

@ -426,6 +426,22 @@ composition that declares no rollback policy treats the request as a task failur
"cannot reset the environment directly": the coordinator applies the policy through the "cannot reset the environment directly": the coordinator applies the policy through the
section 7 methods. section 7 methods.
**Amendment, 2026-09-29 (TASK-01).** The Rust interfaces, as built in `fly-session::task`:
- The inspection argument is an `Inspection`: the observation's typed `inspection` value, plus the
bytes of every attachment the task declares (`Task::inspection_attachments`, for example
`inspection.memory`). A synthetic task declares none, and its inspection reads as the typed value
it always was.
- `Evaluation.slot_saves` names the `Environment.SaveSlot`s the transition asks for at the boundary
it reached. They are applied after every Commit, saves first.
- `Task::rollback(scope', restored)` is step 3 of a declared rollback policy. It returns the next
contexts.
- `Task::restored(scope', restored, clock)` runs after a group restore installed the ledger. A task
whose executor state is transient re-observes the restored world here, and returns the contexts
the coordinator holds against the checkpoint's.
- A task and an executor that are one object (`pokered-macros-v1`) are two handles on one shared
state.
## 5. Admission and audience boundary ## 5. Admission and audience boundary
The first synthetic implementation has no audience input. Later integration maps permitted The first synthetic implementation has no audience input. Later integration maps permitted
@ -453,6 +469,13 @@ first and refunds the second, and the slice wiring the bridge tests both. This i
accepted/applied/aborted distinction the paragraph above asks for, for this one interaction accepted/applied/aborted distinction the paragraph above asks for, for this one interaction
kind; paid interactions in general still need the public v2 contract. kind; paid interactions in general still need the public v2 contract.
**Amendment, 2026-09-29 (TASK-01).** As built, the coordinator's `AdmissionQueue` is the
admission record: an admitted stimulus carries its interaction id into `preStepStimulations`, and it
ends `applied` (with its boundary) or `aborted` (the epoch failed before its Prepare committed). The
legacy composition's rules run on the edge side of the queue. No other interaction kind is admitted.
The legacy operator reward pulse is refused (legacy-gameboy-v1 section 15, amendment of
2026-09-29).
## 6. Health, shutdown and extensions ## 6. Health, shutdown and extensions
All workers implement the common Hello/Status/Shutdown/Acknowledge methods. Capture/restore All workers implement the common Hello/Status/Shutdown/Acknowledge methods. Capture/restore