Skip to content

Commit 8f3468f

Browse files
committed
fix: success path + add test, cursor feedback
1 parent 55674ae commit 8f3468f

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

packages/optimization/src/ldai_optimization/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2209,7 +2209,7 @@ async def _run_optimization(
22092209
optimize_context, iteration
22102210
)
22112211
if all_valid:
2212-
return self._handle_success(last_ctx, iteration)
2212+
return self._handle_success(optimize_context, iteration)
22132213
# Validation failed — treat as a normal failed attempt.
22142214
# Use optimize_context (the main iteration) for terminal API events so
22152215
# the persisted record's completionResponse and userInput stay aligned.

packages/optimization/tests/test_client.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,6 +1101,24 @@ async def test_on_turn_manual_path_success(self):
11011101
result = await client.optimize_from_options("test-agent", options)
11021102
assert result.completion_response == "Answer."
11031103

1104+
async def test_success_result_carries_main_iteration_context_not_validation_context(self):
1105+
# The main iteration returns "Main answer." but the validation run returns
1106+
# "Validation answer.". The result should reflect the main iteration so that
1107+
# completion_response and user_input are consistent with what was POSTed to the API.
1108+
agent_responses = [
1109+
OptimizationResponse(output="Main answer."), # main iteration
1110+
OptimizationResponse(output="Validation answer."), # validation sample
1111+
]
1112+
handle_agent_call = AsyncMock(side_effect=agent_responses)
1113+
handle_judge_call = AsyncMock(return_value=OptimizationResponse(output=JUDGE_PASS_RESPONSE))
1114+
client = _make_client(self.mock_ldai)
1115+
options = _make_options(
1116+
handle_agent_call=handle_agent_call,
1117+
handle_judge_call=handle_judge_call,
1118+
)
1119+
result = await client.optimize_from_options("test-agent", options)
1120+
assert result.completion_response == "Main answer."
1121+
11041122
async def test_status_update_callback_called_at_each_stage(self):
11051123
statuses = []
11061124
handle_agent_call = AsyncMock(return_value=OptimizationResponse(output="Good answer."))

0 commit comments

Comments
 (0)