Skip to content

feat(workflow): opt-in settled result API - #109

Open
Waishnav wants to merge 2 commits into
pr/dw-9-resume-iteration-inspectionfrom
pr/dw-10-settled-results
Open

feat(workflow): opt-in settled result API#109
Waishnav wants to merge 2 commits into
pr/dw-9-resume-iteration-inspectionfrom
pr/dw-10-settled-results

Conversation

@Waishnav

@Waishnav Waishnav commented Jul 25, 2026

Copy link
Copy Markdown
Owner

Summary

  • add an opt-in settle(() => operation) workflow primitive
  • preserve existing Claude-like defaults: agent() throws, parallel()/pipeline() map failures to null
  • return provider-independent { ok, value } | { ok, error: { kind, message, retryable } }
  • support wrapping agent() and nested workflow operations without caching failed outcomes as successes
  • teach provider fallback and failure-aware fan-out in the Dynamic Workflows skill

Stack

Test plan

  • npm run typecheck
  • npm test
  • npm run build
  • git diff --check
  • engine tests cover success, normalized provider failure, journaling, and settled branches inside parallel()
  • sandbox/script tests cover injection and execution of settle()

Summary by CodeRabbit

  • New Features

    • Added settle() for handling workflow operations without throwing.
    • Returns structured success or failure results, including error type, message, and retryability.
    • Preserves failure details when used with parallel workflow branches.
    • Supports nested workflows and sandbox execution.
  • Documentation

    • Added usage guidance, provider fallback examples, and failure-handling recommendations.
    • Updated the workflow API cheatsheet with settle() syntax.
  • Tests

    • Added coverage for successful operations, provider failures, parallel execution, and sandbox behavior.

@coderabbitai

coderabbitai Bot commented Jul 25, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 8c5f4321-f86c-4b89-9c97-425c3133a929

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • ✅ Review completed - (🔄 Check again to review again)
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch pr/dw-10-settled-results

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@skills/dynamic-workflows/SKILL.md`:
- Around line 90-92: Update the journaling statement in the parallel()
documentation to scope it specifically to underlying agent calls that fail after
execution begins. Do not claim that settle() itself journals failures; retain
that settle() preserves branch failures as data and clarify that only failed
agent-call outcomes are journaled and excluded from successful cached-result
replay.

In `@src/workflow-sandbox.test.ts`:
- Around line 15-24: Normalize caught errors like production in both test
doubles: update the settle implementations in src/workflow-sandbox.test.ts lines
15-24 and src/workflow-script.test.ts lines 90-99 to use error.message for Error
instances and String(error) otherwise, while preserving the existing failure
result structure.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: f725217c-3185-4e56-9ef6-7333918c192c

📥 Commits

Reviewing files that changed from the base of the PR and between 058297b and a8db86f.

📒 Files selected for processing (11)
  • skills/dynamic-workflows/SKILL.md
  • src/workflow-api.ts
  • src/workflow-contracts.ts
  • src/workflow-engine.test.ts
  • src/workflow-engine.ts
  • src/workflow-sandbox.test.ts
  • src/workflow-sandbox.ts
  • src/workflow-script.test.ts
  • src/workflow-script.ts
  • src/workflow-tools.ts
  • src/workflow-types.ts

Comment on lines +90 to +92
Inside `parallel()`, wrap each branch with `settle()` to preserve failures as
data instead of `null`. Failed settled outcomes are journaled failures and are
not replayed as successful cached agent results.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Scope the journaling claim to agent calls.

settle() does not journal itself: settle(() => { throw new Error("x") }) returns failure data without an agent-call record. Limit the statement to underlying agent calls that fail after execution begins.

Proposed wording
-Inside `parallel()`, wrap each branch with `settle()` to preserve failures as
-data instead of `null`. Failed settled outcomes are journaled failures and are
-not replayed as successful cached agent results.
+Inside `parallel()`, wrap each agent branch with `settle()` to preserve failures
+as data instead of `null`. Failed agent calls are journaled as failures and are
+not replayed as successful cached agent results.
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
Inside `parallel()`, wrap each branch with `settle()` to preserve failures as
data instead of `null`. Failed settled outcomes are journaled failures and are
not replayed as successful cached agent results.
Inside `parallel()`, wrap each agent branch with `settle()` to preserve failures
as data instead of `null`. Failed agent calls are journaled as failures and are
not replayed as successful cached agent results.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@skills/dynamic-workflows/SKILL.md` around lines 90 - 92, Update the
journaling statement in the parallel() documentation to scope it specifically to
underlying agent calls that fail after execution begins. Do not claim that
settle() itself journals failures; retain that settle() preserves branch
failures as data and clarify that only failed agent-call outcomes are journaled
and excluded from successful cached-result replay.

Comment on lines +15 to +24
settle: async <T>(task: () => T | Promise<T>) => {
try {
return { ok: true, value: await task() };
} catch (error) {
return {
ok: false,
error: { kind: "internal", message: String(error), retryable: false },
};
}
},

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Match production Error-message normalization in both test doubles.

Production returns error.message for Error instances; these stubs return String(error) (for example, "Error: boom"). Tests inspecting settled failures can therefore validate behavior scripts never receive.

  • src/workflow-sandbox.test.ts#L15-L24: use error instanceof Error ? error.message : String(error).
  • src/workflow-script.test.ts#L90-L99: use the same normalization.
📍 Affects 2 files
  • src/workflow-sandbox.test.ts#L15-L24 (this comment)
  • src/workflow-script.test.ts#L90-L99
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/workflow-sandbox.test.ts` around lines 15 - 24, Normalize caught errors
like production in both test doubles: update the settle implementations in
src/workflow-sandbox.test.ts lines 15-24 and src/workflow-script.test.ts lines
90-99 to use error.message for Error instances and String(error) otherwise,
while preserving the existing failure result structure.

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.

1 participant