Skip to content

Publish live budget, token, turn and cache figures in telemetry #244

Closed

Description

@lbacik

Parent

Agent-side change from the map Agent fleet dashboard: map; the consolidated list is in the resolution of Define the dashboard project. The snapshot shape is decided in Define the telemetry snapshot contract and the command mechanics in Decide the agentctl telemetry command. Terms: Telemetry snapshot and Figure basis in CONTEXT.md; ADR 0006.

What to build

During model execution, telemetry shows the current attempt's budget, token, turn and cache figures as they change, each tagged with its figure basis. When model execution ends they freeze at their final values.

Acceptance criteria

  • The executor receives an injected publisher (like its event log) and publishes an immutable attempt view after every limit check. Publishing is a reference swap under a lock held only for the swap. The listener thread never reads the token ledger.
  • budget.used (measured when its estimated part is 0, otherwise estimated), budget.measured, budget.estimated, budget.hard_ceiling_reached, and budget.soft_threshold with value (the effective threshold after the handoff reserve), rule (percentage or reserve), percentage, reserve_turns, crossed, crossed_at_tokens, crossed_at. The soft threshold is configured under percentage; under reserve it inherits the main context's basis.
  • tokens_by_category (input_tokens, cache_read_input_tokens, cache_creation_input_tokens, output_tokens; measured part only), turns (main-thread responses, measured), cache.main_hit_rate with counted (unavailable below the configured minimum of measured responses), elapsed_seconds (measured).
  • provider_rate_limit is always {value: null, basis: "unavailable", reason: "not exposed through the gateway"}. No USD figure is sent.
  • observed_at and sequence advance with every publication. After model execution ends, the view stays frozen at its final values until finalisation.
  • Tests: figures and bases match the attempt-in-progress and soft-threshold-crossed contract examples' shape; a failing publish does not affect the attempt; frozen after execution.

Blocked by

Activity

  1. added
    ready-for-agentFully specified implementation issue ready for an unattended agent
    on Oct 14, 2026
  2. self-assigned this
    on Oct 14, 2026
  3. lbacik commented on Oct 14, 2026

    @lbacik
    OwnerAuthor

    Agent Attempt Result: handoff

    Branch: agent/issue-244
    PR: none
    Handoff note commit: b1980f444ae4e69e48cf8a3dbb532f1ed8f513f5

    Evidence

    • Check command: UV_PROJECT_ENVIRONMENT=/home/agent/venv-py311 uv run --python 3.11 --extra dev ruff check && UV_PROJECT_ENVIRONMENT=/home/agent/venv-py311 uv run --python 3.11 --extra dev pytest && UV_PROJECT_ENVIRONMENT=/home/agent/venv-py313 uv run --python 3.13 --extra dev pytest → exit code None
    • Reviews performed: 1
    • Review repair cycles: 0/2
    • Review findings: not collected

    Details

    Handoff note: issue #244

    • issue: 244
    • started_at: 2026-10-14T14:12:55.198389Z
    • reason: token_soft_threshold
    • last_work_commit: 24d85f3

    Summary

    Implemented live attempt-figure publication for telemetry (issue #244, "publish the attempt's budget/token/turn/cache figures as they change"). All code changes are written but uncommitted (sealing will commit them):

    • simple_coding_agent/token_ledger.py: added main_measured_response_count and main_context_basis() (measured when the main thread's latest response reported usage, else estimated).
    • simple_coding_agent/telemetry.py: TelemetryReporter.publish_attempt_view() stamps observed_at and swaps the stored view under _attempt_view_lock (held only for the swap); _build_current_attempt serves the published view merged with the claim seed (full shape: budget used/measured/estimated + hard ceiling + soft threshold with rule/percentage/reserve_turns/crossed/crossed_at_tokens/crossed_at, tokens_by_category, turns, cache.main_hit_rate with counted, elapsed, provider_rate_limit, no USD). Without a published view it keeps the old tracer shape. begin_attempt/finish_attempt clear the view.
    • simple_coding_agent/model_execution.py: ModelExecutor takes injected attempt_publisher (ctor param + set_attempt_publisher, like event_log), publishes an immutable MappingProxyType view at the end of every _check_limits, records soft-threshold crossing wall-time, logs telemetry_publish_failed without affecting the attempt on publisher failure.
    • simple_coding_agent/lifecycle.py: _wire_attempt_telemetry_publisher() wires reporter.publish_attempt_view into the executor before dispatch; called alongside _wire_attempt_runner_handoff().
    • tests/test_telemetry_live_figures.py (new, 13 tests): example-shape conformance for attempt-in-progress and soft-threshold-crossed, used-basis rule, hit-rate unavailability below minimum, observed_at/sequence advance, immutable per-check publication, failing-publish safety, frozen-after-execution, detached listener copy, begin/finish clearing, ledger helpers, lifecycle wiring.

    Remaining work

    1. Invoke the code-review skill on the changes (required by the completion gate; an attempt with commits but no code-review invocation counts as incomplete).
    2. Run the completion gate in order: ruff check, full pytest on Python 3.12, full pytest on Python 3.13 (env vars redacted in the issue; PATH/HOME/UV_PYTHON_INSTALL_DIR/UV_PYTHON_DOWNLOADS/UV_NO_PROGRESS are set by the gate).
    3. Address any review/gate findings, then commit to agent/issue-244.

    Evidence

    • New tests: UV_PROJECT_ENVIRONMENT=/tmp/venv-py3-check uv run --python 3.12 --extra dev pytest tests/test_telemetry_live_figures.py → 13 passed.
    • Related suites (test_telemetry, test_telemetry_examples, test_model_execution, test_prompt_cache, test_lifecycle) → 206 passed.
    • Full suite on 3.12 → 1099 passed, 10 skipped (one pre-existing PytestUnhandledThreadExceptionWarning about recovery, unrelated).
    • ruff check → all checks passed.
    • NOT yet run: code-review skill, full pytest on Python 3.13, gate with the official env.

    Automatic continuation 0/2 used; the agent will continue automatically.

  4. added
    round-finishedAgent round finished; requires human evaluation to continue
    and removed
    ready-for-agentFully specified implementation issue ready for an unattended agent
    on Oct 14, 2026
  5. assigned and unassigned on Oct 14, 2026
  6. removed
    round-finishedAgent round finished; requires human evaluation to continue
    on Oct 14, 2026
  7. added 3 commits that reference this issue on Oct 14, 2026
  8. lbacik commented on Oct 14, 2026

    @lbacik
    OwnerAuthor

    Agent Attempt Result: complete

    Branch: agent/issue-244
    PR: #254
    Merge: auto-merge enabled (merge)

    Evidence

    • Check command: UV_PROJECT_ENVIRONMENT=/home/agent/venv-py311 uv run --python 3.11 --extra dev ruff check && UV_PROJECT_ENVIRONMENT=/home/agent/venv-py311 uv run --python 3.11 --extra dev pytest && UV_PROJECT_ENVIRONMENT=/home/agent/venv-py313 uv run --python 3.13 --extra dev pytest → exit code 0
    • Reviews performed: 1
    • Review repair cycles: 0/2
    • Review findings: not collected

    Details

    Claude SDK completed the implementation workflow.

  9. removed their assignment
    on Oct 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions