Skip to content

feat(BA-6893): add kernel scheduling-history SDK v2 client and CLI commands#12866

Merged
fregataa merged 1 commit into
mainfrom
feat/BA-6893-kernel-history-sdk-cli
Jul 23, 2026
Merged

feat(BA-6893): add kernel scheduling-history SDK v2 client and CLI commands#12866
fregataa merged 1 commit into
mainfrom
feat/BA-6893-kernel-history-sdk-cli

Conversation

@jopemachine

@jopemachine jopemachine commented Jul 15, 2026

Copy link
Copy Markdown
Member

📚 Stacked PRs

Every PR below this one is merged, so this PR now branches straight off main and its diff is client-only.

Summary

SDK v2 methods and CLI commands over the two REST routes from #12870, completing the surface BA-6889..BA-6892 built up.

Command SDK method Route
bai scheduling-history kernel search search_kernel_history(request) POST /v2/scheduling-history/kernels/admin/search
bai scheduling-history kernel search-scoped KERNEL_ID kernel_scoped_search(request) POST /v2/scheduling-history/kernels/scoped/search
  • Both commands sit in the user-facing cli/v2/scheduling_history/ group as a kernel sub-group, matching the existing session / deployment / route sub-groups of this entity. The system-wide search is still gated server-side by superadmin_required, so a regular user calling it gets a 403.
  • Method naming follows the sibling sub-entities in the same SDK client (search_{entity}_history / {entity}_scoped_search), and the scope travels in the request body (ScopedSearchKernelHistoriesInput.scope) rather than as a path parameter.
  • search-scoped takes the kernel id as a positional argument, like every other scoped search in the CLI, and wraps it into KernelHistoryScopeDTO(kernel=[UUIDScope(...)]) — the list-shaped scope introduced by feat(BA-6989): reshape KernelScope into scope-item lists and accept a session scope #13071 (BA-6989). --session-id on this command is an ordinary filter, not a second scope axis, because the server accepts exactly one scope item.
  • The scoped search is authorized through the owning session (fix(BA-6957): authorize kernel scoped scheduling-history via the owning session #13003): whoever may read the session may read its kernels' scheduling history.
  • This is the only PR in the stack with user-visible behaviour, so it carries the single news fragment. The layers below it are internal; a changelog entry on any of them would describe a change users never experience.

Not covered: #13071 also lets the scope name a session (scope.session), returning the history of every kernel that session owns. The CLI does not expose that axis — the positional argument is the kernel id. If it is wanted, it belongs in a follow-up as its own command rather than as an optional positional.

How to test

Common options for both commands: --limit / --offset, --phase (contains), --from-status / --to-status (repeatable), --result SUCCESS|FAILURE|STALE|NEED_RETRY|EXPIRED|GIVE_UP|SKIPPED, --error-code / --message (contains), --order-by created_at:desc (also updated_at, repeatable), --session-id. search additionally takes --kernel-id; on search-scoped the kernel id is the positional scope instead.

# Find a kernel id (admin)
bai admin session kernel search --limit 5

# 1. Owner reads their kernel's history → 200
bai scheduling-history kernel search-scoped <KERNEL_ID>

# 2. Filters and ordering
bai scheduling-history kernel search-scoped <KERNEL_ID> --result FAILURE
bai scheduling-history kernel search-scoped <KERNEL_ID> --order-by created_at:asc

# 3. System-wide search with filters (superadmin)
bai scheduling-history kernel search --session-id <SESSION_ID>

# 4. Permission gate: the system-wide search as a regular user → 403
bai scheduling-history kernel search --limit 1

# 5. Missing kernel → 404
bai scheduling-history kernel search-scoped 00000000-0000-0000-0000-000000000001

Note: kernel_scheduling_history has no writer yet (BA-6852), so an empty list is the expected live response. To see populated responses, insert rows directly; from_status / to_status must be valid KernelSchedulingPhase values (PREPARING|PULLING|PREPARED|CREATING|RUNNING|TERMINATING|TERMINATED) or serialization fails. Test accounts live in fixtures/manager/example-keypairs.json.

Test plan

Verified end to end against a live manager rebased onto current main (which includes #13071), with a seeded history row:

  • search → 200; row fields (kernel_id, session_id, phase, from_status/to_status, result, attempts, timestamps) deserialize
  • search-scoped KERNEL_ID → 200, returns only that kernel's rows
  • search-scoped KERNEL_ID --session-id → matching session returns the row, non-matching returns none
  • Filters (--phase, --result, --from-status, --to-status, --message, --kernel-id, --session-id) and --order-by created_at:desc
  • --limit 1 --offset 1has_previous_page: true
  • search-scoped with no positional → Missing argument 'KERNEL_ID'
  • Missing kernel → 404 kernel_read_not-found
  • Regular user calling search → 403; the same user's search-scoped on their own kernel → 200
  • pants fmt / fix / lint / check clean
  • Responses containing scheduler-written history rows — blocked on BA-6852 as above

🤖 Generated with Claude Code

@github-actions github-actions Bot added size:L 100~500 LoC comp:client Related to Client component comp:cli Related to CLI component labels Jul 15, 2026
@jopemachine
jopemachine force-pushed the feat/BA-6893-kernel-history-sdk-cli branch from 663d835 to 09c0de0 Compare July 15, 2026 03:36
@jopemachine
jopemachine force-pushed the feat/BA-6892-kernel-history-adapter-rest branch from b9b9a37 to 8c13791 Compare July 15, 2026 09:40
@jopemachine
jopemachine force-pushed the feat/BA-6893-kernel-history-sdk-cli branch from 09c0de0 to fa25770 Compare July 15, 2026 09:40
@jopemachine
jopemachine force-pushed the feat/BA-6892-kernel-history-adapter-rest branch from 8c13791 to 28b1894 Compare July 15, 2026 09:56
@jopemachine
jopemachine force-pushed the feat/BA-6893-kernel-history-sdk-cli branch from fa25770 to d5b9202 Compare July 15, 2026 09:56
@jopemachine
jopemachine force-pushed the feat/BA-6892-kernel-history-adapter-rest branch from 28b1894 to 3db2ec3 Compare July 15, 2026 10:17
@jopemachine
jopemachine force-pushed the feat/BA-6893-kernel-history-sdk-cli branch from d5b9202 to 5803031 Compare July 15, 2026 10:17
@jopemachine
jopemachine force-pushed the feat/BA-6892-kernel-history-adapter-rest branch from 3db2ec3 to 610dd75 Compare July 20, 2026 04:10
@jopemachine
jopemachine force-pushed the feat/BA-6893-kernel-history-sdk-cli branch from 5803031 to 618b2fa Compare July 20, 2026 04:10
@jopemachine
jopemachine force-pushed the feat/BA-6892-kernel-history-adapter-rest branch from 610dd75 to 24c5225 Compare July 20, 2026 04:28
@jopemachine
jopemachine force-pushed the feat/BA-6893-kernel-history-sdk-cli branch from 618b2fa to 8d3b63e Compare July 20, 2026 04:28
@jopemachine
jopemachine force-pushed the feat/BA-6892-kernel-history-adapter-rest branch from 24c5225 to 9207228 Compare July 20, 2026 04:41
@jopemachine
jopemachine force-pushed the feat/BA-6893-kernel-history-sdk-cli branch from 8d3b63e to 9752716 Compare July 20, 2026 04:41
@jopemachine
jopemachine force-pushed the feat/BA-6892-kernel-history-adapter-rest branch from 9207228 to 6163a98 Compare July 20, 2026 04:47
@jopemachine
jopemachine force-pushed the feat/BA-6893-kernel-history-sdk-cli branch from 9752716 to 0b82b8f Compare July 20, 2026 04:47
@jopemachine
jopemachine force-pushed the feat/BA-6892-kernel-history-adapter-rest branch from 6163a98 to 164383b Compare July 20, 2026 04:55
@jopemachine
jopemachine force-pushed the feat/BA-6893-kernel-history-sdk-cli branch from 0b82b8f to 59abd5f Compare July 20, 2026 04:55
@jopemachine
jopemachine force-pushed the feat/BA-6892-kernel-history-adapter-rest branch from 164383b to 942cb3a Compare July 20, 2026 05:05
@jopemachine
jopemachine force-pushed the feat/BA-6893-kernel-history-sdk-cli branch from 59abd5f to 9cd3f7a Compare July 20, 2026 05:05
@jopemachine
jopemachine force-pushed the feat/BA-6892-kernel-history-adapter-rest branch from 942cb3a to 0b1af6b Compare July 20, 2026 05:09
@jopemachine
jopemachine force-pushed the feat/BA-6892-kernel-history-adapter-rest branch from 93a89e1 to 03bd499 Compare July 20, 2026 08:13
@jopemachine
jopemachine force-pushed the feat/BA-6893-kernel-history-sdk-cli branch from fcfce6c to 1b6689c Compare July 20, 2026 08:13
@jopemachine
jopemachine force-pushed the feat/BA-6892-kernel-history-adapter-rest branch from 03bd499 to d956d23 Compare July 20, 2026 08:26
@jopemachine
jopemachine force-pushed the feat/BA-6893-kernel-history-sdk-cli branch from 1b6689c to 2be2f57 Compare July 20, 2026 08:26
@jopemachine
jopemachine force-pushed the feat/BA-6892-kernel-history-adapter-rest branch from d956d23 to bc9dfe8 Compare July 20, 2026 08:41
@jopemachine
jopemachine force-pushed the feat/BA-6893-kernel-history-sdk-cli branch from 2be2f57 to 79065c3 Compare July 20, 2026 08:41
@jopemachine
jopemachine force-pushed the feat/BA-6892-kernel-history-adapter-rest branch from d1cf2de to 642d2ed Compare July 20, 2026 08:50
@jopemachine
jopemachine force-pushed the feat/BA-6893-kernel-history-sdk-cli branch from 79065c3 to f673401 Compare July 20, 2026 08:50
@jopemachine
jopemachine force-pushed the feat/BA-6892-kernel-history-adapter-rest branch 11 times, most recently from 76c497d to 4c5a83f Compare July 21, 2026 05:35
Comment thread src/ai/backend/client/v2/domains_v2/scheduling_history.py

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds kernel scheduling-history support to the SDK v2 and CLI.

Changes:

  • Adds admin and scoped SDK requests.
  • Adds kernel history filtering, ordering, and CLI commands.
  • Updates changelog and CLI reference documentation.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
scheduling_history.py Adds kernel-history SDK methods.
kernel.py Implements kernel-history CLI commands.
commands.py Registers the kernel subgroup.
12866.feature.md Adds the user-facing changelog entry.
SKILL.md Updates the CLI command reference.
Comments suppressed due to low confidence (1)

src/ai/backend/client/cli/v2/scheduling_history/kernel.py:183

  • The scoped command uses the same seven-value KernelHistoryOrderField, but its help advertises only two fields. List all accepted fields so --help reflects the actual interface.
    help="Order by field:direction (e.g., created_at:desc). Fields: created_at, updated_at.",

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

"""Kernel scheduling history commands."""


@kernel.command()
Comment thread src/ai/backend/client/v2/domains_v2/scheduling_history.py
Comment thread src/ai/backend/client/v2/domains_v2/scheduling_history.py
Comment thread src/ai/backend/client/cli/v2/scheduling_history/kernel.py Outdated
Comment thread changes/12866.feature.md Outdated
@@ -0,0 +1 @@
Add kernel scheduling-history queries to REST v2, the SDK, and the CLI (`bai scheduling-history kernel search / search-scoped`), scoped by session and/or kernel.
- **runtime-variant**: user(get, search) · admin(get, search, create, update, delete, bulk-delete)
- **runtime-variant-preset**: user(get, search) · admin(get, search, create, update, delete)
- **scheduling-history**: sub session / deployment / route — each (search, search-scoped)
- **scheduling-history**: sub session / kernel / deployment / route — each (search, search-scoped)
…mmands

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp:cli Related to CLI component comp:client Related to Client component size:L 100~500 LoC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants