Skip to content

docs(openspec): plan #1976 Add process-safety ast-grep rules - #5591

Merged
dan-petty merged 2 commits into
mainfrom
feat/1976-add-ast-grep-rules-for-rlimit
Nov 14, 2026
Merged

dan-petty merged 2 commits into
mainfrom
feat/1976-add-ast-grep-rules-for-rlimit

Conversation

@devops-cli-service

Copy link
Copy Markdown
Contributor

Plans #1976

ARCHITECTURE.md section 7.3 holds three process-safety rules that no check enforces: never set RLIMIT_NPROC, never set O_NONBLOCK on descriptors 0 to 2, and never signal a process group outside the guarded helper. The constructs row of devops ci already runs ast-grep, so three rules join that run: process-setrlimit-nproc, process-nonblocking-std-fd and process-killpg-guarded. Each rule holds src/**, sets severity error, has a case file with a valid and an invalid case, and has one entry in CONST_AST_GREP_RULE_FILES and one in VIOLATIONS of the construct gate. The os.killpg rule allows a call inside the four guard-holding functions of the core process module; the guard values stay with test_terminate_process_group_guards_and_lifecycle. #1976

Change: openspec/changes/1976-add-ast-grep-rules-for-rlimit/

@devops-cli-service devops-cli-service Bot added type/docs Type docs: a change to the documents scope/openspec OpenSpec changes, specs and their checks labels Nov 14, 2026
@devops-cli-service
devops-cli-service Bot marked this pull request as ready for review November 14, 2026 01:45
@dan-petty

Copy link
Copy Markdown
Owner

An agent vetted this plan before a merge (shepherd, 2026-11-14). Verdict: needs fix. Each point below blocks a correct build.

  1. The descriptor rule is built on an attribute that does not exist. Python 3.14.10 gives hasattr(fcntl, 'O_NONBLOCK') == False; the flag is os.O_NONBLOCK. The spec scenario 'A standard descriptor set non-blocking', the issue criterion and the only fcntl invalid case of task 1.1 use fcntl.fcntl(1, fcntl.F_SETFL, fcntl.O_NONBLOCK), which raises AttributeError. Task 1.2 says to match 'an fcntl.O_NONBLOCK attribute or an O_NONBLOCK name among its arguments'. Proof: a scratch rule that follows this text literally (argument_list has fcntl.O_NONBLOCK or the identifier O_NONBLOCK, with no stopBy: end) passes every case that the plan names. It misses the real idiom fcntl.fcntl(1, fcntl.F_SETFL, flags | os.O_NONBLOCK). A rule that searches with stopBy: end catches it. Fix in the change folder: use os.O_NONBLOCK in the scenario, the invalid case and the VIOLATIONS source; add an invalid case for flags | os.O_NONBLOCK; and tell task 1.2 to search the arguments at any depth (stopBy: end).

Points that do not block:

  • The group 1 verify uv run devops ci test tests/gate/construct_gate.py expands to tests/invariants/test_construct_gate_check.py and tests/commands/test_net_construct_rules.py. Neither test starts ast-grep, so the verify cannot show a broken rule or case. The 1.1 line 'fails on the base' is false: the new case files change no test result. The implement job checks a base failure only for behavior groups (implement_step._fail_to_pass_failure). The cause is the stage form (stage_form._manifest_verify_problems), which accepts only uv run devops ci test <path of the group> for a manifest group. The planner did not cause it. The real proof is the constructs row, which task 1.2 names and which the Static Analysis job of ci.yml runs on each PR. This is the same point as the model review (claude-sonnet-5-5 trial). That review did not find the fcntl.O_NONBLOCK fault.
  • The descriptor rules match literal 0, 1 and 2 only. They miss the common form os.set_blocking(sys.stdin.fileno(), False) and sys.stdout.fileno(). The issue chose literals. Adding these forms is optional and cheap.
  • The os.killpg rule allows a call by function name anywhere in src/. A function with one of the four names in another module passes; the design accepts this. os.kill(-pgid, sig), os.kill(0, sig) and from os import killpg also signal a group and stay outside the rule. src/ holds none of them now.
  • ARCHITECTURE.md section 7.3, bullet 'Process groups' (line 200), names _terminate_process_group in src/devops_cli/sandbox/host.py as the model. That helper delegates to core.process.terminate_process_group, and the new rule allows os.killpg only in src/devops_cli/core/process.py. Task 2.1 edits that bullet. It should also point the example at terminate_process_group in core/process.py (AGENTS.md rule 8).
  • Task 2.2 'Edit ARCHITECTURE.md' repeats task 2.1. This comes from the form.
  • Two descriptions are already incomplete, and the change adds rules that they do not name: the ast-grep-scan hook name at .pre-commit-config.yaml:69 and the comment above CONST_AST_GREP_SCAN_ROOTS at src/devops_cli/config/constants.py:4592. The design rejects the hook rename. Optional.
  • The prose is mostly ASD-STE100. Small faults: in the proposal Capabilities line, 'Each' starts with a capital letter after a comma; 'alters' should be 'changes'; some Feasibility sentences are longer than 25 words.
  • PR state: devops-cli-service[bot] marked the PR ready for review at 2026-11-14T01:45:43Z, 4 minutes after it opened it. The stage comment still says 'draft pull request'. The head is one commit behind origin/main (release commit 79eb893). mergeable_state is clean.
  • Checked and correct: the premise holds on origin/main 79eb893. None of the 20 rules covers these calls. src/ holds 0 setrlimit calls, 0 os.set_blocking calls and 0 fcntl O_NONBLOCK calls. It holds one os.killpg call, at src/devops_cli/core/process.py:1205 inside _signal_process_group. The four allowed functions exist at core/process.py:1200, 1218, 1259 and 1334. CONST_AST_GREP_RULE_FILES (line 83) and VIOLATIONS (line 136) are both in tests/gate/construct_gate.py, which the plan names. The invariant tests read those tables, so they need no edit. No workflow edit is necessary. No open PR changes these paths, and no newer issue replaces feat(ci): Add ast-grep rules for RLIMIT_NPROC, O_NONBLOCK, os.killpg #1976. Scratch prototype of the three rules (ast-grep 0.51.2): ast-grep test passes 3 of 3 rules. The rules report 0 matches on src/ and tests/ of the PR head. The bare pattern finds the core/process.py:1205 call, and the not-inside clause allows it. Scratch files: /tmp/claude-1000/-workspaces-devops-cli/be3bdf29-4c72-47fe-9e03-282fea1181a3/scratchpad/vet5591

@dan-petty dan-petty added the verdict/fix-plan Verdict Needs fix of a plan: an open finding keeps the plan in draft until a fix label Nov 14, 2026
@dan-petty
dan-petty force-pushed the feat/1976-add-ast-grep-rules-for-rlimit branch from b3c839f to eebe14a Compare November 14, 2026 13:50
@dan-petty

Copy link
Copy Markdown
Owner

An agent vetted this plan before a merge (2026-11-14). Verdict: ready.

  • Replaced invalid fcntl.O_NONBLOCK attribute references with os.O_NONBLOCK across spec scenarios, invalid case descriptions, and VIOLATIONS table entries.
  • Added invalid test case for fcntl.fcntl(1, fcntl.F_SETFL, flags | os.O_NONBLOCK) and updated task 1.2 to search arguments at any depth (stopBy: end).
  • Updated ARCHITECTURE.md task to point the process group example to terminate_process_group in src/devops_cli/core/process.py.
  • Formatted spec scenarios with explicit devops ci gate commands to satisfy scenario coverage gates.
  • Rebased on origin/main and verified with devops roadmap plan-check 5591 (all checks passed).

@dan-petty
dan-petty merged commit 5007a65 into main Nov 14, 2026
22 checks passed
@dan-petty
dan-petty deleted the feat/1976-add-ast-grep-rules-for-rlimit branch November 14, 2026 13:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope/openspec OpenSpec changes, specs and their checks type/docs Type docs: a change to the documents verdict/fix-plan Verdict Needs fix of a plan: an open finding keeps the plan in draft until a fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant