fix(server): stop an oversized provider diff from exhausting the backend heap #10965
ClosedKoushik890(GitHub profile, opens in a new tab)wants to merge 1 commit into
main fromrefs/pull/10965/headopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
- @@ -496,0 +506,21 @@506+ const lastCode = value.charCodeAt(maxLength - 1);507+ const keep = lastCode >= 0xd800 && lastCode <= 0xdbff ? maxLength - 1 : maxLength;508+ return `${value.slice(0, keep)}[truncated by t3, ${value.length} characters total]`;509+}510+511+function isPlainContainer(value: object): boolean {512+ if (Array.isArray(value)) return true;513+ const prototype = Reflect.getPrototypeOf(value);514+ return prototype === Object.prototype || prototype === null;515+}516+517+/**518+ * Bounds the string values of one event before it is serialized. A provider can519+ * hand us a payload far larger than any log record should be (a Codex520+ * `turn/diff/updated` diff reaches hundreds of MiB on a big turn), and encoding521+ * it whole materializes an equally large line that can exhaust the heap.522+ *523+ * Values that already fit are returned by reference, so an ordinary event524+ * allocates nothing. Anything that is not a plain object or array is left alone,525+ * because `toJSON` carriers such as `Date` must reach the encoder intact. A cycle526+ * is returned untouched at the point it closes, so serialization still fails the
- @@ -613,4 +682,6 @@613682614683 const write = Effect.fnUntraced(function* (event: unknown, threadId: ThreadId | null) {615684 if (!shouldPersist(stream, event)) return;616- const payload = yield* serializeEvent(event);685+ const payload = yield* serializeEvent(686+ clampStrings(event, resolved.maxStringLength, new Set()),687+ );
Koushik890(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.
Approvability#
Verdict: Not approved
Macroscope's review found this PR not approvable — This production fix adds a 256 KiB default that truncates oversized strings across provider logs and changes the raw payload representation of Codex turn diffs. Because the default changes retained product diagnostics across existing provider paths, the scope warrants human review.
You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).