-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Milestone 3 — schema layer (entities, IDs, FK validation, feature dictionary, task manifest) #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
feat: Milestone 3 — schema layer (entities, IDs, FK validation, feature dictionary, task manifest) #7
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
3bf8af4
feat: Milestone 3 — schema layer (entities, IDs, FK validation, featu…
shaypal5 e72c3cc
fix: address Copilot review comments on Milestone 3 PR
shaypal5 bccdf34
ci: upgrade pr-agent-context refresh to v4.0.19 approval-gated fallba…
shaypal5 e23aea4
fix: address round-2 Copilot review comments on Milestone 3 PR
shaypal5 e52d5cb
fix(ci): harden dispatcher dedupe — blocked runs must not suppress fa…
shaypal5 8ce47fa
fix: address Copilot round-3 review comments on PR #7
shaypal5 171961a
fix: address Copilot round-4 review comments on PR #7
shaypal5 84562fe
fix: use listWorkflowRunsForWorkflow for per-workflow dedupe query
shaypal5 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
176 changes: 176 additions & 0 deletions
176
.github/workflows/pr-agent-context-refresh-dispatcher.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,176 @@ | ||
| name: PR agent context refresh dispatcher | ||
|
|
||
| # Runs on a schedule and dispatches pr-agent-context-refresh for any open | ||
| # same-repo PR that had recent review activity but no corresponding in-flight | ||
| # or recently-succeeded refresh run. | ||
| # | ||
| # WHY THIS EXISTS | ||
| # --------------- | ||
| # When a bot (e.g. Copilot / copilot-pull-request-reviewer[bot]) submits a | ||
| # review, the pull_request_review / pull_request_review_comment events fire | ||
| # and trigger pr-agent-context-refresh — but the triggered run is immediately | ||
| # blocked by GitHub's approval gate for bot/external actors: | ||
| # | ||
| # • conclusion=startup_failure → workflow could not start (counts as blocked) | ||
| # • conclusion=action_required → was approval-gated, later auto-cancelled | ||
| # | ||
| # None of those outcomes produce a refresh comment. This dispatcher fires | ||
| # from the default branch (where it is active), bypasses the approval gate | ||
| # by using the schedule's GITHUB_TOKEN, and dispatches a workflow_dispatch | ||
| # run that executes with full repo permissions. | ||
| # | ||
| # DEDUPE CONTRACT | ||
| # --------------- | ||
| # A dispatch is suppressed only when there is already meaningful coverage for | ||
| # the PR's current head SHA: | ||
| # • run is in_progress, queued, waiting, or requested → suppress | ||
| # • run completed with conclusion=success or =neutral recently → suppress | ||
| # | ||
| # Blocked / non-executed conclusions (startup_failure, action_required, | ||
| # failure, cancelled, timed_out, skipped) do NOT count as coverage and do | ||
| # NOT suppress a fallback dispatch. | ||
|
|
||
| on: | ||
| schedule: | ||
| # Every 15 minutes, all day every day. | ||
| # Bot reviews can arrive at any hour; restrict to business hours only if | ||
| # cost is a concern (e.g. '*/15 7-23 * * 1-5' for Mon-Fri 07-23 UTC). | ||
| - cron: '*/15 * * * *' | ||
|
|
||
| permissions: | ||
| actions: write | ||
| pull-requests: read | ||
|
|
||
| jobs: | ||
| dispatch: | ||
| name: Dispatch stalled PR agent context refreshes | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Find and dispatch pending refreshes | ||
| uses: actions/github-script@v7 | ||
| with: | ||
| script: | | ||
| const REFRESH_WORKFLOW = 'pr-agent-context-refresh.yml'; | ||
|
|
||
| // Only look at review activity in the last N minutes. | ||
| const LOOKBACK_MINUTES = 20; | ||
| // A successfully-completed run within this window suppresses redispatch. | ||
| const RECENT_SUCCESS_WINDOW_MINUTES = 10; | ||
|
|
||
| // Conclusions that mean the run was BLOCKED and never produced a | ||
| // refresh comment. These must NOT suppress a fallback dispatch. | ||
| const BLOCKED_CONCLUSIONS = new Set([ | ||
| 'startup_failure', | ||
| 'action_required', | ||
| 'failure', | ||
| 'cancelled', | ||
| 'timed_out', | ||
| 'skipped', | ||
| ]); | ||
|
|
||
| const now = Date.now(); | ||
| const since = new Date(now - LOOKBACK_MINUTES * 60 * 1000).toISOString(); | ||
| const recentSuccessSince = new Date( | ||
| now - RECENT_SUCCESS_WINDOW_MINUTES * 60 * 1000 | ||
| ).toISOString(); | ||
|
|
||
| const defaultBranch = context.payload.repository.default_branch; | ||
|
|
||
| // List ALL open PRs in this repository via pagination (same-repo only). | ||
| const pulls = await github.paginate(github.rest.pulls.list, { | ||
| ...context.repo, | ||
| state: 'open', | ||
| per_page: 100, | ||
| }); | ||
|
|
||
| for (const pr of pulls) { | ||
| // Same-repo guard: skip forks. | ||
| if (pr.head.repo.full_name !== context.payload.repository.full_name) { | ||
| continue; | ||
| } | ||
|
|
||
| try { | ||
| // --- Bounded recent activity check --- | ||
| const [{ data: reviews }, { data: reviewComments }] = await Promise.all([ | ||
| github.rest.pulls.listReviews({ | ||
| ...context.repo, | ||
| pull_number: pr.number, | ||
| per_page: 10, | ||
| }), | ||
| github.rest.pulls.listReviewComments({ | ||
| ...context.repo, | ||
| pull_number: pr.number, | ||
| per_page: 10, | ||
| }), | ||
| ]); | ||
|
|
||
| const hasRecentActivity = | ||
| reviews.some((r) => r.submitted_at >= since) || | ||
| reviewComments.some( | ||
| (c) => c.created_at >= since || c.updated_at >= since | ||
| ); | ||
|
|
||
| if (!hasRecentActivity) continue; | ||
|
|
||
| // --- In-flight / recent-success dedupe --- | ||
| // Fetch runs for this exact head SHA so stale runs from | ||
| // earlier commits don't suppress dispatch for the new SHA. | ||
| const { data: { workflow_runs: runs } } = | ||
| await github.rest.actions.listWorkflowRunsForWorkflow({ | ||
| ...context.repo, | ||
| workflow_id: REFRESH_WORKFLOW, | ||
| head_sha: pr.head.sha, | ||
| per_page: 10, | ||
| }); | ||
|
|
||
| const hasValidCoverage = runs.some((r) => { | ||
| // Actively working toward a refresh — don't interrupt. | ||
| if ( | ||
| r.status === 'in_progress' || | ||
| r.status === 'queued' || | ||
| r.status === 'waiting' || | ||
| r.status === 'requested' | ||
| ) { | ||
| return true; | ||
| } | ||
|
|
||
| // Completed: only suppress if the run actually succeeded | ||
| // recently. Blocked / failed conclusions are transparent. | ||
| if (r.status === 'completed') { | ||
| if (BLOCKED_CONCLUSIONS.has(r.conclusion)) return false; | ||
| return ( | ||
| (r.conclusion === 'success' || r.conclusion === 'neutral') && | ||
| r.updated_at >= recentSuccessSince | ||
| ); | ||
| } | ||
|
|
||
| return false; | ||
| }); | ||
|
|
||
| if (hasValidCoverage) { | ||
| console.log( | ||
| `PR #${pr.number}: valid refresh already running or recently succeeded — skipping.` | ||
| ); | ||
| continue; | ||
| } | ||
|
|
||
| // --- Dispatch --- | ||
| await github.rest.actions.createWorkflowDispatch({ | ||
| ...context.repo, | ||
| workflow_id: REFRESH_WORKFLOW, | ||
| ref: defaultBranch, | ||
| inputs: { | ||
| pull_request_number: String(pr.number), | ||
| pull_request_head_sha: pr.head.sha, | ||
| pull_request_base_sha: pr.base.sha, | ||
| }, | ||
| }); | ||
|
|
||
| console.log( | ||
| `Dispatched refresh for PR #${pr.number} (head: ${pr.head.sha}).` | ||
| ); | ||
| } catch (err) { | ||
| // Per-PR error isolation: log and continue to the next PR. | ||
| console.error(`PR #${pr.number}: dispatch failed — ${err.message}`); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,16 +1,63 @@ | ||
| """Entity ID generation. | ||
|
|
||
| Implemented in Milestone 3. All IDs must be stable, opaque, namespace-unique, | ||
| and deterministic for a given run. | ||
|
|
||
| Canonical prefixes: | ||
| acct_ — Account | ||
| cnt_ — Contact | ||
| lead_ — Lead | ||
| touch_ — Touch | ||
| sess_ — Session | ||
| act_ — SalesActivity | ||
| opp_ — Opportunity | ||
| cust_ — Customer | ||
| sub_ — Subscription | ||
| All IDs are stable, opaque, namespace-unique, and deterministic for a given | ||
| (recipe, config, seed) triple. Callers derive a dedicated RNG substream via | ||
| ``RNGRoot.child()`` and pass a monotonically increasing counter to | ||
| :func:`make_id`. | ||
|
|
||
| Canonical prefixes | ||
| ------------------ | ||
| The following nine prefixes correspond directly to the nine relational tables | ||
| defined in ``schema/entities.py``: | ||
|
|
||
| acct_ — Account | ||
| cnt_ — Contact | ||
| lead_ — Lead | ||
| touch_ — Touch | ||
| sess_ — Session | ||
| act_ — SalesActivity | ||
| opp_ — Opportunity | ||
| cust_ — Customer | ||
| sub_ — Subscription | ||
|
|
||
| The ``rep_`` prefix is an internal-only namespace used for sales-rep entities | ||
|
shaypal5 marked this conversation as resolved.
|
||
| that participate in simulation mechanics but do **not** have a corresponding | ||
| standalone relational table in the v1 output bundle. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| # Canonical prefix registry — single source of truth used by tests and | ||
| # simulation code alike. | ||
| ID_PREFIXES: dict[str, str] = { | ||
| "account": "acct", | ||
| "contact": "cnt", | ||
| "lead": "lead", | ||
| "touch": "touch", | ||
| "session": "sess", | ||
| "sales_activity": "act", | ||
| "opportunity": "opp", | ||
| "customer": "cust", | ||
| "subscription": "sub", | ||
| "rep": "rep", | ||
| } | ||
|
shaypal5 marked this conversation as resolved.
shaypal5 marked this conversation as resolved.
|
||
|
|
||
| _PAD_WIDTH = 6 # e.g. acct_000001 | ||
|
|
||
|
|
||
| def make_id(prefix: str, n: int) -> str: | ||
| """Return a zero-padded entity ID string. | ||
|
|
||
| Args: | ||
| prefix: The namespace prefix (e.g. ``"acct"``). | ||
| n: A 1-based counter for this entity type within one generation run. | ||
|
|
||
| Returns: | ||
| A string of the form ``"<prefix>_<n:06d>"``; e.g. ``"acct_000001"``. | ||
|
|
||
| Raises: | ||
| ValueError: if *n* is not a positive integer. | ||
| """ | ||
| if not isinstance(n, int) or isinstance(n, bool) or n < 1: | ||
| raise ValueError(f"n must be a positive int, got {n!r}") | ||
| return f"{prefix}_{n:0{_PAD_WIDTH}d}" | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.