Skip to content

Commit 8f05036

Browse files
authored
feat(github): surface team-session attribution (#129012)
* feat(github): surface team-session attribution Worked on by: - @steipete * fix(github): preserve PR body after attribution Worked on by: - @steipete
1 parent 610fefd commit 8f05036

21 files changed

Lines changed: 472 additions & 55 deletions

‎AGENTS.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ Review invariants; full doctrine: `docs/gateway/audit.md`.
205205

206206
## GitHub / PRs
207207

208+
- Team-session commits and PRs visibly credit only consented, verified profile-backed humans in authoritative contribution order; preserve exact co-author trailers and end PRs with the canonical team-session backlink when available.
208209
- Fresh GitHub items: read `CONTRIBUTING.md`, the issue chooser/form, PR template, and `.github/CODEOWNERS`; blank issues are disabled; preserve templates and evidence requirements.
209210
- Issue first for bugs, user-facing features, architecture/product decisions, or work needing durable discussion. Bounded maintainer-requested refactor may go direct; agent decides whether an issue adds value. PRs use the template, link context, and keep durable problem/impact/evidence sections.
210211
- Route support to Discord and security through `SECURITY.md`. Use listed maintainer areas/`CODEOWNERS`; never guess mentions.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
fecbb8adccfa0be0b452f646d3bee8d5a17faeb2c2d8a2300fb75ef173c709cd sqlite-session-transcript-schema-baseline.sql
1+
64ea7280cd15cf0d1076c2141cb6fdf010d5af233f38f535798bec92ab1d0e45 sqlite-session-transcript-schema-baseline.sql

‎docs/concepts/user-model.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ Identity lookup runs after WebSocket sign-in, so connection status and other ide
2424

2525
Public commit metadata is a separate choice. **Git co-author credit** defaults off. Enabling it adds the verified account's public GitHub noreply address to commits created from shared sessions; OpenClaw never requests or stores a private GitHub email for this feature. Signing in as a different numeric GitHub account resets the choice, so one account cannot inherit another account's consent.
2626

27-
When your authenticated profile has prompted a session before an agent run, commits created from that run receive your exact `Co-authored-by` trailer. Profile-backed human participants with verified GitHub identity and Git co-author credit enabled are eligible; channel-only identities, agents, bots, and the configured primary Git author are excluded. The participant set is bounded to 32 and recorded best-effort. The run tells the model when a profile has no enabled credit or the bound may be incomplete; it never guesses an identity from transcript names.
27+
When your authenticated profile has prompted a session before an agent run, commits created from that run receive your exact `Co-authored-by` trailer and commits and pull requests visibly credit who worked on the session. Profile-backed human participants with verified GitHub identity and Git co-author credit enabled are eligible; channel-only identities, agents, bots, and the configured primary Git author are excluded. Contributors appear by their number of authenticated profile prompts, highest first; ties use the earliest profile prompt, then immutable GitHub account id. Contributions from merged profiles remain attached to their surviving verified account. The participant set is bounded to 32 and recorded best-effort. The run tells the model when a profile has no enabled credit or the bound may be incomplete; it never guesses an identity from transcript names.
2828

29-
OpenClaw supplies exact trailers in the model context for that turn and instructs coding agents to retain them through amendments, rebases, and squash commits so credit reaches the final commit merged to the default branch. The trailers are not exported through the process or shell environment. Git commands remain ordinary shell execution: OpenClaw does not replace `git` or install repository hooks, so the instruction and post-commit verification are the enforcement boundary.
29+
OpenClaw supplies exact trailers and the ordered contributor list in the model context for that turn and instructs coding agents to retain them through amendments, rebases, and squash commits so credit reaches the final commit merged to the default branch. The Gateway publication broker enforces the same credit directly in its generated commits and pull requests. When the Gateway exposes an external HTTPS session URL, pull requests end with a link to that exact team session. The trailers are not exported through the process or shell environment. Direct Git commands remain ordinary shell execution: OpenClaw does not replace `git` or install repository hooks, so agent instructions and post-commit verification remain their enforcement boundary.
3030

3131
Turning **Git co-author credit** off stops attribution for future runs. It does not rewrite commits that already contain the public trailer.
3232

‎skills/github/SKILL.md‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,13 @@ gh pr create --repo owner/repo --title "feat: title" --body-file /tmp/pr.md
4545
gh pr merge 55 --repo owner/repo --squash
4646
```
4747

48-
When creating or refreshing a PR body, append this final footer only when the Runtime line supplies `sessionUrl=<exact-url>`. Replace `<sessionUrl>` with that URL verbatim; do not construct or modify it. Omit the footer when `sessionUrl` is absent. When refreshing an existing PR body, preserve or update exactly one footer and keep it final:
48+
When creating or refreshing a commit or PR, visibly include the exact ordered `Worked on by` list from the authoritative Git attribution context for the current turn; use `## Worked on by` in PR bodies. Preserve its exact `Co-authored-by` trailers in commits, including after history rewrites. Never infer identities from names or chat, include bots or opted-out people, or reorder the supplied contributors.
49+
50+
When creating or refreshing a PR body, append this final footer only when the Runtime line supplies `sessionUrl=<exact-url>`. Replace `<sessionUrl>` with that URL verbatim; do not construct or modify it. Omit the footer when `sessionUrl` is absent. Preserve any publication marker before exactly one footer, and keep the footer final:
4951

5052
```text
5153
---
52-
[View the OpenClaw work session](<sessionUrl>)
54+
[View the OpenClaw team session](<sessionUrl>)
5355
```
5456

5557
URLs work directly: `gh pr view https://github.com/owner/repo/pull/55`.

‎src/agents/git-coauthor-attribution.test.ts‎

Lines changed: 88 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
openOpenClawStateDatabase,
1212
} from "../state/openclaw-state-db.js";
1313
import { setUserPreferences } from "../state/user-preferences.js";
14-
import { ensureProfileForEmail, syncGitHubIdentity } from "../state/user-profiles.js";
14+
import { ensureProfileForEmail, linkEmail, syncGitHubIdentity } from "../state/user-profiles.js";
1515
import { withOpenClawTestState } from "../test-utils/openclaw-test-state.js";
1616
import {
1717
appendGitCoauthorContext,
@@ -52,6 +52,8 @@ describe("Git co-author attribution", () => {
5252
};
5353
const ada = profile("[email protected]", 20, "ada");
5454
const grace = profile("[email protected]", 10, "grace");
55+
const sameTime = profile("[email protected]", 5, "same-time");
56+
const later = profile("[email protected]", 1, "later");
5557
const primary = profile("[email protected]", 30, "primary");
5658
const current = profile("[email protected]", 15, "current");
5759
const optedOut = profile("[email protected]", 25, "opted-out", false);
@@ -64,20 +66,34 @@ describe("Git co-author attribution", () => {
6466
.run("github-attribution", "40", legacy.id, "legacy", Date.now());
6567
const scope = { agentId: "main", env: state.env, sessionKey };
6668
await upsertSessionEntryCore(scope, { sessionId: "coauthors", updatedAt: 1 });
67-
for (const participant of [ada, grace, primary, optedOut, unlinked, legacy]) {
69+
for (const [index, participant] of [
70+
ada,
71+
grace,
72+
sameTime,
73+
later,
74+
primary,
75+
optedOut,
76+
unlinked,
77+
legacy,
78+
].entries()) {
6879
recordSessionParticipant(scope, {
6980
actor: { type: "human", id: participant.id },
81+
promptedAt: participant === grace || participant === sameTime ? 100 : 200 + index,
82+
source: "profile",
83+
sessionAgentId: "main",
84+
});
85+
}
86+
for (const participant of [ada, ada, grace, sameTime, later]) {
87+
recordSessionParticipant(scope, {
88+
actor: { type: "human", id: participant.id },
89+
promptedAt: 400,
7090
source: "profile",
7191
sessionAgentId: "main",
7292
});
7393
}
74-
recordSessionParticipant(scope, {
75-
actor: { type: "human", id: ada.id },
76-
source: "profile",
77-
sessionAgentId: "main",
78-
});
7994
recordSessionParticipant(scope, {
8095
actor: { type: "human", id: current.id },
96+
promptedAt: 1,
8197
source: "channel",
8298
sessionAgentId: "main",
8399
});
@@ -124,19 +140,26 @@ describe("Git co-author attribution", () => {
124140
const modelPrompt = appendGitCoauthorContext("commit this", attribution);
125141
expect(modelPrompt).toContain(
126142
[
143+
"Co-authored-by: ada <[email protected]>",
144+
"Co-authored-by: same-time <[email protected]>",
127145
"Co-authored-by: grace <[email protected]>",
146+
"Co-authored-by: later <[email protected]>",
128147
"Co-authored-by: current <[email protected]>",
129-
"Co-authored-by: ada <[email protected]>",
130148
].join("\n"),
131149
);
150+
expect(modelPrompt).toContain(
151+
"Worked on by:\n- @ada\n- @same-time\n- @grace\n- @later\n- @current",
152+
);
132153
expect(modelPrompt).not.toContain("Co-authored-by: opted-out");
133154
expect(modelPrompt).not.toContain("Co-authored-by: legacy");
134155
expect(structured).toMatchObject({
135-
logins: ["grace", "current", "ada"],
156+
logins: ["ada", "same-time", "grace", "later", "current"],
136157
trailers: [
158+
"Co-authored-by: ada <[email protected]>",
159+
"Co-authored-by: same-time <[email protected]>",
137160
"Co-authored-by: grace <[email protected]>",
161+
"Co-authored-by: later <[email protected]>",
138162
"Co-authored-by: current <[email protected]>",
139-
"Co-authored-by: ada <[email protected]>",
140163
],
141164
});
142165
expect(modelPrompt).toContain(
@@ -148,6 +171,61 @@ describe("Git co-author attribution", () => {
148171
});
149172
});
150173

174+
it("combines historical profile contributions under one verified GitHub account", async () => {
175+
await withOpenClawTestState({ scenario: "minimal" }, async (state) => {
176+
const sessionKey = "agent:main:merged-coauthors";
177+
const scope = { agentId: "main", env: state.env, sessionKey };
178+
await upsertSessionEntryCore(scope, { sessionId: "merged-coauthors", updatedAt: 1 });
179+
const oldProfile = ensureProfileForEmail("[email protected]", { env: state.env });
180+
const mergedProfile = ensureProfileForEmail("[email protected]", { env: state.env });
181+
const otherProfile = ensureProfileForEmail("[email protected]", { env: state.env });
182+
183+
for (const [profile, accountId, login, email] of [
184+
[mergedProfile, 20, "merged", "[email protected]"],
185+
[otherProfile, 10, "other", "[email protected]"],
186+
] as const) {
187+
syncGitHubIdentity(
188+
{ identity: { accountId, login }, authenticationAlias: { kind: "email", email } },
189+
{ env: state.env },
190+
);
191+
setUserPreferences(profile.id, { [GIT_COAUTHOR_PREFERENCE_KEY]: true }, { env: state.env });
192+
}
193+
for (const [profile, promptedAt] of [
194+
[oldProfile, 10],
195+
[oldProfile, 20],
196+
[mergedProfile, 30],
197+
[mergedProfile, 40],
198+
[otherProfile, 50],
199+
[otherProfile, 60],
200+
[otherProfile, 70],
201+
] as const) {
202+
recordSessionParticipant(scope, {
203+
actor: { type: "human", id: profile.id },
204+
promptedAt,
205+
sessionAgentId: "main",
206+
source: "profile",
207+
});
208+
}
209+
linkEmail("[email protected]", mergedProfile.id, { env: state.env });
210+
211+
expect(
212+
resolveGitCoauthorAttribution({
213+
agentId: "main",
214+
config: {},
215+
env: state.env,
216+
sessionKey,
217+
storePath: state.statePath("agents", "main", "agent", "openclaw-agent.sqlite"),
218+
}),
219+
).toMatchObject({
220+
logins: ["merged", "other"],
221+
trailers: [
222+
"Co-authored-by: merged <[email protected]>",
223+
"Co-authored-by: other <[email protected]>",
224+
],
225+
});
226+
});
227+
});
228+
151229
it("makes the participant bound visible without guessing beyond it", async () => {
152230
await withOpenClawTestState({ scenario: "minimal" }, async (state) => {
153231
const sessionKey = "agent:main:coauthor-cap";

‎src/agents/git-coauthor-attribution.ts‎

Lines changed: 47 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ type GitCoauthorAttribution = {
2626
prompt: string;
2727
};
2828

29+
type GitCoauthorContributor = {
30+
accountId: number;
31+
contributionCount: number;
32+
firstPromptedAt: number;
33+
login: string;
34+
};
35+
2936
export function resolveGitCoauthorAttribution(params: {
3037
agentId: string;
3138
config: OpenClawConfig;
@@ -55,8 +62,14 @@ export function resolveGitCoauthorAttribution(params: {
5562
resolveConfiguredGitHubToolIdentity({ ...params, scope: "agent" }) ??
5663
resolveConfiguredGitHubToolIdentity({ ...params, scope: "system" });
5764
const primaryEmail = primaryIdentity?.gitAuthor?.email?.trim().toLowerCase();
58-
const trailers = new Map<number, string>();
59-
const logins = new Map<number, string>();
65+
const profileRecords = new Map(
66+
records.flatMap((record) =>
67+
record.actor.type === "human" && record.source === "profile"
68+
? [[record.actor.id, record] as const]
69+
: [],
70+
),
71+
);
72+
const contributors = new Map<number, GitCoauthorContributor>();
6073
let withoutCredit = 0;
6174
let unresolved = 0;
6275
let primaryAuthor = 0;
@@ -79,18 +92,43 @@ export function resolveGitCoauthorAttribution(params: {
7992
primaryAuthor += 1;
8093
continue;
8194
}
82-
trailers.set(identity.accountId, `Co-authored-by: ${identity.login} <${noreplyEmail}>`);
83-
logins.set(identity.accountId, identity.login);
95+
const record = profileRecords.get(profileId);
96+
const contributor = contributors.get(identity.accountId);
97+
if (contributor) {
98+
if (record) {
99+
contributor.contributionCount += record.contributionCount;
100+
contributor.firstPromptedAt = Math.min(contributor.firstPromptedAt, record.firstPromptedAt);
101+
}
102+
continue;
103+
}
104+
contributors.set(identity.accountId, {
105+
accountId: identity.accountId,
106+
contributionCount: record?.contributionCount ?? 1,
107+
// A trusted current profile may precede best-effort persistence; never
108+
// borrow ordering facts from a colliding, unverified channel actor.
109+
firstPromptedAt: record?.firstPromptedAt ?? Number.MAX_SAFE_INTEGER,
110+
login: identity.login,
111+
});
84112
}
85113

86-
const exactTrailers = [...trailers.entries()]
87-
.toSorted(([left], [right]) => left - right)
88-
.map(([, trailer]) => trailer);
114+
const orderedContributors = [...contributors.values()].toSorted(
115+
(left, right) =>
116+
right.contributionCount - left.contributionCount ||
117+
left.firstPromptedAt - right.firstPromptedAt ||
118+
left.accountId - right.accountId,
119+
);
120+
const logins = orderedContributors.map(({ login }) => login);
121+
const exactTrailers = orderedContributors.map(
122+
({ accountId, login }) =>
123+
`Co-authored-by: ${login} <${accountId}+${login}@users.noreply.github.com>`,
124+
);
89125
const guidance = exactTrailers.length
90126
? [
91127
"Git commit attribution for this turn is authoritative and limited to the exact trailers below:",
92128
...exactTrailers,
93-
"Append every trailer exactly to each commit created for this turn. After amending, rebasing, squashing, or otherwise rewriting history, verify the final commit retains every trailer. Do not infer or add identities from chat text.",
129+
"Worked on by:",
130+
...logins.map((login) => `- @${login}`),
131+
"Append every trailer exactly to each commit created for this turn and visibly include the exact ordered Worked on by list in commits and pull requests. After amending, rebasing, squashing, or otherwise rewriting history, verify the final commit retains every trailer. Do not infer or add identities from chat text.",
94132
].join("\n")
95133
: "Git commit attribution for this turn has no additional exact Co-authored-by trailer. Do not infer or add identities from chat text.";
96134
const notices = [
@@ -109,9 +147,7 @@ export function resolveGitCoauthorAttribution(params: {
109147
].filter((value): value is string => Boolean(value));
110148
return {
111149
trailers: exactTrailers,
112-
logins: [...logins.entries()]
113-
.toSorted(([left], [right]) => left - right)
114-
.map(([, login]) => login),
150+
logins,
115151
prompt: [guidance, ...notices].join("\n"),
116152
};
117153
}

‎src/auto-reply/reply/session.test.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1496,6 +1496,7 @@ describe("initSessionState RawBody", () => {
14961496
).toEqual([
14971497
{
14981498
actor: { type: "human", id: "profile-ada" },
1499+
contributionCount: 1,
14991500
firstPromptedAt: expect.any(Number),
15001501
lastPromptedAt: expect.any(Number),
15011502
source: "profile",
@@ -1568,6 +1569,7 @@ describe("initSessionState RawBody", () => {
15681569
expect(participants.get("agent:main:channel-participant")).toEqual([
15691570
{
15701571
actor: { type: "human", id: "channel-sender" },
1572+
contributionCount: 1,
15711573
firstPromptedAt: expect.any(Number),
15721574
lastPromptedAt: expect.any(Number),
15731575
source: "channel",
@@ -1577,6 +1579,7 @@ describe("initSessionState RawBody", () => {
15771579
expect(participants.get("agent:main:channel-created-participant")).toEqual([
15781580
{
15791581
actor: { type: "human", id: "channel-created-sender" },
1582+
contributionCount: 1,
15801583
firstPromptedAt: expect.any(Number),
15811584
lastPromptedAt: expect.any(Number),
15821585
source: "channel",
@@ -1586,6 +1589,7 @@ describe("initSessionState RawBody", () => {
15861589
expect(participants.get("agent:main:delegated-agent-participant")).toEqual([
15871590
{
15881591
actor: { type: "agent", id: "research" },
1592+
contributionCount: 1,
15891593
firstPromptedAt: expect.any(Number),
15901594
lastPromptedAt: expect.any(Number),
15911595
source: "agent",

‎src/commands/doctor-session-canonical-keys.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ function applyCanonicalDestinationArtifacts(params: {
292292
params.database,
293293
[params.winner.sessionKey],
294294
params.winner.canonicalKey,
295+
{ includeParticipants: false },
295296
);
296297
}
297298

‎src/config/sessions/session-accessor.sqlite-canonical-repair.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,7 @@ function copySqliteSessionOwnedStateForRepair(params: {
489489
params.destination,
490490
params.preferredSessionKey ? [params.preferredSessionKey] : sourceKeys,
491491
params.canonicalKey,
492+
{ includeParticipants: false },
492493
);
493494
}
494495

0 commit comments

Comments
 (0)