Skip to content

Harden work-queue initialization for empty repositories - #67297

Merged
pelikhan merged 5 commits into
mainfrom
copilot/review-work-queue-protocol
Oct 9, 2026
Merged

pelikhan merged 5 commits into
mainfrom
copilot/review-work-queue-protocol

Conversation

Copilot AI commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

The work-queue runtime needs to handle empty optional settings and repositories with no branches without treating an ambiguous Git response as proof of absence or weakening Policy and worker-route checks.

  • Configuration: Treat empty Issue and dependency-credential settings as unconfigured; continue rejecting malformed JSON.
  • Repository bootstrap: Confirm Git ref conflicts against GitHub’s isEmpty state before treating a ref as absent. A validated first submission can prepare the default branch, then create a separate queue branch.
  • Protocol guarantees: Publish Policy and Work together only after the worker route is verified. If a worker is not yet deployed, preparation stops before queue publication; the same submission can be retried after deployment.

Copilot AI changed the title Harden work queue bootstrap and empty runtime settings Harden work-queue initialization for empty repositories Oct 9, 2026
Copilot AI requested a review from pelikhan October 9, 2026 22:57
@pelikhan
pelikhan marked this pull request as ready for review October 9, 2026 23:04
Copilot AI balanced review requested due to automatic review settings October 9, 2026 23:04
@github-actions

github-actions Bot commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

🧠 Matt Pocock Skills Reviewer is reviewing this pull request using Matt Pocock's engineering skills...

@github-actions

github-actions Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

✅ Ponytail Reviewer completed successfully!

Generated by Ponytail Reviewer for #67297

@github-actions

github-actions Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

✅ Design Decision Gate 🏗️ completed the design decision gate check. See the comment below for the result and any generated ADR draft.

No ADR enforcement needed for PR #67297: has_implementation_label=false and default_business_additions=0 (<=100 new lines in business logic directories), with no custom .design-gate.yml overrides.

🏗️ ADR gate enforced by Design Decision Gate 🏗️

@github-actions

github-actions Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

✅ Test Quality Sentinel completed test quality analysis.

🧪 Test quality analysis by Test Quality Sentinel

@github-actions

github-actions Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

✅ PR Code Quality Reviewer completed the code quality review.

🔎 Code quality review by PR Code Quality Reviewer

@pelikhan

pelikhan commented Oct 9, 2026

Copy link
Copy Markdown
Collaborator

@copilot update TLA+ specs

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

L111: shrink: redundant nameWithOwner echo comparison after repository(owner:$owner,name:$repo). Use response?.repository?.isEmpty === true, 1 fewer condition.

net: -1 lines possible.

Generated by ✂️ Ponytail Reviewer for #67297 · codex · gpt56 · 9.33 AIC · ⌖ 6.48 AIC · ⊞ 13.5K
Comment /ponytail to run again

// GitHub returns 409 rather than 404 for refs in a branchless repository.
// A generic conflict is not proof of absence: confirm the native state.
const response = await githubClient.graphql("query WorkQueueEmptyRepository($owner:String!,$repo:String!) { repository(owner:$owner,name:$repo) { nameWithOwner isEmpty } }", { owner, repo });
if (response?.repository?.nameWithOwner?.toLowerCase() === `${owner}/${repo}`.toLowerCase() && response.repository.isEmpty === true) return null;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

L111: shrink: redundant nameWithOwner echo comparison after repository(owner:$owner,name:$repo). Use response?.repository?.isEmpty === true, 1 fewer condition.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Empty Issues configuration still activates staged snapshot behavior and can skip worker binding.

1 open finding
What changed in this PR

Hardens work-queue configuration parsing and initialization for branchless repositories.

Changes:

  • Treats empty optional settings as unconfigured.
  • Safely bootstraps empty repositories before queue publication.
  • Adds protocol documentation and regression coverage.
File Description
docs/​src/​content/​docs/​reference/​work-queue.md Documents empty-repository bootstrap behavior.
actions/​setup/​js/​work_queue_store.cjs Adds empty-state verification and repository preparation.
actions/​setup/​js/​work_queue_store_checks.cjs Tests bootstrap, retry, and conflict handling.
actions/​setup/​js/​work_queue_issues.cjs Normalizes empty Issues configuration.
actions/​setup/​js/​work_queue_issues_checks.cjs Tests empty and malformed Issues settings.
actions/​setup/​js/​work_queue_control_adapter.cjs Normalizes empty credential bindings.
actions/​setup/​js/​work_queue_control_adapter_checks.cjs Tests credential-setting parsing.

🧠 Review effort: Balanced


💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

const coreApi = options.core || core;
const raw = Object.hasOwn(options, "issues") ? options.issues : process.env.GH_AW_WORK_QUEUE_ISSUES;
const config = issuesConfiguration(typeof raw === "string" ? parseStrictJSON(raw) : raw);
const config = issuesConfiguration(typeof raw === "string" && raw !== "" ? parseStrictJSON(raw) : raw === "" ? undefined : raw);
@github-actions

github-actions Bot commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Comment Memory

Peek at saved memory (pr-code-quality-reviewer)
reviewed_at: 2026-10-09T23:09:02Z
review_event: REQUEST_CHANGES
top_themes:
  - empty-repository bootstrap cannot preserve the same immutable worker ref through verification
  - test double hides bootstrap ref churn, so coverage misses the production failure mode
files_reviewed:
  - actions/setup/js/work_queue_control_adapter.cjs
  - actions/setup/js/work_queue_control_adapter_checks.cjs
  - actions/setup/js/work_queue_issues.cjs
  - actions/setup/js/work_queue_issues_checks.cjs
  - actions/setup/js/work_queue_store.cjs
  - actions/setup/js/work_queue_store_checks.cjs
  - docs/src/content/docs/reference/work-queue.md
comment_count: 2

Note

This comment is managed by comment memory.

Expand the saved memory block to view or edit the persistent context for this thread.
Edit only the text inside the backtick fences; workflow metadata and the footer are regenerated automatically.

Learn more about comment memory

🔎 Code quality review by PR Code Quality Reviewer · copilot · gpt54 · 44 AIC · ⌖ 5.78 AIC · ⊞ 20K · ◷
Comment /review to run again

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict

Requesting changes: the new empty-repository bootstrap flow still relies on an immutable worker ref that cannot exist for the same submission once bootstrap creates the repository's first commit.

Blocking themes
  • The production code verifies Policy + Work against a pre-bootstrap profile.ref, but bootstrap necessarily changes the repository's immutable revision before any worker workflow can exist.
  • The new tests hide that ref churn by pinning main to a preselected fake SHA, so they currently validate a path GitHub cannot reproduce.

🔎 Code quality review by PR Code Quality Reviewer · copilot · gpt54 · 44 AIC · ⌖ 5.78 AIC · ⊞ 20K
Comment /review to run again

const checked = appendCommit(current.transactions, candidate);
log.debug("request.candidate.checked", { operations: checked.commit.operations.length });
if (bootstrapOperation) await prepareEmptyRepository(githubClient, owner, repo, branch);
if (policyOp) await verifyWorkerRoutes({ githubClient, owner, repo, policy: checked.state.policy });

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bootstrapping main before this validation makes the new empty-repository flow impossible to satisfy against the same submission in production.

💡 Why this blocks merge

prepareEmptyRepository() creates the repository's first commit on the default branch, but checked.state.policy still carries the pre-bootstrap immutable profile.ref. In a truly branchless repository there is no commit to point that ref at before bootstrap, and once the worker workflow is deployed afterward it necessarily lands on a different OID than the one already embedded in the Policy. That means the documented "deploy the worker, then retry the same submission" path cannot actually pass verifyWorkerRoutes() outside this test double.

A safer shape here is to treat bootstrap as a separate preparation step: initialize the default branch, return a dedicated "repository prepared, resubmit with a Policy compiled from the new immutable worker ref" result, and only attempt Policy + Work publication after the caller provides a Policy whose profile.ref exists in the real repository.

assert.ok(Buffer.from(content, "base64").toString("utf8").includes("authoritative queue ledger"));
state.bootstrapWrites++;
if (refs.has("main")) throw Object.assign(new Error("Already initialized"), { status: 422 });
refs.set("main", state.defaultRevision);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fake bootstrap path masks the production ref change, so the new empty-repository tests are proving an impossible invariant.

💡 Why this blocks merge

The real repos.createOrUpdateFileContents call creates a fresh commit for the repository's first branch. Here the stub just assigns refs.main to a preselected state.defaultRevision, so every test can keep using the original policy.ref as if bootstrap had not changed the immutable revision at all. That is exactly the case the implementation above depends on, so these tests will stay green while the real empty-repository flow still cannot verify a worker route after bootstrap.

Please make the fake create a new commit OID (or at least mutate defaultRevision) and assert that callers must rebuild/revalidate Policy from the post-bootstrap revision before publication succeeds.

@github-actions

github-actions Bot commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

🧪 Test Quality Sentinel Report

✅ Test Quality Score: 90/100 — Excellent

Analyzed 5 test(s): 5 design, 0 implementation, 0 violation(s). Other languages: none detected.

📊 Metrics (5 tests)
Metric Value
Analyzed 5 (Go: 0, JS: 5)
✅ Design 5 (100%)
⚠️ Implementation 0 (0%)
Edge/error coverage 5 (100%)
Duplicate clusters 0
Inflation Yes (work_queue_store_checks.cjs: +78 vs work_queue_store.cjs: +28, 2.78:1)
🚨 Violations 0
Test File Classification Issues
treats an empty credential setting as no bindings without accepting malformed JSON work_queue_control_adapter_checks.cjs design_test / high_value None
does no live calls when staged or disabled (modified) work_queue_issues_checks.cjs design_test / high_value None
initializes a branchless repository only after validating the first Policy and Work work_queue_store_checks.cjs design_test / high_value None
never initializes an empty repository on the queue branch itself work_queue_store_checks.cjs design_test / high_value None
does not mistake a generic Git conflict for an absent queue branch work_queue_store_checks.cjs design_test / high_value None
⚠️ Flagged Tests (1 — informational, not a failure)

work_queue_store_checks.cjs test suite — the file's added lines (+78) exceed 2:1 against the production file work_queue_store.cjs (+28), triggering the inflation heuristic. This appears justified rather than padding: the three new/behavioral assertions cover distinct invariants of a non-trivial state machine — (1) prepareEmptyRepository bootstrap sequencing gated on worker-route verification, including idempotent-write and unverified-route-retry paths; (2) rejection when the queue branch equals the empty repository's default branch (branch_invalid); (3) distinguishing a generic 409 Git conflict from a true absent-ref isEmpty confirmation. No duplicated assertion patterns were found across these tests.

Verdict

✅ Passed. 0% implementation tests (threshold: 30%). No coding-guideline violations. All five reviewed tests assert observable, user-visible behavior (empty-setting handling, 409-vs-absent disambiguation, bootstrap-then-policy-verification ordering) rather than internal call sequencing, and each includes an explicit edge/error-path assertion.

Sampling note: all 5 changed/added test cases in this PR were analyzed (well under the 50-test budget). No Go or Python/Rust test files were touched.

🧪 Test quality analysis by Test Quality Sentinel · copilot · sonnet50 · 108.6 AIC · ⌖ 15.1 AIC · ⊞ 11.2K · ◷
Comment /review to run again

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Test Quality Sentinel: 90/100. 0% implementation tests (threshold: 30%). No guideline violations; all five tests assert observable behavior with explicit edge/error coverage.

🧪 Test quality analysis by Test Quality Sentinel · copilot · sonnet50 · 108.6 AIC · ⌖ 15.1 AIC · ⊞ 11.2K
Comment /review to run again

@github-actions github-actions Bot mentioned this pull request Oct 9, 2026

Copilot AI commented Oct 9, 2026

Copy link
Copy Markdown
Contributor Author

@copilot update TLA+ specs

Updated in 082b98d and 9822f8d: added QueueBootstrap.tla covering confirmed ref absence, validated default-branch preparation, atomic Policy/Work publication after route verification, external resubmission, and lost-response confirmation/rejection. All 12 bootstrap TLC configurations returned expected results; 94 targeted tests passed. Updated the related specification text.

@pelikhan
pelikhan merged commit a67a4d4 into main Oct 9, 2026
3 checks passed
@pelikhan
pelikhan deleted the copilot/review-work-queue-protocol branch October 9, 2026 23:40
@github-actions

Copy link
Copy Markdown
Contributor

🎉 This pull request is included in a new release.

Release: v0.91.8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants