Skip to content

test(workflows): stop counting schema lookups in the step-runs query test - #805

Merged
artempartos merged 1 commit into
developfrom
fix/workflow-service-query-count-flake
Nov 20, 2026
Merged

artempartos merged 1 commit into
developfrom
fix/workflow-service-query-count-flake

Conversation

@artempartos

Copy link
Copy Markdown
Contributor

Why

WorkflowServiceTest "a run's step runs are created pending, in step order, at a cost that does not grow with the steps" failed on the docs-only #803 (Expected: 4, Actual: 3, Rails shard 3/3) and passed on rerun.

The test counts queries matching /step_runs/ during a two-step start and again during a five-step start, then compares the two counts. The match also catches the two SCHEMA queries Active Record runs to load step_runs' columns (… WHERE a.attrelid = '"step_runs"'::regclass). Those run only on the first call in a process, so they land in the two-step count and never in the five-step one.

  • Run alone, the test always fails: Expected: 5, Actual: 3. Reproduced 3 of 3 on develop.
  • On CI it fails when random ordering puts it first in its worker, before any other test has touched StepRun.

The counted queries on a cold process, logged during the investigation:

Q[WorkflowRun Create]      INSERT INTO "workflow_runs" (… "step_runs_count" …)
Q[SCHEMA]                  SELECT a.attname …
Q[SCHEMA]                  SELECT a.attname, format_type(a.atttypid, a.atttypmod), …
Q[StepRun Bulk Insert]     INSERT INTO "step_runs" …
Q[WorkflowRun Update All]  UPDATE "workflow_runs" SET "step_runs_count" = …

What

The counter skips SCHEMA and cached queries, as the other query-counting tests already do (project_teams/picker_test.rb, internal_tools/session_tools_test.rb, personal_tools/list_sessions_test.rb). The assertion itself is unchanged: the five-step start must cost as many step_runs queries as the two-step one.

I checked the other tests that subscribe to sql.active_record. They either filter SCHEMA already or match a specific FROM "<table>"/UPDATE string that schema lookups do not contain, so this test is the only one with the problem.

Checks

All run in Docker against a private Postgres, with PARALLEL_WORKERS=1:

  • bin/rails test test/services/workflow_service_test.rb:48 alone: 3 of 3 pass. Before the fix, 3 of 3 failed.
  • The whole file twice in random order: 38 runs, 0 failures.
  • rubocop on the file: no offenses.

Test-only change, so no changelog entry.

🤖 Generated with Claude Code

…test

The test compares the step_runs queries of a two-step start with those of a
five-step one. Its /step_runs/ match also caught the two SCHEMA queries that
load the table's columns, which run only on the first call in a process. So
the test failed whenever it ran before anything else had touched StepRun:
always when run alone (5 vs 3), and on CI when the random order put it first
in its worker (4 vs 3, flow #803). It now skips SCHEMA queries, as the other
query-counting tests do.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Artem Petrov <[email protected]>
@artempartos
artempartos merged commit e801fb3 into develop Nov 20, 2026
17 checks passed
artempartos added a commit that referenced this pull request Nov 20, 2026
* origin/docs/session-restore-and-sharing-research:
  feat(sessions): suspend interactive sessions and restore them within 30 days
  docs(design): suspend and restore interactive sessions
  docs(research): restoring an ended session and sharing a live one
  test(workflows): stop counting schema lookups in the step-runs query test (#805)
  chore(agents): raise agent CLI pins for canary #675 (#804)
  docs(runners): tell manual machine owners to block the SCTP module (#803)
  fix(deps): weekly dependency batch — puma 8.1.2 advisories, stripe 21.1, Mantine 9.8.1, jsdom 31 (#799)
  docs(runners): record the second manual runner validation in row 14 (#797)
  docs(runners): tech design of the Go relay service for the interactive tunnel (#796)
  chore(runners): pin aixle-runner 0.4.1 as the recommended version (#795)

# Conflicts:
#	CHANGELOG.md
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