Skip to content

Commit d46b759

Browse files
Copilotpelikhan
andauthored
Fix Metrics Collector full-window coverage (#54356)
* Initial plan * Fix metrics collector full-window collection Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com> * Delete pkg/cli/metrics_collector_workflow_contract_test.go --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com> Co-authored-by: Peli de Halleux <pelikhan@users.noreply.github.com>
1 parent f2b47d4 commit d46b759

2 files changed

Lines changed: 76 additions & 21 deletions

File tree

.github/workflows/metrics-collector.lock.yml

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/workflows/metrics-collector.md

Lines changed: 71 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ tools:
2626
branch-name: memory/meta-orchestrators
2727
file-glob: "metrics/**"
2828
max-patch-size: 131072 # 128KB - handles large daily metrics snapshots without patch-size gate failures
29-
timeout-minutes: 15
29+
timeout-minutes: 30
3030
safe-outputs:
3131
noop:
3232

@@ -72,20 +72,25 @@ If you see any `.md` files at the root (e.g. `agent-performance-latest.md`, `sha
7272

7373
**Workflow Status and Runs**:
7474
- Use the `status` tool to get a list of all workflows in the repository
75-
- Use the `logs` tool to download workflow run data from the last 24 hours, **in small
76-
paginated batches** to avoid the tool timing out on large windows:
75+
- Use the `logs` tool to download workflow run data from the last 24 hours, **in bounded
76+
paginated batches** to cover the full window without a single long-running request:
7777
```
7878
Parameters (first call):
7979
- start_date: "-1d" (last 24 hours)
80-
- count: 20
80+
- count: 80
81+
- timeout: 3
8182
- Include all workflows (no workflow_name filter)
8283
```
8384
- **Pagination loop (required)**: the `logs` tool returns a `continuation` field when it stops
8485
early (timeout or count limit). While a `continuation` field is present in the returned data,
8586
issue another `logs` call using the parameters it provides (notably `before_run_id`, plus the
86-
original `start_date`) with `count: 20`, and accumulate the runs from every batch. Stop when
87-
either no `continuation` field is returned or you have made 10 batch calls (~200 runs), so the
88-
overall step stays within the workflow timeout.
87+
original `start_date`) with `count: 80` and `timeout: 3`, and accumulate the runs from every
88+
batch. Stop only when there is no `continuation` field **and** the oldest collected run is at or
89+
before the 24h window start. Do not stop after a fixed number of batches if the oldest collected
90+
run is still newer than the window start; that produces a partial ~10h snapshot.
91+
- If the logs tool continues returning `continuation` after the oldest collected run reaches the
92+
24h window start, stop paginating and ignore the remaining older cursor because the requested
93+
window is complete.
8994
- Never issue a single `logs` call with `count >= 100` for the full `-1d` window: that request
9095
has repeatedly exceeded the 60s tool timeout and yields truncated data.
9196
- From the logs data, extract for each workflow:
@@ -103,9 +108,16 @@ If you see any `.md` files at the root (e.g. `agent-performance-latest.md`, `sha
103108
- Comments added by workflows
104109
- Discussions created by workflows
105110
- Extract and count these for each workflow
106-
- **If the accumulated log batches still do not cover the full 24h window** (i.e. the last batch
107-
returned a `continuation` field or the oldest run collected is newer than 24h ago), do **not**
108-
report `safe_outputs` as zero. Instead compute safe-output counts from the GitHub API fallback
111+
- Extract typed safe-output counts as well:
112+
- `safe_outputs_by_type`: aggregate usage activity `safe_outputs.items_by_type` from each run
113+
(for example `create_issue`, `create_pull_request`, `add_comment`, `create_discussion`)
114+
- `safe_output_outcomes`: aggregate outcome fields from logs summaries and outcome reports:
115+
`accepted`, `rejected`, `ignored`, `pending`, `lifecycle`, and `lifecycle_close`
116+
- Never leave these fields absent; use empty objects/zero counts only when the full data source
117+
was checked and no matching items exist.
118+
- **If the accumulated log batches still do not cover the full 24h window** (i.e. the oldest run
119+
collected is newer than 24h ago), do **not** report `safe_outputs`, `safe_outputs_by_type`, or
120+
`safe_output_outcomes` as zero. Instead compute safe-output counts from the GitHub API fallback
109121
described below and mark the source accordingly.
110122

111123
**Safe Outputs Fallback (GitHub API)**:
@@ -119,9 +131,11 @@ API instead of zeroing them:
119131
- Comments added: `list_issues` / issue comment listing for issues updated in the window,
120132
counting comments authored by the agent app
121133
- Discussions created: `list_discussions` filtered by creation date in the window
122-
Attribute each result to a workflow via its `gh-aw-workflow-call-id` footer marker, aggregate the
123-
counts per workflow, and set `"safe_outputs_source": "github_api_fallback"` alongside a
124-
`collection_note` explaining the truncation. The same fallback applies to `engagement` fields.
134+
Attribute each result to a workflow and type via its `gh-aw-workflow-call-id` footer marker and
135+
item shape, aggregate the counts per workflow, and set `"safe_outputs_source":
136+
"github_api_fallback"` alongside a `collection_note` explaining the truncation. When API fallback
137+
cannot determine outcome status, set those items to `"pending"` rather than omitting the
138+
`safe_output_outcomes` breakdown. The same fallback applies to `engagement` fields.
125139

126140
**Additional Metrics via GitHub API**:
127141
- Use GitHub MCP server (default toolset) to supplement with:
@@ -142,6 +156,13 @@ Create a JSON object following this schema:
142156
{
143157
"timestamp": "2024-12-24T00:00:00Z",
144158
"period": "daily",
159+
"collection_status": "complete",
160+
"collection_window": {
161+
"start": "2024-12-23T00:00:00Z",
162+
"end": "2024-12-24T00:00:00Z",
163+
"coverage_hours": 24,
164+
"logs_batches": 6
165+
},
145166
"collection_duration_seconds": 45,
146167
"workflows": {
147168
"workflow-name": {
@@ -151,6 +172,20 @@ Create a JSON object following this schema:
151172
"comments_added": 10,
152173
"discussions_created": 1
153174
},
175+
"safe_outputs_by_type": {
176+
"create_issue": 5,
177+
"create_pull_request": 2,
178+
"add_comment": 10,
179+
"create_discussion": 1
180+
},
181+
"safe_output_outcomes": {
182+
"accepted": 9,
183+
"rejected": 1,
184+
"ignored": 2,
185+
"pending": 6,
186+
"lifecycle": 0,
187+
"lifecycle_close": 0
188+
},
154189
"workflow_runs": {
155190
"total": 7,
156191
"successful": 6,
@@ -176,6 +211,20 @@ Create a JSON object following this schema:
176211
"total_workflows": 120,
177212
"active_workflows": 85,
178213
"total_safe_outputs": 45,
214+
"safe_outputs_by_type": {
215+
"create_issue": 20,
216+
"create_pull_request": 8,
217+
"add_comment": 15,
218+
"create_discussion": 2
219+
},
220+
"safe_output_outcomes": {
221+
"accepted": 24,
222+
"rejected": 5,
223+
"ignored": 6,
224+
"pending": 10,
225+
"lifecycle": 0,
226+
"lifecycle_close": 0
227+
},
179228
"overall_success_rate": 0.892,
180229
"total_tokens": 1250000,
181230
"total_cost_usd": 12.50
@@ -258,9 +307,11 @@ find /tmp/gh-aw/repo-memory/default/metrics/daily/ -name "*.json" -mtime +30 -de
258307

259308
**Primary data source**: Use the agentic-workflows tool for all workflow run metrics:
260309
1. Start with `status` tool to get workflow inventory
261-
2. Use `logs` tool with `start_date: "-1d"` and `count: 20`, then follow the `continuation`
262-
field (using its `before_run_id`) for up to 10 batches to cover the full window
263-
3. Extract metrics from the accumulated log data (success/failure, tokens, costs, safe outputs)
310+
2. Use `logs` tool with `start_date: "-1d"`, `count: 80`, and `timeout: 3`, then follow the
311+
`continuation` field (using its `before_run_id`) until the oldest collected run reaches the
312+
24h window start
313+
3. Extract metrics from the accumulated log data (success/failure, tokens, costs, safe outputs,
314+
typed safe-output counts, and outcome breakdowns)
264315

265316
**Secondary data source**: Use GitHub MCP server for engagement metrics only:
266317
- Reactions on issues/PRs created by workflows
@@ -278,6 +329,10 @@ find /tmp/gh-aw/repo-memory/default/metrics/daily/ -name "*.json" -mtime +30 -de
278329
- If token/cost data is unavailable, omit or set to null
279330
- Always include workflows in the metrics even if they have no activity (helps detect stalled workflows)
280331
- **If the agentic-workflows `logs` tool is unavailable**, collect what you can from the GitHub API directly (workflow runs via `list_workflow_runs`) and set `"data_source": "github_api_fallback"` in the JSON
332+
- Set `"collection_status": "complete"` only when workflow run counts and safe-output breakdowns
333+
cover the full 24h window through logs data and/or the GitHub API fallback. Set
334+
`"collection_status": "partial"` only when both logs pagination and fallback collection fail to
335+
cover the window, and include a precise `collection_note` plus `collection_window.coverage_hours`.
281336
- **NEVER write a partial stub file like `{"date": "...", "status": "no-data"}`** — if you can't collect data, write a minimal valid metrics JSON with zeros instead:
282337
```json
283338
{

0 commit comments

Comments
 (0)