cloud-fan opened a new pull request, #60555:
URL: https://github.com/apache/spark/pull/60555

   ### What changes were proposed in this pull request?
   
   This PR turns the root `AGENTS.md` (19978 bytes, which every agent session 
loads) into a 6.3 KB index. It also adds a lint for agent instruction files and 
runs it in CI.
   
   **Root index.** The root keeps what most tasks need, plus the guardrails, 
inline:
   - the pre-flight checks (unchanged)
   - the core SBT compile/test commands, the golden-file rule (regenerate, 
never hand-edit), and the streaming test coverage pointer
   - the 100-char / ASCII / class-member placement rules, and the Spark Connect 
proto README pointer
   - the PR title format, `[FOLLOWUP]`, push/approval/force-push rules, and "a 
merged PR shows up as Closed"
   
   Everything else moves **verbatim** into a root `.agents/` directory. Each 
file sits behind one pointer that starts with its trigger (e.g. "Before writing 
a new Scala or Python test suite: read `.agents/test-base-classes.md`"):
   
   | Former `AGENTS.md` section | Now |
   |---|---|
   | Scala / Python Test Base Classes | `.agents/test-base-classes.md` |
   | Build and Test (SBT detail, PySpark tests) | `.agents/build-and-test.md` |
   | Development Notes: class members, ASCII, 100-char spot-check commands | 
`.agents/code-conventions.md` |
   | Investigating PR CI Failures | `.agents/pr-ci-failures.md` |
   | Checking PR Merge Status | `.agents/pr-merge-status.md` |
   | Pull Request Workflow: JIRA creation, notice, PR template | 
`.agents/pr-workflow.md` |
   | Versioning and Branch Policy | `.agents/versioning.md` |
   
   Moved sections only had their headings promoted by one level. The one text 
change is in `test-base-classes.md`: "(run via `python/run-tests`, see below)" 
referred to a section that is no longer below it, so it now points at 
`.agents/build-and-test.md`. "Project Instructions Discovery" becomes "Agent 
Instructions in This Repo". That section describes the index convention, keeps 
the existing rules (check both `AGENTS.md` and `CLAUDE.md`; a new directory 
gets a real `AGENTS.md` plus a `CLAUDE.md` symlink), and says to run the lint 
after editing agent docs.
   
   **Lint.** `dev/agent_docs_lint.py` is report-only by default; `--strict` 
exits non-zero on errors. The Linters job runs it with `--strict`, guarded by 
`hashFiles(...)` like the structured logging check, so scheduled runs on older 
branches skip it. It only reads files and runs `git ls-files`, so it takes well 
under a second. It checks:
   
   | check | rule | why |
   |---|---|---|
   | `pairing` | every directory with agent instructions has both `AGENTS.md` 
and `CLAUDE.md`, one a symlink to the other | Codex reads `AGENTS.md` and 
ignores `CLAUDE.md` by default. By default, [Claude Code reads `AGENTS.md` only 
when no `CLAUDE.md` exists in or above its working 
directory](https://code.claude.com/docs/en/memory#agents-md). Because the root 
has a `CLAUDE.md`, a nested directory with only an `AGENTS.md` would be 
skipped. Two real files let the tools follow different instructions. |
   | `codex-cap` | each root-to-directory chain of `AGENTS.md` files fits 32 
KiB | Codex concatenates them into one `project_doc_max_bytes` budget (32768 by 
default), filled root first, and silently truncates past it |
   | `budget` (warning) | root <= 8 KiB, nested <= 4 KiB | keeps always-loaded 
text small |
   | `pointers` | backquoted `.agents/...`, `AGENTS.md` and `CLAUDE.md` paths 
in instruction files (including `.agents/` files) resolve | catches stale 
pointers |
   
   **Known failures.** An optional exceptions file, 
`dev/agent_docs_lint_exceptions.txt`, exempts errors that cannot be fixed yet, 
such as vendored third-party docs. It takes one `<check> <subject>` line per 
error, and each error prints the exact line that would exempt it. Exempted 
errors are still reported but do not fail `--strict`. An entry that no longer 
matches any error fails as stale, so the list can only shrink, like 
`configs-without-binding-policy-exceptions`. This PR does not create the file, 
because the repo has no failures.
   
   **Also:**
   - Adds a root `.ignore` containing `!.agents/`, and adds `.ignore` to 
`dev/.rat-excludes` next to `.gitignore`.
   - Adds `.agents/*.md`, `/.ignore` and `/dev/agent_docs_lint.py` to 
`ignored_file_patterns` in `dev/sparktestsupport/modules.py`, so changing them 
does not trigger test modules. This matches `AGENTS.md`, `CLAUDE.md` and the 
other linters. The Linters job always runs, so doc-only PRs are still linted.
   - Updates the docstrings of `dev/next_version_candidates.py` and 
`dev/pr_merge_status.py`, which referred to the moved `AGENTS.md` sections by 
name.
   
   ### Why are the changes needed?
   
   - **Every agent session pays for the whole root file.** Most of the 20 KB is 
detail that only some tasks need. The test base class tables alone are 6.3 KB, 
and the CI-failure, merge-status, JIRA and versioning runbooks matter only for 
those tasks. The index keeps the always-loaded part small and loads the rest 
when its trigger matches.
   - **The file is growing toward Codex's cap.** It grew from 0.7 KB in 
February to 20 KB now. Codex fits the whole root-to-cwd chain of `AGENTS.md` 
files into 32 KiB and drops the rest without warning, and any future nested 
`AGENTS.md` shares that budget with the root.
   - **Structural mistakes are silent.** A directory with only a `CLAUDE.md` is 
invisible to Codex, and one with only an `AGENTS.md` is invisible to Claude 
Code by default. Two diverging real files make the tools disagree, and a 
renamed `.agents/` file leaves a dead pointer. Nothing reports any of these 
today; the lint does, in CI.
   - **Why `.ignore`:** ripgrep skips hidden directories by default. Without 
the whitelist, `rg` from the repo root silently misses everything under 
`.agents/`. That affects agents searching for guidance, and anyone grepping for 
references before renaming a script that the docs mention, e.g. 
`dev/pr_merge_status.py`. A whitelist entry in an ignore file overrides 
ripgrep's hidden-file filter. `.ignore` is the ripgrep-specific file for this, 
so it keeps the setting out of `.gitignore`. `git grep` and `grep -r` are 
unaffected either way.
   
   ### Does this PR introduce _any_ user-facing change?
   
   No. Only contributor and agent documentation, a dev script, and a CI lint 
step change.
   
   ### How was this patch tested?
   
   - **No content lost:** a script checked every non-blank line of the old 
`AGENTS.md` against the new root and `.agents/` files. All lines are present 
verbatim except: lines re-wrapped into bullets in the index (verified identical 
after whitespace normalization), the intended "see below" fix, and the 
rewritten "Project Instructions Discovery" section.
   - **Lint on master vs. this branch:** both have 0 errors; master warns 
`AGENTS.md: 19978 bytes > 8192 target`, and this branch has no warnings.
   - **Lint negative cases** in a scratch repo: a `CLAUDE.md`-only directory, 
an `AGENTS.md`-only directory, two different real files, an 
`AGENTS.override.md`-only directory, a dangling `AGENTS.md` symlink, missing 
pointers from `AGENTS.md` and from a `.agents/` file, a nested pointer resolved 
against the nested `.agents/`, an elided `a/.../AGENTS.md` (skipped), and an 
over-cap chain. Each produced the expected result. `--strict` exits 1, and the 
default mode exits 0.
   - **Exceptions file**, on a scratch repo with many failures:
     - An exceptions file built from the printed hints makes `--strict` pass, 
with the exempted errors still listed.
     - Fixing one of the files turns its entry into a stale-exception error.
     - A malformed line is an error.
     - A new failure that is not listed still fails.
   - The new workflow step parses as expected (checked with PyYAML).
   - `ruff format --check` and `ruff check` (0.14.8, the pinned version) pass 
on the changed Python files.
   - `python3 -m unittest discover -s dev/sparktestsupport/tests -t dev` 
passes. `is_ignored_file` returns true for `.agents/pr-workflow.md`, 
`sql/core/.agents/x.md`, `.ignore` and `dev/agent_docs_lint.py`, and false for 
`x.agents/y.md` and `python/pyspark/sql/x.py`.
   - `dev/check-license` passes on `.ignore`. Without the new 
`dev/.rat-excludes` entry, it flags `.ignore`.
   - With `.ignore`, `rg -l dev/pr_merge_status.py --glob '*.md'` finds 
`.agents/pr-merge-status.md`. Without it, `rg` skips `.agents/`.
   
   ### Was this patch authored or co-authored using generative AI tooling?
   
   Generated-by: Claude Code (Claude Opus 5.5)
   
   This pull request and its description were written by Isaac.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to