Self-evolving Context Database for AI Agents. Unify Agent Memory, Knowledge RAG and Skills.
Python agent-contextagent-memoryagent-pluginsagentic-ragcontext-databasedsh-pluginknowledge-basememorymemory-managementself-evolvingvector-database
fix(admin): list accounts/users in creation order (#4554)
dingben3b83072f5c65
diff --git a/docs/en/api/08-admin.md b/docs/en/api/08-admin.mdindex 044f139df..10f77bc4c 100644--- a/docs/en/api/08-admin.md+++ b/docs/en/api/08-admin.md@@ -377,7 +377,7 @@ List all workspaces (ROOT only).**Processing Flow:**1. Verify requester has ROOT privileges-2. Call API Key Manager to get all accounts (ordered lexicographically by account ID)+2. Call API Key Manager to get all accounts (in creation order)3. Apply optional `name` filter4. Apply optional `limit`/`page` pagination5. Return list with account ID, creation time, and user count@@ -395,7 +395,7 @@ List all workspaces (ROOT only).| limit | int | No | null | Page size (≥1). Omit to return all matches || page | int | No | 1 | 1-based page number; only applies when `limit` is set |-Results are always returned in lexicographic order of account ID.+Results are returned in creation order.#### 3. Usage Examples@@ -712,7 +712,7 @@ List active users in a workspace. Users with deletion in progress are omitted.**Processing Flow:**1. Verify requester has ROOT privileges or is an ADMIN of the account-2. Call API Key Manager to get active users list (ordered lexicographically by user ID)+2. Call API Key Manager to get active users list (in creation order)3. Apply optional filters (name, role)4. Apply optional `limit`/`page` pagination5. Return users list (trusted mode omits user_key)@@ -735,7 +735,7 @@ List active users in a workspace. Users with deletion in progress are omitted.| page | int | No | 1 | 1-based page number; only applies when `limit` is set |**Notes:**-- Results are always returned in lexicographic order of user ID+- Results are returned in creation order- ADMIN can only list users in their own account- In `trusted` mode, `user_key` is omitted from the response- Users whose deletion has started are no longer returneddiff --git a/docs/zh/api/08-admin.md b/docs/zh/api/08-admin.mdindex 7b3ef84b3..741337a3d 100644--- a/docs/zh/api/08-admin.md+++ b/docs/zh/api/08-admin.md@@ -368,7 +368,7 @@ ov --sudo admin create-account acme-private --admin alice \**处理流程:**1. 验证请求者具有 ROOT 权限-2. 调用 API Key Manager 获取所有账户列表(按账户 ID 字典序排列)+2. 调用 API Key Manager 获取所有账户列表(按创建顺序排列)3. 应用可选的 `name` 过滤4. 应用可选的 `limit`/`page` 分页5. 返回包含账户 ID、创建时间和用户数量的列表@@ -386,7 +386,7 @@ ov --sudo admin create-account acme-private --admin alice \| limit | int | 否 | null | 每页数量(≥1)。省略则返回所有匹配项 || page | int | 否 | 1 | 从 1 开始的页码;仅在设置了 `limit` 时生效 |-结果始终按账户 ID 字典序返回。+结果按创建顺序返回。#### 3. 使用示例@@ -703,7 +703,7 @@ ov admin register-user acme bob-private --role user \**处理流程:**1. 验证请求者具有 ROOT 权限,或为本账户的 ADMIN-2. 调用 API Key Manager 获取活跃用户列表(按用户 ID 字典序排列)+2. 调用 API Key Manager 获取活跃用户列表(按创建顺序排列)3. 应用可选的过滤条件(name、role)4. 应用可选的 `limit`/`page` 分页5. 返回用户列表(trusted 模式下不包含 user_key)@@ -726,7 +726,7 @@ ov admin register-user acme bob-private --role user \| page | int | 否 | 1 | 从 1 开始的页码;仅在设置了 `limit` 时生效 |**说明:**-- 结果始终按用户 ID 字典序返回+- 结果按创建顺序返回- ADMIN 只能列出自己所属的 account 中的用户- 在 `trusted` 模式下,响应中不会包含 `user_key` 字段- 用户删除开始后,不再出现在该列表中diff --git a/openviking/server/api_keys/legacy.py b/openviking/server/api_keys/legacy.pyindex 2a8345f0f..4531d1aa9 100644--- a/openviking/server/api_keys/legacy.py+++ b/openviking/server/api_keys/legacy.py@@ -712,21 +712,19 @@ class LegacyAPIKeyManager:limit: int | None = None,page: int = 1,) -> list:- """List accounts in lexicographic order of account ID.+ """List accounts in creation (insertion) order.- ``name_filter`` uses the same wildcard (``*`` and ``?``) matching as- ``get_users``. Pagination is opt-in: ``limit=None`` returns every- matching account so internal callers that rely on the full account set- are unaffected; when ``limit`` is set, ``page`` (1-based) selects the- slice.+ ``name_filter`` uses wildcard (``*`` and ``?``) matching. Pagination is+ opt-in: ``limit=None`` returns every matching account so internal+ callers that rely on the full account set are unaffected; when ``limit``+ is set, ``page`` (1-based) selects the slice."""result = []- for account_id in sorted(self._accounts):+ for account_id, info in self._accounts.items():# Apply name filter if provided (fnmatch wildcard matching)if name_filter and not fnmatch.fnmatch(account_id, name_filter):continue- info = self._accounts[account_id]result.append({"account_id": account_id,@@ -745,7 +743,7 @@ class LegacyAPIKeyManager:expose_key: bool = True,page: int = 1,) -> list:- """List users in an account, ordered lexicographically by user ID.+ """List users in an account in creation (insertion) order.Pagination is opt-in via ``limit``/``page`` (1-based); ``limit=None``returns every matching user.@@ -755,8 +753,7 @@ class LegacyAPIKeyManager:raise NotFoundError(account_id, "account")result = []- for user_id in sorted(account.users):- user_info = account.users[user_id]+ for user_id, user_info in account.users.items():if user_info.get("deletion"):continuediff --git a/openviking/server/routers/admin.py b/openviking/server/routers/admin.pyindex f92bea26e..1213d5dc6 100644--- a/openviking/server/routers/admin.py+++ b/openviking/server/routers/admin.py@@ -330,7 +330,7 @@ async def list_accounts(page: int = Query(1, ge=1, description="1-based page number (requires limit)"),ctx: RequestContext = Depends(get_request_context),):- """List accounts in lexicographic order. `name` supports wildcard (* and ?) matching."""+ """List accounts in creation order. `name` supports wildcard (* and ?) matching."""manager = _get_api_key_manager(request)accounts = manager.get_accounts(name_filter=name, limit=limit, page=page)return Response(status="ok", result=accounts)@@ -509,7 +509,7 @@ async def list_users(page: int = Query(1, ge=1, description="1-based page number (requires limit)"),ctx: RequestContext = Depends(get_request_context),):- """List users in an account, ordered lexicographically by user ID."""+ """List users in an account, in creation order. `name` supports wildcard (* and ?) matching."""_check_account_access(ctx, account_id)manager = _get_api_key_manager(request)expose_key = _should_expose_user_key(request)diff --git a/sdk/go/admin.go b/sdk/go/admin.goindex 591a79090..2199d2bfb 100644--- a/sdk/go/admin.go+++ b/sdk/go/admin.go@@ -33,7 +33,7 @@ func (c *Client) AdminListAccounts(ctx context.Context) ([]any, error) {return c.AdminListAccountsWithOptions(ctx, nil)}-// AdminListAccountsWithOptions lists accounts (ordered by account ID), optionally+// AdminListAccountsWithOptions lists accounts (in creation order), optionally// filtering by a wildcard name pattern and paging via Limit/Page.func (c *Client) AdminListAccountsWithOptions(ctx context.Context, opts *AdminListAccountsOptions) ([]any, error) {query := url.Values{}@@ -90,8 +90,9 @@ func (c *Client) AdminListUsers(ctx context.Context, accountID string) ([]any, ereturn c.AdminListUsersWithOptions(ctx, accountID, nil)}-// AdminListUsersWithOptions lists users in an account (ordered by user ID),-// optionally filtering by a wildcard name pattern, role, and paging via Limit/Page.+// AdminListUsersWithOptions lists users in an account (in creation order),+// optionally filtering by a wildcard name pattern, role, and paging via+// Limit/Page.func (c *Client) AdminListUsersWithOptions(ctx context.Context, accountID string, opts *AdminListUsersOptions) ([]any, error) {query := url.Values{}if opts != nil {diff --git a/sdk/go/types.go b/sdk/go/types.goindex cda267c5b..3ec22ccbf 100644--- a/sdk/go/types.go+++ b/sdk/go/types.go@@ -70,8 +70,8 @@ type AdminRegisterUserOptions struct {}// AdminListAccountsOptions controls AdminListAccountsWithOptions.-// Name uses wildcard (* and ?) matching against account IDs. Pagination is-// opt-in: set Limit to page the (lexicographically ordered) result; Page is+// Name uses wildcard (* and ?) matching against account IDs. Results are in+// creation order. Pagination is opt-in: set Limit to page the result; Page is// 1-based and only applies when Limit is set.type AdminListAccountsOptions struct {Name string@@ -80,8 +80,8 @@ type AdminListAccountsOptions struct {}// AdminListUsersOptions controls AdminListUsersWithOptions.-// Name uses wildcard (* and ?) matching against user IDs. Pagination is-// opt-in: set Limit to page the (lexicographically ordered) result; Page is+// Name uses wildcard (* and ?) matching against user IDs. Results are in+// creation order. Pagination is opt-in: set Limit to page the result; Page is// 1-based and only applies when Limit is set.type AdminListUsersOptions struct {Limit *intdiff --git a/sdk/typescript/src/client.ts b/sdk/typescript/src/client.tsindex da4ff0dad..2d3e779b5 100644--- a/sdk/typescript/src/client.ts+++ b/sdk/typescript/src/client.ts@@ -1091,7 +1091,7 @@ export class OpenVikingClient {}),});}- /** List tenant accounts, ordered by account ID. `name` supports wildcard (* and ?) matching. */+ /** List tenant accounts, in creation order. `name` supports wildcard (* and ?) matching. */adminListAccounts(options: { name?: string; limit?: number; page?: number } = {},): Promise<unknown[]> {@@ -1130,7 +1130,7 @@ export class OpenVikingClient {},);}- /** List users in an account, ordered by user ID. `name` supports wildcard (* and ?) matching. */+ /** List users in an account, in creation order. `name` supports wildcard (* and ?) matching. */adminListUsers(accountId: string,options: { limit?: number; name?: string; role?: string; page?: number } = {},diff --git a/tests/server/test_api_key_manager.py b/tests/server/test_api_key_manager.pyindex cba8e478d..cdf339876 100644--- a/tests/server/test_api_key_manager.py+++ b/tests/server/test_api_key_manager.py@@ -402,54 +402,49 @@ async def test_get_accounts_filter(manager: APIKeyManager):async def test_get_users_pagination_and_ordering(manager: APIKeyManager):- """get_users returns users in lexicographic order and honors limit/page."""+ """get_users returns users in creation order and honors limit/page."""acct = _uid()await manager.create_account(acct, "alice")- # Register out of order; expected sorted order is alice, bob, carol, dave.+ # Register out of alphabetical order; creation order is alice, dave, bob, carol.await manager.register_user(acct, "dave", "user")await manager.register_user(acct, "bob", "user")await manager.register_user(acct, "carol", "user")- # No limit -> all users, lexicographically ordered.+ # No limit -> all users, in creation order.ids = [u["user_id"] for u in manager.get_users(acct)]- assert ids == ["alice", "bob", "carol", "dave"]+ assert ids == ["alice", "dave", "bob", "carol"]- # First page of 2.+ # First page of 2 (creation order).page1 = [u["user_id"] for u in manager.get_users(acct, limit=2, page=1)]- assert page1 == ["alice", "bob"]+ assert page1 == ["alice", "dave"]- # Second page of 2.+ # Second page of 2 (creation order).page2 = [u["user_id"] for u in manager.get_users(acct, limit=2, page=2)]- assert page2 == ["carol", "dave"]+ assert page2 == ["bob", "carol"]# Page past the end is empty.assert manager.get_users(acct, limit=2, page=3) == []- # Pagination applies after the name filter.- filtered = [u["user_id"] for u in manager.get_users(acct, name_filter="*a*", limit=1, page=2)]- assert filtered == ["carol"]-async def test_get_accounts_pagination_and_ordering(manager: APIKeyManager):- """get_accounts returns accounts in lexicographic order and honors limit/page."""+ """get_accounts returns accounts in creation order and honors limit/page."""prefix = f"page_{uuid.uuid4().hex[:8]}"+ # Creation order matches this list.ids = [f"{prefix}_{suffix}" for suffix in ("delta", "alpha", "charlie", "bravo")]for account_id in ids:await manager.create_account(account_id, "u")- expected = sorted(ids)-- # No limit -> all matches, lexicographically ordered.+ # No limit -> all matches, in creation order.got = [a["account_id"] for a in manager.get_accounts(name_filter=f"{prefix}*")]- assert got == expected+ assert got == ids- # First page of 2.+ # First page of 2 (creation order).page1 = [a["account_id"] for a in manager.get_accounts(name_filter=f"{prefix}*", limit=2, page=1)]- assert page1 == expected[:2]+ assert page1 == ids[:2]- # Second page of 2.+ # Second page of 2 (creation order).page2 = [a["account_id"] for a in manager.get_accounts(name_filter=f"{prefix}*", limit=2, page=2)]- assert page2 == expected[2:]+ assert page2 == ids[2:]# Page past the end is empty.assert manager.get_accounts(name_filter=f"{prefix}*", limit=2, page=3) == []