Skip to content

Conversation

@jumski
Copy link
Contributor

@jumski jumski commented Sep 16, 2025

Enhanced Map Step Input Processing

  • Updated start_tasks function to build step input conditionally based on step type
  • Implemented logic for root and dependent map steps to extract array elements
  • Added a new migration script to handle array elements in start_tasks
  • Included comprehensive tests for dependent map element extraction, large array processing, mixed JSON types, and nested arrays
  • Improved handling of array-based tasks and input construction for various step configurations

@changeset-bot
Copy link

changeset-bot bot commented Sep 16, 2025

⚠️ No Changeset found

Latest commit: e87df3c

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 16, 2025

Important

Review skipped

Auto reviews are disabled on this repository.

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.

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

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

✨ Finishing touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch 09-16-handle-arrays-in-start-tasks

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 and usage tips.

Copy link
Contributor Author

jumski commented Sep 16, 2025

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • merge:queue - adds this PR to the back of the merge queue
  • hotfix:queue - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@jumski jumski marked this pull request as ready for review September 16, 2025 19:53
@nx-cloud
Copy link

nx-cloud bot commented Sep 16, 2025

View your CI Pipeline Execution ↗ for commit e87df3c

Command Status Duration Result
nx run-many -t build --projects client,dsl --co... ✅ Succeeded 4s View ↗
nx affected -t build --configuration=production... ✅ Succeeded 3s View ↗
nx affected -t lint typecheck test --parallel -... ✅ Succeeded 6m 5s View ↗

☁️ Nx Cloud last updated this comment at 2025-10-06 15:33:40 UTC

@jumski jumski force-pushed the 09-16-handle-arrays-in-start-tasks branch 3 times, most recently from ce60c8e to a462a29 Compare September 17, 2025 04:39
Comment on lines 352 to 353
(select flow_start_time_ms <= task_creation_time_ms * 1.5
from map_performance
Copy link
Contributor

Choose a reason for hiding this comment

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

The variable comparison appears to be reversed. The test is checking if array processing scales linearly, but the variables in the comparison don't match their content:

select ok(
  (select flow_start_time_ms <= task_creation_time_ms * 1.5
   from map_performance
   where array_size = -1),
  'Array processing MUST scale linearly (time_ratio <= size_ratio * 1.5)'
);

In the sentinel row (where array_size = -1), flow_start_time_ms contains the time ratio and task_creation_time_ms contains the size ratio. The comparison should be:

select ok(
  (select time_ratio <= size_ratio * 1.5
   from map_performance
   where array_size = -1),
  'Array processing MUST scale linearly (time_ratio <= size_ratio * 1.5)'
);

Or using the existing column names:

select ok(
  (select flow_start_time_ms <= task_creation_time_ms * 1.5
   from map_performance
   where array_size = -1),
  'Array processing MUST scale linearly (time_ratio <= size_ratio * 1.5)'
);
Suggested change
(select flow_start_time_ms <= task_creation_time_ms * 1.5
from map_performance
(select time_ratio <= size_ratio * 1.5
from map_performance

Spotted by Diamond

Fix in Graphite


Is this helpful? React 👍 or 👎 to let us know.

Comment on lines +133 to +135
(SELECT jsonb_array_element(value, st.task_index)
FROM jsonb_each(dep_out.deps_output)
LIMIT 1)
Copy link
Contributor

Choose a reason for hiding this comment

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

Critical bug: The subquery uses LIMIT 1 without ORDER BY, making the result non-deterministic when a map step has multiple dependencies. While the comment states 'Map steps have exactly 1 dependency (enforced by add_step)', this creates a race condition if that constraint is ever violated or if there are concurrent modifications. The query should either add ORDER BY for deterministic results or add a runtime check to ensure exactly one dependency exists. This could cause map tasks to receive elements from random dependencies in multi-dependency scenarios.

Suggested change
(SELECT jsonb_array_element(value, st.task_index)
FROM jsonb_each(dep_out.deps_output)
LIMIT 1)
(SELECT jsonb_array_element(value, st.task_index)
FROM jsonb_each(dep_out.deps_output)
WHERE (SELECT COUNT(*) FROM jsonb_each(dep_out.deps_output)) = 1
LIMIT 1)

Spotted by Diamond

Fix in Graphite


Is this helpful? React 👍 or 👎 to let us know.

-- Extract the element at task_index from the run's input array.
-- Note: If run input is not an array, this will return NULL
-- and the flow will fail (validated in start_flow).
jsonb_array_element(r.input, st.task_index)
Copy link
Contributor

Choose a reason for hiding this comment

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

Array bounds vulnerability - jsonb_array_element(r.input, st.task_index) will return NULL if task_index is out of bounds, but this NULL is passed directly as task input without validation. If there's a race condition or bug in task creation that results in task_index >= array_length, tasks will receive NULL input and likely fail at runtime. Add bounds checking or handle NULL case explicitly.

Suggested change
jsonb_array_element(r.input, st.task_index)
CASE
WHEN jsonb_array_length(r.input) > st.task_index THEN jsonb_array_element(r.input, st.task_index)
ELSE jsonb_build_object('error', 'Task index out of bounds')
END

Spotted by Diamond

Fix in Graphite


Is this helpful? React 👍 or 👎 to let us know.

…handling migration

- Updated start_tasks function to build step input conditionally based on step type
- Implemented logic for root and dependent map steps to extract array elements
- Added a new migration script to handle array elements in start_tasks
- Included comprehensive tests for dependent map element extraction, large array processing,
mixed JSON types, and nested arrays
- Improved handling of array-based tasks and input construction for various step configurations
@jumski jumski force-pushed the 09-16-handle-arrays-in-start-tasks branch from 99d14b5 to e87df3c Compare October 6, 2025 15:25
@jumski jumski force-pushed the 09-16-make-initial-tasks-nullable branch from 2adddf3 to 4665802 Compare October 6, 2025 15:25
@github-actions
Copy link
Contributor

github-actions bot commented Oct 6, 2025

🔍 Preview Deployment: Website

Deployment successful!

🔗 Preview URL: https://pr-216.pgflow.pages.dev

📝 Details:

  • Branch: 09-16-handle-arrays-in-start-tasks
  • Commit: 2ee6c15e2700a08b299552a1f44944b53cfbbbb7
  • View Logs

_Last updated: _

@github-actions
Copy link
Contributor

github-actions bot commented Oct 6, 2025

🔍 Preview Deployment: Playground

Deployment successful!

🔗 Preview URL: https://pr-216--pgflow-demo.netlify.app

📝 Details:

  • Branch: 09-16-handle-arrays-in-start-tasks
  • Commit: 2ee6c15e2700a08b299552a1f44944b53cfbbbb7
  • View Logs

_Last updated: _

@graphite-app
Copy link
Contributor

graphite-app bot commented Oct 7, 2025

Merge activity

  • Oct 7, 8:28 AM UTC: jumski added this pull request to the Graphite merge queue.
  • Oct 7, 8:29 AM UTC: CI is running for this pull request on a draft pull request (#232) due to your merge queue CI optimization settings.
  • Oct 7, 8:29 AM UTC: Merged by the Graphite merge queue via draft PR: #232.

graphite-app bot pushed a commit that referenced this pull request Oct 7, 2025
…handling migration (#216)

# Enhanced Map Step Input Processing

- Updated start_tasks function to build step input conditionally based on step type
- Implemented logic for root and dependent map steps to extract array elements
- Added a new migration script to handle array elements in start_tasks
- Included comprehensive tests for dependent map element extraction, large array processing, mixed JSON types, and nested arrays
- Improved handling of array-based tasks and input construction for various step configurations
@graphite-app graphite-app bot closed this Oct 7, 2025
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