Skip to content

refactor(dedup): added batchrewrite helper to remove duplications#223

Merged
SantiagoDePolonia merged 2 commits intomainfrom
refactor/create-a-batchrewrite-module-to-dedup
Apr 11, 2026
Merged

refactor(dedup): added batchrewrite helper to remove duplications#223
SantiagoDePolonia merged 2 commits intomainfrom
refactor/create-a-batchrewrite-module-to-dedup

Conversation

@SantiagoDePolonia
Copy link
Copy Markdown
Contributor

@SantiagoDePolonia SantiagoDePolonia commented Apr 11, 2026

Summary by CodeRabbit

  • Refactor
    • Consolidated batch request rewrite and cleanup helpers into a shared internal module to centralize behavior and reduce duplication.
  • Tests
    • Added unit tests covering batch-rewrite helpers and improved concurrency safety in an existing test stub.
  • Chores / CI
    • Updated test targets and CI to run race-enabled unit tests and added dashboard JS tests.
  • Documentation
    • Updated development testing docs and cleaned ADR formatting.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 11, 2026

📝 Walkthrough

Walkthrough

Consolidates batch-rewrite bookkeeping, file cleanup, and endpoint-hint merging into a new internal/batchrewrite package and updates multiple providers, server components, tests, and CI/dev tooling to use the shared helpers. No exported API signatures were changed.

Changes

Cohort / File(s) Summary
Batch Rewrite Module
internal/batchrewrite/helpers.go, internal/batchrewrite/helpers_test.go
Adds new package with FileDeleter/FileRouter types and helpers: RecordPreparation, RecordResult, CleanupFile*, CleanupSupersededFile*, ShouldCleanupSupersededFile, and MergeEndpointHints. Includes tests for metadata recording, cleanup behavior, supersession logic, and map-merge semantics.
Provider Delegation
internal/aliases/provider.go, internal/guardrails/provider.go
Replaces local batch-prep bookkeeping, file cleanup, and hint-merge helpers with calls into internal/batchrewrite (e.g., RecordPreparation, CleanupFileFromRouter, CleanupSupersededFileFromRouter, MergeEndpointHints). Removes local helper implementations and unused imports.
Server Components Refactor
internal/server/batch_request_preparer.go, internal/server/native_batch_service.go, internal/server/native_batch_support.go
Removes local cleanup/merge helpers and direct DeleteFile sites; uses batchrewrite.RecordResult, batchrewrite.CleanupFile, and batchrewrite.MergeEndpointHints for recording, cleanup, and hint merging. Adjusts call sites to pass router/deleter when needed.
Command Tests Concurrency Fix
cmd/gomodel/main_test.go
Makes the test stub thread-safe by adding a sync.Mutex and accessor methods; updates tests to use accessors and safely inspect captured shutdown context.
CI & Local Hooks
.github/workflows/test.yml, .pre-commit-config.yaml, Makefile, DEVELOPMENT.md
CI: runs make test-race for unit tests and adds test-dashboard job; build depends on dashboard tests. Pre-commit: replaces staged-go test hook with local go-unit-tests calling make test-race, adds dashboard-js-tests. Makefile: adds test-race, test-dashboard, updates test/test-all. DEVELOPMENT.md: documents new targets.
Docs/Formatting
docs/adr/0006-semantic-response-cache.md
Whitespace/formatting cleanup only (no semantic change).

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested labels

release:internal

Poem

🐰 A rabbit nibbles at scattered code with glee,
Hops files together—now tidy as can be.
One cozy package holds hints and cleanup too,
No more duplicates—the meadow's fresh and new.
Cheers for small hops that make the code feel light!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 38.10% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main change: extracting duplicated batch rewriting logic into a new batchrewrite helper module to remove code duplication across multiple files.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/create-a-batchrewrite-module-to-dedup

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors native batch request rewrite handling by consolidating repeated logic (rewrite metadata recording, endpoint-hint merging, and temporary rewritten input file cleanup) into a shared internal/batchrewrite helper package.

Changes:

  • Introduced internal/batchrewrite helpers for recording batch rewrite metadata, cleaning up rewritten input files, and merging endpoint hints.
  • Updated native batch server flow and provider decorators to use the shared helpers instead of local duplicated implementations.
  • Added unit tests covering the new helper behaviors.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.

Show a summary per file
File Description
internal/server/native_batch_support.go Uses shared cleanup helper for rewritten batch input file deletion and removes local hint-merge helper.
internal/server/native_batch_service.go Uses shared helpers to record rewrite results and merge endpoint hints before persisting batches.
internal/server/batch_request_preparer.go Replaces local cleanup + hint merge logic with shared helper calls during preparer chaining.
internal/guardrails/provider.go Replaces duplicated rewrite-recording, cleanup, and hint-merging helpers with shared batchrewrite utilities.
internal/aliases/provider.go Replaces duplicated rewrite-recording, cleanup, and hint-merging helpers with shared batchrewrite utilities.
internal/batchrewrite/helpers.go New shared helper implementations for rewrite metadata recording, cleanup, and hint merging.
internal/batchrewrite/helpers_test.go New tests validating the helper functions’ behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In @.pre-commit-config.yaml:
- Around line 23-28: The pre-commit hook with id "go-unit-tests" currently runs
"make test-race", which invokes the Go race detector and slows commits; update
the hook to run "make test" instead (change the entry value from "make
test-race" to "make test" for the go-unit-tests hook) so pre-commit uses the
faster test target while keeping "make test-race" reserved for CI or explicit
use.

In `@DEVELOPMENT.md`:
- Around line 25-29: DEVELOPMENT.md is missing documentation for the Makefile
targets test-integration and test-contract; update the test target list (the
same section that currently lists make test, make test-race, make
test-dashboard, make test-e2e, make test-all) to include brief entries for make
test-integration and make test-contract, describing what each runs (integration
tests and contract tests respectively) and any special flags or prerequisites
(e.g., tags, environment variables, or services required) so readers can run
them consistently.

In `@docs/adr/0006-semantic-response-cache.md`:
- Line 118: Replace the weak phrase "very large" in the sentence "Pinecone
metadata size caps can block caching very large JSON bodies — mitigated by clear
errors / operational choice of backend" with stronger wording such as "oversized
JSON bodies" or "large JSON payloads" so the ADR reads e.g. "Pinecone metadata
size caps can block caching oversized JSON bodies — mitigated by clear errors /
operational choice of backend"; update that exact sentence in
docs/adr/0006-semantic-response-cache.md.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 575fbbe6-50e9-4f9c-bf6b-66a34bec4dd4

📥 Commits

Reviewing files that changed from the base of the PR and between 22f8365 and f62d362.

📒 Files selected for processing (6)
  • .github/workflows/test.yml
  • .pre-commit-config.yaml
  • DEVELOPMENT.md
  • Makefile
  • cmd/gomodel/main_test.go
  • docs/adr/0006-semantic-response-cache.md

Comment thread .pre-commit-config.yaml
Comment on lines +23 to +28
- id: go-unit-tests
name: make test-race
entry: make test-race
language: system
pass_filenames: false
files: '^((cmd|config|internal)/.*\.go|go\.(mod|sum)|Makefile|\.github/workflows/test\.yml)$'
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick | 🔵 Trivial

Consider using make test instead of make test-race for pre-commit.

Running the race detector on every commit can significantly slow down the development workflow. The race detector adds substantial overhead (typically 2-10x slower execution). Consider:

  • Using make test for pre-commit (fast feedback)
  • Reserving make test-race for CI where thoroughness is prioritized over speed

If the race detector is intentionally required at commit time, this is fine as-is.

♻️ Suggested change for faster pre-commit
       - id: go-unit-tests
-        name: make test-race
-        entry: make test-race
+        name: make test
+        entry: make test
         language: system
         pass_filenames: false
         files: '^((cmd|config|internal)/.*\.go|go\.(mod|sum)|Makefile|\.github/workflows/test\.yml)$'
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- id: go-unit-tests
name: make test-race
entry: make test-race
language: system
pass_filenames: false
files: '^((cmd|config|internal)/.*\.go|go\.(mod|sum)|Makefile|\.github/workflows/test\.yml)$'
- id: go-unit-tests
name: make test
entry: make test
language: system
pass_filenames: false
files: '^((cmd|config|internal)/.*\.go|go\.(mod|sum)|Makefile|\.github/workflows/test\.yml)$'
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.pre-commit-config.yaml around lines 23 - 28, The pre-commit hook with id
"go-unit-tests" currently runs "make test-race", which invokes the Go race
detector and slows commits; update the hook to run "make test" instead (change
the entry value from "make test-race" to "make test" for the go-unit-tests hook)
so pre-commit uses the faster test target while keeping "make test-race"
reserved for CI or explicit use.

Comment thread DEVELOPMENT.md
Comment on lines +25 to +29
make test # Go unit tests
make test-race # Go unit tests with race detection and coverage
make test-dashboard # Dashboard JavaScript unit tests
make test-e2e # End-to-end tests (requires -tags=e2e; uses in-process mock servers, no Docker)
make test-all # All tests
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick | 🔵 Trivial

Documentation is missing test-integration and test-contract targets.

The Makefile defines additional test targets that aren't documented here. Consider adding them for completeness:

📝 Suggested addition
 make test            # Go unit tests
 make test-race       # Go unit tests with race detection and coverage
 make test-dashboard  # Dashboard JavaScript unit tests
 make test-e2e        # End-to-end tests (requires -tags=e2e; uses in-process mock servers, no Docker)
+make test-integration # Integration tests (requires Docker; -tags=integration)
+make test-contract   # Contract replay tests (requires -tags=contract)
 make test-all        # All tests
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
make test # Go unit tests
make test-race # Go unit tests with race detection and coverage
make test-dashboard # Dashboard JavaScript unit tests
make test-e2e # End-to-end tests (requires -tags=e2e; uses in-process mock servers, no Docker)
make test-all # All tests
make test # Go unit tests
make test-race # Go unit tests with race detection and coverage
make test-dashboard # Dashboard JavaScript unit tests
make test-e2e # End-to-end tests (requires -tags=e2e; uses in-process mock servers, no Docker)
make test-integration # Integration tests (requires Docker; -tags=integration)
make test-contract # Contract replay tests (requires -tags=contract)
make test-all # All tests
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@DEVELOPMENT.md` around lines 25 - 29, DEVELOPMENT.md is missing documentation
for the Makefile targets test-integration and test-contract; update the test
target list (the same section that currently lists make test, make test-race,
make test-dashboard, make test-e2e, make test-all) to include brief entries for
make test-integration and make test-contract, describing what each runs
(integration tests and contract tests respectively) and any special flags or
prerequisites (e.g., tags, environment variables, or services required) so
readers can run them consistently.

- ~50–100 ms added latency on semantic miss (acceptable vs LLM latency)
- Requires a provider with a working OpenAI-compatible embeddings endpoint and credentials
- Semantic layer **requires external vector infrastructure** (no embedded sqlite-vec path)
- Pinecone metadata size caps can block caching very large JSON bodies — mitigated by clear errors / operational choice of backend
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick | 🔵 Trivial

Prefer stronger wording over “very large.”

Line 118 can be tightened to avoid weak intensifiers (e.g., “oversized JSON bodies” or “large JSON payloads”).

🧰 Tools
🪛 LanguageTool

[style] ~118-~118: As an alternative to the over-used intensifier ‘very’, consider replacing this phrase.
Context: ...ne metadata size caps can block caching very large JSON bodies — mitigated by clear errors...

(EN_WEAK_ADJECTIVE)

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@docs/adr/0006-semantic-response-cache.md` at line 118, Replace the weak
phrase "very large" in the sentence "Pinecone metadata size caps can block
caching very large JSON bodies — mitigated by clear errors / operational choice
of backend" with stronger wording such as "oversized JSON bodies" or "large JSON
payloads" so the ADR reads e.g. "Pinecone metadata size caps can block caching
oversized JSON bodies — mitigated by clear errors / operational choice of
backend"; update that exact sentence in
docs/adr/0006-semantic-response-cache.md.

@SantiagoDePolonia SantiagoDePolonia merged commit b335560 into main Apr 11, 2026
17 checks passed
@SantiagoDePolonia SantiagoDePolonia deleted the refactor/create-a-batchrewrite-module-to-dedup branch April 25, 2026 11:57
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.

2 participants