diff --git a/.github/workflows/copilot_bugbot_status_card.yml b/.github/workflows/copilot_bugbot_status_card.yml index 7a1f6a2d9..3df17b369 100644 --- a/.github/workflows/copilot_bugbot_status_card.yml +++ b/.github/workflows/copilot_bugbot_status_card.yml @@ -1,5 +1,5 @@ name: Copilot - Bugbot Status Card -run-name: Bugbot status · PR ${{ inputs.pull_number }} +run-name: Bugbot status · PR ${{ inputs.pull_number }} · ${{ inputs.operation }} on: workflow_dispatch: @@ -8,6 +8,10 @@ on: description: Pull request number required: true type: number + operation: + description: SHA-256 correlation of the versioned handoff; not publication authority + required: true + type: string work: description: Versioned publication handoff required: true diff --git a/build/github_action/index.js b/build/github_action/index.js index 0ee3642c3..f9b17b351 100644 --- a/build/github_action/index.js +++ b/build/github_action/index.js @@ -96336,7 +96336,7 @@ async function runGitHubAction(verificationAuthority) { event: eventName, ref, actor, server: serverUrl, workflowRef: process.env.GITHUB_WORKFLOW_REF ?? '', locale: (0, github_action_locale_inputs_1.readGithubActionLocaleInputs)(github_action_input_1.getGithubActionInput).pullRequest, policy: verificationAuthority?.policyDigest ?? 'default', - inputs: { pullNumber: payload.inputs?.pull_number, work: payload.inputs?.work }, + inputs: { pullNumber: payload.inputs?.pull_number, work: payload.inputs?.work, operation: payload.inputs?.operation }, }); if (effect === 'skipped') core.setFailed('No current Bugbot status card publication was authorized.'); @@ -164262,6 +164262,122 @@ function githubBugbotReviewProgress(context, summary, current, observeCheck, wak } +/***/ }), + +/***/ 86730: +/***/ ((__unused_webpack_module, exports, __nccwpck_require__) => { + +"use strict"; + +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.statusCardUnacknowledged = void 0; +exports.createGithubBugbotStatusCardAcknowledgment = createGithubBugbotStatusCardAcknowledgment; +const github_bugbot_status_card_handoff_1 = __nccwpck_require__(83620); +const positive_integer_policy_1 = __nccwpck_require__(19879); +const github_bugbot_status_card_installation_1 = __nccwpck_require__(31666); +class StatusCardAcknowledgmentError extends Error { +} +const statusCardUnacknowledged = () => new StatusCardAcknowledgmentError('The shared Bugbot status card writer did not acknowledge publication. Inspect its native run and retry acknowledgment; preserve the last verified card and Check fallback.'); +exports.statusCardUnacknowledged = statusCardUnacknowledged; +/** Correlation is data provenance, never independent producer-code attestation. */ +function createGithubBugbotStatusCardAcknowledgment(binding) { + const { read, write, scope, ref, runId, attempt, repositoryId } = binding; + const workflow = { ...scope, workflow_id: github_bugbot_status_card_installation_1.bugbotStatusCardWorkflow }; + const unresolved = exports.statusCardUnacknowledged; + const acknowledgments = new Map(); + return async (inputs, sequence) => { + const operation = (0, github_bugbot_status_card_handoff_1.githubBugbotStatusCardOperation)(inputs.work, sequence); + const title = 'Bugbot status · PR ' + inputs.pull_number + ' · ' + operation; + let acknowledgment = acknowledgments.get(operation); + if (!acknowledgment) { + acknowledgment = { issued: false }; + acknowledgments.set(operation, acknowledgment); + } + if (acknowledgment.id) + return { id: acknowledgment.id, title }; + if (acknowledgment.pending) + return { id: await acknowledgment.pending, title }; + const state = acknowledgment; + state.pending = (async () => { + if (!state.issued) { + // A lost response can still mean accepted: retry reads, never this POST. + state.issued = true; + const { data } = await write.request('POST /repos/{owner}/{repo}/actions/workflows/{workflow_id}/dispatches', { + ...workflow, ref, inputs: { ...inputs, operation }, return_run_details: true, + }); + const direct = (0, positive_integer_policy_1.parsePositiveSafeInteger)(data?.workflow_run_id); + if (direct) + return state.id = direct; + } + for (let lookup = 0; lookup < 6; lookup += 1) { + try { + const expected = await read.rest.actions.getWorkflow(workflow); + const origin = await read.rest.actions.getWorkflowRun({ ...scope, run_id: runId }); + const created = origin.data.created_at; + if (!(0, positive_integer_policy_1.parsePositiveSafeInteger)(expected.data.id) || expected.data.path !== github_bugbot_status_card_installation_1.bugbotStatusCardPath + || origin.data.id !== runId || origin.data.repository.id !== repositoryId || origin.data.run_attempt !== attempt + || typeof created !== 'string' || !Number.isFinite(Date.parse(created))) + throw unresolved(); + const matches = new Set(); + const seen = new Set(); + let complete = false; + let total; + for (let page = 1; page <= 10; page += 1) { + const response = await read.rest.actions.listWorkflowRuns({ ...workflow, + branch: ref, event: 'workflow_dispatch', created: '>=' + created, per_page: 100, page }); + const data = response.data; + if (!Array.isArray(data.workflow_runs) || data.workflow_runs.length > 100 + || !Number.isSafeInteger(data.total_count) || data.total_count < 0 + || total !== undefined && total !== data.total_count) + throw unresolved(); + total = data.total_count; + for (const run of data.workflow_runs) { + const id = (0, positive_integer_policy_1.parsePositiveSafeInteger)(run.id); + if (!id || seen.has(id)) + throw unresolved(); + seen.add(id); + if (run.repository.id === repositoryId && run.workflow_id === expected.data.id + && run.path === github_bugbot_status_card_installation_1.bugbotStatusCardPath && run.event === 'workflow_dispatch' + && run.head_branch === ref && run.display_title === title && run.run_attempt === 1 + && Number.isFinite(Date.parse(run.created_at)) && Date.parse(run.created_at) >= Date.parse(created)) + matches.add(id); + } + if (seen.size === total || data.workflow_runs.length < 100) { + if (data.total_count !== seen.size) + throw unresolved(); + complete = true; + break; + } + } + if (!complete || matches.size > 1) + throw unresolved(); + if (matches.size === 1) + return state.id = [...matches][0]; + } + catch (error) { + if ([401, 403].includes(Number((0, github_bugbot_status_card_installation_1.statusCardGithubErrorStatus)(error))) || error instanceof StatusCardAcknowledgmentError) + throw unresolved(); + if (lookup === 5) + throw unresolved(); + } + if (lookup < 5) + await new Promise(resolve => setTimeout(resolve, 500)); + } + throw unresolved(); + })().catch(() => { throw unresolved(); }); + try { + return { id: await state.pending, title }; + } + catch { + throw unresolved(); + } + finally { + state.pending = undefined; + } + }; +} + + /***/ }), /***/ 42190: @@ -164278,7 +164394,8 @@ const positive_integer_policy_1 = __nccwpck_require__(19879); const github_pull_request_client_factory_1 = __nccwpck_require__(9068); const github_bugbot_status_card_handoff_1 = __nccwpck_require__(83620); const github_bugbot_status_card_installation_1 = __nccwpck_require__(31666); -const unresolved = () => new Error('The shared Bugbot status card writer did not acknowledge publication.'); +const github_bugbot_status_card_acknowledgment_1 = __nccwpck_require__(86730); +const unresolved = github_bugbot_status_card_acknowledgment_1.statusCardUnacknowledged; async function createGithubBugbotStatusCardDispatcher(binding, environment = process.env) { const runId = (0, positive_integer_policy_1.parsePositiveSafeInteger)(environment.GITHUB_RUN_ID); const attempt = (0, positive_integer_policy_1.parsePositiveSafeInteger)(environment.GITHUB_RUN_ATTEMPT); @@ -164291,23 +164408,16 @@ async function createGithubBugbotStatusCardDispatcher(binding, environment = pro const read = (0, github_1.getOctokit)(binding.evidenceToken); const write = (0, github_1.getOctokit)(binding.token); const scope = { owner: binding.owner, repo: binding.repository }; - const workflow = { ...scope, workflow_id: github_bugbot_status_card_installation_1.bugbotStatusCardWorkflow }; const installation = await (0, github_bugbot_status_card_installation_1.readGithubBugbotStatusCardInstallation)(read, scope, ref); if (installation === 'absent') return undefined; const pullRequests = new pull_request_lifecycle_repository_1.PullRequestLifecycleRepository((0, github_pull_request_client_factory_1.createPullRequestLifecycleClient)()); - const dispatch = async (request) => { + const acknowledge = (0, github_bugbot_status_card_acknowledgment_1.createGithubBugbotStatusCardAcknowledgment)({ read, write, scope, ref, runId, attempt, repositoryId }); + const dispatch = async (request, sequence) => { const inputs = (0, github_bugbot_status_card_handoff_1.encodeGithubBugbotStatusCardHandoff)(request); if (installation !== 'installed' || !inputs) throw unresolved(); - const { data } = await write.request('POST /repos/{owner}/{repo}/actions/workflows/{workflow_id}/dispatches', { - ...workflow, ref, inputs, return_run_details: true, - }); - const published = data; - const operation = (0, positive_integer_policy_1.parsePositiveSafeInteger)(published?.workflow_run_id); - if (!operation) - throw unresolved(); - return operation; + return acknowledge(inputs, sequence); }; const terminal = { async publish(input) { @@ -164325,7 +164435,7 @@ async function createGithubBugbotStatusCardDispatcher(binding, environment = pro // This deadline is only for acknowledging the short comment job. const until = Date.now() + 7 * 60000; while (Date.now() < until) { - const observed = await read.rest.actions.getWorkflowRun({ ...scope, run_id: effect }).catch((error) => { + const observed = await read.rest.actions.getWorkflowRun({ ...scope, run_id: effect.id }).catch((error) => { if ((0, github_bugbot_status_card_installation_1.statusCardGithubErrorStatus)(error) === 404) return undefined; throw unresolved(); @@ -164335,13 +164445,13 @@ async function createGithubBugbotStatusCardDispatcher(binding, environment = pro continue; } const { data } = observed; - if (data.id !== effect || data.repository.id !== repositoryId || data.path !== github_bugbot_status_card_installation_1.bugbotStatusCardPath + if (data.id !== effect.id || data.display_title !== effect.title || data.run_attempt !== 1 || data.repository.id !== repositoryId || data.path !== github_bugbot_status_card_installation_1.bugbotStatusCardPath || data.event !== 'workflow_dispatch' || data.head_branch !== ref) throw unresolved(); if (data.status === 'completed') { if (data.conclusion !== 'success') throw unresolved(); - const { data: jobs } = await read.rest.actions.listJobsForWorkflowRun({ ...scope, run_id: effect, per_page: 20, filter: 'latest' }); + const { data: jobs } = await read.rest.actions.listJobsForWorkflowRun({ ...scope, run_id: effect.id, per_page: 20, filter: 'latest' }); if (jobs.total_count === 1 && jobs.jobs.length === 1 && jobs.jobs[0].name === 'Publish Bugbot status card' && jobs.jobs[0].head_sha === data.head_sha && jobs.jobs[0].conclusion === 'success' && jobs.jobs[0].steps?.some((step) => step.name === 'Publish canonical comment' && step.conclusion === 'success')) @@ -164359,7 +164469,7 @@ async function createGithubBugbotStatusCardDispatcher(binding, environment = pro if (installation !== 'installed' || !observation.baseSha) return; await dispatch({ kind: 'progress', runId, attempt, source: { repositoryId, pullNumber: observation.pullNumber, - base: observation.baseSha, baseRef: observation.baseRefSha ?? observation.baseSha, head: observation.headSha, policy: binding.policy } }); + base: observation.baseSha, baseRef: observation.baseRefSha ?? observation.baseSha, head: observation.headSha, policy: binding.policy } }, observation.sequence); }, }; } @@ -164375,6 +164485,8 @@ async function createGithubBugbotStatusCardDispatcher(binding, environment = pro Object.defineProperty(exports, "__esModule", ({ value: true })); exports.decodeGithubBugbotStatusCardHandoff = decodeGithubBugbotStatusCardHandoff; exports.encodeGithubBugbotStatusCardHandoff = encodeGithubBugbotStatusCardHandoff; +exports.githubBugbotStatusCardOperation = githubBugbotStatusCardOperation; +const node_crypto_1 = __nccwpck_require__(6005); const bugbot_status_card_publication_policy_1 = __nccwpck_require__(4809); const positive_integer_policy_1 = __nccwpck_require__(19879); const maxHandoffBytes = 64000; @@ -164425,6 +164537,12 @@ function encodeGithubBugbotStatusCardHandoff(request) { const work = JSON.stringify({ version: 1, ...request }); return decodeGithubBugbotStatusCardHandoff({ pullNumber, work }) ? { pull_number: String(pullNumber), work } : undefined; } +/** A correlation key binds bytes; the worker still validates publication authority. */ +function githubBugbotStatusCardOperation(work, sequence) { + if (sequence !== undefined && (!Number.isSafeInteger(sequence) || sequence < 0)) + throw new Error('Invalid progress correlation sequence.'); + return (sequence === undefined ? '' : String(sequence) + ':') + (0, node_crypto_1.createHash)('sha256').update(work).digest('hex'); +} /***/ }), @@ -164611,9 +164729,15 @@ const sourceEvents = new Map([ ]); async function runGithubBugbotStatusCardWorkflow(binding) { const request = (0, github_bugbot_status_card_handoff_1.decodeGithubBugbotStatusCardHandoff)(binding.inputs); + const correlation = typeof binding.inputs.operation === 'string' + ? binding.inputs.operation.match(/^(0|[1-9]\d*):[a-f0-9]{64}$/u)?.[1] : undefined; + const sequence = correlation === undefined ? undefined : Number(correlation); const repository = binding.owner + '/' + binding.repository; if (binding.event !== 'workflow_dispatch' || binding.workflowRef !== repository + '/' + github_bugbot_status_card_installation_1.bugbotStatusCardPath + '@' + binding.ref - || !/^https:\/\/[a-z0-9.-]+(?::\d+)?$/iu.test(binding.server) || !request) + || !/^https:\/\/[a-z0-9.-]+(?::\d+)?$/iu.test(binding.server) || !request + || request.kind === 'progress' && (sequence === undefined || !Number.isSafeInteger(sequence)) + || typeof binding.inputs.work !== 'string' + || binding.inputs.operation !== (0, github_bugbot_status_card_handoff_1.githubBugbotStatusCardOperation)(binding.inputs.work, request.kind === 'progress' ? sequence : undefined)) return 'skipped'; const api = (0, github_1.getOctokit)(binding.evidenceToken); const scope = { owner: binding.owner, repo: binding.repository }; diff --git a/docs/bugbot/failure-scenarios.mdx b/docs/bugbot/failure-scenarios.mdx index cbe25394f..455fa079a 100644 --- a/docs/bugbot/failure-scenarios.mdx +++ b/docs/bugbot/failure-scenarios.mdx @@ -193,3 +193,24 @@ confirmation. Correct the named provider/response cause and recheck from the current source; preserve identity and reconciliation checks. Completed writes remain in place and must not be repeated blindly. See the [structured error reference](/security-operations/operations/error-reference#conflict-eligibility-and-review-freshness). + +## Shared writer acknowledgment + +An accepted status-writer dispatch can omit its run ID. The caller recovers only +one native run that matches the exact handoff operation, repository, workflow, +default ref and producer attempt. A recent run on the same PR is insufficient. +The matching source workflow must be installed on trusted default; preparing a +PR or merging develop does not establish installation. + +If acknowledgment remains unavailable, inspect the native writer run and retry +acknowledgment. The previous verified card and Review check remain authoritative; +no completed publication receipt or unqueued card fallback is issued. A retry in +the same producer adapter reads the accepted operation instead of repeating its +POST. A native rerun creates a new producer attempt and retains the existing +source/head/policy fences. This is not a durable exactly-once guarantee across +arbitrary process restarts. + +Missing permission, foreign or ambiguous runs and incomplete listings fail +closed. The bounded lookup applies to this short publication acknowledgment; +it imposes no model investigation deadline or token/turn/read limit. Operation +correlation establishes data/run identity, not independent code attestation. diff --git a/quality/bugbot/evidence/issue-976/README.md b/quality/bugbot/evidence/issue-976/README.md new file mode 100644 index 000000000..67fc25812 --- /dev/null +++ b/quality/bugbot/evidence/issue-976/README.md @@ -0,0 +1,35 @@ +# Accepted dispatch acknowledgment — #976 + +The five focused dispatch, worker, handoff, publication-workflow and policy +suites pass **62 tests** with fake providers. The dispatch matrix includes the +direct ID, unique accepted 204, absent/ambiguous match, foreign workflow/ref/ +repository/operation, denied lookup permission, transient workflow/origin/list +reads, acknowledgment replay, a foreign direct ID, later/incomplete pages, +lost POST response, concurrent retries, replaced origin and progress sequences. +The actual worker rejects a missing/forged correlation before provider reads. + +The caller hashes the actual encoded handoff. Progress includes its native +observation sequence in the correlation so subsequent progress still wakes the +writer. A replay shares the accepted operation rather than blindly sending +another POST. The worker independently recomputes the hash before applying its +existing source, actor, head, policy, attempt and serialized-publication checks. +Run/data correlation is not independent attestation of executable producer code. + +The first three control attempts could not compile: two TypeScript inference +errors, followed by a stale numeric run-ID use after introducing a typed effect. +They executed zero tests. Their logs are preserved. Subsequent controls passed +17, 47, 59 and 60 tests as receipt binding, worker validation and progress cases +were completed; `final-controls.log.gz` records all 62. These are implementation +controls, not model qualification campaigns or live installation evidence. + +Run the five Jest files named in the final log. Source workflow validation, +typecheck, lint, generated-bundle and specification/docs checks accompany the +PR's delivery SHA. The owning SDD and catalog register this adapter and its +fixed acknowledgment bounds. There is no model investigation deadline or +new user configuration. Consumer installation templates are unchanged. + +No model or real GitHub call occurs in these controls. A completed handoff +receipt is unavailable on failure; existing publication controls preserve the +last verified card and Check fallback. Production verification stays disabled. +The corresponding workflow still needs explicit reviewed installation on the +trusted default branch under #977. A develop PR cannot establish installation. diff --git a/quality/bugbot/evidence/issue-976/controls-2.log.gz b/quality/bugbot/evidence/issue-976/controls-2.log.gz new file mode 100644 index 000000000..61c471d8a Binary files /dev/null and b/quality/bugbot/evidence/issue-976/controls-2.log.gz differ diff --git a/quality/bugbot/evidence/issue-976/controls-3.log.gz b/quality/bugbot/evidence/issue-976/controls-3.log.gz new file mode 100644 index 000000000..0afdd723f Binary files /dev/null and b/quality/bugbot/evidence/issue-976/controls-3.log.gz differ diff --git a/quality/bugbot/evidence/issue-976/controls-4.log.gz b/quality/bugbot/evidence/issue-976/controls-4.log.gz new file mode 100644 index 000000000..932ca66b5 Binary files /dev/null and b/quality/bugbot/evidence/issue-976/controls-4.log.gz differ diff --git a/quality/bugbot/evidence/issue-976/controls-5.log.gz b/quality/bugbot/evidence/issue-976/controls-5.log.gz new file mode 100644 index 000000000..aa01599cc Binary files /dev/null and b/quality/bugbot/evidence/issue-976/controls-5.log.gz differ diff --git a/quality/bugbot/evidence/issue-976/controls-6.log.gz b/quality/bugbot/evidence/issue-976/controls-6.log.gz new file mode 100644 index 000000000..9b0cc307d Binary files /dev/null and b/quality/bugbot/evidence/issue-976/controls-6.log.gz differ diff --git a/quality/bugbot/evidence/issue-976/controls-7.log.gz b/quality/bugbot/evidence/issue-976/controls-7.log.gz new file mode 100644 index 000000000..d464a4b71 Binary files /dev/null and b/quality/bugbot/evidence/issue-976/controls-7.log.gz differ diff --git a/quality/bugbot/evidence/issue-976/final-controls.log.gz b/quality/bugbot/evidence/issue-976/final-controls.log.gz new file mode 100644 index 000000000..466f30382 Binary files /dev/null and b/quality/bugbot/evidence/issue-976/final-controls.log.gz differ diff --git a/quality/bugbot/evidence/issue-976/initial-controls.log.gz b/quality/bugbot/evidence/issue-976/initial-controls.log.gz new file mode 100644 index 000000000..33ebf23d1 Binary files /dev/null and b/quality/bugbot/evidence/issue-976/initial-controls.log.gz differ diff --git a/specs/CATALOG.md b/specs/CATALOG.md index ab1f8e793..bcb72c409 100644 --- a/specs/CATALOG.md +++ b/specs/CATALOG.md @@ -13,7 +13,7 @@ debt or convert unknown historic intent into a design decision. | `github-communication-experience` | Implemented | English-default, localized, semantic, bounded and idempotent product messages across GitHub and repository-aware operator surfaces; complete acceptance batches and cards with stable source identities, verified published SDD provenance, shared complete-inventory text allocation, precise response diagnostics and same-head requirement evidence before Commit progress publication; shared bounded complete-batch recovery for attributable completed acceptance-field length or completion failures; bounded closed-fact recovery and compact large-inventory assessment, exact original hard allocations, explicit admission counts and non-retryable length exhaustion with separate live-provider qualification; exact JSON-byte allocation and one shared source-part size replacement for both framed profiles, captured request contracts, receipt quota revalidation and nonretryable unit-specific exhaustion; shared same-profile complete-batch correction for otherwise-valid repeated citations with current-request origin binding, unchanged evidence gates and nonretryable citation exhaustion | [Semantic GitHub communication and repository localization](./semantic-github-publication-and-notification.md) + 11 companion | 462 paths · 2026-11-18 | | `release-orchestration` | Implemented | Release and hotfix promotion, publication, bounded merge readiness recovery, and receipt-verified reconciliation without republication; explicit native-guarded replacement of closed unpublished candidates with complete fresh validation and bounded audit history | [Configurable production-first release orchestration](./configurable-release-orchestration.md) + 3 companion | 91 paths · 2026-10-30 | | `merge-queue-readiness` | Implemented | Fail-closed validation of required checks and merge-group workflow support; optional manual-only RepoWise analysis with independent CI and verified required-check migration; cached RepoWise exports and bounded full-history secret processing with truthful completeness and resource evidence | [Merge queue readiness and effective target rules](./merge-queue-readiness.md) | 29 paths · 2026-10-21 | -| `bugbot-review-state-reconciliation` | Implemented | Reconcile review snapshots, findings, threads, comments, and check conclusions | [Bugbot review-state reconciliation](./bugbot-review-state-reconciliation.md) | 106 paths · 2026-11-19 | +| `bugbot-review-state-reconciliation` | Implemented | Reconcile review snapshots, findings, threads, comments, and check conclusions | [Bugbot review-state reconciliation](./bugbot-review-state-reconciliation.md) | 108 paths · 2026-11-19 | | `execution-lifecycle` | Implemented | Shared GitHub Action lifecycle with pinned native resource/lane coordination proof, conservative predecessor fencing, routing and durable user-facing results | [Execution admission, queueing, routing, and result publication](./execution-admission-queue-and-publication.md) + 4 companion | 161 paths · 2026-10-29 | | `architecture-quality-hardening` | Implemented | Close verified concurrency, error-contract, context-coupling, fan-out, setup/doctor, and provider-policy risks in dependency order | [Architecture quality and scalability hardening](./architecture-quality-and-scalability-hardening.md) + 1 companion | 72 paths · 2026-10-13 | | `setup-and-doctor` | Implemented | Plan, validate, provision, and audit a repository installation without exposing credentials | [Setup, configuration, credentials, and doctor](./setup-configuration-credentials-and-doctor.md) + 6 companion | 334 paths · 2026-10-29 | @@ -75,7 +75,7 @@ debt or convert unknown historic intent into a design decision. - Specifications: [`specs/bugbot-review-state-reconciliation.md`](./bugbot-review-state-reconciliation.md) - Workflows: [`.github/workflows/copilot_commit.yml`](../.github/workflows/copilot_commit.yml) · [`.github/workflows/copilot_pull_request.yml`](../.github/workflows/copilot_pull_request.yml) · [`.github/workflows/copilot_pull_request_comment.yml`](../.github/workflows/copilot_pull_request_comment.yml) · [`.github/workflows/copilot_pull_request_review_state.yml`](../.github/workflows/copilot_pull_request_review_state.yml) · [`setup/workflows/copilot_pull_request.yml`](../setup/workflows/copilot_pull_request.yml) · [`setup/workflows/copilot_pull_request_review_state.yml`](../setup/workflows/copilot_pull_request_review_state.yml) · [`.github/workflows/copilot_bugbot_status_card.yml`](../.github/workflows/copilot_bugbot_status_card.yml) - Entrypoints: [`src/application/usecases/steps/commit/detect_potential_problems_workflow.ts`](../src/application/usecases/steps/commit/detect_potential_problems_workflow.ts) · [`src/application/usecases/steps/commit/bugbot/reconcile_bugbot_review_state_use_case.ts`](../src/application/usecases/steps/commit/bugbot/reconcile_bugbot_review_state_use_case.ts) · [`src/actions/github_action_completion.ts`](../src/actions/github_action_completion.ts) · [`src/api.ts`](../src/api.ts) -- Core code: [`scripts/coverage-budgets.json`](../scripts/coverage-budgets.json) · [`src/domain/bugbot/review_state.ts`](../src/domain/bugbot/review_state.ts) · [`src/domain/bugbot/review_projection.ts`](../src/domain/bugbot/review_projection.ts) · [`src/application/policies/bugbot_reconciliation_policy.ts`](../src/application/policies/bugbot_reconciliation_policy.ts) · [`src/application/policies/bugbot_event_ownership_policy.ts`](../src/application/policies/bugbot_event_ownership_policy.ts) · [`src/application/policies/bugbot_result_finding_state_projection_policy.ts`](../src/application/policies/bugbot_result_finding_state_projection_policy.ts) · [`src/application/policies/bugbot_telemetry_projection_policy.ts`](../src/application/policies/bugbot_telemetry_projection_policy.ts) · [`src/application/policies/bugbot_message_catalog.ts`](../src/application/policies/bugbot_message_catalog.ts) · [`src/application/policies/bugbot_finding_marker_policy.ts`](../src/application/policies/bugbot_finding_marker_policy.ts) · [`src/application/policies/bugbot_review_presentation_policy.ts`](../src/application/policies/bugbot_review_presentation_policy.ts) · [`src/application/policies/action_summary_policy.ts`](../src/application/policies/action_summary_policy.ts) · [`src/application/policies/copilot_evidence_policy.ts`](../src/application/policies/copilot_evidence_policy.ts) · [`src/application/policies/lifecycle_state_policy.ts`](../src/application/policies/lifecycle_state_policy.ts) · [`src/application/policies/status_command_policy.ts`](../src/application/policies/status_command_policy.ts) · [`src/application/usecases/steps/common/publish_resume_workflow.ts`](../src/application/usecases/steps/common/publish_resume_workflow.ts) · [`src/application/usecases/steps/commit/bugbot/load_bugbot_context_use_case.ts`](../src/application/usecases/steps/commit/bugbot/load_bugbot_context_use_case.ts) · [`src/application/usecases/steps/commit/bugbot/schema.ts`](../src/application/usecases/steps/commit/bugbot/schema.ts) · [`src/application/usecases/steps/commit/bugbot/prepare_bugbot_findings_policy.ts`](../src/application/usecases/steps/commit/bugbot/prepare_bugbot_findings_policy.ts) · [`src/application/usecases/steps/commit/bugbot/publish_pr_review_comments.ts`](../src/application/usecases/steps/commit/bugbot/publish_pr_review_comments.ts) · [`src/application/usecases/steps/commit/bugbot/synchronize_bugbot_review_presentation_use_case.ts`](../src/application/usecases/steps/commit/bugbot/synchronize_bugbot_review_presentation_use_case.ts) · [`src/application/policies/bugbot_status_count_marker_policy.ts`](../src/application/policies/bugbot_status_count_marker_policy.ts) · [`src/application/errors/bugbot_mutation_error.ts`](../src/application/errors/bugbot_mutation_error.ts) · [`src/data/repository/pull_request/pull_request_review_error_metadata.ts`](../src/data/repository/pull_request/pull_request_review_error_metadata.ts) · [`src/domain/bugbot/finding.ts`](../src/domain/bugbot/finding.ts) · [`src/application/usecases/steps/commit/bugbot/analyze_bugbot_revision_use_case.ts`](../src/application/usecases/steps/commit/bugbot/analyze_bugbot_revision_use_case.ts) · [`src/application/usecases/steps/commit/bugbot/publish_findings_use_case.ts`](../src/application/usecases/steps/commit/bugbot/publish_findings_use_case.ts) · [`scripts/validate-workflow-contract.cjs`](../scripts/validate-workflow-contract.cjs) · [`src/application/policies/bugbot_resolution_eligibility_policy.ts`](../src/application/policies/bugbot_resolution_eligibility_policy.ts) · [`src/application/usecases/steps/commit/bugbot/resolve_pull_request_finding.ts`](../src/application/usecases/steps/commit/bugbot/resolve_pull_request_finding.ts) · [`src/application/usecases/steps/commit/bugbot/mark_findings_resolved_workflow.ts`](../src/application/usecases/steps/commit/bugbot/mark_findings_resolved_workflow.ts) · [`src/application/usecases/steps/commit/bugbot/verify_reopened_finding_thread.ts`](../src/application/usecases/steps/commit/bugbot/verify_reopened_finding_thread.ts) · [`src/application/ports/bugbot_pull_request_resolution_ports.ts`](../src/application/ports/bugbot_pull_request_resolution_ports.ts) · [`src/application/ports/bugbot_pull_request_write_ports.ts`](../src/application/ports/bugbot_pull_request_write_ports.ts) · [`src/application/ports/pull_request_review_comment_ports.ts`](../src/application/ports/pull_request_review_comment_ports.ts) · [`src/infrastructure/composition/bugbot_scm_port_factory.ts`](../src/infrastructure/composition/bugbot_scm_port_factory.ts) · [`src/application/policies/bugbot_commit_progress_link_policy.ts`](../src/application/policies/bugbot_commit_progress_link_policy.ts) · [`src/infrastructure/github/github_bugbot_interrupted_check.ts`](../src/infrastructure/github/github_bugbot_interrupted_check.ts) · [`src/application/policies/bugbot_progress_check_observation_policy.ts`](../src/application/policies/bugbot_progress_check_observation_policy.ts) · [`src/application/policies/bugbot_status_card_publication_policy.ts`](../src/application/policies/bugbot_status_card_publication_policy.ts) · [`src/infrastructure/github/github_bugbot_status_card_workflow.ts`](../src/infrastructure/github/github_bugbot_status_card_workflow.ts) · [`src/infrastructure/github/github_bugbot_status_card_dispatch.ts`](../src/infrastructure/github/github_bugbot_status_card_dispatch.ts) · [`src/infrastructure/github/native_list_pagination.ts`](../src/infrastructure/github/native_list_pagination.ts) +- Core code: [`scripts/coverage-budgets.json`](../scripts/coverage-budgets.json) · [`src/domain/bugbot/review_state.ts`](../src/domain/bugbot/review_state.ts) · [`src/domain/bugbot/review_projection.ts`](../src/domain/bugbot/review_projection.ts) · [`src/application/policies/bugbot_reconciliation_policy.ts`](../src/application/policies/bugbot_reconciliation_policy.ts) · [`src/application/policies/bugbot_event_ownership_policy.ts`](../src/application/policies/bugbot_event_ownership_policy.ts) · [`src/application/policies/bugbot_result_finding_state_projection_policy.ts`](../src/application/policies/bugbot_result_finding_state_projection_policy.ts) · [`src/application/policies/bugbot_telemetry_projection_policy.ts`](../src/application/policies/bugbot_telemetry_projection_policy.ts) · [`src/application/policies/bugbot_message_catalog.ts`](../src/application/policies/bugbot_message_catalog.ts) · [`src/application/policies/bugbot_finding_marker_policy.ts`](../src/application/policies/bugbot_finding_marker_policy.ts) · [`src/application/policies/bugbot_review_presentation_policy.ts`](../src/application/policies/bugbot_review_presentation_policy.ts) · [`src/application/policies/action_summary_policy.ts`](../src/application/policies/action_summary_policy.ts) · [`src/application/policies/copilot_evidence_policy.ts`](../src/application/policies/copilot_evidence_policy.ts) · [`src/application/policies/lifecycle_state_policy.ts`](../src/application/policies/lifecycle_state_policy.ts) · [`src/application/policies/status_command_policy.ts`](../src/application/policies/status_command_policy.ts) · [`src/application/usecases/steps/common/publish_resume_workflow.ts`](../src/application/usecases/steps/common/publish_resume_workflow.ts) · [`src/application/usecases/steps/commit/bugbot/load_bugbot_context_use_case.ts`](../src/application/usecases/steps/commit/bugbot/load_bugbot_context_use_case.ts) · [`src/application/usecases/steps/commit/bugbot/schema.ts`](../src/application/usecases/steps/commit/bugbot/schema.ts) · [`src/application/usecases/steps/commit/bugbot/prepare_bugbot_findings_policy.ts`](../src/application/usecases/steps/commit/bugbot/prepare_bugbot_findings_policy.ts) · [`src/application/usecases/steps/commit/bugbot/publish_pr_review_comments.ts`](../src/application/usecases/steps/commit/bugbot/publish_pr_review_comments.ts) · [`src/application/usecases/steps/commit/bugbot/synchronize_bugbot_review_presentation_use_case.ts`](../src/application/usecases/steps/commit/bugbot/synchronize_bugbot_review_presentation_use_case.ts) · [`src/application/policies/bugbot_status_count_marker_policy.ts`](../src/application/policies/bugbot_status_count_marker_policy.ts) · [`src/application/errors/bugbot_mutation_error.ts`](../src/application/errors/bugbot_mutation_error.ts) · [`src/data/repository/pull_request/pull_request_review_error_metadata.ts`](../src/data/repository/pull_request/pull_request_review_error_metadata.ts) · [`src/domain/bugbot/finding.ts`](../src/domain/bugbot/finding.ts) · [`src/application/usecases/steps/commit/bugbot/analyze_bugbot_revision_use_case.ts`](../src/application/usecases/steps/commit/bugbot/analyze_bugbot_revision_use_case.ts) · [`src/application/usecases/steps/commit/bugbot/publish_findings_use_case.ts`](../src/application/usecases/steps/commit/bugbot/publish_findings_use_case.ts) · [`scripts/validate-workflow-contract.cjs`](../scripts/validate-workflow-contract.cjs) · [`src/application/policies/bugbot_resolution_eligibility_policy.ts`](../src/application/policies/bugbot_resolution_eligibility_policy.ts) · [`src/application/usecases/steps/commit/bugbot/resolve_pull_request_finding.ts`](../src/application/usecases/steps/commit/bugbot/resolve_pull_request_finding.ts) · [`src/application/usecases/steps/commit/bugbot/mark_findings_resolved_workflow.ts`](../src/application/usecases/steps/commit/bugbot/mark_findings_resolved_workflow.ts) · [`src/application/usecases/steps/commit/bugbot/verify_reopened_finding_thread.ts`](../src/application/usecases/steps/commit/bugbot/verify_reopened_finding_thread.ts) · [`src/application/ports/bugbot_pull_request_resolution_ports.ts`](../src/application/ports/bugbot_pull_request_resolution_ports.ts) · [`src/application/ports/bugbot_pull_request_write_ports.ts`](../src/application/ports/bugbot_pull_request_write_ports.ts) · [`src/application/ports/pull_request_review_comment_ports.ts`](../src/application/ports/pull_request_review_comment_ports.ts) · [`src/infrastructure/composition/bugbot_scm_port_factory.ts`](../src/infrastructure/composition/bugbot_scm_port_factory.ts) · [`src/application/policies/bugbot_commit_progress_link_policy.ts`](../src/application/policies/bugbot_commit_progress_link_policy.ts) · [`src/infrastructure/github/github_bugbot_interrupted_check.ts`](../src/infrastructure/github/github_bugbot_interrupted_check.ts) · [`src/application/policies/bugbot_progress_check_observation_policy.ts`](../src/application/policies/bugbot_progress_check_observation_policy.ts) · [`src/application/policies/bugbot_status_card_publication_policy.ts`](../src/application/policies/bugbot_status_card_publication_policy.ts) · [`src/infrastructure/github/github_bugbot_status_card_workflow.ts`](../src/infrastructure/github/github_bugbot_status_card_workflow.ts) · [`src/infrastructure/github/github_bugbot_status_card_dispatch.ts`](../src/infrastructure/github/github_bugbot_status_card_dispatch.ts) · [`src/infrastructure/github/native_list_pagination.ts`](../src/infrastructure/github/native_list_pagination.ts) · [`src/infrastructure/github/github_bugbot_status_card_acknowledgment.ts`](../src/infrastructure/github/github_bugbot_status_card_acknowledgment.ts) · [`src/infrastructure/github/github_bugbot_status_card_handoff.ts`](../src/infrastructure/github/github_bugbot_status_card_handoff.ts) - Tests: [`src/domain/bugbot/__tests__/review_state.test.ts`](../src/domain/bugbot/__tests__/review_state.test.ts) · [`src/domain/bugbot/__tests__/review_projection.test.ts`](../src/domain/bugbot/__tests__/review_projection.test.ts) · [`src/application/usecases/steps/commit/bugbot/__tests__/schema.test.ts`](../src/application/usecases/steps/commit/bugbot/__tests__/schema.test.ts) · [`src/application/usecases/steps/commit/bugbot/__tests__/prepare_bugbot_findings.test.ts`](../src/application/usecases/steps/commit/bugbot/__tests__/prepare_bugbot_findings.test.ts) · [`src/application/usecases/steps/commit/bugbot/__tests__/reconcile_bugbot_review_state_integration.test.ts`](../src/application/usecases/steps/commit/bugbot/__tests__/reconcile_bugbot_review_state_integration.test.ts) · [`src/application/usecases/steps/commit/bugbot/__tests__/synchronize_bugbot_review_presentation_use_case.test.ts`](../src/application/usecases/steps/commit/bugbot/__tests__/synchronize_bugbot_review_presentation_use_case.test.ts) · [`src/application/policies/__tests__/bugbot_result_finding_state_projection_policy.test.ts`](../src/application/policies/__tests__/bugbot_result_finding_state_projection_policy.test.ts) · [`src/application/policies/__tests__/bugbot_event_ownership_policy.test.ts`](../src/application/policies/__tests__/bugbot_event_ownership_policy.test.ts) · [`src/application/policies/__tests__/bugbot_telemetry_projection_policy.test.ts`](../src/application/policies/__tests__/bugbot_telemetry_projection_policy.test.ts) · [`src/application/policies/__tests__/bugbot_message_catalog.test.ts`](../src/application/policies/__tests__/bugbot_message_catalog.test.ts) · [`src/application/policies/__tests__/bugbot_finding_marker_policy.test.ts`](../src/application/policies/__tests__/bugbot_finding_marker_policy.test.ts) · [`src/application/policies/__tests__/bugbot_review_presentation_policy.test.ts`](../src/application/policies/__tests__/bugbot_review_presentation_policy.test.ts) · [`src/application/policies/__tests__/action_summary_policy.test.ts`](../src/application/policies/__tests__/action_summary_policy.test.ts) · [`src/application/policies/__tests__/copilot_evidence_policy.test.ts`](../src/application/policies/__tests__/copilot_evidence_policy.test.ts) · [`src/application/policies/__tests__/lifecycle_state_policy.test.ts`](../src/application/policies/__tests__/lifecycle_state_policy.test.ts) · [`src/application/policies/__tests__/status_command_policy.test.ts`](../src/application/policies/__tests__/status_command_policy.test.ts) · [`src/actions/__tests__/github_action_completion.test.ts`](../src/actions/__tests__/github_action_completion.test.ts) · [`src/application/usecases/steps/common/__tests__/publish_resume_use_case.test.ts`](../src/application/usecases/steps/common/__tests__/publish_resume_use_case.test.ts) · [`src/application/usecases/actions/__tests__/synchronize_lifecycle_state_use_case.test.ts`](../src/application/usecases/actions/__tests__/synchronize_lifecycle_state_use_case.test.ts) · [`src/application/usecases/steps/commit/__tests__/detect_potential_problems_use_case.test.ts`](../src/application/usecases/steps/commit/__tests__/detect_potential_problems_use_case.test.ts) · [`src/infrastructure/composition/__tests__/pull_request_use_case_composition_root.test.ts`](../src/infrastructure/composition/__tests__/pull_request_use_case_composition_root.test.ts) · [`src/tooling/__tests__/validate_workflow_contract.test.ts`](../src/tooling/__tests__/validate_workflow_contract.test.ts) · [`src/application/errors/__tests__/bugbot_mutation_error.test.ts`](../src/application/errors/__tests__/bugbot_mutation_error.test.ts) · [`src/application/usecases/steps/commit/bugbot/__tests__/finding_mutation_recovery.test.ts`](../src/application/usecases/steps/commit/bugbot/__tests__/finding_mutation_recovery.test.ts) · [`src/domain/bugbot/__tests__/finding.test.ts`](../src/domain/bugbot/__tests__/finding.test.ts) · [`src/application/usecases/steps/commit/bugbot/__tests__/finding_identity_replay.test.ts`](../src/application/usecases/steps/commit/bugbot/__tests__/finding_identity_replay.test.ts) · [`src/application/usecases/steps/commit/bugbot/__tests__/analyze_bugbot_revision_use_case.test.ts`](../src/application/usecases/steps/commit/bugbot/__tests__/analyze_bugbot_revision_use_case.test.ts) · [`src/application/usecases/steps/commit/bugbot/__tests__/publish_findings_use_case.test.ts`](../src/application/usecases/steps/commit/bugbot/__tests__/publish_findings_use_case.test.ts) · [`src/application/policies/__tests__/bugbot_resolution_eligibility_policy.test.ts`](../src/application/policies/__tests__/bugbot_resolution_eligibility_policy.test.ts) · [`src/application/usecases/steps/commit/bugbot/__tests__/reopened_dismissal_reconciliation.test.ts`](../src/application/usecases/steps/commit/bugbot/__tests__/reopened_dismissal_reconciliation.test.ts) · [`src/infrastructure/composition/__tests__/bugbot_scm_port_factory.test.ts`](../src/infrastructure/composition/__tests__/bugbot_scm_port_factory.test.ts) · [`src/application/ports/__tests__/bugbot_port_boundaries.test.ts`](../src/application/ports/__tests__/bugbot_port_boundaries.test.ts) · [`src/application/policies/__tests__/bugbot_commit_progress_link_policy.test.ts`](../src/application/policies/__tests__/bugbot_commit_progress_link_policy.test.ts) · [`src/infrastructure/github/__tests__/github_bugbot_interrupted_check.test.ts`](../src/infrastructure/github/__tests__/github_bugbot_interrupted_check.test.ts) · [`src/application/policies/__tests__/bugbot_progress_check_observation_policy.test.ts`](../src/application/policies/__tests__/bugbot_progress_check_observation_policy.test.ts) · [`src/data/repository/__tests__/copilot_evidence_repository.test.ts`](../src/data/repository/__tests__/copilot_evidence_repository.test.ts) · [`quality/bugbot/evidence/issue-950/status-card-publication/publisher.test.cjs`](../quality/bugbot/evidence/issue-950/status-card-publication/publisher.test.cjs) · [`quality/bugbot/evidence/issue-950/status-card-publication/packaged-canary.cjs`](../quality/bugbot/evidence/issue-950/status-card-publication/packaged-canary.cjs) · [`src/application/policies/__tests__/bugbot_status_card_publication_policy.test.ts`](../src/application/policies/__tests__/bugbot_status_card_publication_policy.test.ts) · [`src/infrastructure/github/__tests__/github_bugbot_status_card_workflow.test.ts`](../src/infrastructure/github/__tests__/github_bugbot_status_card_workflow.test.ts) · [`src/infrastructure/github/__tests__/github_bugbot_status_card_lane.test.ts`](../src/infrastructure/github/__tests__/github_bugbot_status_card_lane.test.ts) · [`src/infrastructure/github/__tests__/github_bugbot_status_card_dispatch.test.ts`](../src/infrastructure/github/__tests__/github_bugbot_status_card_dispatch.test.ts) · [`src/infrastructure/github/__tests__/github_bugbot_status_card_observation.test.ts`](../src/infrastructure/github/__tests__/github_bugbot_status_card_observation.test.ts) · [`src/infrastructure/github/__tests__/github_bugbot_status_card_handoff.test.ts`](../src/infrastructure/github/__tests__/github_bugbot_status_card_handoff.test.ts) - User documentation: [`docs/bugbot/detection.mdx`](../docs/bugbot/detection.mdx) · [`docs/bugbot/finding-publication.mdx`](../docs/bugbot/finding-publication.mdx) · [`docs/bugbot/quality-observability.mdx`](../docs/bugbot/quality-observability.mdx) · [`docs/bugbot/failure-scenarios.mdx`](../docs/bugbot/failure-scenarios.mdx) · [`docs/bugbot/configuration.mdx`](../docs/bugbot/configuration.mdx) · [`docs/bugbot/how-it-works.mdx`](../docs/bugbot/how-it-works.mdx) · [`docs/bugbot/programmatic-api.mdx`](../docs/bugbot/programmatic-api.mdx) · [`docs/pull-requests/workflow-setup.mdx`](../docs/pull-requests/workflow-setup.mdx) · [`docs/issues/comment-commands.mdx`](../docs/issues/comment-commands.mdx) diff --git a/specs/bugbot-review-state-reconciliation.md b/specs/bugbot-review-state-reconciliation.md index 338e51651..7d8c04a0d 100644 --- a/specs/bugbot-review-state-reconciliation.md +++ b/specs/bugbot-review-state-reconciliation.md @@ -2502,3 +2502,89 @@ path forms and one generated-card ownership case. Reuse actual workflow, adapter, Git and packaged entrypoints; no model calls or evaluated-PR writes. Update the operator documentation and catalog evidence, run specification, architecture and focused checks, and report final-head CI separately. + +## Accepted status-writer dispatch acknowledgment (#976) + +This bounded correction is submitted for review with #976. It does not prove +installation on the trusted default branch; #977 owns that separate, explicitly +authorized operation. The existing worker still authenticates the producer, +comparison, policy and current native evidence before serialized publication. + +An accepted dispatch can omit `workflow_run_id`. The caller MUST correlate that +operation without blindly repeating its POST or adopting a merely recent run. +The infrastructure acknowledgment adapter derives `operation` as SHA-256 of the +exact encoded version-1 handoff, including producer run/attempt, kind, comparison, +policy and any verified body. The source-only workflow accepts this internal +string input and includes it in its native run title. Progress wakes prefix +the digest with their native observation sequence, so later progress still +dispatches while a duplicate observation shares its acknowledgment. The worker recomputes the +digest from its actual handoff before any provider read; a missing or forged +correlation is skipped and the Action publishing step fails. It grants no publication +authority and is not an independent attestation of executable producer code. +No public Action option, consumer template or model-investigation bound changes. + +```mermaid +flowchart LR + H[Validated handoff] --> P[One dispatch POST] + P --> D{Run ID returned?} + D -->|yes| V[Validate exact worker and publishing step] + D -->|no| L[Read complete correlated run listings] + L -->|one exact match| V + L -->|none, foreign, ambiguous or unavailable| K[Keep verified card and Check fallback] + V -->|successful publication| R[Existing receipt may proceed] +``` + +In words, the direct ID remains the ordinary path. Missing-ID recovery reads the +workflow identity and the authenticated producer's creation time/attempt, then +searches that workflow on the same repository/default ref. A match requires the +full operation title, repository, workflow ID/path, event, branch, first worker +attempt and a creation time no earlier than the origin. Enumerate up to ten pages +of 100 unique runs and require a consistent complete count before adopting one +match. A truncated, repeated, inconsistent or ambiguous listing is unresolved. +Six lookup passes with 500 ms between passes cover eventual visibility and +transient reads; 401/403 or invalid identity fails closed. These fixed bounds +apply only to short acknowledgment reads. They impose no verifier research +cutoff, token budget, turn count or read quota. + +The adapter remembers a submitted operation within its producing attempt and +shares an in-flight acknowledgment between duplicate callers. A lost POST +response or a subsequent lookup failure never permits another POST for that +operation in that adapter. Retrying acknowledgment repeats reads. This is not a +durable exactly-once protocol across arbitrary process restarts. A native rerun +has a different producer attempt and therefore a different handoff identity; +ordinary worker source/attempt fences continue to apply. + +Even a directly returned ID MUST match the expected native title, repository, +workflow path/ref/event and first worker attempt before its one successful +publishing job/step can acknowledge completion. Failure leaves the last verified +comment and existing Check/Job Summary authoritative, performs no unqueued card +fallback and issues no completed publication receipt. Operator guidance is: +“Publication acknowledgment unavailable. Inspect the native writer run and retry +acknowledgment; the previous verified review remains available.” This adds no +locale-specific status-card text; diagnostics remain technical detail. + +Rollout requires reviewing the matching adapter and source workflow together and +then installing that exact workflow on trusted default under #977. An old writer +that lacks operation correlation cannot satisfy this recovery contract. A +prepared PR, develop merge or fake-provider control does not demonstrate an +installed writer. Keep production verification disabled throughout. + +The test budget is **13 new dispatch declarations / 18 controlled-provider +rows**, plus one worker declaration covering missing/forged correlation (two rows), plus the seven existing dispatch controls and existing publication/policy +integration suites. Distribution: unique accepted 204, absent match, ambiguity, +four foreign-identity dimensions, missing permission, transient workflow/origin/run-list read failures, +read-only retry after acceptance, foreign direct ID, later-page match, incomplete +listing, lost-response/concurrent retry, replaced origin attempt and distinct/replayed +progress sequences. Assert POST +counts, selected run, absent acknowledgment on failures, and the existing +preserved-card/no-receipt behavior through the actual publication workflow. +All endpoints are fake; no real secrets or GitHub writes occur. + +Acceptance requires that matrix, targeted publication integration, workflow, +typecheck, build/bundle, architecture, coverage, documentation and specification +checks at the delivered SHA. Register the adapter in the existing capability +catalog, regenerate its view, and update failure/retry guidance. Keep historical +pilot artifacts and all qualification gates unchanged. Primary API behavior is +specified by [GitHub workflow dispatch](https://docs.github.com/en/rest/actions/workflows#create-a-workflow-dispatch-event), +[workflow runs](https://docs.github.com/en/rest/actions/workflow-runs#list-workflow-runs-for-a-workflow) +and [native run names](https://docs.github.com/en/actions/reference/workflows-and-actions/workflow-syntax#run-name). diff --git a/specs/catalog.json b/specs/catalog.json index 328a4386d..5cb089f3a 100644 --- a/specs/catalog.json +++ b/specs/catalog.json @@ -727,7 +727,9 @@ "src/application/policies/bugbot_status_card_publication_policy.ts", "src/infrastructure/github/github_bugbot_status_card_workflow.ts", "src/infrastructure/github/github_bugbot_status_card_dispatch.ts", - "src/infrastructure/github/native_list_pagination.ts" + "src/infrastructure/github/native_list_pagination.ts", + "src/infrastructure/github/github_bugbot_status_card_acknowledgment.ts", + "src/infrastructure/github/github_bugbot_status_card_handoff.ts" ], "tests": [ "src/domain/bugbot/__tests__/review_state.test.ts", diff --git a/src/actions/github_action.ts b/src/actions/github_action.ts index 6158e4d7f..eb9982c84 100644 --- a/src/actions/github_action.ts +++ b/src/actions/github_action.ts @@ -59,7 +59,7 @@ export async function runGitHubAction(verificationAuthority?: BugbotVerification event: eventName, ref, actor, server: serverUrl, workflowRef: process.env.GITHUB_WORKFLOW_REF ?? '', locale: readGithubActionLocaleInputs(getGithubActionInput).pullRequest, policy: verificationAuthority?.policyDigest ?? 'default', - inputs: { pullNumber: payload.inputs?.pull_number, work: payload.inputs?.work }, + inputs: { pullNumber: payload.inputs?.pull_number, work: payload.inputs?.work, operation: payload.inputs?.operation }, }); if (effect === 'skipped') core.setFailed('No current Bugbot status card publication was authorized.'); else logInfo('Bugbot status card publication ' + effect + '.'); diff --git a/src/infrastructure/github/__tests__/github_bugbot_status_card_dispatch.test.ts b/src/infrastructure/github/__tests__/github_bugbot_status_card_dispatch.test.ts index d3d466f59..d7cba14c7 100644 --- a/src/infrastructure/github/__tests__/github_bugbot_status_card_dispatch.test.ts +++ b/src/infrastructure/github/__tests__/github_bugbot_status_card_dispatch.test.ts @@ -1,10 +1,11 @@ +import { createHash } from 'node:crypto'; import { createGithubBugbotStatusCardDispatcher } from '../github_bugbot_status_card_dispatch'; import { buildBugbotReviewProjection } from '../../../domain/bugbot/review_projection'; import { renderBugbotStatusCard } from '../../../application/policies/bugbot_review_presentation_policy'; const mockRead = { rest: { repos: { getContent: jest.fn() }, - actions: { getWorkflowRun: jest.fn(), listJobsForWorkflowRun: jest.fn() }, + actions: { getWorkflowRun: jest.fn(), listJobsForWorkflowRun: jest.fn(), getWorkflow: jest.fn(), listWorkflowRuns: jest.fn() }, } }; const mockWrite = { request: jest.fn() }; const mockCurrent = jest.fn(); @@ -39,9 +40,10 @@ beforeEach(() => { headRepositoryOwner: 'vypdev', headRepositoryName: 'copilot', state: 'open' }); mockWrite.request.mockResolvedValue({ data: { workflow_run_id: 42 } }); mockRead.rest.actions.getWorkflowRun.mockResolvedValue({ data: { - id: 42, repository: { id: 19 }, head_sha: applied.head_sha, head_branch: 'develop', + id: 42, repository: { id: 19 }, display_title: acceptedRun().display_title, run_attempt: 1, head_sha: applied.head_sha, head_branch: 'develop', event: 'workflow_dispatch', path: '.github/workflows/copilot_bugbot_status_card.yml', status: 'completed', conclusion: 'success', } }); + mockRead.rest.actions.getWorkflow.mockResolvedValue({ data: { id: 8, path: '.github/workflows/copilot_bugbot_status_card.yml' } }); mockRead.rest.actions.listJobsForWorkflowRun.mockResolvedValue({ data: { jobs: [applied], total_count: 1 } }); }); @@ -110,3 +112,152 @@ it('wakes progress with identifiers only and never waits for a comment from the expect(JSON.parse(payload.inputs.work)).not.toHaveProperty('verifiedBody'); expect(mockRead.rest.actions.getWorkflowRun).not.toHaveBeenCalled(); }); + +const createdAt = '2026-11-19T17:00:00Z'; +function acceptedRun(id = 42, override: Record = {}) { + const work = JSON.stringify({ version: 1, kind: 'analysis-result', runId: 21, attempt: 2, + source: { repositoryId: 19, pullNumber: 11, base: baseSha, baseRef: baseRefSha, head: headSha, policy: 'default' }, + verifiedBody: body }); + return { id, repository: { id: 19 }, workflow_id: 8, path: '.github/workflows/copilot_bugbot_status_card.yml', + event: 'workflow_dispatch', head_branch: 'develop', run_attempt: 1, created_at: createdAt, + display_title: 'Bugbot status · PR 11 · ' + createHash('sha256').update(work).digest('hex'), ...override }; +} +function acceptedWithoutId() { + mockWrite.request.mockResolvedValue({ status: 204, data: undefined }); + const effect = mockRead.rest.actions.getWorkflowRun.getMockImplementation(); + mockRead.rest.actions.getWorkflowRun.mockImplementation((input: { run_id: number }) => input.run_id === 21 + ? Promise.resolve({ data: { id: 21, repository: { id: 19 }, run_attempt: 2, created_at: createdAt } }) + : effect!(input)); + mockRead.rest.actions.listWorkflowRuns.mockResolvedValue({ data: { total_count: 1, workflow_runs: [acceptedRun()] } }); +} +async function failAcknowledgment(dispatcher: NonNullable>>) { + const result = expect(dispatcher.terminal.publish(request)).rejects.toThrow('retry acknowledgment'); + await jest.runAllTimersAsync(); + await result; + expect(mockWrite.request).toHaveBeenCalledTimes(1); + expect(mockRead.rest.actions.listJobsForWorkflowRun).not.toHaveBeenCalled(); +} + +afterEach(() => jest.useRealTimers()); + +it('recovers a unique accepted 204 run bound to the exact handoff operation', async () => { + acceptedWithoutId(); + const dispatcher = await createGithubBugbotStatusCardDispatcher(binding, environment); + await expect(dispatcher!.terminal.publish(request)).resolves.toBe('published'); + const sent = mockWrite.request.mock.calls[0][1].inputs; + expect(sent.operation).toBe(createHash('sha256').update(sent.work).digest('hex')); + expect(mockWrite.request).toHaveBeenCalledTimes(1); + expect(mockRead.rest.actions.getWorkflowRun).toHaveBeenLastCalledWith(expect.objectContaining({ run_id: 42 })); +}); + +it('fails safely when an accepted dispatch has no matching run', async () => { + jest.useFakeTimers(); acceptedWithoutId(); + mockRead.rest.actions.listWorkflowRuns.mockResolvedValue({ data: { total_count: 0, workflow_runs: [] } }); + const dispatcher = await createGithubBugbotStatusCardDispatcher(binding, environment); + await failAcknowledgment(dispatcher!); + expect(mockRead.rest.actions.listWorkflowRuns).toHaveBeenCalledTimes(6); +}); + +it('never adopts ambiguous accepted operations', async () => { + jest.useFakeTimers(); acceptedWithoutId(); + mockRead.rest.actions.listWorkflowRuns.mockResolvedValue({ data: { total_count: 2, workflow_runs: [acceptedRun(), acceptedRun(43)] } }); + const dispatcher = await createGithubBugbotStatusCardDispatcher(binding, environment); + await failAcknowledgment(dispatcher!); +}); + +it.each([ + ['workflow', { workflow_id: 9 }], ['ref', { head_branch: 'other' }], + ['repository', { repository: { id: 20 } }], ['operation', { display_title: 'Bugbot status · PR 11' }], +])('rejects a merely recent run with foreign %s', async (_name, override) => { + jest.useFakeTimers(); acceptedWithoutId(); + mockRead.rest.actions.listWorkflowRuns.mockResolvedValue({ data: { total_count: 1, workflow_runs: [acceptedRun(42, override)] } }); + const dispatcher = await createGithubBugbotStatusCardDispatcher(binding, environment); + await failAcknowledgment(dispatcher!); +}); + +it('retains accepted dispatch state when lookup permissions are unavailable', async () => { + jest.useFakeTimers(); acceptedWithoutId(); + mockRead.rest.actions.listWorkflowRuns.mockRejectedValue({ status: 403 }); + const dispatcher = await createGithubBugbotStatusCardDispatcher(binding, environment); + await failAcknowledgment(dispatcher!); + expect(mockRead.rest.actions.listWorkflowRuns).toHaveBeenCalledTimes(1); +}); + +it.each(['getWorkflow', 'getWorkflowRun', 'listWorkflowRuns'] as const)('retries a transient %s failure without repeating the accepted POST', async method => { + jest.useFakeTimers(); acceptedWithoutId(); + const port = mockRead.rest.actions[method]; + port.mockRejectedValueOnce({ status: 503 }); + const dispatcher = await createGithubBugbotStatusCardDispatcher(binding, environment); + const result = expect(dispatcher!.terminal.publish(request)).resolves.toBe('published'); + await jest.runAllTimersAsync(); await result; + expect(port.mock.calls.length).toBeGreaterThanOrEqual(2); + expect(mockWrite.request).toHaveBeenCalledTimes(1); +}); + +it('replays acknowledgment after accepted dispatch without another POST or a false receipt', async () => { + jest.useFakeTimers(); acceptedWithoutId(); + mockRead.rest.actions.listWorkflowRuns.mockRejectedValueOnce({ status: 403 }); + const dispatcher = await createGithubBugbotStatusCardDispatcher(binding, environment); + await failAcknowledgment(dispatcher!); + await expect(dispatcher!.terminal.publish(request)).resolves.toBe('published'); + expect(mockWrite.request).toHaveBeenCalledTimes(1); +}); + +it('rejects a direct ID for a different handoff even when workflow and ref match', async () => { + const dispatcher = await createGithubBugbotStatusCardDispatcher(binding, environment); + mockRead.rest.actions.getWorkflowRun.mockResolvedValue({ data: { ...acceptedRun(), display_title: 'foreign', status: 'completed', conclusion: 'success' } }); + await expect(dispatcher!.terminal.publish(request)).rejects.toThrow('retry acknowledgment'); + expect(mockRead.rest.actions.listJobsForWorkflowRun).not.toHaveBeenCalled(); +}); + +it('recovers the one matching operation on a later complete page', async () => { + acceptedWithoutId(); + const other = Array.from({ length: 100 }, (_, index) => acceptedRun(100 + index, { display_title: 'unrelated' })); + mockRead.rest.actions.listWorkflowRuns.mockImplementation(({ page }: { page: number }) => Promise.resolve({ data: { + total_count: 101, workflow_runs: page === 1 ? other : [acceptedRun()], + } })); + const dispatcher = await createGithubBugbotStatusCardDispatcher(binding, environment); + await expect(dispatcher!.terminal.publish(request)).resolves.toBe('published'); + expect(mockRead.rest.actions.listWorkflowRuns).toHaveBeenCalledTimes(2); +}); + +it('refuses a matching operation in an incomplete listing', async () => { + jest.useFakeTimers(); acceptedWithoutId(); + mockRead.rest.actions.listWorkflowRuns.mockResolvedValue({ data: { total_count: 2, workflow_runs: [acceptedRun()] } }); + const dispatcher = await createGithubBugbotStatusCardDispatcher(binding, environment); + await failAcknowledgment(dispatcher!); +}); + +it('does not redispatch after a lost POST response and concurrent acknowledgment retries', async () => { + acceptedWithoutId(); + mockWrite.request.mockRejectedValueOnce({ status: 502 }); + const dispatcher = await createGithubBugbotStatusCardDispatcher(binding, environment); + await expect(dispatcher!.terminal.publish(request)).rejects.toThrow('retry acknowledgment'); + await expect(Promise.all([dispatcher!.terminal.publish(request), dispatcher!.terminal.publish(request)])) + .resolves.toEqual(['published', 'published']); + expect(mockWrite.request).toHaveBeenCalledTimes(1); + expect(mockRead.rest.actions.listWorkflowRuns).toHaveBeenCalledTimes(1); +}); + +it('refuses recovery when the origin attempt is replaced', async () => { + jest.useFakeTimers(); acceptedWithoutId(); + mockRead.rest.actions.getWorkflowRun.mockResolvedValue({ data: { id: 21, repository: { id: 19 }, run_attempt: 3, created_at: createdAt } }); + const dispatcher = await createGithubBugbotStatusCardDispatcher(binding, environment); + await failAcknowledgment(dispatcher!); + expect(mockRead.rest.actions.listWorkflowRuns).not.toHaveBeenCalled(); +}); + +it('dispatches distinct progress sequences while acknowledging a replay without another wake', async () => { + const dispatcher = await createGithubBugbotStatusCardDispatcher(binding, environment); + const observation = { stage: 'analyzing' as const, pullNumber: 11, baseSha, baseRefSha, headSha, + observedAt: '2026-11-19T17:00:00Z', elapsedMs: 1, sequence: 2 }; + await dispatcher!.wake(observation); + await dispatcher!.wake({ ...observation, sequence: 3 }); + await dispatcher!.wake({ ...observation, sequence: 3 }); + expect(mockWrite.request).toHaveBeenCalledTimes(2); + const first = mockWrite.request.mock.calls[0][1].inputs; + const second = mockWrite.request.mock.calls[1][1].inputs; + expect(first.work).toBe(second.work); + expect(first.operation).not.toBe(second.operation); + expect(first.operation).toBe('2:' + createHash('sha256').update(first.work).digest('hex')); +}); diff --git a/src/infrastructure/github/__tests__/github_bugbot_status_card_workflow.test.ts b/src/infrastructure/github/__tests__/github_bugbot_status_card_workflow.test.ts index 3e8b13309..ce0a08702 100644 --- a/src/infrastructure/github/__tests__/github_bugbot_status_card_workflow.test.ts +++ b/src/infrastructure/github/__tests__/github_bugbot_status_card_workflow.test.ts @@ -1,5 +1,5 @@ import { runGithubBugbotStatusCardWorkflow } from '../github_bugbot_status_card_workflow'; -import { encodeGithubBugbotStatusCardHandoff } from '../github_bugbot_status_card_handoff'; +import { encodeGithubBugbotStatusCardHandoff, githubBugbotStatusCardOperation } from '../github_bugbot_status_card_handoff'; import { buildBugbotProgressCheckMarker } from '../../../application/policies/bugbot_progress_check_observation_policy'; import { buildBugbotReviewProjection } from '../../../domain/bugbot/review_projection'; import { renderBugbotStatusCard } from '../../../application/policies/bugbot_review_presentation_policy'; @@ -54,7 +54,7 @@ const progress = { source, runId: 23, attempt: 2, kind: 'progress' as const }; function invoke(request: Parameters[0] = progress, overrides: Partial = {}) { const wire = encodeGithubBugbotStatusCardHandoff(request)!; - return runGithubBugbotStatusCardWorkflow({ ...base, ...overrides, inputs: { pullNumber: wire.pull_number, work: wire.work } }); + return runGithubBugbotStatusCardWorkflow({ ...base, ...overrides, inputs: { pullNumber: wire.pull_number, work: wire.work, operation: githubBugbotStatusCardOperation(wire.work, request.kind === 'progress' ? 0 : undefined) } }); } beforeEach(() => { @@ -144,3 +144,12 @@ it('preserves active native progress when an independent authorized recheck refr expect(mockUpdate.mock.calls[0][2]).toContain('18/50 partitions validated'); expect(mockUpdate.mock.calls[0][2].endsWith(verifiedBody)).toBe(true); }); + +it.each([undefined, 'f'.repeat(64)])('refuses a missing or forged operation correlation before provider reads (%s)', async operation => { + const wire = encodeGithubBugbotStatusCardHandoff(progress)!; + await expect(runGithubBugbotStatusCardWorkflow({ ...base, inputs: { pullNumber: wire.pull_number, work: wire.work, operation } })) + .resolves.toBe('skipped'); + expect(mockApi.rest.repos.get).not.toHaveBeenCalled(); + expect(mockUpdate).not.toHaveBeenCalled(); + expect(mockAdd).not.toHaveBeenCalled(); +}); diff --git a/src/infrastructure/github/github_bugbot_status_card_acknowledgment.ts b/src/infrastructure/github/github_bugbot_status_card_acknowledgment.ts new file mode 100644 index 000000000..b706b4927 --- /dev/null +++ b/src/infrastructure/github/github_bugbot_status_card_acknowledgment.ts @@ -0,0 +1,89 @@ +import type { getOctokit } from '@actions/github'; +import { githubBugbotStatusCardOperation } from './github_bugbot_status_card_handoff'; +import { parsePositiveSafeInteger } from '../../domain/positive_integer_policy'; +import { bugbotStatusCardPath, bugbotStatusCardWorkflow, statusCardGithubErrorStatus } from './github_bugbot_status_card_installation'; + +class StatusCardAcknowledgmentError extends Error {} + +export const statusCardUnacknowledged = () => new StatusCardAcknowledgmentError('The shared Bugbot status card writer did not acknowledge publication. Inspect its native run and retry acknowledgment; preserve the last verified card and Check fallback.'); + +/** Correlation is data provenance, never independent producer-code attestation. */ +export function createGithubBugbotStatusCardAcknowledgment(binding: { + read: ReturnType; write: ReturnType; + scope: { owner: string; repo: string }; ref: string; runId: number; attempt: number; repositoryId: number; +}) { + const { read, write, scope, ref, runId, attempt, repositoryId } = binding; + const workflow = { ...scope, workflow_id: bugbotStatusCardWorkflow }; + const unresolved = statusCardUnacknowledged; + const acknowledgments = new Map }>(); + return async (inputs: { pull_number: string; work: string }, sequence?: number): Promise<{ id: number; title: string }> => { + const operation = githubBugbotStatusCardOperation(inputs.work, sequence); + const title = 'Bugbot status · PR ' + inputs.pull_number + ' · ' + operation; + let acknowledgment = acknowledgments.get(operation); + if (!acknowledgment) { + acknowledgment = { issued: false }; + acknowledgments.set(operation, acknowledgment); + } + if (acknowledgment.id) return { id: acknowledgment.id, title }; + if (acknowledgment.pending) return { id: await acknowledgment.pending, title }; + const state = acknowledgment; + state.pending = (async (): Promise => { + if (!state.issued) { + // A lost response can still mean accepted: retry reads, never this POST. + state.issued = true; + const { data } = await write.request('POST /repos/{owner}/{repo}/actions/workflows/{workflow_id}/dispatches', { + ...workflow, ref, inputs: { ...inputs, operation }, return_run_details: true, + }); + const direct = parsePositiveSafeInteger((data as { workflow_run_id?: number } | undefined)?.workflow_run_id); + if (direct) return state.id = direct; + } + for (let lookup = 0; lookup < 6; lookup += 1) { + try { + const expected = await read.rest.actions.getWorkflow(workflow); + const origin = await read.rest.actions.getWorkflowRun({ ...scope, run_id: runId }); + const created = origin.data.created_at; + if (!parsePositiveSafeInteger(expected.data.id) || expected.data.path !== bugbotStatusCardPath + || origin.data.id !== runId || origin.data.repository.id !== repositoryId || origin.data.run_attempt !== attempt + || typeof created !== 'string' || !Number.isFinite(Date.parse(created))) throw unresolved(); + const matches = new Set(); + const seen = new Set(); + let complete = false; + let total: number | undefined; + for (let page = 1; page <= 10; page += 1) { + const response: Awaited> = await read.rest.actions.listWorkflowRuns({ ...workflow, + branch: ref, event: 'workflow_dispatch', created: '>=' + created, per_page: 100, page }); + const data = response.data; + if (!Array.isArray(data.workflow_runs) || data.workflow_runs.length > 100 + || !Number.isSafeInteger(data.total_count) || data.total_count < 0 + || total !== undefined && total !== data.total_count) throw unresolved(); + total = data.total_count; + for (const run of data.workflow_runs) { + const id = parsePositiveSafeInteger(run.id); + if (!id || seen.has(id)) throw unresolved(); + seen.add(id); + if (run.repository.id === repositoryId && run.workflow_id === expected.data.id + && run.path === bugbotStatusCardPath && run.event === 'workflow_dispatch' + && run.head_branch === ref && run.display_title === title && run.run_attempt === 1 + && Number.isFinite(Date.parse(run.created_at)) && Date.parse(run.created_at) >= Date.parse(created)) matches.add(id); + } + if (seen.size === total || data.workflow_runs.length < 100) { + if (data.total_count !== seen.size) throw unresolved(); + complete = true; + break; + } + } + if (!complete || matches.size > 1) throw unresolved(); + if (matches.size === 1) return state.id = [...matches][0]; + } catch (error) { + if ([401, 403].includes(Number(statusCardGithubErrorStatus(error))) || error instanceof StatusCardAcknowledgmentError) throw unresolved(); + if (lookup === 5) throw unresolved(); + } + if (lookup < 5) await new Promise(resolve => setTimeout(resolve, 500)); + } + throw unresolved(); + })().catch(() => { throw unresolved(); }); + try { return { id: await state.pending, title }; } + catch { throw unresolved(); } + finally { state.pending = undefined; } + }; +} diff --git a/src/infrastructure/github/github_bugbot_status_card_dispatch.ts b/src/infrastructure/github/github_bugbot_status_card_dispatch.ts index 4f7b03fde..87ac63cfa 100644 --- a/src/infrastructure/github/github_bugbot_status_card_dispatch.ts +++ b/src/infrastructure/github/github_bugbot_status_card_dispatch.ts @@ -7,10 +7,12 @@ import { parsePositiveSafeInteger } from '../../domain/positive_integer_policy'; import { createPullRequestLifecycleClient } from '../composition/github_pull_request_client_factory'; import { encodeGithubBugbotStatusCardHandoff } from './github_bugbot_status_card_handoff'; import { - bugbotStatusCardPath, bugbotStatusCardWorkflow, readGithubBugbotStatusCardInstallation, statusCardGithubErrorStatus, + bugbotStatusCardPath, readGithubBugbotStatusCardInstallation, statusCardGithubErrorStatus, } from './github_bugbot_status_card_installation'; -const unresolved = () => new Error('The shared Bugbot status card writer did not acknowledge publication.'); +import { createGithubBugbotStatusCardAcknowledgment, statusCardUnacknowledged } from './github_bugbot_status_card_acknowledgment'; + +const unresolved = statusCardUnacknowledged; export async function createGithubBugbotStatusCardDispatcher(binding: { owner: string; repository: string; repositoryId: unknown; defaultBranch: unknown; @@ -26,20 +28,14 @@ export async function createGithubBugbotStatusCardDispatcher(binding: { const read = getOctokit(binding.evidenceToken); const write = getOctokit(binding.token); const scope = { owner: binding.owner, repo: binding.repository }; - const workflow = { ...scope, workflow_id: bugbotStatusCardWorkflow }; const installation = await readGithubBugbotStatusCardInstallation(read, scope, ref); if (installation === 'absent') return undefined; const pullRequests = new PullRequestLifecycleRepository(createPullRequestLifecycleClient()); - const dispatch = async (request: Parameters[0]): Promise => { + const acknowledge = createGithubBugbotStatusCardAcknowledgment({ read, write, scope, ref, runId, attempt, repositoryId }); + const dispatch = async (request: Parameters[0], sequence?: number) => { const inputs = encodeGithubBugbotStatusCardHandoff(request); if (installation !== 'installed' || !inputs) throw unresolved(); - const { data } = await write.request('POST /repos/{owner}/{repo}/actions/workflows/{workflow_id}/dispatches', { - ...workflow, ref, inputs, return_run_details: true, - }); - const published = data as { workflow_run_id?: number } | undefined; - const operation = parsePositiveSafeInteger(published?.workflow_run_id); - if (!operation) throw unresolved(); - return operation; + return acknowledge(inputs, sequence); }; const terminal: BugbotStatusCardTerminalPort = { async publish(input) { @@ -57,7 +53,7 @@ export async function createGithubBugbotStatusCardDispatcher(binding: { // This deadline is only for acknowledging the short comment job. const until = Date.now() + 7 * 60_000; while (Date.now() < until) { - const observed = await read.rest.actions.getWorkflowRun({ ...scope, run_id: effect }).catch((error: unknown) => { + const observed = await read.rest.actions.getWorkflowRun({ ...scope, run_id: effect.id }).catch((error: unknown) => { if (statusCardGithubErrorStatus(error) === 404) return undefined; throw unresolved(); }); @@ -66,11 +62,11 @@ export async function createGithubBugbotStatusCardDispatcher(binding: { continue; } const { data } = observed; - if (data.id !== effect || data.repository.id !== repositoryId || data.path !== bugbotStatusCardPath + if (data.id !== effect.id || data.display_title !== effect.title || data.run_attempt !== 1 || data.repository.id !== repositoryId || data.path !== bugbotStatusCardPath || data.event !== 'workflow_dispatch' || data.head_branch !== ref) throw unresolved(); if (data.status === 'completed') { if (data.conclusion !== 'success') throw unresolved(); - const { data: jobs } = await read.rest.actions.listJobsForWorkflowRun({ ...scope, run_id: effect, per_page: 20, filter: 'latest' }); + const { data: jobs } = await read.rest.actions.listJobsForWorkflowRun({ ...scope, run_id: effect.id, per_page: 20, filter: 'latest' }); if (jobs.total_count === 1 && jobs.jobs.length === 1 && jobs.jobs[0].name === 'Publish Bugbot status card' && jobs.jobs[0].head_sha === data.head_sha && jobs.jobs[0].conclusion === 'success' && jobs.jobs[0].steps?.some((step: { name: string; conclusion?: string | null }) => @@ -87,7 +83,7 @@ export async function createGithubBugbotStatusCardDispatcher(binding: { async wake(observation: BugbotReviewProgressObservation) { if (installation !== 'installed' || !observation.baseSha) return; await dispatch({ kind: 'progress', runId, attempt, source: { repositoryId, pullNumber: observation.pullNumber, - base: observation.baseSha, baseRef: observation.baseRefSha ?? observation.baseSha, head: observation.headSha, policy: binding.policy } }); + base: observation.baseSha, baseRef: observation.baseRefSha ?? observation.baseSha, head: observation.headSha, policy: binding.policy } }, observation.sequence); }, }; } diff --git a/src/infrastructure/github/github_bugbot_status_card_handoff.ts b/src/infrastructure/github/github_bugbot_status_card_handoff.ts index bc3e1edb1..20b295b83 100644 --- a/src/infrastructure/github/github_bugbot_status_card_handoff.ts +++ b/src/infrastructure/github/github_bugbot_status_card_handoff.ts @@ -1,3 +1,4 @@ +import { createHash } from 'node:crypto'; import { isBugbotStatusCardSource, readBugbotStatusCardHead, type BugbotStatusCardWakeup, } from '../../application/policies/bugbot_status_card_publication_policy'; @@ -48,3 +49,9 @@ export function encodeGithubBugbotStatusCardHandoff(request: CardRequest): { pul const work = JSON.stringify({ version: 1, ...request }); return decodeGithubBugbotStatusCardHandoff({ pullNumber, work }) ? { pull_number: String(pullNumber), work } : undefined; } + +/** A correlation key binds bytes; the worker still validates publication authority. */ +export function githubBugbotStatusCardOperation(work: string, sequence?: number): string { + if (sequence !== undefined && (!Number.isSafeInteger(sequence) || sequence < 0)) throw new Error('Invalid progress correlation sequence.'); + return (sequence === undefined ? '' : String(sequence) + ':') + createHash('sha256').update(work).digest('hex'); +} diff --git a/src/infrastructure/github/github_bugbot_status_card_workflow.ts b/src/infrastructure/github/github_bugbot_status_card_workflow.ts index 2a659eafc..5ad296819 100644 --- a/src/infrastructure/github/github_bugbot_status_card_workflow.ts +++ b/src/infrastructure/github/github_bugbot_status_card_workflow.ts @@ -5,7 +5,7 @@ import { canonicalGitObjectId } from '../../domain/git_object_id'; import { PullRequestLifecycleRepository } from '../../data/repository/pull_request/pull_request_lifecycle_repository'; import { createPullRequestLifecycleClient } from '../composition/github_pull_request_client_factory'; import { createBugbotCompositionRoot } from '../composition/bugbot_composition_root'; -import { decodeGithubBugbotStatusCardHandoff } from './github_bugbot_status_card_handoff'; +import { decodeGithubBugbotStatusCardHandoff, githubBugbotStatusCardOperation } from './github_bugbot_status_card_handoff'; import { runAdmittedGithubBugbotStatusCardJob } from './github_bugbot_status_card_lane'; import { nativeBugbotAnalysisPath, readNativeBugbotStatusCardReview, type NativeGithubRun, type NativeGithubCheck } from './github_bugbot_status_card_observation'; import { bugbotStatusCardPath } from './github_bugbot_status_card_installation'; @@ -21,12 +21,18 @@ const sourceEvents = new Map([ export async function runGithubBugbotStatusCardWorkflow(binding: { owner: string; repository: string; event: string; ref: string; workflowRef: string; actor: string; token: string; evidenceToken: string; server: string; - locale: string; policy: string; inputs: { pullNumber: unknown; work: unknown }; + locale: string; policy: string; inputs: { pullNumber: unknown; work: unknown; operation: unknown }; }) { const request = decodeGithubBugbotStatusCardHandoff(binding.inputs); + const correlation = typeof binding.inputs.operation === 'string' + ? binding.inputs.operation.match(/^(0|[1-9]\d*):[a-f0-9]{64}$/u)?.[1] : undefined; + const sequence = correlation === undefined ? undefined : Number(correlation); const repository = binding.owner + '/' + binding.repository; if (binding.event !== 'workflow_dispatch' || binding.workflowRef !== repository + '/' + bugbotStatusCardPath + '@' + binding.ref - || !/^https:\/\/[a-z0-9.-]+(?::\d+)?$/iu.test(binding.server) || !request) return 'skipped'; + || !/^https:\/\/[a-z0-9.-]+(?::\d+)?$/iu.test(binding.server) || !request + || request.kind === 'progress' && (sequence === undefined || !Number.isSafeInteger(sequence)) + || typeof binding.inputs.work !== 'string' + || binding.inputs.operation !== githubBugbotStatusCardOperation(binding.inputs.work, request.kind === 'progress' ? sequence : undefined)) return 'skipped'; const api = getOctokit(binding.evidenceToken); const scope = { owner: binding.owner, repo: binding.repository }; const [authenticated, repo] = await Promise.all([