Skip to content

Commit dfbbdae

Browse files
Integrate Wave-Native Network (WNN) constraints into DSM
- Introduced `WnnTelemetry` struct and hard limits to `DeterministicSafetyMonitor` (`WNN_MAX_CURVATURE_PROXY`, `WNN_MIN_OSCILLATORY_PREFACTOR`). - Implemented `pollWnnAndEnforce` method to evaluate WNN parameters and execute immediate rollback on constraint violation. - Expanded `ITLEntry` structures with `WnnAlertPayload` and `WNN_ALERT` to ensure persistent ledger trace of trigger events via `ITLManager::log_wnn_rollback_event`. - Instantiated `StateSnapshotBuffer` using lock-free `TelemetryRingBuffer` to safely record and non-destructively peek (`try_peek_latest`) the last known safe state. - Wired the WNN limit breach to `execute_rollback_plan` without introducing dynamic memory allocation. Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
1 parent 975979e commit dfbbdae

8 files changed

Lines changed: 127 additions & 3 deletions

File tree

include/core/raps_definitions.hpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,11 @@ struct ITLEntry {
106106
AileeStatus status;
107107
};
108108

109+
struct WnnAlertPayload {
110+
double curvature_proxy;
111+
double oscillatory_prefactor;
112+
};
113+
109114
// --- Union Payload Container ---
110115

111116
union PayloadData {
@@ -123,6 +128,7 @@ struct ITLEntry {
123128
AileeSafetyStatusPayload ailee_safety_status;
124129
AileeGraceResultPayload ailee_grace_result;
125130
AileeConsensusResultPayload ailee_consensus_result;
131+
WnnAlertPayload wnn_alert;
126132
};
127133

128134
// --- Entry Type ---
@@ -144,7 +150,8 @@ struct ITLEntry {
144150
SUPERVISOR_EXCEPTION,
145151
AILEE_SAFETY_STATUS,
146152
AILEE_GRACE_RESULT,
147-
AILEE_CONSENSUS_RESULT
153+
AILEE_CONSENSUS_RESULT,
154+
WNN_ALERT
148155
};
149156

150157
// --- ITL Entry Header ---

include/itl/itl_manager.hpp

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
#include <cstddef>
44
#include <cstdint>
55

6-
#include "RAPSDefinitions.hpp"
7-
#include "PlatformHAL.hpp"
6+
#include "core/raps_definitions.hpp"
7+
#include "platform/platform_hal.hpp"
88

99
// Immutable Telemetry Ledger (ITL) Manager
1010
// Owns queueing, durability, flash IO, and Merkle batching lifecycle.
@@ -35,4 +35,23 @@ class ITLManager {
3535

3636
// Background processing (low-priority task)
3737
void flush_pending();
38+
39+
// Log WNN rollback event
40+
void log_wnn_rollback_event(double curvature, double prefactor);
3841
};
42+
43+
inline void ITLManager::log_wnn_rollback_event(double curvature, double prefactor) {
44+
ITLEntry wnn_entry{};
45+
wnn_entry.type = ITLEntry::Type::WNN_ALERT;
46+
wnn_entry.timestamp_ms = PlatformHAL::now_ms();
47+
wnn_entry.payload.wnn_alert.curvature_proxy = curvature;
48+
wnn_entry.payload.wnn_alert.oscillatory_prefactor = prefactor;
49+
commit(wnn_entry);
50+
51+
ITLEntry rollback_entry{};
52+
rollback_entry.type = ITLEntry::Type::ROLLBACK_COMMIT;
53+
rollback_entry.timestamp_ms = PlatformHAL::now_ms();
54+
// Payload for rollback commit (CommandExecutionPayload)
55+
// we just commit the entry to mark the rollback execution triggered by WNN
56+
commit(rollback_entry);
57+
}

include/raps/safety/deterministic_safety_monitor.hpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
#include <iostream>
55
#include <limits>
66

7+
#include "raps/rollback_execution.hpp"
8+
#include "itl/itl_manager.hpp"
9+
710
// =====================================================
811
// Deterministic Safety Monitor (DSM)
912
// =====================================================
@@ -25,8 +28,17 @@ constexpr double MAX_TCC_COUPLING_J = 1.0e+04;
2528
// Failsafe parameters
2629
constexpr double MIN_RESONANCE_AMPLITUDE_CUTOFF = 0.10;
2730

31+
// WNN Constraints
32+
constexpr double WNN_MAX_CURVATURE_PROXY = 5.0e-11;
33+
constexpr double WNN_MIN_OSCILLATORY_PREFACTOR = 0.85;
34+
2835
} // namespace DSM_Config
2936

37+
struct WnnTelemetry {
38+
double curvature_proxy;
39+
double oscillatory_prefactor;
40+
};
41+
3042
// =====================================================
3143
// DSM Sensor Inputs (Independent Channels)
3244
// =====================================================
@@ -55,6 +67,14 @@ class DeterministicSafetyMonitor {
5567

5668
int evaluateSafety(const DsmSensorInputs& inputs);
5769

70+
bool pollWnnAndEnforce(
71+
const WnnTelemetry& wnn_telem,
72+
ITLManager& itl_manager,
73+
const RollbackPlan* rollback_store,
74+
uint32_t rollback_count,
75+
PhysicsState& active_state_pointer
76+
);
77+
5878
private:
5979
double last_estimated_Rmax_;
6080
bool safing_sequence_active_;
@@ -164,3 +184,26 @@ DeterministicSafetyMonitor::evaluateSafety(
164184

165185
return ACTION_NONE;
166186
}
187+
188+
inline bool
189+
DeterministicSafetyMonitor::pollWnnAndEnforce(
190+
const WnnTelemetry& wnn_telem,
191+
ITLManager& itl_manager,
192+
const RollbackPlan* rollback_store,
193+
uint32_t rollback_count,
194+
PhysicsState& active_state_pointer
195+
) {
196+
if (wnn_telem.curvature_proxy > DSM_Config::WNN_MAX_CURVATURE_PROXY ||
197+
wnn_telem.oscillatory_prefactor < DSM_Config::WNN_MIN_OSCILLATORY_PREFACTOR) {
198+
199+
// Breach detected! Log to ITL and execute immediate rollback
200+
itl_manager.log_wnn_rollback_event(wnn_telem.curvature_proxy, wnn_telem.oscillatory_prefactor);
201+
202+
return trigger_wnn_immediate_rollback(
203+
rollback_store,
204+
rollback_count,
205+
active_state_pointer
206+
);
207+
}
208+
return false; // No breach
209+
}

include/raps/telemetry/telemetry_ring_buffer.hpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,18 @@ class TelemetryRingBuffer final {
4343
return true;
4444
}
4545

46+
// Peek the latest written item without popping.
47+
bool try_peek_latest(T& out) const noexcept {
48+
const uint64_t w = _write_idx.load(std::memory_order_acquire);
49+
const uint64_t r = _read_idx.load(std::memory_order_relaxed);
50+
51+
if (r == w) return false;
52+
53+
// The most recent valid write is at w - 1
54+
out = _data[(w - 1) & (CapacityPow2 - 1)];
55+
return true;
56+
}
57+
4658
// Pop one item if available.
4759
bool try_pop(T& out) noexcept {
4860
const uint64_t r = _read_idx.load(std::memory_order_relaxed);

src/itl/itl_payload_sizing.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ inline size_t itl_effective_payload_len(
4949
case ITLEntry::Type::AILEE_CONSENSUS_RESULT:
5050
return sizeof(ITLEntry::AileeConsensusResultPayload);
5151

52+
case ITLEntry::Type::WNN_ALERT:
53+
return sizeof(ITLEntry::WnnAlertPayload);
54+
5255
default:
5356
return 0;
5457
}

src/itl/itl_state_snapshot.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#pragma once
22

3+
#include "itl/itl_manager.hpp"
4+
35
inline void commit_state_snapshot(
46
ITLManager& itl_manager,
57
const PhysicsState& current_state) {

src/raps/rollback_execution.hpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include "raps/core/raps_core_types.hpp"
88
#include "platform/platform_hal.hpp"
9+
#include "safety/rollback_store.hpp"
910

1011
// Executes a rollback plan via the actuator interface.
1112
// Returns true if execution succeeded.
@@ -45,3 +46,30 @@ inline bool execute_rollback_plan(
4546
RAPSConfig::WATCHDOG_MS / 4
4647
);
4748
}
49+
50+
// Triggers an immediate rollback due to WNN constraints breach
51+
inline bool trigger_wnn_immediate_rollback(
52+
const RollbackPlan* rollback_store,
53+
uint32_t rollback_count,
54+
PhysicsState& active_state_pointer
55+
) {
56+
if (rollback_count == 0) {
57+
return false;
58+
}
59+
60+
const RollbackPlan& latest_plan = rollback_store[rollback_count - 1];
61+
62+
std::string tx_id;
63+
if (!execute_rollback_plan(latest_plan, tx_id)) {
64+
return false;
65+
}
66+
67+
// Peek the latest snapshot without destructive reading
68+
PhysicsState last_valid_snapshot;
69+
if (StateSnapshotBuffer.try_peek_latest(last_valid_snapshot)) {
70+
// Point the active state pointer to the last valid state
71+
active_state_pointer = last_valid_snapshot;
72+
}
73+
74+
return true;
75+
}

src/safety/rollback_store.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,16 @@
33
#include <optional>
44
#include <cstring>
55

6+
#include "raps/telemetry/telemetry_ring_buffer.hpp"
7+
#include "itl/itl_state_snapshot.hpp"
8+
9+
// Continuous, statically allocated snapshot buffer
10+
inline raps::telemetry::TelemetryRingBuffer<PhysicsState, 64> StateSnapshotBuffer;
11+
12+
inline void store_state_snapshot_tick(const PhysicsState& state) {
13+
StateSnapshotBuffer.try_push(state);
14+
}
15+
616
inline void store_rollback_plan(
717
RollbackPlan* rollback_store,
818
uint32_t& rollback_count,

0 commit comments

Comments
 (0)