Skip to content

feat(kernel): generate immutable payload views with layered dtogen - #2749

Merged
jbeda merged 4 commits into
mainfrom
impl/2747-view-codegen-options
Nov 9, 2026
Merged

jbeda merged 4 commits into
mainfrom
impl/2747-view-codegen-options

Conversation

@jbeda

@jbeda jbeda commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Generate immutable DTO-backed views and consolidate session authoring around canonical session/format payloads in the isolated kernel. No production integration.

  • dtogen independently generates CBOR, Clone, Equal, and view accessors from a shared typed graph. It loads owners without executing their code, renders and typechecks the selected closure before installation, and protects deterministic generated artifacts.
  • Source-local //dtogen:include markers select roots. DTO view tags define omitted or handwritten fields; safe untagged fields generate getters. Scope-bearing child navigation stays handwritten.
  • Session payload names alias canonical format DTOs. Commit methods take full destination identities separately, require synthesized identity fields to be zero, and populate bounded local copies without mutating caller storage.
  • Occurrence IDs support validated decomposition and reconstruction. Reconstruction establishes an identity value, not allocation, membership, or authority. Nested numeric payload references are interpreted relative to the destination run.
  • Payload views borrow immutable accepted backing. Byte leaves use views.Bytes with explicit leaf-only Copy; collections use views.SliceView without materializing intermediate view slices. Zero and optional views preserve absence versus present-empty values.
  • Package and contributor documentation describes current ownership and contracts rather than implementation history.

Closes #2747. Relates to #2663.

Review navigation

Area Contract
internal/dtogen/ Source selection, field policy, owner loading, closure checking, artifact installation
engine/kernel/views/ Borrowing, lifetime, zero/bounds behavior, explicit copying
engine/kernel/session/format/ Canonical payloads, recursive public validation, bounded codec hooks
engine/kernel/session/ Destination scope, relative references, identity reconstruction, scoped navigation, acceptance and loading
engine/api/ Generated public API snapshots

Verification

The implementation at c2b93c83f passed task test, task test:race, task lint, task docs, DTO generation/freshness and API snapshot checks, plus the offline demo exercising a tool call, permission approval, and result. Final generator-selection regressions also passed the focused dtogen race suite.

The documentation-only head db5b932aa passed task generate:data, task generate:data:check, task docs, and git diff --check; regeneration changed no artifacts. Full code suites were not rerun for that documentation-only delta.

Submit and storage-backed Load tests cover complete nested traversal, scoped identities, zero/presence behavior, retained snapshots, and leaf-only copying with nonempty siblings. Allocation checks distinguish context-free traversal from captured-adapter construction and iterator escape costs; scoped collection construction is not claimed to be allocation-free.

API compatibility

This is an unwired experimental kernel Go API change, approved during review: canonical payload aliases, explicit-destination commit signatures, zero-only synthesized authoring fields, relative nested references, recursive public validation, occurrence-ID reconstruction, and borrowed/container inspection accessors. In-tree callers and API snapshots are updated.

No production wire/client/SDK behavior, protobuf contract, wire major or feature identifier, runtime entry point, module dependency pin, persistence schema/version, or canonical stored bytes changes. No client/server or stored-data upgrade is required. Production integration remains a separate change.

Evolve cborgen into independent DTO generation capabilities, add borrowed containers, and adopt canonical payload-backed session views. Preserve scoped adapters and bounded persistence behavior.

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

jbeda commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor Author

Design rationale

One payload model; explicit destination scope

session/format owns mutable payload structure and validation. Session commit methods own destination scope, lifecycle legality, and operational admission. Keeping those responsibilities separate avoids duplicate payload models and prevents caller-populated numeric fields from silently selecting a destination. Synthesized identity fields must be zero even when they would match the destination; authoring fills a bounded local copy.

Nested numeric references intentionally have destination-run meaning. Extracting a component from another run does not preserve its origin: it may resolve to an eligible occurrence in the destination run. Membership and ordering are still checked there. Full public occurrence IDs retain parent scope for equality and correlation; reconstructing one neither allocates nor establishes membership.

Mechanical getters; explicit contextual navigation

The DTO owns default field policy, while the consuming view owns enclosing identity context. Automatically constructed children must be context-free. Required, optional, and collection children that need scope use handwritten navigation rather than receiving incomplete identities. Handwritten collection adapters may capture immutable enclosing context; that construction can allocate and is measured separately from traversal.

Borrowed inspection; explicit export

Accepted backing is privately owned and immutable. Nested views retain it without copying siblings; byte Copy detaches only the selected leaf, and RecordView.Format provides a detached transport export. The generic views runtime itself only borrows: it does not freeze caller-owned data or synchronize mutation.

Bounded validation; checked installation

Public composite DTO validation checks complete child contracts without imposing resource policy. Codec traversal applies bounds before allocation and invokes immediate validation hooks rather than repeating recursive validation. Generator loading never executes owner code. Rendering and typechecking precede installation, but atomic file replacements are not a multi-file transaction; a filesystem failure can require regeneration.

@jbeda

jbeda commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor Author

Review outcome

Final implementation review covered Spec, Standards, Test adequacy, Architecture, Security, Library reuse, and Duplication. The final review reported no remaining blockers, important findings, or advisories.

Review and regression coverage includes canonical payload/view adoption; exact scoped identities through Submit and storage-backed Load; zero, presence, borrowing, and leaf-copy contracts; and generator selection, owner loading, and artifact protections. Allocation checks cover populated Media variants and distinguish captured-adapter construction and iterator escape from direct traversal.

Verification is scoped by revision in the PR description.

PANEL: ship_blockers=0 important=0 advisory=0 reviewer_failures=0

jbeda and others added 3 commits November 8, 2026 15:57
Use canonical session DTOs with explicit destination scope, validated occurrence-ID reconstruction, and source-tagged generation across all payload views. Preserve bounded admission, immutable borrowing, and canonical storage bytes.

Co-authored-by: Mecatl <[email protected]>
Select DTO and view roots beside their declarations with dtogen include
markers while preserving explicit-list support and load-only validation.
Generate plain media leaf getters and use scoped SliceView collections for
effective inputs, with separate coverage for closure allocation costs.

Co-authored-by: Mecatl <[email protected]>
@jbeda
jbeda enabled auto-merge (squash) November 9, 2026 15:18
@jbeda
jbeda merged commit e726fdb into main Nov 9, 2026
51 checks passed
@jbeda
jbeda deleted the impl/2747-view-codegen-options branch November 9, 2026 15:27
@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.

Reduce session immutable-view boilerplate with reusable view support

1 participant