fly-session: the coordinator runs the legacy composition's boundary (TASK-01)
- A task declares the inspection attachments it reads; the coordinator holds them (O[k] until its transition is evaluated) and hands the task and the executor their bytes (task::Inspection). - The executor's clock is the agent's brain time after Prepare. - Evaluation.slot_saves: Environment.SaveSlot at the boundary reached. - A declared rollback policy runs itself: Ready(e,k) -> RollingBack(k) -> Ready(e',k) with RestoreSlot, Task::rollback, Agent.Rollback; a composition that declares it needs agents that advertise it. - AdmissionQueue: admitted stimuli cut into each Prepare, ended applied or aborted; the last commit's stimulusRemainingMs for the edge. - Coordinator::import: a checkpoint of another format as a session's start, through the ordinary group restore (Ready(0) -> Restoring(k)); Task::restored re-observes the restored world and must agree with the recorded contexts. capture_participant, import_scope. - Composition setters: environment config, media, decision schema, world state format, per-agent model versions; StepDetails for parity. - ENV-01's interim 'declared rollback pauses' test now states the rule: a declared policy needs participants that apply it.
This commit is contained in:
parent
d034a26be5
commit
817318f014
4 changed files with 1351 additions and 75 deletions
File diff suppressed because it is too large
Load diff
|
|
@ -9,6 +9,8 @@
|
||||||
//! Ready(k) / Paused(k) -> Capturing(k) -> same boundary
|
//! Ready(k) / Paused(k) -> Capturing(k) -> same boundary
|
||||||
//! any unresolved partial failure -> Failed -> Restoring(new epoch) -> Paused(k)
|
//! any unresolved partial failure -> Failed -> Restoring(new epoch) -> Paused(k)
|
||||||
//! terminal episode -> Paused(k) -> Resetting(new epoch) -> Ready(0)
|
//! terminal episode -> Paused(k) -> Resetting(new epoch) -> Ready(0)
|
||||||
|
//! declared rollback: Ready(e, k) -> RollingBack(e', k) -> Ready(e', k)
|
||||||
|
//! checkpoint as the start: Ready(0), no transition taken -> Restoring(k) -> Paused(k)
|
||||||
//! ```
|
//! ```
|
||||||
//!
|
//!
|
||||||
//! A transition the table does not list is a bug, not a recoverable condition, so it returns
|
//! A transition the table does not list is a bug, not a recoverable condition, so it returns
|
||||||
|
|
@ -34,6 +36,9 @@ pub enum Phase {
|
||||||
Restoring(u64),
|
Restoring(u64),
|
||||||
/// `Resetting(k)`: leaving boundary `k` for a new epoch and episode at step 0.
|
/// `Resetting(k)`: leaving boundary `k` for a new epoch and episode at step 0.
|
||||||
Resetting(u64),
|
Resetting(u64),
|
||||||
|
/// A declared rollback policy running at a committed boundary (`step-v1` section 2
|
||||||
|
/// amendment of 2026-09-23): same boundary, new epoch, no capture.
|
||||||
|
RollingBack(u64),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Phase {
|
impl Phase {
|
||||||
|
|
@ -50,6 +55,7 @@ impl Phase {
|
||||||
Phase::Failed => "Failed".to_owned(),
|
Phase::Failed => "Failed".to_owned(),
|
||||||
Phase::Restoring(k) => format!("Restoring({k})"),
|
Phase::Restoring(k) => format!("Restoring({k})"),
|
||||||
Phase::Resetting(k) => format!("Resetting({k})"),
|
Phase::Resetting(k) => format!("Resetting({k})"),
|
||||||
|
Phase::RollingBack(k) => format!("RollingBack({k})"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -115,6 +121,14 @@ impl PhaseMachine {
|
||||||
(Restoring(k), Paused(j)) => k == j,
|
(Restoring(k), Paused(j)) => k == j,
|
||||||
(Paused(k), Resetting(j)) => k == j,
|
(Paused(k), Resetting(j)) => k == j,
|
||||||
(Resetting(_), Ready(0)) => true,
|
(Resetting(_), Ready(0)) => true,
|
||||||
|
// `step-v1` section 2, amendment of 2026-09-23: `Ready(e, k) -> RollingBack(e', k)
|
||||||
|
// -> Ready(e', k)`. The epoch changes, which is the coordinator's; the boundary
|
||||||
|
// does not.
|
||||||
|
(Ready(k), RollingBack(j)) | (RollingBack(k), Ready(j)) => k == j,
|
||||||
|
// A session that bootstrapped and has taken no transition may install a checkpoint
|
||||||
|
// as its start: the legacy composition's FLYSIM01 import (TASK-01). The install is
|
||||||
|
// the group restore of `state-media-v1` section 6 and ends `Paused(k)` like one.
|
||||||
|
(Ready(0), Restoring(_)) => true,
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -150,6 +164,21 @@ impl PhaseMachine {
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn a_rollback_keeps_its_boundary_and_an_import_starts_from_an_unstepped_zero() {
|
||||||
|
let mut m = PhaseMachine::new();
|
||||||
|
m.to(Phase::Ready(0)).unwrap();
|
||||||
|
m.to(Phase::Restoring(40)).unwrap();
|
||||||
|
m.to(Phase::Paused(40)).unwrap();
|
||||||
|
m.to(Phase::Ready(40)).unwrap();
|
||||||
|
assert!(m.to(Phase::RollingBack(41)).is_err(), "a rollback keeps the boundary");
|
||||||
|
m.to(Phase::RollingBack(40)).unwrap();
|
||||||
|
assert!(m.to(Phase::Capturing(40)).is_err(), "no capture inside a rollback");
|
||||||
|
assert!(m.to(Phase::Preparing(40)).is_err(), "no Prepare before every reply");
|
||||||
|
m.to(Phase::Ready(40)).unwrap();
|
||||||
|
assert!(m.to(Phase::Restoring(3)).is_err(), "only boundary 0 may take a start");
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn the_happy_path_walks_the_section_2_diagram() {
|
fn the_happy_path_walks_the_section_2_diagram() {
|
||||||
let mut m = PhaseMachine::new();
|
let mut m = PhaseMachine::new();
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@
|
||||||
//! writes a controller or neural state directly.
|
//! writes a controller or neural state directly.
|
||||||
|
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
use serde_json::{Map, Value, json};
|
use serde_json::{Map, Value, json};
|
||||||
|
|
||||||
|
|
@ -53,6 +54,48 @@ pub fn controller_schema_ref() -> SchemaRef {
|
||||||
synthetic_schema("arena.controller.v1", 1)
|
synthetic_schema("arena.controller.v1", 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// One boundary's inspection as the task and the executor read it: the observation's typed
|
||||||
|
/// `inspection` value plus the bytes of the attachments the task declared
|
||||||
|
/// ([`Task::inspection_attachments`]).
|
||||||
|
///
|
||||||
|
/// An artifact-backed inspection (`gameboy-memory-inspection-v1`: a 64 KiB image per boundary)
|
||||||
|
/// names its bytes by `ArtifactRef`; the coordinator holds the artifact until the transition
|
||||||
|
/// that reads it has been evaluated (`step-v1` section 3, Phase C amendment) and hands the task
|
||||||
|
/// the bytes, so neither the task nor the executor ever reads a live world. The synthetic
|
||||||
|
/// composition declares no attachment, and its inspection derefs to the typed value it always
|
||||||
|
/// was.
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
pub struct Inspection {
|
||||||
|
/// The boundary the observation belongs to.
|
||||||
|
pub boundary: u64,
|
||||||
|
pub value: TypedValue,
|
||||||
|
/// Attachment name to bytes, for the names the task declared.
|
||||||
|
pub attachments: BTreeMap<String, Arc<Vec<u8>>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Inspection {
|
||||||
|
/// An inspection with no attachment: the synthetic composition's.
|
||||||
|
pub fn plain(boundary: u64, value: TypedValue) -> Inspection {
|
||||||
|
Inspection { boundary, value, attachments: BTreeMap::new() }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl std::ops::Deref for Inspection {
|
||||||
|
type Target = TypedValue;
|
||||||
|
|
||||||
|
fn deref(&self) -> &TypedValue {
|
||||||
|
&self.value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// What a task's part of a rollback produced (`step-v1` section 6 amendment, step 3): the next
|
||||||
|
/// decision contexts for the restored boundary, and any events it reports.
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
pub struct RollbackEvaluation {
|
||||||
|
pub next_contexts: BTreeMap<Id, TypedValue>,
|
||||||
|
pub events: Vec<TaskEvent>,
|
||||||
|
}
|
||||||
|
|
||||||
/// What `Task.bootstrap` produced.
|
/// What `Task.bootstrap` produced.
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct Bootstrap {
|
pub struct Bootstrap {
|
||||||
|
|
@ -70,16 +113,27 @@ pub struct Evaluation {
|
||||||
pub progress: TypedValue,
|
pub progress: TypedValue,
|
||||||
pub events: Vec<TaskEvent>,
|
pub events: Vec<TaskEvent>,
|
||||||
pub episode: Option<EpisodeRequest>,
|
pub episode: Option<EpisodeRequest>,
|
||||||
|
/// Slot saves the transition asks for at the boundary it reached, applied by the coordinator
|
||||||
|
/// after every Commit and before any capture or rollback there (`step-v1` section 3, Phase C
|
||||||
|
/// amendment; environment capability `gameboy-slots-v1`). Empty in every composition that
|
||||||
|
/// declares no slots.
|
||||||
|
pub slot_saves: Vec<Id>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A checkpointable task ledger and the two evaluation entry points.
|
/// A checkpointable task ledger and the two evaluation entry points.
|
||||||
pub trait Task: Send {
|
pub trait Task: Send {
|
||||||
fn schema(&self) -> SchemaRef;
|
fn schema(&self) -> SchemaRef;
|
||||||
|
|
||||||
|
/// The inspection attachments this task and its executor read, which the coordinator asks
|
||||||
|
/// the environment for, holds and hands over as bytes. None by default.
|
||||||
|
fn inspection_attachments(&self) -> Vec<String> {
|
||||||
|
Vec::new()
|
||||||
|
}
|
||||||
|
|
||||||
/// Called once, at boundary 0, before any agent is initialized.
|
/// Called once, at boundary 0, before any agent is initialized.
|
||||||
fn bootstrap(
|
fn bootstrap(
|
||||||
&mut self,
|
&mut self,
|
||||||
initial_inspection: &TypedValue,
|
initial_inspection: &Inspection,
|
||||||
bindings: &[PortBinding],
|
bindings: &[PortBinding],
|
||||||
) -> DomainResult<Bootstrap>;
|
) -> DomainResult<Bootstrap>;
|
||||||
|
|
||||||
|
|
@ -87,11 +141,40 @@ pub trait Task: Send {
|
||||||
fn evaluate_transition(
|
fn evaluate_transition(
|
||||||
&mut self,
|
&mut self,
|
||||||
scope: &Scope,
|
scope: &Scope,
|
||||||
old_inspection: &TypedValue,
|
old_inspection: &Inspection,
|
||||||
new_inspection: &TypedValue,
|
new_inspection: &Inspection,
|
||||||
applied_controls: &[PortControl],
|
applied_controls: &[PortControl],
|
||||||
) -> DomainResult<Evaluation>;
|
) -> DomainResult<Evaluation>;
|
||||||
|
|
||||||
|
/// Step 3 of a declared rollback policy, coordinator-local (`step-v1` section 6 amendment):
|
||||||
|
/// the task clears its transient observations and the executor cancels any running action
|
||||||
|
/// and observes the restored boundary, which yields the next decision contexts. `scope` is
|
||||||
|
/// the new epoch at the restored boundary. A task that declares no rollback policy refuses.
|
||||||
|
fn rollback(
|
||||||
|
&mut self,
|
||||||
|
_scope: &Scope,
|
||||||
|
_restored: &Inspection,
|
||||||
|
) -> DomainResult<RollbackEvaluation> {
|
||||||
|
Err(DomainError::before(
|
||||||
|
ErrorCode::Unsupported,
|
||||||
|
"this task declares no rollback policy",
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// After a group restore installed this task's ledger: the restored boundary's inspection
|
||||||
|
/// and the agents' restored brain clock. A task whose executor state is transient
|
||||||
|
/// (`restore: legacy-transient-reset`) re-observes the world here and returns the decision
|
||||||
|
/// contexts it would hand the agents, which the coordinator holds against the ones the
|
||||||
|
/// checkpoint recorded. `None` (the default) means the recorded contexts stand unchecked.
|
||||||
|
fn restored(
|
||||||
|
&mut self,
|
||||||
|
_scope: &Scope,
|
||||||
|
_restored: &Inspection,
|
||||||
|
_clock: &RationalNs,
|
||||||
|
) -> DomainResult<Option<BTreeMap<Id, TypedValue>>> {
|
||||||
|
Ok(None)
|
||||||
|
}
|
||||||
|
|
||||||
fn progress(&self) -> TypedValue;
|
fn progress(&self) -> TypedValue;
|
||||||
|
|
||||||
/// How many times `evaluate_transition` has run. A transition must evaluate once.
|
/// How many times `evaluate_transition` has run. A transition must evaluate once.
|
||||||
|
|
@ -127,7 +210,7 @@ pub trait ActionExecutor: Send {
|
||||||
&mut self,
|
&mut self,
|
||||||
scope: &Scope,
|
scope: &Scope,
|
||||||
decision: &TypedValue,
|
decision: &TypedValue,
|
||||||
current_game_state: &TypedValue,
|
current_game_state: &Inspection,
|
||||||
progress: &TypedValue,
|
progress: &TypedValue,
|
||||||
clock: &RationalNs,
|
clock: &RationalNs,
|
||||||
) -> DomainResult<(ControllerIntent, Vec<TaskEvent>)>;
|
) -> DomainResult<(ControllerIntent, Vec<TaskEvent>)>;
|
||||||
|
|
@ -151,7 +234,7 @@ impl ActionExecutor for IdentityExecutor {
|
||||||
&mut self,
|
&mut self,
|
||||||
_scope: &Scope,
|
_scope: &Scope,
|
||||||
decision: &TypedValue,
|
decision: &TypedValue,
|
||||||
_current_game_state: &TypedValue,
|
_current_game_state: &Inspection,
|
||||||
_progress: &TypedValue,
|
_progress: &TypedValue,
|
||||||
_clock: &RationalNs,
|
_clock: &RationalNs,
|
||||||
) -> DomainResult<(ControllerIntent, Vec<TaskEvent>)> {
|
) -> DomainResult<(ControllerIntent, Vec<TaskEvent>)> {
|
||||||
|
|
@ -294,7 +377,7 @@ impl Task for CounterTask {
|
||||||
|
|
||||||
fn bootstrap(
|
fn bootstrap(
|
||||||
&mut self,
|
&mut self,
|
||||||
initial_inspection: &TypedValue,
|
initial_inspection: &Inspection,
|
||||||
bindings: &[PortBinding],
|
bindings: &[PortBinding],
|
||||||
) -> DomainResult<Bootstrap> {
|
) -> DomainResult<Bootstrap> {
|
||||||
if initial_inspection.schema != inspection_schema() {
|
if initial_inspection.schema != inspection_schema() {
|
||||||
|
|
@ -329,8 +412,8 @@ impl Task for CounterTask {
|
||||||
fn evaluate_transition(
|
fn evaluate_transition(
|
||||||
&mut self,
|
&mut self,
|
||||||
scope: &Scope,
|
scope: &Scope,
|
||||||
old_inspection: &TypedValue,
|
old_inspection: &Inspection,
|
||||||
new_inspection: &TypedValue,
|
new_inspection: &Inspection,
|
||||||
applied_controls: &[PortControl],
|
applied_controls: &[PortControl],
|
||||||
) -> DomainResult<Evaluation> {
|
) -> DomainResult<Evaluation> {
|
||||||
let old = old_inspection.integer("counter").map_err(DomainError::invalid)?;
|
let old = old_inspection.integer("counter").map_err(DomainError::invalid)?;
|
||||||
|
|
@ -445,6 +528,7 @@ impl Task for CounterTask {
|
||||||
progress: self.progress_value(),
|
progress: self.progress_value(),
|
||||||
events,
|
events,
|
||||||
episode,
|
episode,
|
||||||
|
slot_saves: Vec::new(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ both_transports!(
|
||||||
the_committed_snapshot_names_the_boundary_that_just_ended,
|
the_committed_snapshot_names_the_boundary_that_just_ended,
|
||||||
a_terminal_episode_pauses_at_its_own_boundary,
|
a_terminal_episode_pauses_at_its_own_boundary,
|
||||||
a_rollback_request_without_a_declared_policy_fails_the_epoch,
|
a_rollback_request_without_a_declared_policy_fails_the_epoch,
|
||||||
a_declared_rollback_policy_holds_the_session_at_its_boundary,
|
a_declared_rollback_policy_needs_participants_that_apply_it,
|
||||||
status_answers_with_the_committed_boundary,
|
status_answers_with_the_committed_boundary,
|
||||||
a_worker_refuses_a_second_initialize,
|
a_worker_refuses_a_second_initialize,
|
||||||
a_single_agent_composition_runs_the_same_transaction,
|
a_single_agent_composition_runs_the_same_transaction,
|
||||||
|
|
@ -329,9 +329,13 @@ async fn a_rollback_request_without_a_declared_policy_fails_the_epoch(via: Via)
|
||||||
f.shutdown().await;
|
f.shutdown().await;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// With `legacy-ratchet-rollback-v1` declared the request is accepted: the transition commits and
|
/// With `legacy-ratchet-rollback-v1` declared the coordinator runs the policy itself
|
||||||
/// the session holds at its boundary with the request recorded, for the policy to run.
|
/// (`step-v1` section 6 amendment; TASK-01), so a composition may only declare it over
|
||||||
async fn a_declared_rollback_policy_holds_the_session_at_its_boundary(via: Via) {
|
/// participants that can apply it: agents that answer `Agent.Rollback` and a world with
|
||||||
|
/// `gameboy-slots-v1`. The synthetic agents answer neither, so the session never starts --
|
||||||
|
/// rather than accepting a rollback request it cannot apply. (Until TASK-01 the declared request
|
||||||
|
/// paused the session at its boundary.)
|
||||||
|
async fn a_declared_rollback_policy_needs_participants_that_apply_it(via: Via) {
|
||||||
let config = HarnessConfig {
|
let config = HarnessConfig {
|
||||||
terminal: fly_session::task::Terminal::RollbackAfterTransitions(2),
|
terminal: fly_session::task::Terminal::RollbackAfterTransitions(2),
|
||||||
..HarnessConfig::default()
|
..HarnessConfig::default()
|
||||||
|
|
@ -342,13 +346,11 @@ async fn a_declared_rollback_policy_holds_the_session_at_its_boundary(via: Via)
|
||||||
.declare_rollback_policy("legacy-ratchet-rollback-v1")
|
.declare_rollback_policy("legacy-ratchet-rollback-v1")
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert!(f.harness.coordinator.declare_rollback_policy("reset-everything").is_err());
|
assert!(f.harness.coordinator.declare_rollback_policy("reset-everything").is_err());
|
||||||
within("bootstrap", f.harness.coordinator.bootstrap()).await.unwrap();
|
let err = within("bootstrap", f.harness.coordinator.bootstrap()).await.unwrap_err();
|
||||||
let reports = within("run", f.harness.coordinator.run(4)).await.unwrap();
|
assert_eq!(err.error.code, ErrorCode::Unsupported, "{}", err.error.message);
|
||||||
assert_eq!(reports.len(), 2);
|
assert!(err.error.message.contains("Agent.Rollback"), "{}", err.error.message);
|
||||||
assert!(!f.harness.coordinator.is_fenced());
|
assert!(f.harness.coordinator.is_fenced());
|
||||||
assert_eq!(f.harness.coordinator.phase(), Phase::Paused(2));
|
assert!(f.harness.coordinator.episode_request().is_none());
|
||||||
let request = f.harness.coordinator.episode_request().unwrap();
|
|
||||||
assert_eq!(request.kind, EpisodeRequestKind::Rollback);
|
|
||||||
f.shutdown().await;
|
f.shutdown().await;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue