Sub topic 11
Contributing AI-assisted code to open-source projects
This chapter assumes you have read the earlier chapters on human authorship, license contamination and tool terms. It also assumes you can fork a repository, open a pull request and read a CONTRIBUTING file. It is general education, not legal advice.
Why contributing is a different situation
Using generated code inside your own private project mostly concerns your own risk. A contribution to someone else's open-source project is different. You are making a statement to the maintainers, and often to everyone who later uses the project, that you have the right to offer this code under the project's license.
Three things can go wrong with AI-assisted code in that setting:
- Provenance. The tool may have reproduced code from a source under an incompatible license. Chapter-level reminder: this is the license contamination problem, and a contribution passes it on to the whole project.
- Ownership. Parts of the output that no human authored may not be protected by copyright in some jurisdictions. The project may then be unable to license or enforce rights over those parts the way it expects.
- Review burden. Maintainers are volunteers. A large patch that the submitter does not understand costs them time, whatever its license status.
What you promise when you submit
Projects collect assurances in different ways. The mechanism determines what you are asserting.
| Mechanism | How it appears | What you assert | AI-specific concern |
|---|---|---|---|
| No formal process (inbound = outbound) | Your pull request is assumed to be under the project's existing license | You have the right to license the code under that license | You alone judge whether generated code is clean |
| Developer Certificate of Origin (DCO) | A `Signed-off-by:` line in each commit | You wrote it, or it derives from code under a compatible open-source license, or someone who certified it passed it to you | You cannot truthfully certify what you have not checked |
| Contributor License Agreement (CLA) | A signed agreement, often through a bot | You grant the project a license and usually warrant that the work is yours to give | Warranties about originality can be breached by copied output |
The DCO is short and worth reading in full at developercertificate.org. In plain terms, your sign-off says one of four things: you created the contribution and may submit it, you based it on existing code whose license permits that, someone else gave it to you with the same certification, or it is a matter of public record. Generated code fits none of these automatically. It fits them only after you have reviewed it and have a reasonable basis to believe it is original or properly licensed.
A sign-off is a human act. Some projects say explicitly that tools and bots must not add Signed-off-by lines. The person submitting remains responsible for the certification.
Project AI policies vary widely
There is no single rule. Some projects have banned AI-generated contributions, citing unsettled copyright and license questions. Gentoo, NetBSD and QEMU have been reported to do so, and policies change, so check the current text. Others permit AI assistance if you disclose it and take full responsibility. Many have no stated policy.
Before you open a pull request, look in these places:
CONTRIBUTING.mdand anyAI_POLICYor similar file.- The pull request template, which may include an AI disclosure checkbox.
- The project's governance or legal pages, if it belongs to a foundation.
- Recent closed pull requests and mailing-list threads, which show how maintainers apply the policy in practice.
If a project bans AI-generated code, "I rewrote it a little" is not a safe reading. Ask the maintainers how they define the ban before you submit anything. If there is no policy, disclosing your use is a low-cost courtesy that lets maintainers decide how closely to review.
License compatibility still decides
A contribution must be licensed compatibly with the project. The usual direction of flow matters.
- Code under MIT, BSD or Apache-2.0 can generally be included in a GPL project.
- GPL code cannot be included in an MIT project without changing that project's licensing terms.
- Apache-2.0 and GPLv2 have a known compatibility problem. Apache-2.0 and GPLv3 are compatible.
AI tools do not know which license your target project uses. If you prompt in the context of a permissively licensed project and the tool reproduces a GPL function from its training data, the contribution carries an obligation the project cannot meet. If you cannot tell where a non-trivial block came from, treat it as unverified.
Practical checks before submitting:
- Search for distinctive identifiers, comments or error strings from the generated code in public code search.
- Run a snippet-matching or license-scanning tool if your organization has one.
- Be most careful with long, unusual or highly specific blocks such as parsers, cryptographic routines, and algorithms with distinctive structure. Short idiomatic code, such as a loop or a getter, is much less likely to be protectable or traceable.
- Prefer using the assistant to explain an approach and writing the implementation yourself when the project is strict.
Whose permission do you also need?
Your right to contribute can be limited by people other than the project.
- Your employer. Employment agreements often assign work product to the company. If you contribute on your own time but the code relates to your job, the company may own it. Many companies require approval before contributions and have rules on AI tools.
- Your client. Contract work may forbid sending client code to external tools or publishing derived code.
- Your tool's terms. Some terms restrict how output may be used or place conditions on it. Chapter on tool terms covers this. Confirm that nothing there blocks open-source release.
- Confidential material in prompts. If you pasted private code into a prompt and the output closely follows it, publishing the output may disclose it. See the confidentiality chapter.
A contribution workflow
The diagram shows a practical sequence. Each step can end the process early, and that is the intended behavior.
Disclosing in the commit message
Where a project asks for disclosure, put it in the commit message, where it stays with the history. Trailer names are a team or project convention and are not a standard, so follow what the project documents. If it documents nothing, a plain sentence in the pull request description works.
This example uses git commit -s, which adds the Signed-off-by: line from your configured name and email, and --trailer (Git 2.32 or later) to add a disclosure line:
git commit -s \
-m "Add retry with exponential backoff to HTTP client" \
-m "Drafted with an AI assistant, then rewritten and tested by hand. Checked for copied code." \
--trailer "Assisted-by: example-assistant"The resulting message ends with the two trailers:
Add retry with exponential backoff to HTTP client
Drafted with an AI assistant, then rewritten and tested by hand. Checked for copied code.
Assisted-by: example-assistant
Signed-off-by: Jane Developer <[email protected]>Projects that use the DCO usually enforce sign-offs in CI. You can run the same check locally before pushing. This script lists commits on your branch that lack a Signed-off-by: line:
import subprocess
import sys
def git(*args: str) -> str:
result = subprocess.run(
["git", *args], capture_output=True, text=True, check=True
)
return result.stdout
base = sys.argv[1] if len(sys.argv) > 1 else "origin/main"
missing = []
for sha in git("rev-list", f"{base}..HEAD").split():
message = git("show", "-s", "--format=%B", sha)
if not any(line.startswith("Signed-off-by:") for line in message.splitlines()):
missing.append(sha[:10])
for sha in missing:
print(f"missing Signed-off-by: {sha}")
sys.exit(1 if missing else 0)If it reports missing commits, git rebase --signoff origin/main adds the line to each. Do that only after you have reviewed the content, because the line is a certification.
Common mistakes
- Treating the tool as the author. Listing an assistant in place of your own sign-off does not transfer responsibility. You remain the one answering for the code.
- Submitting code you cannot explain. Maintainers will ask why a choice was made. "The tool wrote it" is a reason to close the pull request.
- Large, unrequested patches. Open an issue first. A small, focused change is easier to review and easier to check for provenance.
- Mixing generated code with copied examples. Documentation snippets, Stack Overflow answers and blog posts carry their own licenses. An assistant may reproduce them without telling you.
- Ignoring tests and headers. New files should carry the license header the project uses. The earlier chapter on license metadata shows how to automate the check.
- Assuming a past acceptance sets precedent. A maintainer who merged one AI-assisted patch may still decline the next, especially when policies change.
Key points
- Your contribution is a representation that you have the right to license it. AI assistance does not reduce that responsibility.
- Read and follow the project's AI policy first. Bans are real and enforced.
- A DCO sign-off or CLA is a statement you make personally, after review.
- Check employer, client and tool-term restrictions before you publish.
- Disclose where the project asks, using its format.
Exercise
A project uses the DCO and has no written AI policy. You generated a 120-line parser with an assistant, tested it, and want to submit it. List three steps to take before adding Signed-off-by:, and say why a long parser deserves extra care.
Show answer
(1) Review and understand every line, and run the tests. (2) Search for distinctive identifiers or strings from the code in public code search, or run a license scanner, to look for copied code and its license. (3) Confirm that your employer or client allows the contribution and that your tool's terms do not restrict publishing the output. A 120-line parser is long, specific and structurally distinctive, so it is more likely to match existing code than a short idiomatic snippet. Disclosing the AI use in the commit message or pull request is also sensible when no policy exists.
Exercise
Your project is MIT-licensed. Your assistant produced a function that you later find is nearly identical to a function in a GPL-licensed library. What should you do, and why can you not simply sign off and submit?
Show answer
Do not submit it as is. A DCO sign-off certifies that you may submit the code under the project's license, and GPL-derived code cannot be placed under MIT terms. Rewrite the function independently, or drop it and use a compatible alternative, then re-review. Anyone who wants the GPL function must follow GPL terms, which the MIT project cannot satisfy for its users.