Skip to content

Phase 1: prod-safety foundation for staging - #931

Merged
neuromechanist merged 2 commits into
feature/issue-923-epic-test-stagingfrom
feature/issue-930-phase1-prod-safety
Jul 6, 2026
Merged

neuromechanist merged 2 commits into
feature/issue-923-epic-test-stagingfrom
feature/issue-930-phase1-prod-safety

Conversation

@neuromechanist

Copy link
Copy Markdown
Contributor

Summary

Foundation for the staging environment (epic #923). Every change is a no-op or narrowing on production; nothing here alters prod behavior, so it is safe to promote to `main` promptly ahead of the later phases.

  • Migration 0057 adds `is_exemplar` (0/1, default 0) to `datasets`. Inert until phases 4-5 relax the `xx` gates; production never has `is_exemplar=1` rows.
  • Sandbox ID partition (`datasetId.ts`): `generateDatasetId` takes optional `{sandboxIdFloor, sandboxIdCeiling}`, clamped to `[start, 99999]`. Prod `SANDBOX_ID_CEILING="89999"` (xx000001-xx089999); dev/test `SANDBOX_ID_FLOOR="90001"` (xx090001-xx099999). Inside the existing cap so `isValidDatasetId` and all prod gates keep exact semantics. New `DEV_SANDBOX_RANGE_RE` + `isDevRangeDatasetId`.
  • Webhook gate (`webhooks/github.ts`): `POST /webhooks/github` short-circuits `xx09NNNN` repos with `reason: "dev_range_repo"` only when `ENVIRONMENT === "production"`; prod never dispatches against staging repos (callbacks would 404). Dev falls through (phase 5 adds the forward).
  • On-import block (`admin/imports.ts`): `POST /admin/datasets/import` production-only (deterministic on-id repo collisions).
  • Sandbox upload size cap raised outside production (10 MB -> 500 MB).

Test plan

  • `backend/test/dataset-id-partition.test.ts` — real in-memory D1 (no mocks): floor/ceiling/gap-fill, legacy-low-id skip, exhaustion, nm-unaffected, boundary.
  • `backend/test/webhook-github-dev-range.test.ts` — real Hono route + real HMAC: prod short-circuits dev-range before dispatch; prod repos and dev worker fall through.
  • `bun test` green; `tsc --noEmit` clean; Biome clean.

Closes #930
Part of epic #923

Epic #923 (#930). All changes are no-ops/narrowing on prod:
- migration 0057 adds is_exemplar column (inert until phases 4-5)
- generateDatasetId gains a sandbox ID range partition; prod caps at
  xx089999 (SANDBOX_ID_CEILING), dev/test floors at xx090001
  (SANDBOX_ID_FLOOR), so the shared nemarDatasets org can't collide
- DEV_SANDBOX_RANGE_RE + isDevRangeDatasetId identify staging repos
- POST /webhooks/github short-circuits dev-range repos on prod (no
  dispatch against staging repos whose callbacks 404 on prod)
- POST /admin/datasets/import is production-only (on-id collisions)
- sandbox upload size cap raised outside production
- unit tests: partition (real D1) + webhook gate (real HMAC route)
- resolveRange() guards non-finite bounds with Number.isFinite so the
  clamp invariant holds at the function layer, not just via the caller;
  single source of truth for the allocator loop and exhaustion message
- parseRangeBound warns on an unparseable SANDBOX_ID_* value instead of
  silently reverting to the full xx range
- tests: function-level NaN/Infinity clamp; webhook gate leaves a
  prod-range xx (sandbox) repo below the ceiling untouched
@neuromechanist

Copy link
Copy Markdown
Contributor Author

Review (sonnet, pr-review-toolkit) — findings addressed

Full backend suite green (424 tests, incl. 16 new for this phase); migration 0057 verified against a populated table; range math traced by hand for NaN/empty/negative/floor>ceiling/floor>cap.

Addressed in a9df607:

  • [moderate] findLowestUnusedNumber clamp propagated NaN (lower bound silently dropped). Extracted resolveRange() with Number.isFinite guards so the invariant holds at the function layer, not just via the one caller; it's now the single source of truth for the allocator and the exhaustion-error range.
  • [moderate] parseRangeBound silently reverted a typo'd SANDBOX_ID_* to the full range. Now console.warns (mirrors the existing ENVIRONMENT warning).
  • [suggestion] exhaustion message no longer duplicates clamp logic (uses resolveRange).
  • [test gap] added: function-level NaN/Infinity clamp test; webhook test that a prod-range xx (sandbox) repo below the ceiling is NOT gated.

No prod behavior change; every edit remains a no-op/narrowing on production.

@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown

📦 Package Preview

Your package is ready to test!

bun install -g nemar-cli@PR931

Version: 0.8.76-PR931.a9df607
Commit: a9df607


🤖 Updated on each push.

This branch was previously deployed

1 inactive deployment
npm — a9df6074 Deployed Jul 6, 2026 by neuromechanist via publish #1682
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