Skip to content

chore: housekeeping April 2026#134

Merged
thushan merged 12 commits into
mainfrom
chore/housekeeping-april-2026
Apr 17, 2026
Merged

chore: housekeeping April 2026#134
thushan merged 12 commits into
mainfrom
chore/housekeeping-april-2026

Conversation

@thushan
Copy link
Copy Markdown
Owner

@thushan thushan commented Apr 17, 2026

Various changes for dependabot and minor tweaks from internal review before next major release.

Summary by CodeRabbit

Release Notes

  • Chores

    • Updated Go toolchain to version 1.25.0
    • Updated core dependencies for improved stability
  • Bug Fixes

    • Fixed concurrency issues in health checking to prevent race conditions when stopping services
    • Improved cleanup operations to safely handle multiple shutdown requests
    • Enhanced connection error classification with better documentation
  • Tests

    • Added tests for concurrent operations to verify reliability

@thushan thushan self-assigned this Apr 17, 2026
@thushan thushan added the chore Chore tasks and cleanup label Apr 17, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 17, 2026

Walkthrough

The changes refactor context key handling across the proxy pipeline to use a typed constant (ContextModelKey) instead of string literals, enhance concurrency safety in health checking and service cleanup with atomic operations and sync.Once guards, remove legacy code and unused components, bump Go version and dependencies, and update related documentation.

Changes

Cohort / File(s) Summary
Concurrency Safety
internal/adapter/health/checker.go, internal/adapter/health/checker_test.go, internal/adapter/proxy/olla/service.go, internal/adapter/proxy/olla/service_leak_test.go
Introduced atomic CompareAndSwap guard in health checker's StopChecking and sync.Once guard in service Cleanup to ensure single-execution semantics. Added concurrent invocation tests to verify idempotency without panicking.
Context Key Refactoring
internal/core/constants/context.go, internal/adapter/proxy/olla/service.go, internal/adapter/proxy/sherpa/service_retry.go, internal/app/handlers/handler_translation.go, internal/adapter/proxy/proxy_headers_test.go, internal/app/handlers/handler_translation_alias_test.go
Introduced typed ContextModelKey constant and migrated all model context value lookups from string literal "model" to the new constant across proxy pipeline and handlers.
Dependency Updates
go.mod
Bumped Go toolchain to 1.25.0, promoted ttlcache/v3 to direct dependency, and updated golang.org/x/sync and golang.org/x/time versions.
Code Cleanup
internal/adapter/proxy/core/retry.go, internal/adapter/proxy/olla/service.go
Updated connection error classification documentation and removed legacy proxyToSingleEndpointLegacy function; removed unused responsePool from Service.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'chore: housekeeping April 2026' is vague and does not meaningfully convey the specific changes made, which include dependency updates, concurrency fixes, dead code removal, and context key refactoring. Consider a more descriptive title that captures the main changes, such as 'chore: update dependencies and add concurrency guards' or 'chore: refactor context keys and remove dead code'.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ 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 chore/housekeeping-april-2026

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

@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: 1

🧹 Nitpick comments (3)
internal/adapter/proxy/olla/service.go (1)

382-385: Minor: prefer constants.HeaderXModel over the literal "X-Model".

internal/adapter/proxy/sherpa/service_retry.go:90 uses proxyReq.Header.Set(constants.HeaderXModel, model) for the same purpose. The literal here is pre-existing, but while you're touching this block to switch to the typed context key, aligning the header constant too would remove the last string-literal in this path.

Proposed tweak
 	if model, ok := ctx.Value(constants.ContextModelKey).(string); ok && model != "" {
-		proxyReq.Header.Set("X-Model", model)
+		proxyReq.Header.Set(constants.HeaderXModel, model)
 		stats.Model = model
 	}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@internal/adapter/proxy/olla/service.go` around lines 382 - 385, Replace the
hard-coded header string in the block that reads from
ctx.Value(constants.ContextModelKey) and sets the header using
proxyReq.Header.Set("X-Model", model) with the shared constant by calling
proxyReq.Header.Set(constants.HeaderXModel, model); leave stats.Model = model
and the context lookup unchanged so behavior is identical but the header name is
centralized.
internal/core/constants/context.go (1)

14-28: Optional: ContextModelAliasMapKey still uses a plain string.

The rationale in the new comment (avoiding collisions with third-party middleware using a plain "model" key) applies equally to ContextModelAliasMapKey = "model_alias_map" on line 28, which remains an untyped string. Consider migrating it to contextKey("model_alias_map") in a follow-up for consistency with the rest of the sticky-session keys in this block.

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

In `@internal/core/constants/context.go` around lines 14 - 28,
ContextModelAliasMapKey is defined as a plain string ("model_alias_map") while
other context keys use the typed contextKey to avoid collisions; change
ContextModelAliasMapKey to use contextKey("model_alias_map") so it matches the
pattern used by ContextModelKey, ContextStickyKeyKey, etc.; update the
declaration of ContextModelAliasMapKey to call contextKey with the same
identifier and ensure any consumers that compare key types still use the typed
key symbol ContextModelAliasMapKey.
internal/adapter/proxy/olla/service_leak_test.go (1)

370-391: Covers the double-close regression; minor suggestion: assert goroutine exit.

The test validates that sync.Once prevents the second close(cleanupStop) from panicking. Since Cleanup() closes cleanupStop and stops the ticker, the background cleanupLoop goroutine returns — but the test exits before verifying it. A short sleep + goroutine count check (as in TestCleanupLoop_ExitsCleanly) would additionally guarantee the guard doesn't accidentally skip channel closure on the first call. Not blocking.

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

In `@internal/adapter/proxy/olla/service_leak_test.go` around lines 370 - 391,
TestCleanup_DoubleInvoke currently only calls s.Cleanup() twice; enhance it to
assert the background cleanupLoop goroutine actually exits after the first
Cleanup by waiting briefly and verifying goroutine exit (follow the pattern used
in TestCleanupLoop_ExitsCleanly): after starting cleanupLoop and calling
s.Cleanup(), sleep a short duration, then check that the goroutine count (or
other exit signal) has decreased/indicates the cleanupLoop returned before
calling s.Cleanup() the second time; reference symbols:
TestCleanup_DoubleInvoke, Service, cleanupLoop, Cleanup, cleanupStop,
cleanupTicker.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@go.mod`:
- Line 3: The go.mod Go version directive is 1.25.0 but CI uses GO_VERSION:
1.24.x, causing a mismatch; either update the CI workflow GO_VERSION entries (in
the CI and release workflows) to 1.25.x to match the go.mod directive, or change
the go.mod "go" directive back to 1.24 (e.g., go 1.24.0) so both targets align;
locate the go.mod "go" line and the CI workflow environment entries named
GO_VERSION and make them identical across the repo before merging.

---

Nitpick comments:
In `@internal/adapter/proxy/olla/service_leak_test.go`:
- Around line 370-391: TestCleanup_DoubleInvoke currently only calls s.Cleanup()
twice; enhance it to assert the background cleanupLoop goroutine actually exits
after the first Cleanup by waiting briefly and verifying goroutine exit (follow
the pattern used in TestCleanupLoop_ExitsCleanly): after starting cleanupLoop
and calling s.Cleanup(), sleep a short duration, then check that the goroutine
count (or other exit signal) has decreased/indicates the cleanupLoop returned
before calling s.Cleanup() the second time; reference symbols:
TestCleanup_DoubleInvoke, Service, cleanupLoop, Cleanup, cleanupStop,
cleanupTicker.

In `@internal/adapter/proxy/olla/service.go`:
- Around line 382-385: Replace the hard-coded header string in the block that
reads from ctx.Value(constants.ContextModelKey) and sets the header using
proxyReq.Header.Set("X-Model", model) with the shared constant by calling
proxyReq.Header.Set(constants.HeaderXModel, model); leave stats.Model = model
and the context lookup unchanged so behavior is identical but the header name is
centralized.

In `@internal/core/constants/context.go`:
- Around line 14-28: ContextModelAliasMapKey is defined as a plain string
("model_alias_map") while other context keys use the typed contextKey to avoid
collisions; change ContextModelAliasMapKey to use contextKey("model_alias_map")
so it matches the pattern used by ContextModelKey, ContextStickyKeyKey, etc.;
update the declaration of ContextModelAliasMapKey to call contextKey with the
same identifier and ensure any consumers that compare key types still use the
typed key symbol ContextModelAliasMapKey.
🪄 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: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 8d0f9115-475e-4ea7-8be3-8bc53a4f81bc

📥 Commits

Reviewing files that changed from the base of the PR and between 7d153be and 9c0debc.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (11)
  • go.mod
  • internal/adapter/health/checker.go
  • internal/adapter/health/checker_test.go
  • internal/adapter/proxy/core/retry.go
  • internal/adapter/proxy/olla/service.go
  • internal/adapter/proxy/olla/service_leak_test.go
  • internal/adapter/proxy/proxy_headers_test.go
  • internal/adapter/proxy/sherpa/service_retry.go
  • internal/app/handlers/handler_translation.go
  • internal/app/handlers/handler_translation_alias_test.go
  • internal/core/constants/context.go

Comment thread go.mod Outdated
@thushan thushan merged commit 0c4bfb4 into main Apr 17, 2026
6 checks passed
@thushan thushan deleted the chore/housekeeping-april-2026 branch April 17, 2026 02:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

chore Chore tasks and cleanup

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant