feat(acp): session/usage reporting and doc(cfg) annotations#4522
Merged
Conversation
…#4457, #4497) Add session/usage ACP message support (feature: unstable-session-usage): - Extend LoopbackEvent::Usage with cache_read_tokens, cache_write_tokens, cost_cents - Add emit_usage_event() helper in metrics_compact.rs - Add TurnUsage, SessionUsageAccumulator, DrainResult to zeph-acp agent - drain_agent_events dual-accumulates: per-turn for PromptResponse.usage, session-lifetime for session/close summary - build_prompt_response attaches acp::schema::Usage; thought_tokens = None (unsupported) - do_close_session sends cumulative UsageUpdate before removing session entry - cost_cents uses overwrite semantics (cumulative value from CostTracker, not summation) - Unit tests: session_accumulator_sums_tokens_and_overwrites_cost_and_context_window, build_prompt_response_attaches_usage Add doc(cfg) annotations to all feature-gated pub items in zeph-acp and zeph-gateway: SessionSummary, SessionEventDto, HealthStatus, AcpHttpState, acp_router, SendAgentSpawner, with_unstable_providers, with_provider_names, with_metrics_registry Update Channel::send_usage trait and all implementations (AppChannel, GatewayChannel, any.rs, json_cli.rs, bench) with new cache/cost parameters.
f081cf4 to
a64dc4d
Compare
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
session/usageACP message (feat(acp): implement Session Usage reporting (token/cost via ACP) #4457) — wires existing cost/token metrics into per-turnUsageUpdatenotifications and session-close cumulative summary, feature-gated behindunstable-session-usage#[cfg_attr(docsrs, doc(cfg(...)))]annotations to all feature-gated pub items inzeph-acpandzeph-gateway(zeph-acp: feature-gated pub types missing #[cfg_attr(docsrs, doc(cfg(...)))] annotations #4497)Changes
zeph-core (
channel.rs,metrics_compact.rs):LoopbackEvent::Usageextended withcache_read_tokens,cache_write_tokens,cost_centsChannel::send_usagetrait updated with the three new parameters (all call-sites updated)emit_usage_event()helper consolidates usage emission after each LLM callzeph-acp (
agent/mod.rs,agent/helpers.rs,transport/http.rs,transport/router.rs):TurnUsageaccumulates per-call token counts within a single prompt turnSessionUsageAccumulatortracks session-lifetime totals;last_cost_centsandlast_context_windowuse overwrite semantics (not summation) becauseCostTrackeralready provides cumulative valuesdrain_agent_eventsdual-accumulates: per-turn forPromptResponse.usage, session-lifetime for the close summarybuild_prompt_responseattachesacp::schema::Usage;thought_tokens = None(unsupported providers)do_close_sessionsends cumulativeUsageUpdatebefore removing the session entry from the map#[cfg_attr(docsrs, doc(cfg(...)))]zeph-gateway (
server.rs):with_metrics_registryannotated withdoc(cfg(feature = "prometheus"))Test plan
cargo +nightly fmt --check— cleancargo clippy --workspace -- -D warnings— cleancargo nextest run --workspace --lib --bins— 10053 passed (+4 new tests)RUSTFLAGS="-D warnings" cargo check --workspace --all-targets --features desktop,ide,server,chat,pdf,scheduler --locked— cleanRUSTDOCFLAGS="--deny rustdoc::broken_intra_doc_links" cargo doc --no-deps --all-features -p zeph-acp— cleanRUSTDOCFLAGS="--deny rustdoc::broken_intra_doc_links" cargo doc --no-deps --all-features -p zeph-gateway— cleansession_accumulator_sums_tokens_and_overwrites_cost_and_context_window,session_accumulator_default_is_zero,build_prompt_response_attaches_usage,build_prompt_response_zero_usage_still_attachesNotes
do_delete_sessionand the idle reaper intentionally do not send a usage summary —session/closeis the canonical path (documented with inline comments)unstable-session-usage; asession_usage.expose_costconfig knob is tracked as a pre-GA concern (SECURITY-1 from audit)Closes #4457
Closes #4497