Skip to content

feat(acp): session/usage reporting and doc(cfg) annotations#4522

Merged
bug-ops merged 2 commits into
mainfrom
acp-session-usage
May 28, 2026
Merged

feat(acp): session/usage reporting and doc(cfg) annotations#4522
bug-ops merged 2 commits into
mainfrom
acp-session-usage

Conversation

@bug-ops
Copy link
Copy Markdown
Owner

@bug-ops bug-ops commented May 28, 2026

Summary

Changes

zeph-core (channel.rs, metrics_compact.rs):

  • LoopbackEvent::Usage extended with cache_read_tokens, cache_write_tokens, cost_cents
  • Channel::send_usage trait updated with the three new parameters (all call-sites updated)
  • emit_usage_event() helper consolidates usage emission after each LLM call

zeph-acp (agent/mod.rs, agent/helpers.rs, transport/http.rs, transport/router.rs):

  • TurnUsage accumulates per-call token counts within a single prompt turn
  • SessionUsageAccumulator tracks session-lifetime totals; last_cost_cents and last_context_window use overwrite semantics (not summation) because CostTracker already provides cumulative values
  • drain_agent_events dual-accumulates: per-turn for PromptResponse.usage, session-lifetime for the close summary
  • build_prompt_response attaches acp::schema::Usage; thought_tokens = None (unsupported providers)
  • do_close_session sends cumulative UsageUpdate before removing the session entry from the map
  • All feature-gated pub items now carry #[cfg_attr(docsrs, doc(cfg(...)))]

zeph-gateway (server.rs): with_metrics_registry annotated with doc(cfg(feature = "prometheus"))

Test plan

  • cargo +nightly fmt --check — clean
  • cargo clippy --workspace -- -D warnings — clean
  • cargo 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 — clean
  • RUSTDOCFLAGS="--deny rustdoc::broken_intra_doc_links" cargo doc --no-deps --all-features -p zeph-acp — clean
  • RUSTDOCFLAGS="--deny rustdoc::broken_intra_doc_links" cargo doc --no-deps --all-features -p zeph-gateway — clean
  • New unit tests: session_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_attaches

Notes

  • do_delete_session and the idle reaper intentionally do not send a usage summary — session/close is the canonical path (documented with inline comments)
  • Cost exposure to IDE clients is gated behind unstable-session-usage; a session_usage.expose_cost config knob is tracked as a pre-GA concern (SECURITY-1 from audit)

Closes #4457
Closes #4497

@github-actions github-actions Bot added documentation Improvements or additions to documentation channels zeph-channels crate (Telegram) rust Rust code changes core zeph-core crate enhancement New feature or request size/L Large PR (201-500 lines) labels May 28, 2026
…#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.
@bug-ops bug-ops force-pushed the acp-session-usage branch from f081cf4 to a64dc4d Compare May 28, 2026 15:21
@bug-ops bug-ops enabled auto-merge (squash) May 28, 2026 15:32
@bug-ops bug-ops merged commit 39229a9 into main May 28, 2026
32 checks passed
@bug-ops bug-ops deleted the acp-session-usage branch May 28, 2026 15:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channels zeph-channels crate (Telegram) core zeph-core crate documentation Improvements or additions to documentation enhancement New feature or request rust Rust code changes size/L Large PR (201-500 lines)

Projects

None yet

1 participant