From a528a653d2929d788ad713c2a6cc769ebb3ed114 Mon Sep 17 00:00:00 2001 From: Robert Gruen Date: Mon, 2 Nov 2026 08:54:09 -0800 Subject: [PATCH 1/2] Allow related PR citations without blocking accepted work Treat citations as preserved evidence, not reservations on independent work. Keep target-Issue links and mentions, revision freshness, owned-branch checks, and publication-intent safeguards. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- AUTOMATION.md | 7 ++- tools/issue-implementation.mjs | 9 ++- tools/tests/issue-implementation.test.mjs | 70 +++++++++++++++++++++-- 3 files changed, 73 insertions(+), 13 deletions(-) diff --git a/AUTOMATION.md b/AUTOMATION.md index 2e3e5235..43385f58 100644 --- a/AUTOMATION.md +++ b/AUTOMATION.md @@ -902,8 +902,11 @@ Discussion builds and inline notes remain unsupported; #502 is still deferred. ### Frozen authorization and bounded spending Preflight verifies owner identity, default-branch workflow code, the current -scope policy and its ancestry, acceptance, and existing contributions. Open -linked or possibly competing PRs stop the run, including ambiguous references. +scope policy and its ancestry, acceptance, and existing contributions. Open PRs +linked to the target Issue or naming it in their title/body stop the run for +owner review. Citing an open PR as related work does not by itself reserve the +Issue or block an independently accepted task. References and contributor credit +remain in the agreement, and their approved revisions are still checked. The agreement, discussion, exact source revision, control fingerprints, and short-lived App-access proof are frozen. An immutable spending reservation precedes inference. The model-start guard repeats authorization and rejects App diff --git a/tools/issue-implementation.mjs b/tools/issue-implementation.mjs index d65b51f7..ef2eb6d1 100644 --- a/tools/issue-implementation.mjs +++ b/tools/issue-implementation.mjs @@ -265,8 +265,7 @@ async function existingBuild(github, target, acceptance) { throw new Error("An implementation branch exists without a confirmed PR; inspect the earlier write before recovery."); } -async function competingContributions(github, target, acceptance) { - const associated = new Set(acceptance.references.map(reference => reference.number)); +async function competingContributions(github, target) { const query = `query ImplementationContributions($owner:String!,$repo:String!,$number:Int!,$after:String) { repository(owner:$owner,name:$repo) { issue(number:$number) { timelineItems(first:100,after:$after,itemTypes:[CROSS_REFERENCED_EVENT,CONNECTED_EVENT]) { @@ -309,7 +308,7 @@ async function competingContributions(github, target, acceptance) { for (const pr of prs) { requireValue(typeof pr.title === "string" && (pr.body === null || typeof pr.body === "string"), "Open-contribution metadata is incomplete."); - requireValue(!associated.has(pr.number) && !mention.test(`${pr.title}\n${pr.body ?? ""}`), + requireValue(!mention.test(`${pr.title}\n${pr.body ?? ""}`), `Open PR #${pr.number} may already implement this Issue; obtain owner guidance instead of a competing patch.`); } if (prs.length < 100) return; @@ -338,7 +337,7 @@ export async function prepareBuild(github, context, env, clock = () => new Date( request.mode === "command" ? request.acceptanceId : request.command.acceptanceId, request.command?.bodyHash, current); const existing = await existingBuild(github, target, acceptance); if (existing) return existing; - await competingContributions(github, target, acceptance); + await competingContributions(github, target); requireValue(!await priorIntent(github, `${BUILD_WRITE_PREFIX}${scopeKey(target, acceptance)}`), "An earlier publication is unresolved; inspect it before requesting more work."); if (request.mode === "command") { @@ -395,7 +394,7 @@ export async function verifyBuildAuthorization(github, context, env, prepared, c const acceptance = await acceptanceRecord(github, thread, request.command.acceptanceId, request.command.bodyHash, current); requireValue(same(acceptance, prepared.acceptance) && snapshotHash(thread) === prepared.snapshotHash, "The acceptance or discussion changed after authorization; obtain a new owner decision."); - await competingContributions(github, request.target, acceptance); + await competingContributions(github, request.target); return request; } diff --git a/tools/tests/issue-implementation.test.mjs b/tools/tests/issue-implementation.test.mjs index ed020683..4f9087c8 100644 --- a/tools/tests/issue-implementation.test.mjs +++ b/tools/tests/issue-implementation.test.mjs @@ -29,14 +29,14 @@ const repo = { id: REPOSITORY.id, full_name: "microsoft/TypeChat", private: fals const target = { kind: "issue", number: 75, id: "I_75", url: "https://github.com/microsoft/TypeChat/issues/75" }; const original = "export const value = 1;\n"; -function fixture() { +function fixture(references = []) { const policyText = "The project direction owner is **@robgruen**.\nPreserve schema accuracy.\n"; const fingerprints = Object.fromEntries(BUILD_CONTROL_PATHS.map(file => [file, blobHash(file)])); fingerprints["GOALS.md"] = blobHash(policyText); const body = renderAcceptance({ target, producer: { runId: 50, attempt: 1, commit: POLICY }, marker: "e".repeat(64), draft: { proposal: { goal: "Preserve correct values.", scope: ["Fix the agreed value."], nonGoals: ["No other behavior changes."] }, - suggestedCriteria: ["A deterministic test verifies the value."], pullRequests: [] }, + suggestedCriteria: ["A deterministic test verifies the value."], pullRequests: references }, }); const owner = { __typename: "User", login: OWNER.login, id: "OWNER" }; const bot = { __typename: "Bot", login: "github-actions", id: ACTIONS_BOT_ID }; @@ -53,7 +53,13 @@ function fixture() { lastEditedAt: null, author: owner, repository: { nameWithOwner: "microsoft/TypeChat", isPrivate: false } }, baseline: [...Object.entries(fingerprints).map(([file, sha]) => ({ path: file, type: "blob", mode: "100644", sha })), { path: "typescript/src/value.ts", type: "blob", mode: "100644", sha: blobHash(original) }], - ref: null, pr: null, competitors: [], linked: [], writes: [], createdEntries: [], persistPrError: false, prError: null, + ref: null, pr: null, competitors: references.map(reference => ({ + number: reference.number, title: "Related work on another Issue", body: "Fixes #454", + })), + referenceData: new Map(references.map(reference => [reference.number, { + number: reference.number, state: "open", head: { sha: reference.headSha }, base: { repo: { id: REPOSITORY.id } }, + }])), + linked: [], writes: [], createdEntries: [], persistPrError: false, prError: null, }; const context = { eventName: "issue_comment", actor: OWNER.login, sha: SHA, runId: 100, @@ -100,7 +106,10 @@ function fixture() { }, pulls: { list: async input => ({ data: structuredClone(input.state === "all" ? state.pr ? [state.pr] : [] : state.competitors) }), - get: async () => { throw new Error("No contribution fetch expected."); }, + get: async ({ pull_number }) => { + assert.ok(state.referenceData.has(pull_number), "No unexpected contribution fetch."); + return { data: structuredClone(state.referenceData.get(pull_number)) }; + }, }, git: { getTree: async ({ tree_sha }) => ({ data: { truncated: false, tree: structuredClone(tree_sha === TREE ? state.createdEntries : @@ -172,8 +181,8 @@ function fixture() { return { state, context, env, github, writer, proof, artifact }; } -async function preparedFixture() { - const f = fixture(); +async function preparedFixture(references = []) { + const f = fixture(references); const plan = await prepareBuild(f.github, f.context, f.env, clock); f.prepared = freezeBuild(plan, f.proof, clock); f.candidate = { version: 1, contextHash: digest(f.prepared), baseSha: SHA, summary: "Correct the agreed value.", limitations: [], @@ -205,6 +214,55 @@ test("the public durable acceptance generates an exact, copyable Issue command", assert.equal(parseAcceptedWork(f.state.comments[1].body, target).terms.goal, "Preserve correct values."); }); +test("a cited open PR for different work does not block command preparation", async () => { + const f = fixture([{ number: 466, headSha: "f".repeat(40) }]); + f.context.eventName = "workflow_dispatch"; + f.context.payload.inputs = { issue: "75", acceptance: "41" }; + delete f.env.TYPECHAT_IMPLEMENTATION_ENABLED; + const result = await prepareBuild(f.github, f.context, f.env, clock); + assert.equal(result.mode, "command"); + assert.equal(result.command, buildCommand(41, digest(f.state.comments[1].body))); + assert.equal(result.enabled, false); + assert.equal(f.state.artifacts.size, 0); + assert.equal(f.state.writes.length, 0); +}); + +test("a related citation is preserved through preflight and verified publication", async () => { + const references = [{ number: 466, headSha: "f".repeat(40) }]; + const f = await preparedFixture(references); + assert.deepEqual(f.prepared.acceptance.references, references); + const result = await f.publish(); + assert.equal(result.mode, "published"); + assert.ok(f.state.pr.body.includes("https://github.com/microsoft/TypeChat/pull/466")); + assert.equal(f.state.writes.filter(operation => operation === "branch").length, 1); + assert.equal(f.state.writes.filter(operation => operation === "pr").length, 1); +}); + +test("a cited PR still blocks when it is linked to or names the target Issue", async () => { + for (const linked of [true, false]) { + const f = fixture([{ number: 466, headSha: "f".repeat(40) }]); + if (linked) f.state.linked.push({ source: { number: 466, state: "OPEN" } }); + else f.state.competitors[0].body = "Fixes #75"; + await assert.rejects(() => prepareBuild(f.github, f.context, f.env, clock), /linked to this Issue|may already implement/); + assert.equal(f.state.writes.length, 0); + } +}); + +test("a related reference becoming competing work blocks publication", async () => { + const f = await preparedFixture([{ number: 466, headSha: "f".repeat(40) }]); + f.state.competitors[0].body = "Implements #75"; + await assert.rejects(() => checkBuildPublication(f.github, f.context, f.env, + f.prepared, f.candidate, f.scan, f.checks, f.evidence, clock), /may already implement/); + assert.equal(f.state.writes.length, 0); +}); + +test("a related reference still requires its approved revision to remain current", async () => { + const f = await preparedFixture([{ number: 466, headSha: "f".repeat(40) }]); + f.state.referenceData.get(466).head.sha = "0".repeat(40); + await assert.rejects(() => verifyBuildAuthorization(f.github, f.context, f.env, f.prepared, clock), /Accepted contribution #466 changed/); + assert.equal(f.state.writes.length, 0); +}); + for (const body of ["/typechat build 1:abc", `/typechat build 1:${"f".repeat(64)}\nAdd another feature`, `/typechat accept 1:${"f".repeat(64)}`, `/typechat build 9007199254740993:${"f".repeat(64)}`]) { test(`reject unsupported build syntax: ${body.slice(0, 40)}`, () => assert.throws(() => parseBuildCommand(body))); From 689a6bbd2c4fb0a412ae32779f91e232af3636c2 Mon Sep 17 00:00:00 2001 From: Robert Gruen Date: Mon, 2 Nov 2026 09:01:18 -0800 Subject: [PATCH 2/2] Assert complete accepted text in the related-PR regression Verify preservation of the entire agreement instead of using a literal URL substring assertion that CodeQL misclassifies as URL sanitization. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- tools/tests/issue-implementation.test.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/tests/issue-implementation.test.mjs b/tools/tests/issue-implementation.test.mjs index 4f9087c8..0688b6d1 100644 --- a/tools/tests/issue-implementation.test.mjs +++ b/tools/tests/issue-implementation.test.mjs @@ -233,7 +233,7 @@ test("a related citation is preserved through preflight and verified publication assert.deepEqual(f.prepared.acceptance.references, references); const result = await f.publish(); assert.equal(result.mode, "published"); - assert.ok(f.state.pr.body.includes("https://github.com/microsoft/TypeChat/pull/466")); + assert.ok(f.state.pr.body.includes(f.prepared.acceptance.body)); assert.equal(f.state.writes.filter(operation => operation === "branch").length, 1); assert.equal(f.state.writes.filter(operation => operation === "pr").length, 1); });