Skip to content

feat: Detached Tasks#106

Merged
monoxgas merged 6 commits into
mainfrom
feat/detached-tasks
Jul 17, 2025
Merged

feat: Detached Tasks#106
monoxgas merged 6 commits into
mainfrom
feat/detached-tasks

Conversation

@monoxgas
Copy link
Copy Markdown
Contributor

@monoxgas monoxgas commented Jul 16, 2025

Detached Tasks

Key Changes:

  • Enable tasks to run outside of run contexts
  • Standardize attribute parameter patterns across API
  • Add proper null checks and optional run handling
  • Improve task span initialization for detached execution

Added:

  • Detached task execution capability
  • Enhanced documentation with parameter details for log_output
  • Null-safe run context handling throughout codebase

Changed:

  • Replaced **attributes with attributes: AnyDict | None = None pattern
  • Updated all API methods to use consistent attribute parameter style
  • Modified task execution to handle missing run context gracefully
  • Updated documentation to reflect new parameter signatures
  • Enhanced task span creation with optional run context

Removed:

  • Hard requirement for run context in task execution
  • Inconsistent **attributes parameter patterns
  • JsonDict type usage in favor of AnyDict

Generated Summary:

  • Updated function definitions across multiple files to replace **attributes: JsonValue with attributes: AnyDict | None.
  • Enhanced consistency of attribute parameter types to ensure they are clearly defined as optional dictionaries.
  • Adjusted method calls to align with the new attribute parameter syntax, making the API cleaner and more intuitive.
  • Fixed conditional checks to ensure they handle the case when run is None, preventing possible runtime errors.
  • Improved documentation to specify attributes across various functions clearly.
  • Overall, these changes improve maintainability and readability of the SDK, and ensure that function signatures are more consistent across the codebase.

This summary was generated with ❤️ by rigging

@monoxgas monoxgas requested a review from Copilot July 16, 2025 23:40
@dreadnode-renovate-bot dreadnode-renovate-bot Bot added area/docs Changes to documentation and guides type/docs Documentation updates and improvements labels Jul 16, 2025
Copy link
Copy Markdown
Contributor

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 enables tasks to run outside of run contexts while standardizing the API parameter patterns across the codebase. The changes allow for "detached tasks" that can execute independently without requiring an active run, while maintaining backward compatibility for existing run-based workflows.

  • Removes hard requirements for run context in task execution
  • Standardizes attribute parameter patterns from **attributes to attributes: AnyDict | None = None
  • Enhances string cleaning utility and improves API documentation

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
dreadnode/util.py Enhanced clean_str function to strip trailing underscores
dreadnode/tracing/span.py Updated span constructors to support optional run context and standardized attribute parameters
dreadnode/task.py Modified task execution to handle missing run context gracefully
dreadnode/main.py Standardized API method signatures and improved documentation
docs/sdk/task.mdx Updated documentation to reflect detached task execution changes
docs/sdk/main.mdx Updated documentation with new parameter signatures and enhanced details

Comment thread dreadnode/task.py Outdated
run_id=run.run_id if run else "",
tracer=self.tracer,
) as span:
if self.log_execution_metrics:
Copy link

Copilot AI Jul 16, 2025

Choose a reason for hiding this comment

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

This line will cause a runtime error when run is None. The code should check if run is not None before calling run.log_metric(), similar to the pattern used elsewhere in this file.

Suggested change
if self.log_execution_metrics:
if self.log_execution_metrics and run is not None:

Copilot uses AI. Check for mistakes.
Comment thread dreadnode/tracing/span.py
label: str | None = None,
event_name: str = EVENT_NAME_OBJECT,
**attributes: JsonValue,
attributes: AnyDict | None = None,
Copy link

Copilot AI Jul 16, 2025

Choose a reason for hiding this comment

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

The signature change from **attributes: JsonValue to attributes: AnyDict | None = None is inconsistent with other log methods in the same class that still use **attributes: JsonValue pattern (lines 610, 725). This creates an inconsistent API within the same class.

Suggested change
attributes: AnyDict | None = None,
**attributes: JsonValue,

Copilot uses AI. Check for mistakes.
Comment thread dreadnode/tracing/span.py
Comment on lines 819 to +821
**attributes: JsonValue,
) -> str:
label = label or clean_str(name)
hash_ = self.run.log_object(
label = clean_str(label or name)
Copy link

Copilot AI Jul 16, 2025

Choose a reason for hiding this comment

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

This method still uses the old **attributes: JsonValue pattern while other methods in the same class have been updated to use attributes: AnyDict | None = None. This creates inconsistency within the TaskSpan class API.

Copilot uses AI. Check for mistakes.
Comment thread dreadnode/tracing/span.py
Comment on lines 848 to +850
**attributes: JsonValue,
) -> str:
label = label or clean_str(name)
hash_ = self.run.log_object(
label = clean_str(label or name)
Copy link

Copilot AI Jul 16, 2025

Choose a reason for hiding this comment

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

This method still uses the old **attributes: JsonValue pattern while other methods in the same class have been updated to use attributes: AnyDict | None = None. This creates inconsistency within the TaskSpan class API.

Copilot uses AI. Check for mistakes.
Comment thread dreadnode/main.py
raise RuntimeError("log_inputs() must be called within a run")

target.log_input(name, value, label=label, **attributes)
target.log_input(name, value, label=label, attributes=attributes)
Copy link

Copilot AI Jul 16, 2025

Choose a reason for hiding this comment

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

This call will fail because the target's log_input method still expects **attributes: JsonValue but is being called with attributes=attributes. The underlying method signature hasn't been updated to match the new API pattern.

Suggested change
target.log_input(name, value, label=label, attributes=attributes)
target.log_input(name, value, label=label, **(attributes or {}))

Copilot uses AI. Check for mistakes.
Comment thread dreadnode/main.py
)

target.log_output(name, value, label=label, **attributes)
target.log_output(name, value, label=label, attributes=attributes)
Copy link

Copilot AI Jul 16, 2025

Choose a reason for hiding this comment

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

This call will fail because the target's log_output method still expects **attributes: JsonValue but is being called with attributes=attributes. The underlying method signature hasn't been updated to match the new API pattern.

Suggested change
target.log_output(name, value, label=label, attributes=attributes)
target.log_output(name, value, label=label, **(attributes or {}))

Copilot uses AI. Check for mistakes.
@monoxgas monoxgas merged commit 769bc1f into main Jul 17, 2025
8 checks passed
@monoxgas monoxgas deleted the feat/detached-tasks branch July 17, 2025 02:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/docs Changes to documentation and guides type/docs Documentation updates and improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants