Skip to content

Commit e8f8e23

Browse files
committed
fix(nightshift): fix already-running race, Codex completion, and upstream compat
- Drop RunGuard before emitting run-completed event to prevent race where user clicks Run Now before RUNNING_PROJECTS is cleared - Use has_content (text + tool_calls + content_blocks) instead of just full_content for Codex error/fallback checks — prevents false chat:error when Codex works via tools with no text output - Add nightshift fields to new upstream Session constructor site
1 parent 57635b5 commit e8f8e23

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

src-tauri/src/chat/codex.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1838,7 +1838,9 @@ pub fn tail_codex_output(
18381838
}
18391839
}
18401840

1841-
if !error_emitted && !error_lines.is_empty() && full_content.is_empty() {
1841+
let has_content = !full_content.is_empty() || !content_blocks.is_empty() || !tool_calls.is_empty();
1842+
1843+
if !error_emitted && !error_lines.is_empty() && !has_content {
18421844
let error_text = error_lines.join("\n");
18431845
log::warn!("Codex CLI error output for session {session_id}: {error_text}");
18441846

@@ -1855,7 +1857,7 @@ pub fn tail_codex_output(
18551857
}
18561858

18571859
// Fallback: process died silently with no content and no error emitted
1858-
if !error_emitted && !completed && full_content.is_empty() && cancelled {
1860+
if !error_emitted && !completed && !has_content && cancelled {
18591861
log::warn!("Codex process died silently for session {session_id} with no output");
18601862
let _ = app.emit_all(
18611863
"chat:error",

src-tauri/src/chat/storage.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -776,6 +776,9 @@ where
776776
last_run_execution_mode: None,
777777
label: None,
778778
queued_messages: vec![],
779+
source: None,
780+
nightshift_check_id: None,
781+
nightshift_run_id: None,
779782
}
780783
};
781784
hydrated_sessions.push(session);

src-tauri/src/nightshift/engine.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -714,6 +714,16 @@ pub fn execute_run(params: &RunParams<'_>) {
714714
log::error!("Failed to save final nightshift run: {e}");
715715
}
716716

717+
log::trace!(
718+
"Nightshift run {run_id} completed: status={:?}, checks={}",
719+
run.status,
720+
run.check_results.len()
721+
);
722+
723+
// Release project lock BEFORE notifying frontend — prevents "already running"
724+
// race where user clicks Run Now immediately after seeing the completion toast
725+
drop(_guard);
726+
717727
let _ = app.emit_all(
718728
"nightshift:run-completed",
719729
&RunCompletedEvent {
@@ -724,14 +734,6 @@ pub fn execute_run(params: &RunParams<'_>) {
724734
worktree_id: Some(worktree.id.clone()),
725735
},
726736
);
727-
728-
// _guard handles cleanup_run + mark_project_done on drop
729-
730-
log::trace!(
731-
"Nightshift run {run_id} completed: status={:?}, checks={}",
732-
run.status,
733-
run.check_results.len()
734-
);
735737
}
736738

737739
/// Start a nightshift run in a background thread. Returns the run ID.

0 commit comments

Comments
 (0)