Skip to content

Add unwired exact-selected Sites publication orchestration - #1265

Merged
sidneyswift merged 3 commits into
mainfrom
codex/sites-selected-publication
Nov 17, 2026
Merged

sidneyswift merged 3 commits into
mainfrom
codex/sites-selected-publication

Conversation

@sidneyswift

@sidneyswift sidneyswift commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Sites has evidence capture/read adapters but needs publication orchestration bound to the exact selected preview and explicit intent. This adds an unwired orchestrator against Database proposal #136, exact successor afd214aa73dfd70b0f2b860fce90c12ceb23f28b.

The server independently resolves the selected draft or signed working build and requires matching digest/revision/owner/artist plus explicitly nullable publication-pointer metadata. Workspace, Context, artist, paid entitlement and prepared fan configuration are checked before evidence capture and rechecked before publication. A stored review or explicitly requested override runs through the complete existing predicate. SQL receives the immutable record identity, selected digest, expected pointer and expected artist ID; its site-row lock now fences artist changes before publication writes. It publishes the stored candidate, never request-supplied replacement bytes.

Existing advisory publishing remains unchanged. Shared paid, return-URL and capture-envelope transforms are reused. Only the new path opts into Stripe read-error propagation (503 versus a real unpaid402). Missing/malformed pointer or evidence metadata fails closed; errors never become implicit overrides, replacement keys or automatic retries. There is no public route, UI/MCP/workflow caller, new mandatory artist approval, schema exposure, runtime grant, migration or activation. Database #136 stays draft and unmerged.

Remaining gates: external artist access/name, paid entitlement, Context, fan configuration and Workflow reads are not atomic with SQL. Latest-preview races, pointer ABA, explicit selection/override interaction, artist/fan preparation transitions, SQL release/admission and retention remain separate. The expected-artist fence closes the identified site-artist-ID race, not these other policies. Receipt/transport errors can follow a committed publication and must not trigger blind retries. See docs/site-selected-publication.md.

Validation:181 focused/regression tests across16files, actual-import TypeScript check, repository lint, changed-file formatting and diff check. Database proposal:30disposable tests on each PostgreSQL15.10/17.7 (29proposal+1inherited), including artist mismatch/no-write, null semantics and observed lock contention. API boundaries are mocked; actual identity/predicate/golden serialization are exercised. Independent spec/standards reviews cleared exact API1f2b819f1e01d3e158829a678cd84799f81274b5 paired with SQLafd214a. All8initial automated findings are addressed and resolved. Final cleanup head 97b5d6a800ad2e77091d388911a1d2381b65a932 is fully green: Unit workflow 44201131099 checked synthetic merge 39ec4968 with an identical tree, passed9,975tests/53skipped and every later offline/type step. Both independent reviewers cleared the cleanup; all10review threads are resolved. Final Cubic review found zero new issues in its four-file delta scope. Cross-repository authority remains bounded by the paired reviews and documented activation gates.

@vercel

vercel Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
api Ready Ready Preview Nov 17, 2026 11:39pm UTC

Request Review

@coderabbitai

coderabbitai Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Pre-merge checks: Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Solid & Clean Code Warning The check FAILS on SRP, DRY and Clean Code thresholds. I re-verified each claim in the standing failure against current code at HEAD 97b5d6a. All of these files are new in this PR. `git diff --stat 7… Refactor before merge: 1. Split publishSelectedSiteEvidence into small single-purpose functions. Examples: resolve-and-authorize, obtain the evidence ID (review or override), assess the selected evidence, and publish. Keep the orchestrato…
Full details: Solid & Clean Code

Explanation

The check FAILS on SRP, DRY and Clean Code thresholds. I re-verified each claim in the standing failure against current code at HEAD 97b5d6a. All of these files are new in this PR. git diff --stat 72b628ac HEAD -- lib/sites lists each as added, so causality is direct. 1. publishSelectedSiteEvidence.ts lines 16–92 (77 lines). The check sets a limit of 20 lines per function. This function is about four times that limit. It validates input, resolves candidates, authorizes, inserts overrides, validates receipts, defines an inline assess closure, publishes, and validates the publication receipt. That is several responsibilities in one function. It also reassigns resolved and evidenceId with let. 2. Repeated resolve-and-authorize pair. Lines 25–26 and 78–79 call resolveSelectedSiteCandidate then authorizeSelectedSitePublication with the same arguments. The pair is not extracted into a helper. This is a DRY violation. 3. Repeated validateSiteOverrideReceipt call. Lines 37–42 and 58–63 use the same call with the same arguments. This is a DRY violation. 4. resolveSelectedSiteCandidate.ts lines 9–43 (about 35 lines). It combines site lookup, workspace authorization, pointer compare-and-set, candidate selection and identity hashing. Line 20 uses an unsafe cast, (site as unknown as Record<string, unknown>).published_evidence_id. 5. authorizeSelectedSitePublication.ts lines 12–41 (about 30 lines). It combines brief, artist, organization, entitlement, fan configuration and artist-name checks. Line 35 is a bare getFanOAuthConfig(); call. Its result is discarded, so its side effect is implicit. 6. validateSitePublicationReceipt.ts lines 34–61 (about 28 lines). It combines schema parsing, identity recomputation and field comparison. Passing checks: - Each new file name matches its exported function name. - The paid-subscription and return-URL logic is extracted and reused. - Nesting stays within three levels. These passing items do not offset the violations above. The standing failure is not addressed. Commit 1f2b819f changes error handling and the artist fence. It does not split the flagged functions, remove the duplicate pair or the duplicate receipt call, remove the discarded call, or replace the unsafe cast.

Resolution

Refactor before merge: 1. Split publishSelectedSiteEvidence into small single-purpose functions. Examples: resolve-and-authorize, obtain the evidence ID (review or override), assess the selected evidence, and publish. Keep the orchestrator under 20 lines. 2. Extract the repeated resolveSelectedSiteCandidate → authorizeSelectedSitePublication pair into one helper. Call it at both points that need a fresh check. 3. Extract the repeated validateSiteOverrideReceipt call into one local helper, or keep a single call site. 4. Shorten resolveSelectedSiteCandidate, authorizeSelectedSitePublication and validateSitePublicationReceipt to under 20 lines each. Move the pointer compare-and-set check, candidate selection and field comparisons into named helpers. 5. Replace the discarded getFanOAuthConfig(); call in authorizeSelectedSitePublication.ts with an explicit, named validation step. Remove it if it is not needed. 6. Replace as unknown as Record<string, unknown> in resolveSelectedSiteCandidate.ts with a typed or schema-based read of published_evidence_id.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-17T23:23:03.100241Z d804661 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

All reported issues were addressed across 19 files

Architecture diagram
sequenceDiagram
    participant Server as Server (unwired caller)
    participant Pub as publishSelectedSiteEvidence
    participant Resolve as resolveSelectedSiteCandidate
    participant Auth as authorizeSelectedSitePublication
    participant Assess as assessSitePublishEvidence
    participant SQL as SQL RPC layer
    participant DB as Database (proposal #136)
    participant Stripe as Stripe Provider
    participant Context as Context Provider
    participant Fan as Fan Config Store

    Note over Server,DB: Unwired exact-selected publication orchestration
    
    Server->>Pub: publishSelectedSiteEvidence(accountId, operationKey, input)
    
    Pub->>Resolve: First resolution pass
    Resolve->>DB: selectSite(siteId)
    DB-->>Resolve: Site row
    Resolve->>Resolve: authorizeSiteWorkspace(accountId, ownerId)
    Resolve->>Resolve: Validate pointer/CAS metadata match
    
    alt Has generationToken
        Resolve->>Resolve: readPublishableBuild(signed generation)
    else Draft preview
        Resolve->>Resolve: Use site.draft
    end
    
    Resolve->>Resolve: Compute candidate digest, verify against selection
    Resolve-->>Pub: Resolved site + candidate + identity

    Pub->>Auth: First authority pass
    Auth->>Context: readSiteContextBrief(briefId)
    Auth->>Auth: Check artist exists and belongs to workspace
    Auth->>Stripe: readPaidSiteSubscription(ownerId) [fresh read]
    Stripe-->>Auth: Paid entitlement status
    Auth->>Fan: getFanOAuthConfig + selectFanConfig(siteId)
    Fan-->>Auth: Existing config
    Auth->>Auth: resolveSiteFanReturnUrl (validate destination)
    Auth-->>Pub: Authority confirmed

    alt Override intent
        Pub->>SQL: insertSiteOverrideEvidence (create-once capture)
        SQL->>DB: record_evidence RPC
        DB-->>SQL: Captured override record
        SQL-->>Pub: Override receipt
        Pub->>Pub: validateSiteOverrideReceipt
    else Stored review
        Pub->>SQL: selectSitePublishEvidence (later in assess)
    end

    Pub->>Assess: First assessment pass
    Assess->>SQL: selectSitePublishEvidence
    SQL-->>Assess: Stored evidence record
    Assess->>Assess: Run full predicate (review/override eligibility)
    Assess-->>Pub: Assessment satisfied

    Pub->>Resolve: Second resolution pass (fresh recheck)
    Resolve-->>Pub: Re-resolved site + candidate

    Pub->>Auth: Second authority pass (recheck all gates)
    Auth-->>Pub: Authority confirmed again

    Pub->>Assess: Second assessment pass (repeat)
    Assess-->>Pub: Evidence still valid

    Pub->>SQL: publishSiteEvidenceCandidate (fixed CAS args)
    SQL->>DB: publish_candidate RPC
    DB-->>SQL: Publication receipt
    SQL-->>Pub: Receipt with immutable stored candidate

    Pub->>Pub: validateSitePublicationReceipt
    
    alt Receipt valid
        Pub-->>Server: Success with published site + evidence
    else Receipt mismatch or SQL conflict
        Pub-->>Server: Error propagates (no retry/fallback/rekey)
    end

    Note over Server,DB: Failure modes fail closed - no implicit overrides
Loading

Reply with feedback, questions, or to request a fix.

View guided diff | Turn on auto-fix | Re-trigger cubic

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

All reported issues were addressed across 19 files (changes from recent commits).

Reply with feedback, questions, or to request a fix.

View guided diff | Turn on auto-fix | Re-trigger cubic

Comment thread docs/site-selected-publication.md Resolved

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

0 issues found across 4 files (changes from recent commits).

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Requires human review: The orchestration appears deliberately unwired, but omitted diffs prevent verifying that no runtime caller activates it. The proposed SQL artist fence is also outside the diff, so its key publication safeguard cannot be checked.

View guided diff | Turn on auto-fix | Re-trigger cubic

@sidneyswift
sidneyswift merged commit f6103bc into main Nov 17, 2026
8 checks passed

This branch was successfully deployed

1 active deployment
Preview — 97b5d6a8 Deployed Nov 17, 2026 by vercel[bot]
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