Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,11 @@ extension SessionStore {
isBootstrap: true
)
obs.applySnapshotProjection(state.toDetailSnapshotProjection())
obs.diff = state.currentDiff
obs.plan = state.currentPlan
obs.turnDiffs = state.turnDiffs
obs.currentTurnId = state.currentTurnId
obs.turnCount = state.turnCount
obs.subagents = state.subagents
let transition = SessionControlStateReducer.snapshotTransition(
current: controlState(sessionId: state.id, observable: obs),
Expand Down
22 changes: 20 additions & 2 deletions orbitdock-server/crates/connector-core/src/transition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,9 @@ pub fn transition(
})));
}

// Clear current_diff now that it has been archived into turn_diffs
state.current_diff = None;

// Finalize any tool messages stuck at is_in_progress before status change
effects.extend(finalize_in_progress_rows(
&sid,
Expand All @@ -595,6 +598,7 @@ pub fn transition(
work_status: Some(WorkStatus::Waiting),
last_activity_at: Some(now.to_string()),
current_turn_id: Some(None),
current_diff: Some(None),
..Default::default()
},
})));
Expand Down Expand Up @@ -3379,20 +3383,34 @@ mod tests {

let (new_state, effects) = transition(state, Input::TurnCompleted, NOW);

// Diff should be snapshotted
// Diff should be snapshotted into turn_diffs
assert_eq!(new_state.turn_diffs.len(), 1);
assert_eq!(new_state.turn_diffs[0].turn_id, "turn-1");
assert!(new_state.turn_diffs[0].diff.contains("+new"));

// Turn ID should be cleared
// Turn ID and current_diff should be cleared
assert!(new_state.current_turn_id.is_none());
assert!(
new_state.current_diff.is_none(),
"current_diff should be cleared after archiving into turn_diffs"
);

// Should emit TurnDiffSnapshot
let has_snapshot = effects.iter().any(|e| matches!(
e,
Effect::Emit(ref msg) if matches!(msg.as_ref(), ServerMessage::TurnDiffSnapshot { .. })
));
assert!(has_snapshot, "should emit TurnDiffSnapshot");

// SessionDelta should clear current_diff
let clears_diff = effects.iter().any(|e| match e {
Effect::Emit(msg) => match msg.as_ref() {
ServerMessage::SessionDelta { changes, .. } => changes.current_diff == Some(None),
_ => false,
},
_ => false,
});
assert!(clears_diff, "SessionDelta should clear current_diff");
}

#[test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,12 @@ pub(super) fn execute_command(
params![session_id, turn_id, diff, input_tokens as i64, output_tokens as i64, cached_tokens as i64, context_window as i64],
)?;

// Clear current_diff now that the turn diff has been archived
conn.execute(
"UPDATE sessions SET current_diff = NULL WHERE id = ?1",
params![session_id],
)?;

upsert_usage_turn_snapshot(
conn,
&session_id,
Expand Down
Loading