Repository navigation
ops: clean lag-index + SSOT + emoji fix onto master (supersedes dirty #156/#153) #178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c48a89e
ops: clean rebase of lag-index + SSOT + emoji fix onto master (#156/#…
timerloggedout-spec c9d71dc
ops: add scripts/ci/calculate_lag_index.py for dynamic continuous-ops…
timerloggedout-spec 27de230
fix(ci): emoji reaction for pull_request_review_comment events
timerloggedout-spec ec98f30
ops(lag-index): schema v2 disposition model — ACK != review (#174 pair)
timerloggedout-spec e163d85
docs(ops): lag disposition upgrade spec — ACK != review (#174 pair)
timerloggedout-spec File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| { | ||
| "global_averages": { | ||
| "avg_message_response_lag_sec": 2700, | ||
| "avg_actual_response_lag_sec": 7200, | ||
| "suggested_debounce_ms": 2700000, | ||
| "suggested_stale_ms": 7200000 | ||
| }, | ||
| "by_pr": {}, | ||
| "note": "Defaults aligned with high-perf continuous-ops on master (45m debounce / 2h stale). Recalculated by scripts/ci/calculate_lag_index.py on cron." | ||
|
timerloggedout-spec marked this conversation as resolved.
Resolved
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,220 @@ | ||
| #!/usr/bin/env python3 | ||
| """Compute response-time lag index for continuous-ops dynamic debounce/stale windows. | ||
| Fixes #155. Soft-fails without token (writes fallback JSON + SSOT table section). | ||
| """ | ||
| from __future__ import annotations | ||
|
|
||
| import json | ||
| import os | ||
| import sys | ||
| import urllib.error | ||
| import urllib.request | ||
| from datetime import datetime | ||
|
|
||
| DEFAULT_DEBOUNCE_SEC = 45 * 60 | ||
| DEFAULT_STALE_SEC = 2 * 60 * 60 | ||
|
|
||
| def github_api_request(url: str, token: str | None): | ||
| req = urllib.request.Request(url) | ||
| req.add_header("User-Agent", "termux-monorepo-lag-index") | ||
| req.add_header("Accept", "application/vnd.github.v3+json") | ||
| if token: | ||
| req.add_header("Authorization", f"token {token}") | ||
| try: | ||
| with urllib.request.urlopen(req, timeout=30) as response: | ||
| return json.loads(response.read().decode("utf-8")) | ||
| except Exception as e: | ||
| print(f"API Error for {url}: {e}", file=sys.stderr) | ||
| return None | ||
|
|
||
| def parse_iso8601(ts_str: str | None): | ||
| if not ts_str: | ||
| return None | ||
| try: | ||
| return datetime.strptime(ts_str.replace("Z", ""), "%Y-%m-%dT%H:%M:%S") | ||
| except ValueError: | ||
| return None | ||
|
timerloggedout-spec marked this conversation as resolved.
Resolved
|
||
|
|
||
| def write_outputs(metrics: dict, table_rows: list[str]) -> None: | ||
| os.makedirs("docs/ops", exist_ok=True) | ||
| with open("docs/ops/response_time_lag_index.json", "w", encoding="utf-8") as f: | ||
| json.dump(metrics, f, indent=2) | ||
| f.write("\n") | ||
| print("docs/ops/response_time_lag_index.json written") | ||
|
timerloggedout-spec marked this conversation as resolved.
Resolved
|
||
|
|
||
| ssot_path = "docs/ops/LANE_CONSOLIDATION_SSOT.md" | ||
| marker = "\n## Current Work & Dynamic Response Lags\n" | ||
| g = metrics["global_averages"] | ||
| table = marker + "\n" | ||
| if table_rows: | ||
| table += "| PR/Issue | Message Response Lag | Programmatic Response Lag | State |\n|---|---|---|---|\n" | ||
| table += "\n".join(table_rows) + "\n" | ||
| else: | ||
| table += "*No summon events in recent history; defaults applied.*\n" | ||
| table += ( | ||
| f"\n### Calculated Global Averages\n" | ||
| f"- Message ack lag: {round(g['avg_message_response_lag_sec'] / 60, 1)} min\n" | ||
| f"- Programmatic lag: {round(g['avg_actual_response_lag_sec'] / 3600, 1)} h\n" | ||
| f"- Suggested debounce: {round(g['suggested_debounce_ms'] / 60000, 1)} min\n" | ||
| f"- Suggested stale: {round(g['suggested_stale_ms'] / 3600000, 1)} h\n" | ||
| ) | ||
| if os.path.exists(ssot_path): | ||
| text = open(ssot_path, encoding="utf-8").read() | ||
| if marker.strip() in text: | ||
| idx = text.find(marker.strip()) | ||
| if idx >= 0: | ||
| pre = text[:idx].rstrip() | ||
| text = pre + "\n" + table | ||
|
timerloggedout-spec marked this conversation as resolved.
Resolved
|
||
| else: | ||
| text = text.rstrip() + "\n" + table | ||
| else: | ||
| text = text.rstrip() + "\n" + table | ||
| open(ssot_path, "w", encoding="utf-8").write(text) | ||
|
timerloggedout-spec marked this conversation as resolved.
Resolved
|
||
| print(f"{ssot_path} updated with lag table") | ||
| else: | ||
| open(ssot_path, "w", encoding="utf-8").write("# Lane Consolidation SSOT\n" + table) | ||
|
|
||
| def main() -> None: | ||
| token = ( | ||
| os.environ.get("OPERATOR_GITHUB_TOKEN") | ||
| or os.environ.get("OPERATOR_TOKEN") | ||
| or os.environ.get("GITHUB_TOKEN") | ||
| ) | ||
| repo = os.environ.get("GITHUB_REPOSITORY") or "timerloggedout-spec/termux-monorepo" | ||
| metrics = { | ||
| "global_averages": { | ||
| "avg_message_response_lag_sec": DEFAULT_DEBOUNCE_SEC, | ||
| "avg_actual_response_lag_sec": DEFAULT_STALE_SEC, | ||
| "suggested_debounce_ms": DEFAULT_DEBOUNCE_SEC * 1000, | ||
| "suggested_stale_ms": DEFAULT_STALE_SEC * 1000, | ||
| }, | ||
| "by_pr": {}, | ||
| } | ||
|
timerloggedout-spec marked this conversation as resolved.
Resolved
|
||
| table_rows: list[str] = [] | ||
|
|
||
| if not token: | ||
| print("No token; writing fallback lag index", file=sys.stderr) | ||
| write_outputs(metrics, table_rows) | ||
| return | ||
|
|
||
| open_prs = github_api_request( | ||
| f"https://api.github.com/repos/{repo}/pulls?state=open&per_page=30", token | ||
| ) or [] | ||
| closed_prs = github_api_request( | ||
| f"https://api.github.com/repos/{repo}/pulls?state=closed&per_page=20", token | ||
| ) or [] | ||
| all_prs = open_prs + closed_prs | ||
| all_message_lags: list[float] = [] | ||
| all_actual_lags: list[float] = [] | ||
| agent_logins = [ | ||
| "google-labs-jules", | ||
| "devin-ai-integration", | ||
| "coderabbitai", | ||
| "github-actions", | ||
| "copilot", | ||
| "gitar-bot", | ||
| "blocksorg", | ||
| ] | ||
|
|
||
| def is_agent(username: str) -> bool: | ||
| u = (username or "").lower() | ||
| return any(a in u for a in agent_logins) | ||
|
|
||
| for pr in all_prs: | ||
| pr_number = pr["number"] | ||
| comments = github_api_request( | ||
| f"https://api.github.com/repos/{repo}/issues/{pr_number}/comments?per_page=100", | ||
| token, | ||
| ) or [] | ||
| commits = github_api_request( | ||
| f"https://api.github.com/repos/{repo}/pulls/{pr_number}/commits?per_page=100", | ||
| token, | ||
| ) or [] | ||
|
timerloggedout-spec marked this conversation as resolved.
Resolved
timerloggedout-spec marked this conversation as resolved.
Resolved
timerloggedout-spec marked this conversation as resolved.
Resolved
|
||
| timeline = [] | ||
| for c in comments: | ||
| t = parse_iso8601(c.get("created_at")) | ||
| if t: | ||
| timeline.append( | ||
| { | ||
| "type": "comment", | ||
| "user": (c.get("user") or {}).get("login") or "unknown", | ||
| "body": c.get("body") or "", | ||
| "time": t, | ||
| } | ||
| ) | ||
| for commit in commits: | ||
| meta = commit.get("commit") or {} | ||
| committer = meta.get("committer") or meta.get("author") or {} | ||
| t = parse_iso8601(committer.get("date")) | ||
| if t: | ||
| timeline.append({"type": "commit", "user": "unknown", "time": t}) | ||
|
timerloggedout-spec marked this conversation as resolved.
Resolved
|
||
| timeline.sort(key=lambda x: x["time"]) | ||
|
|
||
| summon_time = None | ||
| pr_message_lags: list[float] = [] | ||
| pr_actual_lags: list[float] = [] | ||
| actual_response_time = None | ||
| message_response_time = None | ||
|
|
||
| for event in timeline: | ||
| if event["type"] == "comment": | ||
| body = event["body"] | ||
| is_summon = any( | ||
| m in body | ||
| for m in ( | ||
| "<!-- continuous-agent-ops -->", | ||
| "<!-- agent-auto-jules -->", | ||
| "@jules", | ||
| "@gemini-cli", | ||
| ) | ||
| ) | ||
| if is_summon: | ||
| summon_time = event["time"] | ||
| message_response_time = None | ||
| actual_response_time = None | ||
| continue | ||
| if summon_time and not message_response_time and is_agent(event["user"]): | ||
| message_response_time = event["time"] | ||
| lag = (message_response_time - summon_time).total_seconds() | ||
| pr_message_lags.append(lag) | ||
| all_message_lags.append(lag) | ||
| elif event["type"] == "commit" and summon_time and not actual_response_time: | ||
| actual_response_time = event["time"] | ||
| lag = (actual_response_time - summon_time).total_seconds() | ||
| pr_actual_lags.append(lag) | ||
| all_actual_lags.append(lag) | ||
|
|
||
| pr_avg_msg = sum(pr_message_lags) / len(pr_message_lags) if pr_message_lags else None | ||
| pr_avg_act = sum(pr_actual_lags) / len(pr_actual_lags) if pr_actual_lags else None | ||
| if pr_avg_msg is not None or pr_avg_act is not None: | ||
| suggested_debounce = max(30 * 60, (pr_avg_msg or DEFAULT_DEBOUNCE_SEC) * 1.5) | ||
| suggested_stale = max(60 * 60, (pr_avg_act or DEFAULT_STALE_SEC) * 1.5) | ||
| metrics["by_pr"][str(pr_number)] = { | ||
| "avg_message_response_lag_sec": pr_avg_msg, | ||
| "avg_actual_response_lag_sec": pr_avg_act, | ||
| "suggested_debounce_ms": int(suggested_debounce * 1000), | ||
| "suggested_stale_ms": int(suggested_stale * 1000), | ||
| } | ||
| msg_lag_str = f"{round(pr_avg_msg / 60, 1)} min" if pr_avg_msg else "N/A" | ||
| act_lag_str = f"{round(pr_avg_act / 3600, 1)} hrs" if pr_avg_act else "N/A" | ||
|
timerloggedout-spec marked this conversation as resolved.
Resolved
|
||
| table_rows.append( | ||
| f"| PR #{pr_number} | {msg_lag_str} | {act_lag_str} | {pr['state'].upper()} |" | ||
| ) | ||
|
|
||
| if all_message_lags: | ||
| avg_msg = sum(all_message_lags) / len(all_message_lags) | ||
| metrics["global_averages"]["avg_message_response_lag_sec"] = avg_msg | ||
| metrics["global_averages"]["suggested_debounce_ms"] = int( | ||
| max(30 * 60, avg_msg * 1.5) * 1000 | ||
| ) | ||
| if all_actual_lags: | ||
| avg_act = sum(all_actual_lags) / len(all_actual_lags) | ||
| metrics["global_averages"]["avg_actual_response_lag_sec"] = avg_act | ||
| metrics["global_averages"]["suggested_stale_ms"] = int( | ||
| max(60 * 60, avg_act * 1.5) * 1000 | ||
| ) | ||
|
|
||
| write_outputs(metrics, table_rows) | ||
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.