Refactor duplicated gojq execution path in jqschema middleware#5427
Merged
Refactor duplicated gojq execution path in jqschema middleware#5427
Conversation
7 tasks
Copilot
AI
changed the title
[WIP] Refactor duplicate jq filter execution logic in jqschema.go
Refactor duplicated gojq execution path in jqschema middleware
May 10, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
Refactors internal/middleware/jqschema.go to remove duplicated gojq execution/timeout/error-handling logic by introducing a shared helper, while preserving the distinct error-message prefixes and the tool-response filter’s single-result contract.
Changes:
- Added
runJqCode(...)+runJqCodeOptionsto centralize gojq execution, default-timeout application, andgojq.HaltError/context error handling. - Updated
applyJqSchemaandapplyToolResponseFilterto delegate torunJqCode, with schema-specific execution prefixing and tool-filter multi-result enforcement. - Added targeted tests covering “no results” and “multiple results” edge cases for tool-response filters.
Show a summary per file
| File | Description |
|---|---|
| internal/middleware/jqschema.go | Consolidates duplicated gojq execution logic into runJqCode while keeping caller-specific semantics (execution prefix + multi-result enforcement). |
| internal/middleware/jqschema_test.go | Adds tests for tool response filter edge contracts (empty output and multi-output). |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 2/2 changed files
- Comments generated: 0
This was referenced May 10, 2026
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.
✨ Enhancement
applyJqSchemaandapplyToolResponseFiltereach implemented nearly identical gojq execution/timeout/error-handling logic, creating a maintenance hotspot in one file. This change consolidates that shared path into a single helper while preserving behavior-specific differences (notably tool-filter multi-result enforcement).What does this improve?
gojq.HaltError+ context-cancellation handling in one place.jq query execution failedwording for schema path, multi-result rejection for tool response filters).Why is this valuable?
Implementation approach:
runJqCode(...)withrunJqCodeOptionsfor controlled per-caller behavior:applyJqSchemato delegate torunJqCodewith schema-specific execution prefix.applyToolResponseFilterto delegate withCheckMultipleResults: true.empty) returnstool response filter returned no results.[]) returnstool response filter returned multiple results...