Skip to content

feat(labeler): code-AI and history stage wiring + dead-stage removal (slice A) - #2090

Merged
ascorbic merged 4 commits into
feat/plugin-registry-labelling-servicefrom
feat/labeler-stage-wiring
Jul 17, 2026
Merged

ascorbic merged 4 commits into
feat/plugin-registry-labelling-servicefrom
feat/labeler-stage-wiring

Conversation

@ascorbic

@ascorbic ascorbic commented Jul 17, 2026 •

Copy link
Copy Markdown
Member

What does this PR do?

Slice A of the production-stage wiring for the labeler's assessment pipeline (RFC #694, umbrella #1909). Targets the feat/plugin-registry-labelling-service integration branch.

The orchestrator has run deploy-gated stub stages since #1978. This slice adapts the two built analysis modules whose inputs already exist — the code-AI adapter and the publisher-history context — to the orchestrator's StageAdapter contract, and removes the two stages that a ratified scope decision made permanently dead. The production deploy gate does not lift here: scoping found the acquire stage has no production consumer (its release-resolution and SSRF-hardened egress don't exist yet), so a production build still refuses to run — the gate lifts only in the follow-up "acquire consumer" slice when the pipeline can genuinely run end-to-end. buildStages/executeAssessmentInstance are byte-untouched.

  • assessment-stages.ts (new): createCodeAiStage — reads the acquired bundle's decoded files + a capabilities-only declared surface (matching the calibration input shape; allowedHosts are runtime-enforced, not a moderation signal) and runs analyzeCode; a ModelTransientError becomes a StageTransientError so a flaky model call retries and can never finalize a spurious pass. createHistoryStage — thin over the best-effort analyzeHistory. Plus the per-run CoverageAccumulator and its serializer.
  • Dead stages removed: deterministic and dependency come out of the stage set (ratified 2026-07-17: plugins are dependency-free and the workerd sandbox enforces declared access at runtime, so scanner/capability stages have no work; integrity findings stay in the acquire stage).
  • Coverage seam: an optional resolveCoverageJson thunk stamps analysis coverage into coverage_json atomically with the finalization CAS (existing COALESCE path). Production is unchanged this slice.
  • Comment fix: the stale orchestrator comment claiming the finalization label-leak window still needed a guard is rewritten — the requireAssessmentState gate from feat(labeler): production Workflow shell over AssessmentOrchestrator (#1978) #2072 already closes it. Comment-only; no behavior change.

An adversarial review pass ran before this PR: no HIGH/blocking findings; the gate was verified byte-identical, droppedFiles paths were verified unable to reach the public assessment view, and the transient-never-passes invariant is locked by a test. Two accepted items are documented for the acquire-consumer slice in the plan (threading the release record's description — the bundle manifest has none, so misleading-metadata/privacy-risk run near-inert until then, flagged as a calibration-input divergence; and the coverage-on-error semantics call).

Part of #1909. Related to #694.

Type of change

  • Bug fix
  • Feature (requires maintainer-approved Discussion)
  • Refactor (no behavior change)
  • Translation
  • Documentation
  • Performance improvement
  • Tests
  • Chore (dependencies, CI, tooling)

Checklist

  • I have read CONTRIBUTING.md
  • pnpm typecheck passes (all three labeler projects)
  • pnpm lint passes (0 new diagnostics; repo baseline unchanged)
  • pnpm test passes (7 new stage-wiring integration tests over fake AI/aggregator + real bundle fixtures; 22 migrated orchestrator tests; full labeler suite 788/788)
  • pnpm format has been run
  • I have added/updated tests for my changes (if applicable)
  • User-visible strings in the admin UI are wrapped for translation (if applicable) — n/a: server-only.
  • I have added a changeset (if this PR changes a published package) — n/a: @emdash-cms/labeler is private: true; the new @emdash-cms/plugin-types dependency is workspace:* on an app, no published-package change.
  • New features link to an approved Discussion — the umbrella Plugin registry labelling service #1909 tracks RFC RFC: Decentralized Plugin Registry #694; this is one slice under it.

AI-generated code disclosure

  • This PR includes AI-generated code — model/tool: Claude Opus 4.8 (implementation + adversarial review), orchestrated by Claude Fable 5

Screenshots / test output

assessment-stages.test.ts:      7 passed
assessment-orchestrator.test.ts: 22 passed
full labeler suite:             788 passed

Key cases: fake-AI malware finding → blocked with the label issued and no assessment-passed; clean response → passed with coverage.code: "complete"; persistent model failure → transient retries exhaust and finalize error, not a spurious pass; over-budget bundle → partial coverage with the dropped file recorded; checksum-mismatch acquire → AI never invoked, blocked on artifact-integrity-failure; history-stage DB failure → run still finalizes normally.


Try this PR

Open a fresh playground →

A full working EmDash site, deployed from this branch. Each visit gets its own session-scoped sandbox: no login needed and no shared state. Try the admin, edit content, hit the public site.

Tracks feat/labeler-stage-wiring. Updated automatically when the playground redeploys.

…(slice A)

Adapts the built analyzeCode/analyzeHistory analysis modules to the
orchestrator's StageAdapter contract, following the createAcquireStage
closure idiom. Pure additions this slice: buildStages, the production
deploy gate, and executeAssessmentInstance are untouched — the gate stays
down until the acquire consumer (release resolution + SSRF-hardened
egress + image-metadata extraction) lands and the pipeline can genuinely
run end-to-end.

- assessment-stages.ts: createCodeAiStage (decoded bundle files +
  capabilities-only declared surface matching the calibration input shape;
  ModelTransientError converted to StageTransientError so a flaky model
  retries and can never finalize a spurious pass) and createHistoryStage
  (thin over the best-effort analyzeHistory), plus the per-run
  CoverageAccumulator and serializeCoverage.
- assessment-orchestrator.ts: the deterministic and dependency stages are
  removed (ratified cut: plugins are dependency-free and the sandbox
  enforces declared access, so those stages have no work); a
  resolveCoverageJson seam stamps coverage atomically with the
  finalization CAS; the stale label-leak comment now reflects the
  requireAssessmentState gate that already closes the window (#2072).
- tests: full runAssessment integration over a fake AiBinding/aggregator
  and real bundle fixtures — block/warn/clean outcomes, transient
  exhaustion finalizing error not passed, partial coverage propagation,
  acquire-failure short-circuit, and history best-effort.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@changeset-bot

changeset-bot Bot commented Jul 17, 2026 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: dbe8847

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jul 17, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
emdash-demo-cache dbe8847 Jul 17 2026, 12:19 PM

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jul 17, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
emdash-demo-do dbe8847 Jul 17 2026, 12:20 PM

@github-actions

Copy link
Copy Markdown
Contributor

Scope check

This PR changes 660 lines across 6 files. Large PRs are harder to review and more likely to be closed without review.

If this scope is intentional, no action needed. A maintainer will review it. If not, please consider splitting this into smaller PRs.

See CONTRIBUTING.md for contribution guidelines.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jul 17, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
emdash-playground dbe8847 Jul 17 2026, 12:20 PM

@github-actions github-actions Bot added review/needs-review No maintainer or bot review yet cla: signed labels Jul 17, 2026

@emdashbot emdashbot Bot 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.

This slice is the right change at the right time. It adapts the two analysis modules whose inputs already exist (code-AI and publisher-history) to the orchestrator’s StageAdapter contract, removes the stages ratified as dead, and keeps the production deploy gate closed — all consistent with the umbrella (#1909 / RFC #694) integration plan. The wiring follows the same per-run closure idiom as createAcquireStage, the transient-error mapping preserves the important “flaky model calls can never finalize a spurious pass” invariant, and the coverage seam is stamped atomically via the existing finalization CAS + COALESCE path.

I read the full diff, the changed source files, the related adapter/store/service modules, and searched the labeler tree for leftover references to the removed stages. I did not run the test suite/linter/builds (no shell); the author reports 788/788 with 7 new stage-wiring tests, and the new tests statically cover block, pass, warn, transient-exhaustion, partial coverage, acquire-with-no-bundle, and best-effort history. No SQL-injection vectors, authorization holes, content-table locale bugs, or published-package changesets are introduced. @emdash-cms/plugin-types is newly consumed but not modified, and @emdash-cms/labeler is private, so the author’s “no changeset” rationale holds.

Only one non-blocking item: the module-level docblock in assessment-orchestrator.ts still lists the removed deterministic/dependency stages as future work. It should be updated to match the new OrchestratorStages shape so the next slice’s implementer isn’t misled.


Findings

  • [suggestion] apps/labeler/src/assessment-orchestrator.ts:10-12

    The module-level docblock still describes the future stage set as including deterministic validation and dependency/SBOM, but this PR removes both deterministic and dependency from OrchestratorStages and STAGE_ORDER. That drift is harmless to runtime behavior but will mislead whoever wires the acquire-consumer slice next.

    	 *		orchestrator per run and calls `runAssessment`. Until W7/W8 supply the real stage adapters
    	 *		(acquire, code/metadata AI, image AI), that wiring runs `stubStages` — every stage resolves with no findings, so
    

@github-actions github-actions Bot added review/awaiting-author Reviewed; waiting on the author to respond and removed review/needs-review No maintainer or bot review yet labels Jul 17, 2026
The module comment still listed the removed deterministic/dependency stages
as pending real adapters. Addresses the emdashbot review suggestion on #2090.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@ascorbic

Copy link
Copy Markdown
Member Author

Docblock aligned (commit 1e1a118) — the orchestrator's module comment now describes the reduced stage set (acquire, code/metadata AI, image AI, history) and points the stub note at the acquire-consumer slice rather than the removed deterministic/dependency stages.

~ 🤖 Claude Fable 5

@ascorbic ascorbic added the bot:review Trigger an emdashbot code review on this PR label Jul 17, 2026
@github-actions github-actions Bot added review/needs-rereview New commits since the last review and removed review/awaiting-author Reviewed; waiting on the author to respond labels Jul 17, 2026

@emdashbot emdashbot Bot 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.

Re-review: the prior stale-docblock finding is fixed, and the slice remains the right change at the right time.

This PR adapts the two analysis modules whose inputs already exist — the code-AI adapter and publisher-history context — to the orchestrator’s StageAdapter contract, removes the deterministic and dependency stages ratified as dead, and leaves the production deploy gate down. That matches the umbrella (#1909 / RFC #694) plan and the integration-branch target. The wiring follows the same per-run closure idiom as createAcquireStage, ModelTransientError is correctly promoted to StageTransientError so flaky model calls can never finalize a spurious pass, and the coverage seam is written atomically through the existing finalization CAS + COALESCE path.

What I checked

  • Read the full diff and the head versions of the changed files (assessment-orchestrator.ts, assessment-stages.ts, the migrated orchestrator tests, and the new stage-wiring tests).
  • Traced the new stage factories through code-ai-adapter.ts, history-context.ts, artifact-acquisition.ts, assessment-store.ts, and public-assessment.ts.
  • Searched the labeler tree for leftover references to deterministic/dependency stages.
  • Verified the prior finding in the assessment-orchestrator.ts module docblock was updated.

The code is otherwise clean: no SQL-injection vectors, no authorization holes, no content-table locale bugs, and no published-package changeset is required (@emdash-cms/labeler is private; the new @emdash-cms/plugin-types dependency is only consumed, not modified).

Only two small pieces of prose drift remain — one in a file this PR intentionally left byte-untouched, and one in a migrated test block. Both are comment/test-label cleanups, not runtime issues.


Findings

  • [suggestion] apps/labeler/src/assessment-workflow.ts:117-118

    The buildStages docblock still describes the future real adapters as including deterministic/dependency/AI scanning, but this PR removes deterministic and dependency from OrchestratorStages and STAGE_ORDER. Since the acquire-consumer slice will wire acquire, codeAi, imageAi, and history here, the comment should match the new stage set so the next implementer doesn’t resurrect dead stages.

     * adapters attach here in the acquire-consumer follow-on — acquire (via the aggregator
     * client), code/metadata AI, image AI, and publisher history; today
    
  • [suggestion] apps/labeler/test/assessment-orchestrator.test.ts:456

    This describe block was migrated from the old deterministic stage to codeAi, but the label still says "permanent deterministic failure". The stage that now emits the permanent artifact-integrity-failure finding is the acquire stage; this test injects it through codeAi purely as a harness. Renaming the block removes the stale stage name and avoids confusion.

    describe("AssessmentOrchestrator: permanent blocking finding", () => {
    

@emdashbot emdashbot Bot removed the bot:review Trigger an emdashbot code review on this PR label Jul 17, 2026
@github-actions github-actions Bot added review/awaiting-author Reviewed; waiting on the author to respond and removed review/needs-rereview New commits since the last review labels Jul 17, 2026
…label

Addresses the two prose-drift suggestions in the emdashbot re-review of #2090:
the buildStages docblock and a migrated test describe block still named the
removed deterministic/dependency stages.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@ascorbic

Copy link
Copy Markdown
Member Author

Both prose-drift suggestions applied (commit 90c3d73): the buildStages docblock now names the real stage set (acquire, code/metadata AI, image AI, history) pointing at the acquire-consumer follow-on, and the migrated test describe block is renamed to "permanent blocking finding" (the acquire stage owns the integrity finding; the test injects it through codeAi as a harness).

~ 🤖 Claude Fable 5

@ascorbic ascorbic added the bot:review Trigger an emdashbot code review on this PR label Jul 17, 2026
@github-actions github-actions Bot added review/needs-rereview New commits since the last review and removed review/awaiting-author Reviewed; waiting on the author to respond labels Jul 17, 2026

@emdashbot emdashbot Bot 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.

Re-review: prior suggestions are fixed; one stale plan-code drift remains

Approach judgment — The slice is still the right change at the right time. Adapting the existing code-AI adapter and publisher-history module to the orchestrator's StageAdapter contract, removing the ratified-dead deterministic and dependency stages, adding the CoverageAccumulator seam, and leaving the production deploy gate down matches the umbrella plan (#1909 / RFC #694) and the integration branch target. The wiring preserves the pure analysis modules, the per-run closure idiom, and the transient-never-passes invariant.

What I checked

  • Read the updated diff and the head versions of assessment-stages.ts, assessment-orchestrator.ts, assessment-workflow.ts, the migrated orchestrator tests, and the new stage-wiring tests.
  • Verified the two previous emdashbot[bot] findings are resolved:
    • assessment-workflow.ts:117-118 buildStages docblock now lists acquire, code/metadata AI, image AI, and publisher history with no dead stages.
    • assessment-orchestrator.test.ts:456 describe block is renamed to AssessmentOrchestrator: permanent blocking finding.
  • Searched the labeler tree for leftover deterministic/dependency stage references — none found.
  • Traced the coverage seam through serializeCoverage, buildFinalizationStatements (COALESCE path), and public-assessment.ts to confirm droppedFiles does not leak to the public view and that no coverage is written on the stale/cancel paths.
  • Confirmed @emdash-cms/plugin-types is a workspace dependency on the private labeler app, so no changeset is required.

Headline conclusion

The code is otherwise clean: no logic bugs, no authorization or SQL-injection issues, no content-table locale concerns, and the transient-error classification is correct. One piece of prose drift remains in assessment-workflow.ts: the DEPLOY GATE comment and the production deploy-gate error message still reference the old W7/W8 plan codes, even though the rest of the slice now calls the remaining work the acquire-consumer slice. Since the file is already edited for this re-review, updating those two references would make the guard comment and the runtime error message consistent with the current plan.


Findings

  • [suggestion] apps/labeler/src/assessment-workflow.ts:12

    The DEPLOY GATE comment still references the old W7/W8 plan codes. The rest of this PR now scopes the remaining gate-lifting work as the acquire-consumer slice, and the buildStages docblock below has already been updated to that terminology. Keeping W7/W8 here makes the guard comment inconsistent and harder to map to the current plan for the next implementer.

     * stages (acquire-consumer slice) land; shipping it live before then would vouch for everything.
    
  • [suggestion] apps/labeler/src/assessment-workflow.ts:132

    The production deploy-gate error message still tells the operator to "Wire the real analysis stages (W7/W8) before deploying." W7/W8 is no longer the active plan name; this slice scopes the remaining work as the acquire-consumer slice. The runtime error should use the current term so it stays actionable when that slice eventually removes the gate.

    			"AssessmentWorkflow has only stub stages in a production build — refusing to issue assessment-passed for unscanned subjects. Wire the real stage adapters (acquire-consumer slice) before deploying.",
    

@emdashbot emdashbot Bot removed the bot:review Trigger an emdashbot code review on this PR label Jul 17, 2026
@github-actions github-actions Bot added the review/awaiting-author Reviewed; waiting on the author to respond label Jul 17, 2026
@github-actions github-actions Bot removed the review/needs-rereview New commits since the last review label Jul 17, 2026
…-consumer slice

Last prose-drift item from the emdashbot re-review of #2090: the DEPLOY GATE
comment and the production-gate error message still cited the W7/W8 plan codes.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@ascorbic

Copy link
Copy Markdown
Member Author

Last prose-drift item applied (commit dbe8847): the DEPLOY GATE docblock and the production-gate error message now name "the acquire-consumer slice" instead of the W7/W8 plan codes, consistent with the rest of the slice.

~ 🤖 Claude Fable 5

@ascorbic ascorbic added the bot:review Trigger an emdashbot code review on this PR label Jul 17, 2026
@github-actions github-actions Bot added review/needs-rereview New commits since the last review and removed review/awaiting-author Reviewed; waiting on the author to respond labels Jul 17, 2026

@emdashbot emdashbot Bot 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.

Approach judgment — This slice is the right change at the right time. It adapts the existing code-AI adapter and publisher-history analysis modules to the orchestrator's StageAdapter contract, removes the ratified-dead deterministic and dependency stages, adds a bounded CoverageAccumulator seam, and keeps the production deploy gate firmly down. That matches the umbrella plan (#1909 / RFC #694) and the integration branch target.

Re-review status — The two prior emdashbot[bot] findings are resolved:

  • apps/labeler/src/assessment-workflow.ts no longer mentions W7/W8; the DEPLOY GATE comment and the production build error message now use the current acquire-consumer slice terminology.
  • apps/labeler/test/assessment-orchestrator.test.ts describe block is renamed to AssessmentOrchestrator: permanent blocking finding.

What I checked

  • Read the updated diff and the head versions of assessment-stages.ts, assessment-orchestrator.ts, assessment-workflow.ts, code-ai-adapter.ts, history-context.ts, the migrated orchestrator tests, and the new stage-wiring tests.
  • Verified the stage set in assessment-orchestrator.ts is just acquire → codeAi → imageAi → history, with no leftover deterministic/dependency stage references in the orchestrator or workflow.
  • Traced the coverage seam through serializeCoverage, buildFinalizationStatements (COALESCE path), and public-assessment.ts: droppedFiles is stored in the row but is dropped by the public serializer, so it never reaches the public assessment view.
  • Confirmed transient model failures become StageTransientError and cannot finalize as passed; persistent model failures finalize as error (verified by tests).
  • Confirmed @emdash-cms/plugin-types is a workspace-only dependency on the private labeler app, so no changeset is required for a published package.
  • Checked AGENTS.md conventions: no admin UI strings (server-only), no new content-table queries, no SQL interpolation, no authorization changes, no index/schema changes.

Headline conclusion

The code is clean. I found no logic bugs, no security or authorization regressions, no SQL-injection risk, no content-table locale concerns, and no remaining AGENTS.md violations. The prior prose drift is fixed, the gate remains intact, and the transient-never-passes invariant is preserved.

@emdashbot emdashbot Bot removed the bot:review Trigger an emdashbot code review on this PR label Jul 17, 2026
@github-actions github-actions Bot added review/approved Approved; no new commits since and removed review/needs-rereview New commits since the last review labels Jul 17, 2026
@ascorbic
ascorbic merged commit 5d8f775 into feat/plugin-registry-labelling-service Jul 17, 2026
11 checks passed
@ascorbic
ascorbic deleted the feat/labeler-stage-wiring branch July 17, 2026 12:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla: signed review/approved Approved; no new commits since size/XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant