Fix forked process console forwarding reporting shared references as circular - #335594
Open
Leo Camus (Dev-next-gen) wants to merge 2 commits into
Open
Fix forked process console forwarding reporting shared references as circular#335594Leo Camus (Dev-next-gen) wants to merge 2 commits into
Leo Camus (Dev-next-gen) wants to merge 2 commits into
Conversation
…circular
The JSON.stringify replacer in bootstrap-fork's safeToString pushed every
object into a `seen` array and never removed anything, so a value that is
referenced twice in the console arguments of a forked process (a DAG, not
a cycle) was forwarded to the parent as "[Circular]" after its first
occurrence. For example console.log(shared, { a: shared, b: shared })
arrived as [{"value":1},{"a":"[Circular]","b":"[Circular]"}].
Track only the current ancestor path instead, using the replacer's `this`
(the holder) to drop subtrees that are finished. True cycles are still
reported as "[Circular]". The isObject helper is gone: every object has
to be tracked for the holder check to work, and RegExp/Date were the only
exclusions (a Date is already a string by the time the replacer sees it).
Added an integration test that forks bootstrap-fork with a fixture that
logs a shared reference and a genuine cycle.
Copilot started reviewing on behalf of
Leo Camus (Dev-next-gen)
September 10, 2026 23:23
View session
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The implementation and focused integration test correctly cover the regression; the remaining comment-style feedback is non-blocking.
Pull request overview
Fixes console forwarding so shared object references are serialized normally while genuine cycles remain protected.
Changes:
- Tracks only the active ancestor path during serialization.
- Adds integration coverage for shared references and cycles.
- Adds a forked-process fixture producing representative console output.
File summaries
| File | Description |
|---|---|
src/bootstrap-fork.ts |
Corrects circular-reference detection. |
src/vs/base/test/node/processes/processes.integrationTest.ts |
Verifies forwarded console arguments. |
src/vs/base/test/node/processes/fixtures/fork_console.ts |
Provides shared and circular test values. |
Review details
- Files reviewed: 3/3 changed files
- Comments generated: 1
- Review effort level: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
While fixing
safeStringifyin #335589 I noticed thatsrc/bootstrap-fork.tshas its own copy of the same replacer.safeToString, which forwardsconsole.*calls from forked processes to the parent whenVSCODE_VERBOSE_LOGGINGis set (the pty host, the file watcher and the agent host starters all set it), pushes every object into aseenarray and never removes anything. So an object that is logged twice, or referenced from two properties, reaches the parent as"[Circular]"after its first occurrence, even though there is no cycle.With a forked fixture that runs
the
__$consolemessage the parent receives is:The fix is the same one as in #335589 and in
stableStringify(#327398). The replacer only tracks the current ancestor path, and usesthis(the holder) to pop subtrees that are finished. Real cycles are still replaced with"[Circular]". I removed theisObjecthelper because every object has to go on the stack for the holder check to work. Together with theArray.isArraycheck, the only objects it left out were RegExp and Date instances, and a Date has already been turned into a string bytoJSONby the time the replacer sees it.How I tested it: I added a case to
processes.integrationTest.tsthat forksbootstrap-forkwith a newfork_consolefixture and checks the forwarded arguments, including a genuine cycle. It fails against the currentbootstrap-fork.tswith the "before" output above and passes with the fix, and the other tests in the file still pass. I ran it withtest/unit/node/index.js --run src/vs/base/test/node/processes/processes.integrationTest.ts, with the Node version check commented out because the machine I used has Node 22. eslint is clean on the changed files andtypecheck-clientreports nothing in them.There is no issue for this that I could find. This PR doesn't depend on #335589, they touch different files.
AI tools used