# S4 — CandidateImpact & Assurance Recompilation

## Checkpoint and prerequisite audit

- Repository: `/home/james/Desarrollo/agentic-engineering-harness`
- Branch: `core-architecture-v2`
- Expected and observed HEAD: `7eb8a08a0f7d3db0220526981d37ef1d9ca986c0`
- Origin: `origin/core-architecture-v2` at the same HEAD
- Initial working tree: clean
- Recent history: accepted S5 checkpoint at HEAD; accepted S3 checkpoint at `92abcbe`; S2 semantic runtime evidence recorded in Status and Conformance.
- Normative source read: `docs/CORE_ARCHITECTURE_V2.md`, including §§1.2, 2, 3, 6–10, 12; current-state sources read: `docs/CORE_ARCHITECTURE_V2_STATUS.md`, `docs/CORE_ARCHITECTURE_V2_CONFORMANCE.md`.

The Status records the semantic decision runtime as `IMPLEMENTED` (S2), the authority kernel as `IMPLEMENTED` (S3), context/session and Paseo identity as `DETERMINISTICALLY_VERIFIED` (S5), and candidate truth as `DETERMINISTICALLY_CERTIFIED`. The approved S4 prerequisites are therefore present at this checkpoint. Deterministic test evidence does not establish provider certification.

## Current affected-row assessment before S4

Fields below reproduce the relevant Status row values so the S4 delta can be reviewed without changing the normative target.

| Row | CURRENT | GAP | NEXT GATE | EVIDENCE | EVIDENCE LANE | LAST VERIFIED |
| --- | --- | --- | --- | --- | --- | --- |
| Candidate truth and assembly | Assembly, wave lineage, repair, and workspace identity checks are wired. S1 candidate assembly invalidates bindings and structured results for the previous candidate. | Downstream impact and assurance consumers remain open. | Keep deterministic certification scoped to candidate truth; every accepted mutation remains a ChangeSet. | `src/candidates/`; `src/operations/state.ts`; `tests/candidateIdentity.test.ts`, `tests/candidateWaveLineage.test.ts`, `tests/candidateRepairProtection.test.ts`, `tests/operations.test.ts`, `tests/structuredResultGateway.test.ts`. | CONTRACT; UNIT | 2026-09-24 S1 remediation deterministic verification |
| WorkGraph, scheduling, and resource claims | WorkGraph, claims, topological waves, parallelism, and scope checks remain deterministic. Typed semantic ROUTE and issue-route decisions feed contract routing and therefore the bounded Planner/WorkGraph path; stack profile is supplied to ParticipantPlan compilation and validation resolution. | Full operation-policy and assurance integration remains beyond S2; S4 impact-driven assurance recompilation remains future scope. | Prove every executable wave has validated claims and current candidate bases; S4 owns impact-driven assurance recompilation. | `src/architecture/workGraph.ts`, `src/agents/parallelism.ts`, `src/agents/waveExecutor.ts`, `src/core/triage.ts`, `src/issues/intake.ts`; `tests/architectureWorkGraph.test.ts`, `tests/parallelism.test.ts`, `tests/triage.test.ts`. | CONTRACT; UNIT; INTEGRATION | 2026-09-24 S2 deterministic verification |
| CandidateImpact | Every production CandidateAssembler path in runTask, wave integration, and repair receives the semantic runtime, assesses bounded post-assembly file/patch receipts bound to the new CandidateRevision, validates paths/provenance/policy/digests, and reverses an unbound patch on invalid assessment. Unbound precomputed impact inputs are removed; without the runtime the projection is BLOCKED and retains independent review. The projected impact preserves unknowns and semantic assessment digest. | S4 downstream assurance/reviewer/validation/acceptance recompilation is explicitly future scope; deterministic tests do not certify provider interpretation. | S4 consumes impact later; S2 does not recompile downstream assurance. | `src/candidates/assembler.ts`, `src/candidates/wave.ts`, `src/candidates/repair.ts`, `src/core/run.ts`; `tests/candidateAssembler.test.ts`, `tests/candidateWaveLineage.test.ts`, `tests/runRepairCandidateLifecycle.test.ts`, `tests/candidateRepairProtection.test.ts`, `tests/semanticAssessment.test.ts`. | CONTRACT; UNIT; REAL_PROVIDER pending | 2026-09-24 S2 deterministic verification |
| Review and assurance recompilation | Review lifecycle, independent participants, repair, and convergence exist; impact flags are not consumed to compile required reviewers/dimensions. | Review requirements are not recompiled from actual impact. | A required impact dimension blocks progression without independent evidence. | `src/agents/reviewLifecycle.ts`; `tests/reviewLifecycle.test.ts`, `tests/reviewRepairCandidateLifecycle.test.ts`. | UNIT; INTEGRATION | 2026-09-23 audit snapshot; not rerun |
| Validation | Stack semantic profile is passed into project-script resolution; deterministic validator/provider matching and current-candidate evidence checks remain. VALIDATION_NEED is supported by SemanticAssessmentV1 but is not wired to an unrelated validation redesign because no additional S2 caller is required. | Provider mapping/coverage, assurance recompilation, and managed acceptance remain outside S2. | Prove required resolutions run or block, separately from acceptance; later validation redesign remains future scope. | `src/core/verify.ts`, `src/architecture/validationRequirements.ts`, `src/agents/waveExecutor.ts`, `src/participants/stack.ts`; `tests/validationProviders.test.ts`, `tests/participantsStackDiscovery.test.ts`. | CONTRACT; UNIT; INTEGRATION; REAL_PROVIDER and BROWSER pending where required | 2026-09-24 S2 deterministic verification |
| Repair, recovery, and convergence | Production runTask preserves mechanically certain failure facts as DETERMINISTIC and sends ambiguous bounded failure evidence to the candidate-bound Semantic Assessor. Failure unknowns/provenance are retained in the recovery decision/event. Repair candidate assembly receives the same candidate-impact semantic path and fails closed with rollback on invalid assessment. | Full recovery/quality state integration, S4 impact-driven assurance recompilation, and later convergence/runtime concerns remain future dependencies. | Keep retries, budgets, and transitions deterministic; S4 consumes impact without entering this slice. | `src/agents/recovery.ts`, `src/core/run.ts`, `src/candidates/repair.ts`, `src/semantic/assessment.ts`; `tests/recovery.test.ts`, `tests/candidateRepairProtection.test.ts`, `tests/candidateAssembler.test.ts`. | CONTRACT; UNIT; INTEGRATION; REAL_PROVIDER pending | 2026-09-24 S2 deterministic verification |
| AcceptanceOracle | Quality gate and synchronous Lead acceptance exist; managed Lead acceptance is deferred; no complete production oracle path exists. | Managed operation lacks candidate-bound acceptance before delivery. | Persist AcceptanceOracle disposition; validation PASS alone cannot accept. | `src/agents/reviewLifecycle.ts`, `src/certification/`; `tests/reviewLifecycle.test.ts`, `tests/certification.test.ts`. | UNIT; PACKED_E2E and REAL_PROVIDER acceptance journeys pending | 2026-09-23 audit snapshot; not rerun |
| Browser and visual validation | External validator adapter exists; requirement mapping exists, but no browser provider/candidate journey certification. | Browser evidence and Control Center journeys are not produced end-to-end. | Run required browser assertions and persist candidate-bound trace/screenshot. | `src/validators/external.ts`, `toolEvidence.ts`; provider contract tests. | CONTRACT; BROWSER pending; PACKED_E2E pending | 2026-09-23 audit snapshot; not rerun |
| Real-provider certification matrix | CertificationCore, 22-capability matrix, packed bootstrap, and Codex adapter exist; provider matrix/journeys are incomplete. | No full real-provider/Paseo/Podman/browser campaign. | Certify each claimed provider with receipts and independent oracle. | `src/certification/`; `tests/certification.test.ts`, `certificationMatrix.test.ts`. | CONTRACT; UNIT; REAL_PROVIDER pending; PACKED_E2E incomplete | 2026-09-23 audit snapshot; not rerun |

Conformance currently says CandidateImpact does not recompile reviewer, validation, and acceptance requirements; `requiresIndependentReview` is evidence rather than proof of assignment. Validation, review, and acceptance are separate gates. The full production `AcceptanceAssertion → OracleResolver → EvidenceBundle → AcceptanceOracle` chain remains S6 scope. S4 will compile candidate-bound assertions and evidence requirements but will not implement that S6 chain.

## Tactical WorkGraph — frozen before implementation

| ID | Work unit | Ownership class | Mechanism | Depends on | Frozen output / acceptance |
| --- | --- | --- | --- | --- | --- |
| S4-W0 | Freeze CandidateAssuranceCompilationV1 input/output and deterministic floor/assignment rules; author acceptance tests first. | LUNA_OWNED | DETERMINISTIC | Accepted candidate, policy, semantic, and session contracts | Candidate, impact, policy, reviewer pool, validation needs, acceptance assertions, assurance floor, evidence strength, and blocker behavior have explicit typed contract and negative tests before implementation. |
| S4-W1 | Implement the pure candidate-assurance compiler against the frozen contract. | FLASH_DELEGATABLE | HYBRID | S4-W0 | New compiler module only; deterministic checks and compilation over the already evidence-bound MODEL CandidateImpact; worker cannot change caller lifecycle or authority. |
| S4-W2 | Bind each post-assembly impact and compilation to exact CandidateRevision/policy and carry it through direct, wave, and repair candidate paths. | LUNA_OWNED | HYBRID | S4-W0, S4-W1 | Missing/invalid/stale impact fails closed and cannot lower policy floors; durable candidate assembly evidence includes the compile identity. |
| S4-W3 | Consume the compilation in validation and review; create actual read-only Reviewer assignments covering required dimensions; make unresolved high-risk impact block acceptance progression. | LUNA_OWNED | HYBRID | S4-W2 | Required validation resolutions run or block; reviewer selections are configured identities independent of Implementer; each required dimension has independent evidence; no model output selects identities or grants authority. |
| S4-W4 | Add candidate-bound acceptance assertions/evidence strength to the compilation record without implementing the S6 oracle chain; reconcile Status, Conformance, and Ledger. | LUNA_OWNED | HYBRID | S4-W2, S4-W3 | S4 gate evidence is durable and current-candidate bound; all affected row fields and pending evidence lanes are accurate. |
| S4-W5 | Luna runs regression-first focused tests, supported TypeScript check/build, affected and full non-system Vitest, applicable deterministic system suites, and final diff review. | SEQUENTIAL_AFTER_CONTRACT_FREEZE | DETERMINISTIC | S4-W1–W4 | Exact commands/counts and source review recorded; no real-provider or packed certification inferred from fixtures. |

## Delegation Assessment — S4 only

The pure compiler (S4-W1) is a meaningful, safely separable implementation unit after S4-W0 freezes its input/output and acceptance tests. It has no authority to mutate candidate truth, choose concrete reviewers, execute validation, change operation policy, accept a candidate, or implement lifecycle wiring. It worked in a separate Paseo worktree without overlap with Luna-owned integration files. The assigned worker prompt included OBJECTIVE, EXACT SCOPE, FILES/AREAS, DEPENDENCIES, INVARIANTS, ACCEPTANCE CRITERIA, TESTS, EXPLICIT EXCLUSIONS, and NO NESTED DELEGATION. Luna owns contract freeze, tests, integration, policy interpretation, documentation, validation, review, and final gate. No nested delegation was enabled or used.

Delegated agent `b6f54a20-9bd9-45bd-ae6b-fea824586940` used the configured profile **DeepSeek V4.1 Flash Implementer** with provider `opencode`, model `opencode-go/deepseek-v4.1-flash`, mode `build`, thinking `max`, and feature values `{ "auto_accept": true }`; the created-agent provider was `opencode/opencode-go/deepseek-v4.1-flash`. Its separate workspace was `/home/james/.paseo/worktrees/0jx5pvzi/s4-candidate-assurance-flash`, workspace id `wks_8033b61572f7d0a0`, branch `s4-candidate-assurance-flash`. The worker added the pure compiler and its focused tests; Luna reviewed and integrated the compiler, then owned all cross-file lifecycle changes. No worker commit or push was made.

## Frozen local contract and acceptance boundary

The candidate assurance compiler is a pure deterministic function over:

- the exact assembled `CandidateRevisionV1`;
- the `CandidateImpactV1` projected from bounded MODEL assessment plus deterministic assembly facts, including candidate identity;
- the frozen policy digest, minimum assurance, independent-review floor, validation restrictions, and required evidence strength;
- the preselected configured Reviewer candidates (identity, canonical role, provider, and read-only status), plus the Implementer identity;
- existing typed validation and acceptance requirements.

The frozen API is `candidateImpactValidationRequirementsV1(impact)` followed by `compileCandidateAssuranceV1(input)`. `CandidateImpactV1` carries `candidate: { candidateId, revision, identityDigest }`; the compiler rejects any mismatch with the supplied `CandidateRevisionV1` and verifies the impact digest. `CandidateAssurancePolicyV1` carries the frozen policy digest, `minimumAssurance`, `independentReviewRequired`, `minimumIndependentReviewers`, `providerDiversity`, `allowedValidationKinds`, and `evidenceStrength`. Reviewer candidates carry configured `identity`, canonical `role`, `provider`, and `readOnly`; the compiler also receives the Implementer identity, task risk, typed base validation requirements, a resolver result covering the combined requirements, and base `{ id, statement, requirementRefs }` acceptance assertions.

The versioned output binds candidate ID/revision/digest, impact digest, and policy digest; contains `minimumAssurance`, `reviewAssignments`, merged `validationRequirements`, `acceptanceAssertions`, `evidenceStrength`, `blockers`, `status`, and a canonical `digest`. Each review assignment contains `reviewerIdentity`, `provider`, `dimensions`, and exact candidate/impact/policy bindings. Each generated `AcceptanceAssertionV1` contains `version`, stable `id`, `statement`, `requirementRefs`, exact candidate/impact/policy bindings, `dimensions`, and `evidenceStrength`. The evidence-strength object contains `minimumAssurance`, `minimumIndependentReviewers`, `providerDiversity`, and sorted `requiredDimensions`. Assignments are chosen only from the configured Reviewer candidate pool; the Impact model never chooses identities. Dimension-to-validation policy is deterministic and versioned; disallowed, unresolved, or unresolvable required validation blocks rather than silently skipping. The default dimension assurance floors are STANDARD for `behavior.correctness`, ELEVATED for `public API`, `UI/browser`, `architecture`, and `operations`, and CRITICAL for `security`, `authentication/authorization`, `migration/schema`, `dependency/supply chain`, and `concurrency`; unrecognized dimensions conservatively floor to ELEVATED. Policy minimums can only raise these floors. High-risk task impact that is BLOCKED or retains unresolved unknowns blocks acceptance progression. The compiler may not select an agent outside the supplied configured pool, grant capability, alter frozen policy, or turn unresolved impact into acceptance.

Acceptance tests must cover: candidate/impact mismatch rejection; policy floor never lowered; semantic impact only strengthening; actual reviewer identity assignment per required dimension; exclusion of Implementer and writable/non-Reviewer candidates; missing Reviewer blocking; validation requirement retention/addition and missing resolver blocking; acceptance assertion and evidence-strength binding; missing/invalid impact preserving floors; unresolved high-risk impact blocking progression; stable digest; and no changes to the normative target or S6 oracle scope.

## Decision mechanism classification

Candidate file inventory, patch paths/digests, candidate/policy identity, minimum comparisons, reviewer role/identity/read-only checks, requirement resolution, evidence freshness, and blockers are DETERMINISTIC. CandidateImpact interpretation over bounded post-assembly receipts is MODEL via the accepted S2 SemanticAssessmentService. Recompilation is HYBRID: MODEL dimensions/unknowns are accepted only after S2 evidence and binding checks, then deterministic policy, assignment, validation, acceptance-assertion, and evidence-floor rules constrain them.

## Implementation and verification record

S4-W0 through S4-W5 completed in this checkout. `CandidateImpactV1` now binds the exact assembled candidate, its base candidate, and the ChangeSet patch digest. `candidateAssurance.ts` verifies impact/resolver integrity and deterministically compiles the non-weakened policy floor, impact requirements, configured read-only Reviewer assignments, candidate-bound assertions, evidence strength, and blockers. `runTask` consumes only the current candidate's impact from direct assembly, the final wave, or Repairer assembly; it rebinds the unchanged frozen policy semantics to the current candidate, resolves and executes impact validations, persists `harness.candidate.assurance-recompiled`, and fails the report gate closed. Review lifecycle invokes the compiled identities and recompiles after quality repair or rollback. Unknown specialized provider actions fail closed unless a matching adapter or explicit command exists. The normative target was not changed.

The deterministic gate evidence is:

| S4 gate statement | Evidence |
| --- | --- |
| Impact cannot weaken policy minimums. | Compiler uses the maximum of frozen minimum/evidence floors and deterministic dimension floors; tests cover a CRITICAL policy floor and impact-derived CRITICAL floors. Compilation verifies candidate/impact/policy digests. |
| Required dimensions create required independent evidence. | Compiler requires an eligible configured read-only Reviewer, excludes Implementer identity, compiles each dimension into assignments, and emits candidate/impact/policy-bound Reviewer-session checks. `runRepairCandidateLifecycle.test.ts` exercises an actual configured Reviewer invocation against the new candidate. |
| Missing or unresolved high-risk impact blocks acceptance progression. | Missing/invalid/stale/tampered impact and high-risk BLOCKED/unknown impact fail the assurance report gate; tests cover high-risk unknowns, invalid digest, stale binding, missing resolver action, and disallowed validation kind. The complete S6 AcceptanceOracle is intentionally not implemented here. |

Validation executed after the provider-dispatch hardening:

- `npx vitest run tests/candidateAssurance.test.ts tests/candidateAssembler.test.ts tests/reviewLifecycle.test.ts tests/reviewRepairCandidateLifecycle.test.ts tests/runRepairCandidateLifecycle.test.ts tests/candidateRepairProtection.test.ts tests/candidateWaveLineage.test.ts` — exit 0, 7 files / 41 tests passed (rerun 2026-09-24).
- `npm run typecheck` — exit 0.
- `npm run build` — exit 0; release `release-1790299120251-2597132-058f35f2` (rerun 2026-09-24).
- `npx vitest run --exclude 'tests/system/**'` — exit 0, 153 files passed / 1 skipped; 848 tests passed / 7 skipped.
- `git diff --check` — clean.
- `rg -n -i 'candidate.?impact|assurance|runTask|candidate\.assembled' tests/system` — exit 1 (no matching system suite); the S4 lifecycle is exercised by the deterministic public `runTask` integration test, so no S4-specific system suite was applicable.

No REAL_PROVIDER, BROWSER, OPA_PROVIDER, ADVERSARIAL, or PACKED_E2E claim is made from these deterministic fixtures. CandidateImpact interpretation/session behavior and actual external validators remain separate lanes. S6 still owns the complete `AcceptanceAssertion → OracleResolver → EvidenceBundle → AcceptanceOracle` chain and managed acceptance ordering.
