Sub topic 12
Recording Provenance and License Metadata
Prerequisites
This chapter assumes you can use an AI coding assistant, work with Git branches and pull requests, and know what an open-source license is. It builds on the earlier chapters about copyrightability and license contamination. It is general education, not legal advice.
Why provenance records matter
Provenance means the recorded origin and history of a piece of code: who wrote it, with what help, under which license, and who checked it. Earlier chapters showed that the legal questions around AI-assisted code are unsettled. You can't resolve them with a record, but a record helps in three ways:
- Answering questions later. A customer audit, a due-diligence review, or a license complaint may arrive years after the commit. Reviewers and tools will have changed by then.
- Showing care. A record of review shows you took reasonable steps. That matters if a generated snippet turns out to match licensed code.
- Routing risk. If you know which changes involved AI, you can re-review them when a tool's terms change or a legal ruling arrives.
Provenance records should be cheap to write and easy to query. If they take effort, people skip them.
What to record
Not every fact deserves a field. Choose a small set that you can enforce.
| Fact | Where it lives | Why it helps |
|---|---|---|
| That AI assistance was used | Commit trailer or pull request template | Lets you find affected changes later |
| Which tool and version | Commit trailer | Tool terms and indemnity differ by vendor and plan |
| Who reviewed it | Commit trailer, review record | Shows a human made the final decisions |
| What the human changed | Commit body | Supports the human-authorship story |
| License of the file | SPDX header | States how the project distributes the file |
| Copyright holder | Header or REUSE metadata | Identifies who claims ownership |
| Third-party code found during review | Commit body, NOTICE file | Preserves attribution duties |
Do not record prompts by default. Prompts can contain confidential material, and keeping them in a public repository can leak it. If you need to keep prompts, store them in a private system with access controls.
Commit-level records
A commit message is the best place for per-change facts. It travels with the code through merges, forks, and history rewrites that keep messages. Git supports trailers, which are Key: value lines in the last paragraph of a message. Well-known examples are Signed-off-by and Co-authored-by. The names below are a team convention, not a standard, so agree on them and document them.
Add retry with exponential backoff to HTTP client
The retry loop was drafted with an AI assistant and then rewritten by hand.
I reviewed it for copied code and license notices.
AI-Assisted: yes
AI-Tool: example-assistant
Reviewed-by: Jane Developer <[email protected]>The body describes what the human did. The trailers are short and machine-readable. The statement "I reviewed it for copied code and license notices" is a claim, so write it only if it is true.
Because the trailers are plain text, you can query them with ordinary Git commands:
git log --format="%h %an %s" --grep="^AI-Assisted: yes"This lists every commit whose message has a line starting with AI-Assisted: yes. You can run the same search before a release, an audit, or a policy change.
Choosing trailer values
Keep values simple. yes and no are easier to enforce than a scale like "mostly" or "a little". If you want more detail, add a second trailer, such as AI-Scope: tests only, instead of overloading the first.
A commit that squashes several commits loses their trailers unless someone copies them. Check how your host builds squash messages. If it keeps only the pull request title, put the trailers in the pull request description and make the merge process copy them.
File-level license metadata
Commit trailers describe a change. License headers describe a file as it exists today. Every source file should state its license in a form that humans and tools can read. The SPDX standard defines short license identifiers such as MIT, Apache-2.0, and GPL-3.0-only.
# SPDX-License-Identifier: Apache-2.0
# Copyright (c) 2026 Example Corp.
def clamp(value: float, low: float, high: float) -> float:
return max(low, min(value, high))This header states the license under which the project distributes the file. It does not prove the code is copyrightable, and it does not prove nobody else owns part of it. It records the project's intent and makes that intent clear to downstream users.
Two points matter for AI-assisted files:
- Do not copy headers from the assistant's output. If a generated file arrives with a different license header or a copyright line for someone else, treat it as a warning. It may mean the model reproduced existing code. Investigate before you change or remove it.
- Do not add a header you cannot justify. A copyright line for your company claims ownership. Make sure your employment and client contracts support that claim.
If your project uses many file types or vendored data, consider the REUSE specification. It uses the same SPDX tags, adds SPDX-FileCopyrightText, and lets you license files that cannot hold comments through a separate dependency file. A reuse lint command checks compliance.
Automating the check
Policies that depend on memory fail. Add a CI check that fails when a new source file has no SPDX identifier. This script scans Python files under src/:
import sys
from pathlib import Path
def has_spdx(path: Path) -> bool:
with path.open(encoding="utf-8", errors="ignore") as f:
head = [next(f, "") for _ in range(5)]
return any("SPDX-License-Identifier:" in line for line in head)
missing = [p for p in Path("src").rglob("*.py") if not has_spdx(p)]
for p in missing:
print(f"missing SPDX header: {p}")
sys.exit(1 if missing else 0)How it works: has_spdx reads at most five lines from the top of a file. next(f, "") returns an empty string at end of file, so short files do not raise an error. The script collects every file that lacks the tag, prints each one, and exits with status 1, which makes the CI job fail.
This check has limits, and you should know them:
- It checks presence, not correctness. A file with
SPDX-License-Identifier: MITin a project licensed underGPL-3.0-onlypasses. - It covers only
.pyfiles undersrc/. Extend the glob for other languages and directories. - It flags old files too. On an existing repository, either fix every file first or limit the check to files changed in the pull request.
- It cannot detect copied code. For that, use a snippet-matching or software composition analysis tool, and treat its matches as leads for human review, not verdicts.
You can enforce commit trailers the same way. A commit-msg hook or a CI step can require that every commit include an AI-Assisted: line with yes or no. Requiring an explicit answer is better than requiring the trailer only when AI was used. The explicit form shows the author considered the question.
How the pieces fit together
The loop back to the author matters. Records are most accurate when the same person who made the change writes them, while the details are fresh.
Edge cases and common errors
- Partial use. An assistant may only rename variables or suggest a one-line completion. Decide in your policy where the line is. A common choice is to mark any change where the tool produced a substantial block of code, not every autocomplete. Whatever you pick, apply it consistently.
- Rewritten history. Rebase and squash can drop trailers. Copy them forward deliberately.
- Multiple authors. If several people contributed to a change, each person's use of AI should be reflected. One trailer on the commit is enough if the team agrees it covers the whole change.
- Found a match. If review turns up code that looks copied, record what you found and what you did: removed it, rewrote it, or kept it with the required notice and license. Add third-party license texts to a NOTICE or similar file when the license requires it.
- False reassurance. A tidy record does not cure a license problem. If a generated function reproduces copyleft code, an
AI-Assisted: yestrailer does not remove the obligations. The record only helps you find and fix it. - Retention. Decide how long you keep records. Git history is permanent by default, which is useful for audits but unsuitable for personal data or confidential details. Keep those out of commits.
Summary of the working model
Record per-change facts in commit trailers and per-file facts in SPDX headers. Let CI enforce presence, and let humans judge accuracy. Treat the record as evidence of process, not as a legal shield. Keep it small enough that people actually maintain it.
Exercise
Your repository squash-merges pull requests, and the squash commit message contains only the pull request title. A teammate's commit had the trailer AI-Assisted: yes. What happens to your ability to find AI-assisted changes with git log --grep, and what two things could you do about it?
Show answer
The trailer is lost from the main branch history, so the search will miss that change. You could configure or script the merge so the squash message includes the pull request description, where the trailers are copied. You could also add a CI check on the pull request that requires an AI-Assisted: line in the description and a merge step that copies it into the final commit message.
Exercise
The SPDX check script passes on a new file whose header says SPDX-License-Identifier: GPL-3.0-only in a project licensed under Apache-2.0. Why does it pass, and how would you catch this kind of problem?
Show answer
The script only checks that the string SPDX-License-Identifier: appears in the first five lines. It does not read the value or compare it with the project license. To catch the mismatch, extend the script to parse the identifier and compare it with an allowed list, or use a tool such as reuse lint or a license scanner. Human review should also look at any header that differs from the rest of the project, since it may signal copied code.