fix: sanitize OneCLI agent identifiers#2179
fix: sanitize OneCLI agent identifiers#2179CopyPasteFail wants to merge 1 commit intoqwibitai:mainfrom
Conversation
25fafa7 to
057ceba
Compare
Implementation notesThis PR fixes the OneCLI agent identifier mismatch without changing the database identity of agent groups. ProblemNanoClaw agent group IDs can contain underscores, for example: OneCLI agent identifiers only accept lowercase letters, numbers, and hyphens. Passing the raw NanoClaw agent group ID into OneCLI can therefore fail validation. The obvious fix would be to replace underscores with hyphens before calling OneCLI: ag_f249a3521081 -> ag-f249a3521081However, that creates a second issue: OneCLI approval requests later return the normalized identifier as the agent external ID. If approval handling treats that normalized value as the original database Fix approachThis PR adds a small helper module for OneCLI agent identifiers: toOneCliAgentIdentifier(agentGroupId)This converts NanoClaw agent group IDs into OneCLI-safe identifiers by replacing
Approval handling also resolves the normalized OneCLI identifier back to the real database agent group before selecting approvers: getAgentGroupByOneCliIdentifier(request.agent.externalId)That preserves the existing scoped approver behavior:
Edge case consideredThere is a theoretical ambiguity: If both database IDs existed, they would normalize to the same OneCLI identifier. The resolver handles this conservatively:
This avoids silently routing an approval to the wrong group-scoped admin. When the normalized OneCLI identifier cannot be resolved uniquely, the code logs a warning and falls back to the existing non-scoped approver path instead of guessing. Risk considerationsThe main behavior change is that OneCLI approval routing now depends on normalized identifier resolution. Expected behavior:
This is safer than choosing the wrong scoped group, but it does mean that in an ambiguous case a group-scoped admin may not receive the approval. That seems like the right failure mode for this edge case. The resolver currently scans all agent groups. This should be acceptable because it runs during OneCLI approval handling, not in a hot path. If this ever becomes a concern, it could be replaced with a persisted normalized identifier or an indexed lookup. Possible follow-up: rename TestingAdded focused tests for:
Validation run locally: pnpm vitest run src/onecli-agent-identifier.test.ts
pnpm typecheck
pnpm testResults: |
5da033c to
655529d
Compare
|
Updated after review:
Validation after update: On the migration concern: this PR intentionally does not add migration logic for existing OneCLI registrations. The reported failing IDs contain underscores, which OneCLI rejects, so those affected IDs likely could not have been successfully registered under the old identifier in the first place. If there are older valid identifiers that normalize differently, OneCLI may see a new identifier, but that seems outside the narrow fix for #2046 and would need confirmation of OneCLI’s |
655529d to
4782899
Compare
|
Follow-up on review comments: I added the cheap missing coverage for already-valid OneCLI identifiers, since current generated IDs can already be hyphenated and should pass through unchanged. A few suggestions from review are intentionally left as future considerations rather than part of this bugfix:
Current validation after the latest update: |
|
I traced every code path that creates an @dr-pabs, did you actually hit this, and if so where did the underscore id come from in your DB? Without a reproducible source we'd rather not add permanent translation logic at the OneCLI boundary for a state the codebase doesn't produce. |
|
Small clarification on reproduction: I did not run a full end-to-end NanoClaw + OneCLI container-spawn reproduction that produced the live 400 response. What I verified locally is the code path that would cause it:
So this PR is based on code-path verification plus focused tests, not a full live end-to-end reproduction. I think that is enough for this fix, but I want to be explicit about what was and was not reproduced. |
Fixes #2046.
NanoClaw agent group IDs can contain underscores, for example
ag_f249a3521081, while OneCLI agent identifiers only accept lowercase letters, numbers, and hyphens.This normalizes the identifier before calling OneCLI by replacing underscores with hyphens. The same normalized identifier is used for
ensureAgentandapplyContainerConfig.Because OneCLI approval requests carry the normalized identifier back as the agent external ID, this resolves that identifier back to the real
agent_groups.idbefore scoped approver selection. If multiple database IDs normalize to the same OneCLI identifier, the resolver treats it as ambiguous, logs a warning, and does not select a scoped group.Possible follow-up: rename
getAgentGroupByOneCliIdentifiertoresolveAgentGroupByOneCliIdentifier, since the function can return no result when the identifier is missing or ambiguous.Validation:
pnpm vitest run src/onecli-agent-identifier.test.tspnpm typecheckpnpm test