Skip to content

Make CodeGen deterministic-from-external-source; converge with downstream - #192

Merged
ptr727 merged 1 commit into
developfrom
codegen-deterministic-converge
Jun 23, 2026
Merged

ptr727 merged 1 commit into
developfrom
codegen-deterministic-converge

Conversation

@ptr727

@ptr727 ptr727 commented Jun 23, 2026

Copy link
Copy Markdown
Owner

Makes the CodeGen example deterministic-from-external-source (like the real downstream consumers NxWitness/LanguageTags) and converges the codegen/merge-bot workflows with the best downstream patterns.

Problem

The CodeGen demo embedded a per-build timestamp, so CI needed a get-runtime job to capture one UTC timestamp and pass it via --runtime to both the main and develop matrix legs (to keep output byte-identical and avoid develop -> main conflicts). That state-sharing is convoluted and unlike how the actual downstream codegen consumers work.

Note: ESPHome-NonRoot and homeassistant-purpleair do NOT use codegen — they use the upstream-version checker. The codegen consumers are NxWitness and LanguageTags, so the example is aligned to those.

Core change — timestamp is opt-in, local-only

  • --runtime absent ⇒ deterministic output (the ApiNinjas quote-of-the-day alone); now ⇒ embed DateTime.UtcNow; ISO literal ⇒ embed it.
  • The quote-of-the-day is daily-stable, so both matrix legs on the same day produce identical output. The only divergence is the rare day-boundary case (source updates between legs) — anticipated and self-healing, exactly like NxWitness/LanguageTags.
  • get-runtime job and --runtime removed from CI; each leg runs a single deterministic dotnet run. CodeGen.cs regenerated without the timestamp. launch.json passes --runtime now so local runs still demonstrate the per-run-divergence lesson.

Convergence with downstream (best end-state, per request)

  • merge-bot → pull_request_target (LanguageTags' hardened variant): the jobs mint an App token, so the workflow definition and action SHAs now resolve from the trusted base branch, not the PR head. Safe because no job checks out PR code — each only runs gh pr merge by URL. ⚠️ Highest-risk change in this PR; please review with focus.
  • run-periodic concurrency → workflow-only group: fixes a real race the ref-scoped group allowed (a workflow_dispatch from a non-default ref and the scheduled run could run simultaneously against the fixed codegen-* branches).

Verification

  • Clean-compile: build 0 warnings, CSharpier clean, dotnet format style --verify-no-changes clean.
  • Behavior: no --runtime ⇒ byte-identical across runs, no dateTime const; --runtime now ⇒ differs per run; literal ⇒ embeds the value.
  • All 3 workflows parse; merge-bot has zero checkout steps (the pull_request_target safety precondition); line endings preserved.

Operational note

pull_request_target runs triggered by Dependabot still use the Dependabot secrets store, so the CODEGEN_APP_* secrets must be present there (already documented in README) — unchanged by this PR, but worth confirming.

Deferred (not in this PR)

  • Action version bumps where downstream leads (checkout v7, setup-dotnet v5.3, fetch-metadata v3.1) — Dependabot's job; hand-applying to only these files would diverge them from the rest of the template.
  • Pushing the template's merge-upstream-version merge-bot job down to NxWitness (a downstream edit).

🤖 Generated with Claude Code

…ream

The CodeGen demo embedded a per-build timestamp, which forced a convoluted
get-runtime job to share one UTC timestamp across the main/develop matrix
legs so output stayed byte-identical. That is unlike the real downstream
codegen consumers (NxWitness, LanguageTags), which generate deterministically
from an external source with no cross-leg state.

- CodeGen app: --runtime is now opt-in. Absent -> deterministic output (the
  quote alone); `now` -> embed DateTime.UtcNow; ISO literal -> embed it. The
  timestamp path is a local-only demo of why per-run state diverges.
- CodeGen.cs regenerated to the deterministic shape (no timestamp).
- run-codegen-pull-request-task.yml: drop the get-runtime job and --runtime;
  each matrix leg runs a single deterministic dotnet run, like NxWitness/
  LanguageTags. Rare day-boundary drift is expected and self-heals.
- launch.json: pass --runtime now so a local run still exercises the demo.

Convergence with downstream (best end-state):
- merge-bot: trigger on pull_request_target, not pull_request (LanguageTags'
  hardened variant) - jobs hold the App key so action SHAs must resolve from
  the trusted base; safe because no job checks out PR code.
- run-periodic concurrency: workflow-only group (fixes a real dispatch-vs-
  schedule race the ref-scoped group allowed).

Docs: rewrite the AGENTS.md codegen bullet to the deterministic model; note
the merge-bot pull_request_target choice in README.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Copilot AI review requested due to automatic review settings June 23, 2026 17:46

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.

Pull request overview

This PR updates the template's CodeGen example and related workflows to remove CI-specific per-run state sharing and align the template with deterministic-from-external-source patterns used by downstream consumers. It also hardens the merge-bot workflow by switching it to pull_request_target while keeping the safety precondition of not checking out PR code.

Changes:

  • Make CodeGen output deterministic by default (timestamp embedding becomes opt-in via --runtime, intended for local-only demonstration).
  • Simplify the codegen PR workflow by removing the shared get-runtime job and the --runtime plumbing.
  • Switch merge-bot to pull_request_target and adjust periodic-codegen concurrency to avoid branch write races.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.

Show a summary per file
File Description
README.md Documents the pull_request_target rationale/safety model for merge-bot.
CodeGen/CommandLine.cs Updates --runtime option help text to reflect new deterministic-by-default behavior.
CodeGen/CodeGenBuilder.cs Splits generation into deterministic vs timestamp-embedded variants; adds runtime resolution (now vs literal).
CodeGen/CodeGen.cs Regenerates the sample output to remove the embedded timestamp in the deterministic default.
AGENTS.md Updates the guidance to emphasize deterministic-from-inputs codegen and positions --runtime as local-only demo.
.vscode/launch.json Adds --runtime now to the CodeGen debug profile to keep the local divergence demo.
.github/workflows/run-periodic-codegen-pull-request.yml Changes concurrency grouping to workflow-only to prevent scheduled/dispatch races on fixed branches.
.github/workflows/run-codegen-pull-request-task.yml Removes the shared runtime capture job and stops passing --runtime in CI.
.github/workflows/merge-bot-pull-request.yml Switches trigger to pull_request_target and documents the safety premise (no PR checkout; merge by URL).

@ptr727
ptr727 merged commit f981198 into develop Jun 23, 2026
5 checks passed
ptr727 added a commit that referenced this pull request Jun 23, 2026
Closes #193.

- Removed the dead intra-doc anchor from the mandated-verbatim PR Review Etiquette callout (its target lives under the hub-only Quick Start, which derived repos don't carry).
- Split the codegen-determinism bullet into a carryable provider-agnostic principle (regenerate committed files; output deterministic from inputs, never per-run state; what/how is the derived repo's concern) and a clearly-marked droppable template-demo note (API-Ninjas quote + --runtime).
- Stopped naming sibling repos in carried text.
ptr727 added a commit that referenced this pull request Jun 23, 2026
Promotes the current `develop` head to `main` for release.

Contents:
- **#192** — Make CodeGen deterministic-from-external-source; converge
codegen/merge-bot workflows with downstream (drops the per-build
timestamp + `get-runtime` state-sharing; merge-bot hardened to
`pull_request_target`; periodic concurrency workflow-only group).
- **#194** — Make the #192 codegen docs carry cleanly into derived repos
(closes #193: dead-anchor removal + split codegen principle from demo
specifics).

Standard release promotion: merge (not squash). A separate
`publish-release.yml` dispatch performs the actual release after this
lands.

🤖 Generated with [Claude Code](https://claude.com/claude-code)
@ptr727
ptr727 deleted the codegen-deterministic-converge branch July 7, 2026 21:05
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.

2 participants