Repository navigation
Description
Friction
Three process-safety rules have no check: never call setrlimit(RLIMIT_NPROC, ...), never set O_NONBLOCK on file descriptors 0 to 2, and never call os.killpg without the PID 1, own-group and caller-group guards. #1961 moved them from AGENTS.md to ARCHITECTURE.md section 7.3, where an agent reads them only when it looks.
Evidence
.ast-grep/rules/ holds the net-construct rules and the test elapsed-time rule; no rule covers these calls.
Existing tool considered
ast-grep, which the gate already runs. Nothing is built beyond rules.
Proposed remedy
Add ast-grep rules that fail on resource.setrlimit(resource.RLIMIT_NPROC, ...), on os.set_blocking(<0|1|2>, False) and fcntl O_NONBLOCK on those descriptors, and on an os.killpg call outside the guarded helper _terminate_process_group, with rule tests.
Alternatives check of 2026-11-01: not-applicable.
Tool: none found.
Proposed design
Problem statement
ARCHITECTURE.md section 7.3 (lines 201-202) holds three process-safety rules with no automated check: never set RLIMIT_NPROC, never set O_NONBLOCK on descriptors 0, 1 or 2, and never signal a process group without the PID 1, own-group and caller-group guards. The constructs row of devops ci runs ast-grep, but no rule covers these calls, so an agent reads the rules only when it opens that section. This issue adds the three rules, their fixtures and their entries in the construct gate. The guarded helpers in sandbox/host.py and k8s/port_forward_daemon.py now delegate to core.process.terminate_process_group, so the only direct os.killpg call in src/ is the guarded primitive _signal_process_group in core/process.py.
Acceptance criteria
Requirement: RLIMIT_NPROC is refused
The constructs gate SHALL report a violation for a call to resource.setrlimit whose first argument is resource.RLIMIT_NPROC.
Scenario: setrlimit with RLIMIT_NPROC
- WHEN The rule runs on a fixture that calls
resource.setrlimit(resource.RLIMIT_NPROC, (0, 0)). - THEN ast-grep reports one violation at the call.
Requirement: A standard descriptor is not set non-blocking
The gate SHALL report a violation for an os.set_blocking call with a literal descriptor of 0, 1 or 2 and a value of False.
Scenario: stdin set non-blocking
- WHEN The rule runs on a fixture that calls
os.set_blocking(0, False). - THEN ast-grep reports one violation at the call.
Requirement: O_NONBLOCK is refused on a standard descriptor
The gate SHALL report a violation for an fcntl.fcntl call on a literal descriptor of 0, 1 or 2 whose flags argument holds fcntl.O_NONBLOCK.
Scenario: stdout set non-blocking with fcntl
- WHEN The rule runs on a fixture that calls
fcntl.fcntl(1, fcntl.F_SETFL, fcntl.O_NONBLOCK). - THEN ast-grep reports one violation at the call.
Requirement: A descriptor above 2 is allowed
The two descriptor rules SHALL report no violation for a literal descriptor above 2.
Scenario: descriptor 3
- WHEN The rules run on a fixture that calls
os.set_blocking(3, False)andfcntl.fcntl(3, fcntl.F_SETFL, fcntl.O_NONBLOCK). - THEN ast-grep reports no violation.
Requirement: An unguarded process-group signal is refused
The gate SHALL report a violation for an os.killpg call outside the functions of src/devops_cli/core/process.py that hold the PID 1, own-group and caller-group guards.
Scenario: bare os.killpg
- WHEN The rule runs on a fixture that calls
os.killpg(os.getpgid(pid), signal.SIGTERM)at module level. - THEN ast-grep reports one violation at the call.
Requirement: The guarded primitive is allowed
The os.killpg rule SHALL report no violation for a call inside _signal_process_group, terminate_process_group, _terminate_process_group_os or _terminate_process_group_async.
Scenario: guarded primitive
- WHEN The rule runs on a fixture whose
_signal_process_groupfunction callsos.killpg(pgid, sig). - THEN ast-grep reports no violation.
Requirement: The source tree passes the new rules
The new rules MUST report no violation on src/.
Scenario: constructs scan over src
- WHEN The
constructsrow ofdevops ciscanssrc/with the new rules. - THEN ast-grep reports no violation.
Requirement: Each rule has a test
Each new rule MUST have a file in .ast-grep/rule-tests/ with at least one valid and one invalid case.
Scenario: rule test suite
- WHEN
uv run ast-grep test --skip-snapshot-testsruns. - THEN The tests of the three new rules pass.
Requirement: Each rule joins the construct gate
Each new rule MUST set severity: error and files: ["src/**"], and MUST have an entry in CONST_AST_GREP_RULE_FILES and one in VIOLATIONS of tests/gate/construct_gate.py.
Scenario: construct gate table
- WHEN The construct gate check of the
constructsrow reads the rule files and the violation table. - THEN It reports no missing rule, no rule outside the table, and no rule without a valid and an invalid case.
Existing Tool Considered
ast-grep covers the need: it is the open, maintained scanner that the constructs row and the ast-grep-test hook already run, and the change adds three rule files and their fixtures, so it builds no program code and carries no build cost. What it lacks: it matches syntax, not values, so the PID 1, own-group and caller-group guard values stay with tests/core/test_process.py::test_terminate_process_group_guards_and_lifecycle; and it has no relation for "inside this function in this file", so the os.killpg exception is by function name. The alternatives check of 2026-11-01 found no other tool and gave not-applicable.
Key questions
- Where do the new ast-grep rules and their tests go?: A rule goes in
.ast-grep/rules/<id>.yml, beside the net-construct rules and the test elapsed-time rule, and its cases go in.ast-grep/rule-tests/<id>-test.yml.sgconfig.ymlnames both directories asruleDirsandtestDir. [sources: sgconfig.yml:1, sgconfig.yml:4, .ast-grep/rules/review-cwd-read.yml:1, .ast-grep/rule-tests/review-cwd-read-test.yml:1] - Which command runs the ast-grep rule tests, and how do they join the CI gate?:
uv run ast-grep test --skip-snapshot-testsruns the cases under.ast-grep/rule-tests/. Theast-grep-testpre-commit hook runs that command, and theconstructsrow ofdevops cirunsast-grep testas one of itsalso_cmds, so the same cases run in the gate. [sources: .pre-commit-config.yaml:75, .pre-commit-config.yaml:77, docs/TESTING.md:72, tests/commands/test_net_construct_rules.py:22, sgconfig.yml:4] - Does the repository set RLIMIT_NPROC anywhere that the rule must allow?: No.
src/only reads the limit:tests/ai/test_tool_executor_contract.py:1304callsresource.getrlimit(resource.RLIMIT_NPROC), which the rule does not match, anddocs/TESTING.md:139states that no test sets it. ARCHITECTURE.md and the tool executor state why it is never set. The rule flags everysetrlimitcall with no exemption. [sources: ARCHITECTURE.md:202, src/devops_cli/security/tool_executor.py:45, tests/ai/test_tool_executor_contract.py:1304, docs/TESTING.md:139] - Which descriptors and which calls does the O_NONBLOCK rule cover?: Descriptors 0, 1 and 2 only, for
os.set_blocking(fd, False)and forfcntl.fcntl(fd, fcntl.F_SETFL, ...)withfcntl.O_NONBLOCKin the flags argument. The rule does not coveros.open. (best practice) [sources: ARCHITECTURE.md:202, tests/ai/test_review_defects.py:565]- Chosen: Descriptors 0 to 2 for
os.set_blockingandfcntl.fcntl. ARCHITECTURE.md limits the rule to descriptors 0, 1 and 2, and these are the calls that change an existing descriptor. - Rejected: Every use of
O_NONBLOCK. It flags the legitimate FIFO open attests/ai/test_review_defects.py:565. - Rejected: Every descriptor of
os.set_blockingandfcntl.fcntl. A pipe or socket descriptor above 2 needs a non-blocking mode. - Rejected: Include
os.openwithO_NONBLOCK.os.openreturns a fresh descriptor and cannot target 0 to 2, and it is the call that opens the FIFO attests/ai/test_review_defects.py:565.
- Chosen: Descriptors 0 to 2 for
- How does the os.killpg rule allow the guarded helper?: The rule allows
os.killpgonly inside the functions ofsrc/devops_cli/core/process.pythat hold the guards:terminate_process_group,_terminate_process_group_os,_terminate_process_group_asyncand the primitive_signal_process_group. The_terminate_process_grouphelpers insandbox/host.pyandk8s/port_forward_daemon.pydelegate tocore.process.terminate_process_groupand hold noos.killpgcall, and the only direct call insrc/is_signal_process_groupatsrc/devops_cli/core/process.py:952. The rule uses the ast-grepinsiderelation with afunction_definitionwhose name matches that set. (best practice) [sources: src/devops_cli/core/process.py:947, src/devops_cli/core/process.py:952, src/devops_cli/core/process.py:958, src/devops_cli/core/process.py:965, src/devops_cli/core/process.py:1006, src/devops_cli/core/process.py:1081, src/devops_cli/sandbox/host.py:65, src/devops_cli/sandbox/host.py:69, src/devops_cli/k8s/port_forward_daemon.py:99, src/devops_cli/k8s/port_forward_daemon.py:103, ARCHITECTURE.md:201, .ast-grep/rules/test-elapsed-upper-bound.yml:107]- Chosen: Allow inside the guard-holding functions of
core/process.py. It covers the one direct call insrc/and the functions that hold the guards, and needs no file list. - Rejected: Allow by file path. A new unguarded call in
core/process.pywould pass. - Rejected: Allow the
_terminate_process_grouphelpers insandbox/host.pyandk8s/port_forward_daemon.py. Both helpers delegate tocore.process.terminate_process_groupand hold noos.killpgcall, so this list would leave the real call atcore/process.py:952unallowed and fail the source-tree criterion. - Rejected: Allow no call. The guarded primitive itself would fail the gate.
- Chosen: Allow inside the guard-holding functions of
- Which tree does each new rule hold?: Each of the three rules holds
src/**only. The construct gate holds one tree per rule and needs a twin violation in the other tree that the rule does not report, and the test tree holds no violation of these rules today. (best practice) [sources: tests/gate/construct_gate.py:83, tests/gate/construct_gate.py:96, tests/gate/construct_gate.py:175, tests/gate/construct_gate.py:310, src/devops_cli/config/constants.py:4491, docs/TESTING.md:139, tests/ai/test_tool_executor_contract.py:1304]- Chosen:
src/**for all three rules. It matches the trees of the existing rules, and the gate writes and checks a twin intests/that the rule must not report. - Rejected:
src/**andtests/**for each rule. The construct gate writes a twin in the other tree and requires no report, and_OTHER_TREEhas no entry for a rule that holds both trees. - Rejected: A second rule set for
tests/**. The test tree holds no violation today, and it doubles the rule and fixture count.
- Chosen:
- Do the PID 1, own-group and caller-group guards stay with the existing test?: Yes. ast-grep matches syntax and not values, so the rule confines the call to the guard-holding functions. The values stay with
test_terminate_process_group_guards_and_lifecycleintests/core/test_process.py, which covers pid 0, 1 and a negative pid, the own process group, and the fallback toos.kill. (best practice) [sources: tests/core/test_process.py:199, tests/core/test_process.py:207, tests/core/test_process.py:229, openspec/changes/archive/2026-11-06-3749-sandbox-tests-on-fakes/proposal.md:49]- Chosen: Confine the call to the guard-holding functions and keep the guard test. The rule catches a new unguarded call, and the test catches a missing guard.
- Rejected: Enforce the guard values with an ast-grep rule. ast-grep matches syntax and not the value of a pid or a process group.
- What must change in the construct gate besides the rule and test files?: Each rule id must join
CONST_AST_GREP_RULE_FILESwith itsfileslist, and one violation of each rule must joinVIOLATIONS. The construct gate reports a rule outside that table, a rule whosefilesdiffer, a rule without a valid or an invalid case, and a rule with no violation in its tree. [sources: tests/gate/construct_gate.py:83, tests/gate/construct_gate.py:138, tests/gate/construct_gate.py:164, tests/gate/construct_gate.py:310, tests/gate/construct_gate.py:322] - Does this issue depend on docs(agents): AGENTS.md routes each task to the document that owns it, and no agent prompt or instruction carries the legacy process #1961?: No. ARCHITECTURE.md section 7.3 already holds the three rules at lines 201 and 202, so docs(agents): AGENTS.md routes each task to the document that owns it, and no agent prompt or instruction carries the legacy process #1961 is done. This issue only adds the rules, their tests and their gate entries. [sources: ARCHITECTURE.md:201, ARCHITECTURE.md:202]
- What tool does the CI gate already run for these checks?: ast-grep. The
constructsrow ofdevops cirunsuv run ast-grep scanoversrcandtestswithCONST_AST_GREP_SCAN_ARGS, and theast-grep-testhook runs the rule tests. This issue adds rules to that run and needs no new tool. [sources: .pre-commit-config.yaml:67, .pre-commit-config.yaml:69, .pre-commit-config.yaml:75, src/devops_cli/config/constants.py:4492, docs/TESTING.md:72]
Fit
Fits in one pull request.
Suspected block
None.
Dependencies
None.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsNew
- StatusShow more project fieldsNew
Activity
dan-petty commentedon Oct 23, 2026
Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones on the board.
The candidate adds ast-grep rules to the CI process.The change improves process safety and is not critical.The change helps prevent process-safety issues in the project.Adding new ast-grep rules and tests requires moderate work.dan-petty commentedon Oct 28, 2026
Refine cannot set this item to Ready at bb46660 until a person answers the questions below. Reply in a comment or edit the body, and the next refine round looks at the item again.
25 remaining items
devops-cli-service commentedon Nov 14, 2026
The runner Job devops-cli-runner-20261114-211850-83e5 ended: succeeded.
Image digest: sha256:97690e98a3a8531d7114db820dd9859802ae6cb26167f0192f4b9026ed63154e
The last lines of its log:
devops-cli-service commentedon Nov 14, 2026
Cleared the stop at group 1 by the rule
digest: the runner image changed since the stop, from sha256:97690e98a3a8531d7114db820dd9859802ae6cb26167f0192f4b9026ed63154e to sha256:30054d111c2d804d0561b96d1f0fa248bb1ff61a2253a4ef8b386d66d01aec37, and the classci_infraof the stop is one that a new attempt can fix. The item is Planned again, and the Service takes it in the next round. The Service clears at most 1 for each class and 3 for each item by digest. A stop of another class, a new stop on this image, and a stop over a limit wait for a commentimplement: retry.wip: 1 of 2 tasks of group 1, Add the three process-safety rules, the…
wip: 2 of 2 tasks of group 1, Add the three process-safety rules, the…
feat(ci): Name process-safety rules in ARCHITECTURE.md and archive #1976
devops-cli-service commentedon Nov 15, 2026
Released in v0.148.0: https://github.com/dan-petty/devops-cli/releases/tag/v0.148.0
devops-cli-service commentedon Nov 15, 2026
Live since 2026-11-15 04:09 UTC