refactor: fold tool-call and nudge accumulators into turn state (#2803 slice 3)#2820
Merged
Conversation
…slice 3) Eliminate the remaining by-reference accumulator params smuggled through datamachine_build_provider_turn_adapter() by folding last_tool_calls, all_tool_calls, and completion_nudges onto DataMachineProviderTurnState. The adapter factory drops its last three by-ref params (6 -> 0 by-ref): slices 1+2 already absorbed latest_messages, latest_turn_count, and last_request_metadata; this slice absorbs the tool-call and nudge accumulators so all per-turn mutable state flows through one object. Reads in the failure-path error result and the result normalizer now source the same values from $turn_state at the same points, keeping behavior byte-for-byte identical across every conversation path.
Contributor
Homeboy Results —
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Third scoped slice of #2803. Eliminates the remaining by-reference parameter smuggling in
conversation-loop.phpby folding the per-turn mutable accumulators onto the existingDataMachineProviderTurnStateobject. This is a state-plumbing refactor only — behavior is byte-for-byte identical across every conversation path.Slices 1+2 (merged via #2808 and #2815) introduced
DataMachineProviderTurnStateand absorbedlatest_messages,latest_turn_count, andlast_request_metadata. This slice absorbs the last three.Fields added to
DataMachineProviderTurnStatepublic array $last_tool_calls = array();— tool calls from the latest dispatched turn (DM-flavored shape)public array $all_tool_calls = array();— all tool calls accumulated across the runpublic array $completion_nudges = array();— completion nudge diagnostics accumulated across the run (DM-only)Declared as public typed properties with array init, matching the existing field style on the object.
By-ref params removed
datamachine_build_provider_turn_adapter()signature, before → after:&$last_tool_calls,&$all_tool_calls,&$completion_nudges) — on top of the 3 by-ref already removed in slices 1+2, this is the 6 → 0 by-ref target from the issue.$turn_stateobject.Dropped from both the function signature and the returned closure's
use(...)list.Call sites updated
datamachine_run_conversation, ~L180) — removed the 3 by-ref args.$last_tool_calls = $tool_calls→$turn_state->last_tool_calls = $tool_calls;$all_tool_calls[] = ...→$turn_state->all_tool_calls[] = ....datamachine_record_completion_nudge( $turn_state->completion_nudges, ... ). The helper keeps its own by-ref param and now mutates the object property directly (valid PHP — public array property passed by reference).$turn_state->last_tool_calls/$turn_state->all_tool_calls.$turn_state->last_tool_calls,$turn_state->all_tool_calls,$turn_state->completion_nudges.array()initializers (now object-owned).Per-path parity
Every former by-ref read now reads the same value from
$turn_stateat the same point in execution:last_tool_calls/all_tool_callsfrom$turn_state, populated by the closure up to the point of failure, identical to the prior by-ref snapshot.$turn_state->completion_nudges, read by the normalizer at the same point with the same accumulated sequence.Verification
php -lclean on both touched files.vendor/bin/phpcbf+vendor/bin/phpcs— fully green on both files, including theGeneric.Formatting.MultipleStatementAlignmentequals-alignment sniff.agent-conversation-runner-request,agent-conversation-result,agent-conversation-runtime-policy,ai-message-envelope,ai-loop-event-sink,provider-turn-tool-extraction-contract.main. Zero regressions introduced.grepconfirms&$last_tool_calls,&$all_tool_calls,&$completion_nudgesare gone from the adapter; the only remaining occurrence is the receiving by-ref param inside thedatamachine_record_completion_nudgehelper (which now receives$turn_state->completion_nudges).Scope
Slice 3 of #2803 — references #2803, does not close it. Remaining: the broader 64-function file split into cohesive modules.