fix(cli): ncl groups delete cascades + auto-IDs survive OneCLI validation#2540
Open
abarbaccia wants to merge 1 commit into
Open
fix(cli): ncl groups delete cascades + auto-IDs survive OneCLI validation#2540abarbaccia wants to merge 1 commit into
abarbaccia wants to merge 1 commit into
Conversation
…dation
Two coupled fixes for ncl groups create/delete:
1. `customDelete` hook on ResourceDef. genericDelete previously ran
`DELETE FROM ${table}` directly, which is fine for leaf resources
but breaks on agent_groups — sessions, wirings, members, roles,
destinations, and a few approval tables all hold a FK with no ON
DELETE CASCADE. The cascade now happens in deleteAgentGroup() inside
a single transaction. genericDelete falls back to the raw SQL when
no customDelete is set, so every other resource is unchanged.
2. `idPrefix` on ResourceDef + accept explicit --id on create.
randomUUID() starts with a digit ~62% of the time. OneCLI rejects
any agent identifier that doesn't match ^[a-z][a-z0-9-]{0,49}$, so
every freshly-created group via `ncl groups create` failed forever
on the first wakeContainer with HTTP 400 Bad Request. Groups now
carry idPrefix='ag-' so auto-IDs are always OneCLI-safe, and
callers can pass --id explicitly when they want a readable identifier.
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
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
Two coupled bugs that surface together the moment you create a brand-new agent group via `ncl groups create` and try to clean it up.
1. `ncl groups delete` always fails with FOREIGN KEY constraint failed
`genericDelete` in `src/cli/crud.ts` ran `DELETE FROM ${table}` directly. That's fine for leaf rows, but `agent_groups` has FK references with no `ON DELETE CASCADE` from `sessions`, `messaging_group_agents`, `agent_group_members`, `user_roles`, `agent_destinations`, and a few pending-approval tables. Result: once a session row exists for the group, `ncl groups delete` errors forever and there's no `ncl` verb to clean it up.
Fix:
2. Auto-generated agent group IDs are rejected by OneCLI
`genericCreate` generates IDs via `randomUUID()`. UUIDs start with a digit ~62% of the time. OneCLI's `POST /api/agents` validates `identifier` against `^[a-z][a-z0-9-]{0,49}$` and returns 400 Bad Request. The host's first wakeContainer call then fails forever:
```
OneCLIRequestError: [URL=…/api/agents] [StatusCode=400] OneCLI returned 400 Bad Request
```
Repro: `./bin/ncl groups create --name Foo --folder foo` — any UUID starting with a digit. Symptom is silent — the host just keeps retrying on every sweep.
Fix:
Test plan
🤖 Generated with Claude Code