Skip to content

Validate workflow parseability after CI deploy - #469

Merged
neuromechanist merged 4 commits into
devfrom
feature/issue-287-post-deploy-validate
May 14, 2026
Merged

neuromechanist merged 4 commits into
devfrom
feature/issue-287-post-deploy-validate

Conversation

@neuromechanist

Copy link
Copy Markdown
Contributor

Closes #287

Summary

After deployWorkflows() commits workflow YAML files via the Contents/Trees
API, GitHub Actions only lists files it can actually parse. A workflow file
that committed cleanly but contains a YAML syntax error is silently broken:
it appears in the repo's .github/workflows/ directory but GitHub Actions
never runs it.

Added a best-effort post-deploy verification step:

  1. After the tree commit succeeds, wait ~2.5s for GitHub to index the new files
  2. Call GET /repos/{org}/{repo}/actions/workflows?per_page=100
  3. For each filename in deployed, check whether GitHub Actions listed it
  4. Workflows that committed but are missing from the listing land in a new
    optional validationErrors field on the return value

Validation is opt-out (validate: false) but defaults on. It never fails the
deploy: transient indexing lag is the most common cause of "missing" warnings,
and aggregating these as warnings lets the admin (or audit log) surface real
YAML parse errors without breaking the publish pipeline.

POST /admin/datasets/:id/ci/deploy now surfaces validation_warnings in
its JSON response when validation finds any issue.

Test plan

  • bun test test/tree-batched-commit.test.ts (24 pass; new tests cover
    missing/all-present/server-error code paths against the existing fake
    Bun.serve GitHub used by the rest of the suite)
  • bun run tsc --noEmit (passes for both CLI and backend/)
  • No mocks: tests run against a real local HTTP server that records every
    request, consistent with the project's NO MOCK policy

@github-actions

github-actions Bot commented May 14, 2026 •

Copy link
Copy Markdown

📦 Package Preview

Your package is ready to test!

bun install -g nemar-cli@PR469

Version: 0.8.14-PR469.9a8e13e
Commit: 9a8e13e


🤖 Updated on each push.

@neuromechanist

Copy link
Copy Markdown
Contributor Author

PR Review: #469 — Validate workflow parseability after CI deploy

Critical

[errors] validation_warnings silently dropped in CLI — AddCiResponse in src/lib/api.ts does not include validation_warnings, so the field is stripped and never surfaced to the admin at the terminal. The backend correctly returns it in the JSON response, but the CLI loop at admin.ts:748 only iterates result.workflows_deployed. An admin running nemar admin ci add nm000104 gets "CI workflows deployed" with no indication of YAML parse failures. This defeats the purpose of the feature for the primary user-facing workflow. Fix: add validation_warnings?: string[] to AddCiResponse and print a yellow warning block after the workflow list if non-empty.

[errors] 2.5s setTimeout blocks Cloudflare Worker per invocation — await new Promise((resolve) => setTimeout(resolve, delayMs)) runs on the Worker event loop and counts toward Cloudflare's wall-clock limit. The POST /admin/datasets/:id/ci endpoint already does a tree commit (4 GitHub API round trips) and now unconditionally sleeps 2.5s + makes a 5th API call before responding. The --all path in the CLI iterates serially: at 200 datasets, each Worker invocation incurs ~3s of overhead (2.5s sleep + one listing call). That's 600s of total HTTP time from the CLI side, and each of those 200 Worker invocations spends 2.5s of its wall-clock budget asleep. Cloudflare Workers have a 30s wall-clock limit per invocation (shorter CPU time budget on paid plans). The single-dataset path is fine; the fleet-deploy scenario is a real operational risk.

Important

[code] No retry/backoff for indexing lag — The entire rationale for the 2.5s delay is that GitHub's workflow index lags the git commit. A single fixed sleep with a single probe makes the check brittle: if GitHub indexing takes 3s on a loaded instance, every deploy generates a spurious warning. A simple 2-3 attempt retry loop with exponential backoff (1s, 2s, 4s) would cost at most ~7s in the slow case while nearly eliminating false positives. githubFetchWithRetry retries on 5xx, but the caller only invokes it once after the fixed delay — so the single-shot nature of this check is a design gap.

[code] Route does not forward validate option; callers cannot opt-out via API — deployWorkflows(repoName, await getDatasetsToken(c.env)) at admin.ts:2314 always uses the default (validate: true). There is no query-param or request body field to pass validate: false. This means every CI deploy via the admin route incurs the 2.5s wait + extra API call, even in bulk scenarios where a caller might prefer speed over validation. Either document this as intentional or expose validate as an optional body param.

[tests] No test for 429 / rate-limit on the validation listing call — actionsWorkflowsBehavior only models "ok" | "server-error". The 429 path is handled by githubFetchWithRetry in production, but the current test enum has no way to express it. Worth a TODO comment noting the gap (testing it would require mocking sleep, which conflicts with the project's no-mock policy).

[tests] state: disabled workflow not addressed — GitHub lists workflows that are syntactically valid but state: disabled_manually. The PR's validation only checks filename presence, not state. A disabled workflow is still listed, so the check correctly treats it as "parseable." A comment explaining this design choice (presence = parseable, state is irrelevant here) would prevent future reviewers from wondering why disabled workflows are not flagged as issues.

Suggestions

[simplify] validateWorkflowsParseable catch block has dead branch — err instanceof Error ? err.message : String(err): the String(err) branch is unreachable in practice because fetch only throws Error subtypes. Minor, but a String(err) fallback for network errors is usually a sign of defensive code that never gets exercised.

[code] per_page=100 is not paginated — GitHub paginates workflow listings at 100 per page. With 6 templates today this is fine, but if getWorkflowTemplates() ever grows, workflows on page 2 would silently appear "missing." A comment noting the assumed upper bound (// 6 templates; page 1 of 100 is sufficient) would future-proof the intent.

[comments] JSDoc on deployWorkflows says "Callers MUST check success" but does not mention validationErrors — Update the doc to note that callers should also inspect validationErrors when success is true.

Nice-to-haves

  • The audit log at admin.ts:2333 records deployed_by but not validation_warnings. Including them would let operators audit whether a deploy had YAML issues without re-running validation.
  • validateDelayMs is tunable but not documented in the function JSDoc. A sentence explaining the 2500ms default (chosen empirically for GitHub's indexing lag) would help future maintainers.

False positives / intentional design choices

  • Best-effort, never throws, never fails deploy: keeping success: true despite validation warnings is intentional and correct; transient indexing lag is the most common trigger. Not a false positive.
  • Single GET /actions/workflows call: a single call is a valid first iteration. Flagged as Important rather than Critical because the fallout (spurious warning) is non-blocking.

- Add validation_warnings field to AddCiResponse type
- Print yellow warning block after workflow list in ci add
- Print per-dataset warnings in --all loop with dsSpinner.warn()
- Add --no-validate flag to ci add for fleet deploys
- Pass ?validate=false query param to backend when --no-validate used
- Backend reads validate param and forwards to deployWorkflows()
- Include validation_warnings in audit log details
- Add retry in deployWorkflows: probe at 2.5s, retry once at 5s if missing
- Document disabled workflow state behavior in comments and JSDoc
- Add per_page=100 pagination comment in validateWorkflowsParseable
- Add 429 handling note in comment with TODO for future test coverage
- Update tests: expect 2 listing calls on missing, 3 on server-error
@neuromechanist

Copy link
Copy Markdown
Contributor Author

Review findings addressed (commit 9a8e13e)

Critical #1 — validation_warnings silently dropped:

  • Added validation_warnings?: string[] to AddCiResponse in src/lib/api.ts with doc comment.
  • ci add (single dataset): prints a yellow warning block after the workflow list when non-empty.
  • ci add --all: uses dsSpinner.warn() + per-warning lines for datasets that deployed with warnings.
  • Note: ci check returns current CI run status (GET), not deploy-time warnings, so it has no validation_warnings to surface — these are orthogonal concerns.

Critical #2 — 2.5 s Worker sleep burns budget at scale:

  • Added --no-validate flag to ci add. Commander sets options.validate = false; the flag is documented with the fleet-deploy tradeoff in the help text.
  • addCi() in api.ts accepts { validate?: boolean } and appends ?validate=false when needed.
  • Backend reads c.req.query("validate") and passes { validate: shouldValidate } to deployWorkflows().
  • Audit log now records validation_warnings when present.
  • Follow-up issue for moving validation out of Worker entirely: Move CI workflow validation out of Worker #472.

Important #1 — retry/backoff for indexing lag:

  • deployWorkflows probes at validateDelayMs (default 2.5 s); if any workflow is still missing and no API error occurred, retries once after validateDelayMs * 2 (default 5 s). Cap: 2 probes total.
  • Tests updated: "missing" case now expects 2 listing calls; "all present" case expects 1.

Important #3 — 429 test coverage:

  • Added TODO comment in the "server-error" test explaining why 429 can't be tested here (no-mock policy + sleep control requirement) and noting that githubFetchWithRetry covers the retry path.
  • Added note in validateWorkflowsParseable that 429 from exhausted retries surfaces in validationErrors.

Important #4 — state: disabled workflows:

  • Added code comment in validateWorkflowsParseable explaining presence = parseable, state is irrelevant.
  • Added comment in the "all present" test fixture explaining this design choice.

Suggestions (also addressed):

  • Added per_page=100 pagination comment noting assumed upper bound of 6 templates.
  • Updated deployWorkflows JSDoc to mention validationErrors, validateDelayMs default rationale, and retry strategy.
  • Audit log now includes validation_warnings.

@neuromechanist
neuromechanist merged commit 4d1614c into dev May 14, 2026
1 check passed
@neuromechanist
neuromechanist deleted the feature/issue-287-post-deploy-validate branch May 14, 2026 05:15

This branch was previously deployed

1 inactive deployment
npm — 898ab32b Deployed May 14, 2026 by neuromechanist via publish #829
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.

1 participant