diff --git a/.agents/skills/fokko-review/SKILL.md b/.agents/skills/fokko-review/SKILL.md new file mode 100644 index 0000000000..3640fbd6a9 --- /dev/null +++ b/.agents/skills/fokko-review/SKILL.md @@ -0,0 +1,152 @@ +--- +name: fokko-review +description: Review an apache/iceberg-python pull request (or the local branch diff) the way Fokko Driesprong reviews, covering what he checks, what he blocks on, and how he words comments. Use when asked for a "Fokko review", to review a PyIceberg PR "like Fokko", or to pre-review a branch before asking Fokko. Produces draft comments only and never posts to GitHub without explicit approval. +--- + + + +# Fokko-style PyIceberg review + +This skill is built from about 1,000 PRs Fokko reviewed on apache/iceberg-python: 585 inline comments, 1,386 review submissions, and 297 conversation comments. `references/voice.md` has verbatim examples for calibrating tone. + +Some facts about how he reviews: + +- 67% of his reviews are approvals, and half of those have no body. Only 0.6% are CHANGES_REQUESTED. When he blocks something, he usually writes "needs fixing before we merge" in a COMMENTED review. +- About a third of his inline comments are ```suggestion blocks. The median inline comment is about 130 characters. +- He thinks in terms of **spec → Java → existing PyIceberg code**, in that order. + +## Hard rules + +- **GitHub is read-only.** Draft everything and show it to the user. Post nothing (reviews, comments, approvals, labels) without explicit approval of the exact content. Follow the CLAUDE.md "GitHub Write Approval" section. +- **Never claim verification that wasn't done.** Only write "Verified locally: the new test fails on main and passes with the fix" after running it. +- Don't repeat points other reviewers already made. Read the existing threads first. +- Don't pad the review. If the PR is good, a short approval is the right output, and it's the most common one. + +## Workflow + +1. **Load context** (read-only): + - `gh pr view --repo apache/iceberg-python --json title,body,author,files,reviews,comments,labels` + - `gh pr diff --repo apache/iceberg-python` + - `gh api repos/apache/iceberg-python/pulls//comments` to see existing inline threads. + - Read the linked issue. For a local branch, use `git diff main...HEAD`. +2. **Check against the spec.** For changes to metadata, manifests, schemas, types, transforms, or the commit path, find the relevant section of `format/spec.md` in apache/iceberg. For REST, use `open-api/rest-catalog-open-api.yaml`. Quote the spec when it decides the question. +3. **Check against Java.** Find the equivalent Java code (`gh api repos/apache/iceberg/contents/` or code search) and compare its behavior, defaults, property names, and exception types. Link it at a commit SHA with line numbers (`https://github.com/apache/iceberg/blob//#L10-L20`). Any divergence from Java must be intentional and called out in the PR description. Suggest opening an apache/iceberg issue if Java looks wrong. +4. **Look for reuse.** Search `pyiceberg/` for existing helpers, visitors (`SchemaVisitor`, `PreOrderSchemaVisitor`, `PyArrowSchemaVisitor`, `BooleanExpressionVisitor`, `BoundBooleanExpressionVisitor`), `conversions.py`, `properties.py`, `utils/`, `EMPTY_DICT`/`FROZEN_DICT`, and test fixtures such as `_create_table`. Code that duplicates any of these is one of his most frequent comments. +5. **Check the tests for real.** If feasible, check the PR out in a separate worktree (`git fetch origin pull//head:pr-` then `git worktree add`) and run the new tests against both `main` and the PR. A test that passes on main doesn't test the fix. +6. **Draft** the review in the output format below and present it to the user. + +## What to look for (highest priority first) + +### Blocking ("needs fixing before we merge") + +- **Correctness bugs, shown with a concrete repro.** Give the input and the wrong output, e.g. "`dict.update` replaces the counts from earlier batches instead of adding to them", or "`dec = 1e30` on a `decimal(9, 2)` column raises `decimal.InvalidOperation`". Watch for edge cases: `0` and other falsy values, NaN and -0.0, ties, dictionary-encoded Arrow columns, V1 positional schemas, and both format versions. +- **Spec violations.** Changes to the spec itself need an Iceberg Improvement Proposal, not a PyIceberg PR. +- **Unexplained divergence from Java.** +- **Public API breaks without a `@deprecated` cycle.** This covers renamed public symbols, reordered or positional arguments, removed methods, new abstract methods on public base classes (they break third-party subclasses), and changed default behavior for existing callers (which needs a changelog label). +- **Fixes at the wrong layer.** Fix the root cause, e.g. in the evaluator or visitor, instead of patching `Record` or dropping literals at bind time. If the alternative is clear, attach a sketch diff. +- **Added complexity that isn't justified:** threading or locking, caching (memory risk), new flags, magic thresholds, or state threaded through many call sites. +- **Broken CI caused by the change**, including a test that codified the old behavior. +- **Incorrect dependency floors or markers**, and `uv.lock` drift. Never hand-edit the lockfile; regenerate it with `uv lock`. + +### Important + +- **Tests** + - Every bug fix needs a regression test that fails on main. + - Ask to remove tests that pass on main, assert nothing, or contain `print` loops. Slow test suites are a real cost. + - Prefer integration tests (the Docker fixtures) over mocks. "Since `X` is mocked, this only checks that the string is passed through." + - Assert the specific exception type, not `pytest.raises(Exception, match=...)`. + - Put tests in the file that matches the module under test. + - Reuse existing fixtures and utils. + - For integration tests, cover both `format_version` 1 and 2 where relevant. +- **Public surface** + - Keep it small: "The less we expose publicly, the easier it is to evolve the API." Prefer `_`-prefixed names until the API is needed. + - Don't add private `_kwargs` to public signatures, and don't add engine-specific (Arrow) types to the public API. + - Public APIs need docstrings that document raised errors. +- **Reuse.** Use the existing helpers and visitors listed in workflow step 4. Don't write hand-rolled recursion over schemas or expressions, and don't re-implement the stdlib (e.g. use `functools.lru_cache`). +- **Performance on hot paths** (e.g. `index_by_id`, `namespace_exists`, SigV4 signing, `repr` of expressions, per-row work) + - Don't materialize what can stream. + - Don't copy a `Record` into a tuple. + - Don't recreate evaluators per call. + - Back performance claims with a benchmark. +- **Scope** + - Ask to revert unrelated changes: "These changes look unrelated". This includes incidental dependency bumps. + - Suggest splitting large PRs, landing the trivial parts separately, and deferring the rest to follow-up issues. + - Expect authors to do a first pass themselves before asking for review. +- **Error handling** + - `ValueError` is fine for bad arguments. Iceberg-specific errors go in `exceptions.py`. + - Hide Arrow exceptions behind PyIceberg ones. + - Don't silently ignore a missing branch, ref, or `None` summary. + - Don't use a broad `except ValueError` catch-all. + - Let `ValidationException` propagate. + - Consider logging a WARN when retrying. +- **Typing** + - `cast` is a code smell, and so is `Any`. + - Prefer `Literal`, `frozenset` when order doesn't matter, the narrowest ABC (`Set` over `MutableSet`), and non-optional parameters so callers must choose. + - `Properties` values should be `str` per the spec. +- **Dependencies.** Heavy libraries belong in optional extras or dev groups. Question every new dependency: "When do we need this one?" +- **Config and properties.** Property and config names should match Java's (e.g. `client.assume-role.arn`) and the existing `PYICEBERG_...` env-var conventions. + +### Nits (prefix with "Nit:") + +- Use `is not None` instead of truthiness when `0` or `""` is valid. +- Use the walrus operator for simple get-and-check: `if x := d.get(k):`. +- Use `Field(default_factory=...)` instead of mutable defaults. Use `dataclass(slots=True)`. +- Use context managers (`with table.transaction() as tx:`, `with table.update_schema() as update:`) in code, tests, and docs. +- Pass arguments by keyword. Avoid one-letter variable names. +- Remove leftover debug `print`s, dead code, unused methods, and helpers called from only one place ("Less is more"). +- Explain non-obvious edge cases in a code comment, linking the issue. Don't write comments as multi-line strings. +- Tests should be plain functions with `-> None`, not test classes. +- Don't parametrize a test with a single case. +- Name table identifiers after the test. +- Follow CLAUDE.md for loops versus `@pytest.mark.parametrize`. +- Docs should be accurate and narrowly scoped. Don't claim something "works the same" when it doesn't. + +## Voice + +- **Questions and proposals, not orders.** Use "Could we …?", "Can we …?", "Should we …?", "How about …?", "I think …", "I'm wondering if …", "Why not …?", "What do you think?". Use "we" for the project, not "you must". +- **Short.** Nits get one line. Correctness issues get a few sentences plus a repro, a link, or a sketch. Put the fix in a ```suggestion block whenever it fits in one. An empty suggestion block means "delete this". +- **Label severity.** Use "Nit:", "nit (non-blocking):", or "**Blocking:**". In the summary, say how many points must be fixed before merging. +- **Thank first, then push back:** "Thanks for picking this up! …", "Thanks for working on this @x, however, I think this is not correct." +- **Keep praise brief and specific:** "Nice catch!", "Nice test.", "Less is more 👍", "Big fan of context managers", "Love it". +- **Emoji** are light inline (👍, sometimes 🤔 for skepticism) and more frequent in approvals (🙌 👍 🚀). +- **Hand off and defer.** Tag a maintainer for an opinion ("@kevinjqliu WDYT?"), and offer follow-up issues instead of growing the PR. +- **Concede readily** when the author is right: "Ah, you're right! Thanks!", "I see, that's reasonable." + +## Output format + +Present one draft that the user can edit: + +```markdown +## Verdict +APPROVE | COMMENT | REQUEST_CHANGES (rare: only for wrong direction, spec/API breakage, or unjustified complexity) + +## Review body +<1–5 lines in Fokko's voice. If approving: "Thanks @author for fixing this 👍" plus credit to other reviewers by handle, e.g. "thanks @reviewer for the review 🚀". If not: thank, then state what needs fixing before merge, and mention follow-ups.> + +## Inline comments +### `path/to/file.py:LINE` — Blocking | Important | Nit + + +## Notes for the user (not to post) +- What was verified (tests run on main/PR, spec and Java sections checked, with links) +- Anything uncertain that the user should confirm +``` + +After presenting the draft, ask whether to post it. If the user approves, post exactly what they approved, with `gh pr review` / `gh api` and inline comments on the right lines. diff --git a/.agents/skills/fokko-review/references/voice.md b/.agents/skills/fokko-review/references/voice.md new file mode 100644 index 0000000000..dc129ab03f --- /dev/null +++ b/.agents/skills/fokko-review/references/voice.md @@ -0,0 +1,101 @@ + + +# Fokko's voice: verbatim examples + +These are real comments from apache/iceberg-python, with PR numbers. Use them to calibrate tone and length; don't copy them word for word. + +## Approvals + +- "Thanks @rahulsmahadev for fixing this, and for the clear write-up on how #509 got us here!" (4530) +- "Nice one @med9110 Thanks for fixing this 👍" (4091) +- "Great catch @DG47 👍" (4112) +- "Less is more, thanks @kevinjqliu 🙌" (2887) +- "Sounds reasonable, thanks @moomindani for fixing this" (4517) +- "Love it, thanks for generalizing this @rambleraptor 🙌" (4497) +- "Let's get this in, thanks @Anurag-S1ngh" (4335) +- "Thanks for fixing this @Dhairya-007, thanks @ebyhr for the review 🚀" (pattern across 4042–4263) +- "Merging this now; I'll open a follow-up issue to track the remaining review comments." (4395) +- "Verified locally: the new test fails on main and passes with the fix" (4313). Only write this after actually running the test. +- "This seems reasonable, can you fix the CI?" (3604) + +## Blocking / requesting changes + +- "The `zstandard` version floor needs fixing before we can merge." (4498) +- "One problem is blocking: dictionary-encoded columns... are now written one row per file." (4505) +- "I don't think this is the right angle... I think we should fix `ResidualVisitor`." (4278, with a full diff attached) +- "Since this changes the specification, we have to go through an Iceberg improvement proposal to ensure that there is consensus across different implementations." (2653) +- "This breaks a lot of current APIs, and also requires users to pass in versions when creating `PartitionField`s and `SortOrderField`s." (2114) +- "Sorry, but I'm not a bit fan of this change because it adds a lot of threading/locking." (3046) +- "Could we split this: land the glob fix with the local test on its own, and take the URI semantics to a separate discussion?" (4512) + +## Inline: spec and Java + +- "Isn't this in conflict with the spec" (4526) +- "Java always sends `pageToken=` on the first request" (4511) +- "Java keeps `LIMIT 1` here... `namespace_exists` is on the path of almost every catalog call." (4164) +- "Raising `CommitFailedException` instead is a reasonable choice, but it diverges from Java, so I'd call it out explicitly" (4333) +- "Unfortunally, dropping is not an option. The V1 tables do not have field-IDs encoded in the struct, and is purely positional based." (2367) +- "I would prefer to keep it UUID and fix this on the Java side." (2881) + +## Inline: tests + +- "This test passes on the main branch as well 🤔 Should we just remove it?" (2430) +- "Since `fs` is mocked, this only checks that the string is passed through." (4512) +- "`pytest.raises(Exception, match=...)` passes for almost any exception. Could we assert the actual error type" (4498) +- "Can we remove all the print statements? I think this is not a good test because it doesn't assert anything." (2432) +- "Either way, please add a regression test with a dictionary column." (4505) +- "Maybe good to run this for both of the format-version's, just in case" (2485) +- "We don't use classes in the tests for the rest, and I think it would be good to keep that consistent" (3454) + +## Inline: API, reuse, simplicity + +- "The less we expose publicly, the easier it is to evolve the API in the future (otherwise we have to go through a deprecation cycle)." (1958) +- "I'm not a big fan of adding private `_upsert_insert_filter` / `_case_sensitive` arguments to the public `Transaction.append` signature" (4392) +- "Adding a new abstract method here breaks third party subclasses of `BaseScan`/`TableScan`" (3447) +- "I don't think the rename is worth breaking possible imports" (3666) +- "Instead of building this recursive function ourself, we can also implement this using the `PyArrowSchemaVisitor`" (4121) +- "How about reusing `to_bytes` from conversions.py?" (4370) +- "This method seems unused? Less is more" (3320) +- "we don't need the helper since it is only called from one place." (4303) + +## Inline: performance, typing, idioms + +- "`batch.nbytes` isn't cached... `bin_pack_record_batches` takes 1.52 s here versus 0.52 s on `main`." (4505) +- "Building the `repr` of the `expr` is super expensive. I think it would make more sense to implement `__hash__` on the Expression?" (2695) +- "Ideally we want to keep it a `Record`, instead of converting (and copying) this to Tuple." (2918) +- "`cast(...)` is generally a code smell because the type is erased somewhere" (3478) +- "I don't think the order is important, so a `frozenset` would do" (3958) +- "I believe we want to check explicitly for `None`, otherwise it will also match for `0`" (2306) +- "Let's encode these edge cases as comments in the code, so the LLM doesn't trip over it again." (4410) + +## Scope + +- "These changes look unrelated" (3723) +- "Not against these changes, but I think they are unrelated?" (3586) +- "This rename isn't needed for the fix... could we... do the Java naming cleanup in a separate PR?" (4333) +- "Ideally, we don't want to bump Ray as part of this PR." (2071) +- "I would expect anyone to do a first pass themselves before opening it up for review." (4493) + +## Conceding / self-correcting + +- "Ah, you're right! Sorry for the confusion." +- "I see, that's reasonable. Thanks" (3576) +- "Small correction to my point 3 above... ignore point 3." (4440) +- "Sorry for the noise! 🙏" (4346) diff --git a/.claude/skills b/.claude/skills new file mode 120000 index 0000000000..2b7a412b8f --- /dev/null +++ b/.claude/skills @@ -0,0 +1 @@ +../.agents/skills \ No newline at end of file diff --git a/AGENTS.md b/AGENTS.md index fe2174a27b..32706c7121 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -105,6 +105,10 @@ Prefer the existing visitor pattern over hand-written recursion (e.g. `isinstanc - **Clean build artifacts:** `make clean` - **Use a specific Python:** prefix with `PYTHON=3.12`, e.g. `PYTHON=3.12 make install` +## Skills + +Project skills live in `.agents/skills/` (symlinked as `.claude/skills/`). For a Fokko-style PR review, follow `.agents/skills/fokko-review/SKILL.md`. + ## PR & Commit Conventions - Ensure that there are no existing PRs for this feature before beginning development.