Skip to content

fix(executor): propagate complete_turn failure instead of silent warn#648

Merged
majiayu000 merged 2 commits intomainfrom
feat/626-complete-turn-error-propagation
Apr 12, 2026
Merged

fix(executor): propagate complete_turn failure instead of silent warn#648
majiayu000 merged 2 commits intomainfrom
feat/626-complete-turn-error-propagation

Conversation

@majiayu000
Copy link
Copy Markdown
Owner

Summary

  • Fixes complete_turn 失败仅 warn,违反 U-29 禁止静默降级 #626: complete_turn failure was only logged as warn, leaving the turn state inconsistent
  • Upgrades to tracing::error! with structured thread_id and turn_id fields
  • Calls mark_turn_failed to properly mark the turn failed, persist thread state, and emit TurnCompleted{Failed} notification
  • Eliminates the silent degradation that violated U-29

Test plan

  • cargo fmt --all — clean
  • cargo clippy --workspace --all-targets -- -D warnings — clean
  • cargo test -p harness-server — all 5 turn lifecycle tests pass

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request enhances error handling in the run_turn_lifecycle function by logging detailed error information and explicitly marking turns as failed when completion fails. The review feedback suggests improving consistency with other error handling paths by recording an error item in the thread history and persisting the thread state before marking the turn as failed.

Comment on lines +301 to +317
Err(err) => {
tracing::error!(
thread_id = %thread_id,
turn_id = %turn_id,
"failed to complete turn after execution: {err}"
);
mark_turn_failed(
&server,
&thread_db,
&notify_tx,
&notification_tx,
&thread_id,
&turn_id,
err.to_string(),
)
.await;
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To maintain consistency with the error handling logic used when the agent execution itself fails (lines 319-343), consider adding an error item to the turn history and persisting the thread state before marking the turn as failed. This ensures that the system failure during the completion phase is recorded in the thread's item history, providing better visibility in the UI and audit logs.

            Err(err) => {
                let error_msg = err.to_string();
                tracing::error!(
                    thread_id = %thread_id,
                    turn_id = %turn_id,
                    "failed to complete turn after execution: {error_msg}"
                );
                if let Err(e) = server.thread_manager.add_item(
                    &thread_id,
                    &turn_id,
                    harness_core::types::Item::Error {
                        code: -1,
                        message: format!("Failed to complete turn: {error_msg}"),
                    },
                ) {
                    tracing::warn!("failed to add error item to turn: {e}");
                } else {
                    persist_runtime_thread(&thread_db, &server, &thread_id).await;
                }
                mark_turn_failed(
                    &server,
                    &thread_db,
                    &notify_tx,
                    &notification_tx,
                    &thread_id,
                    &turn_id,
                    error_msg,
                )
                .await;
            }

@majiayu000
Copy link
Copy Markdown
Owner Author

/gemini review

@gemini-code-assist
Copy link
Copy Markdown

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@github-actions
Copy link
Copy Markdown

/gemini review

@majiayu000 majiayu000 force-pushed the feat/626-complete-turn-error-propagation branch from 6aa7a6d to 87c03ea Compare April 10, 2026 13:28
@github-actions
Copy link
Copy Markdown

/gemini review

When complete_turn fails after successful agent execution, the turn state
is left inconsistent — the agent finished but no TurnCompleted notification
is emitted and the thread state is never persisted. This violates U-29
(no silent degradation when user-visible data is affected).

Fix: replace tracing::warn with tracing::error (with structured thread_id
and turn_id fields) and call mark_turn_failed so the turn is properly
marked failed, the thread is persisted, and a TurnCompleted{Failed}
notification is emitted to downstream consumers.

Closes #626

Signed-off-by: majiayu000 <1835304752@qq.com>
…failure

Before marking the turn failed when complete_turn errors, add an Error
item to the turn history and persist the thread state. This mirrors the
existing pattern used when agent execution itself fails (lines 319-343)
and ensures the failure is visible in the UI and audit logs.

Signed-off-by: majiayu000 <1835304752@qq.com>
@majiayu000 majiayu000 force-pushed the feat/626-complete-turn-error-propagation branch from 87c03ea to 28b67f9 Compare April 11, 2026 16:07
@github-actions
Copy link
Copy Markdown

/gemini review

@majiayu000 majiayu000 merged commit bd59e7c into main Apr 12, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

complete_turn 失败仅 warn,违反 U-29 禁止静默降级

1 participant