Skip to content

fix: avoid stack overflow when snapshotting deeply nested JSON - #742

Open
tpansino wants to merge 2 commits into
agentclientprotocol:mainfrom
tpansino:fix/json-snapshot-stack-overflow
Open

tpansino wants to merge 2 commits into
agentclientprotocol:mainfrom
tpansino:fix/json-snapshot-stack-overflow

Conversation

@tpansino

@tpansino tpansino commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

I maintain the nixpkg of codex-acp, and I'm trying to upgrade from v2.1.1 to v2.5.0. Linux x86-64 builds are currently failing for a few reasons, which I plan to file PRs to fix here upstream.

From Codex:

On Node 24.21.0 on Linux, JSON.stringify successfully serializes the
existing 4,000-level nested test value, while jsonSnapshot throws
RangeError: Maximum call stack size exceeded. This also reproduces
outside Vitest.

The snapshot walk recursively descends 256 levels before delegating to
native serialization, leaving hundreds of calls on the stack. Replace
that recursion with an explicit container stack, preserving getter order,
serialization behavior, and snapshot reuse.

The original 4,000-level regression test now passes without reducing its
depth or increasing Node's stack limit. Typechecking and compilation pass;
the full test suite reports 2,481 passed and 39 skipped.

Related to #741

EugeneTheDev pushed a commit that referenced this pull request Nov 11, 2026
I maintain the
[nixpkg](https://github.com/NixOS/nixpkgs/blob/1a04a224938e97a7a4d4d5bfb36a4099f9c6ab21/pkgs/by-name/co/codex-acp/package.nix#L65)
of codex-acp, and I'm trying to
[upgrade](NixOS/nixpkgs#582790) from v2.1.1 to
v2.5.0. Linux x86-64 builds are currently failing for a few reasons,
which I plan to file PRs to fix here upstream.

From Codex:

> The supervisor tests generate executable scripts with `#!/usr/bin/env
node`.
> These fail to start in the Nix Linux build sandbox, where
`/usr/bin/env`
> is absent, causing three output-draining tests to fail.
> 
> Use `process.execPath` in the generated shebangs so fixtures run with
the
> same Node executable as the test runner.

Related to #742
@tpansino

Copy link
Copy Markdown
Contributor Author

@EugeneTheDev could I please get a review of this as well? Thanks.

Comment thread src/__tests__/JsonSnapshot.test.ts Resolved
Comment thread src/JsonSnapshot.ts Resolved
Comment thread src/JsonSnapshot.ts Resolved
Comment thread src/JsonSnapshot.ts Resolved

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants