Skip to content

Commit 1b3495f

Browse files
Commit Linux analysis process exit fix
1 parent 33103db commit 1b3495f

1 file changed

Lines changed: 91 additions & 0 deletions

File tree

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
name: Commit Linux analysis process exit fix
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
types:
8+
- opened
9+
- synchronize
10+
- reopened
11+
12+
permissions:
13+
contents: write
14+
15+
jobs:
16+
commit-fix:
17+
if: github.actor != 'github-actions[bot]' && github.event.pull_request.head.repo.full_name == github.repository
18+
runs-on: ubuntu-latest
19+
steps:
20+
- uses: actions/checkout@v4
21+
with:
22+
ref: agent/release-readiness-audit
23+
fetch-depth: 0
24+
- name: Patch completed postprocessing command exits
25+
shell: bash
26+
run: |
27+
set -euo pipefail
28+
python - <<'PY'
29+
from pathlib import Path
30+
31+
path = Path('src/wwgpt/cli.py')
32+
text = path.read_text()
33+
marker = "def _seeds(s: str | None) -> list[int] | None:\n return None if not s else [int(x) for x in s.split(',') if x]\n\n\n"
34+
helper = "def _seeds(s: str | None) -> list[int] | None:\n return None if not s else [int(x) for x in s.split(',') if x]\n\n\ndef _exit_after_flush(status: int = 0) -> None:\n \"\"\"Exit a completed CLI command without waiting on library worker threads.\"\"\"\n sys.stderr.flush()\n sys.stdout.flush()\n os._exit(status)\n\n\n"
35+
if 'def _exit_after_flush(status: int = 0)' not in text:
36+
if marker not in text:
37+
raise SystemExit('seed helper marker not found')
38+
text = text.replace(marker, helper, 1)
39+
40+
old = ' elif args.cmd=="analyze-results": print(analyze_results(args.results_root, args.analysis_plan))\n'
41+
new = ' elif args.cmd=="analyze-results":\n print(analyze_results(args.results_root, args.analysis_plan), flush=True)\n _exit_after_flush(0)\n'
42+
if old in text:
43+
text = text.replace(old, new, 1)
44+
elif new.strip() not in text:
45+
raise SystemExit('analyze-results branch not found')
46+
47+
old = " sys.stderr.flush()\n sys.stdout.flush()\n # Some streaming dataset backends can leave non-daemon workers alive after all artifacts\n # have been written. Exit the CLI process deterministically so shell wrappers can finish.\n os._exit(0)\n"
48+
new = " # Some data and analysis backends can leave non-daemon workers alive after all\n # artifacts have been written. Exit deterministically so shell wrappers finish.\n _exit_after_flush(0)\n"
49+
if old in text:
50+
text = text.replace(old, new, 1)
51+
52+
old = ' elif args.cmd=="generate-reproducibility-report":\n print(\n write_reproducibility_report(\n args.experiment_root,\n strict=args.strict,\n analysis_plan=args.analysis_plan,\n )\n )\n'
53+
new = ' elif args.cmd=="generate-reproducibility-report":\n print(\n write_reproducibility_report(\n args.experiment_root,\n strict=args.strict,\n analysis_plan=args.analysis_plan,\n ),\n flush=True,\n )\n _exit_after_flush(0)\n'
54+
if old in text:
55+
text = text.replace(old, new, 1)
56+
elif new.strip() not in text:
57+
raise SystemExit('reproducibility-report branch not found')
58+
path.write_text(text)
59+
60+
tests = Path('tests/test_release_readiness_audit.py')
61+
test_text = tests.read_text()
62+
addition = '''
63+
64+
def test_postprocessing_cli_exits_after_flushing_completed_artifacts() -> None:
65+
source = Path("src/wwgpt/cli.py").read_text()
66+
assert "def _exit_after_flush(status: int = 0)" in source
67+
assert 'elif args.cmd=="analyze-results":\\n print(' in source
68+
assert 'elif args.cmd=="generate-reproducibility-report":' in source
69+
assert source.count("_exit_after_flush(0)") >= 3
70+
'''
71+
if 'test_postprocessing_cli_exits_after_flushing_completed_artifacts' not in test_text:
72+
tests.write_text(test_text + addition)
73+
PY
74+
rm -f .github/workflows/commit-linux-analysis-exit.yml
75+
rm -f .github/workflows/apply-linux-analysis-exit.yml
76+
rm -f .github/workflows/apply-linux-cli-exit-fix.yml
77+
python -m compileall -q src tests
78+
git diff --check
79+
- name: Commit source fix
80+
shell: bash
81+
run: |
82+
set -euo pipefail
83+
git config user.name github-actions[bot]
84+
git config user.email 41898282+github-actions[bot]@users.noreply.github.com
85+
git add src/wwgpt/cli.py tests/test_release_readiness_audit.py \
86+
.github/workflows/commit-linux-analysis-exit.yml \
87+
.github/workflows/apply-linux-analysis-exit.yml \
88+
.github/workflows/apply-linux-cli-exit-fix.yml
89+
git diff --cached --check
90+
git commit -m 'Exit completed postprocessing commands deterministically'
91+
git push origin HEAD:agent/release-readiness-audit

0 commit comments

Comments
 (0)