Skip to content

fix(service): keep namespaced owner ids out of the agent id validation - #3709

Open
Lyin-OTTF wants to merge 1 commit into
agentscope-ai:mainfrom
Lyin-OTTF:fix/gh-3705-agent-id-colon
Open

Lyin-OTTF wants to merge 1 commit into
agentscope-ai:mainfrom
Lyin-OTTF:fix/gh-3705-agent-id-colon

Conversation

@Lyin-OTTF

Copy link
Copy Markdown

Description

Fixes #3705.

A managed session never runs when the control plane reports a namespaced owner id:

Managed session turn failed: sessionId=sess_62a374ad4da7, error=Invalid agentId
'dpa-namespace:default:default-92145f4c-...-sess_62a374ad4da7': must match [A-Za-z0-9._-]+ ...

HarnessAgentBuildService#sessionLogAgentId joins three parts:

return DP_AGENT_PREFIX + session.ownerId() + "-" + session.agentId() + "-" + session.id();

and the result is passed to HarnessAgent.Builder#agentId(...), which validates it through AgentBase.normalizeAgentId. The colon comes from the owner id (namespace:default), not from the agent id, and the validation rejects the whole assembled value.

Change

Took the first option from the issue: clean up on assembly, not widen the pattern.

Widening [A-Za-z0-9._-] is not safe here. normalizeAgentId documents the id as a single path/namespace segment, HarnessAgent.Builder#agentId pins it as the stable namespace key for composite-filesystem paths, and : is invalid in Windows paths regardless. So the assembled parts now go through a segment mapper that replaces anything outside the accepted alphabet with -:

dpa-namespace:default:default-92145f4c-...-sess_62a374ad4da7
dpa-namespace-default-default-92145f4c-...-sess_62a374ad4da7

Mapping instead of stripping keeps the owner, agent and session parts readable and distinct (dropping the namespace would let two namespaces with the same name collide). An id that was already valid is returned unchanged, so nothing changes for owners without a namespace prefix.

Tests

Added to HarnessAgentBuildServiceCacheKeyTest:

  • sessionLogAgentIdIsValidForNamespacedOwnerIds — builds a session with ownerId = "namespace:default", asserts the assembled id and runs it through AgentBase.normalizeAgentId, which is the check that was failing.
  • sessionLogAgentIdLeavesValidIdsUntouched — the plain owner-1 case still yields dpa-owner-1-bbb-sess_1.

Without the change the first test fails on the assembled id (dpa-namespace:default-default-..., colon still there), which is exactly what normalizeAgentId rejects in the reported log line.

A managed session fails before its first turn when the control plane reports a
namespaced owner id. sessionLogAgentId() joins "dpa-" + ownerId + "-" + agentId +
"-" + sessionId and hands the result to HarnessAgent.Builder#agentId, which
validates it through AgentBase.normalizeAgentId. With an owner id like
"namespace:default" the assembled id becomes
"dpa-namespace:default:default-...-sess_...", the validation rejects it with
"Invalid agentId ...: must match [A-Za-z0-9._-]+", and SessionTurnRunner logs
"Managed session turn failed" for every turn.

Widening the pattern is not the fix: normalizeAgentId documents the id as a
single path/namespace segment, harness pins it as the stable namespace key for
composite-filesystem paths, and ':' is invalid in Windows paths anyway. Map
characters outside the accepted alphabet to '-' per part instead, so the owner,
agent and session parts stay readable and distinct, and an id that was already
valid comes out unchanged.

Fixes agentscope-ai#3705

This branch has not been deployed

No deployments
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.

[Bug]:托管会话自动生成的 agentId 包含冒号,正则校验失败导致会话无法执行

1 participant