Repository navigation
CYF AI Code Reviewer
The CYF AI Code Reviewer is a GitHub App that gives students instructional feedback on pull requests.
It is intended to supplement, not replace, review by a volunteer. The reviewer looks for bugs and meaningful opportunities to improve the student's reasoning and coding skills while avoiding unsupported, speculative, or purely stylistic feedback.
A review starts when someone adds the Needs Review label to a pull request in a repository where the GitHub App is installed.
Opening a pull request or pushing additional commits does not start a review by itself.
Before starting, the application checks that:
- The label event was not generated by another bot.
- The person adding the label is authorized to use the reviewer.
- The pull request is eligible for another AI review.
In production, authorization is based on membership of the configured GitHub organization. In development, it uses a configured allowlist of GitHub usernames.
Whether the same pull request can be reviewed more than once is controlled by MULTIPLE_REVIEWS_ALLOWED. It defaults to false, although the supplied example environment files set it to true.
When repeated reviews are disabled, the reviewer checks the pull request timeline for previous activity from the reviewer bot and does not review the pull request again if it has already participated.
The reviewer fetches the changed files from GitHub at the pull request's current head commit.
For each changed file, it sends:
- The GitHub diff, including the added lines that may receive feedback.
- The complete file at the pull request head when it is a text file and fits within the context limits.
Full-file source is supporting context only. It helps the model trace how a change interacts with the rest of the file, but feedback must still be about lines added by the pull request.
Full-file source is not included when:
- The file was deleted.
- The file appears to be binary or is not valid UTF-8 text.
- The file exceeds the 256 KiB per-file limit.
- Including it would exceed the 1 MiB total full-file context limit for the review.
- GitHub could not return the file contents.
Deleted and unchanged code may help the model understand a change, but they are not valid feedback targets.
The reviewer currently requests up to 100 changed files from GitHub. It does not clone the repository or automatically include other unchanged files, repository documentation, linked issues, or the pull request description.
The application makes one request to OpenRouter for the entire pull request. All review categories are considered together so the model can prioritize the most useful findings across files and categories.
The model, reasoning effort, and completion-token limit are configurable. Their defaults are:
- Model:
openai/gpt-6-luna - Reasoning effort:
medium - Maximum completion tokens:
25000
The request uses a temperature of 0 and requires a structured JSON response.
The model is instructed to return no more than five distinct findings. Five is a maximum, not a target, and returning no findings is considered a valid result.
Findings are prioritized by:
- Impact
- Confidence
- Educational value
The model is also instructed to avoid repeating the same or very similar feedback. When the same problem occurs in several visible places, it should give the lesson once at a representative location and briefly mention the other occurrences.
The current review checklist covers five categories.
The reviewer looks for demonstrable problems such as:
- Logic errors
- Incorrect state changes
- Variable-scope bugs
- Mishandled inputs
- Boundary-condition errors
Bug reports should explain what triggers the problem and what incorrect behavior results.
The reviewer looks for choices that make the code materially harder to understand or change, including:
- Duplication that would benefit from shared code
- Unnecessary coupling
- Difficult control flow
- Excessive nesting
It should not recommend abstraction or restructuring without explaining the concrete benefit.
The reviewer considers issues such as:
- Misleading variable or function names
- Unnecessary indirection
- Structure that obscures intent
- Boolean branches that could more clearly return their condition
- Temporary variables that add no useful clarity
Shorter code is not automatically clearer, and descriptive intermediate variables may be useful.
The reviewer looks for concrete unnecessary work or resource use.
It should explain when the extra work occurs and why it matters. It is instructed not to report speculative scaling concerns or insignificant micro-optimizations.
The reviewer considers only comments actually added by the pull request.
It may report comments that:
- Are misleading
- Contradict the implementation
- Merely repeat obvious code without adding useful context
It must not invent hypothetical comments, criticize code for comments that were never added, or treat language directives such as "use strict" as comments.
Feedback is written for students who are learning to code.
Each finding should:
- Identify a specific choice in the supplied code.
- Explain its concrete consequence.
- Help the student understand why it matters.
- Use a respectful and instructional tone.
- Include a focused leading question or small suggestion when useful.
The reviewer should explain bugs clearly, but it should not normally provide a complete replacement implementation. It should also avoid vague questions, generic lectures, personal preferences, and advice based on unsupported assumptions.
OpenRouter is asked to return a JSON object matching a strict response schema.
Each finding must contain:
- A feedback type
- A checklist topic
- A filename
- Feedback text
- A severity from 1 to 10
- One line number or contiguous line range
If the model returns a response that does not match the schema, the application retries the request once.
After receiving a valid response, the application performs additional checks. It removes findings when:
- The named file is not part of the pull request.
- The line-number format is invalid.
- Any targeted line was not actually added by the pull request.
This prevents feedback based on full-file context from being posted against pre-existing code.
Validation can verify the structure and location of feedback, but it cannot guarantee that every model-generated explanation is correct. Students and volunteers should still evaluate AI feedback critically.
If there are valid findings, the application posts them as inline comments in a single GitHub pull request review. Each comment is anchored to an added line or added-line range.
If there are no valid findings, it posts a pull request comment explaining that the AI reviewer had no comments and that the student should wait for a volunteer review.
After completing the workflow, the application:
- Removes the Needs Review label.
- Adds the Reviewed label.
- Posts a completion message explaining whether another AI review may be requested.
Each generated feedback point is stored in PostgreSQL with information including:
- Feedback category and topic
- Filename and line number
- Feedback text
- Severity
- Pull request head commit
- Model used
- Exact system prompt used
The exact prompt is retained so that feedback can later be evaluated in the context of the instructions that produced it.
Each inline GitHub comment includes a link where an authorized user can like or dislike the feedback. Users authenticate through GitHub before submitting a rating, and each user may rate a feedback point once.
This feedback is intended to help evaluate and improve the reviewer over time.