Skip to content

feat: extract agent-bus scheduling kernel - #15

Merged
zhanghanduo merged 7 commits into
mainfrom
refactor/agent-bus-scheduling
Sep 2, 2026
Merged

zhanghanduo merged 7 commits into
mainfrom
refactor/agent-bus-scheduling

Conversation

@zhanghanduo

Copy link
Copy Markdown
Collaborator

Summary

  • extract the complete AgentBus scheduling domain: communication, durable result recovery, spawn guards, reusable sessions, fan-in, shared pools, and stop signals
  • add portable Tool, KernelEvent, TaskBudget, finalization-budget, role-resource, and DAG scheduler contracts needed by the bus
  • converge ApodexHarness result-message recovery with FrontierAgent session wait/activity behavior as one compatible superset
  • keep product persistence, tool assembly, workflow defaults/policy, pause checks, LLM construction, and execution context behind explicit injection points
  • document the final AgentBus boundary and the next provider-substrate batch

Validation

  • uv run ruff check agent_core tests
  • uv run pyright agent_core — 0 errors, 0 warnings
  • uv run pytest -q — 809 passed
  • uv build

zhanghanduo and others added 7 commits September 2, 2026 12:17
Four defects in the extracted scheduling kernel, all of the same shape:
code carried over from the source implementation kept an assumption its
original environment satisfied, while the portable abstraction changed.

SpawnGuard reservations leaked on any failed submit. `pre_check` reserves
tokens and registers the job, but the RAII release lives in
`_run_and_finalize`, which does not exist until `create_task` has run — so
an unregistered role (`get_prompt_for` raising) or a failing session
dispatch leaked the reservation permanently, decaying `remaining_tokens`
and the concurrency count for the life of the bus. Resolve the system
prompt before reserving, register the job entry before spawning, and
release explicitly on every path that can raise in between. Sessions get
the same treatment on both the free and the queued dispatch — the latter
matters because `_drain_session_queue` swallows dispatch failures by
design, so nothing upstream is left to hand the reservation back.

`AgentComm.consume` ordered its durable cursor with `int(event.id)`, but
`EventId` is an opaque string and `new_event_id()` returns uuid4 hex. Add
an explicit `KernelEvent.seq` ordinal and read it through `event_ordinal`,
falling back to a decimal id so stores that expose their integer primary
key keep working. A store that stamps neither now raises
`EventStoreContractError` naming the fix instead of a bare `ValueError`,
and `AgentBus` logs the lost durable-recovery capability at ERROR rather
than swallowing it at debug — that blanket `except Exception` is why the
whole L1-0 path could be dead with nothing in the logs.

`_AgentCommEventStore` declared `EventSink.append(task_id, event_type,
payload, agent_role)` but was called with a whole `KernelEvent`, so a host
implementing the documented protocol bound the event to `task_id` and
returned None. Messaging genuinely needs the richer append —
`from_agent` / `to_agent` / `message_type` / `correlation_id` are the
fields the reader queries on — so declare that signature and drop the
`EventSink` inheritance. `EventSink` stays exactly as it was for
telemetry; the two roles are now distinct and documented.

`resolve_research_wall` selected its input by key presence, so
`wall_deadline_s` was unreadable whenever `research_wall_time_s` existed:
`hard_total_s` came back 0, `check_wall_feasibility` passed
unconditionally, and the total-task ceiling was silently unenforced. Read
both keys independently and select on value validity.

Contract tests cover all four, including the store-ordering contract the
`consume` docstring referenced but that did not exist in this package.

Validation: ruff clean, pyright 0 errors, 849 passed (was 812), `uv build`,
plus a smoke run of all four paths against the built wheel.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@zhanghanduo
zhanghanduo merged commit 4609e92 into main Sep 2, 2026
1 check passed
@zhanghanduo
zhanghanduo deleted the refactor/agent-bus-scheduling branch September 2, 2026 05:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant