feat(sdk/engine,sdk/event,sdk/model): engine host extensibility, event sampling, and token usage enrichment#51
Merged
lIang70 merged 1 commit intoApr 29, 2026
Conversation
…t sampling, and token usage enrichment Engine layer: - Add Capabilities struct + Describer interface so engines can advertise SupportsResume, EmitsUserPrompt, EmitsCheckpoint, and RequiredDepNames. Pod/agent layer reads these to validate PodSpecs and gate behaviour. - Add HostMiddleware type + ComposeHost helper for stacking policy decorators (audit → rate-limit → budget → secret-resolve) around a base Host. HostFuncs adapter makes partial decoration easy. - Add MergeInterrupts helper to fan-in N interrupt channels into one, the shape sandbox/pod hosts need for combining user cancel, SIGTERM, budget exceeded, graceful stop, etc. - Change UsageReporter.ReportUsage to return error. Hosts may now return errdefs.BudgetExceeded to signal accumulated usage has crossed a configured budget; engines MUST stop LLM-cost-incurring work on seeing it. Event layer: - Add BackpressurePolicy.Sample for probabilistic envelope delivery with configurable per-subscription rate via WithSampleRate. Useful for high-volume streams (token deltas, voice frames) where exact delivery is unnecessary and Block/DropOldest/DropNewest have undesirable side-effects. - Add AckSubscription interface for at-least-once delivery semantics (cross-process buses backed by NATS/Redis Streams/Kafka). v1 minimal contract: Ack(envelopeID) with duplicate tolerance. Model layer: - Enrich TokenUsage with Model, LatencyMs, CostMicros fields so sandbox hosts can enforce dollar-denominated budgets and per-model rate limits without a separate sidecar. TokenUsage.Add() updated to aggregate all numeric fields; Model label is preserved from the accumulator. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
lIang70
deleted the
feat/engine-host-extensibility-and-event-bus-enhancements
branch
April 29, 2026 10:39
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
Capabilitiesstruct +Describerinterface so engines can advertiseSupportsResume,EmitsUserPrompt,EmitsCheckpoint, andRequiredDepNames. Pod/agent layer reads these to validate PodSpecs and gate behaviour at apply time.ComposeHosthelper for stacking policy layers (audit → rate-limit → budget → secret-resolve) around a baseHost.HostFuncsadapter makes partial decoration easy without struct embedding.MergeInterrupts: New helper that fans N interrupt channels into one — the shape sandbox/pod hosts need for combining user cancel, SIGTERM, budget exceeded, graceful stop, etc.UsageReporter.ReportUsage: Changed fromvoidtoerrorreturn. Hosts may now returnerrdefs.BudgetExceededto signal accumulated usage has crossed a budget; engines MUST stop LLM-cost-incurring work on seeing it.BackpressurePolicy.Samplefor probabilistic envelope delivery withWithSampleRateoption — useful for high-volume streams (token deltas, voice frames) where exact delivery is unnecessary. Also addsAckSubscriptioninterface for at-least-once delivery semantics in cross-process buses.TokenUsageenriched withModel,LatencyMs,CostMicrosfields so sandbox hosts can enforce dollar-denominated budgets without a separate sidecar.Test plan
make cipasses on all in-tree modulescapabilities_test.go,middleware_test.go,interrupt_test.gocover the new helpershost_test.gocovers the newUsageReportercontract🤖 Generated with Claude Code