Skip to content

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

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

[runtime][plan][python] Add built-in operational metrics#955
joeyutong wants to merge 11 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 depends on #924, which introduces the execution lifecycle and trace context consumed by these metrics. The PR is opened as a draft and will be rebased onto main after #924 is merged. Until then, the Metrics-only diff is available in this branch comparison.

Runtime lifecycle integration

  • ActionExecutionOperator records input queue, input-run, Action task, and Action execution boundaries at the points where they actually 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. Event Log writing and metric aggregation consume the same in-process execution event independently.

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 their own 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 model_resource scope in both Java and Python, including final-failure and IGNORE paths.
  • Existing token metrics remain under the 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.

Validation

  • mvn -T4 -B --no-transfer-progress spotless:check
  • mvn -B --no-transfer-progress -pl plan,runtime -am -DskipITs -Dtest=ChatModelActionRetryTest,CompileUtilsTest,BuiltInActionMetricsTest,BuiltInExecutionMetricsTest,BuiltInInputRunMetricsTest,ActionExecutionOperatorTest -Dsurefire.failIfNoSpecifiedTests=false test
    • Plan: 11 tests passed
    • Runtime: 57 tests passed
  • uv run ruff check flink_agents/plan/actions/chat_model_action.py flink_agents/plan/tests/actions/test_chat_model_action_retry.py
  • python -m pytest -q flink_agents/plan/tests/actions/test_chat_model_action_retry.py
    • Python: 9 tests passed

Related work

汤雨 added 9 commits July 24, 2026 10:22
Treat eventAttributes as the payload root and document durable replay limitations.

Co-Authored-By: Codex <noreply@openai.com>

AI-Model: gpt-5
AI-Contributed/Feature: 59/59
AI-Contributed/UT: 28/28
Report raw Action errors as failed and emit successful Action completion before processing emitted Events.

Co-Authored-By: Codex <noreply@openai.com>

AI-Model: gpt-5
AI-Contributed/Feature: 3/3
AI-Contributed/UT: 0/0
Keep Event Log writes best-effort while exposing failures through a counter and a first-failure warning. Attempt flush independently after append failures and surface PrintWriter I/O errors.

Co-Authored-By: Codex <noreply@openai.com>

AI-Model: gpt-5
AI-Contributed/Feature: 57/57
AI-Contributed/UT: 43/43
Document execution lifecycle event level overrides, the flat Event Log field migration, and Python per-occurrence Event IDs.

Co-Authored-By: Codex <noreply@openai.com>

AI-Model: gpt-5
AI-Contributed/Feature: 11/11
AI-Contributed/UT: 0/0
Follow only explicitly chained Python causes so failure attribution matches Java Throwable.getCause semantics.

Co-Authored-By: Codex <noreply@openai.com>

AI-Model: gpt-5
AI-Contributed/Feature: 2/2
AI-Contributed/UT: 29/29
Assert that STANDARD payload truncation leaves the top-level Event ID unchanged.

Co-Authored-By: Codex <noreply@openai.com>

AI-Model: gpt-5
AI-Contributed/Feature: 0/0
AI-Contributed/UT: 4/4
@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
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: Codex <noreply@openai.com>

AI-Model: gpt-5
AI-Contributed/Feature: 2/2
AI-Contributed/UT: 0/0
@joeyutong
joeyutong force-pushed the codex/agent-operational-metrics-pr branch from faddd6f to 934c1ce Compare August 3, 2026 11:33
Document the current Java and Python Tool result mappings and link the follow-up alignment work.

Co-Authored-By: Codex <noreply@openai.com>

AI-Model: gpt-5
AI-Contributed/Feature: 2/2
AI-Contributed/UT: 0/0
@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
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