Skip to content

test(claude): add compatibility sentinels and centralize builtin fallback handling#2491

Merged
luispater merged 2 commits intorouter-for-me:devfrom
mpfo0106:feature/claude-code-safe-alignment-sentinels
Apr 6, 2026
Merged

test(claude): add compatibility sentinels and centralize builtin fallback handling#2491
luispater merged 2 commits intorouter-for-me:devfrom
mpfo0106:feature/claude-code-safe-alignment-sentinels

Conversation

@mpfo0106
Copy link
Copy Markdown
Contributor

@mpfo0106 mpfo0106 commented Apr 2, 2026

Summary

  • add Claude Code-informed compatibility sentinel tests for representative SDK/control shapes
  • extract Claude builtin tool fallback names into a small internal helper used by applyClaudeToolPrefix
  • preserve the current fallback behavior while making builtin-prefix handling easier to extend and review
  • add focused executor regression tests for fallback-seeded builtins across tool_choice, tool_use, tool_reference, and nested tool_result paths

Motivation

This is a safe first step toward keeping CLIProxyAPI grounded against the now-public Claude Code source without introducing broader runtime risk.

The scope is intentionally narrow:

  • keep current default behavior intact for existing users
  • improve coverage around builtin tool prefixing edge cases, especially history-only builtin references
  • add lightweight source-informed sentinel coverage for a few Claude Code message/control shapes so future drift is easier to notice

This is compatibility scaffolding, not a broader Claude Code control-plane/session alignment change.

Why this is low-risk

  • the runtime change is intentionally small and confined to Claude builtin prefix handling
  • the previous hardcoded builtin fallback is still preserved; it is now centralized rather than replaced by a broader new runtime contract
  • the new helper is augmentative, not replacement-only: typed builtins still extend the set found in the current request body
  • no stable public route behavior is intentionally changed beyond the narrow builtin-prefix safety fix
  • the patch is covered by focused regression tests and a full go test ./... pass

Why this is useful now that Claude Code source is public

  • the public source gives a concrete reference for a few SDK/control concepts that were previously inferred indirectly
  • this patch captures a small subset of those concepts as compatibility sentinels, so future drift is easier to notice during maintenance
  • it also makes builtin handling easier to reason about and extend without broadening the runtime surface area in the same PR
  • in other words, this change improves maintainability and observability first, while deliberately avoiding a larger control-plane/session redesign

Notes

  • the builtin fallback remains small and authoritative in this slice: web_search, code_execution, text_editor, computer
  • this PR should be read as a safe compatibility hardening patch, not as full Claude Code alignment
  • larger follow-up work (if needed) should happen separately for runtime/session/control-plane behavior

Tests

  • go test ./test/...
  • go test ./sdk/translator/...
  • go test ./internal/runtime/executor -run 'Claude|Builtin|Tool'
  • go test ./...

This change stops short of broader Claude Code runtime alignment and instead
hardens two safe edges: builtin tool prefix handling and source-informed
sentinel coverage for future drift checks.

Constraint: Must preserve existing default behavior for current users
Rejected: Implement control-plane/session alignment now | too much runtime risk for a first slice
Confidence: high
Scope-risk: narrow
Reversibility: clean
Directive: Treat the new fixtures as compatibility sentinels, not a full Claude Code schema contract
Tested: go test ./test/...; go test ./sdk/translator/...; go test ./internal/runtime/executor -run 'Claude|Builtin|Tool'; go test ./...
Not-tested: End-to-end Claude Code direct-connect/session runtime behavior
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a centralized registry for Claude's built-in tools and adds compatibility tests for Claude 'sentinel' message shapes. The tool prefixing logic in claude_executor.go has been refactored to use a dynamic registry seeded with default tools and augmented by the request body. Additionally, new test fixtures and shape validation tests were added for various Claude-specific message types, including tool progress, session state changes, and tool use summaries. I have no feedback to provide.

@luispater
Copy link
Copy Markdown
Collaborator

Hi @mpfo0106 — could you please move the following files into internal/runtime/executor/helps/ (the helps package) to keep helper utilities centralized?

  • internal/runtime/executor/claude_builtin_tools.gointernal/runtime/executor/helps/claude_builtin_tools.go
  • internal/runtime/executor/claude_builtin_tools_test.gointernal/runtime/executor/helps/claude_builtin_tools_test.go

git mv is preferred to preserve history.

Thanks!

Copy link
Copy Markdown
Collaborator

@luispater luispater left a comment

Choose a reason for hiding this comment

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

Please move the following helper files into internal/runtime/executor/helps/ (the helps package) so helper utilities stay centralized:

  • internal/runtime/executor/claude_builtin_tools.gointernal/runtime/executor/helps/claude_builtin_tools.go
  • internal/runtime/executor/claude_builtin_tools_test.gointernal/runtime/executor/helps/claude_builtin_tools_test.go

git mv is preferred to preserve history.

The review asked for the builtin tool registry helper to live with the rest
of executor support utilities. This moves the registry code into the helps
package, exports the minimal surface executor needs, and keeps behavior tests
with the executor while leaving registry-focused checks with the helper.

Constraint: Requested layout keeps executor helper utilities centralized under internal/runtime/executor/helps
Rejected: Keep the files in executor and reply with rationale | conflicts with requested package organization
Confidence: high
Scope-risk: narrow
Reversibility: clean
Directive: Keep executor behavior tests near applyClaudeToolPrefix and keep pure registry tests in helps
Tested: go test ./internal/runtime/executor/helps ./internal/runtime/executor -run 'Claude|Builtin|Tool'; go test ./test/...; go test ./...
Not-tested: End-to-end Claude Code direct-connect/session runtime behavior
@mpfo0106 mpfo0106 requested a review from luispater April 2, 2026 15:15
Copy link
Copy Markdown
Collaborator

@luispater luispater left a comment

Choose a reason for hiding this comment

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

The requested layout change is complete: the Claude builtin helper now lives under internal/runtime/executor/helps/, and applyClaudeToolPrefix now uses the exported helper from that package.

I verified the updated executor/helper tests and the new Claude Code sentinel tests on the PR head, and they pass. No blocking issues remain.

This is an automated Codex review result and still requires manual verification by a human reviewer.

@luispater luispater added the codex label Apr 5, 2026
@luispater luispater changed the base branch from main to dev April 6, 2026 01:26
@luispater luispater merged commit c3f8dc3 into router-for-me:dev Apr 6, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants