Skip to content

feat(BA-6852): record Agent kernel transitions into scheduling history#13033

Closed
jopemachine wants to merge 2 commits into
mainfrom
feat/BA-6852-kernel-status-transition-recording
Closed

feat(BA-6852): record Agent kernel transitions into scheduling history#13033
jopemachine wants to merge 2 commits into
mainfrom
feat/BA-6852-kernel-status-transition-recording

Conversation

@jopemachine

Copy link
Copy Markdown
Member

Resolves #12785 (BA-6852)

Summary

Nothing wrote kernel_scheduling_history until now — KernelSchedulingHistoryCreatorSpec had no caller — so the kernel scheduling-history APIs (#12870/#12989/#12866) always returned empty lists. This implements the Manager-side recording/apply contract of BEP-1061 §3e, plus the unified event type from §3d that it consumes.

Piece Change
Event (§3d) KernelStatusTransitionAnycastEvent(kernel_id, from_status, to_status, reason, result, error_code, message) — no phase/step payload; from/to are sokovan KernelStatus values
Apply (§3e-2) Atomic UPDATE … WHERE status = from in the scheduler repository, so a duplicate/stale transition matches nothing and is rejected idempotently; a FAILED report leaves the status untouched
Record (§3e-1) History row written in the same transaction, mapping the transition onto phase/from_status/to_status/result/error_code/message; a redelivered identical record merges by incrementing attempts (at-least-once transport / sweep re-emission)
Follow-up Applied transitions request the same ScheduleType marks as the granular handlers (e.g. CHECK_PULLING_PROGRESS after PULLING)
Guard Targets outside the Agent-reportable phase set (PREPARING…TERMINATED) are ignored — CANCELLED/reschedule stays with sokovan session scheduling, per the BEP

phase derives from the Agent execution stage owning the target status (prepare / create / terminate, per the BEP handler table). TERMINATED transitions also free resource allocations, mirroring the existing terminated path.

Boundary

The Agent-side egress that emits this event is BA-6851 (not started); until it lands, the granular anycast events remain the live path and this handler consumes only what is published to the unified event. Migrating granular consumers is BA-6853.

Note: BA-6852 is assigned to @HyeockJinKim — this PR was made on jopemachine's direction to unblock the kernel history feature line; happy to hand over or adjust to your planned shape.

Test plan

  • Unit — coordinator handler (13 cases): full domain of the 7 Agent-reportable target phases with their follow-up schedule marks, FAILED report without follow-up, stale rejection, unknown/non-reportable statuses ignored
  • Repository (real DB, 6 cases): apply+record atomically; stale from rejected without history; redelivered applied transition rejected; FAILED records without status change; repeated FAILED merges to one row with attempts=2; non-reportable target ignored
  • Live end-to-end: published the event onto the Redis events stream against a running manager — status applied (PULLING → PREPARED), history row recorded and visible to the kernel owner through scopedKernelSchedulingHistories, redelivered copy rejected (no duplicate), repeated failure reports merged (attempts=2)
  • ruff check / ruff format clean

🤖 Generated with Claude Code

Add the unified KernelStatusTransitionAnycastEvent (BEP-1061 3d) and the
Manager-side recording/apply contract (3e). Nothing wrote
kernel_scheduling_history until now -- KernelSchedulingHistoryCreatorSpec had
no caller -- so the kernel scheduling-history APIs always returned empty lists.

On receiving the event, the Manager:

- applies `from -> to` atomically (UPDATE WHERE status = from), so a
  duplicate or stale transition matches nothing and is rejected idempotently;
  a failure report leaves the status untouched and records history only
- records the transition into kernel_scheduling_history in the same
  transaction, mapping the Agent's KernelStatus transition and processing
  result onto phase/from_status/to_status/result/error_code/message; a
  redelivered identical record merges by incrementing attempts (at-least-once
  transport, sweep re-emission)
- requests the same follow-up schedule types as the granular event handlers
  (e.g. CHECK_PULLING_PROGRESS after PULLING) when a transition is applied

The phase column derives from the Agent execution stage owning the target
status (prepare/create/terminate, per the BEP handler table). Transitions
targeting statuses outside the Agent-reportable phase set (e.g. CANCELLED,
which belongs to sokovan session scheduling) are ignored.

The Agent-side egress that emits this event is BA-6851; until it lands, the
granular anycast events remain the live path and this handler consumes only
what is published to the unified event. Verified end to end on a live stack by
publishing the event to the Redis stream: the Manager consumed it, applied the
transition, recorded history visible through the scoped kernel history API,
rejected a redelivered copy, and merged repeated failure reports into one row
with attempts=2.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@github-actions github-actions Bot added comp:manager Related to Manager component comp:common Related to Common component labels Jul 22, 2026
@jopemachine

Copy link
Copy Markdown
Member Author

This work should be done after the agent refactoring.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp:common Related to Common component comp:manager Related to Manager component size:XL 500~ LoC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Manager: record kernel status transitions into kernel_scheduling_history and apply from->to

1 participant