Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ results/
!/.github/signature-fixtures/basic_jobs.json
!perf/perf_baseline.json
!src/trend_analysis/export/manifest_schema.json
!tests/fixtures/keepalive/*.json
# Stop tracking noisy autofix history (now artifact-only)
ci/autofix/history.json
ci/autofix/diagnostics.json
Expand Down
5 changes: 3 additions & 2 deletions scripts/keepalive-runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,9 @@ async function runKeepalive({ core, github, context, env = process.env }) {
}

const latestCommandTs = new Date(commandComments[commandComments.length - 1].created_at).getTime();
if (latestCommandTs > lastAgentTs) {
core.info(`#${prNumber}: skipped – waiting for Codex response to the latest command.`);
const minutesSinceCommand = (now - latestCommandTs) / 60000;
if (latestCommandTs > lastAgentTs && minutesSinceCommand < idleMinutes) {
core.info(`#${prNumber}: skipped – waiting for Codex response to the latest command (${minutesSinceCommand.toFixed(1)} minutes < ${idleMinutes}).`);
continue;
}

Expand Down
42 changes: 42 additions & 0 deletions tests/fixtures/keepalive/command_pending.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"repo": {"owner": "stranske", "repo": "Trend_Model_Project"},
"now": "2024-05-18T12:00:00Z",
"env": {
"OPTIONS_JSON": "{}",
"DRY_RUN": "false"
},
"pulls": [
{
"number": 606,
"labels": ["agent:codex"],
"comments": [
{
"user": {"login": "triage-bot"},
"body": "@codex plan-and-execute",
"created_at": "2024-05-18T11:55:00Z"
},
{
"user": {"login": "chatgpt-codex-connector"},
"body": "Daily update\n- [ ] Refresh datasets",
"created_at": "2024-05-18T11:40:00Z"
}
]
},
{
"number": 707,
"labels": ["agent:codex"],
"comments": [
{
"user": {"login": "triage-bot"},
"body": "@codex plan-and-execute",
"created_at": "2024-05-18T10:40:00Z"
},
{
"user": {"login": "chatgpt-codex-connector"},
"body": "Checklist\n- [ ] Extract scripts\n- [x] Prepare branch",
"created_at": "2024-05-18T10:30:00Z"
}
]
}
]
}
28 changes: 26 additions & 2 deletions tests/test_keepalive_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ def _raw_entries(summary: dict) -> list[str]:

def _details(summary: dict, title_prefix: str) -> dict | None:
for entry in summary["entries"]:
if entry.get("type") == "details" and entry.get("title", "").startswith(title_prefix):
if entry.get("type") == "details" and entry.get("title", "").startswith(
title_prefix
):
return entry
return None

Expand Down Expand Up @@ -91,11 +93,33 @@ def test_keepalive_dedupes_configuration() -> None:
labels_line = next(line for line in raw if line.startswith("Target labels:"))
logins_line = next(line for line in raw if line.startswith("Agent logins:"))
assert _extract_marked_values(labels_line) == ["agent:codex", "agent:triage"]
assert _extract_marked_values(logins_line) == ["chatgpt-codex-connector", "helper-bot"]
assert _extract_marked_values(logins_line) == [
"chatgpt-codex-connector",
"helper-bot",
]

created = data["created_comments"]
assert [item["issue_number"] for item in created] == [505]
assert created[0]["body"].endswith("<!-- codex-keepalive -->")

details = _details(summary, "Triggered keepalive comments")
assert details is not None and any("#505" in entry for entry in details["items"])


def test_keepalive_waits_for_recent_command() -> None:
data = _run_scenario("command_pending")
summary = data["summary"]

created = data["created_comments"]
assert [item["issue_number"] for item in created] == [707]

info_logs = data["logs"]["info"]
assert any(
"#606: skipped – waiting for Codex response to the latest command (5.0 minutes < 10)."
== message
for message in info_logs
)

raw = _raw_entries(summary)
assert "Triggered keepalive count: 1" in raw
assert "Evaluated pull requests: 2" in raw
Loading