Sub topic 11
Contributing AI-assisted code to open-source projects
This chapter assumes you know Git and code review. It also assumes you know what open-source licenses are and have read the earlier chapters on license contamination and tool terms. It is general education, not legal advice.
Why contributing is a separate case
When you send a pull request, you tell the maintainers that you have the right to submit the code under the project's license. AI assistance makes that claim harder to check. The generated code might reproduce licensed code, and you may not be able to trace where it came from.
Two things sit behind your contribution:
- The project license. It defines how others may use the code once it is merged.
- The contributor terms. These are the rules for what you promise when you submit. Many projects use a Contributor License Agreement (CLA), which is a signed grant of rights to the project. Others use a Developer Certificate of Origin (DCO), which is a sign-off line stating you have the right to submit the work.
What a DCO sign-off claims
A DCO sign-off is added with git commit -s. It appends a Signed-off-by: line. By adding it, you certify that you wrote the contribution, or that it is based on suitable open-source code, or that someone else who had the right gave it to you. You also certify that you have the right to submit it under the project's license.
AI-generated code does not fit these statements neatly. If you cannot say where a block came from, you cannot honestly certify it. The sign-off is your personal claim, and the tool does not make it for you.
Project policies vary
Projects have taken different positions. Some ask contributors to disclose AI use. Some restrict AI-generated code or ban it. Others have no rule yet. Check these files before you contribute:
CONTRIBUTING.mdand any AI policy document.- The pull request template.
- The CLA or DCO text.
- Recent discussions or rejected pull requests that mention AI.
A policy can change, so read the current version each time you contribute to a project you have not touched recently.
A workflow before you submit
The steps in the diagram work like this:
- Understand every line. Reviewers will ask about your code. If you cannot explain it, do not submit it.
- Check for copied code. Search distinctive snippets in code search engines. Look for license headers or comments that came with the output. Run a license or snippet scanner if your organization has one.
- Check license compatibility. Code from a GPL project cannot go into a project under an incompatible license. Ask whether the output resembles anything you know.
- Record provenance. Use the commit conventions from the provenance chapter, so maintainers can see how the change was made.
Disclosure in practice
When a project asks for disclosure, say what the tool did and what you did. A short note in the pull request is enough:
This change adds input validation to the parser.
I drafted the validation loop with an AI assistant, then rewrote it
and added the tests by hand. I checked it for copied code and found none.
Signed-off-by: Jane Developer <[email protected]>Disclosure helps maintainers decide how closely to review. It does not move your responsibility to the tool.
Common errors
- Assuming the tool's terms cover the project. An indemnity offer, if any, usually covers you as a customer. It does not cover the project or its other users.
- Signing off without checking. The DCO line is a legal statement. Do not add it automatically to code you have not reviewed.
- Submitting an employer's code. If your employer owns your work, you may need permission to contribute. The employment chapter covers this.
- Pasting confidential code into a prompt. The tool may have received private code that then appears in your contribution.
- Ignoring a ban. Submitting banned AI code can get your pull request closed and damage your standing with the project.
Exercise
You used an AI assistant to write a function for an open-source project that requires a DCO sign-off. The function looks very similar to code you once saw in a GPL project, and the project is MIT-licensed. What should you do before you sign off?
Show answer
Do not sign off yet. Compare the function with the GPL code and search for matches. If it copies or closely follows the GPL code, rewrite it independently or drop it, since GPL code cannot go into an MIT project without meeting the GPL terms. If you cannot rule out copying, treat the origin as unclear and write the code yourself. Then record provenance and disclose AI use if the project asks.