Repository navigation
perf(workflows): reuse saved steps when writing dependencies - #581
Merged
artempartos merged 2 commits intoOct 28, 2026
Merged
Conversation
WorkflowStepSync#write_dependencies re-found every step with dependencies via Step.find, although write_steps had just saved those records. write_steps now returns key -> Step and the dependencies are updated on those records. Fixes Sentry PALAD-AI-RAILS-4C. Signed-off-by: aixle-developer-agent <[email protected]>
Hitin
marked this pull request as ready for review
October 27, 2026 07:19
* origin/develop: docs(workflows): describe workflows as sessions made of steps (AixleHQ#595) feat(workflows): open archived workflows read-only in the builder (AixleHQ#594) feat(task-comments): let authors delete their own recent comments (AixleHQ#593) feat(mcp): log the JSON-RPC method and tool name of each MCP call (AixleHQ#592) fix(board): show a run waiting for a session slot as Queued on its card (AixleHQ#591) feat(brand): use the new Aixle Flow lockup and route fonts through tokens (AixleHQ#590) feat(overview): show tokens used and session time instead of token cost (AixleHQ#589) fix(agents): pre-acknowledge Claude Code's cost-threshold notice (AixleHQ#587) test(playwright): QA helpers batch 2 (appRequest, readInertiaPage, shot, probeRoutes, signOut) (AixleHQ#586) test(playwright): plain-JS QA helpers for browser_run_code on staging (AixleHQ#584) feat(runners): add the runners table and the Runner model (AixleHQ#583) refactor(feature-flags): plain cached reads, no usage tooling (AixleHQ#579) # Conflicts: # CHANGELOG.md
Contributor
|
Finishing this in place before merge:
The code change and the test are unchanged. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
PUT …/workflows/:id/aggregate(AggregatesController#update→WorkflowAggregateSave#apply!→WorkflowStepSync#sync!) re-read every step with dependencies viaStep.find(id)inwrite_dependencies, even thoughwrite_stepshad just saved those records. That's the N+1 Sentry reported (SELECT "steps".* FROM "steps" WHERE "steps"."id" = $1 ORDER BY "steps"."position" ASC LIMIT $2).write_stepsnow returns key →Step.sync!buildskey_map(key → id) from it, so the return value ofsync!and therewrite_draft_references/retire_otherscontracts stay the same.write_dependenciescallsupdate!(depends_on_step_ids:)on the in-memory record. This drops theStep.findand also theworkflowlookup the validations made on a freshly found record: 2 fewer queries per step with dependencies.depends_on_step_idsis written there. The in-memoryinstructionscan still hold draft keys ({{step:new-1}}) thatrewrite_draft_referencesalready replaced viaupdate_all. A partialupdate!doesn't touch them, andinstruction_references_belong_to_projectonly runs when instructions change. The existing test "a reference to a step created in the same save…" covers this.Out of scope: the
pluckof sibling steps inStep#depends_on_step_ids_validstill runs once per step with dependencies. It's needed for the cycle and reference check, so changing it is a separate task.The same path is used by workflow version revert (
Versions::Snapshots::Workflow).Related issues
Sentry PALAD-AI-RAILS-4C. Board task #23.
Type of change
How was this tested?
New integration test in
test/integration/api/v1/projects/workflows/aggregates_test.rb: it saves a dependency chain (Build←new-1←Test) insideassert_no_queries_match(/FROM "steps" WHERE "steps"\."id" = .* LIMIT /)and checks the storeddepends_on_step_ids. The pattern requiresLIMIT, so it matchesStep.findand does not match theupdate_allsubquery or the validationpluck. On the old code it should fail on the twoStep.findcalls.Tests were not run locally (no Ruby in this environment). Verification is left to CI.
Checklist
git commit -s).organization has executed the Corporate CLA.
make check_allpasses locally (tests, rubocop, brakeman, eslint, typescript). CI only.[Unreleased]in CHANGELOG.md.