mirror of
https://github.com/openai/codex.git
synced 2026-11-06 08:31:30 +00:00
Handle undefined values before JSON serialization in code mode (#43873)
## Why
Passing `undefined` to a tool could fail JSON parsing because V8 stringifies it as the non-JSON text `undefined`.
## What changed
Return no JSON value for JavaScript `undefined`, so explicit `undefined` tool arguments behave like omitted arguments. Attempts to `store` an undefined value report the existing serializability error and preserve the previous stored value.
## Testing
Add regression coverage for storing `undefined` over an existing `null` value, and extend the current-time tool test to cover `{}`, omitted arguments, and explicit `undefined`.
GitOrigin-RevId: 071050ebb2ecc44c8f08453cf8523b4d21728c7e
This commit is contained in:
1 parent
44ab72674e
commit
c1f1467f30
3 files changed
+55
-3
No files matched your search
@@ -297,6 +297,11 @@ pub(super) fn v8_value_to_json(
|
||||
scope: &mut v8::PinScope<'_, '_>,
|
||||
value: v8::Local<'_, v8::Value>,
|
||||
) -> Result<Option<JsonValue>, String> {
|
||||
// V8 stringifies undefined as the non-JSON text "undefined".
|
||||
if value.is_undefined() {
|
||||
return Ok(None);
|
||||
}
|
||||
|
||||
let tc = std::pin::pin!(v8::TryCatch::new(scope));
|
||||
let mut tc = tc.init();
|
||||
let Some(stringified) = v8::json::stringify(&tc, value) else {
|
||||
|
||||
Reference in new issue
Block a user