From 462fbdb002b152758eb38a292e1f14cddfdf68fb Mon Sep 17 00:00:00 2001 From: Google Team Member Date: Tue, 24 Nov 2026 20:19:31 -0800 Subject: [PATCH] rename function_invocation to function_call. PiperOrigin-RevId: 1029549843 --- internal/cli/custom/envruntime/events.go | 24 ++++---- internal/cli/custom/envruntime/wire.go | 38 ++++++------- internal/cli/custom/envruntime/wire_test.go | 56 ++++++++++--------- internal/cli/custom/envruntime/worker.go | 18 +++--- internal/cli/custom/envruntime/worker_test.go | 12 ++-- internal/cli/custom/runtime_test.go | 2 +- 6 files changed, 78 insertions(+), 72 deletions(-) diff --git a/internal/cli/custom/envruntime/events.go b/internal/cli/custom/envruntime/events.go index d1fc1f7..e75dc35 100644 --- a/internal/cli/custom/envruntime/events.go +++ b/internal/cli/custom/envruntime/events.go @@ -42,12 +42,12 @@ type ClientEvent struct { // EventPayload carries the typed event union shared by ClientEvent and ServerEvent. type EventPayload struct { - SubInteractionID string - Step *Step - FunctionInvocation *FunctionInvocation - FunctionResult *FunctionResultEvent - CallHookRequest *CallHookRequest - CallHookResponse *CallHookResponse + SubInteractionID string + Step *Step + FunctionCall *FunctionCallEvent + FunctionResult *FunctionResultEvent + CallHookRequest *CallHookRequest + CallHookResponse *CallHookResponse } // Clone returns a deep copy of EventPayload suitable for caching across reconnects. @@ -78,10 +78,10 @@ func (p *EventPayload) Clone() *EventPayload { } cp.Step = &st } - if p.FunctionInvocation != nil { - fi := *p.FunctionInvocation - fi.Arguments = cloneMap(p.FunctionInvocation.Arguments) - cp.FunctionInvocation = &fi + if p.FunctionCall != nil { + fc := *p.FunctionCall + fc.Arguments = cloneMap(p.FunctionCall.Arguments) + cp.FunctionCall = &fc } if p.FunctionResult != nil { fr := *p.FunctionResult @@ -166,8 +166,8 @@ type FunctionResultStep struct { Result any } -// FunctionInvocation represents a top-level server-to-client function call payload. -type FunctionInvocation struct { +// FunctionCallEvent represents a top-level server-to-client function call payload. +type FunctionCallEvent struct { CallID string Name string Arguments map[string]any diff --git a/internal/cli/custom/envruntime/wire.go b/internal/cli/custom/envruntime/wire.go index 8fd8763..a5349a5 100644 --- a/internal/cli/custom/envruntime/wire.go +++ b/internal/cli/custom/envruntime/wire.go @@ -211,12 +211,12 @@ func marshalPayload(p *EventPayload) []byte { sub = appendBytesField(sub, 11, stepBytes) } } - if fi := p.FunctionInvocation; fi != nil { - var fib []byte - fib = appendStringField(fib, 1, fi.CallID) - fib = appendStringField(fib, 2, fi.Name) - fib = appendBytesField(fib, 3, EncodeProtoStruct(fi.Arguments)) - sub = appendBytesField(sub, 14, fib) + if fc := p.FunctionCall; fc != nil { + var fcb []byte + fcb = appendStringField(fcb, 1, fc.CallID) + fcb = appendStringField(fcb, 2, fc.Name) + fcb = appendBytesField(fcb, 3, EncodeProtoStruct(fc.Arguments)) + sub = appendBytesField(sub, 14, fcb) } if req := p.CallHookRequest; req != nil { if len(req.RawWire) > 0 { @@ -683,11 +683,11 @@ func unmarshalPayload(data []byte) (*EventPayload, error) { } out.Step = st case num == 14 && wt == wireBytes: - fi, err := unmarshalFunctionInvocation(vb) + fc, err := unmarshalFunctionCallEvent(vb) if err != nil { return nil, err } - out.FunctionInvocation = fi + out.FunctionCall = fc case num == 15 && wt == wireBytes: hr, err := unmarshalCallHookRequest(vb) if err != nil { @@ -827,8 +827,8 @@ func unmarshalFunctionResultStep(data []byte) (*FunctionResultStep, error) { return out, nil } -func unmarshalFunctionInvocation(data []byte) (*FunctionInvocation, error) { - out := &FunctionInvocation{} +func unmarshalFunctionCallEvent(data []byte) (*FunctionCallEvent, error) { + out := &FunctionCallEvent{} for len(data) > 0 { num, wt, _, vb, n, err := ConsumeField(data) if err != nil { @@ -1066,9 +1066,9 @@ func functionResultJSONMap(callID, name string, isError bool, result any) map[st return ev } -func functionInvocationJSONMap(callID, name string, args map[string]any) map[string]any { +func functionCallJSONMap(callID, name string, args map[string]any) map[string]any { ev := map[string]any{ - "event_type": "function_invocation", + "event_type": "function_call", "call_id": callID, "name": name, } @@ -1252,12 +1252,12 @@ func MarshalServerEventBatchJSON(b *ServerEventBatch) ([]byte, error) { p := se.Payload var ev map[string]any switch { - case p.FunctionInvocation != nil: - ev = functionInvocationJSONMap(p.FunctionInvocation.CallID, p.FunctionInvocation.Name, p.FunctionInvocation.Arguments) + case p.FunctionCall != nil: + ev = functionCallJSONMap(p.FunctionCall.CallID, p.FunctionCall.Name, p.FunctionCall.Arguments) case p.Step != nil && p.Step.ToolCall != nil && p.Step.ToolCall.FunctionCall != nil: tc := p.Step.ToolCall fc := tc.FunctionCall - ev = functionInvocationJSONMap(tc.ID, fc.Name, fc.Arguments) + ev = functionCallJSONMap(tc.ID, fc.Name, fc.Arguments) case p.CallHookRequest != nil: ev = map[string]any{ "event_type": "call_hook_request", @@ -1467,12 +1467,12 @@ func UnmarshalServerEventBatchJSON(data []byte) (*ServerEventBatch, error) { out.InteractionReconnected = &InteractionReconnectedEvent{ NextInputSeqNum: nextIn, } - case "function_invocation": + case "function_call", "function_invocation": out.Events = append(out.Events, &ServerEvent{ SeqNum: seqNum, TimestampMicros: tsMicros, Payload: &EventPayload{ - FunctionInvocation: &FunctionInvocation{ + FunctionCall: &FunctionCallEvent{ CallID: ev.CallID, Name: ev.Name, Arguments: ev.Arguments, @@ -1507,7 +1507,7 @@ func UnmarshalServerEventBatchJSON(data []byte) (*ServerEventBatch, error) { SeqNum: seqNum, TimestampMicros: tsMicros, Payload: &EventPayload{ - FunctionInvocation: &FunctionInvocation{ + FunctionCall: &FunctionCallEvent{ CallID: callID, Name: name, Arguments: args, @@ -1523,7 +1523,7 @@ func UnmarshalServerEventBatchJSON(data []byte) (*ServerEventBatch, error) { SeqNum: seqNum, TimestampMicros: tsMicros, Payload: &EventPayload{ - FunctionInvocation: &FunctionInvocation{ + FunctionCall: &FunctionCallEvent{ CallID: callID, Name: ev.Name, Arguments: ev.Arguments, diff --git a/internal/cli/custom/envruntime/wire_test.go b/internal/cli/custom/envruntime/wire_test.go index 9ff3dfd..cc02d4b 100644 --- a/internal/cli/custom/envruntime/wire_test.go +++ b/internal/cli/custom/envruntime/wire_test.go @@ -194,7 +194,7 @@ func TestMarshalAndUnmarshalClientEventBatch(t *testing.T) { { SeqNum: 2, Payload: &EventPayload{ - FunctionInvocation: &FunctionInvocation{ + FunctionCall: &FunctionCallEvent{ CallID: "fi_1", Name: "list_dir", Arguments: map[string]any{"dir": "."}, @@ -290,9 +290,9 @@ func TestMarshalAndUnmarshalClientEventBatch(t *testing.T) { !reflect.DeepEqual(got.Step.ToolResult.FunctionResult.Result, map[string]any{"error": "missing"}) { t.Errorf("decoded Events[0] = %+v", got) } - if got := decoded.Events[1].Payload; got.FunctionInvocation.CallID != "fi_1" || - got.FunctionInvocation.Name != "list_dir" || - got.FunctionInvocation.Arguments["dir"] != "." || + if got := decoded.Events[1].Payload; got.FunctionCall.CallID != "fi_1" || + got.FunctionCall.Name != "list_dir" || + got.FunctionCall.Arguments["dir"] != "." || got.FunctionResult.CallID != "fi_1" || got.FunctionResult.Name != "list_dir" || !got.FunctionResult.IsError || @@ -670,7 +670,7 @@ func TestEventPayloadCloneAndNopObserver(t *testing.T) { }, }, }, - FunctionInvocation: &FunctionInvocation{ + FunctionCall: &FunctionCallEvent{ CallID: "f1", Name: "fn2", Arguments: map[string]any{"a": "b"}, @@ -689,8 +689,8 @@ func TestEventPayloadCloneAndNopObserver(t *testing.T) { cloned.Step.ToolCall.FunctionCall.Arguments["arr"].([]any)[0].(map[string]any)["inner"] = "mutated" cloned.Step.ToolResult.FunctionResult.Name = "mutated_fn" cloned.Step.ToolResult.FunctionResult.Result.(map[string]any)["out"] = "mutated" - cloned.FunctionInvocation.Name = "mutated_fn2" - cloned.FunctionInvocation.Arguments["a"] = "mutated" + cloned.FunctionCall.Name = "mutated_fn2" + cloned.FunctionCall.Arguments["a"] = "mutated" cloned.FunctionResult.Name = "mutated_fn2" cloned.FunctionResult.Result.([]string)[0] = "mutated" cloned.CallHookRequest.RawWire[0] = 99 @@ -705,8 +705,8 @@ func TestEventPayloadCloneAndNopObserver(t *testing.T) { if orig.Step.ToolResult.FunctionResult.Name != "fn" || orig.Step.ToolResult.FunctionResult.Result.(map[string]any)["out"] != "ok" { t.Errorf("Clone() shared Step.ToolResult.FunctionResult with original: %+v", orig.Step.ToolResult.FunctionResult) } - if orig.FunctionInvocation.Name != "fn2" || orig.FunctionInvocation.Arguments["a"] != "b" { - t.Errorf("Clone() shared FunctionInvocation with original: %+v", orig.FunctionInvocation) + if orig.FunctionCall.Name != "fn2" || orig.FunctionCall.Arguments["a"] != "b" { + t.Errorf("Clone() shared FunctionCall with original: %+v", orig.FunctionCall) } if orig.FunctionResult.Name != "fn2" || orig.FunctionResult.Result.([]string)[0] != "s1" { t.Errorf("Clone() shared FunctionResult with original: %+v", orig.FunctionResult) @@ -929,21 +929,27 @@ func TestEventBatchJSONRoundTripAndWSCloseMapping(t *testing.T) { t.Errorf("UnmarshalServerEventBatchJSON(%q) = (%+v, %v), want empty batch and nil error", emptySrv, b, err) } } - if decSrvMulti.Events[0].Payload.FunctionInvocation == nil || decSrvMulti.Events[0].Payload.FunctionInvocation.Name != "read_file" { - t.Errorf("UnmarshalServerEventBatchJSON(srvMulti).Events[0].Payload = %+v, want FunctionInvocation{Name:\"read_file\"}", decSrvMulti.Events[0].Payload) + if decSrvMulti.Events[0].Payload.FunctionCall == nil || decSrvMulti.Events[0].Payload.FunctionCall.Name != "read_file" { + t.Errorf("UnmarshalServerEventBatchJSON(srvMulti).Events[0].Payload = %+v, want FunctionCall{Name:\"read_file\"}", decSrvMulti.Events[0].Payload) } - // Golden literal JSON server events: interaction.complete, step.start, interaction.status_update, string error.code, and bare error object. + // Golden literal JSON server events: function_call, legacy function_invocation, interaction.complete, step.start, interaction.status_update, string error.code, and bare error object. + if b, err := UnmarshalServerEventBatchJSON([]byte(`{"event_type":"function_call","seq_num":"13","call_id":"call_fc_1","name":"read_file","arguments":{"path":"README.md"}}`)); err != nil || len(b.Events) != 1 || b.Events[0].SeqNum != 13 || b.Events[0].Payload.FunctionCall == nil || b.Events[0].Payload.FunctionCall.CallID != "call_fc_1" || b.Events[0].Payload.FunctionCall.Name != "read_file" || b.Events[0].Payload.FunctionCall.Arguments["path"] != "README.md" { + t.Errorf("UnmarshalServerEventBatchJSON(function_call) = (%+v, %v), want seq=13 call_id=\"call_fc_1\" name=\"read_file\" path=\"README.md\"", b, err) + } + if b, err := UnmarshalServerEventBatchJSON([]byte(`{"event_type":"function_invocation","seq_num":"13","call_id":"call_fi_legacy","name":"read_file","arguments":{"path":"README.md"}}`)); err != nil || len(b.Events) != 1 || b.Events[0].SeqNum != 13 || b.Events[0].Payload.FunctionCall == nil || b.Events[0].Payload.FunctionCall.CallID != "call_fi_legacy" || b.Events[0].Payload.FunctionCall.Name != "read_file" || b.Events[0].Payload.FunctionCall.Arguments["path"] != "README.md" { + t.Errorf("UnmarshalServerEventBatchJSON(legacy function_invocation) = (%+v, %v), want seq=13 call_id=\"call_fi_legacy\" name=\"read_file\" path=\"README.md\"", b, err) + } if b, err := UnmarshalServerEventBatchJSON([]byte(`{"event_type":"interaction.complete","status":{"code":0,"message":"ok"}}`)); err != nil || b.InteractionCompleted == nil { t.Errorf("UnmarshalServerEventBatchJSON(interaction.complete) = (%+v, %v), want non-nil InteractionCompleted", b, err) } - if b, err := UnmarshalServerEventBatchJSON([]byte(`{"event_type":"step.start","seq_num":"14","step":{"type":"function_call","id":"call_99","name":"execute_bash","arguments":{"command":"ls"}}}`)); err != nil || len(b.Events) != 1 || b.Events[0].SeqNum != 14 || b.Events[0].Payload.FunctionInvocation == nil || b.Events[0].Payload.FunctionInvocation.CallID != "call_99" || b.Events[0].Payload.FunctionInvocation.Name != "execute_bash" { + if b, err := UnmarshalServerEventBatchJSON([]byte(`{"event_type":"step.start","seq_num":"14","step":{"type":"function_call","id":"call_99","name":"execute_bash","arguments":{"command":"ls"}}}`)); err != nil || len(b.Events) != 1 || b.Events[0].SeqNum != 14 || b.Events[0].Payload.FunctionCall == nil || b.Events[0].Payload.FunctionCall.CallID != "call_99" || b.Events[0].Payload.FunctionCall.Name != "execute_bash" { t.Errorf("UnmarshalServerEventBatchJSON(step.start) = (%+v, %v), want seq=14 call_id=\"call_99\" name=\"execute_bash\"", b, err) } - if b, err := UnmarshalServerEventBatchJSON([]byte(`{"event_type":"step","seq_num":"15","type":"function_call","id":"call_flat_1","name":"execute_bash","arguments":{"command":"pwd"}}`)); err != nil || len(b.Events) != 1 || b.Events[0].SeqNum != 15 || b.Events[0].Payload.FunctionInvocation == nil || b.Events[0].Payload.FunctionInvocation.CallID != "call_flat_1" || b.Events[0].Payload.FunctionInvocation.Name != "execute_bash" { + if b, err := UnmarshalServerEventBatchJSON([]byte(`{"event_type":"step","seq_num":"15","type":"function_call","id":"call_flat_1","name":"execute_bash","arguments":{"command":"pwd"}}`)); err != nil || len(b.Events) != 1 || b.Events[0].SeqNum != 15 || b.Events[0].Payload.FunctionCall == nil || b.Events[0].Payload.FunctionCall.CallID != "call_flat_1" || b.Events[0].Payload.FunctionCall.Name != "execute_bash" { t.Errorf("UnmarshalServerEventBatchJSON(flattened step) = (%+v, %v), want seq=15 call_id=\"call_flat_1\" name=\"execute_bash\"", b, err) } - if b, err := UnmarshalServerEventBatchJSON([]byte(`{"event_type":"step","type":"function_call","call_id":"call_flat_cid","id":"ignored_flat_id","name":"execute_bash"}`)); err != nil || len(b.Events) != 1 || b.Events[0].Payload.FunctionInvocation == nil || b.Events[0].Payload.FunctionInvocation.CallID != "call_flat_cid" { + if b, err := UnmarshalServerEventBatchJSON([]byte(`{"event_type":"step","type":"function_call","call_id":"call_flat_cid","id":"ignored_flat_id","name":"execute_bash"}`)); err != nil || len(b.Events) != 1 || b.Events[0].Payload.FunctionCall == nil || b.Events[0].Payload.FunctionCall.CallID != "call_flat_cid" { t.Errorf("UnmarshalServerEventBatchJSON(flattened step call_id precedence) = (%+v, %v), want call_id=\"call_flat_cid\"", b, err) } for _, nonFCStep := range []string{ @@ -1042,7 +1048,7 @@ func TestEventBatchJSONRoundTripAndWSCloseMapping(t *testing.T) { }, { Payload: &EventPayload{ - FunctionInvocation: &FunctionInvocation{CallID: "fi_z", Name: "fn"}, + FunctionCall: &FunctionCallEvent{CallID: "fi_z", Name: "fn"}, }, }, { @@ -1094,7 +1100,7 @@ func TestEventBatchJSONRoundTripAndWSCloseMapping(t *testing.T) { SeqNum: 3, TimestampMicros: 999, Payload: &EventPayload{ - FunctionInvocation: &FunctionInvocation{ + FunctionCall: &FunctionCallEvent{ CallID: "fi_1", Name: "exec", Arguments: map[string]any{"x": 1}, @@ -1114,8 +1120,8 @@ func TestEventBatchJSONRoundTripAndWSCloseMapping(t *testing.T) { }, }, }) - if err != nil || strings.Contains(string(rawSrvDirectEvents), "ack_input_seq_num") || !strings.Contains(string(rawSrvDirectEvents), `"timestamp_micros":"999"`) || !strings.Contains(string(rawSrvDirectEvents), `"timestamp_micros":"1001"`) { - t.Errorf("MarshalServerEventBatchJSON(direct FunctionInvocation + CallHookRequest) = (%s, %v), want timestamp_micros 999 and 1001 without ack_input_seq_num", rawSrvDirectEvents, err) + if err != nil || strings.Contains(string(rawSrvDirectEvents), "ack_input_seq_num") || !strings.Contains(string(rawSrvDirectEvents), `"event_type":"function_call"`) || !strings.Contains(string(rawSrvDirectEvents), `"timestamp_micros":"999"`) || !strings.Contains(string(rawSrvDirectEvents), `"timestamp_micros":"1001"`) { + t.Errorf("MarshalServerEventBatchJSON(direct FunctionCall + CallHookRequest) = (%s, %v), want function_call and timestamp_micros 999 and 1001 without ack_input_seq_num", rawSrvDirectEvents, err) } rawSrvMultiWithAck, err := MarshalServerEventBatchJSON(&ServerEventBatch{ AckInputSeqNum: 11, @@ -1132,7 +1138,7 @@ func TestEventBatchJSONRoundTripAndWSCloseMapping(t *testing.T) { SeqNum: 3, TimestampMicros: 999, Payload: &EventPayload{ - FunctionInvocation: &FunctionInvocation{ + FunctionCall: &FunctionCallEvent{ CallID: "fi_1", Name: "exec", Arguments: map[string]any{"x": float64(1)}, @@ -1175,13 +1181,13 @@ func TestEventBatchJSONRoundTripAndWSCloseMapping(t *testing.T) { if b, err := UnmarshalServerEventBatchJSON([]byte(`{"event_type":"interaction.completed","status":null}`)); err != nil || b.InteractionCompleted == nil || b.InteractionCompleted.Status != nil { t.Errorf("UnmarshalServerEventBatchJSON(null status) = (%+v, %v), want InteractionCompleted with nil Status", b, err) } - if b, err := UnmarshalServerEventBatchJSON([]byte(`{"event_type":"step","step":{"function_call":{"call_id":"fc_cid","name":"view_file","arguments":{"p":"a"}}}}`)); err != nil || len(b.Events) != 1 || b.Events[0].Payload.FunctionInvocation.CallID != "fc_cid" || b.Events[0].Payload.FunctionInvocation.Name != "view_file" || b.Events[0].Payload.FunctionInvocation.Arguments["p"] != "a" { + if b, err := UnmarshalServerEventBatchJSON([]byte(`{"event_type":"step","step":{"function_call":{"call_id":"fc_cid","name":"view_file","arguments":{"p":"a"}}}}`)); err != nil || len(b.Events) != 1 || b.Events[0].Payload.FunctionCall.CallID != "fc_cid" || b.Events[0].Payload.FunctionCall.Name != "view_file" || b.Events[0].Payload.FunctionCall.Arguments["p"] != "a" { t.Errorf("UnmarshalServerEventBatchJSON(nested function_call call_id) = (%+v, %v), want call_id=\"fc_cid\" name=\"view_file\"", b, err) } - if b, err := UnmarshalServerEventBatchJSON([]byte(`{"event_type":"step","step":{"function_call":{"id":"fc_id","name":"view_file"}}}`)); err != nil || len(b.Events) != 1 || b.Events[0].Payload.FunctionInvocation.CallID != "fc_id" { + if b, err := UnmarshalServerEventBatchJSON([]byte(`{"event_type":"step","step":{"function_call":{"id":"fc_id","name":"view_file"}}}`)); err != nil || len(b.Events) != 1 || b.Events[0].Payload.FunctionCall.CallID != "fc_id" { t.Errorf("UnmarshalServerEventBatchJSON(nested function_call id) = (%+v, %v), want call_id=\"fc_id\"", b, err) } - if b, err := UnmarshalServerEventBatchJSON([]byte(`{"event_type":"step","step":{"call_id":"outer_cid","name":"outer_fn","arguments":{"k":"outer"},"function_call":{"call_id":"inner_cid","name":"inner_fn","arguments":{"k":"inner"}}}}`)); err != nil || len(b.Events) != 1 || b.Events[0].Payload.FunctionInvocation.CallID != "outer_cid" || b.Events[0].Payload.FunctionInvocation.Name != "outer_fn" || b.Events[0].Payload.FunctionInvocation.Arguments["k"] != "outer" { + if b, err := UnmarshalServerEventBatchJSON([]byte(`{"event_type":"step","step":{"call_id":"outer_cid","name":"outer_fn","arguments":{"k":"outer"},"function_call":{"call_id":"inner_cid","name":"inner_fn","arguments":{"k":"inner"}}}}`)); err != nil || len(b.Events) != 1 || b.Events[0].Payload.FunctionCall.CallID != "outer_cid" || b.Events[0].Payload.FunctionCall.Name != "outer_fn" || b.Events[0].Payload.FunctionCall.Arguments["k"] != "outer" { t.Errorf("UnmarshalServerEventBatchJSON(outer step precedence over nested function_call) = (%+v, %v), want call_id=\"outer_cid\" name=\"outer_fn\"", b, err) } @@ -1250,8 +1256,8 @@ func TestEventBatchJSONRoundTripAndWSCloseMapping(t *testing.T) { for _, badSrvJSON := range []string{ `{"ack_input_seq_num":"not_int"}`, `{"events":[],"event_type":123}`, - `{"event_type":"function_invocation","seq_num":"not_int"}`, - `{"event_type":"function_invocation","timestamp_micros":"not_int"}`, + `{"event_type":"function_call","seq_num":"not_int"}`, + `{"event_type":"function_call","timestamp_micros":"not_int"}`, `{"event_type":"interaction.connected","next_input_seq_num":"not_int"}`, `{"event_type":"yield","next_input_seq_num":"not_int"}`, } { diff --git a/internal/cli/custom/envruntime/worker.go b/internal/cli/custom/envruntime/worker.go index ebfba1b..557ffbe 100644 --- a/internal/cli/custom/envruntime/worker.go +++ b/internal/cli/custom/envruntime/worker.go @@ -662,17 +662,17 @@ func (w *PullWorker) handleServerEvent(ctx context.Context, ev *ServerEvent, sta return nil } - if fi := ev.Payload.FunctionInvocation; fi != nil { - callKey := "fn:" + cmp.Or(fi.CallID, fmt.Sprintf("seq-%d", ev.SeqNum)) + if fc := ev.Payload.FunctionCall; fc != nil { + callKey := "fn:" + cmp.Or(fc.CallID, fmt.Sprintf("seq-%d", ev.SeqNum)) if cached := w.loadCachedCall(state, callKey); cached != nil { return cached } - w.logger.Printf("[%s] Executing function %s", state.interactionID, fi.Name) - resMap, isErr := w.tools.Dispatch(ctx, fi.Name, fi.Arguments) + w.logger.Printf("[%s] Executing function %s", state.interactionID, fc.Name) + resMap, isErr := w.tools.Dispatch(ctx, fc.Name, fc.Arguments) out := &EventPayload{ FunctionResult: &FunctionResultEvent{ - CallID: fi.CallID, - Name: fi.Name, + CallID: fc.CallID, + Name: fc.Name, IsError: isErr, Result: resMap, }, @@ -680,11 +680,11 @@ func (w *PullWorker) handleServerEvent(ctx context.Context, ev *ServerEvent, sta if exceedsMaxToolResultWire(out) { out = &EventPayload{ FunctionResult: &FunctionResultEvent{ - CallID: fi.CallID, - Name: fi.Name, + CallID: fc.CallID, + Name: fc.Name, IsError: true, Result: map[string]any{ - "error": fmt.Sprintf("tool %q result exceeds maximum frame size (%d bytes); narrow the query or specify start_line and end_line", fi.Name, MaxGRPCFrameBytes), + "error": fmt.Sprintf("tool %q result exceeds maximum frame size (%d bytes); narrow the query or specify start_line and end_line", fc.Name, MaxGRPCFrameBytes), }, }, } diff --git a/internal/cli/custom/envruntime/worker_test.go b/internal/cli/custom/envruntime/worker_test.go index 5625193..e20602a 100644 --- a/internal/cli/custom/envruntime/worker_test.go +++ b/internal/cli/custom/envruntime/worker_test.go @@ -168,7 +168,7 @@ func TestPullWorkerReconnectReplayHooksYieldAndOversizedResult(t *testing.T) { // Attempt 1: transient connect error -> retried because RetryConnectErrors=true. return nil, errors.New("transient dial error") case 2: - // Attempt 2: delivers empty payload + FunctionInvocation("fi_once") + Step.ToolCall("call_1"), Send fails -> rolls back seq while caching both! + // Attempt 2: delivers empty payload + FunctionCallEvent("fi_once") + Step.ToolCall("call_1"), Send fails -> rolls back seq while caching both! return &scriptedStream{ sendFn: func(call int, _ *ClientEventBatch) error { if call == 1 { @@ -188,7 +188,7 @@ func TestPullWorkerReconnectReplayHooksYieldAndOversizedResult(t *testing.T) { { SeqNum: 2, Payload: &EventPayload{ - FunctionInvocation: &FunctionInvocation{ + FunctionCall: &FunctionCallEvent{ CallID: "fi_once", Name: "execute_bash", Arguments: map[string]any{"command": "fn_once"}, @@ -216,7 +216,7 @@ func TestPullWorkerReconnectReplayHooksYieldAndOversizedResult(t *testing.T) { // Attempt 3: // - Call 1: ack-only event (SeqNum=1, Payload=nil). // - Call 2: replays "fi_once" (SeqNum=2) and "call_1" (SeqNum=3) verifying rolled-back client seq 1 & 2. - // - Call 3: InteractionReconnected{NextInputSeqNum: 10} + CallHookRequest("hk_1") + FunctionInvocation("fi_big", "huge") + non-terminal Yield{NextInputSeqNum: 1}. + // - Call 3: InteractionReconnected{NextInputSeqNum: 10} + CallHookRequest("hk_1") + FunctionCallEvent("fi_big", "huge") + non-terminal Yield{NextInputSeqNum: 1}. // - Call 4: ReconnectionRequired. s := &scriptedStream{ recvFn: func(call int) (*ServerEventBatch, error) { @@ -233,7 +233,7 @@ func TestPullWorkerReconnectReplayHooksYieldAndOversizedResult(t *testing.T) { { SeqNum: 2, Payload: &EventPayload{ - FunctionInvocation: &FunctionInvocation{ + FunctionCall: &FunctionCallEvent{ CallID: "fi_once", Name: "execute_bash", Arguments: map[string]any{"command": "fn_once"}, @@ -266,7 +266,7 @@ func TestPullWorkerReconnectReplayHooksYieldAndOversizedResult(t *testing.T) { { SeqNum: 5, Payload: &EventPayload{ - FunctionInvocation: &FunctionInvocation{ + FunctionCall: &FunctionCallEvent{ CallID: "fi_big", Name: "execute_bash", Arguments: map[string]any{"command": "huge"}, @@ -343,7 +343,7 @@ func TestPullWorkerReconnectReplayHooksYieldAndOversizedResult(t *testing.T) { t.Errorf("side-effecting tool execution count = %d, want 1 (replay cache must prevent duplicate execution)", got) } if got := fnCalls.Load(); got != 1 { - t.Errorf("FunctionInvocation execution count = %d, want 1 (replay cache must prevent duplicate execution)", got) + t.Errorf("FunctionCall execution count = %d, want 1 (replay cache must prevent duplicate execution)", got) } if got := hookCalls.Load(); got != 1 { t.Errorf("hook execution count = %d, want 1 (replay cache must prevent duplicate hook run)", got) diff --git a/internal/cli/custom/runtime_test.go b/internal/cli/custom/runtime_test.go index 35423f4..dda1919 100644 --- a/internal/cli/custom/runtime_test.go +++ b/internal/cli/custom/runtime_test.go @@ -513,7 +513,7 @@ func TestEnvironmentsRuntimeCommandsFlagsDryRunAndExecution(t *testing.T) { Events: []*envruntime.ServerEvent{{ SeqNum: 1, Payload: &envruntime.EventPayload{ - FunctionInvocation: &envruntime.FunctionInvocation{ + FunctionCall: &envruntime.FunctionCallEvent{ CallID: "c_bash", Name: "execute_bash", Arguments: map[string]any{"command": "echo nope"},