Skip to content

Conversation

drockparashar
Copy link
Contributor

@drockparashar drockparashar commented Sep 30, 2025

Changelog

-Ensures consistent workflow output path for both manual and scheduled runs.
-Removes any timestamp or schedule-specific suffix from workflow_id when generating the output path.
-Output path now always follows the format: artifacts/apps/{application_name}/workflows/{workflow_id}/{run_id}.

Additional context (e.g. screenshots, logs, links)

image

closes #719

Checklist

  • Additional tests added
  • All CI checks passed
  • Relevant documentation updated

Copyleft License Compliance

  • Have you used any code that is subject to a Copyleft license (e.g., GPL, AGPL, LGPL)?
  • If yes, have you modified the code in the context of this project? please share additional details.

Note

Normalize workflow output paths by stripping timestamp suffixes from workflow IDs; add targeted unit tests.

  • Utilities (application_sdk/activities/common/utils.py):
    • build_output_path: Strip schedule timestamp suffix (-YYYY-MM-DDTHH:MM:SSZ) from workflow_id using compiled TIMESTAMP_PATTERN before formatting output path.
    • Add re import and TIMESTAMP_PATTERN constant.
  • Tests (tests/unit/activities/common/test_utils.py):
    • Add tests for build_output_path covering standard ID, scheduled ID with timestamp removal, and empty ID handling.

Written by Cursor Bugbot for commit c10ff41. This will update automatically on new commits. Configure here.

@Copilot Copilot AI review requested due to automatic review settings September 30, 2025 02:16
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes inconsistent workflow output paths between manual and scheduled workflow runs by sanitizing the workflow ID to remove timestamp suffixes.

  • Adds regex-based sanitization to remove timestamp suffixes from workflow IDs
  • Ensures consistent output path format: artifacts/apps/{application_name}/workflows/{workflow_id}/{run_id}
  • Imports the re module to support regular expression operations

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines 78 to 79
# If workflow_id contains a timestamp (e.g., '-YYYY-MM-DDTHH:MM:SSZ'), remove it
sanitized_workflow_id = re.sub(r'-\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$', '', raw_workflow_id)
Copy link
Preview

Copilot AI Sep 30, 2025

Choose a reason for hiding this comment

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

The regex pattern is hardcoded and assumes a specific timestamp format. Consider defining this as a module-level constant with a descriptive name like SCHEDULE_TIMESTAMP_PATTERN to improve maintainability and make the pattern reusable.

Copilot uses AI. Check for mistakes.

raw_workflow_id = get_workflow_id()

# If workflow_id contains a timestamp (e.g., '-YYYY-MM-DDTHH:MM:SSZ'), remove it
sanitized_workflow_id = re.sub(r'-\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$', '', raw_workflow_id)
Copy link
Preview

Copilot AI Sep 30, 2025

Choose a reason for hiding this comment

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

The regex should be compiled once at module level for better performance, especially since this function may be called frequently. Use re.compile() to create a compiled pattern object.

Copilot uses AI. Check for mistakes.

cursor[bot]

This comment was marked as outdated.

- Move timestamp regex to module-level constant for maintainability
- Use compiled regex pattern for performance
- Add fallback to raw workflow_id if sanitization results in empty string
logger = get_logger(__name__)

# Compiled regex pattern for removing timestamp suffix from workflow IDs
TIMESTAMP_PATTERN = re.compile(r"-\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$")
Copy link
Member

Choose a reason for hiding this comment

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

let's keep this variable localized as it's only used by a a single method as of now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I implemented that initially, but the copilot suggested me otherwise, what should i go with?

image

Comment on lines +86 to +87
if not sanitized_workflow_id:
sanitized_workflow_id = raw_workflow_id
Copy link
Member

Choose a reason for hiding this comment

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

when could be this be the case? can you handle in tests if so

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This case should not occur in practice, as workflow IDs are always generated by Temporal and will include a valid identifier. The fallback is just a safeguard for unexpected input, but is not expected to be triggered in real workflows.

Copy link
Member

@inishchith inishchith left a comment

Choose a reason for hiding this comment

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

thanks for contributing. the change looks fine, could you contribute to unit tests for this function?

@drockparashar
Copy link
Contributor Author

thanks for contributing. the change looks fine, could you contribute to unit tests for this function?

Sure, I'll start working on it right away!

@drockparashar
Copy link
Contributor Author

@inishchith , I've added the unit tests for the build_output_path function in the tests folder!

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.

Fix workflow output path when run in schedule mode
2 participants