nmarshall commited on
Commit
4237b41
·
1 Parent(s): 244a13d

gameplay: link defuse events in server pool

Browse files
crates/urt-gameplay/src/bin/urt-defuse.rs CHANGED
@@ -108,6 +108,7 @@ fn main() {
108
  "log-dispatch" => println!("{}", log_dispatch(&w)),
109
  "event-lifecycle" => println!("{}", event_lifecycle(&w)),
110
  "located-full" => println!("{}", located_full(&w, None)),
 
111
  "world-located" => println!("{}", located_full(&w[1..], Some(w[0]))),
112
  "sequence" => println!("{}", sequence(&w)),
113
  _ => panic!("unknown policy"),
@@ -617,3 +618,95 @@ fn rank_feedback(w: &[u32]) -> String {
617
  list(&[team_scores[0] as u32, team_scores[1] as u32])
618
  )
619
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
108
  "log-dispatch" => println!("{}", log_dispatch(&w)),
109
  "event-lifecycle" => println!("{}", event_lifecycle(&w)),
110
  "located-full" => println!("{}", located_full(&w, None)),
111
+ "server-located" => println!("{}", server_located(&w)),
112
  "world-located" => println!("{}", located_full(&w[1..], Some(w[0]))),
113
  "sequence" => println!("{}", sequence(&w)),
114
  _ => panic!("unknown policy"),
 
618
  list(&[team_scores[0] as u32, team_scores[1] as u32])
619
  )
620
  }
621
+
622
+ fn server_located(w: &[u32]) -> String {
623
+ use std::io::Read;
624
+ use urt_assets::bsp::BspVisibility;
625
+ use urt_gameplay::area_portals::AreaPortals;
626
+ use urt_gameplay::server_entities::{ServerDefuseRadio, ServerEntities};
627
+ use urt_gameplay::spatial_index::Bounds;
628
+ use urt_gameplay::world_visibility::WorldVisibility;
629
+
630
+ let (mut world, input) = decode_full(&w[..31]);
631
+ let pool_len = w[32] as usize;
632
+ let (mut pool, _, start) = decode_pool(&w[33..33 + pool_len]);
633
+ for slot in &mut pool.slots {
634
+ slot.words[416 / 4..464 / 4].fill(0);
635
+ slot.words[500 / 4..512 / 4].fill(0);
636
+ slot.words[424 / 4] = w[31];
637
+ for offset in [520, 528, 548, 556, 560, 592, 604, 608, 612, 616, 620] {
638
+ slot.words[offset / 4] = 0;
639
+ }
640
+ }
641
+ let mut fixture = radio_fixture::decode_radio(&w[33 + pool_len..]);
642
+ let entries = fixture
643
+ .entries
644
+ .iter()
645
+ .copied()
646
+ .map(Some)
647
+ .collect::<Vec<_>>();
648
+ let mut bytes = Vec::new();
649
+ std::io::stdin().read_to_end(&mut bytes).unwrap();
650
+ let bsp = BspVisibility::parse(&bytes).unwrap();
651
+ let mut portals = AreaPortals::new(bsp.area_count());
652
+ portals.adjust(Some(0), Some(1), true).unwrap();
653
+ let map = WorldVisibility {
654
+ bsp: &bsp,
655
+ portals: &portals,
656
+ ignore_areas: false,
657
+ };
658
+ let bounds = Bounds::new([-128.; 3], [128.; 3]).unwrap();
659
+ let mut server = ServerEntities::new(bounds, pool).unwrap();
660
+ let out = server
661
+ .process_defuse(
662
+ &map,
663
+ &mut world,
664
+ input,
665
+ start,
666
+ &mut fixture.state,
667
+ ServerDefuseRadio {
668
+ entries: &entries,
669
+ lookup: (&fixture.location).into(),
670
+ mode: fixture.input.mode,
671
+ clients: &fixture.clients,
672
+ texts: &fixture.texts,
673
+ active_server: true,
674
+ },
675
+ )
676
+ .unwrap();
677
+ let a = out.allocation.unwrap();
678
+ let linked = if let Some(link) = a.link {
679
+ let id = server.id_at(link.slot).unwrap();
680
+ let record = server.record(id).unwrap();
681
+ assert_eq!(record.words[416 / 4], 1);
682
+ assert_eq!(record.words[420 / 4], 1);
683
+ let areas = server.links().metadata(link.slot).unwrap().areas;
684
+ let before = server.links().spatial().query(bounds, 4).slots;
685
+ let payload = record.words[184 / 4];
686
+ let tick = input.base.tick;
687
+ server.expire(id, tick + 300, None, |_| Some(0)).unwrap();
688
+ let retained = server.links().spatial().query(bounds, 4).slots;
689
+ server.expire(id, tick + 301, None, |_| Some(0)).unwrap();
690
+ format!(
691
+ r#"{{"slot":{},"snapshot_link":{},"snapshot_payload":{},"payload":{payload},"areas":{areas:?},"before":{before:?},"retained":{retained:?},"after":{:?},"released":{}}}"#,
692
+ link.slot,
693
+ link.record.words[416 / 4],
694
+ link.record.words[184 / 4],
695
+ server.links().spatial().query(bounds, 4).slots,
696
+ server.record(id).is_none(),
697
+ areas = areas.map(|a| a.unwrap_or(u32::MAX))
698
+ )
699
+ } else {
700
+ "null".to_string()
701
+ };
702
+ let radio = out
703
+ .radio
704
+ .map(|r| radio_fixture::radio_fields(r.output, &fixture.state))
705
+ .unwrap_or("null".into());
706
+ format!(
707
+ r#"{{"status":"{}","count":{},"registered":{},"linked":{linked},"radio":{radio}}}"#,
708
+ a.allocation.status,
709
+ a.allocation.count,
710
+ server.registered_count()
711
+ )
712
+ }
crates/urt-gameplay/src/entity_links.rs CHANGED
@@ -39,6 +39,7 @@ pub fn link_metadata(
39
 
40
  /// Owns linked-slot membership and visibility metadata. The game pool owns
41
  /// the associated entity records.
 
42
  pub struct EntityLinks {
43
  index: SpatialIndex,
44
  metadata: Vec<Option<LinkMetadata>>,
 
39
 
40
  /// Owns linked-slot membership and visibility metadata. The game pool owns
41
  /// the associated entity records.
42
+ #[derive(Clone)]
43
  pub struct EntityLinks {
44
  index: SpatialIndex,
45
  metadata: Vec<Option<LinkMetadata>>,
crates/urt-gameplay/src/location_feedback.rs CHANGED
@@ -837,7 +837,7 @@ pub fn process_located_defuse(
837
  mode: context.mode,
838
  clients: context.clients,
839
  texts: context.texts,
840
- select: |actor, tick| {
841
  let mut location = context.location.clone();
842
  location.actor = actor;
843
  location.tick = tick;
@@ -847,11 +847,28 @@ pub fn process_located_defuse(
847
  )
848
  }
849
 
850
- pub(crate) struct DefuseRadioLookup<'a, F> {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
851
  pub mode: u32,
852
  pub clients: &'a [crate::effect_feedback::RadioClient],
853
  pub texts: &'a [Vec<u8>],
854
- pub select: F,
855
  }
856
 
857
  pub(crate) fn process_located_defuse_with(
@@ -860,7 +877,7 @@ pub(crate) fn process_located_defuse_with(
860
  input: crate::defuse::FullDefuseInput,
861
  level_start: u32,
862
  radio_state: &mut DefuseRadioState,
863
- context: DefuseRadioLookup<'_, impl FnOnce([u32; 3], u32) -> Result<LocationSelection, Error>>,
864
  ) -> Result<LocatedDefuseOutcome, Error> {
865
  use crate::defuse::DefuseEffect;
866
  use crate::effect_feedback::RadioInput;
@@ -882,7 +899,8 @@ pub(crate) fn process_located_defuse_with(
882
  branch,
883
  level_start,
884
  origin,
885
- |mut outcome| {
 
886
  let radio = if let [DefuseEffect::TeamRadio { slot, code }] =
887
  outcome.after_allocation.as_slice()
888
  {
@@ -905,7 +923,7 @@ pub(crate) fn process_located_defuse_with(
905
  context.clients,
906
  &input,
907
  context.texts,
908
- || (context.select)(actor_point, base.tick),
909
  )?;
910
  let plan = DefuseRadioPlan {
911
  slot: *slot,
@@ -944,19 +962,28 @@ pub fn allocate_defuse_branch(
944
  start: u32,
945
  origin: [u32; 3],
946
  ) -> Result<Option<DefuseAllocation>, Error> {
947
- allocate_defuse_with(state, pool, input, branch, start, origin, |outcome| {
948
- Ok(outcome)
949
- })
 
 
 
 
 
 
 
 
950
  }
951
 
952
- fn allocate_defuse_with<T>(
953
  state: &mut crate::defuse::DefuseState,
954
  pool: &mut EntityPool,
955
  input: crate::defuse::DefuseInput,
956
  branch: DefuseBranch,
957
  start: u32,
958
  origin: [u32; 3],
959
- resolve: impl FnOnce(DefuseAllocation) -> Result<T, Error>,
 
960
  ) -> Result<Option<T>, Error> {
961
  use crate::defuse::{DefuseEffect, begin_defuse, cancel_defuse, finish_defuse};
962
 
@@ -988,6 +1015,7 @@ fn allocate_defuse_with<T>(
988
  let record = &mut next_pool.slots[index];
989
  let initialized = record.clone();
990
  construct_event(record, origin, event_kind, input.tick)?;
 
991
  let link = DefuseEventLink {
992
  slot: index,
993
  record: record.clone(),
@@ -999,14 +1027,17 @@ fn allocate_defuse_with<T>(
999
  after_allocation.clear();
1000
  (None, None)
1001
  };
1002
- let result = resolve(DefuseAllocation {
1003
- event_kind,
1004
- allocation,
1005
- initialized,
1006
- link,
1007
- before_allocation: effects,
1008
- after_allocation,
1009
- })?;
 
 
 
1010
  *state = caller;
1011
  *pool = next_pool;
1012
  Ok(Some(result))
 
837
  mode: context.mode,
838
  clients: context.clients,
839
  texts: context.texts,
840
+ spatial: |actor, tick| {
841
  let mut location = context.location.clone();
842
  location.actor = actor;
843
  location.tick = tick;
 
847
  )
848
  }
849
 
850
+ pub(crate) trait DefuseSpatial {
851
+ fn link(&mut self, _slot: usize, _record: &mut EntitySlot) -> Result<(), Error> {
852
+ Ok(())
853
+ }
854
+
855
+ fn select(&mut self, actor: [u32; 3], tick: u32) -> Result<LocationSelection, Error>;
856
+ }
857
+
858
+ impl<F> DefuseSpatial for F
859
+ where
860
+ F: FnMut([u32; 3], u32) -> Result<LocationSelection, Error>,
861
+ {
862
+ fn select(&mut self, actor: [u32; 3], tick: u32) -> Result<LocationSelection, Error> {
863
+ self(actor, tick)
864
+ }
865
+ }
866
+
867
+ pub(crate) struct DefuseRadioLookup<'a, S> {
868
  pub mode: u32,
869
  pub clients: &'a [crate::effect_feedback::RadioClient],
870
  pub texts: &'a [Vec<u8>],
871
+ pub spatial: S,
872
  }
873
 
874
  pub(crate) fn process_located_defuse_with(
 
877
  input: crate::defuse::FullDefuseInput,
878
  level_start: u32,
879
  radio_state: &mut DefuseRadioState,
880
+ mut context: DefuseRadioLookup<'_, impl DefuseSpatial>,
881
  ) -> Result<LocatedDefuseOutcome, Error> {
882
  use crate::defuse::DefuseEffect;
883
  use crate::effect_feedback::RadioInput;
 
899
  branch,
900
  level_start,
901
  origin,
902
+ &mut context.spatial,
903
+ |mut outcome, spatial| {
904
  let radio = if let [DefuseEffect::TeamRadio { slot, code }] =
905
  outcome.after_allocation.as_slice()
906
  {
 
923
  context.clients,
924
  &input,
925
  context.texts,
926
+ || spatial.select(actor_point, base.tick),
927
  )?;
928
  let plan = DefuseRadioPlan {
929
  slot: *slot,
 
962
  start: u32,
963
  origin: [u32; 3],
964
  ) -> Result<Option<DefuseAllocation>, Error> {
965
+ let mut unused_lookup = |_, _| Err(Error::InvalidInput);
966
+ allocate_defuse_with(
967
+ state,
968
+ pool,
969
+ input,
970
+ branch,
971
+ start,
972
+ origin,
973
+ &mut unused_lookup,
974
+ |outcome, _| Ok(outcome),
975
+ )
976
  }
977
 
978
+ fn allocate_defuse_with<T, S: DefuseSpatial>(
979
  state: &mut crate::defuse::DefuseState,
980
  pool: &mut EntityPool,
981
  input: crate::defuse::DefuseInput,
982
  branch: DefuseBranch,
983
  start: u32,
984
  origin: [u32; 3],
985
+ spatial: &mut S,
986
+ resolve: impl FnOnce(DefuseAllocation, &mut S) -> Result<T, Error>,
987
  ) -> Result<Option<T>, Error> {
988
  use crate::defuse::{DefuseEffect, begin_defuse, cancel_defuse, finish_defuse};
989
 
 
1015
  let record = &mut next_pool.slots[index];
1016
  let initialized = record.clone();
1017
  construct_event(record, origin, event_kind, input.tick)?;
1018
+ spatial.link(index, record)?;
1019
  let link = DefuseEventLink {
1020
  slot: index,
1021
  record: record.clone(),
 
1027
  after_allocation.clear();
1028
  (None, None)
1029
  };
1030
+ let result = resolve(
1031
+ DefuseAllocation {
1032
+ event_kind,
1033
+ allocation,
1034
+ initialized,
1035
+ link,
1036
+ before_allocation: effects,
1037
+ after_allocation,
1038
+ },
1039
+ spatial,
1040
+ )?;
1041
  *state = caller;
1042
  *pool = next_pool;
1043
  Ok(Some(result))
crates/urt-gameplay/src/server_entities.rs CHANGED
@@ -81,17 +81,12 @@ impl ServerEntities {
81
  tick: u32,
82
  level_start: u32,
83
  ) -> Result<(AllocationOutcome, Option<EntityId>), Error> {
84
- let generation = self.next_generation;
85
- let next_generation = generation.checked_add(1).ok_or(Error::InvalidCount)?;
 
 
86
  let outcome = allocate_entity(&mut self.pool, tick, level_start)?;
87
- if let Some(&count) = outcome.registrations.last() {
88
- self.registered_count = count;
89
- }
90
- let id = outcome.selected.map(|slot| {
91
- self.next_generation = next_generation;
92
- self.generations[slot] = generation;
93
- EntityId { slot, generation }
94
- });
95
  Ok((outcome, id))
96
  }
97
 
@@ -157,3 +152,107 @@ impl ServerEntities {
157
  Ok(())
158
  }
159
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
81
  tick: u32,
82
  level_start: u32,
83
  ) -> Result<(AllocationOutcome, Option<EntityId>), Error> {
84
+ let next_generation = self
85
+ .next_generation
86
+ .checked_add(1)
87
+ .ok_or(Error::InvalidCount)?;
88
  let outcome = allocate_entity(&mut self.pool, tick, level_start)?;
89
+ let id = self.note_allocation(&outcome, next_generation);
 
 
 
 
 
 
 
90
  Ok((outcome, id))
91
  }
92
 
 
152
  Ok(())
153
  }
154
  }
155
+
156
+ /// Slot-indexed location records and recipient state at the callback boundary.
157
+ pub struct ServerDefuseRadio<'a> {
158
+ pub entries: &'a [Option<crate::location_feedback::LocationEntry>],
159
+ pub lookup: crate::location_feedback::LocationLookup<'a>,
160
+ pub mode: u32,
161
+ pub clients: &'a [crate::effect_feedback::RadioClient],
162
+ pub texts: &'a [Vec<u8>],
163
+ pub active_server: bool,
164
+ }
165
+
166
+ struct ServerDefuseSpatial<'a, 'map> {
167
+ visibility: &'a crate::world_visibility::WorldVisibility<'a, 'map>,
168
+ links: &'a mut EntityLinks,
169
+ entries: &'a [Option<crate::location_feedback::LocationEntry>],
170
+ lookup: crate::location_feedback::LocationLookup<'a>,
171
+ active_server: bool,
172
+ }
173
+
174
+ impl crate::location_feedback::DefuseSpatial for ServerDefuseSpatial<'_, '_> {
175
+ fn link(&mut self, slot: usize, record: &mut EntitySlot) -> Result<(), Error> {
176
+ self.links
177
+ .link(self.visibility.bsp, slot, record, self.active_server)
178
+ }
179
+
180
+ fn select(
181
+ &mut self,
182
+ actor: [u32; 3],
183
+ tick: u32,
184
+ ) -> Result<crate::location_feedback::LocationSelection, Error> {
185
+ self.visibility.nearest_location(
186
+ self.links.spatial(),
187
+ self.entries,
188
+ crate::location_feedback::LocationLookup {
189
+ actor,
190
+ tick,
191
+ ..self.lookup
192
+ },
193
+ )
194
+ }
195
+ }
196
+
197
+ impl ServerEntities {
198
+ /// Allocate, register and link a defuse event in the owned pool. The
199
+ /// construction link precedes caller payload writes and location lookup.
200
+ /// Typed lookup or link failures leave server and caller state unchanged.
201
+ pub fn process_defuse(
202
+ &mut self,
203
+ visibility: &crate::world_visibility::WorldVisibility<'_, '_>,
204
+ world: &mut crate::defuse::DefuseWorld,
205
+ input: crate::defuse::FullDefuseInput,
206
+ level_start: u32,
207
+ radio: &mut crate::location_feedback::DefuseRadioState,
208
+ context: ServerDefuseRadio<'_>,
209
+ ) -> Result<crate::location_feedback::LocatedDefuseOutcome, Error> {
210
+ use crate::location_feedback::{DefuseRadioLookup, process_located_defuse_with};
211
+
212
+ let next_generation = self
213
+ .next_generation
214
+ .checked_add(1)
215
+ .ok_or(Error::InvalidCount)?;
216
+ let mut links = self.links.clone();
217
+ let outcome = process_located_defuse_with(
218
+ world,
219
+ &mut self.pool,
220
+ input,
221
+ level_start,
222
+ radio,
223
+ DefuseRadioLookup {
224
+ mode: context.mode,
225
+ clients: context.clients,
226
+ texts: context.texts,
227
+ spatial: ServerDefuseSpatial {
228
+ visibility,
229
+ links: &mut links,
230
+ entries: context.entries,
231
+ lookup: context.lookup,
232
+ active_server: context.active_server,
233
+ },
234
+ },
235
+ )?;
236
+ if let Some(allocation) = &outcome.allocation {
237
+ self.note_allocation(&allocation.allocation, next_generation);
238
+ self.links = links;
239
+ }
240
+ Ok(outcome)
241
+ }
242
+
243
+ fn note_allocation(
244
+ &mut self,
245
+ allocation: &AllocationOutcome,
246
+ next_generation: u64,
247
+ ) -> Option<EntityId> {
248
+ if let Some(&count) = allocation.registrations.last() {
249
+ self.registered_count = count;
250
+ }
251
+ allocation.selected.map(|slot| {
252
+ let generation = self.next_generation;
253
+ self.next_generation = next_generation;
254
+ self.generations[slot] = generation;
255
+ EntityId { slot, generation }
256
+ })
257
+ }
258
+ }
crates/urt-gameplay/src/spatial_index.rs CHANGED
@@ -73,7 +73,7 @@ pub struct Split {
73
  pub children: [usize; 2],
74
  }
75
 
76
- #[derive(Debug, Default)]
77
  struct Sector {
78
  split: Option<Split>,
79
  members: Vec<usize>,
@@ -85,7 +85,7 @@ struct Link {
85
  bounds: Bounds,
86
  }
87
 
88
- #[derive(Debug)]
89
  pub struct SpatialIndex {
90
  sectors: Vec<Sector>,
91
  links: Vec<Option<Link>>,
 
73
  pub children: [usize; 2],
74
  }
75
 
76
+ #[derive(Clone, Debug, Default)]
77
  struct Sector {
78
  split: Option<Split>,
79
  members: Vec<usize>,
 
85
  bounds: Bounds,
86
  }
87
 
88
+ #[derive(Clone, Debug)]
89
  pub struct SpatialIndex {
90
  sectors: Vec<Sector>,
91
  links: Vec<Option<Link>>,
crates/urt-gameplay/src/world_visibility.rs CHANGED
@@ -99,7 +99,7 @@ impl WorldVisibility<'_, '_> {
99
  mode: context.mode,
100
  clients: context.clients,
101
  texts: context.texts,
102
- select: |actor, tick| {
103
  self.nearest_location(
104
  context.index,
105
  context.entries,
 
99
  mode: context.mode,
100
  clients: context.clients,
101
  texts: context.texts,
102
+ spatial: |actor, tick| {
103
  self.nearest_location(
104
  context.index,
105
  context.entries,
docs/FINDINGS.md CHANGED
@@ -2083,3 +2083,5 @@ RE-1034–1043 batch validation passed:2,018 Python tests,339 Rust tests,146 det
2083
  - Entity relinking now updates game-record link words, ordered spatial membership and BSP area and cluster metadata together. [Entity link ownership](research/RUST_ENTITY_LINKS.md).
2084
 
2085
  - The server pool removes linked metadata on expiry and rejects an earlier occupant's handle after slot reuse. [Server entity lifetimes](research/RUST_SERVER_ENTITIES.md).
 
 
 
2083
  - Entity relinking now updates game-record link words, ordered spatial membership and BSP area and cluster metadata together. [Entity link ownership](research/RUST_ENTITY_LINKS.md).
2084
 
2085
  - The server pool removes linked metadata on expiry and rejects an earlier occupant's handle after slot reuse. [Server entity lifetimes](research/RUST_SERVER_ENTITIES.md).
2086
+
2087
+ - Defuse events now link in the owned server pool before payload publication and can expire through the same world. [Registered defuse events](research/RUST_SERVER_DEFUSE.md).
docs/PROVISIONAL_TODO.md CHANGED
@@ -2145,3 +2145,5 @@ RE-974–983 completed routing, command rewrite, inactivity, movement-parameter
2145
  - [x] RE-1068 Compose shared sector membership and BSP metadata for entity links ([evidence](research/RUST_ENTITY_LINKS.md)).
2146
 
2147
  - [x] RE-1069 Own entity registration, spatial links and slot generations in the server pool ([evidence](research/RUST_SERVER_ENTITIES.md)).
 
 
 
2145
  - [x] RE-1068 Compose shared sector membership and BSP metadata for entity links ([evidence](research/RUST_ENTITY_LINKS.md)).
2146
 
2147
  - [x] RE-1069 Own entity registration, spatial links and slot generations in the server pool ([evidence](research/RUST_SERVER_ENTITIES.md)).
2148
+
2149
+ - [x] RE-1070 Execute allocated defuse links in the registered server pool ([evidence](research/RUST_SERVER_DEFUSE.md)).
docs/RESEARCH_LEDGER.md CHANGED
@@ -2951,3 +2951,7 @@ The entity link service uses record-derived bounds, BSP leaf enumeration and sec
2951
  ## 2026-11-25 — RE-1069 Own entity registration, spatial links and slot generations in the server pool
2952
 
2953
  The server pool consumes unlink requests, invalidates freed identities and keeps registered extent bounded even at the full-pool allocator terminal. See [server entity lifetimes](research/RUST_SERVER_ENTITIES.md).
 
 
 
 
 
2951
  ## 2026-11-25 — RE-1069 Own entity registration, spatial links and slot generations in the server pool
2952
 
2953
  The server pool consumes unlink requests, invalidates freed identities and keeps registered extent bounded even at the full-pool allocator terminal. See [server entity lifetimes](research/RUST_SERVER_ENTITIES.md).
2954
+
2955
+ ## 2026-11-25 — RE-1070 Execute allocated defuse links in the registered server pool
2956
+
2957
+ The server pool now links the constructed event before the callback writes payload or resolves radio, and owns the resulting identity through expiry. See [registered defuse cases](research/RUST_SERVER_DEFUSE.md).
docs/research/README.md CHANGED
@@ -1711,3 +1711,5 @@ The extension collector adds five focused tests for native tail calls, command-r
1711
  - [Entity link ownership and BSP metadata](RUST_ENTITY_LINKS.md)
1712
 
1713
  - [Ownership of registered entity slots](RUST_SERVER_ENTITIES.md)
 
 
 
1711
  - [Entity link ownership and BSP metadata](RUST_ENTITY_LINKS.md)
1712
 
1713
  - [Ownership of registered entity slots](RUST_SERVER_ENTITIES.md)
1714
+
1715
+ - [Defuse events in the registered server pool](RUST_SERVER_DEFUSE.md)
docs/research/RUST_SERVER_DEFUSE.md ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ # Defuse events in the registered server pool
2
+
3
+ `ServerEntities::process_defuse` allocates and links the temporary event in the world that owns its slot. The construction link writes spatial membership and BSP metadata before the caller writes the event payload and before a start resolves radio. The link snapshot records this order. The server applies allocation registration and assigns a new identity when the staged callback succeeds. A typed callback error discards the staged changes.
4
+
5
+ [Five controlled cases](rust-server-defuse.json) cover start, completion, cancellation and both allocator terminals. Successful events appear in the sector index, remain linked at age 300 and disappear at 301. At either allocator terminal there is no event link or radio. Accepted radio commands and other feedback remain plans for dispatch.
docs/research/rust-server-defuse.json ADDED
@@ -0,0 +1,269 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "limits": "Controlled BSP and portal fixture. Server owns event links and expiry; external feedback remains planned.",
3
+ "probes": [
4
+ {
5
+ "expected": {
6
+ "count": 65,
7
+ "linked": {
8
+ "after": [],
9
+ "areas": [
10
+ 0,
11
+ 4294967295
12
+ ],
13
+ "before": [
14
+ 64
15
+ ],
16
+ "payload": 5,
17
+ "released": true,
18
+ "retained": [
19
+ 64
20
+ ],
21
+ "slot": 64,
22
+ "snapshot_link": 1,
23
+ "snapshot_payload": 305419896
24
+ },
25
+ "radio": {
26
+ "commands": [
27
+ {
28
+ "slot": 0,
29
+ "text": "727361792032202d3120372022506f7274616c20726f6f6d22"
30
+ },
31
+ {
32
+ "slot": 2,
33
+ "text": "727361792032202d3120372022506f7274616c20726f6f6d22"
34
+ }
35
+ ],
36
+ "getter_calls": 1,
37
+ "location_pvs": [
38
+ 0
39
+ ],
40
+ "location_queries": [
41
+ [
42
+ [
43
+ 3256877056,
44
+ 3256877056,
45
+ 3260022784
46
+ ],
47
+ [
48
+ 1109393408,
49
+ 1109393408,
50
+ 1112539136
51
+ ]
52
+ ]
53
+ ],
54
+ "location_result": 0,
55
+ "marker": [
56
+ 13500,
57
+ 1
58
+ ],
59
+ "ring": 2,
60
+ "warnings": 0
61
+ },
62
+ "registered": 65,
63
+ "status": "returned"
64
+ },
65
+ "initial_count": 64,
66
+ "profile": 0,
67
+ "rust": {
68
+ "count": 65,
69
+ "linked": {
70
+ "after": [],
71
+ "areas": [
72
+ 0,
73
+ 4294967295
74
+ ],
75
+ "before": [
76
+ 64
77
+ ],
78
+ "payload": 5,
79
+ "released": true,
80
+ "retained": [
81
+ 64
82
+ ],
83
+ "slot": 64,
84
+ "snapshot_link": 1,
85
+ "snapshot_payload": 305419896
86
+ },
87
+ "radio": {
88
+ "commands": [
89
+ {
90
+ "slot": 0,
91
+ "text": "727361792032202d3120372022506f7274616c20726f6f6d22"
92
+ },
93
+ {
94
+ "slot": 2,
95
+ "text": "727361792032202d3120372022506f7274616c20726f6f6d22"
96
+ }
97
+ ],
98
+ "getter_calls": 1,
99
+ "location_pvs": [
100
+ 0
101
+ ],
102
+ "location_queries": [
103
+ [
104
+ [
105
+ 3256877056,
106
+ 3256877056,
107
+ 3260022784
108
+ ],
109
+ [
110
+ 1109393408,
111
+ 1109393408,
112
+ 1112539136
113
+ ]
114
+ ]
115
+ ],
116
+ "location_result": 0,
117
+ "marker": [
118
+ 13500,
119
+ 1
120
+ ],
121
+ "ring": 2,
122
+ "warnings": 0
123
+ },
124
+ "registered": 65,
125
+ "status": "returned"
126
+ }
127
+ },
128
+ {
129
+ "expected": {
130
+ "count": 65,
131
+ "linked": {
132
+ "after": [],
133
+ "areas": [
134
+ 0,
135
+ 4294967295
136
+ ],
137
+ "before": [
138
+ 64
139
+ ],
140
+ "payload": 1,
141
+ "released": true,
142
+ "retained": [
143
+ 64
144
+ ],
145
+ "slot": 64,
146
+ "snapshot_link": 1,
147
+ "snapshot_payload": 305419896
148
+ },
149
+ "radio": null,
150
+ "registered": 65,
151
+ "status": "returned"
152
+ },
153
+ "initial_count": 64,
154
+ "profile": 2,
155
+ "rust": {
156
+ "count": 65,
157
+ "linked": {
158
+ "after": [],
159
+ "areas": [
160
+ 0,
161
+ 4294967295
162
+ ],
163
+ "before": [
164
+ 64
165
+ ],
166
+ "payload": 1,
167
+ "released": true,
168
+ "retained": [
169
+ 64
170
+ ],
171
+ "slot": 64,
172
+ "snapshot_link": 1,
173
+ "snapshot_payload": 305419896
174
+ },
175
+ "radio": null,
176
+ "registered": 65,
177
+ "status": "returned"
178
+ }
179
+ },
180
+ {
181
+ "expected": {
182
+ "count": 65,
183
+ "linked": {
184
+ "after": [],
185
+ "areas": [
186
+ 0,
187
+ 4294967295
188
+ ],
189
+ "before": [
190
+ 64
191
+ ],
192
+ "payload": 0,
193
+ "released": true,
194
+ "retained": [
195
+ 64
196
+ ],
197
+ "slot": 64,
198
+ "snapshot_link": 1,
199
+ "snapshot_payload": 305419896
200
+ },
201
+ "radio": null,
202
+ "registered": 65,
203
+ "status": "returned"
204
+ },
205
+ "initial_count": 64,
206
+ "profile": 3,
207
+ "rust": {
208
+ "count": 65,
209
+ "linked": {
210
+ "after": [],
211
+ "areas": [
212
+ 0,
213
+ 4294967295
214
+ ],
215
+ "before": [
216
+ 64
217
+ ],
218
+ "payload": 0,
219
+ "released": true,
220
+ "retained": [
221
+ 64
222
+ ],
223
+ "slot": 64,
224
+ "snapshot_link": 1,
225
+ "snapshot_payload": 305419896
226
+ },
227
+ "radio": null,
228
+ "registered": 65,
229
+ "status": "returned"
230
+ }
231
+ },
232
+ {
233
+ "expected": {
234
+ "count": 1022,
235
+ "linked": null,
236
+ "radio": null,
237
+ "registered": 1022,
238
+ "status": "diagnostic-loop-pending"
239
+ },
240
+ "initial_count": 1022,
241
+ "profile": 0,
242
+ "rust": {
243
+ "count": 1022,
244
+ "linked": null,
245
+ "radio": null,
246
+ "registered": 1022,
247
+ "status": "diagnostic-loop-pending"
248
+ }
249
+ },
250
+ {
251
+ "expected": {
252
+ "count": 1025,
253
+ "linked": null,
254
+ "radio": null,
255
+ "registered": 1024,
256
+ "status": "fatal-error-pending"
257
+ },
258
+ "initial_count": 1024,
259
+ "profile": 0,
260
+ "rust": {
261
+ "count": 1025,
262
+ "linked": null,
263
+ "radio": null,
264
+ "registered": 1024,
265
+ "status": "fatal-error-pending"
266
+ }
267
+ }
268
+ ]
269
+ }
scripts/analyze_rust_server_defuse.py ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Check completed spatial links and radio in the registered server callback."""
2
+ import json
3
+ import os
4
+ import subprocess
5
+ from pathlib import Path
6
+
7
+ from analyze_qvm import write_json
8
+ from analyze_rust_defuse_complete import encode as encode_callback
9
+ from analyze_rust_location_allocation import encode as encode_pool
10
+ from analyze_rust_location_radio import encode as encode_radio
11
+ from analyze_rust_world_visibility import fixture
12
+ from qvm_location_feedback_oracle import radio as model_radio
13
+
14
+
15
+ def main():
16
+ subprocess.run(['cargo', 'build', '--offline', '-p', 'urt-gameplay', '--bin',
17
+ 'urt-defuse'], check=True)
18
+ binary = Path(os.environ.get('CARGO_TARGET_DIR', 'target')) / 'debug' / 'urt-defuse'
19
+ source = json.loads(Path('docs/research/qvm-defuse-located-callback.json').read_text())
20
+ profiles = {}
21
+ for row in source['probes']:
22
+ a = row['input']
23
+ if a['allocation']['profile'] == 0:
24
+ profiles.setdefault(a['profile'], a)
25
+ probes = []
26
+ for profile, count, payload in [(0, 64, 5), (2, 64, 1), (3, 64, 0),
27
+ (0, 1022, None), (0, 1024, None)]:
28
+ a = profiles[profile]
29
+ radio = dict(a['radio'], payload=b'Portal room'.hex())
30
+ location = dict(radio['location'], cache=None, query=[], order=[0],
31
+ points=[[-5., 0., 0.], [5., 0., 0.], [8., 0., 0.]],
32
+ triggers=[0, 0, 0], visible=[1, 0, 0])
33
+ radio['location'] = location
34
+ pool = encode_pool(dict(a['allocation'], count=count))
35
+ words = [*encode_callback(a), a['event_flags'], len(pool), *pool, *encode_radio(radio)]
36
+ cmd = [str(binary), 'server-located', *[str(w & 0xffffffff) for w in words]]
37
+ rust = json.loads(subprocess.run(cmd, check=True, input=fixture(3), capture_output=True).stdout)
38
+ if payload is None:
39
+ status = 'diagnostic-loop-pending' if count == 1022 else 'fatal-error-pending'
40
+ expected = dict(status=status, count=count + (count == 1024), registered=count,
41
+ linked=None, radio=None)
42
+ else:
43
+ reply = model_radio(radio)
44
+ fields = ('commands', 'getter_calls', 'marker', 'ring', 'location_result',
45
+ 'location_queries', 'location_pvs', 'warnings')
46
+ expected = dict(status='returned', count=65, registered=65,
47
+ linked=dict(slot=64, snapshot_link=1, snapshot_payload=0x12345678,
48
+ payload=payload, areas=[0, 0xffffffff], before=[64],
49
+ retained=[64], after=[], released=True),
50
+ radio={k: reply[k] for k in fields} if profile == 0 else None)
51
+ probes.append(dict(profile=profile, initial_count=count, expected=expected, rust=rust))
52
+ write_json(Path('docs/research/rust-server-defuse.json'), {
53
+ 'probes': probes, 'limits': 'Controlled BSP and portal fixture. Server owns event links and expiry; external feedback remains planned.',
54
+ })
55
+
56
+
57
+ if __name__ == '__main__':
58
+ main()
scripts/test_rust_server_defuse.py ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import unittest
3
+ from pathlib import Path
4
+
5
+
6
+ class ServerDefuseTests(unittest.TestCase):
7
+ def test_registered_defuse_effects(self):
8
+ rows = json.loads(Path('docs/research/rust-server-defuse.json').read_text())['probes']
9
+ self.assertEqual(len(rows), 5)
10
+ for row in rows:
11
+ with self.subTest(profile=row['profile'], count=row['initial_count']):
12
+ self.assertEqual(row['rust'], row['expected'])
13
+
14
+
15
+ if __name__ == '__main__':
16
+ unittest.main()
xtask/checks.tsv CHANGED
@@ -4987,3 +4987,17 @@ edge crates/urt-gameplay/src/location_feedback.rs scripts/analyze_rust_server_en
4987
  edge crates/urt-assets/src/bsp.rs scripts/analyze_rust_server_entities.py
4988
  edge crates/urt-gameplay/src/bin/urt-server-entities.rs scripts/analyze_rust_server_entities.py
4989
  edge crates/urt-gameplay/src/server_entities.rs scripts/analyze_rust_health_impulse.py
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4987
  edge crates/urt-assets/src/bsp.rs scripts/analyze_rust_server_entities.py
4988
  edge crates/urt-gameplay/src/bin/urt-server-entities.rs scripts/analyze_rust_server_entities.py
4989
  edge crates/urt-gameplay/src/server_entities.rs scripts/analyze_rust_health_impulse.py
4990
+ report scripts/analyze_rust_server_defuse.py docs/research/rust-server-defuse.json
4991
+ edge docs/research/rust-server-defuse.json scripts/test_rust_server_defuse.py
4992
+ group rust-server-defuse scripts/analyze_rust_server_defuse.py
4993
+ group rust-server-defuse scripts/analyze_rust_server_entities.py
4994
+ group rust-server-defuse scripts/analyze_rust_defuse_world_radio.py
4995
+ group gameplay scripts/analyze_rust_server_defuse.py
4996
+ edge docs/research/qvm-defuse-located-callback.json scripts/analyze_rust_server_defuse.py
4997
+ edge crates/urt-gameplay/src/server_entities.rs scripts/analyze_rust_server_defuse.py
4998
+ edge crates/urt-gameplay/src/entity_links.rs scripts/analyze_rust_server_defuse.py
4999
+ edge crates/urt-gameplay/src/spatial_index.rs scripts/analyze_rust_server_defuse.py
5000
+ edge crates/urt-gameplay/src/defuse.rs scripts/analyze_rust_server_defuse.py
5001
+ edge crates/urt-gameplay/src/location_feedback.rs scripts/analyze_rust_server_defuse.py
5002
+ edge crates/urt-gameplay/src/world_visibility.rs scripts/analyze_rust_server_defuse.py
5003
+ edge crates/urt-gameplay/src/bin/urt-defuse.rs scripts/analyze_rust_server_defuse.py