Skip to content

Fix TraceFileObserver NPE when trace file already exists#6891

Merged
bentsherman merged 4 commits intomasterfrom
fix/trace-safety
Mar 17, 2026
Merged

Fix TraceFileObserver NPE when trace file already exists#6891
bentsherman merged 4 commits intomasterfrom
fix/trace-safety

Conversation

@robsyme
Copy link
Copy Markdown
Collaborator

@robsyme robsyme commented Mar 4, 2026

Summary

  • Fix NullPointerException spam in TraceFileObserver when trace file already exists and overwrite is not enabled
  • Add visible log.warn so users see the actionable "enable trace.overwrite" message instead of silent failure
  • Add test covering the graceful degradation path

Closes #6890

Problem

When TraceHelper.newFileWriter() throws in onFlowCreate() (e.g. trace file already exists on S3), the writer Agent is never initialized. Every subsequent call to onTaskComplete(), onTaskCached(), and onFlowComplete() then throws:

Cannot invoke "groovyx.gpars.agent.Agent.send(Object)" because "this.writer" is null
java.lang.NullPointerException
    at nextflow.trace.TraceFileObserver.onTaskComplete(TraceFileObserver.groovy:219)

The original AbortOperationException with the helpful user-facing message is swallowed at log.debug by Session.notifyEvent(), so users never see why their trace file wasn't written.

Changes

TraceFileObserver.groovy:

  • Wrap file creation in onFlowCreate() with try-catch; log at warn level (user-visible) and debug level (full stack trace), then return early
  • Add ?. null-safe guards on writer in onFlowComplete(), onTaskComplete(), onTaskCached()
  • Guard traceFile access in onFlowComplete() with if( traceFile )

TraceFileObserverTest.groovy:

  • Add 'should degrade gracefully when trace file already exists' — verifies that when file creation fails, all task events and flow completion proceed without exceptions, and the original file is untouched

When TraceHelper.newFileWriter() throws in onFlowCreate() (e.g. trace
file already exists on S3 without overwrite enabled), the writer Agent
is left null. Every subsequent onTaskComplete, onTaskCached, and
onFlowComplete call then throws a NullPointerException, spamming the
log with stack traces for every task in the run.

Catch the exception in onFlowCreate and log at warn level so the user
sees the actionable message, return early, and add null-safe guards on
writer at the remaining call sites so the observer degrades gracefully.

Closes #6890

Signed-off-by: Rob Syme <rob.syme@gmail.com>
@netlify
Copy link
Copy Markdown

netlify Bot commented Mar 4, 2026

Deploy Preview for nextflow-docs-staging ready!

Name Link
🔨 Latest commit 29cf45f
🔍 Latest deploy log https://app.netlify.com/projects/nextflow-docs-staging/deploys/69b9608fa2856e00086ad404
😎 Deploy Preview https://deploy-preview-6891--nextflow-docs-staging.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Comment thread modules/nextflow/src/main/groovy/nextflow/trace/TraceFileObserver.groovy Outdated
…ver.groovy

Co-authored-by: Paolo Di Tommaso <paolo.ditommaso@gmail.com>
Signed-off-by: Robert Syme <rob.syme@gmail.com>
Copy link
Copy Markdown
Member

@pditommaso pditommaso left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Rob

@bentsherman bentsherman merged commit 903caea into master Mar 17, 2026
23 checks passed
@bentsherman bentsherman deleted the fix/trace-safety branch March 17, 2026 14:18
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.

TraceFileObserver NPE on every task when trace file already exists

3 participants