Skip to content

fix(engine): use type-appropriate zero values for optional input defaults#123

Open
PolyphonyRequiem wants to merge 2 commits intomicrosoft:mainfrom
PolyphonyRequiem:fix/optional-input-defaults
Open

fix(engine): use type-appropriate zero values for optional input defaults#123
PolyphonyRequiem wants to merge 2 commits intomicrosoft:mainfrom
PolyphonyRequiem:fix/optional-input-defaults

Conversation

@PolyphonyRequiem
Copy link
Copy Markdown
Member

Problem

Optional workflow inputs without an explicit default: value previously defaulted to Python None. This causes two issues:

  1. Templates render "None"{{ workflow.input.optional_msg }} renders as the literal string "None" instead of empty string
  2. | default() doesn't catch None{{ workflow.input.optional_msg | default("fallback") }} still renders "None" because Jinja's default filter only catches undefined, not None (unless boolean=true is passed)

Reproduction

workflow:
  name: test-optional
  entry_point: echo
  input:
    required_id:
      type: number
      required: true
    optional_msg:
      type: string
      required: false
      # no default: specified
agents:
  - name: echo
    type: script
    command: pwsh
    args:
      - "-Command"
      - "Write-Output '{{ workflow.input.optional_msg | default(\"fallback\") }}'; exit 0"
    routes:
      - to: $end

conductor run test.yaml --input required_id=42

Expected: Script outputs fallback (or empty string)
Actual: Script outputs None

Fix

_apply_input_defaults() now uses type-appropriate zero values instead of None for optional inputs with no declared default:

Type Zero value
string ""
number 0
boolean false
array []
object {}

Explicit default: values in the schema are still honored. This is a backward-compatible change — templates that checked if workflow.input.X will still work since zero values are falsy.

Changes

  • src/conductor/engine/workflow.py: Add _TYPE_ZERO_VALUES class constant, update _apply_input_defaults() to use it
  • tests/test_engine/test_workflow.py: Test verifying optional inputs render cleanly (no "None")

Testing

  • 75 workflow engine tests pass (including new test)

…ults

Optional workflow inputs without an explicit `default:` previously
defaulted to Python None, which renders as "None" in templates and
isn't caught by Jinja's `| default()` filter without the boolean flag.

Now uses type-appropriate zero values: "" for string, 0 for number,
false for boolean, [] for array, {} for object. This ensures templates
render cleanly without requiring `| default()` guards or `if X else Y`
workarounds.

Explicit `default:` values in the schema are still honored.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 25, 2026

Codecov Report

❌ Patch coverage is 75.00000% with 2 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (main@dbcf20f). Learn more about missing BASE report.

Files with missing lines Patch % Lines
src/conductor/engine/workflow.py 75.00% 2 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #123   +/-   ##
=======================================
  Coverage        ?   84.84%           
=======================================
  Files           ?       53           
  Lines           ?     7172           
  Branches        ?        0           
=======================================
  Hits            ?     6085           
  Misses          ?     1087           
  Partials        ?        0           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Replace shared [] and {} instances in the class-level _TYPE_ZERO_VALUES
dict with a _zero_value_for_type() method that returns fresh copies for
mutable types (array, object). Prevents potential shared-state bugs if
a caller ever mutates the returned default.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.

2 participants