Skip to content

Commit 104648b

Browse files
authored
fix: verify registry-free review request intent (#164)
* fix: verify registry-free review request intent * fix: bind and retain materializing request provenance --------- Co-authored-by: Franz Hemmer <8227352+HemSoft@users.noreply.github.com>
1 parent 05e71cf commit 104648b

7 files changed

Lines changed: 147 additions & 42 deletions

File tree

‎.github/workflows/sfl-pr-review-auto.yml‎

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,7 @@ jobs:
747747
}
748748
}
749749
// BEGIN TESTABLE ACTIVE INVALIDATIONS
750+
const verifiedMaterializingRequests = new Set();
750751
const activeInvalidationRuns = async () => {
751752
const activeStatuses = ["requested", "queued", "in_progress", "waiting", "pending"];
752753
const events = ["pull_request_target", "push", "issue_comment"];
@@ -789,20 +790,44 @@ jobs:
789790
status.context === "SFL Codex Review Request Registry" &&
790791
(status.target_url || "").toLowerCase() === target &&
791792
Boolean(status.creator && status.creator.login));
792-
// Ignore ordinary comments even from current administrators.
793-
// A historically registered author remains entitled to revoke
794-
// their evidence, and a current writer may remove that comment.
795-
// The run title preserves marker intent from the event payload,
796-
// including a later-erased body. Hold a writer's request before
797-
// its CLI registry POST becomes visible. Older rc25 titles lack
798-
// this distinction, so their active runs remain conservative.
799-
const materializingRequest = run.display_title ===
800-
`SFL Codex comment #${pullNumber} request ${requestId}`;
801-
if ((registrations.length && (registrations.some(status =>
802-
status.creator.login.toLowerCase() === actor) || await requesterAllowed(actor))) ||
803-
(materializingRequest && await requesterAllowed(actor))) {
804-
authorized.push(run);
793+
// Registered authors may revoke their evidence after access loss.
794+
// A title with marker intent is only a candidate for a fresh request:
795+
// quoted or malformed markers must not block ordinary publication.
796+
const registeredInvalidation = registrations.length &&
797+
(registrations.some(status => status.creator.login.toLowerCase() === actor) ||
798+
await requesterAllowed(actor));
799+
const verifiedRequestIdentity = `${run.id}:${requestId}:${actor}`;
800+
let materializingRequest = verifiedMaterializingRequests.has(verifiedRequestIdentity);
801+
if (!registeredInvalidation && !materializingRequest && !registrations.length &&
802+
run.display_title === `SFL Codex comment #${pullNumber} request ${requestId}` &&
803+
await requesterAllowed(actor)) {
804+
let comment;
805+
try {
806+
comment = (await github.rest.issues.getComment({
807+
owner, repo, comment_id: requestId,
808+
})).data;
809+
} catch (error) {
810+
if (error.status !== 404) throw error;
811+
}
812+
const token = requestContextFromBody(comment && comment.body);
813+
materializingRequest = Boolean(comment && token &&
814+
comment.id === requestId &&
815+
(comment.html_url || "").toLowerCase() === target &&
816+
((comment.user && comment.user.login) || "").toLowerCase() === actor &&
817+
Number.isFinite(Date.parse(comment.created_at || "")) &&
818+
comment.updated_at === comment.created_at &&
819+
comment.body === `@codex review\n\n${baseMarker}context=${token} -->`);
820+
if (materializingRequest) {
821+
const currentContextChecks = await github.paginate(github.rest.checks.listForRef,
822+
{owner, repo, ref: currentHead, check_name: "SFL Reviewer Gate Runner",
823+
filter: "all", per_page: 100}, response => response.data);
824+
materializingRequest = reviewContextUnambiguous(currentContextChecks, pullNumber, currentBase) &&
825+
currentContextChecks.some(check => check.app && check.app.id === 15368 &&
826+
check.external_id === token);
827+
if (materializingRequest) verifiedMaterializingRequests.add(verifiedRequestIdentity);
828+
}
805829
}
830+
if (registeredInvalidation || materializingRequest) authorized.push(run);
806831
}
807832
return authorized;
808833
};

‎VERSION‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.1.0-rc.27
1+
2.1.0-rc.28

‎deployment/infrastructure/sfl-pr-review-auto.yml‎

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,7 @@ jobs:
747747
}
748748
}
749749
// BEGIN TESTABLE ACTIVE INVALIDATIONS
750+
const verifiedMaterializingRequests = new Set();
750751
const activeInvalidationRuns = async () => {
751752
const activeStatuses = ["requested", "queued", "in_progress", "waiting", "pending"];
752753
const events = ["pull_request_target", "push", "issue_comment"];
@@ -789,20 +790,44 @@ jobs:
789790
status.context === "SFL Codex Review Request Registry" &&
790791
(status.target_url || "").toLowerCase() === target &&
791792
Boolean(status.creator && status.creator.login));
792-
// Ignore ordinary comments even from current administrators.
793-
// A historically registered author remains entitled to revoke
794-
// their evidence, and a current writer may remove that comment.
795-
// The run title preserves marker intent from the event payload,
796-
// including a later-erased body. Hold a writer's request before
797-
// its CLI registry POST becomes visible. Older rc25 titles lack
798-
// this distinction, so their active runs remain conservative.
799-
const materializingRequest = run.display_title ===
800-
`SFL Codex comment #${pullNumber} request ${requestId}`;
801-
if ((registrations.length && (registrations.some(status =>
802-
status.creator.login.toLowerCase() === actor) || await requesterAllowed(actor))) ||
803-
(materializingRequest && await requesterAllowed(actor))) {
804-
authorized.push(run);
793+
// Registered authors may revoke their evidence after access loss.
794+
// A title with marker intent is only a candidate for a fresh request:
795+
// quoted or malformed markers must not block ordinary publication.
796+
const registeredInvalidation = registrations.length &&
797+
(registrations.some(status => status.creator.login.toLowerCase() === actor) ||
798+
await requesterAllowed(actor));
799+
const verifiedRequestIdentity = `${run.id}:${requestId}:${actor}`;
800+
let materializingRequest = verifiedMaterializingRequests.has(verifiedRequestIdentity);
801+
if (!registeredInvalidation && !materializingRequest && !registrations.length &&
802+
run.display_title === `SFL Codex comment #${pullNumber} request ${requestId}` &&
803+
await requesterAllowed(actor)) {
804+
let comment;
805+
try {
806+
comment = (await github.rest.issues.getComment({
807+
owner, repo, comment_id: requestId,
808+
})).data;
809+
} catch (error) {
810+
if (error.status !== 404) throw error;
811+
}
812+
const token = requestContextFromBody(comment && comment.body);
813+
materializingRequest = Boolean(comment && token &&
814+
comment.id === requestId &&
815+
(comment.html_url || "").toLowerCase() === target &&
816+
((comment.user && comment.user.login) || "").toLowerCase() === actor &&
817+
Number.isFinite(Date.parse(comment.created_at || "")) &&
818+
comment.updated_at === comment.created_at &&
819+
comment.body === `@codex review\n\n${baseMarker}context=${token} -->`);
820+
if (materializingRequest) {
821+
const currentContextChecks = await github.paginate(github.rest.checks.listForRef,
822+
{owner, repo, ref: currentHead, check_name: "SFL Reviewer Gate Runner",
823+
filter: "all", per_page: 100}, response => response.data);
824+
materializingRequest = reviewContextUnambiguous(currentContextChecks, pullNumber, currentBase) &&
825+
currentContextChecks.some(check => check.app && check.app.id === 15368 &&
826+
check.external_id === token);
827+
if (materializingRequest) verifiedMaterializingRequests.add(verifiedRequestIdentity);
828+
}
805829
}
830+
if (registeredInvalidation || materializingRequest) authorized.push(run);
806831
}
807832
return authorized;
808833
};

‎deployment/release-metadata.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
"reviewedAt": "2026-10-08",
44
"distribution": {
55
"repository": "hemsoft-dev/set-it-free-loop",
6-
"version": "2.1.0-rc.27",
6+
"version": "2.1.0-rc.28",
77
"visibility": "private",
8-
"tag": "v2.1.0-rc.27",
8+
"tag": "v2.1.0-rc.28",
99
"prerelease": true
1010
},
1111
"reviewerRuntime": {

‎deployment/tests/test-final-review-history.cjs‎

Lines changed: 66 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -114,19 +114,51 @@ async function activeCases() {
114114
const end = source.indexOf('function requestGateExternalIdPrefix(', start);
115115
assert(start >= 0 && end > start);
116116
const classify = new AsyncFunction('fixture', `
117-
const owner='hemsoft-dev',repo='fixture',pullNumber=42,currentHead='${head}',context={runId:99};
117+
const owner='hemsoft-dev',repo='fixture',pullNumber=42,currentHead='${head}',currentBase='${base}',context={runId:99};
118+
const baseMarker='<!-- sfl-codex-review:head=${head};base=${base};';
119+
${block('REQUEST ELIGIBILITY').split('const requestOrder =')[0]}
120+
${block('REVIEW CONTEXT PROVENANCE')}
118121
const requesterAllowed=async login=>fixture.allowed.includes(login);
119-
const github={rest:{actions:{listWorkflowRuns:'runs'},repos:{listCommitStatusesForRef:'statuses'}},
120-
paginate:async(method,args)=>method==='runs'?(args.status==='queued'?fixture.runs:[]):fixture.statuses};
122+
const github={rest:{actions:{listWorkflowRuns:'runs'},repos:{listCommitStatusesForRef:'statuses'},checks:{listForRef:'checks'},
123+
issues:{getComment:async({comment_id})=>{
124+
if(fixture.error)throw fixture.error;
125+
if(fixture.comment===null)throw Object.assign(new Error('deleted'),{status:404});
126+
return {data:fixture.comment || {id:comment_id,body:fixture.exact,html_url:'https://github.com/hemsoft-dev/fixture/pull/42#issuecomment-'+comment_id,user:{login:'admin'},created_at:'2026-10-08T00:00:01Z',updated_at:'2026-10-08T00:00:01Z'}};
127+
}}},
128+
paginate:async(method,args)=>method==='runs'?(args.status==='queued'?fixture.runs:[]):method==='checks'?(fixture.checks || [{app:{id:15368},external_id:fixture.token,output:{text:JSON.stringify({schema:1,pull_number:42,action:'opened',base_sha:currentBase})}}]):fixture.statuses};
121129
${unindent(source.slice(start,end))}
122130
${block('ACTIVE INVALIDATIONS')}
123-
return (await activeInvalidationRuns()).map(run=>run.id);`);
131+
const results=[];
132+
for(const step of fixture.steps || [{}]){
133+
Object.assign(fixture,step);
134+
results.push((await activeInvalidationRuns()).map(run=>run.id));
135+
}
136+
return fixture.steps ? results : results[0];`);
124137
const run = (actor, id=101, markerIntent=false) => ({id:1,event:'issue_comment',status:'queued',actor:{login:actor},display_title:titleForComment(id, markerIntent ? exact : 'ordinary comment')});
125138
const registration = (creator='author',url=commentURL) => ({context:'SFL Codex Review Request Registry',creator:{login:creator},target_url:url});
126139
const cases = [
127140
['ordinary administrator comment', [run('admin')], [], ['admin'], []],
128141
['writer request before registry visibility', [run('admin',101,true)], [], ['admin'], [1]],
129142
['reader marker before registry visibility', [run('reader',101,true)], [], [], []],
143+
...[
144+
['quoted marker', `An earlier request said:\n${exact}`],
145+
['trailing prose', `${exact}\nordinary follow-up`],
146+
['old head', exact.replace(head,'c'.repeat(40))],
147+
['old base', exact.replace(base,'c'.repeat(40))],
148+
['arbitrary context', exact.replace(token,'foo')],
149+
['empty context', exact.replace(token,'')],
150+
['padded context', exact.replace(token,' '+token)],
151+
].map(([name,body])=>[name,[{...run('admin',101,true),display_title:titleForComment(101,body)}],[],['admin'],[],
152+
{id:101,body,html_url:commentURL,user:{login:'admin'},created_at:'2026-10-08T00:00:01Z',updated_at:'2026-10-08T00:00:01Z'}]),
153+
['deleted registry-free marker', [run('admin',101,true)], [], ['admin'], [], null],
154+
['deleted revoked registered request', [run('author',101,true)], [registration()], [], [1], null],
155+
['edited registry-free marker', [run('admin',101,true)], [], ['admin'], [],
156+
{id:101,body:exact,html_url:commentURL,user:{login:'admin'},created_at:'2026-10-08T00:00:01Z',updated_at:'2026-10-08T00:00:02Z'}],
157+
['different comment target', [run('admin',101,true)], [], ['admin'], [],
158+
{id:101,body:exact,html_url:commentURL.replace('/42#','/43#'),user:{login:'admin'},created_at:'2026-10-08T00:00:01Z',updated_at:'2026-10-08T00:00:01Z'}],
159+
['different author before registry', [run('admin',101,true)], [], ['admin'], [],
160+
{id:101,body:exact,html_url:commentURL,user:{login:'other'},created_at:'2026-10-08T00:00:01Z',updated_at:'2026-10-08T00:00:01Z'}],
161+
130162
['registered administrator request', [run('admin')], [registration('admin')], ['admin'], [1]],
131163
['revoked registered author', [run('author')], [registration()], [], [1]],
132164
['unprivileged other actor', [run('reader')], [registration()], [], []],
@@ -142,9 +174,32 @@ async function activeCases() {
142174
['completed comment run', [{...run('admin'),status:'completed'}], [registration('admin')], ['admin'], []],
143175
['legacy writer run', [{...run('admin'),display_title:'SFL Codex review request #42'}], [], ['admin'], [1]],
144176
];
145-
for (const [name,runs,statuses,allowed,want] of cases) {
146-
assert.deepEqual(await classify({runs,statuses,allowed}),want,name);
177+
for (const [name,runs,statuses,allowed,want,comment] of cases) {
178+
if(process.argv[3]==='probe-pinned' && name==='arbitrary context')continue;
179+
assert.deepEqual(await classify({runs,statuses,allowed,comment,exact,token}),want,name);
180+
}
181+
if(process.argv[3] !== 'probe-pinned') {
182+
const trusted={app:{id:15368},external_id:token,output:{text:JSON.stringify({schema:1,pull_number:42,action:'opened',base_sha:base})}};
183+
for(const checks of [[],[{...trusted,app:{id:1}}],[{...trusted,output:{text:'malformed'}}],
184+
[{...trusted,output:{text:JSON.stringify({schema:1,pull_number:42,action:'opened',base_sha:'c'.repeat(40)})}}],
185+
[trusted,{...trusted,external_id:token+'1'}]]) {
186+
assert.deepEqual(await classify({runs:[run('admin',101,true)],statuses:[],allowed:['admin'],exact,token,checks}),[],'materializing request requires unique authenticated current context provenance');
187+
}
188+
}
189+
if(process.argv[3] !== 'probe-context') {
190+
for(const changed of [null,{id:101,body:exact+' edited',html_url:commentURL,user:{login:'admin'},created_at:'2026-10-08T00:00:01Z',updated_at:'2026-10-08T00:00:02Z'}]) {
191+
const runs=[run('admin',101,true)];
192+
assert.deepEqual(await classify({runs,statuses:[],allowed:['admin'],exact,token,steps:[{}, {comment:changed}, {runs:[]}] }),[[1],[1],[]],'verified request remains serialized after mutation until its active run ends');
193+
}
194+
}
195+
if(process.argv[3] !== 'probe-context') {
196+
assert.deepEqual(await classify({runs:[run('admin',101,true)],statuses:[],allowed:['admin'],exact,token,
197+
steps:[{}, {allowed:[],comment:null}, {runs:[]}] }),[[1],[1],[]],'verified request stays serialized after authorization loss until its active run ends');
198+
assert.deepEqual(await classify({runs:[run('admin',101,true)],statuses:[],allowed:['admin'],exact,token,
199+
steps:[{}, {runs:[{...run('admin',101,true),id:2}],comment:null}] }),[[1],[]],'verified identity does not transfer to another run');
147200
}
201+
const error=Object.assign(new Error('comment verification unavailable'),{status:500});
202+
await assert.rejects(classify({runs:[run('admin',101,true)],statuses:[],allowed:['admin'],exact,token,error}),observed=>observed===error);
148203
}
149204
function retargetCases() {
150205
const supported = new Function('pull','context','headRepo','owner','repo',
@@ -319,22 +374,22 @@ async function publishedCheckRetryCases(baseFixture,first,selected) {
319374

320375
(async () => {
321376
const mode = process.argv[3] || 'all';
322-
assert(['all', 'probe-invalidation', 'probe-history', 'probe-revoked', 'probe-active', 'probe-retarget', 'probe-polling', 'probe-empty', 'probe-repair', 'probe-publication', 'probe-check-retry'].includes(mode));
377+
assert(['all', 'probe-invalidation', 'probe-history', 'probe-revoked', 'probe-active', 'probe-retarget', 'probe-polling', 'probe-empty', 'probe-repair', 'probe-publication', 'probe-check-retry', 'probe-context', 'probe-pinned'].includes(mode));
323378
if (['all', 'probe-polling'].includes(mode)) {
324379
for (const action of ['created', 'edited', 'deleted']) {
325380
await invalidationCase(`unprivileged marker ${action}`, exact, action === 'edited', false, false, null, action, 'read', 1);
326381
}
327382
}
328-
if (['all', 'probe-active'].includes(mode)) await activeCases();
383+
if (['all', 'probe-active', 'probe-context', 'probe-pinned'].includes(mode)) await activeCases();
329384
if (['all', 'probe-retarget'].includes(mode)) retargetCases();
330385
if (['all', 'probe-revoked'].includes(mode)) {
331386
for (const [action, body] of [['edited', 'erased request'], ['deleted', exact], ['created', exact]]) {
332387
await invalidationCase(`revoked registered author ${action}`, body, action === 'edited', true, true, 'failure', action, 'read');
333388
}
334389
await invalidationCase('revoked unregistered author', 'ordinary comment', false, false, false, null, 'created', 'read');
335390
}
336-
if (mode.startsWith('probe-') && !['probe-invalidation', 'probe-history', 'probe-empty', 'probe-repair', 'probe-publication', 'probe-check-retry'].includes(mode)) return;
337-
if (!['probe-history', 'probe-empty', 'probe-repair', 'probe-publication', 'probe-check-retry'].includes(mode)) {
391+
if (mode.startsWith('probe-') && !['probe-invalidation', 'probe-history', 'probe-empty', 'probe-repair', 'probe-publication', 'probe-check-retry', 'probe-context', 'probe-pinned'].includes(mode)) return;
392+
if (!['probe-history', 'probe-empty', 'probe-repair', 'probe-publication', 'probe-check-retry', 'probe-context', 'probe-pinned'].includes(mode)) {
338393
if (mode === 'all') {
339394
assert.match(source, /issue_comment:\s*types: \[created, edited, deleted\]/);
340395
const title = /run-name: >-\n\s*\$\{\{([\s\S]*?)\}\}/.exec(source);
@@ -395,6 +450,6 @@ async function publishedCheckRetryCases(baseFixture,first,selected) {
395450
}
396451
if (['all','probe-repair'].includes(mode)) await repairCases(fixture,first,selected);
397452
if (['all','probe-publication'].includes(mode)) await publicationCases(fixture,first,selected);
398-
if (['all','probe-check-retry'].includes(mode)) await publishedCheckRetryCases(fixture,first,selected);
453+
if (['all','probe-check-retry', 'probe-context', 'probe-pinned'].includes(mode)) await publishedCheckRetryCases(fixture,first,selected);
399454
console.log('Production invalidation and fresh historical-publication regressions passed');
400455
})().catch(error => { console.error(error); process.exitCode = 1; });

0 commit comments

Comments
 (0)