fix(BA-6062): Wrap legacy string based start_command via shell -c instead of shlex.split#11648
Open
seedspirit wants to merge 3 commits into
Open
fix(BA-6062): Wrap legacy string based start_command via shell -c instead of shlex.split#11648seedspirit wants to merge 3 commits into
start_command via shell -c instead of shlex.split#11648seedspirit wants to merge 3 commits into
Conversation
…f shlex.split Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR changes legacy string start_command handling for model service definitions from shlex.split() normalization to shell execution via [shell, "-c", command], plus a migration intended to repair previously persisted malformed single-element argv values.
Changes:
- Adds shared default shell wrapping for string
start_commandin Pydantic and trafaret validation paths. - Adds Alembic migration
70ffcaaa5f5cto rewrite selected persisted single-element argv lists. - Updates compatibility tests and adds a changelog entry.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
src/ai/backend/common/config.py |
Replaces shlex.split coercion with shell wrapping and updates default shell usage. |
src/ai/backend/manager/models/alembic/versions/70ffcaaa5f5c_rewrap_legacy_string_start_command_via_.py |
Adds data migration for previously wrapped single-element start_command lists. |
tests/unit/manager/data/deployment/test_model_definition_start_command_compat.py |
Updates tests to expect [shell, "-c", command] wrapping. |
changes/11648.fix.md |
Adds release note for the compatibility fix and migration. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
shlex.splitnormalization withshell -cwrapping for legacy stringstart_commandin stored model definitions, preserving shell semantics (pipes, redirections, env expansion, multiline). Effective on data-hydration paths only — see Scope below.70ffcaaa5f5cthat re-wraps existing single-element argv lists whose only token contains whitespace. Repairs rows produced by prior migration8c1f7d3a9e2bwhich stored legacy shell strings as a meaningless one-token list like["python service.py"]._wrap_str_start_command_into_argvis non-mutating: returns a new dict with overriddenstart_commandonly when wrapping is needed.Scope
The wrap fires at the strict-type boundary (
ModelServiceConfig.model_validate) and on draft hydration of stored payloads:PydanticColumn(ModelDefinition)/PydanticColumn(ModelDefinitionDraft).model-definition.yamlvalidation throughmodel_definition_iv(trafaret).ModelDefinitionDraft.REST v2 / GraphQL request input is not affected:
ModelServiceConfigInput(common/dto/manager/v2/deployment/request.py) still typesstart_commandaslist[str] | None, so request payloads must be argv lists. The wrap is purely a backward-compat for pre-existing stored data and user-authored yaml.Test plan
runtime_variants(whitespace 1-elem → rewrap, no-ws 1-elem preserved, multi-elem preserved, null preserved, custom-shell vs DEFAULT_SHELL fallback). Downgrade no-op, re-upgrade idempotent.tests/unit/manager/data/deployment/test_model_definition_start_command_compat.pycovers Pydantic, trafaret, raw YAML, andPydanticColumnread paths with both default-shell and custom-shell cases.pants test --changed-since=...green.Resolves BA-6062