Skip to content

fix: treat model auto as runtime default - #181

Merged
pedronauck merged 1 commit into
mainfrom
codex/fix-cursor-model-auto
May 31, 2026
Merged

pedronauck merged 1 commit into
mainfrom
codex/fix-cursor-model-auto

Conversation

@pedronauck

@pedronauck pedronauck commented May 31, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Treat --model auto as the selected ACP runtime default before alias resolution and session model selection.
  • Prevent Cursor/non-bootstrap ACP runtimes from receiving literal SetSessionModel("auto") while preserving explicit model overrides such as composer-2.
  • Make scripts/link-skills.sh idempotent for stale or dangling skill symlinks, which was required for make verify to pass in an existing workspace.

Verification

  • rtk go test ./internal/core/agent
  • rtk bash scripts/link-skills.sh
  • rtk make verify
  • cy-impl-peer-review round 1: SHIP with 0 blockers

Fixes #177

Summary by CodeRabbit

  • Bug Fixes

    • Improved model selection to properly handle "AUTO" values as runtime defaults
    • Enhanced build process robustness for symlink cleanup
  • Tests

    • Added validation for session model selection behavior with explicit and automatic model assignment

@coderabbitai

coderabbitai Bot commented May 31, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

This PR implements handling of the "auto" model selector to resolve issue #177, where --model auto was failing. The core change normalizes "auto" (with whitespace and casing variations) to empty string, allowing fallback to runtime-specific defaults. Changes span model resolution logic, unit tests, ACP client integration tests, and a shell script symlink fix.

Changes

Model Auto-Normalization Feature

Layer / File(s) Summary
Model resolution normalization
internal/core/agent/registry_launch.go
resolveModel delegates to new normalizeRequestedModel helper that trims whitespace and maps case-insensitive "auto" to empty string; existing default fallback and alias resolution remain unchanged.
Model normalization unit tests
internal/core/agent/registry_test.go
TestResolveRuntimeModelTreatsAutoAsRuntimeDefault validates "auto" with whitespace and casing variations resolves to IDE-specific runtime defaults for Cursor and Codex; explicit trimmed model strings pass through as-is.
ACP client session model integration
internal/core/agent/client_test.go
Helper scenario extended with ExpectedSessionModelID and RejectSessionModel fields; helper agent gains state tracking (modelMu, modelSet) to validate SetSessionModel is called before Prompt; test client constructors refactored with newTestClientWithSpecConfig; two new tests verify "AUTO" does not trigger unexpected model setting and explicit models trigger session model setup before prompting.

Symlink Handling Fix

Layer / File(s) Summary
Dangling symlink cleanup
scripts/link-skills.sh
link_skill now matches both existing paths and unresolved symlinks at target location (-e ... || -L ...), ensuring stale symlinks are removed before relinking.

Sequence Diagram: ACP Client Session Model Setup

sequenceDiagram
  participant Test
  participant Client as ACP Client
  participant Agent as Helper Agent
  
  Test->>Client: CreateSession(ClientConfig.Model="explicit-id")
  activate Client
  Client->>Client: resolveModel(normalized="explicit-id")
  Client->>Agent: SetSessionModel(model_id="explicit-id")
  activate Agent
  Agent->>Agent: Mark modelSet=true
  Agent-->>Client: SetSessionModelResponse
  deactivate Agent
  Client->>Agent: Prompt(...)
  activate Agent
  Agent->>Agent: Check modelSet==true
  Agent-->>Client: PromptResponse
  deactivate Agent
  Client-->>Test: Success
  deactivate Client
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • compozy/compozy#83: Earlier edits to the same resolveModel path in registry_launch.go that trim requested model names and resolve aliases.
  • compozy/compozy#78: Prior modifications to the shared ACP test harness in internal/core/agent/client_test.go for NewSession and LoadSession expectations.
  • compozy/compozy#34: Original introduction of the resolveModel path and related ACP agent client/registry tests in the "use acp instead of stream raw json" work.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the main change: treating the model 'auto' value as the ACP runtime default instead of passing it literally.
Linked Issues check ✅ Passed The PR addresses all coding objectives from issue #177: normalizing 'auto' to runtime default [registry_launch.go], preventing literal 'auto' from reaching ACP [client_test.go], preserving explicit overrides [registry_launch.go], and fixing idempotency [link-skills.sh].
Out of Scope Changes check ✅ Passed All changes are directly scoped to the objectives: model normalization logic, test coverage for session model behavior, and shell script idempotency for verification consistency.

✏️ 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 codex/fix-cursor-model-auto

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

@greptile-apps

greptile-apps Bot commented May 31, 2026

Copy link
Copy Markdown

Greptile Summary

This PR fixes --model auto so it is treated as a sentinel meaning "use the ACP runtime's default model" rather than being forwarded literally as a model ID. It also makes scripts/link-skills.sh idempotent against dangling symlinks.

  • normalizeRequestedModel() is extracted from resolveModel() and maps any case/whitespace variant of \"auto\" to an empty string, causing fallback to spec.DefaultModel before alias resolution — so non-bootstrap runtimes (Cursor, etc.) never receive SetSessionModel(\"auto\").
  • Two integration tests verify the behaviour: one asserts no SetSessionModel call is made when model is \" AUTO \" for a non-bootstrap ACP, and another asserts explicit models like \"composer-2\" still flow through to SetSessionModel correctly.
  • link-skills.sh adds || [ -L \"$target_path\" ] to the outer guard so dangling symlinks (symlink exists but target is gone) are caught and re-linked rather than triggering a ln: File exists error.

Confidence Score: 5/5

Safe to merge — the core logic change is small and well-scoped, and the tests directly exercise both the 'auto suppresses SetSessionModel' path and the 'explicit model still calls SetSessionModel' path.

The model normalisation change is a single, well-isolated function added to registry_launch.go, and the downstream conditional (requestedModel != startModel) already provides the correct gate for SetSessionModel. The new tests exercise both the happy path and the edge cases (mixed-case, trimmed whitespace). The shell script fix is a one-line additive change that cannot break working symlinks.

No files require special attention.

Important Files Changed

Filename Overview
internal/core/agent/registry_launch.go Extracts normalizeRequestedModel() helper that maps 'auto' (case-insensitive, trimmed) to empty string before alias resolution, causing resolveModel() to fall back to spec.DefaultModel — preventing literal 'auto' from reaching SetSessionModel on non-bootstrap ACPs.
internal/core/agent/client_test.go Adds two integration tests verifying 'auto' model suppresses SetSessionModel on non-bootstrap ACP and explicit models (e.g. 'composer-2') still call SetSessionModel correctly; extends helper infrastructure with RejectSessionModel and ExpectedSessionModelID sentinel fields.
internal/core/agent/registry_test.go Adds unit test covering resolveModel/ResolveRuntimeModel for multiple IDEs and input variants of 'auto' (trimmed, uppercase, lowercase) confirming spec.DefaultModel is returned instead of the literal string.
scripts/link-skills.sh Fixes dangling-symlink detection in link_skill(): outer guard now includes [ -L "$target_path" ] so stale symlinks pointing to deleted targets are caught and re-linked instead of causing a 'File exists' ln error.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["cfg.Model input (e.g. 'auto', ' AUTO ', 'composer-2')"] --> B["normalizeRequestedModel()"]
    B --> C{EqualFold 'auto'?}
    C -- yes --> D["selected = ''"]
    C -- no --> E["selected = trimmed value"]
    D --> F["selected = spec.DefaultModel"]
    E --> G["modelprovider.ResolveAlias(selected)"]
    F --> G
    G --> H["normalizeRuntimeModel()"]
    H --> I["requestedModel"]
    I --> J{requestedModel == startModel?}
    J -- yes --> K["Skip SetSessionModel"]
    J -- no --> L["Call SetSessionModel(requestedModel)"]
Loading

Reviews (1): Last reviewed commit: "fix: treat model auto as runtime default" | Re-trigger Greptile

@coderabbitai coderabbitai Bot left a comment

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 comments (1)
internal/core/agent/registry_launch.go (1)

173-179: ⚡ Quick win

Add function documentation.

The exported helper normalizeRequestedModel should have a doc comment explaining its purpose and behavior, particularly the case-insensitive "auto" conversion to empty string.

📝 Proposed documentation
+// normalizeRequestedModel preprocesses the user-provided model name by trimming
+// whitespace and converting the case-insensitive literal "auto" to an empty string,
+// enabling fallback to the runtime's default model.
 func normalizeRequestedModel(modelName string) string {

As per coding guidelines: "Keep comments short and focused on intent, invariants, or protocol edge cases."

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/core/agent/registry_launch.go` around lines 173 - 179, Add a short
doc comment for normalizeRequestedModel explaining its purpose: it trims
whitespace from the input modelName and returns the cleaned name, with a special
case that treats the string "auto" case-insensitively as meaning "no specific
model" and returns an empty string; mention that comparison is case-insensitive
and that the function returns the trimmed model name otherwise.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@internal/core/agent/registry_launch.go`:
- Around line 173-179: Add a short doc comment for normalizeRequestedModel
explaining its purpose: it trims whitespace from the input modelName and returns
the cleaned name, with a special case that treats the string "auto"
case-insensitively as meaning "no specific model" and returns an empty string;
mention that comparison is case-insensitive and that the function returns the
trimmed model name otherwise.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 5405d1f0-5681-458e-9c12-556606d398ff

📥 Commits

Reviewing files that changed from the base of the PR and between a6967b5 and 7675241.

📒 Files selected for processing (4)
  • internal/core/agent/client_test.go
  • internal/core/agent/registry_launch.go
  • internal/core/agent/registry_test.go
  • scripts/link-skills.sh

@pedronauck
pedronauck merged commit 97cff24 into main May 31, 2026
8 checks passed
@pedronauck
pedronauck deleted the codex/fix-cursor-model-auto branch May 31, 2026 20:05
@pedronauck
pedronauck restored the codex/fix-cursor-model-auto branch June 11, 2026 14:52
@pedronauck
pedronauck deleted the codex/fix-cursor-model-auto branch July 27, 2026 18:23
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.

Cursor agent is stuck on 'waiting for ACP updates' error.

1 participant