Skip to content

Commit 1ec7ef7

Browse files
CopilotTheaxiom
andcommitted
Fix RefinementApplied event handling: error on missing code_diff, use payload timestamp, refactor WorkflowRegistered pattern matching
Co-authored-by: Theaxiom <57013+Theaxiom@users.noreply.github.com>
1 parent 8ee1136 commit 1ec7ef7

File tree

1 file changed

+30
-16
lines changed

1 file changed

+30
-16
lines changed

orchestrator/core/src/infrastructure/temporal_event_listener.rs

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,10 @@ impl TemporalEventListener {
325325
.iteration_number
326326
.ok_or_else(|| anyhow!("Missing iteration_number for RefinementApplied event"))?;
327327

328-
let diff_val = payload.code_diff.clone().unwrap_or_default();
328+
let diff_val = payload
329+
.code_diff
330+
.clone()
331+
.ok_or_else(|| anyhow!("Missing code_diff for RefinementApplied event"))?;
329332
let diff_str = match diff_val {
330333
serde_json::Value::String(s) => s,
331334
_ => diff_val.to_string(),
@@ -336,12 +339,17 @@ impl TemporalEventListener {
336339
diff: diff_str,
337340
};
338341

342+
let applied_at = match DateTime::parse_from_rfc3339(&payload.timestamp) {
343+
Ok(dt) => dt.with_timezone(&Utc),
344+
Err(_) => Utc::now(),
345+
};
346+
339347
let domain_event = crate::domain::events::ExecutionEvent::RefinementApplied {
340348
execution_id,
341349
agent_id,
342350
iteration_number,
343351
code_diff,
344-
applied_at: chrono::Utc::now(),
352+
applied_at,
345353
};
346354

347355
self.execution_repository
@@ -363,22 +371,28 @@ impl TemporalEventListener {
363371
let domain_event = TemporalEventMapper::to_domain_event(&payload)
364372
.context("Failed to map Temporal event to domain event")?;
365373

374+
// Definition-time event — no execution_id exists.
375+
// Publish to the event bus so subscribers are notified, then return early.
376+
if let WorkflowEvent::WorkflowRegistered { .. } = &domain_event {
377+
self.event_bus
378+
.publish_workflow_event(domain_event.clone());
379+
return Ok(String::new());
380+
}
381+
382+
// All remaining workflow events are execution-scoped and carry an execution_id.
366383
let execution_id_obj = match &domain_event {
367-
WorkflowEvent::WorkflowRegistered { .. } => {
368-
// Definition-time event — no execution_id exists.
369-
// Publish to the event bus so subscribers are notified, then return early.
370-
self.event_bus.publish_workflow_event(domain_event.clone());
371-
return Ok(String::new());
384+
WorkflowEvent::WorkflowExecutionStarted { execution_id, .. }
385+
| WorkflowEvent::WorkflowStateEntered { execution_id, .. }
386+
| WorkflowEvent::WorkflowStateExited { execution_id, .. }
387+
| WorkflowEvent::WorkflowIterationStarted { execution_id, .. }
388+
| WorkflowEvent::WorkflowIterationCompleted { execution_id, .. }
389+
| WorkflowEvent::WorkflowIterationFailed { execution_id, .. }
390+
| WorkflowEvent::WorkflowExecutionCompleted { execution_id, .. }
391+
| WorkflowEvent::WorkflowExecutionFailed { execution_id, .. }
392+
| WorkflowEvent::WorkflowExecutionCancelled { execution_id, .. } => {
393+
*execution_id
372394
}
373-
WorkflowEvent::WorkflowExecutionStarted { execution_id, .. } => *execution_id,
374-
WorkflowEvent::WorkflowStateEntered { execution_id, .. } => *execution_id,
375-
WorkflowEvent::WorkflowStateExited { execution_id, .. } => *execution_id,
376-
WorkflowEvent::WorkflowIterationStarted { execution_id, .. } => *execution_id,
377-
WorkflowEvent::WorkflowIterationCompleted { execution_id, .. } => *execution_id,
378-
WorkflowEvent::WorkflowIterationFailed { execution_id, .. } => *execution_id,
379-
WorkflowEvent::WorkflowExecutionCompleted { execution_id, .. } => *execution_id,
380-
WorkflowEvent::WorkflowExecutionFailed { execution_id, .. } => *execution_id,
381-
WorkflowEvent::WorkflowExecutionCancelled { execution_id, .. } => *execution_id,
395+
WorkflowEvent::WorkflowRegistered { .. } => unreachable!("handled above"),
382396
};
383397

384398
let execution_id_str = execution_id_obj.0.to_string();

0 commit comments

Comments
 (0)