# Core Architecture v2 S2 WorkGraph and Delegation Assessment

## Slice boundary and pre-edit findings

- **Slice:** S2 — Production Semantic Decision Runtime. No later slice is started.
- **Objective and gate:** as listed in `CORE_ARCHITECTURE_V2_STATUS.md`: wire bounded semantic assessment into public intent, route, stack, issue, failure, and impact paths; each path declares `DETERMINISTIC`, `MODEL`, or `HYBRID`, preserves unknowns and provenance, and cannot grant authority or bypass policy.
- **Approved composition:** Semantic Assessor is an AEH-managed agent resolved from `AgentTopology` plus deterministic semantic capability policy and run through Paseo. Raw provider invocation and inference SDKs are prohibited.
- **Checkout preflight:** branch `core-architecture-v2`, HEAD `f186468dfcd7b905fdb4aa10bd3b965084f405cc`; campaign checkout was clean. S1 execution identity, operation-state mutation guards, and binding checks were inspected in `src/architecture/executionIdentity.ts`, `src/operations/state.ts`, and their focused tests before edits.
- **Prior isolated S2 artifact:** `/home/james/.paseo/worktrees/0jx5pvzi/s2-stack-flash-20260924` contains a dirty snapshot based on `7e01ac84e6ea14b1444301fa6eb16a08d2bf3128`, including an uncommitted `src/participants/stack.ts` adapter and `tests/participantsStackSemanticAssessment.test.ts`. The adapter still depends on deterministic detector discovery and `DETERMINISTIC_FAST_PATH`, and uses a provider-shaped injected service. It conflicts with the newly approved stack decision and runtime composition. It is rejected for reuse; no files or test claims are copied from it.
- **Existing S2 contract:** `src/semantic/assessment.ts` already has type names and typed judgments for most S2 work, including `VALIDATION_NEED`, but its injected `SemanticAssessmentExecutorV1` and cache result do not record AEH agent identity, Paseo session identity, or read receipts. The contract must be frozen around those omissions before worker delegation.
- **Prior blocker:** the current status describes missing executor/profile/composition as a blocker. The user's approved Paseo/AgentTopology decision resolves that architecture question. S2 proceeds against it; the old BLOCKED conclusion is not carried forward.

## Frozen S2 contract and authority/read boundary

1. `SemanticAssessmentServiceV1` remains a controller-side typed gateway. Its production runtime resolves the canonical `Semantic Assessor` role from the active `ResolvedAgentTopology` and a deterministic AEH semantic-capability policy, then calls a Paseo-managed agent. Topology supplies actual runtime/model/profile identity; there is no second model configuration or vendor invocation path.
2. The one role supports `INTENT`, `ROUTE`, `STACK`, `ISSUE`, `FAILURE`, `CANDIDATE_IMPACT`, and `VALIDATION_NEED`. It is an AEH Agent, not a WorkGraph Participant by default. Operation/candidate evidence is bound to the request without inventing WorkUnit ownership, ChangeSet authority, or mutation capability.
3. Semantic capability policy is deterministic and assessment-specific. It freezes the policy revision, output contract, evidence/context ceilings, budget, timeout, and required Paseo/runtime permission profile. Missing or incompatible topology/profile/runtime fails closed.
4. The model actor receives only bounded controller-collected evidence and a strict structured-output contract. For stack, the controller uses a technology-neutral bounded repository inventory/read policy; model judgments select/cite relevant supplied files. Every supplied file has a normalized repository-relative path, content digest, and read receipt bound to repository/candidate identity. The semantic agent gets no repository tool, shell, write, Git, network, MCP, delegation, acceptance, policy, or capability-grant permission. A runtime that cannot enforce the frozen no-tools/read-only profile is ineligible.
5. `SemanticAssessmentV1` stores the assessment type; AEH logical agent, topology profile/model/runtime identity; actual Paseo provider/session/workspace/transport identity; applicable repository/operation/candidate binding; cited evidence refs and digest plus read receipts; policy revision; typed judgment and unknowns; assessment digest; and cache identity/freshness. All stored fields are deterministically revalidated on return and cache hit. Judgment is data, never authority.
6. Failure or invalidity follows each surface's deterministic minimum/fail-closed rule. There is no silent fallback to removed stack detectors or weakened assurance, review, validation, acceptance, policy, or authority.

## Tactical WorkGraph

| WorkUnit | Output and bounded scope | Ownership | Mechanism | Dependencies |
| --- | --- | --- | --- | --- |
| S2-WU1 Contract freeze | Extend the typed assessment/result/cache contracts with topology/profile and actual Paseo session provenance, evidence read receipts, cache identity/freshness and stale/replay rejection. Add the single `Semantic Assessor` role/output contract and deterministic assessment capability policy. | LUNA_OWNED | HYBRID | Accepted S1 identity interfaces; user-approved composition decision |
| S2-WU2 Paseo execution and safety | Resolve the assessor from active `AgentTopology`; construct a strict evidence-only prompt/output contract; execute through Paseo; validate actual session/profile provenance and enforce read-only/no-tool permissions before dispatch. | LUNA_OWNED | HYBRID | WU1; existing Paseo managed-agent runtime and permission projection |
| S2-WU3 Stack discovery and detector removal | Replace all stack detector semantics with generic bounded repository evidence/read receipts, `STACK` assessment, deterministic binding/schema/provenance checks and `ProjectStackProfile`; remove all listed detector APIs, implementations, exports, production paths, fixtures and tests. | FLASH_DELEGATABLE | HYBRID (removal and evidence gates are DETERMINISTIC) | WU1 frozen request/result/read-receipt contracts; WU2 frozen gateway interface |
| S2-WU4 Intent and route | Wire public request intent and route assessment to the gateway while preserving explicit CLI intent, deterministic policy constraints, assurance floors, and S1 `ResolvedOperationPolicy` binding. | LUNA_OWNED | HYBRID | WU1–WU2; accepted S1 policy identity |
| S2-WU5 Issue | Bind issue interpretation and typed requirements to the immutable raw issue/source snapshot; validate references, schema, scope and authorization deterministically. | LUNA_OWNED | HYBRID | WU1–WU2; issue intake/source snapshot |
| S2-WU6 Failure diagnosis | Call the `FAILURE` assessment at production recovery diagnosis after deterministic process/test facts; preserve ambiguity and keep retry, recovery, budgets and transitions deterministic. | LUNA_OWNED | HYBRID | WU1–WU2; recovery lifecycle |
| S2-WU7 Candidate impact | Assess actual post-assembly candidate/ChangeSet evidence; bind result to the resulting candidate identity/digest; preserve conservative behavior on missing/invalid assessment. Do not implement S4 downstream recompilation. | LUNA_OWNED | HYBRID | WU1–WU2; S1 candidate identity; candidate assembly |
| S2-WU8 Validation-need support | Keep `VALIDATION_NEED` in the canonical assessment schema/policy and wire it only to a validation-needs caller already required by S2 public paths/status. Do not redesign validation resolution. | LUNA_OWNED | HYBRID | WU1–WU2; current validation caller audit |
| S2-WU9 Integration, evidence and docs | Inspect every diff; verify all six public paths, assessor topology/Paseo execution, safety/provenance/cache contracts and detector deletion; run required validation; reconcile directly affected status and conformance rows. | SEQUENTIAL_AFTER_CONTRACT_FREEZE | DETERMINISTIC | WU1–WU8 |

## Delegation assessment and frozen worker boundary

WU3 is safely delegatable after WU1 and WU2 freeze their exported contracts. Stack discovery and detector retirement form an independently testable subsystem with a narrow file boundary. The worker can implement against stable service/request/read-receipt types without changing topology resolution, Paseo execution, other public paths, S1 identity, or status/conformance. The lead owns all shared contracts and integration. There is therefore no zero-worker justification; one meaningful Flash assignment is mandatory and planned.

The Flash assignment will use a new Paseo-managed worktree based on the current `core-architecture-v2` HEAD, not the dirty prior worktree. Its write scope is limited to `src/participants/stack.ts`, `src/participants/stackTypes.ts`, `src/participants/stackDetectorRegistry.ts`, `src/participants/stackDetectors/**`, the stack discovery tests/fixtures, and stack export sites explicitly listed in its prompt after dependency inspection. It may not edit semantic contracts, topology, Paseo/security runtime, public intent/route/issue/failure/impact callers, campaign documents, accepted S1 paths, or unrelated tests. No nested delegation, commits, or pushes.

Immediately before creating the implementation worker, `list_profiles` was called again. The returned **DeepSeek V4.1 Flash Implementer** profile was materialized exactly: `provider: opencode`, `model: opencode-go/deepseek-v4.1-flash`, `modeId: build`, `thinkingOptionId: max`, `features: { auto_accept: true }`. The worker was Paseo agent `41e3b3ba-bfec-4915-84b3-29dedb069781` in worktree `wks_504a82db4a321cc4`, path `/home/james/.paseo/worktrees/0jx5pvzi/s2-stack-semantic-flash-20260924`, branch `s2-stack-semantic-flash-20260924`, based on `core-architecture-v2`. Its prompt contained the required objective, exact scope, files/areas, dependencies, invariants, acceptance criteria, tests, explicit exclusions, and no-nested-delegation clauses. Worker tests used deterministic Paseo fakes and do not establish REAL_PROVIDER certification.

## Evidence accounting

The prior dirty isolated S2 artifact remains rejected because it retained deterministic detector semantics. The fresh worker changed only `src/participants/stack.ts` and its two assigned tests; a final worktree audit confirmed that the other dirty files were the pre-delegation frozen contract snapshot. Its untracked `node_modules` symlink resolves to the main checkout's dependency tree and was not integrated. The lead reviewed the output against the frozen read boundary and approved contracts, manually integrated the scoped implementation, then independently ran the focused S2 suites, typecheck, build, and full non-system suite; worker-reported results were not used as acceptance evidence. No commits or pushes were made. S3 authority consumption, S4 impact-driven downstream recompilation, S5 progressive context/session reuse, and all later slices remain future dependencies.

## S2 same-slice remediation: repository evidence boundary, skill-root validation, INTENT risk, and role wording

### Pre-edit verification and frozen contract

- **Checkout state:** `core-architecture-v2` at `f186468dfcd7b905fdb4aa10bd3b965084f405cc`; the checkout is dirty from the already integrated, uncommitted S2 implementation, with no staged changes. S1 identity files `src/architecture/executionIdentity.ts` and `src/operations/state.ts` have no changes. Fresh focused prerequisite verification passed: `npx vitest run tests/executionIdentity.test.ts tests/operationV2Identity.test.ts tests/operations.test.ts` — 3 files / 41 tests.
- **Digest semantics:** `computeWorktreeDigest` hashes sorted Git-tracked and non-ignored untracked paths and their bytes (symlinks are represented by their link text); if Git enumeration fails, its filesystem fallback excludes `.git`, `.harness`, `dist`, and `node_modules`. `.harness` runtime/cache files are ignored by the checkout's `.gitignore`.
- **Boundary defect:** `createSemanticRepositoryBindingV1` previously hashed `path.resolve(root)` while stack collection resolved its own real root, and the stack collector did not compare either that root or current content to the supplied binding. `repositoryRootDigest` remains optional in the shared binding schema for non-STACK surfaces; STACK must require it and validate its canonical realpath digest.
- **Frozen STACK invariant:** compare `sha256Canonical(realpath(root))` to required `binding.repositoryRootDigest` and compare `computeWorktreeDigest(realpath(root))` to `binding.repositoryDigest` before reading, after evidence capture, and again after the assessor returns and before projection. Any mismatch/drift fails closed. Keep current operation/candidate fields and evidence receipts unchanged; add no technology-specific detection or fallback.
- **Frozen evidence inventory invariant:** the stack inventory must be drawn from the same Git-tracked and non-ignored untracked file set that `computeWorktreeDigest` covers, or a stricter generic subset. It must not read or cite ignored secrets or runtime state such as `.env` and `.harness/cache`; generic path and filesystem rules only.
- **Frozen project skill-root invariant:** every model-proposed `projectSkillRoots` entry is data requiring deterministic generic path validation: normalized repository-relative path, no absolute path, traversal, malformed component, or escape through filesystem resolution, and it must resolve to an existing directory inside the bound canonical repository/candidate. Invalid roots reject the typed stack result. Valid roots are descriptive output only and do not select/grant skills or capabilities.
- **Frozen INTENT invariant:** semantic INTENT supports the caller's LOW, STANDARD, and HIGH risk classes within its existing reasoning/context/token/time ceilings. Raise only its maximum accepted risk class to HIGH; deterministic high-risk route and assurance floors remain unchanged.
- **Frozen role wording:** normative Section 3.1 names Semantic Assessor within canonical AEH Agent responsibilities and explicitly states that the canonical WorkGraph Participant role set excludes it. Do not add any assessment-specific roles or otherwise alter role topology.

### Focused remediation WorkGraph

| WorkUnit | Output and bounded scope | Ownership | Mechanism | Dependencies |
| --- | --- | --- | --- | --- |
| S2-R1 Contract freeze | Freeze STACK real-root/content checks, global optional versus STACK-required root digest, check timing, Git non-ignored evidence inventory, deterministic validation of proposed project skill-root paths, and supported INTENT risk ceiling. | LUNA_OWNED | DETERMINISTIC | Current S2 assessment/binding contract; accepted S1 identity |
| S2-R2 Regression coverage | Add root-A/binding-B substitution, stale-before-scan content, drift during assessor execution, missing STACK root digest, ignored secret/runtime exclusion, absolute/traversal/malformed/whitespace-padded/nonexistent/escaping project skill roots, valid descriptive roots, and HIGH-risk semantic INTENT regressions. Tests only. | FLASH_DELEGATABLE | HYBRID | S2-R1 frozen expectations; existing stack and semantic test helpers |
| S2-R3 Boundary/policy implementation | Canonicalize binding root with `realpath`; validate digest before/after collection and after inference; require STACK root digest; share or tighten the digest's non-ignored file inventory; validate project skill-root paths as normalized relative paths resolving to existing in-root directories without granting capability; allow INTENT risk through HIGH without changing deterministic floors. | LUNA_OWNED | HYBRID (identity/currentness, path/inventory validation, and policy enforcement are DETERMINISTIC) | S2-R1; no S1 identity changes |
| S2-R4 Normative role clarification | Update only Section 3.1 to distinguish canonical Agent responsibilities from canonical WorkGraph Participant roles. | LUNA_OWNED | DETERMINISTIC | Approved single Semantic Assessor role decision |
| S2-R5 Integration, evidence, and documentation | Review worker tests and every diff; run focused stack/semantic suites, typecheck, build, and full non-system Vitest; reconcile only affected S2 evidence rows. | SEQUENTIAL_AFTER_CONTRACT_FREEZE | DETERMINISTIC | S2-R1–R4 |

S2-R2 was safely separable because it changed only deterministic regression tests in `tests/participantsStackDiscovery.test.ts` and `tests/auditIntent.test.ts`; shared source contracts, implementation, documentation, and S1 files remained lead-owned. The worker used an isolated Paseo worktree seeded with the current S2 snapshot. No zero-worker justification applied. Its prompt stated exact scope, dependencies, invariants, acceptance criteria, tests, exclusions, and no nested delegation. No commits or pushes were permitted.

Immediately before creating the S2-R2 test worker, `list_profiles` was called again. The freshly returned **DeepSeek V4.1 Flash Implementer** profile was materialized exactly: `provider: opencode`, `model: opencode-go/deepseek-v4.1-flash`, `modeId: build`, `thinkingOptionId: max`, `features: { auto_accept: true }`. Paseo agent `36ad6900-35b7-4ba5-a658-b9ce9a85c4c1` ran in isolated workspace `wks_0aa890e895147745`, path `/home/james/.paseo/worktrees/0jx5pvzi/s2-evidence-boundary-flash-20260924`, branch `s2-evidence-boundary-flash-20260924`. The assignment allowed writes only to the two test files named above and prohibited source/docs changes, nested delegation, commits, and pushes. Its pre-integration focused run intentionally demonstrated the regressions: `npx vitest run tests/participantsStackDiscovery.test.ts tests/auditIntent.test.ts` — 2 files failed, 14 failed / 44 passed (58), including the existing scan-bound fixture charging `.git` under the old filesystem walk. The lead independently reviewed and integrated only the assigned test changes, then verified the corrected Git-inventory implementation with the integrated S2 suite (14 files / 123 tests passed) and full non-system lane. Worker results are failure reproduction, not acceptance evidence or certification.

## Integrated remediation evidence

- STACK binding creation now hashes canonical `realpath`; the STACK caller requires the optional shared `repositoryRootDigest`, compares root and worktree digests before reading, after evidence capture, after assessment, and before returning the profile. The evidence inventory reuses `computeWorktreeDigest`'s tracked/non-ignored-untracked Git path set and fails closed if Git cannot establish it; ignored `.env` and `.harness` runtime/cache paths are excluded. Proposed `projectSkillRoots` are byte-preserved for deterministic validation, then rejected unless normalized, relative, existing directories whose realpaths remain within the bound root. Their output grants no skill or capability.
- `INTENT.maxRiskClass` now permits HIGH within existing request budgets and reasoning/context ceilings. Tests retain deterministic high-risk routing and assurance floors.
- `npx vitest run tests/auditIntent.test.ts tests/triage.test.ts tests/recovery.test.ts tests/candidateAssembler.test.ts tests/candidateWaveLineage.test.ts tests/candidateRepairProtection.test.ts tests/issueIntake.test.ts tests/issueDeliveryIdentity.test.ts tests/participantsStackDiscovery.test.ts tests/participantsCanonical.test.ts tests/semanticAssessment.test.ts tests/semanticAssessmentRuntime.test.ts tests/semanticAssessorTopology.test.ts tests/runRepairCandidateLifecycle.test.ts` — 14 files / 123 tests passed.
- `npx vitest run tests/participantsStackDiscovery.test.ts tests/auditIntent.test.ts tests/semanticAssessment.test.ts tests/semanticAssessmentRuntime.test.ts tests/semanticAssessorTopology.test.ts` — 5 files / 75 tests passed; `npx tsc --noEmit` — exit 0; `npm run build` — exit 0; `npx vitest run --exclude 'tests/system/**'` — 151 files passed, 1 skipped; 803 tests passed, 7 skipped.
- This is deterministic fixture/contract/build evidence only; no REAL_PROVIDER, BROWSER, or ADVERSARIAL certification is claimed. S1 identity files remain unchanged. No commit/push was made and no later slice was started.
