Skip to content

Commit 708f3f1

Browse files
committed
break backwards compat
1 parent 09066b5 commit 708f3f1

36 files changed

Lines changed: 150 additions & 199 deletions

File tree

cli/golem-cli/wit/deps/golem-1.x/golem-oplog.wit

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ interface oplog {
106106
initial-total-linear-memory-size: u64,
107107
initial-active-plugins: list<plugin-installation-description>,
108108
local-agent-config: list<local-agent-config-entry>,
109-
original-phantom-id: option<uuid>
109+
original-phantom-id: option<uuid>,
110+
instance-id: uuid
110111
}
111112

112113
record host-call-parameters {
@@ -454,8 +455,7 @@ interface oplog {
454455
initial-active-plugins: list<environment-plugin-grant-id>,
455456
local-agent-config: list<raw-local-agent-config-entry>,
456457
original-phantom-id: option<uuid>,
457-
/// Per-instance UUID. None for agents created before this field was introduced.
458-
instance-id: option<uuid>
458+
instance-id: uuid
459459
}
460460

461461
record raw-host-call-parameters {

golem-api-grpc/proto/golem/worker/public_oplog.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ message CreateParameters {
9797
repeated PluginInstallationDescription initial_active_plugins = 11;
9898
golem.common.EnvironmentId environment_id = 12;
9999
optional golem.common.UUID original_phantom_id = 13;
100+
golem.common.UUID instance_id = 14;
100101
}
101102

102103
message HostCallParameters {

golem-common/src/base_model/mod.rs

Lines changed: 22 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -165,72 +165,36 @@ impl FromValue for Timestamp {
165165
}
166166
}
167167

168+
/// A stable, per-instance fingerprint for a worker, generated as a random UUID at creation time.
169+
/// Globally unique across recreations of the same agent ID.
168170
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
169-
#[cfg_attr(feature = "full", derive(desert_rust::BinaryCodec))]
170-
#[cfg_attr(feature = "full", desert(evolution()))]
171-
#[serde(tag = "type", content = "value", rename_all = "camelCase")]
172-
pub enum AgentFingerprint {
173-
/// Randomly generated at worker creation time. Globally unique across recreations.
174-
Uuid(Uuid),
175-
/// Fallback for workers created before `AgentFingerprint` was introduced.
176-
/// The timestamp is the worker's `created_at` from the oplog `Create` entry.
177-
Timestamp(Timestamp),
178-
}
171+
#[cfg_attr(
172+
feature = "full",
173+
derive(
174+
desert_rust::BinaryCodec,
175+
golem_wasm_derive::IntoValue,
176+
golem_wasm_derive::FromValue,
177+
)
178+
)]
179+
#[cfg_attr(feature = "full", desert(transparent))]
180+
#[serde(transparent)]
181+
pub struct AgentFingerprint(pub Uuid);
179182

180-
impl Display for AgentFingerprint {
181-
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
182-
match self {
183-
AgentFingerprint::Uuid(u) => write!(f, "uuid:{u}"),
184-
AgentFingerprint::Timestamp(t) => write!(f, "ts:{t}"),
185-
}
183+
impl Default for AgentFingerprint {
184+
fn default() -> Self {
185+
Self::new()
186186
}
187187
}
188188

189-
#[cfg(feature = "full")]
190-
impl golem_wasm::IntoValue for AgentFingerprint {
191-
fn into_value(self) -> golem_wasm::Value {
192-
match self {
193-
AgentFingerprint::Uuid(u) => {
194-
golem_wasm::Value::Variant {
195-
case_idx: 0,
196-
case_value: Some(Box::new(u.into_value())),
197-
}
198-
}
199-
AgentFingerprint::Timestamp(ts) => golem_wasm::Value::Variant {
200-
case_idx: 1,
201-
case_value: Some(Box::new(golem_wasm::Value::U64(ts.to_millis()))),
202-
},
203-
}
204-
}
205-
206-
fn get_type() -> golem_wasm::analysis::AnalysedType {
207-
use golem_wasm::analysis::analysed_type;
208-
analysed_type::variant(vec![
209-
analysed_type::case("uuid", Uuid::get_type()),
210-
analysed_type::case("timestamp", u64::get_type()),
211-
])
189+
impl AgentFingerprint {
190+
pub fn new() -> Self {
191+
AgentFingerprint(Uuid::now_v7())
212192
}
213193
}
214194

215-
#[cfg(feature = "full")]
216-
impl golem_wasm::FromValue for AgentFingerprint {
217-
fn from_value(value: golem_wasm::Value) -> Result<Self, String> {
218-
match value {
219-
golem_wasm::Value::Variant {
220-
case_idx: 0,
221-
case_value: Some(inner),
222-
} => Ok(AgentFingerprint::Uuid(Uuid::from_value(*inner)?)),
223-
golem_wasm::Value::Variant {
224-
case_idx: 1,
225-
case_value: Some(inner),
226-
} => match *inner {
227-
golem_wasm::Value::U64(millis) => {
228-
Ok(AgentFingerprint::Timestamp(Timestamp::from(millis)))
229-
}
230-
other => Err(format!("Expected U64 for Timestamp fingerprint, got {other:?}")),
231-
},
232-
other => Err(format!("Expected Variant for AgentFingerprint, got {other:?}")),
233-
}
195+
impl Display for AgentFingerprint {
196+
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
197+
write!(f, "{}", self.0)
234198
}
235199
}
236200

golem-common/src/base_model/oplog/mod.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ use raw_imports::*;
6565
// - public: fields of the PublicOplogEntry case
6666
oplog_entry! {
6767
/// The first entry of every oplog
68-
#[desert(evolution(FieldAdded("instance_id", None)))]
6968
Create {
7069
hint: false
7170
wit_raw_type: "raw-create-parameters"
@@ -82,7 +81,8 @@ oplog_entry! {
8281
initial_active_plugins: HashSet<EnvironmentPluginGrantId>,
8382
local_agent_config: Vec<UntypedAgentConfigEntry>,
8483
original_phantom_id: Option<Uuid>,
85-
instance_id: Option<Uuid>
84+
/// Per-instance fingerprint, unique across recreations of the same agent ID.
85+
instance_id: Uuid
8686
}
8787
public {
8888
agent_id: AgentId,
@@ -95,7 +95,8 @@ oplog_entry! {
9595
initial_total_linear_memory_size: u64,
9696
initial_active_plugins: BTreeSet<PluginInstallationDescription>,
9797
local_agent_config: Vec<TypedAgentConfigEntry>,
98-
original_phantom_id: Option<Uuid>
98+
original_phantom_id: Option<Uuid>,
99+
instance_id: Uuid
99100
}
100101
},
101102
/// The agent invoked a host function

golem-common/src/model/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,12 +341,11 @@ pub enum ScheduledAction {
341341
/// mismatch means the original worker was deleted and a new one was created with the same
342342
/// ID — the invocation is silently dropped. `None` means fire unconditionally (used for
343343
/// legacy entries and non-wasm-rpc invocations).
344-
#[desert(evolution(FieldAdded("target_worker_fingerprint", None)))]
345344
Invoke {
346345
account_id: AccountId,
347346
owned_agent_id: OwnedAgentId,
348347
invocation: Box<AgentInvocation>,
349-
target_worker_fingerprint: Option<AgentFingerprint>,
348+
target_worker_fingerprint: AgentFingerprint,
350349
},
351350
/// Resume the agent
352351
Resume {

golem-common/src/model/oplog/payload/types.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1341,7 +1341,7 @@ pub enum SerializableWebsocketError {
13411341
}
13421342

13431343
#[derive(Debug, Clone, PartialEq, BinaryCodec, IntoValue, FromValue)]
1344-
#[desert(evolution(FieldAdded("target_worker_fingerprint", None)))]
1344+
#[desert(evolution())]
13451345
#[wit_transparent]
13461346
pub struct SerializableScheduledInvocation {
13471347
pub timestamp: i64,
@@ -1355,7 +1355,7 @@ pub struct SerializableScheduledInvocation {
13551355
pub trace_id: TraceId,
13561356
pub trace_states: Vec<String>,
13571357
pub spans: Vec<Vec<PublicSpanData>>,
1358-
pub target_worker_fingerprint: Option<AgentFingerprint>,
1358+
pub target_worker_fingerprint: AgentFingerprint,
13591359
}
13601360

13611361
impl SerializableScheduledInvocation {

golem-common/src/model/oplog/protobuf.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,11 @@ use super::{
2525
StringAttributeValue, WriteRemoteBatchedParameters, WriteRemoteTransactionParameters,
2626
};
2727
use crate::base_model::OplogIndex;
28-
use crate::model::AgentInvocationResult;
2928
use crate::model::Empty;
3029
use crate::model::agent::DataValue;
31-
use crate::model::agent::UntypedDataValue;
3230
use crate::model::component::PluginPriority;
3331
use crate::model::invocation_context::{SpanId, TraceId};
3432
use crate::model::oplog::payload::OplogPayload;
35-
use crate::model::oplog::payload::host_functions::{
36-
HostFunctionName, host_request_from_value_and_type, host_response_from_value_and_type,
37-
};
3833
use crate::model::oplog::public_oplog_entry::{
3934
ActivatePluginParams, AgentInvocationFinishedParams, AgentInvocationStartedParams,
4035
BeginAtomicRegionParams, BeginRemoteTransactionParams, BeginRemoteWriteParams,
@@ -315,6 +310,10 @@ impl TryFrom<golem_api_grpc::proto::golem::worker::OplogEntry> for PublicOplogEn
315310
.collect::<Result<Vec<_>, _>>()?,
316311
),
317312
original_phantom_id: create.original_phantom_id.map(|id| id.into()),
313+
instance_id: create
314+
.instance_id
315+
.map(|id| id.into())
316+
.ok_or("Missing instance_id in Create entry")?,
318317
})),
319318
oplog_entry::Entry::HostCall(host_call) => {
320319
Ok(PublicOplogEntry::HostCall(HostCallParams {
@@ -759,6 +758,7 @@ impl TryFrom<PublicOplogEntry> for golem_api_grpc::proto::golem::worker::OplogEn
759758
.map(Into::into)
760759
.collect(),
761760
original_phantom_id: create.original_phantom_id.map(|id| id.into()),
761+
instance_id: Some(create.instance_id.into()),
762762
},
763763
)),
764764
},
@@ -2419,7 +2419,7 @@ impl TryFrom<OplogEntry> for golem_api_grpc::proto::golem::worker::RawOplogEntry
24192419
.map(|e| crate::serialization::serialize(&e))
24202420
.collect::<Result<Vec<_>, _>>()?,
24212421
original_phantom_id: original_phantom_id.map(Into::into),
2422-
instance_id: instance_id.map(Into::into),
2422+
instance_id: Some(instance_id.into()),
24232423
}),
24242424
OplogEntry::HostCall {
24252425
function_name,
@@ -2750,10 +2750,10 @@ impl TryFrom<golem_api_grpc::proto::golem::worker::RawOplogEntry> for OplogEntry
27502750
let proto_uuid: golem_api_grpc::proto::golem::common::Uuid = u;
27512751
uuid::Uuid::from(proto_uuid)
27522752
});
2753-
let instance_id: Option<uuid::Uuid> = p.instance_id.map(|u| {
2754-
let proto_uuid: golem_api_grpc::proto::golem::common::Uuid = u;
2755-
uuid::Uuid::from(proto_uuid)
2756-
});
2753+
let instance_id: uuid::Uuid = p
2754+
.instance_id
2755+
.map(uuid::Uuid::from)
2756+
.ok_or("Missing instance_id in Create entry")?;
27572757
Ok(OplogEntry::Create {
27582758
timestamp,
27592759
agent_id,

golem-common/src/model/oplog/tests.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ fn create_serialization_poem_serde_equivalence() {
9393
parameters: BTreeMap::new(),
9494
}]),
9595
original_phantom_id: None,
96+
instance_id: Uuid::new_v4(),
9697
});
9798
let serialized = entry.to_json_string();
9899
let deserialized: PublicOplogEntry = serde_json::from_str(&serialized).unwrap();

golem-common/src/model/tests.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ use crate::model::environment::EnvironmentId;
1717
use crate::model::oplog::{OplogIndex, TimestampedUpdateDescription, UpdateDescription};
1818
use crate::model::worker::TypedAgentConfigEntry;
1919
use crate::model::{
20-
AccountId, AgentFilter, AgentFingerprint, AgentId, AgentInvocation, AgentMetadata, AgentStatus, AgentStatusRecord, ComponentId, FilterComparator, IdempotencyKey, StringFilterComparator, Timestamp, TimestampedAgentInvocation
20+
AccountId, AgentFilter, AgentFingerprint, AgentId, AgentInvocation, AgentMetadata, AgentStatus,
21+
AgentStatusRecord, ComponentId, FilterComparator, IdempotencyKey, StringFilterComparator,
22+
Timestamp, TimestampedAgentInvocation,
2123
};
2224
use desert_rust::BinaryCodec;
2325
use golem_wasm::ValueAndType;
@@ -226,7 +228,7 @@ fn worker_filter_matches() {
226228
..AgentStatusRecord::default()
227229
},
228230
original_phantom_id: None,
229-
fingerprint: AgentFingerprint::Uuid(Uuid::now_v7())
231+
fingerprint: AgentFingerprint(Uuid::now_v7()),
230232
};
231233

232234
assert!(

golem-common/wit/deps/golem-1.x/golem-oplog.wit

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ interface oplog {
106106
initial-total-linear-memory-size: u64,
107107
initial-active-plugins: list<plugin-installation-description>,
108108
local-agent-config: list<local-agent-config-entry>,
109-
original-phantom-id: option<uuid>
109+
original-phantom-id: option<uuid>,
110+
instance-id: uuid
110111
}
111112

112113
record host-call-parameters {
@@ -454,8 +455,7 @@ interface oplog {
454455
initial-active-plugins: list<environment-plugin-grant-id>,
455456
local-agent-config: list<raw-local-agent-config-entry>,
456457
original-phantom-id: option<uuid>,
457-
/// Per-instance UUID. None for agents created before this field was introduced.
458-
instance-id: option<uuid>
458+
instance-id: uuid
459459
}
460460

461461
record raw-host-call-parameters {

0 commit comments

Comments
 (0)