From ff8ebc7add3cde95075e94ae94d95a1818e91f6e Mon Sep 17 00:00:00 2001 From: binarymax Date: Fri, 21 Aug 2026 10:21:32 -0400 Subject: [PATCH 1/4] Removes float32->base64 precision widening a.k.a. float bloat --- scripts/castiron/custom_code_report.py | 8 ++------ scripts/castiron/test_custom_code_report.py | 8 ++------ src/openai/resources/embeddings.py | 10 ++++++---- 3 files changed, 10 insertions(+), 16 deletions(-) diff --git a/scripts/castiron/custom_code_report.py b/scripts/castiron/custom_code_report.py index 3e6ed19e89..2a5677a14b 100644 --- a/scripts/castiron/custom_code_report.py +++ b/scripts/castiron/custom_code_report.py @@ -875,9 +875,7 @@ def write_report( return report -def trusted_report( - repo: Path, repository: str, run_id: int, run_attempt: int, out: Path -) -> None: +def trusted_report(repo: Path, repository: str, run_id: int, run_attempt: int, out: Path) -> None: """Recompute from GitHub-associated Git objects, never from PR-produced artifacts.""" if not REPOSITORY.fullmatch(repository) or min(run_id, run_attempt) <= 0: raise ReportError("invalid GitHub report target") @@ -918,9 +916,7 @@ def trusted_report( git(repo, "fetch", "--quiet", "--no-tags", "origin", base, head) write_report(repo, base, head, out, fetch=True, require_head_hash=True, public=public) (out / "context.json").write_text( - json.dumps( - {"pr": number, "repository": repository, "run": run_id, "attempt": run_attempt} - ) + json.dumps({"pr": number, "repository": repository, "run": run_id, "attempt": run_attempt}) + "\n" ) diff --git a/scripts/castiron/test_custom_code_report.py b/scripts/castiron/test_custom_code_report.py index cc3663034f..d6f04f3f5f 100644 --- a/scripts/castiron/test_custom_code_report.py +++ b/scripts/castiron/test_custom_code_report.py @@ -429,9 +429,7 @@ def test_trusted_report_recomputes_pr_output_in_a_bare_repository(self) -> None: self.write("generated.py", "generated\n# custom\n") # Neither a replacement reporter nor its claimed result may be executed # or read by the trusted job. - self.write( - "scripts/castiron/custom_code_report.py", "raise RuntimeError('PR code ran')\n" - ) + self.write("scripts/castiron/custom_code_report.py", "raise RuntimeError('PR code ran')\n") self.write("report.json", json.dumps(legitimate)) head = self.commit() broken_stats = ( @@ -473,9 +471,7 @@ def local_git(repo: Path, *args: str, input_bytes: bytes | None = None) -> bytes producer.mkdir() (producer / "report.json").write_text(json.dumps(forged)) - def fake_api( - method: str, path: str, payload: dict[str, Any] | None = None - ) -> Any: + def fake_api(method: str, path: str, payload: dict[str, Any] | None = None) -> Any: calls.append((method, path)) if method == "GET": responses: dict[str, Any] = { diff --git a/src/openai/resources/embeddings.py b/src/openai/resources/embeddings.py index 5b5a018de5..a08ccb9ebc 100644 --- a/src/openai/resources/embeddings.py +++ b/src/openai/resources/embeddings.py @@ -125,11 +125,12 @@ def parser(obj: CreateEmbeddingResponse) -> CreateEmbeddingResponse: continue if not has_numpy(): # use array for base64 optimisation - embedding.embedding = array.array("f", base64.b64decode(data)).tolist() + values = array.array("f", base64.b64decode(data)).tolist() else: - embedding.embedding = np.frombuffer( # type: ignore[no-untyped-call] + values = np.frombuffer( # type: ignore[no-untyped-call] base64.b64decode(data), dtype="float32" ).tolist() + embedding.embedding = [float(f"{value:.9g}") for value in values] return obj @@ -249,11 +250,12 @@ def parser(obj: CreateEmbeddingResponse) -> CreateEmbeddingResponse: continue if not has_numpy(): # use array for base64 optimisation - embedding.embedding = array.array("f", base64.b64decode(data)).tolist() + values = array.array("f", base64.b64decode(data)).tolist() else: - embedding.embedding = np.frombuffer( # type: ignore[no-untyped-call] + values = np.frombuffer( # type: ignore[no-untyped-call] base64.b64decode(data), dtype="float32" ).tolist() + embedding.embedding = [float(f"{value:.9g}") for value in values] return obj From 74607ee9e54ad3b4cf0749ef6463e704a61d47b9 Mon Sep 17 00:00:00 2001 From: Max Irwin Date: Thu, 27 Aug 2026 11:27:25 -0400 Subject: [PATCH 2/4] Update custom_code_report.py Undo format change --- scripts/castiron/custom_code_report.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/castiron/custom_code_report.py b/scripts/castiron/custom_code_report.py index 2a5677a14b..73dce1056a 100644 --- a/scripts/castiron/custom_code_report.py +++ b/scripts/castiron/custom_code_report.py @@ -875,7 +875,9 @@ def write_report( return report -def trusted_report(repo: Path, repository: str, run_id: int, run_attempt: int, out: Path) -> None: +def trusted_report( + repo: Path, repository: str, run_id: int, run_attempt: int, out: Path +) -> None: """Recompute from GitHub-associated Git objects, never from PR-produced artifacts.""" if not REPOSITORY.fullmatch(repository) or min(run_id, run_attempt) <= 0: raise ReportError("invalid GitHub report target") From dde0f48cdbca9e10d277fd3185b9d9fc8769d7b2 Mon Sep 17 00:00:00 2001 From: Max Irwin Date: Thu, 27 Aug 2026 11:28:22 -0400 Subject: [PATCH 3/4] Update custom_code_report.py Undo formatting change --- scripts/castiron/custom_code_report.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/castiron/custom_code_report.py b/scripts/castiron/custom_code_report.py index 73dce1056a..3e6ed19e89 100644 --- a/scripts/castiron/custom_code_report.py +++ b/scripts/castiron/custom_code_report.py @@ -918,7 +918,9 @@ def trusted_report( git(repo, "fetch", "--quiet", "--no-tags", "origin", base, head) write_report(repo, base, head, out, fetch=True, require_head_hash=True, public=public) (out / "context.json").write_text( - json.dumps({"pr": number, "repository": repository, "run": run_id, "attempt": run_attempt}) + json.dumps( + {"pr": number, "repository": repository, "run": run_id, "attempt": run_attempt} + ) + "\n" ) From 42b61a31ca2d8a41fd46b8af8344ef27ba705367 Mon Sep 17 00:00:00 2001 From: Max Irwin Date: Thu, 27 Aug 2026 11:30:18 -0400 Subject: [PATCH 4/4] Update test_custom_code_report.py Undo formatting change --- scripts/castiron/test_custom_code_report.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/scripts/castiron/test_custom_code_report.py b/scripts/castiron/test_custom_code_report.py index d6f04f3f5f..cc3663034f 100644 --- a/scripts/castiron/test_custom_code_report.py +++ b/scripts/castiron/test_custom_code_report.py @@ -429,7 +429,9 @@ def test_trusted_report_recomputes_pr_output_in_a_bare_repository(self) -> None: self.write("generated.py", "generated\n# custom\n") # Neither a replacement reporter nor its claimed result may be executed # or read by the trusted job. - self.write("scripts/castiron/custom_code_report.py", "raise RuntimeError('PR code ran')\n") + self.write( + "scripts/castiron/custom_code_report.py", "raise RuntimeError('PR code ran')\n" + ) self.write("report.json", json.dumps(legitimate)) head = self.commit() broken_stats = ( @@ -471,7 +473,9 @@ def local_git(repo: Path, *args: str, input_bytes: bytes | None = None) -> bytes producer.mkdir() (producer / "report.json").write_text(json.dumps(forged)) - def fake_api(method: str, path: str, payload: dict[str, Any] | None = None) -> Any: + def fake_api( + method: str, path: str, payload: dict[str, Any] | None = None + ) -> Any: calls.append((method, path)) if method == "GET": responses: dict[str, Any] = {