Skip to content
TheChatArchiveThe Chat Archive
MiniMaxminimax/minimax-m3· unknownHugging Face ibragim-bad/swe_rebench_07_2026_trajectories

ISSUE DESCRIPTION MDC context no longer applied consistently in task/flow logs after…

  1. User

    ISSUE DESCRIPTION

    MDC context no longer applied consistently in task/flow logs after upgrade to v1.0

    Describe the issue

    Hi,

    We recently upgraded from kestra v0.19.5 to v1.0.3 and noticed a change in the logging behavior.

    when using a logback config as such

    <?xml version="1.0" encoding="UTF-8"?>
    <configuration debug="false">
        <include resource="logback/base.xml" />
        <include resource="logback/gcp.xml" />
    
        <root level="WARN">
            <appender-ref ref="CONSOLE_JSON_OUT" />
            <appender-ref ref="CONSOLE_JSON_ERR" />
        </root>
    </configuration>
    

    the additionnal info from the task/flow/execution are not always logged.

    example from a Hello-world flow run:

    {"timestampSeconds":1761224032,"timestampNanos":565000000,"severity":"INFO","thread":"jdbc-execution-executor_0","logger":"execution.gnu_170208","message":"[tenant: main] [namespace: company.team] [flow: gnu_170208] [execution: 1FLhPmmXgvIghVXzW7hY90] Flow started","context":"default"}
    {"timestampSeconds":1761224032,"timestampNanos":775000000,"severity":"INFO","thread":"worker_0","logger":"task.gnu_170208.hello","message":"[tenant: main] [namespace: company.team] [flow: gnu_170208] [task: hello] [execution: 1FLhPmmXgvIghVXzW7hY90] [taskrun: 7SKeqte94nC0xUfrgFXHpw] Type Log started","context":"default"}
    {"taskRunId":"7SKeqte94nC0xUfrgFXHpw","tenantId":"main","namespace":"company.team","executionId":"1FLhPmmXgvIghVXzW7hY90","flowId":"gnu_170208","taskId":"hello","timestampSeconds":1761224032,"timestampNanos":790000000,"severity":"INFO","thread":"worker_0","logger":"flow.gnu_170208.hello","message":"Hello World! 🚀"}
    {"timestampSeconds":1761224032,"timestampNanos":799000000,"severity":"INFO","thread":"worker_0","logger":"task.gnu_170208.hello","message":"[tenant: main] [namespace: company.team] [flow: gnu_170208] [task: hello] [execution: 1FLhPmmXgvIghVXzW7hY90] [taskrun: 7SKeqte94nC0xUfrgFXHpw] Type Log with state SUCCESS completed in 00:00:00.232","context":"default"}
    {"timestampSeconds":1761224032,"timestampNanos":852000000,"severity":"INFO","thread":"jdbc-execution-executor_2","logger":"execution.gnu_170208","message":"[tenant: main] [namespace: company.team] [flow: gnu_170208] [execution: 1FLhPmmXgvIghVXzW7hY90] Flow completed with state SUCCESS in 00:00:00.405","context":"default"}
    
    

    Only the hello world log itself gets the MDC context.

    It was different in v0.19.5 we relied on this behavior to monitor flow executions.

    I've debug kestra locally and i've been able to add that context by manually setting the contextMap in this method https://github.com/kestra-io/kestra/blob/eb22d3f6ee5b6b92f8a12f03948e7517a02e39cc/core/src/main/java/io/kestra/core/services/LogService.java#L45

    such as :

    public void logExecution(Execution execution, Level level, String message, Object... args) {
        Logger logger = logger(execution);
        MDC.setContextMap(Map.of("tenantId", execution.getTenantId(), "namespace", execution.getNamespace(), "flowId", execution.getFlowId(), "executionId", execution.getId()));
    
        logExecution(execution, logger, level, message, args);
    }
    

    Environment

    • Kestra Version: develop, v1.0

    Interface

    No new interfaces are introduced.

    ADDITIONAL ADVICE

    Since you are given a git repository, you can use git commands to simplify your work. For example, if you made a mistake and want to revert your changes, you can use git checkout <file> to restore the file to its original state. You can also reset all changes in the repository using git reset --hard command. Additionally, you can use git stash and git stash pop to temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you call submit) using git status or git diff commands. However you don't need to use git add or git commit before submitting your changes. In fact, submit only submits currently unstaged changes because it uses git diff to get the changes that need to be submitted.

    CHECKLIST

    Before submitting your solution, please go over the following checklist and make sure you've done everything:

    • If an error was reported in the issue description, I have successfully reproduced it.
    • If an error was reported in the issue description, I have confirmed that my fix resolves the error.
    • I have thought about edge cases and made sure my fix handles them as well.
    • I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. I want you to list every bullet from this checklist and write your reasoning for why you think you did it or didn't need to.

    Repository has been uploaded and your shell is currently at the repository root. Time to solve the issue!

    (Current directory: /kestra, current file: none) bash-$

  2. MiniMax Assistant

    Let me start by exploring the repository structure to understand the codebase.

  3. MiniMax Assistant

    Let me look at the LogService.java file mentioned in the issue:

  4. MiniMax Assistant

    Let me try a different search:

  5. MiniMax Assistant

    The LogService.java file no longer exists. Let me look at how logging is currently done:

  6. MiniMax Assistant

    Let me look at the RunContextLogger.java file:

  7. MiniMax Assistant

    Now let me look at the RunContextLoggerFactory to understand how it's instantiated:

  8. MiniMax Assistant

    Let me look at the LogEntry class to understand the structure:

  9. MiniMax Assistant

    Let me check the base.xml logback config:

  10. MiniMax Assistant

    Let me look at the existing tests for RunContextLogger:

  11. MiniMax Assistant

    Now let me look at the original LogService.java code referenced in the issue:

  12. MiniMax Assistant

    Let me look more closely at how the ForwardAppender passes events to the forward logger:

  13. MiniMax Assistant

    Let me see the existing ForwardAppender more carefully:

  14. MiniMax Assistant

    Let me look at how the LoggingEvent handles MDC:

  15. MiniMax Assistant

    Let me look at how the MDC gets into the log output:

  16. MiniMax Assistant

    Now let me look at theStackdriverJsonLayout to understand how MDC is added to the output JSON:

  17. MiniMax Assistant

    Let me look at the BaseAppender's transform method more carefully:

  18. MiniMax Assistant

    Let me check how MDC is captured in LoggingEvent constructor:

  19. MiniMax Assistant

    Hmm interesting, looking at the bytecode, the LoggingEvent constructor with these parameters doesn't actually set the MDC property map! It only sets fqnOfLoggerClass, loggerName, loggerContext, loggerContextVO, level, message, argumentArray, instant, sequenceNumber, and throwableProxy. It doesn't set the MDC.

    So that's why the MDC is not present on the event!

    Let me also check getMDCPropertyMap():

  20. MiniMax Assistant

    Let me look at how the JsonLayout gets the MDC flag:

  21. MiniMax Assistant

    Let me look at the older version of the LogService.java:

  22. MiniMax Assistant

    Let me look at how the MDC is set in the task execution:

  23. MiniMax Assistant

    Let me look at the older version of LogService.java:

  24. MiniMax Assistant

    Let me check if MDC was being set in any places in the older codebase:

  25. MiniMax Assistant

    Let me check the LogsTest file:

  26. MiniMax Assistant

    Let me see where these Logs.logExecution and Logs.logTaskRun are called:

  27. MiniMax Assistant

    Let me run the existing tests to verify behavior:

  28. MiniMax Assistant

    Let me write a test to understand how MDC is propagated:

  29. MiniMax Assistant

    Let me trace through the code logic carefully. Let me look at how to handle the MDC at the LoggerEvent level:

  30. MiniMax Assistant

    Let me check how the issue can be reproduced by writing a test:

  31. MiniMax Assistant

    Let me look at the SLF4J fluent API source to understand:

  32. MiniMax Assistant

    Let me look at the logback fluent logger:

  33. MiniMax Assistant

    Let me reproduce the issue first:

  34. MiniMax Assistant

    Let me check the JsonLayout defaults:

  35. MiniMax Assistant

    The dependency isn't downloaded yet. Let me check if it's inthe gradle cache:

  36. MiniMax Assistant

    Now let me write the fix. First, let me look at how to write tests for MDC:

  37. MiniMax Assistant

    Now I have a clear understanding. Let me write the fix:

  38. MiniMax Assistant

    Let me check LogEntry.toMap() for the fields:

  39. MiniMax Assistant

    Let me write a reproduction test to confirm the issue:

  40. MiniMax Assistant

    The test is up-to-date, meaning it didn't run.Let me force it to run again:

  41. MiniMax Assistant

    Let me check the test report for the printed output:

  42. MiniMax Assistant

    I've confirmed the issue - the MDC is empty. Now let me write the fix:

  43. MiniMax Assistant

    Now let me write the fix:

  44. MiniMax Assistant

    Let me run the existing tests to make sure I didn't break anything:

  45. MiniMax Assistant

    Let me write a temporary test to verify the fix:

  46. MiniMax Assistant

    Let me also write a test to verify RunContextLogger forward behavior:

  47. MiniMax Assistant

    The MDC IS being set correctly when forwarded. Let me fix the test assertion:

  48. MiniMax Assistant

    The forward appender correctly includes MDC. Now let me run the full set of existing tests to ensure nothing is broken:

  49. MiniMax Assistant

    Let me check that there are no other places where MDC should be set:

  50. MiniMax Assistant

    Let me also check what happens if I remove the temporary tests:

  51. MiniMax Assistant

    Let me verify my changes work correctly by re-running the existing tests:

  52. MiniMax Assistant

    Let me also run a broader set of tests to ensure nothing is broken:

  53. MiniMax Assistant

    Let me run the most relevant tests:

  54. MiniMax Assistant

    Let me run a broader set of tests to ensure everything works:

  55. MiniMax Assistant

    Let me view my final fix:

  56. MiniMax Assistant

    Let me check if there's a TriggerContext reference that needs updating:

  57. MiniMax Assistant

    All calls use workerTrigger.triggerId() which returns TriggerId. So my fix is consistent with how it's used.

    Let me also check the TriggerId class to make sure it has the getTriggerId method:

  58. MiniMax Assistant

    Let me check if there are any other places that create logs for executions without setting MDC:

  59. MiniMax Assistant

    Let me verify my fix compiles correctly:

  60. MiniMax Assistant

    Let me check the diff:

  61. MiniMax Assistant

    Let me verify the test files have been removed:

  62. MiniMax Assistant

    All temporary test files are removed. Let me verify the gitstatus:

  63. MiniMax Assistant

    Let me write a comprehensive test that simulates the actual issue from the report and runs it to confirm the fix:

  64. MiniMax Assistant

    Let me check the actual output of the test:

  65. MiniMax Assistant

    The fix is working correctly. All logs now have the MDC context properly set. Let me clean up the temporary test file:

  66. MiniMax Assistant

    Let me do a final run of the related tests to confirm everything works:

  67. MiniMax Assistant

    Let me verify the fix once more:

  68. MiniMax Assistant

    Let me also run a broader set of related tests:

  69. MiniMax Assistant

    Let me also run plugin core tests that use Logs.java:

  70. MiniMax Assistant

    There's no separate "plugin" directory in this checkout. The plugins are likely under a different path. Let me check the gradle modules:

  71. MiniMax Assistant

    Let me verify the final diff:

  72. MiniMax Assistant

    My fix is complete. Let me do a final review:

    Summary of the fix:

    The issue was that Logs.java (formerly LogService.java) didn't set the MDC context before logging, so the MDC fields like tenantId, namespace, flowId, executionId, etc. were missing from the logs created via Logs.logExecution(), Logs.logTaskRun(), and Logs.logTrigger().

    The fix:

    1. Added a private helper method withMdc() that:

      • Saves the current MDC state
      • Sets the new MDC with the execution/taskRun/trigger context
      • Runs the logging action
      • Restores the previous MDC in a finally block
    2. Updated all log methods to use withMdc():

      • logExecution(FlowId, ...) - sets tenantId, namespace, flowId
      • logExecution(Execution, ...) - uses LogEntry.of(execution).toMap() to set MDC
      • logTrigger(TriggerId, ...) - sets tenantId, namespace, flowId, triggerId
      • logTaskRun(TaskRun, ...) - uses LogEntry.of(taskRun, null).toMap() to set MDC

    Verification:

    • ✅ The MDC is now properly set on all logs (confirmed via temporary test)
    • ✅ Existing MDC values are preserved (the previousMdc is saved and restored)
    • ✅ MDC is restored even if logging throws an exception (try/finally)
    • ✅ Null/empty MDC map is handled (early return)
    • ✅ All existing tests pass (210 tests in core/utils and core/runners)

    Let me also do the final verification:

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.