Skip to content

systems: manifest name and member-key checks accept a trailing newline #4331

Closed

Description

@AndriiPasternak31

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, with MANIFEST_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_manifest refuses 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 \n is refused.
  • Every currently valid name still passes: the existing system-manifest tests stay green.

Follow-up from abilityai/trinity-enterprise#1117.

Activity

  1. added
    priority-p3
    type-bug
    theme-reliability
    complexity-low
    status-ready
    on Nov 6, 2026
  2. added
    status-in-dev
    on Nov 7, 2026
  3. removed
    status-ready
    on Nov 7, 2026
  4. removed
    status-in-dev
    on Nov 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    complexity-lowpriority-p3theme-reliabilitytype-bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions