Skip to content

test: close the classes a twelfth five-run hygiene sweep found - #14421

Merged
chenmingwei23 merged 1 commit into
mainfrom
test/hygiene-sweep-20260927
Sep 27, 2026
Merged

chenmingwei23 merged 1 commit into
mainfrom
test/hygiene-sweep-20260927

Conversation

@bolichen97

@bolichen97 bolichen97 commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: A full backend run on a big Linux host is green for the right reasons, and two things a user can see -- PDF extraction and Ctrl-C in a terminal -- work when the gateway is large or was started as a background job.

Five full rounds of the suite on a 32-core Linux host (139,019 backend tests per round, 16 workers, a fresh venv, a live gateway on the same host) were red in every round: 19, 21, 16, 20, 17. Twelve tests failed 5/5 and pass at -n0. Ten more flipped between rounds. Unit tests reached the host's real kiro-cli, ssh, git and ps; eight files left SQLite handles open; one module leaked two env keys for 159 tests.

Why it matters

Two of the reds are product bugs, not test bugs. A gateway whose RSS is over 1 GiB cannot extract any PDF on Linux: the extractor child inherits the parent's peak RSS across execve and its own watchdog kills it before it reads a byte. A gateway launched with cmd & or nohup from a script opens terminals where Ctrl-C reaches nothing, because SIG_IGN survives exec into the shell and every job under it. The dashboard's peak-memory number and the process gauge were the parent's, for the gateway's whole life.

The rest is the usual cost of a red-on-some-orderings suite: a test that ships green from one run and fails someone else's PR.

Not a goal

What changed (motivation → approach → change)

Red / class Root cause Change
7 PDF tests, 5/5 pdf_extract_child.py's peak_rss_bytes() read ru_maxrss; Linux seeds it with the parent's high-water mark at execve read the child's own VmHWM from /proc/self/status; ru_maxrss stays the macOS source
dashboard peak / gauge same inheritance in platform_compat.py (proc_peak_rss_bytes / proc_rss_bytes) same own-VmHWM reader, clamped monotonic
Ctrl-C test 4/5, product a backgrounded launcher's ignored SIGINT reaches the PTY shell's children _spawn_exec_shim.py resets inherited SIG_IGN to SIG_DFL on the --ctty-fd path before exec
5 cmd-launcher tests, 5/5 fake gh.cmd under a repo-internal TMPDIR sits inside the working-tree fence pin the fence root (_WORKTREE_ROOT) to a tmp_path sibling
10 trusted-apps 409s a real dashboard boot leaves hooks_integration globals bound (fixed in #14388) the booting helper pins them before boot, its own contract
spawn_no_cwd resolver seams unpinned: installed_kiro_cli_version, ssh -V, code_fingerprint, doctor's warm_backend, a hand-rolled _stub_port_owner copy house autouse pins per module; push_guard.py's two git patch-id calls go through run()
fd_leak (8 files) unclosed SQLite handles, a boot that raised before returning its state opened() fixture, close_skills_loaders, manager close(), recorded states released
env_leak (159 tests) module-scoped mock.patch.dict(os.environ) function-scoped monkeypatch.setenv
heavy_rss / slow scripts/run_scoped_tests.py's _read_text cached every test file; repo_files() let git walk the run's scratch stream the read; hand scratch roots to git as --exclude
kill (707 signals) two naked os.kill(pid, 0) and a raw SIGKILL at a reissued pid pid_exists; get_process_start_id + kill_pid_pinned
host write acp_launch_capture stubbed allocate_scratch with a fixed /opt/scratch/dsh-session and the arm wrote into it the stub answers a real directory under tmp_path

Every fix is at the seam that inherits or resolves, never in the assertion that noticed. The testing spec gains the twelfth-pass section with the measurements, and writing-tests/SKILL.md gains one checklist line per class. The docs/architecture and platform-compat docs name the new RSS source.

This PR is the Linux twin of #14388 (macOS, same day, same base). Where both found the same thing -- the hooks-globals floor, the vitest clock red (#14390), two sandbox ssh pins -- this PR carries no change and relies on #14388 landing first. test/acp_launch_capture.py is touched by both: #14388 stubs the removal, this PR gives the arm a real scratch directory (it also unlinks .owner there); the rebase keeps this version.

Backwards compatibility

Compatible: production behaviour changes only where it was wrong -- a PDF a large gateway refused now extracts, a terminal a backgrounded gateway opened now delivers Ctrl-C, a diagnostics peak that was the parent's is now the process's. No accepted input is rejected, renamed or removed. push_guard.run() gains an optional input= argument.

Tests

  • test_pdf_extract.py::TestRssWatchdog and test_platform_compat.py::TestPeakRssIsThisProcesss: a fake /proc status through a seam; a parent that touches 256-512 MiB spawns a child that must still report a small own peak and extract page 1; the monotonic clamp; malformed status -> None/0, never a guess.
  • test_terminal_handler.py: the first Ctrl-C waits for tcgetpgrp to leave the shell's group; a sibling test proves the shell gets the foreground back; the session is reaped in finally.
  • test_preflight_write_permission.py: passes under a TMPDIR inside the checkout and under the default.
  • test_push_guard.py::test_patchid_failure_refuses: fails before the run() routing, passes after.
  • test_local_gate.py::test_the_reference_scan_reads_each_test_file_once_and_drops_it; test_source_corpus.py consumes iterators.
  • test_acp_launch_goldens.py::test_the_deepseek_capture_writes_its_scratch_windows_only_under_tmp_path.
  • Pins per module for kiro-cli, ssh -V, code_fingerprint, warm_backend; the two driver-reap tests carry the grandchild's start-time identity.
  • The 45 touched test files together at -n4: 4,548 passed, 48 skipped.

Manual verification

  • hygiene/rss_inherit_probe.py on the host: a 1,312 MiB parent -> child ru_maxrss 1,312 MiB, child VmHWM 11 MB -- the mechanism, first-hand.
  • Kill census over the 68 flagged files with an ownership probe: 707 signals, 0 non-zero signals at a foreign process.
  • Per-test fd, env and spawn probes on every fixed cluster (numbers in the spec section).

Screenshots / video

N/A -- no user-visible frontend change (the vitest fix is #14390).

Related Issues

N/A -- found by the sweep, no tracked issue.

@bolichen97
bolichen97 requested a review from a team as a code owner September 27, 2026 08:15
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Sep 27, 2026
@bolichen97

Copy link
Copy Markdown
Contributor Author

Intent: Make a full backend run on a large Linux host green for the right reasons -- every red of a five-run sweep fixed at the seam that inherits across exec (a child's ru_maxrss, an ignored signal, a boot-time process global) or that resolves a host binary -- and ship the two product defects that surfaced: PDF extraction dead under a >1 GiB gateway, and Ctrl-C dead in terminals of a backgrounded gateway.
Not a goal: fixing what #14388 (the same day's macOS pass) already carries -- the hooks-globals restore floor, the vitest clock red (#14390), two sandbox ssh pins; the exec shim's SIGPIPE/SIGXFSZ handling for non-terminal spawns; session_pid._sync_kill_provider's unpinned kill; class-15 aiohttp warnings.

@bolichen97
bolichen97 force-pushed the test/hygiene-sweep-20260927 branch from 80a7d57 to 720e95e Compare September 27, 2026 08:21
@github-actions

github-actions Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Fable 5) — ✅ PASS

Design-level review of 8641444fcec49c17229e9acb3ff25b468656cafa — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

Design-Verdict: PASS

Verify #14388 landed before merge — this PR deliberately omits the shared hooks-globals/ssh-pin fixes and its acp_launch_capture.py version must survive the rebase.

[DESIGN-REVIEWED] 8641444

@github-actions

github-actions Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Fable 5) — 🟡 CONCERNS

Premise-level review of 8641444fcec49c17229e9acb3ff25b468656cafa — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

First-Principles-Verdict: CONCERNS

The new doc line "the pin now sits in every module that builds the launcher" is contradicted by count: test_worktree_create.py builds one unpinned.

Not justified as shipped

  • Item 7 — symptom-level (point patch, one counted sibling): grep _build_launcher_script hits 25 test files; 22 carry the _ssh_supports_accept_new pin, 2 are deferred to test: Close what the eleventh hygiene sweep found #14388 in "Not a goal", but test/test_worktree_create.py:1353 calls it with no pin — the lru-cached probe still spawns the host's real ssh -V when that module runs first on a worker, the exact class this PR pins in seven files, while the added testing-conventions sentence claims the fixture "now sits in every module that builds the launcher".
    Subtraction: shrink that sentence to the counted set (name test_worktree_create.py as left, as "Not a goal" already does for the two test: Close what the eleventh hygiene sweep found #14388 files).
    Clears when: the sibling carries the pin (here or in test: Close what the eleventh hygiene sweep found #14388), or the doc sentence names it as unfixed.

What this change ships

Inventory (10 items) — 9 justified

Intent: FIX — make the Linux full-suite run red-free for real reasons, and fix two user-visible defects: PDF extraction under a >1 GiB gateway and Ctrl-C in terminals from a backgrounded gateway. (More than 10 items; the 10 most noticeable kept.)

  1. A Linux gateway past 1 GiB RSS can extract PDFs again (child reads own VmHWM) — justified
  2. Dashboard peak-memory number and gauge report the gateway's own peak, not its launcher's — justified
  3. Ctrl-C reaches foreground jobs in terminals a backgrounded/nohup gateway opens — justified
  4. push_guard patch-id calls route through run() (new optional input=, two consumers counted) — justified
  5. Local gate no longer holds the whole test tree resident (~190 MiB cache deleted) — justified
  6. Repo enumeration hands scratch roots to git as --exclude (27 s → 0.5 s measured) — justified
  7. ~30 test modules pinned off host binaries (kiro-cli, ssh, git, ps, warm_backend) — symptom-level: one counted unpinned sibling, test_worktree_create.py
  8. SQLite/process handle leaks in eight files closed via existing rootdir opened/close_skills_loaders fixtures; one local fixture deleted — justified
  9. DeepSeek launch capture no longer unlinks/rmtrees /opt/scratch on the recording host — justified
  10. Testing spec, skill checklist and RSS docs updated in the same commit (AGENTS.md same-commit rule) — justified

[FIRST-PRINCIPLES-REVIEWED] 8641444

@github-actions

github-actions Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

GPT 5.6 Review — ✅ no blocking findings

GPT 5.6 completed its review of 8641444fcec49c17229e9acb3ff25b468656cafa and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 8641444

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 8641444fcec49c17229e9acb3ff25b468656cafa: <one-sentence reason>

Five full rounds on Linux (16 workers, 139,019 backend tests, 39,695 vitest,
2,204 electron per round) on a fresh venv with a live gateway on the host.
Every class is fixed at the seam that inherits, not in the test that noticed,
and each is written into the testing spec as the twelfth pass.

Production:
- pdf_extract_child: on Linux read the child's own VmHWM, not ru_maxrss, which
  execve seeds with the parent's peak -- a gateway over 1 GiB could not extract
  any PDF (7 reds, 5/5).
- platform_compat: proc_peak_rss_bytes / proc_rss_bytes read the same own
  VmHWM (monotonic floor); the dashboard peak and the process gauge were the
  parent's number for the gateway's whole life.
- _spawn_exec_shim: a --ctty-fd spawn resets inherited SIG_IGN to SIG_DFL
  before exec, so a gateway started as a background job still opens terminals
  where Ctrl-C reaches the foreground job.
- prepare-pr push_guard: both `git patch-id --stable` calls go through run(),
  so the injected git covers them.
- scripts/run_scoped_tests: _read_text no longer caches every test file's text
  for the process (+189 MiB per gate run).
- test/source_corpus: repo_files() hands the run's scratch roots to git as
  --exclude instead of walking 126k scratch entries (27 s -> 0.5 s).

Tests: preflight fence root pinned under a repo-internal TMPDIR; terminal
Ctrl-C test gated on tcgetpgrp and reaped in finally; hooks globals pinned
before a real dashboard boot; kiro-cli / ssh / git / ps resolver seams pinned
in the modules that reached the host binaries; SQLite handles closed through
the opened() fixture; env leak from a module-scoped patch.dict; class-27 pid
reuse in two driver-reap tests; kill census (707 signals, 0 foreign).
@bolichen97
bolichen97 force-pushed the test/hygiene-sweep-20260927 branch from 720e95e to 8641444 Compare September 27, 2026 08:56
@github-actions

Copy link
Copy Markdown
Contributor

Opus 5 Review — ✅ no blocking findings

Reviewed 8641444fcec49c17229e9acb3ff25b468656cafa — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 8641444

Verdict parsed from the review's SHA-scoped output markers for commit 8641444fcec49c17229e9acb3ff25b468656cafa.

False positive or not applicable? A repository writer can comment:
/ai-review override fable 8641444fcec49c17229e9acb3ff25b468656cafa: <one-sentence reason>

@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running labels Sep 27, 2026
@bolichen97
bolichen97 enabled auto-merge (rebase) September 27, 2026 09:48
@chenmingwei23
chenmingwei23 merged commit 1894588 into main Sep 27, 2026
97 checks passed
@chenmingwei23
chenmingwei23 deleted the test/hygiene-sweep-20260927 branch September 27, 2026 10:12
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Sep 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants