Files
CLIProxyAPI/internal/runtime/executor/helps/codex_terminal_incomplete.go
Luis Pater 6e6afab99a refactor: migrate gjson, sjson, and base64 to MoeForge/moego
- Replace tidwall/gjson and tidwall/sjson with github.com/MoeForge/moego/ojson
  and encoding/base64 with github.com/MoeForge/moego/base64 across the main
  module and examples
- Introduce cross-method *ojson.Doc request rewriting pipelines across
  thinking, signature, client/codex, runtime/executor/helps, pluginhost, and
  all provider executors with FinalizePayloadDoc as the final semantic barrier
- Convert all consecutive JSON mutations (>= 2 Set/SetRaw/Delete operations)
  to batch edits on ojson.Doc
- Upgrade read-only byte paths to ojson.GetBytesNoCopy,
  ojson.GetManyBytesNoCopy, and util.ParseGJSONBytesNoCopy with explicit
  strings.Clone ownership protection across streaming and persistent state
- Use base64.StdEncoding.ValidateString for zero-allocation signature checks
  and base64.EncodeDataURL for single-allocation data URL construction
2026-11-03 03:05:04 +08:00

61 lines
2.4 KiB
Go

package helps
import (
"strings"
"github.com/MoeForge/moego/ojson"
)
const (
// CodexEmptyIncompleteStreamMessage is the error message emitted when upstream ChatGPT Codex
// terminates with response.incomplete having 0 output tokens and 0 content output.
CodexEmptyIncompleteStreamMessage = "stream error: upstream terminated with incomplete empty response (0 tokens)"
)
// HasMeaningfulCodexOutputDelta reports whether an event carries non-empty generated content
// (such as non-empty text, reasoning, or function call arguments delta).
func HasMeaningfulCodexOutputDelta(eventData []byte) bool {
eventType := ojson.GetBytesNoCopy(eventData, "type").String()
switch eventType {
case "response.output_text.delta", "response.reasoning_text.delta", "response.reasoning_summary_text.delta":
delta := ojson.GetBytesNoCopy(eventData, "delta")
return delta.Exists() && len(strings.TrimSpace(delta.String())) > 0
case "response.function_call_arguments.delta":
delta := ojson.GetBytesNoCopy(eventData, "delta")
return delta.Exists() && len(strings.TrimSpace(delta.String())) > 0
}
return false
}
// IsCodexTerminalEmptyIncomplete reports whether a response.incomplete event represents
// an upstream silent abort where explicitly zero output tokens were generated and zero
// output content (no output items and no non-empty output deltas) was produced.
func IsCodexTerminalEmptyIncomplete(eventData []byte, outputItemsCount int, sawOutputDelta bool) bool {
eventType := ojson.GetBytesNoCopy(eventData, "type").String()
if eventType != "response.incomplete" {
return false
}
// If any non-empty text delta, reasoning delta, or tool argument delta was emitted, content was produced.
if sawOutputDelta {
return false
}
// If any completed output items exist, output was produced.
if outputItemsCount > 0 {
return false
}
// If response.output contains any items, output was produced.
output := ojson.GetBytesNoCopy(eventData, "response.output")
if output.Exists() && output.IsArray() && len(output.Array()) > 0 {
return false
}
// Require explicit numeric zero for output tokens (reject floats like 0.5, non-numbers, missing, or null).
outputTokens := ojson.GetBytesNoCopy(eventData, "response.usage.output_tokens")
if !outputTokens.Exists() || outputTokens.Type != ojson.Number {
return false
}
if outputTokens.Num != 0 || strings.TrimSpace(outputTokens.Raw) != "0" {
return false
}
return true
}