Skip to content

refactor(kernel): validate destination scope at public batch boundary - #2748

Merged
jbeda merged 1 commit into
mainfrom
impl/kernel-validation-cleanup
Nov 8, 2026
Merged

jbeda merged 1 commit into
mainfrom
impl/kernel-validation-cleanup

Conversation

@jbeda

@jbeda jbeda commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Approved cleanup plan and verification record

Follow-up to #2746 for the final review cleanup that was implemented locally but not included in that merge. Refs #2663; separate from the next boilerplate investigation in #2747.

  • Replace constructing Created solely to validate a history ID with direct private history-ID validation.
  • Move destination ownership checks to public SessionCommit methods, before scope-erasing DTO conversion.
  • Remove redundant destination HistoryID arguments from all 11 private record constructors and adapt callers/reservations.
  • Test the public boundary for invalid/foreign identities, equal local ordinals, idle replacements, failure atomicity and error precedence over malformed/oversized payloads.

The branch starts at merged main (8c1276a7da77eca4ce31f3e7c44023464aeb0994). Its base tree is identical to the original review baseline, and the cleanup patch is byte-identical to the reviewed and tested candidate.

Verification

Passed on the exact final implementation candidate:

  • Scoped race: cd engine && go test -race ./id ./kernel/... ./arch ./adapter/history/...
  • Standalone: cd engine && GOWORK=off go test ./kernel/... ./arch ./adapter/history/...
  • 386: cd engine && GOARCH=386 go test ./kernel/...
  • task lint, task api:check, task generate:codecs:check, git diff --check
  • Spec, Standards, Test adequacy, security, architecture, reuse and duplication reviews: no open findings after targeted recheck.

Isolated-engine scope; no full repository suite, production demo or live-provider tests. No tracked Markdown, generated files or public API snapshot changes.

API compatibility

No wire/protobuf/server/client changes, feature/major changes or production integration. Public Go signatures, persistence schema/version and canonical bytes are unchanged. Private constructor signatures change. Public additions validate top-level identity, then owner, then bounded payload; input/request retain exact-active-run-first behavior. Valid foreign identity returns ErrIdentity before contradictory malformed/oversized payload errors. No stored-data migration or upgrade action.

Scope

Public replacement HistoryID fields remain unchanged. Reusable view/generator tooling and dependency choices remain #2747's investigation; this PR does not select or implement that approach.

Replace Created-as-validator coupling with directly named history identity validation. Remove destination HistoryID plumbing from private record constructors and enforce owner checks before conversion in public batch methods.

Cover invalid and foreign identities, failure atomicity, and ownership-before-payload precedence through public methods. Follow-up to #2746; refs #2663.

API compatibility: no public Go signatures, wire behavior, persistence formats, or production integration changes.

Co-authored-by: Mecatl <[email protected]>
@jbeda

jbeda commented Nov 8, 2026

Copy link
Copy Markdown
Contributor Author

Published: 2026-11-08T02:42:23Z
Source provenance: .scratch/kernel-validation-cleanup-plan.md (local, not a remote link)
Plan source SHA-256: 93bfb1c088ee14f1d62090421ca7a5095cc4b3a30e6b1a51dafc4aa0f144f5ae
Verified PR head: cbeb8bb8cfcd2a7e1c976620a54f1461600e5740

Kernel validation cleanup — follow-up to #2746

Slug: kernel-validation-cleanup
Branch: impl/kernel-validation-cleanup
Base: main at 8c1276a
Original implementation/review baseline: 19ff882

Scope and decisions

Deliver the approved round-4 review cleanup that remained uncommitted when #2746 merged. The original baseline and merged main have identical tracked trees; the exact reviewed cleanup diff is unchanged on the follow-up branch. This is not the reusable view/boilerplate investigation in #2747.

  1. Remove creation-fact coupling from history-ID validation. Replace constructing Created merely to validate an identity with a directly named private validateHistoryID using the existing parser. Preserve identity grammar and the existing public error wording; no new public validator API or generic framework.
  2. Move destination-scope checks to public SessionCommit methods before materialization drops enclosing scope. Remove destination HistoryID parameters and owner comparisons from all 11 private typed record constructors and adapt internal ending reservation and callers. Keep local payload validation, bounds, encoding, nested-reference checks and owned canonical backing in materialization.
  3. Keep public replacement HistoryID fields unchanged. Destination-neutral replacements are a separate undecided API design, not part of this cleanup.
  4. Preserve batch-handle-first validation and exact-active-run-first ErrTransition for AddUserInput/AddModelRequest. Other scoped additions validate top-level identity (codec.ErrInvalidData), then reject valid foreign history (ErrIdentity), then validate bounded payloads/nested references. A foreign owner takes precedence over contradictory malformed/oversized payloads; do not duplicate whole aggregate validation solely to retain incidental former precedence.
  5. Preserve nested run/history references, retries/capture validation, failed-add atomicity and unconsumed identities, immutable backing, canonical bytes, current-policy limits, emergency reservation and frozen history-proposal retries.

Tasks and acceptance

  • Replace the Created-as-validator pattern across affected session values and New without changing RunID-specific error wording.
  • Relocate public owner checks, simplify private constructor signatures and adapt all production/test/fuzz callers. Do not replace scope plumbing with another retained wrapper.
  • Replace private destination-ownership assertions with real public-boundary tests: invalid IDs, foreign histories with equal ordinals, matching-owner positive controls, idle replacements including same-batch creation/ending, nested references, unchanged batch/admission/accepted state, and unconsumed IDs.
  • Prove owner checks precede malformed and oversized payload errors. Oversized tests use valid local positive controls and a deliberately tight encoding limit rather than large allocations.
  • Run integrated checks and independent Spec/Standards/Test/Domain reviews; fix concrete findings and recheck the exact delta.

Verification

Required scoped checks:

  • cd engine && go test -race ./id ./kernel/... ./arch ./adapter/history/...
  • cd engine && GOWORK=off go test ./kernel/... ./arch ./adapter/history/...
  • cd engine && GOARCH=386 go test ./kernel/...
  • task lint
  • task api:check
  • task generate:codecs:check
  • git diff --check

All passed on the final implementation candidate before delivery. A final test-adequacy advisory was resolved with the oversized-payload matrix; original malformed coverage was retained, integrated checks rerun, and targeted incremental review passed. Final panel: no open blockers, important or advisory findings; no unresolved reviewer failures. Public API/schema/generated files and tracked Markdown are unchanged, so no regeneration/docs gate is required. Isolated-engine exemption applies: no full repository suite, production demo, live-provider tests or module pin changes.

Compatibility and boundaries

API compatibility: no wire/protobuf/server/client changes, major/feature changes or production integration. Public Go signatures, persistence schema/version and canonical bytes are unchanged. Only private constructor signatures and validation placement change; the explicit error precedence above is within the isolated experimental kernel. No stored-data migration or upgrade action.

Defer #2747 investigation/approach selection, extension registry, lifecycle redesign, passive tool disposition, request reconstruction, final accounting and production wiring. No approach for reusable views/generation/dependencies is selected here.

Joe authorized the follow-up PR after discovering this cleanup was not pushed with #2746. Commit/push/PR publication are authorized; merge remains human-only. The earlier checkout reset stays paused while this PR is open.

@jbeda
jbeda enabled auto-merge (squash) November 8, 2026 02:45
@jbeda
jbeda merged commit 8d178d5 into main Nov 8, 2026
46 checks passed
@jbeda
jbeda deleted the impl/kernel-validation-cleanup branch November 8, 2026 02:52
@toolhive-release-app toolhive-release-app Bot mentioned this pull request Nov 18, 2026
2 tasks
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