Skip to content

fix: reduce @log decorator volume to prevent thread-stream flush timeout#1215

Merged
scolladon merged 3 commits intomainfrom
fix/reduce-log-decorator-volume
Feb 18, 2026
Merged

fix: reduce @log decorator volume to prevent thread-stream flush timeout#1215
scolladon merged 3 commits intomainfrom
fix/reduce-log-decorator-volume

Conversation

@scolladon
Copy link
Copy Markdown
Owner

Explain your changes

The @log decorator eagerly serialized method arguments and results via JSON.stringify on every invocation (25 usages across 15 files). For large diffs (800+ components), hot-path methods like StandardHandler.collect, TypeHandlerFactory.getTypeHandler, and MetadataDiff.compare generated thousands of log entries with potentially MB-sized payloads (full XML trees, file contents). This overwhelmed pino's thread-stream transport, causing its hardcoded 10s flushSync timeout to fail at process exit.

Changes:

  • Simplify the @log decorator to only emit lightweight Logger.trace for entry/exit (class name + method name, no serialization)
  • Remove dead code (stringify, hasCustomToString, replacer) that was only used by the removed debug calls
  • Add Logger.debug with relevant context to catch blocks that were previously relying on the decorator for diagnostic information:
    • GitAdapter.gitGrep: was completely silent, now logs pattern/path/revision
    • StandardHandler.collect: adds change type and metadata type to existing warn
    • ConfigValidator._validateGitSha: logs parameter name, value, and raw error

Does this close any currently open issues?

closes #1214

  • Jest tests added to cover the fix.
  • NUT tests added to cover the fix.
  • E2E tests added to cover the fix.

Any particular element that can be tested locally

Run sf sgd source delta with a large diff (800+ components) and SF_LOG_LEVEL=debug — the command should complete without _flushSync took too long errors.

Any other comments

The root cause is that pino's thread-stream has a hardcoded 10s flush timeout (Atomics.wait with 10 spins × 1s) that is not configurable through @salesforce/core. Rather than trying to work around the timeout, this fix eliminates the log volume that causes it.

Trace-level entry/exit logging is preserved for execution flow debugging. Debug-level context is now logged at error boundaries (catch blocks) where it is most useful for diagnosing issues.

Remove Logger.debug calls from the @log decorator that eagerly
serialized method arguments and results via JSON.stringify on every
invocation. This caused thread-stream flush timeouts for large diffs
(800+ components) when debug logging was enabled (#1214).

The decorator now only emits lightweight Logger.trace for entry/exit.
Remove dead code (stringify, hasCustomToString, replacer) and update
tests accordingly.
@codecov
Copy link
Copy Markdown

codecov bot commented Feb 17, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (2db49be) to head (d9acd46).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #1215   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           57        57           
  Lines         1543      1528   -15     
  Branches       201       194    -7     
=========================================
- Hits          1543      1528   -15     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Add Logger.debug with relevant context to catch blocks that were
previously relying on the @log decorator for diagnostic information:
- GitAdapter.gitGrep: was completely silent, now logs pattern/path/revision
- StandardHandler.collect: adds change type and metadata type to existing warn
- ConfigValidator._validateGitSha: logs parameter name, value, and raw error
@scolladon scolladon force-pushed the fix/reduce-log-decorator-volume branch from b195ab7 to 4203209 Compare February 17, 2026 16:42
@scolladon
Copy link
Copy Markdown
Owner Author

Hi @gjagadish1234 !

Could you test on your laptop and help us validate this PR please ?
You can follow those steps to easily do it locally.

sf plugins install sf-git-merge-driver@dev-1215

scolladon added a commit to scolladon/sf-git-merge-driver that referenced this pull request Feb 17, 2026
Remove eager JSON.stringify serialization from the @log decorator
(stringify, hasCustomToString, replacer) that ran on every invocation.
The decorator now only emits lightweight Logger.trace for entry/exit.

Also defer JSON.stringify in run.ts debug calls using lazy evaluation,
and add missing valueSettings test for 100% coverage.

Port of scolladon/sfdx-git-delta#1215.
scolladon added a commit to scolladon/sf-git-merge-driver that referenced this pull request Feb 17, 2026
Remove eager JSON.stringify serialization from the @log decorator
(stringify, hasCustomToString, replacer) that ran on every invocation.
The decorator now only emits lightweight Logger.trace for entry/exit.

Also defer JSON.stringify in run.ts debug calls using lazy evaluation,
and add missing valueSettings test for 100% coverage.

Port of scolladon/sfdx-git-delta#1215.
@gjagadish1234
Copy link
Copy Markdown

gjagadish1234 commented Feb 18, 2026

Hi @gjagadish1234 !

Could you test on your laptop and help us validate this PR please ? You can follow those steps to easily do it locally.

sf plugins install sf-git-merge-driver@dev-1215

Hi @scolladon

Thank you for the quick response and for looking into this

I'd like to clarify that in the issue I didn't explicitly mention this, but the flush sync issue has only been observed in our CI/CD pipeline not locally. To validate this, I tested it directly in the pipeline using sf plugins install sfdx-git-delta@dev-1215, and the flush sync issue was not reproduced.

@github-actions
Copy link
Copy Markdown

Published under dev-1215 npm channel.

$ sf plugins install sf-git-merge-driver@dev-1215

@scolladon scolladon merged commit 181a27d into main Feb 18, 2026
22 of 24 checks passed
@scolladon scolladon deleted the fix/reduce-log-decorator-volume branch February 18, 2026 06:39
@github-actions
Copy link
Copy Markdown

Shipped in release v6.32.1.
Version v6.32.1 will be assigned to the latest npm channel soon
Install it using either v6.32.1 or the latest-rc npm channel

$ sf plugins install sfdx-git-delta@latest-rc
# Or
$ sf plugins install sfdx-git-delta@v6.32.1

💡 Enjoying sfdx-git-delta?
Your contribution helps us provide fast support 🚀 and high quality features 🔥
Become a sponsor 💙
Happy incremental deployment!

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.

Error '_flushSync took too long' while generating a delta

2 participants