mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-05-14 22:02:59 -07:00
4810e7794b
This PR implements several critical improvements to repository health monitoring and automated triage workflows. ### Summary of Changes 1. **Backlog Age Metric**: Added `tools/gemini-cli-bot/metrics/scripts/backlog_age.ts` to measure the median and P90 age of open issues and PRs. This addresses the "Survivorship Bias" in current latency metrics, which only sample recently closed items. 2. **Metrics Persistence**: Fixed a bug in `tools/gemini-cli-bot/metrics/index.ts` that limited the timeseries history to 100 lines (effectively ~2 runs). Increased to 5000 lines to preserve historical trends. 3. **Robust Stale Closer**: Upgraded `.github/workflows/gemini-scheduled-stale-issue-closer.yml` to a 2-phase system (Mark as Stale -> Close). This centralized logic replaces the throttled default stale action and includes robust human activity detection. 4. **Triage Bug Fix**: Fixed a critical bug in `.github/workflows/unassign-inactive-assignees.yml` where a missing `for` loop caused the script to fail. 5. **Policy Consolidation**: Disabled issue staleness in `.github/workflows/stale.yml` to avoid conflicts with the new custom 2-phase closer. ### Why this is recommended - **Data-Driven Triage**: Without backlog age metrics, we were blind to the "Slow Path" backlog that is growing despite fast "recently closed" latency. - **Automated Hygiene**: The broken and throttled triage workflows were allowing the backlog to grow unchecked (now at 2351 issues). These fixes restore automated pruning. - **Metrics Reliability**: Expanding the timeseries window ensures that deltas and trends are calculated against stable historical data. ### Impact - **Backlog Visibility**: New metrics will show the real age of open items. - **Throughput**: Increased stale closer throughput will begin reducing the 2300+ issue backlog. - **Reliability**: Automated unassignment of inactive contributors will keep "help wanted" items moving.
66 lines
2.1 KiB
TypeScript
66 lines
2.1 KiB
TypeScript
/**
|
|
* @license
|
|
* Copyright 2026 Google LLC
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
import { GITHUB_OWNER, GITHUB_REPO } from '../types.js';
|
|
import { execSync } from 'node:child_process';
|
|
|
|
try {
|
|
// Query for the 100 oldest open issues and 100 oldest open PRs
|
|
const query = `
|
|
query($owner: String!, $repo: String!) {
|
|
repository(owner: $owner, name: $repo) {
|
|
issues(first: 100, states: OPEN, orderBy: {field: CREATED_AT, direction: ASC}) {
|
|
nodes {
|
|
createdAt
|
|
}
|
|
}
|
|
pullRequests(first: 100, states: OPEN, orderBy: {field: CREATED_AT, direction: ASC}) {
|
|
nodes {
|
|
createdAt
|
|
}
|
|
}
|
|
}
|
|
}
|
|
`;
|
|
const output = execSync(
|
|
`gh api graphql -F owner=${GITHUB_OWNER} -F repo=${GITHUB_REPO} -f query='${query}'`,
|
|
{ encoding: 'utf-8' },
|
|
);
|
|
const data = JSON.parse(output).data.repository;
|
|
|
|
const now = Date.now();
|
|
|
|
const calculateAges = (nodes: { createdAt: string }[]) => {
|
|
return nodes.map((node) => (now - new Date(node.createdAt).getTime()) / (1000 * 60 * 60 * 24)); // Age in days
|
|
};
|
|
|
|
const issueAges = calculateAges(data.issues.nodes);
|
|
const prAges = calculateAges(data.pullRequests.nodes);
|
|
|
|
const getMedian = (ages: number[]) => {
|
|
if (ages.length === 0) return 0;
|
|
const sorted = [...ages].sort((a, b) => a - b);
|
|
const mid = Math.floor(sorted.length / 2);
|
|
return sorted.length % 2 !== 0 ? sorted[mid] : (sorted[mid - 1] + sorted[mid]) / 2;
|
|
};
|
|
|
|
const getP90 = (ages: number[]) => {
|
|
if (ages.length === 0) return 0;
|
|
const sorted = [...ages].sort((a, b) => a - b);
|
|
const index = Math.floor(sorted.length * 0.9);
|
|
return sorted[index];
|
|
};
|
|
|
|
process.stdout.write(`backlog_issue_median_age_days,${Math.round(getMedian(issueAges))}\n`);
|
|
process.stdout.write(`backlog_issue_p90_age_days,${Math.round(getP90(issueAges))}\n`);
|
|
process.stdout.write(`backlog_pr_median_age_days,${Math.round(getMedian(prAges))}\n`);
|
|
process.stdout.write(`backlog_pr_p90_age_days,${Math.round(getP90(prAges))}\n`);
|
|
|
|
} catch (err) {
|
|
process.stderr.write(err instanceof Error ? err.message : String(err));
|
|
process.exit(1);
|
|
}
|