Skip to content

fix: skip CountWorkflow in batch operations when --yes is set#1012

Merged
chaptersix merged 5 commits into
temporalio:mainfrom
bitalizer:skip-count-on-yes
May 31, 2026
Merged

fix: skip CountWorkflow in batch operations when --yes is set#1012
chaptersix merged 5 commits into
temporalio:mainfrom
bitalizer:skip-count-on-yes

Conversation

@bitalizer

@bitalizer bitalizer commented Apr 29, 2026

Copy link
Copy Markdown
Contributor

Closes #838.

Implements the design @cretz proposed in the issue thread: when --yes bypasses the confirmation prompt, skip the CountWorkflowExecutions request entirely.

What was changed

When --yes skips the count, the prompt text changes from Start batch against approximately N workflow(s)? y/N to Start batch against workflows matching query "<query>"? y/N, so the output (which promptYes still prints in the auto-confirm path) stays informative.

The non---yes interactive flow is untouched: it still counts, still prompts, still prints the same approximately N workflow(s) message.

Why

workflowExecOrBatch (terminate / signal / cancel) and the reset command both unconditionally call CountWorkflowExecutions before starting a batch. The result is only used to fill in the approximately N workflow(s) confirmation. When --yes is set, the prompt is skipped — but the count call still runs, and on clusters where the visibility API is timing out it fails the entire batch start. The original report is from a Postgres-backed cluster where the batch query itself works but the count times out; users can't start batch jobs they otherwise have permission to run.

How was this tested

Added TestWorkflow_Terminate_BatchWorkflow_SkipsCountWhenYes that:

  1. Installs a unary gRPC interceptor that counts CountWorkflowExecutionsRequest and StartBatchOperationRequest calls.
  2. Starts one workflow, then runs workflow terminate --query ... --yes.
  3. Asserts: 0 CountWorkflow calls, 1 StartBatchOperation call, prompt text contains matching query and not approximately.

The interceptor pattern matches the existing testTerminateBatchWorkflow helper.

Ran the new test plus a sample of the existing batch tests locally; they pass. (TestWorkflow_Terminate_BatchWorkflowSuccess flakes locally on the unrelated Completed assertion both with and without my changes — pre-existing timing issue, not caused by this PR.)

The visibility CountWorkflowExecutions request was issued unconditionally
before every batch terminate / signal / cancel / reset. The count is only
used to populate the "Start batch against approximately N workflow(s)?"
confirmation prompt. When --yes bypasses the prompt entirely, the count
result is never read.

In clusters whose visibility API is overloaded (e.g. Postgres-backed
clusters with many workflows), this CountWorkflow call can time out and
prevent batch jobs from being started at all, even though the batch
operation itself uses the same query and would succeed. Skipping the
count when --yes is set lets these batch jobs proceed unconditionally.

Both batch entry points are updated:
- commands.workflow.go (terminate / signal / cancel)
- commands.workflow_reset.go (reset)

When the count is skipped, the prompt text shown by --yes changes from
"Start batch against approximately N workflow(s)? y/N" to
"Start batch against workflows matching query "<query>"? y/N" so the
output remains informative.

Adds TestWorkflow_Terminate_BatchWorkflow_SkipsCountWhenYes which uses
a gRPC unary interceptor to assert that
CountWorkflowExecutionsRequest is *not* sent when --yes is passed,
while StartBatchOperationRequest still is. The existing without-yes
tests are unaffected.

Closes temporalio#838
@bitalizer bitalizer requested a review from a team as a code owner April 29, 2026 08:32
@CLAassistant

CLAassistant commented Apr 29, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@chaptersix

chaptersix commented May 21, 2026

Copy link
Copy Markdown
Contributor

Overall: LGTM
Minor: prompt wording

The --yes path prints Start batch against workflows matching query "..."? y/N — but since promptYes is called with s.Yes=true, the user never sees this interactively. It appears in stdout as an auto-confirmed message, so the ? y/N suffix looks a bit odd in that context. Pre-existing issue, but worth noting.

Test

The test is thorough — interceptor pattern, gRPC call counting, Eventually for visibility lag. One nit: the drain at the end waits for run.Get to return a non-nil error after termination. That's correct, but it would be clearer to assert the error is specifically a termination error rather than just "not nil".

Missing coverage for workflow_reset.go

The test only covers workflow terminate. The reset path has the identical change but no corresponding test. Worth adding or at least noting.

Remove gRPC interceptor from terminate test -- asserting on prompt text
is sufficient to verify the count is skipped. Add reset batch test for
the same --yes skip-count behavior. Assert terminated error specifically
in drain check.
TestWorkflow_Delete_BatchWorkflowSuccess uses -y, which now skips the
count call. Update assertion from "approximately 2 workflow(s)" to
"matching query" to match the new prompt text.
@chaptersix chaptersix merged commit 7e5ba38 into temporalio:main May 31, 2026
10 checks passed
@bitalizer bitalizer deleted the skip-count-on-yes branch June 1, 2026 21:01
chaptersix added a commit that referenced this pull request Jul 6, 2026
…#1104)

## Summary

Backports server-independent changes from `main` into `release/1.8.x`.
Every commit here was verified to build and pass codegen against the
release line's current dependency pins (`server v1.31.0`, `sdk v1.41.1`,
`api v1.62.8`) — nothing pulls in the newer server/SDK/API that landed
on `main` via #1017.

Scope agreed as: bug fixes + CLI changes + CI/tooling. Dependency bumps
(#1040, #1052, #1063) and server-version-dependent features are
intentionally excluded.

## Included (22 commits, cherry-picked with `-x`)

**CLI / bug fixes**
- #1006 Fix help with value flags (addresses #1003 — `--help` with value
flags like `--address 123` surfaced `pflag: help requested` as an error)
- #1012 skip CountWorkflow in batch operations when `--yes` is set
- #1016 Sort output of listing search attributes
- #1029 Workflow delete now prompts for confirmation
- #1033 Add persistence info to start-dev banner
- #1047 Add `temporal schedule list-matching-times` command
- #1056 Fix task-queue config set help: use real fairness weight flag
names
- #1059 Prefix dev server cluster ID with `dev-server-`
- #1089 fix: tls is not added for profiles without tls
- #1099 Clarify activity pause timeout behavior
- #941 auto-generate deprecation warnings from YAML config

**Tests**
- #1005 Fix flakey test by disabling EC2 metadata lookup
- #1020 Remove `time.Sleep()` in commands.taskqueue_test.go

**CI / tooling**
- #1015 pin alpine docker image to 3.23.4
- #1024 remediate missing-dependency-cooldown
- #1034 Bump actions/upload-artifact from 4 to 7
- #1044 improve dependabot config
- #1045 add PR template
- #1054 pin and bump GitHub Actions to latest versions
- #1057 use allow instead of ignore for dependency-type in dependabot
config
- #1080 Bump the github-actions group with 2 updates

## Excluded (rely on the new server/SDK version)
#1017 (server bump v1.31.0 -> v1.32.0-157.0), #1046, #1087, #1001,
#1091, #1084

## Verification
- `go build ./...` passes
- all test packages compile
- `make gen` reports no codegen drift
- server/sdk/api pins unchanged from `release/1.8.x`



## CI endpoint fix (added)
Also backports the API-key CI test endpoint change from #1087
(`us-east-1` -> `ca-central-1`) as a standalone CI-only commit. This
resolves the `Request unauthorized` failure in the "Test cloud API key"
steps on `release/1.8.x`. The rest of #1087 (Nexus Operation command
code) is excluded as it depends on the new server version.

---------

Signed-off-by: dependabot[bot] <support@github.com>
Signed-off-by: Sai Asish Y <say.apm35@gmail.com>
Co-authored-by: Kevin Woo <3469532+kevinawoo@users.noreply.github.com>
Co-authored-by: Rodrigo Zhou <rodrigo.zhou@temporal.io>
Co-authored-by: Stephan Behnke <stephanos@users.noreply.github.com>
Co-authored-by: Jiechen Zhong <jiechen.zhong@temporal.io>
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-authored-by: Kent Gruber <kent.gruber@temporal.io>
Co-authored-by: picatz <14850816+picatz@users.noreply.github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: John Votta <jpvotta@gmail.com>
Co-authored-by: Nasit  Sarwar Sony <nasitsony96@gmail.com>
Co-authored-by: hussam-salah <156124396+hussam-salah@users.noreply.github.com>
Co-authored-by: Sai Asish Y <say.apm35@gmail.com>
Co-authored-by: Bitalizer <23104115+bitalizer@users.noreply.github.com>
Co-authored-by: Sean Kane <spkane31@gmail.com>
Co-authored-by: Jessica Laughlin <JLDLaughlin@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.

[Bug] Unable to start a batch job if counting the workflows times out

3 participants