Repository navigation
Description
Problem
validate_manifest (src/backend/services/system_service.py:345) checks the system name and each member key with re.match and a pattern that ends in $:
- the system name at
:358:re.match(r'^[a-z0-9][a-z0-9-]{0,48}[a-z0-9]$|^[a-z0-9]{1,2}$', manifest.name) - each member key at
:374, withMANIFEST_KEY_RE(:80):^[a-z0-9]([a-z0-9_.-]*[a-z0-9_.])?$
In Python, $ also matches just before a final \n. So a quoted YAML name such as "ab\n", or a member key such as "w\n", passes validation. The agent name is then built as f"{system_name}-{short}" (:570, or the bare key under naming: bare) and passed to create_agent_internal with skip_name_sanitization=True (deploy at :2519, apply at :4494). The name is not checked again on the way, so a newline ends up in the agent name, in log lines and in the error the deploy reports when Docker refuses the container name.
A / cannot pass these patterns, so this is not a path problem. It is a validation bug.
The same re.match + $ shape is used for local template names (_LOCAL_TEMPLATE_NAME_RE, src/backend/services/template_service.py:1475, used at :1514, and its copy in src/backend/services/agent_service/crud.py:83, used at :189).
Evidence
Checked at origin/dev 1c56892d8. No open PR changes these patterns.
Repro, run from the repository root against an export of 1c56892d8 with the backend test dependencies. Set TRINITY_DB_PATH to a temporary file path and REDIS_URL to any URL with credentials, for example redis://u:[email protected]:1.
import re, sys
sys.path.insert(0, "src/backend")
from services.system_service import parse_manifest, validate_manifest
docs = {
"member key 'w' + newline": 'name: demo\nagents:\n "w\\n":\n template: local:x\n',
"system name 'ab' + newline": 'name: "ab\\n"\nagents:\n w:\n template: local:x\n',
"control: interior newline": 'name: demo\nagents:\n "w\\nx":\n template: local:x\n',
}
for label, doc in docs.items():
try:
m = parse_manifest(doc); validate_manifest(m)
print(f"{label:28} ACCEPTED name={m.name!r} keys={list(m.agents)}")
except Exception as e:
print(f"{label:28} refused ({type(e).__name__})")
print("re.match('^w$', 'w\\n'):", bool(re.match(r"^w$", "w\n")), "| re.fullmatch('w', 'w\\n'):", bool(re.fullmatch(r"w", "w\n")))Output:
member key 'w' + newline ACCEPTED name='demo' keys=['w\n']
system name 'ab' + newline ACCEPTED name='ab\n' keys=['w']
control: interior newline refused (ValueError)
re.match('^w$', 'w\n'): True | re.fullmatch('w', 'w\n'): False
What happens after validation (the name reaching create_agent_internal, then Docker refusing it) is read from the code and was not executed.
Suggested fix
Use re.fullmatch (or end the patterns with \Z) at system_service.py:358 and :374, and for _LOCAL_TEMPLATE_NAME_RE in template_service.py and crud.py.
Acceptance criteria
-
validate_manifestrefuses a system name and a member key that end in\n, with the existing "Invalid system name" / "Invalid agent name" messages. - A local template name ending in
\nis refused. - Every currently valid name still passes: the existing system-manifest tests stay green.
Follow-up from abilityai/trinity-enterprise#1117.
Activity
merge-train: test_ent591 pins the \Z anchor on crud's local template …
fix(systems): reject trailing newline in system names, member keys an…