Skip to content

fix(transform): ignore context cancellation in object_jq#315

Open
vincent067 wants to merge 1 commit into
brexhq:mainfrom
vincent067:fix-object-jq-context-cancel
Open

fix(transform): ignore context cancellation in object_jq#315
vincent067 wants to merge 1 commit into
brexhq:mainfrom
vincent067:fix-object-jq-context-cancel

Conversation

@vincent067
Copy link
Copy Markdown

Hi team! 👋

First off, thank you for building Substation — it's been a joy to work with.

This PR fixes #305. When object_jq runs after an aggregate transform (like sub.tf.aggregate.to.array) in the CLI, the reader's context can be cancelled before jq finishes evaluating the batch. That produces the cryptic context canceled error reported by @raphael-ru.

The fix is simple: pass context.WithoutCancel(ctx) to RunWithContext, which aligns with the pattern already used in the Send transforms (as @jshlbrd noted in the issue).

I haven't added a new unit test here because the existing transform/object_jq_test.go already exercises the transform, and the bug only manifests when the upstream context is cancelled — which is tricky to reproduce in a table-driven unit test without pulling in the full pipeline. I'm happy to add an integration-style test if you'd prefer!

Let me know what you think. 😊

When object_jq runs after aggregate transforms in the CLI, the
reader context may be cancelled before jq evaluation finishes.
Use context.WithoutCancel to let the transform complete, matching
the pattern already used in Send transforms.

Fixes brexhq#305
@vincent067 vincent067 requested a review from a team as a code owner April 11, 2026 18:21
@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented Apr 11, 2026

Greptile Summary

Fixes #305 — a bug where object_jq transforms fail with a context canceled error when running after aggregate transforms (like aggregate.to.array) in the CLI. The root cause is that the reader's context is cancelled after it finishes reading input, but before jq finishes evaluating the batch.

The fix applies context.WithoutCancel(ctx) to the RunWithContext call, which is an established pattern already used in Send transforms, enrich transforms, and internal utilities throughout the codebase (~20+ locations).

  • Single-line change in transform/object_jq.go at line 82
  • No new tests added; the bug is a pipeline-level race condition difficult to reproduce in unit tests
  • The context.WithoutCancel derived context still carries parent values (e.g., tracing) but won't be cancelled when the parent context is cancelled

Confidence Score: 4/5

This PR is safe to merge — it's a minimal, well-understood one-line fix that follows an established codebase pattern.

Score of 4 reflects a small, focused change that correctly applies a well-established pattern (context.WithoutCancel) already used in 20+ places across the codebase. The fix addresses a real bug (#305) with a clear root cause. One minor consideration: WithoutCancel means a pathological jq filter (e.g., infinite loop) could not be cancelled via context, but this is a pre-existing concern unrelated to this PR and consistent with how the rest of the codebase operates.

No files require special attention.

Important Files Changed

Filename Overview
transform/object_jq.go One-line fix wrapping ctx with context.WithoutCancel() before passing to gojq.RunWithContext, preventing premature cancellation when upstream reader finishes. Follows the same pattern used in 20+ other locations across the codebase.

Reviews (1): Last reviewed commit: "fix(transform): ignore context cancellat..." | Re-trigger Greptile

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.

Cannot run sub.tf.object.jq after sub.transform.aggregate.to.array

1 participant