Skip to content

[runtime][plan][python] Add built-in operational metrics - #955

Open
joeyutong wants to merge 3 commits into
apache:mainfrom
joeyutong:codex/agent-operational-metrics-pr
Open

[runtime][plan][python] Add built-in operational metrics#955
joeyutong wants to merge 3 commits into
apache:mainfrom
joeyutong:codex/agent-operational-metrics-pr

Conversation

@joeyutong

@joeyutong joeyutong commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator

What changed

This PR implements the built-in operational metrics proposed in Discussion #901.

It builds on the execution lifecycle and trace context introduced by the merged #924. Metrics and Event Log recording consume the same in-process execution events independently; metrics are not derived by reading the Event Log.

Runtime lifecycle integration

  • ActionExecutionOperator records input queue, input-run, Action task, and Action execution boundaries at the points where they occur.
  • OperatorStateManager exposes pending Action state for restoring current-count gauges after task recovery.
  • BuiltInMetrics is the central dispatcher. Action lifecycle events feed Action metrics, while LLM and Tool lifecycle events feed execution-entity metrics.

Metric implementations

  • BuiltInInputRunMetrics records run outcomes, end-to-end, queue, and processing latency, pending input Events, and active input runs.
  • BuiltInActionMetrics records scheduling and logical execution latency, pending Action tasks, and active Action executions.
  • BuiltInExecutionMetrics pairs execution start and terminal events by execution id, then dispatches by entity type.
  • LlmExecutionMetricRecorder records model-resource success, failure, and latency.
  • ToolExecutionMetricRecorder records Tool metrics and projects explicit Skill and MCP Server metadata into independent scopes.
  • Current-count gauges are rebuilt from Flink state after restore. Historical latency and outcome samples that began in a previous task attempt are intentionally not reconstructed.

Tool outcomes retain the existing language-specific contracts. Java maps an unsuccessful ToolResponse to failure. Python maps resource preparation and invocation exceptions to failure, while a normal arbitrary return remains successful because Python currently has no explicit error-result type. Strict alignment is tracked in #956 and is planned after the parallel Tool-call work in #926. This PR retains the Tool and MCP outcome counters and does not infer failure from arbitrary return payloads.

Java and Python ChatModel paths

  • Each framework-observed ChatModel invocation emits its own LLM execution outcome and latency sample, including retry attempts.
  • Retry count and wait time are recorded under the configured model_resource in both Java and Python, including final-failure and IGNORE paths.
  • With Java model routing, retry metrics are attributed to the concrete candidate ChatModel resource used by each attempt.
  • Existing request-scoped token metrics remain under the provider model scope.

Metric scope and documentation

  • The Agent name is used as the Flink operator name, with the existing operator name retained as a fallback.
  • The monitoring documentation lists the new scopes, metric types, lifecycle boundaries, retry semantics, recovery limitations, and current Tool outcome mapping.
  • The configuration reference now describes retry metrics under the configured ChatModel resource rather than the underlying connection.

Validation

  • mvn -T4 -B --no-transfer-progress spotless:check
  • mvn -B --no-transfer-progress -pl plan,runtime -am -DskipITs -Dtest=ChatModelActionRetryTest,ChatModelActionRoutingTest,CompileUtilsTest,BuiltInActionMetricsTest,BuiltInExecutionMetricsTest,BuiltInInputRunMetricsTest,ActionExecutionOperatorTest -Dsurefire.failIfNoSpecifiedTests=false test
    • Plan: 27 tests passed
    • Runtime: 67 tests passed
  • From python/: pytest -q flink_agents/plan/tests/actions/test_chat_model_action_retry.py flink_agents/api/tests/test_execution_reporter.py flink_agents/runtime/tests/test_flink_runner_context_trace.py
    • Python: 14 tests passed
  • From python/: ruff check flink_agents/plan/actions/chat_model_action.py flink_agents/plan/tests/actions/test_chat_model_action_retry.py

Related work

@github-actions github-actions Bot added doc-label-missing The Bot applies this label either because none or multiple labels were provided. fixVersion/0.4.0 priority/major Default priority of the PR or issue. labels Aug 3, 2026
@joeyutong
joeyutong force-pushed the codex/agent-operational-metrics-pr branch from faddd6f to 934c1ce Compare August 3, 2026 11:33
@github-actions github-actions Bot added doc-label-missing The Bot applies this label either because none or multiple labels were provided. and removed doc-label-missing The Bot applies this label either because none or multiple labels were provided. labels Aug 3, 2026
@joeyutong
joeyutong force-pushed the codex/agent-operational-metrics-pr branch from 6bfa5f7 to cf250fa Compare August 4, 2026 03:07
@joeyutong
joeyutong force-pushed the codex/agent-operational-metrics-pr branch 2 times, most recently from d056238 to 1715c67 Compare August 11, 2026 16:08
joeyutong and others added 3 commits August 23, 2026 20:19
Derive input-run, Action, LLM, Tool, Skill, and MCP metrics from runtime lifecycle boundaries. Rebuild current-count gauges from Flink state and align Java and Python retry metrics under the model resource scope.

Co-Authored-By: Claude Code <noreply@anthropic.com>
AI-Model: gpt-5
AI-Contributed/Feature: 1214/1214
AI-Contributed/UT: 653/653
Document the current Java and Python Tool result mappings, align the retry configuration reference with the model resource scope, and link the follow-up alignment work.

Co-Authored-By: Claude Code <noreply@anthropic.com>
AI-Model: gpt-5
AI-Contributed/Feature: 4/4
AI-Contributed/UT: 0/0
Use the test Agent name when validating the operator metric scope.

Co-Authored-By: Claude Code <noreply@anthropic.com>
AI-Model: gpt-5
AI-Contributed/Feature: 0/0
AI-Contributed/UT: 8/8
@joeyutong
joeyutong force-pushed the codex/agent-operational-metrics-pr branch from 1715c67 to 806fdc9 Compare August 23, 2026 12:20
@github-actions github-actions Bot added doc-label-missing The Bot applies this label either because none or multiple labels were provided. and removed doc-label-missing The Bot applies this label either because none or multiple labels were provided. labels Aug 23, 2026
@joeyutong
joeyutong marked this pull request as ready for review August 23, 2026 12:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

doc-label-missing The Bot applies this label either because none or multiple labels were provided. fixVersion/0.4.0 priority/major Default priority of the PR or issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant