Sashiko Documentation

repository·main·Indexed 20 days ago

https://github.com/sashiko-dev/sashiko

Sashiko is an agentic code review system for the Linux kernel (version 0.2.5) that automates patch reviews using a multi-stage protocol. It supports monitoring mailing lists, GitHub, and GitLab, and provides a daemon mode with a Web UI and API. The system integrates with various LLM providers including Gemini, Claude, AWS Bedrock, and Vertex AI, and includes specialized review prompts and skills for the Linux kernel and iproute2.

Tokens
279.2K
Snippets
537
Records
1.2K
Agent score
76%

What's inside Sashiko

  1. Use the Review PR Skill

    main

    The review-pr skill is designed to perform scrutinizing code reviews against project standards (such as GEMINI.md) and design documents. It automatically detects relevant design files, categorizes findings by severity, and generates actionable diffs.

    When to use: Use this skill when you need to review a Pull Request (PR), a specific diff, or particular components of a codebase.

  2. Understand the NFS Server Subsystem architecture

    main

    The NFSD (fs/nfsd/) implements the Linux NFS server for versions v2, v3, and v4.x. The subsystem is composed of several key components including the XDR codec, stateid/delegation state machines, file handle validation, client lifecycle management, callbacks, and session slots.

    File Layout Overview

    FilesDomain
    nfs4xdr.c, nfs3xdr.cXDR codec, page encoding
    nfs4state.c, nfs4proc.cNFSv4 state, operations, copy offload
    n3proc.c, nfsproc.cNFSv2/v3 operations
    vfs.c, nfsfh.c, nfsfh.hVFS interface, file handles, splice
    nfs4callback.cCallbacks
    nfs4layouts.cpNFS layouts
    filecache.c, nfscache.cFile cache, DRC
    export.c, nfsctl.c, netlink.cExport mgmt, admin, netlink
    nfs4recover.cGrace period, reclaim
    state.h, netns.hData structures
  3. Configure and use the File Analyzer Agent

    main

    The file-analyzer agent is designed to perform deep regression analysis on a single FILE-N group (all changes to a single source file) from a Linux kernel commit. It uses a multi-phase approach involving bulk context loading, subsystem guide analysis, and semcode-based code lookups to identify regressions.

    Agent Configuration:

    • Model: opus
    • Tools: Read, Write, Search, and various mcp__plugin_semcode_semcode__ tools (e.g., find_function, find_type, find_callers, find_calls, find_callchain, grep_functions, find_commit).

    Core Constraints:

    • Ignore: fs/bcachefs and test program issues (unless causing system instability).
    • Exclusions: Do not report assertion, WARN, or BUG removals as regressions.
    • Methodology: Never read entire source files; always use semcode tools for lookups.
    --- 
    name: file-analyzer
    description: Performs deep regression analysis on a single FILE-N group
    tools: Read, Write, Search, mcp__plugin_semcode_semcode__find_function, mcp__plugin_semcode_semcode__find_type, mcp__plugin_semcode_semcode__find_callers, mcp__plugin_semcode_semcode__find_calls, mcp__plugin_semcode_semcode__find_callchain, mcp__plugin_semcode_semcode__grep_functions, mcp__plugin_semcode_semcode__find_commit
    model: opus
    ---
  4. iproute2 Review Documentation File Structure

    main

    The review documentation is organized into several specialized files. Use this table to determine which file to load based on the patch content being reviewed.

    FilePurposeWhen to Load
    review-core.mdMain entry point with review checklistAlways start here
    technical-patterns.mdCore technical patterns and common bugsLoad first (per review-core.md)
    coding-style.mdComplete style guideStyle questions, new files
    argument-parsing.mdArgument handling patternsChanges to argument parsing
    json.mdJSON output implementation and validationChanges to output functions
    netlink.mdNetlink protocol patternsNetlink request/response code
    false-positive-guide.mdAvoiding incorrect review findingsWhen uncertain about violations
  5. What is Coccinelle Semantic Patch Generation?

    main
    Coccinelle semantic patches (SmPL) are used for systematic, pattern-based code transformations across the kernel tree. Instead of manual file edits, SmPL allows you to define repeatable patterns for changes like function renames, API signature updates, or wrapping calls with locks. This approach is preferred whenever a change follows a consistent pattern across multiple files or subsystems.
  6. Overview of Sashiko System Architecture

    main

    Sashiko is a distributed system for tracking, applying, and reviewing Linux Kernel changes. It uses a modular, single-node architecture built with Rust's async runtime (tokio).

    Core Workflow:

    1. Ingestion: Patches are ingested via NNTP (Live Mode) or local git archives (Offline/Test Mode).
    2. Fetching: A Fetch Agent handles manual SHA1 submissions with throttling.
    3. Processing: A Patch Worker parses emails into Patch and Patchset structures, detects git baselines, and applies them in a sandboxed Git worktree.
    4. Review: An AI Review Worker sends patches to LLMs for automated feedback.
    5. Persistence: All metadata and results are stored in a libSQL (Turso) database.
    6. Interface: An Axum-based Web API and a minimalistic Nginx-served frontend provide access to the data.
  7. Overview Analyzer Agent: Role and Scope

    main

    The overview-analyzer agent performs a holistic analysis of an entire diff as a single unit. Unlike per-file or per-function agents, its primary purpose is to identify issues that span multiple hunks or functions—inconsistencies that are invisible when looking at individual changes in isolation.

    Scope Boundaries

    To maintain efficiency, the agent adheres to strict boundaries:

    • DO NOT walk callstacks or identify side effects (this is the responsibility of side-effect.md).
    • DO NOT investigate per-function regressions (this is the responsibility of review.md).
    • DO focus on cross-hunk inconsistencies, code duplication, API clarity, global variable changes, and subsystem rule violations.
  8. Maintain SMB Direct (RDMA) Credit Grant Ordering

    main

    When working with the SMB/ksmbd subsystem, you must ensure that the negotiate response is the very first message that grants credits to the peer. Sending credit-granting messages (via data transfer messages) before the negotiate response causes protocol violations, connection failures, or undefined behavior on the client side.

    Credit Granting Mechanism

    Credits control the number of outstanding send requests. Credits are set via manage_credits_prior_sending() in two places:

    1. The negotiate response: smb_direct_send_negotiate_response() in fs/smb/server/transport_rdma.c.
    2. Data transfer messages: smb_direct_create_header().

    Work Item Chain

    The smbdirect_socket structure (defined in fs/smb/common/smbdirect/smbdirect_socket.h) uses two work items that can trigger credit-granting sends:

    Work itemHandler (ksmbd)Effect
    recv_io.posted.refill_worksmb_direct_post_recv_credits()Posts receive buffers, then queues idle.immediate_work if any credits were posted
    idle.immediate_worksmb_direct_send_immediate_work()Calls smb_direct_post_send_data() with zero payload, which sends a data transfer PDU carrying credits_granted

    The correct execution flow is: recv_io.posted.refill_work handler posts buffers $\rightarrow$ calls queue_work(sc->workqueue, &sc->idle.immediate_work) $\rightarrow$ idle.immediate_work handler sends the empty data transfer message that grants credits.

  9. Correctly use WARN_ON at EL2

    main

    At EL2 in nVHE/pKVM, BUG_ON() and WARN_ON() both expand to BRK. This means there is no "warn and continue" semantics; the hypervisor will panic and the code following the macro is unreachable.

    How to test if a WARN_ON(cond) is used correctly: Determine if cond evaluates to true through contract-permitted inputs or only through invariant violations.

    • Incorrect Use (Flag as bug): cond is true due to host-supplied input (post-de-privilege), allocator/lookup outcomes, hardware/firmware return values, or concurrency races. In these cases, the function should return an error instead of asserting.
    • Correct Use: cond is true only when EL2's own internal invariants are violated (e.g., a slot EL2 just populated is NULL, or a refcount EL2 just incremented is zero).

    Critical Warning: Patterns like if (WARN_ON(err)) { /* recovery */ } are dead code. The WARN_ON will trigger a BRK and panic before the recovery path is ever reached.

  10. Configure UID/GID mappings for user namespaces

    main

    When using user namespaces, you must map container IDs to host IDs using the /proc/PID/uid_map and /proc/PID/gid_map files. The format for these files is:

    <container_id> <host_id> <count>

    Best Practices:

    • Ensure mappings do not overlap incorrectly.
    • Ensure the container's root user maps to an appropriate host UID.
    • Consult /etc/subuid and /etc/subgid if required by the system configuration.
    • Note that the mount namespace inherits user namespace ownership; some mounts may require the MS_BIND flag when used within a user namespace.
  11. Use `u64` for all AMDGPU Ring Buffer Write Pointers

    main

    To prevent integer truncation when ring buffers are large or write pointers exceed the 32-bit range, all write pointer (wptr) related variables, parameters, and struct fields must use the u64 type.

    Required Types:

    • struct amdgpu_ring.wptr must be u64.
    • struct amdgpu_fence.wptr must be u64.
    • All function parameters representing write positions must be u64.
    // CORRECT: both wptr parameters are u64
    static void func(struct amdgpu_ring *ring, u64 start_wptr, u64 end_wptr)
  12. Handle D-Bus errors (DBUS-007 & DBUS-008)

    main

    When returning errors in a D-Bus context, use the appropriate sd_bus_error functions:

    • sd_bus_error_set_errno(error, r): Sets error based on an integer error code.
    • sd_bus_error_set_errnof(error, r, "format", ...): Sets error with a custom message.
    • sd_bus_error_set_const(error, CODE, "message"): Sets a well-known D-Bus error.

    In method callbacks, ensure all error paths set the sd_bus_error and that the success path explicitly returns a reply using sd_bus_reply_method_return.

    /* Return error to caller */
    return sd_bus_error_set_errno(error, r);
    
    /* With custom message */
    return sd_bus_error_set_errnof(error, r, "Failed to %s: %m", operation);
    
    /* Well-known D-Bus error */
    return sd_bus_error_set_const(error, SD_BUS_ERROR_INVALID_ARGS, 
                                  "Invalid argument");