用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/questdb/py-questdb-client --skill review-pr命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
基于 SOC 职业分类
正在显示 SKILL.md
| name | review-pr |
| description | Review a GitHub pull request against py-questdb-client (Cython + C-ABI) coding standards |
Review the pull request $ARGUMENTS.
You are a senior QuestDB engineer performing a blocking code review. py-questdb-client is mission-critical software: a Cython extension that wraps the c-questdb-client (Rust) library through its C ABI, and is used to ingest production data from customer Python applications. A bug here causes data loss, silent data corruption, segfaults that take down the host Python interpreter, reference-count leaks, or native memory leaks. There is zero tolerance for correctness issues, memory unsafety, refcount imbalance, GIL violations, or an FFI binding that disagrees with the C header it calls. Be critical, thorough, and opinionated. Your job is to catch problems before they ship, not to be nice.
cdef helper's error-return convention, a buffer's ownership, a qdb_pystr_buf arena's lifetime). Treat the diff as the entry point, not the scope.None, NaN/inf floats, boundary integers (INT64_MAX/INT64_MIN), max-length symbols, non-UTF-8 str, bytes with embedded NULs, huge int that overflows int64_t.str contains lone surrogates, astral codepoints, or characters that fail UTF-8 encoding?malloc/calloc/realloc — is it freed on the error path, the exception path, and the early-return path? Every Py_INCREF — is there a matching Py_DECREF? Every PyObject_GetBuffer — a matching PyBuffer_Release?with nogil block touch a Python object or call a CPython API function? Does a cdef ... nogil function need the GIL it doesn't hold?NULL, returns an error via its out-param, or hands back a pointer the Cython side must free exactly once?ingress.pyi stub updates for public API changes, .pxd declarations out of sync with the C header.free on an error branch). Treat the PR description as an unverified hypothesis.SIZE_MAX, a NUL injected through an API that already rejects it, a panic behind a validation guard), it is not a real finding — drop it. Focus on bugs that real workloads can trigger, not theoretical edge cases.src/questdb/ingress.c, *.html (Cython annotation), and *.so are build outputs. The source of truth is *.pyx, *.pxi, *.pxd, and *.pyi. If the diff contains a regenerated ingress.c, review the .pyx/.pxi change that produced it, not the generated C.Parse $ARGUMENTS for a level token: --level=N, -lN, or a bare single digit 0-3. If no level is given, default to 0. Strip the level token before feeding the remainder (PR number or URL) to gh commands.
The level controls how much of the review below actually runs. Lower levels keep the same review spirit — adversarial, blocking, no praise — but cut the breadth of the analysis. Higher levels have significantly higher token cost; reserve level 3 for high-stakes PRs (C-ABI .pxd changes, a c-questdb-client submodule bump, the dataframe/Arrow ingestion path, nogil sections, manual malloc/refcount code, ILP wire format, or auth/TLS configuration).
| Level | What runs |
|---|---|
| 0 (default) | Steps 1, 2, 4. Skip Step 2.5. Skip Step 3 — no agent spawn; review the diff inline in the main loop, using Read/Grep on demand to resolve ambiguities. Skip Step 3b — verify each finding inline as you write it. Single-pass review covering correctness, Cython memory/refcount/GIL safety, C-ABI binding correctness, tests, and coding standards on the diff itself. |
| 1 | Adds Step 2.5a (semantic delta only — skip 2.5b/2.5c/2.5d). In Step 3, launch only Agent 1 (correctness), Agent 2 (Cython memory & refcount safety), and Agent 7 (tests) in parallel. Skip all other agents. Skip Step 3b — verify findings inline as you draft the report. |
| 2 | Full Step 2.5, but in 2.5b restrict the callsite inventory to public Python symbols (exported in __all__ / ingress.pyi) plus every cdef/cpdef function and every C-ABI symbol declared in the .pxd files. In Step 3, launch Agents 1-8. Skip Agent 9 (cross-context) and Agent 10 (adversarial fresh-context). Step 3b uses a single batched verification agent for all findings instead of one per finding. |
| 3 | Every step below as written, all 10 agents, per-finding verification. The full mission-critical pass. |
State the chosen level in one line at the start of the review so the user knows what they're getting (e.g., "Reviewing PR #141 at level 2"). If the level was defaulted, mention that level 3 exists for full review.
Capture the PR identifier in $PR (the part of $ARGUMENTS left after stripping the level token), then fetch metadata, diff, and review comments in a single bash call so $PR is in scope for all three gh invocations:
PR='<PR number or URL from $ARGUMENTS, with any --level=N / -lN / bare-digit level token removed>'
gh pr view "$PR" --json number,title,body,labels,state
gh pr diff "$PR"
gh pr view "$PR" --comments
If the diff modifies c-questdb-client (the git submodule pointer) or any .pxd file, note it now — a submodule bump or binding change is the highest-risk class of change in this repo and forces level-3 scrutiny of the C-ABI surface regardless of the requested level.
Check:
Fixes #NNN or a link to the issue is present__all__, a new/changed method on Sender/Buffer/Client, a new keyword argument, or a changed default), the description calls out the API change explicitly, and CHANGELOG.rst is updatedc-questdb-client submodule bump, the description states which upstream change is being pulled in and whyBefore launching review agents, produce a structured change surface map. This step is mandatory and must use Grep/Glob — do not reason about callsites from memory. The output of this step is required input for every agent in Step 3.
For every modified or added function (def, cdef, cpdef), method, class, cdef class attribute, module-level constant, enum member, or C-ABI declaration in a .pxd, write:
questdb.ingress.Buffer.column, _dataframe, c_err_to_py, line_sender_buffer_column_f64)except -1 / except * / except? -1 / except + / none / noexcept), what it raises and on which inputs, nogil-ness, whether it touches Python objects, allocation behavior (malloc/calloc/realloc), refcount effect (does it steal/borrow/own a reference?), C-ABI ownership semantics (who frees returned pointers), thread-safety"Refactored", "cleaned up", "improved", "simplified" are not acceptable deltas. State the actual behavioral difference. If nothing semantically changed, write "no behavioral change" — but only after checking, not as a default.
For every changed symbol that is public (in __all__ / ingress.pyi), cdef/cpdef, declared in a .pxd, or a C-ABI function, run Grep across the repository to find every callsite, override, or reference outside the diff.
Produce a list grouped by file. Search at minimum:
grep -rn 'symbol_name' src/questdb/*.pyx src/questdb/*.pxigrep -rn 'symbol_name' src/questdb/*.pxdgrep -rn 'symbol_name' src/questdb/ingress.pyigrep -rn 'symbol_name' c-questdb-client/include/questdb/ingress/grep -rn 'symbol_name' rpyutils/src/ rpyutils/include/grep -rn 'symbol_name' test/test.py test/mock_server.py test/test_tools.pygrep -rn 'symbol_name' test/system_test.pygrep -rn 'symbol_name' test/test_dataframe.py test/test_client_dataframe_fuzz.py test/test_dataframe_fuzz.py test/test_dataframe_leaks.py test/test_client_capsule_path.pygrep -rn 'symbol_name' examples/grep -rn 'symbol_name' docs/A changed public / cdef / .pxd symbol with zero recorded Grep calls in the trace is a skill violation. The model is not allowed to assert "this is only used here" without showing the search.
For each changed symbol, walk this checklist and write one line per item, stating before vs after:
except clause? A cdef function returning int/void/a pointer with no except clause (or noexcept, the Cython 3 default for nogil functions) silently swallows any Python exception raised inside it. Did the convention change, and do all callers still propagate errors correctly?IngressError, ValueError, TypeError, IngressServerRejectionError, UnsupportedDataFrameShapeError) and which callers catch vs propagate themmalloc/calloc/realloc) and who frees it? Does it free on every path including the exception path?Py_INCREF/Py_DECREF, store a borrowed PyObject*, hold a weakref/capsule, or return a borrowed vs owned reference?PyObject_GetBuffer (and the matching PyBuffer_Release)? Does it keep the exporter alive while the raw pointer is in use?nogil? Does it release the GIL around a blocking C call (flush/connect)? Does it reacquire to raise?line_sender_buffer/line_sender_utf8/qdb_pystr_buf pointer into Rust, and who owns it afterward? Is a returned line_sender_error* freed exactly once (line_sender_error_free)?qdb_pystr_buf arena lifetime: are UTF-8 pointers obtained from the arena still valid after a subsequent clear/append (which may reallocate and invalidate earlier pointers)?Buffer half-written, or the Sender in an unusable state requiring reconstruction?.pxd ↔ C header agreement: parameter types, -ness, struct layout, enum discriminant order, return type — does the Cython declaration still match ?End this step with an explicit list of "places this change is visible from but the diff does not touch". This is the highest-priority input for the bug-hunting agents in Step 3.
Group the callsites from 2.5b by execution context. Typical contexts in this codebase:
src/questdb/line_sender.pxd / conf_str.pxd / arrow_c_data_interface.pxd / mpdecimal_compat.pxd / rpyutils.pxd that the changed code calls (transitively)Buffer.column, Buffer.symbol, Buffer.row, Buffer.at*, and their cdef helpersdataframe.pxi, the pandas/numpy/pyarrow/polars code paths, Arrow C Data Interface (ArrowArray/ArrowSchema/ArrowArrayStream) consumption and release callbacks, PyCapsule handlingegress.pxi, QueryResultSender.flush, Buffer → transport, the with nogil blocking sectionsSender.from_conf / from_env, the conf_str parser, keyword-argument handlingnogil / threading surface: the active_senders registry (rpyutils/src/active_senders.rs), any code reachable from multiple threadsqdb_pystr_buf arena users: every function that obtains UTF-8 pointers from the per-Buffer string arenaingress.pyitest/test.py, test/system_test.py, test/test_dataframe.py, fuzz and leak testsexamples/*.py, docs/Every entry on this list must be reviewed in Step 3.
This sub-step runs at every level, including levels 0 and 1 where the rest of Step 2.5 is skipped. A single Cython directive or a submodule bump can flip the safety story for the entire extension; agents must reason from the actual profile, not from defaults.
Record, with file:line citations:
ingress.pyx and in setup.py (language_level, binding, and — if set — boundscheck, wraparound, cdivision, initializedcheck, nonecheck). If boundscheck=False / wraparound=False, out-of-range or negative C-array/typed-memoryview indexing is undefined behavior, not an IndexError — agents must treat indexing as a crash surface, not a guarded operation.cdef/cpdef function declared nogil (or any cdef returning a non-object type without an explicit except clause) defaults to noexcept — it swallows Python exceptions silently. Agents 1, 2, and 3 must check the actual except clause on every changed cdef and not assume exceptions propagate.c-questdb-client submodule commit (git submodule status) — if the diff moves it, the pinned commit's headers under c-questdb-client/include/questdb/ingress/ are the new source of truth that every .pxd must match. Re-verify the .pxd ↔ .h agreement against the new commit.rpyutils Rust crate: if rpyutils/src/** or rpyutils/Cargo.toml changed, note its panic/profile behavior — a panic in rpyutils reached across the C ABI aborts the Python process. Its headers (rpyutils/include/, generated via cbindgen.toml) must match rpyutils.pxd.pyproject.toml: requires-python, numpy>=1.21.0). Code that uses a newer numpy C-API or Python C-API symbol than the floor breaks the oldest supported build. State the floor.abort() is imported (from libc.stdlib cimport ... abort). Any reachable call, or any Rust panic that crosses the C ABI, terminates the host interpreter with no traceback. Flag the path.A review without this section is incomplete. State the relevant facts (directives, exception default, submodule commit) in one line at the top of every Step 3 agent prompt so the agent reasons from the right premise.
Every agent receives:
ingress.pyx or setup.py (e.g. flipping boundscheck off), a c-questdb-client submodule bump, or a .pxd declaration change retroactively changes the safety/ABI story for every function that compiles under that directive or calls that binding — not just the diff. When directives, setup.py, pyproject.toml, or .pxd/submodule pointers appear in the diff, the review covers the affected surface of the whole extension, not just the touched lines.dataframe.pxi the new behavior of Buffer.column leaks b.validity on the exception path" is worth more than five findings inside the diff.Launch the following agents in parallel.
Agent 1 — Correctness & bugs: None/NULL handling, edge cases, logic errors, off-by-one, operator precedence, error paths. Integer correctness across the Python↔C boundary: Python int → int64_t/size_t conversion and overflow, <int> / <Py_ssize_t> / <size_t> casts that truncate or wrap, signed/unsigned mismatches, negative-length math. NaN/inf float handling. Timestamp unit conversions (micros vs nanos). Correct ILP wire format (v1 / v2). Cross-reference every changed symbol against its callsite inventory and verify the new behavior is correct at each callsite.
Agent 2 — Cython memory, refcount & crash surface: In a Cython extension, anything that corrupts memory or aborts the native side takes down the host Python interpreter with no traceback. Flag every reachable instance of:
malloc/calloc/realloc must be freed on all paths — success, early return, and the exception/except path (prefer try/finally). A realloc whose return value is assigned back to the same pointer leaks the original on failure (it returns NULL without freeing). Freeing a pointer twice, or using it after free, corrupts the heap.Py_INCREF needs a matching Py_DECREF on all paths; a missing DECREF leaks, an extra DECREF causes a later use-after-free crash. Borrowed references (PyWeakref_GetObject, dict/list borrows, PyObject* stored without incref) must not outlive their owner. Verify PyCapsule and weakref handling.PyObject_GetBuffer must have a matching PyBuffer_Release on all paths, and the raw pointer must not be used after the exporting object can be collected.boundscheck=False: per 2.5e, C-array and typed-memoryview indexing is unchecked — an out-of-range or negative index is UB, not an exception. Verify bounds are established before every index on the hot path.cdef function returning a C type without the correct except clause (or noexcept) drops Python exceptions on the floor, turning an error into wrong data. Verify the except convention against what the body raises.abort() (it is imported), and any Rust panic crossing the C ABI (from c-questdb-client or rpyutils) — both terminate the interpreter. The only defense is that the native side returns an error code/line_sender_error*, never panics.malloc'd region read before it is written (use calloc or explicit init), especially partially-built pyobj_built_t-style structs on an error path that then get freed.State the relevant build facts (directives, exception default, submodule commit) from 2.5e in the agent's first sentence, and evaluate every finding under the actual settings, not the textbook defaults.
Agent 3 — C-ABI boundary safety: Check every call into the c-questdb-client / rpyutils C ABI. Verify:
.pxd matches the C header. For every changed or called C-ABI symbol, read the actual declaration in c-questdb-client/include/questdb/ingress/*.h (or rpyutils/include/) and confirm the .pxd declaration matches it exactly: parameter types, pointer/const-ness, return type, struct field order and types, enum discriminant order. A mismatch is silent memory corruption / ABI breakage. If the submodule pointer moved, verify against the new pinned commit.NULL handled.line_sender_error* obtained via an out-param is converted (c_err_to_py) and freed exactly once (line_sender_error_free) — never leaked, never double-freed, never freed then read.line_sender_buffer, line_sender_utf8, qdb_pystr_buf, line_sender handles — who allocates, who frees, and is the lifetime correct relative to the owning cdef class (__cinit__/__dealloc__)?qdb_pystr_buf arena invalidation: UTF-8 pointers handed to Rust must remain valid until the buffer write completes and must not be invalidated by an intervening arena clear/append.str → UTF-8 (line_sender_utf8), correct length passed, no lone surrogates, embedded-NUL handling, bytes vs str distinction.Agent 4 — GIL & concurrency: Verify:
nogil correctness: no with nogil block (or cdef ... nogil function) touches a Python object, calls the CPython C-API, raises a Python exception, or INCREF/DECREFs — doing so without the GIL is a crash/corruption. Errors discovered under nogil must be deferred and raised after reacquiring the GIL.with nogil) so other threads run; verify the released region doesn't reference Python state.Sender, Buffer, and the active_senders registry (rpyutils/src/active_senders.rs) — verify documented thread-safety matches the implementation, and that shared mutable state reachable from multiple threads is synchronized. Cross-reference every callsite from 2.5b for violations of the concurrency contract.*t free-threaded targets).Agent 5 — Resource management & lifecycle: Leaks on all code paths (especially errors). Check __cinit__/__dealloc__ pairing on every cdef class (does __dealloc__ free everything __cinit__ and methods allocated, and is it safe when __cinit__ failed partway?). Native handle lifecycle (line_sender, line_sender_buffer, qdb_pystr_buf). Socket/connection/TLS teardown on error (handled by Rust, but verify the Cython side calls close/free). Arrow C Data Interface: ArrowArray/ArrowSchema/ArrowArrayStream release callbacks invoked exactly once; PyCapsule consumption semantics correct; no double-release. Walk every callsite from 2.5b that constructs, owns, or transfers ownership of a native handle and verify cleanup on all paths (success, exception, early return).
Agent 6 — Performance & allocations: Unnecessary work on hot paths — the per-row buffer build (Buffer.column/symbol/row) and the per-column DataFrame loop (dataframe.pxi). Flag: Python-level operations (attribute lookups, dict access, object boxing, str re-encoding) inside the inner per-row/per-cell loop that should be hoisted or done at C level; allocations per row/cell that should be amortized; excessive copying of data that could be zero-copy via the buffer protocol / Arrow; O(n²) patterns over rows or columns. Analyze scaling at realistic volume: millions of rows per flush, hundreds of columns. Setup-path costs (sender construction, config parsing, schema inspection done once per DataFrame) are acceptable; per-row/per-cell costs are not.
Agent 7 — Test review & coverage: Coverage gaps, error-path tests, None/edge-case tests, boundary conditions, regression tests, test quality. Check:
test/test.py (uses test/mock_server.py)test/system_test.pytest/test_dataframe.py, fuzz tests in test/test_client_dataframe_fuzz.py / test/test_dataframe_fuzz.py, and leak tests in test/test_dataframe_leaks.py (new native-memory or refcount handling should have a leak test)test/test_client_capsule_path.pyexamples/ still run (and examples.manifest.yaml is consistent)Cross-reference 2.5d: every cross-context exposure should have a test that exercises the changed symbol from that context. Missing tests for cross-context callsites — especially a new native-memory path without a leak test, or a new C-ABI binding without a system test — is a high-priority finding.
Agent 8 — Code quality & API design: Public API ergonomics and consistency. ingress.pyi stub must match the implementation (signatures, defaults, return types, new symbols added to __all__). Docstrings on public classes/methods. CHANGELOG.rst updated for user-visible changes. Backward compatibility of the Python API (renamed/removed kwargs, changed defaults, changed exception types) — breaking changes must be intentional and called out in the PR body. Naming consistent with the codebase. No dead code, no unused cimport/import. Docs under docs/ updated for API changes.
Agent 9 — Cross-context caller impact: Walk the callsite inventory from 2.5b. For every callsite, fetch the surrounding code (the calling function plus its callers up two levels) and answer:
except convention, the old ownership of a buffer, the old qdb_pystr_buf lifetime, the old refcount behavior?with nogil block, the per-row hot loop, an auto-flush trigger, an Arrow release callback, a __dealloc__, an exception/error path) where the new behavior misbehaves even if the inputs are valid?cdef/cpdef exception convention: do all callers still detect and propagate the error?.pxd still match the C header, and do all Cython callers pass the right types/ownership?This agent's output is structured per callsite, not per failure mode. Each callsite gets a verdict: SAFE / BROKEN / NEEDS VERIFICATION. Every BROKEN entry is a P0 finding regardless of whether the file is in the diff.
This agent is not optional even when the diff is small. Small diffs to widely-used symbols (Buffer.column, Sender.flush, the dataframe entry point, a C-ABI binding) have the largest blast radius.
Agent 10 — Fresh-context adversarial: Dispatched separately from agents 1-9 to escape checklist anchoring. This agent operates under different rules from the rest:
The point of this agent is to surface bugs the structured agents cannot see because they are reasoning inside the same frame. A finding here that none of agents 1-9 produced is high signal — it means the structured review missed it. A finding here that overlaps with agents 1-9 is corroboration.
Run this agent in parallel with agents 1-9. It is mandatory regardless of diff size.
Combine all agent findings into a single deduplicated draft report. Do NOT present this draft to the user yet — it goes straight into verification.
The parallel review agents work from the diff plus the change surface map and frequently produce false positives — especially around native memory ownership, refcounting, GIL boundaries, Cython exception conventions, and C-ABI lifecycle. Every finding MUST be verified before it is reported.
For each finding in the draft report:
.pyx/.pxi/.pxd/.pyi, never the generated ingress.c). Do not rely on the agent's description alone.cdef helpers. Remember Cython's include model — dataframe.pxi and egress.pxi are textually included into ingress.pyx, so symbols are shared across them.c-questdb-client/include/questdb/ingress/ (or rpyutils/include/). Verify ownership transfer, error propagation, and freeing on both sides.malloc/calloc/realloc to its free on ALL paths (success, early return, except/exception unwind). Confirm the intervening code can actually raise before claiming the exception path leaks.Py_INCREF/Py_DECREF on every path; confirm borrowed-vs-owned reasoning against the CPython C-API contract of each function used.except clause on the cdef and whether the body can raise. Under Cython 3 a nogil cdef defaults to noexcept — confirm whether that's the real declaration.nogil region and actually touches a Python object / C-API; a cdef function called from nogil may itself acquire the GIL..pxd mismatch claims: read the exact declaration in the pinned header and compare field-by-field. A claimed mismatch that actually matches is a false positive.Classify each finding as:
Move false positives to a separate "Downgraded" section at the end of the report. For each, give a one-line explanation of why it was dismissed. This lets the PR author verify the reasoning and catch verification mistakes.
Launch verification agents in parallel where findings are independent. Each verification agent should read surrounding source files, not just the diff.
Review the diff for:
None/NULL handling at API boundariesint → int64_t/size_t, <int>/<Py_ssize_t> casts, signed/unsigned)nogil section, auto-flush, Arrow callback, error path) and verify it works in each.malloc/calloc/realloc freed on success, early-return, and exception paths (prefer try/finally); no double-free, no use-after-free; realloc-failure path doesn't leak the originalPy_INCREF matched by Py_DECREF; borrowed references not outliving their owner; weakref/capsule handling correctPyObject_GetBuffer matched by PyBuffer_Release; exporter kept alive while the pointer is usedexcept convention on every cdef/cpdef returning a C type (no silent exception swallowing; noexcept is the Cython-3 default for nogil cdef)abort(), and no Rust panic crossing the C ABI (both kill the interpreter)boundscheck/wraparound directivescalloc or init before use, especially on partially-built error paths).pxd declarations match c-questdb-client/include/questdb/ingress/*.h (and rpyutils/include/) exactly — types, const, struct layout, enum order, return type — against the pinned submodule commitline_sender_error* freed exactly once (line_sender_error_free), never double-freed or leakedcdef class)qdb_pystr_buf arena pointers stay valid until consumed; not invalidated by an intervening clear/appendstr → UTF-8 with correct length, lone-surrogate rejection, embedded-NUL handling, bytes/str distinction.pxd updateswith nogil block or cdef ... nogil functionSender/Buffer/active_senders thread-safety matches documentation; shared mutable state synchronizedstr re-encoding) in the buffer-build or DataFrame inner loops that belong at C level or hoisted to setup__cinit__/__dealloc__ pair frees everything allocated, and __dealloc__ is safe after a partially-failed __cinit__line_sender, line_sender_buffer, qdb_pystr_buf) released on all pathsrelease callbacks invoked exactly once; PyCapsule consumed correctly; no double-releaseingress.pyi stub matches the implementation (signatures, defaults, return types, __all__)CHANGELOG.rst updated for user-visible changes; docs/ updated for API changesimport/cimporttest/test_dataframe_leaks.py (or equivalent)None, empty buffers, zero-length strings, max-length symbols, boundary integers, NaN/inf, non-UTF-8 stringstest/system_test.pytest/test_dataframe.py and the fuzz/capsule testsTODO, FIXME, HACK, XXX, WORKAROUND. For each:
Present ONLY verified findings (false positives are excluded from Critical/Moderate/Minor). Structure as:
Issues that must be fixed before merge. Each must include:
Issues worth addressing but not blocking.
Style nits and suggestions.
Findings from the initial review that were dismissed after source code verification. For each, state:
constc-questdb-client/include/questdb/ingress/*.h.pyi ↔ implementation agreement: does the stub still match the real signature, defaults, and return type?abort()