You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
CompileToolResponseFilter and CompileToolResponseFilterWithVars in internal/middleware/jqschema.go share ~20 lines of near-identical cache-check / parse / compile / cache-store logic. Any future change to this pipeline (error messages, metrics, cache invalidation) must be applied twice.
Cache key type: string vs toolResponseFilterVarsCacheKey
Compile opts: secureCompileOpts... vs compileOptsWithVariables(varNames)...
Log messages append , vars=%v in the WithVars variant
Impact Analysis
Maintainability: Any change to the cache-check/parse/compile/store pattern (e.g., adding telemetry, changing error messages, switching from sync.Map) must be applied to both functions identically
Bug Risk: Low at present, but a future inconsistent edit (e.g., adding cache eviction in only one function) could introduce subtle behavioral differences
Code Bloat: ~20 lines of structural duplication in a 861-line file
Refactoring Recommendations
Option 1 (Preferred): Extract a private generic helper
Extract a private compileFilterInternal[K comparable] function that accepts a pre-computed cache key, the raw filter string, and the compiler options. Both public functions become thin wrappers:
Summary
CompileToolResponseFilterandCompileToolResponseFilterWithVarsininternal/middleware/jqschema.goshare ~20 lines of near-identical cache-check / parse / compile / cache-store logic. Any future change to this pipeline (error messages, metrics, cache invalidation) must be applied twice.Part of duplicate code analysis: #8551
Duplication Details
Pattern: Repeated cache-check / parse / compile / store pipeline
internal/middleware/jqschema.golines 255–283 (CompileToolResponseFilter)internal/middleware/jqschema.golines 298–330 (CompileToolResponseFilterWithVars)Duplicated structural skeleton (annotated):
Differences (only 3):
stringvstoolResponseFilterVarsCacheKeysecureCompileOpts...vscompileOptsWithVariables(varNames)..., vars=%vin the WithVars variantImpact Analysis
sync.Map) must be applied to both functions identicallyRefactoring Recommendations
Option 1 (Preferred): Extract a private generic helper
Extract a private
compileFilterInternal[K comparable]function that accepts a pre-computed cache key, the raw filter string, and the compiler options. Both public functions become thin wrappers:Option 2: Accept duplication with cross-reference comments
Add a comment to each function noting the structural duplication and pointing to the other function. Lower effort but leaves the duplication in place.
Implementation Checklist
make agent-finishedto verify build, lint, and tests passParent Issue
See parent analysis report: #8551
Related to #8551
Warning
Firewall blocked 1 domain
The following domain was blocked by the firewall during workflow execution:
awmgmcpgSee Network Configuration for more information.