mirror of
https://github.com/kvcache-ai/AgentENV.git
synced 2026-11-05 01:17:36 +00:00
[GH-ISSUE #365] [Design Proposal] SQL schema migrations and mixed-version operation #94
Labels
No labels
bug
documentation
enhancement
enhancement
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
kvcache-ai/AgentENV#94
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @guozy18 on GitHub (Oct 12, 2026).
Original GitHub issue: https://github.com/kvcache-ai/AgentENV/issues/365
Affected component
Cross-cutting / other
Problem statement
Part of the parent proposal. Related: data model and interfaces, sandbox lifecycle and resource holds, and online GC and history retention.
Once the database is authoritative, an upgrade involves more than replacing Node binaries. Old and new Nodes, GC workers, tools, and existing connections may access the same database concurrently. Existing sandboxes continue to fork, resume, publish, and eventually release their holds.
A DDL change can permit new values without making old code understand them. Unified layer UUID/predecessor semantics, immutable manifests referenced by manifest_ref, head-only dependency registration, P2P artifact selection and layer GC affect more than SQL row shapes. A program may still connect successfully while misunderstanding identity or protection. Schema changes, compatible code deployment, new writes and GC activation need separate steps.
Use case
The initial transition from an OSS/POSIX file catalog to SQL is covered by data mapping and migration.
Current behavior and workarounds
Running Nodes, workers, tools and P2P publishers/readers may use different artifact and metadata contracts during a rollout. The example below covers the transition from an older representation to unified layer identities, immutable manifests referenced from SQL, and dependency heads. It is a compatibility example, not a requirement to implement the older full-mapping SQL proposal first. If SQL has not been deployed, initialize the agreed target model directly and follow #363 for the file-catalog transition.
A schema check at Node startup does not cover later changes: existing pools need not reconnect, and old workers, tools, or delayed callbacks may still write. Replica counts or missing heartbeats do not prove that all old accessors and external side effects have ended.
Neither “upgrade the database first” nor “upgrade the code first” is sufficient. The order must account for what old code can read, what the schema permits, and which data formats are currently allowed to be produced.
Desired behavior
Proposed approach
Example: enabling unified layer identity, manifest references and heads
The target Catalog records each validated layer UUID with its fixed predecessor and published descriptor, records the chain heads retained by S, and refers to a complete immutable backend manifest through
manifest_ref. It does not register every layer again for each snapshot. The data-model issue defines the final schema and field names; these examples do not prescribe a table count or a common volume schema.A legacy accessor may expect full descriptions in SQL, explicit snapshot-to-object mappings, or old UUID/P2P behavior. A compatible release must understand both the existing deployment contract and the approved new one before new-only data appears. Legacy layers with missing/conflicting UUIDs or predecessors require the compatibility path in #363; a schema change does not make them valid.
Phase 2 requires proof that old code can use the expanded schema. If an old binary accepts only one exact schema version, first deploy a bridge release that improves compatibility checks while retaining old writes. Unknown structures must not be assumed compatible.
The exact OCI UUID-generation algorithm, canonical publication representation, layer terminal retention and safe physical-key reuse must be resolved by their owning proposals before enabling operations that depend on them. This issue defines the activation discipline, not those choices. Snapshot/hold first-admission and pruning rules do not automatically apply to layer UUIDs.
How requests continue during coexistence
The existing
no_schedulemechanism can exclude old Nodes from new allocations while retaining their sandbox bindings, API, and heartbeats. Fork can still create children on an old Node, and resume follows the original binding. Its workload therefore need not decrease monotonically.Keep the old Pod serving until its business obligations are handed off or complete. Its shutdown path stops the reporter, orchestrator, and devices, while Gateway routes existing requests by sandbox binding. Preserving recoverable state alone does not keep requests uninterrupted.
If an old Node or long-lived paused state still requires the old contract, retain that Node, its required metadata and fixed artifact inputs, and delay incompatible new semantics. Proceed only when the relevant read, write, and final-release paths are compatible or their obligations have ended. This does not promise replacement of every Node within a fixed time.
Separate schema compatibility from permitted data formats
schema_version/ migration stepsrequired_read_formatsallowed_write_formatsDatabase policy is durable; its concrete layout belongs to the Catalog migration infrastructure, not a new per-Node or per-VM table. Admission of a binary and permission to produce a new format are separate decisions. An expanded schema must not automatically enable new identity semantics, graph GC or historical pruning.
Enabling new-format writes raises the required read contract. Disabling those writes later does not remove that requirement: new manifests, heads, UUID bindings and terminal states may already exist. Lowering the requirement would need an independently verified reverse migration; this proposal provides no automatic one.
The following pseudocode illustrates format admission, not a mandatory schema layout:
Format activation and Catalog publication/cleanup checks use a common synchronization boundary. Prepare bytes and immutable manifests outside SQL; checking the currently permitted contract and committing its rows/heads must be ordered against activation. External I/O, device waits and uploads stay outside that policy lock. Normal hot VM operations do not add SQL requests for version checks.
Constraints cannot prevent every semantically incompatible write that bypasses Catalog. Only reviewed write/cleanup paths may connect. Policy checks, connection permissions and deployment isolation must constrain actual accessors; a version number alone is not isolation evidence. P2P compatibility also requires controlling producers, aliases and readers, not just database permissions. An existing digest requirement must not be silently bypassed by UUID lookup during coexistence.
Migrator and accessor responsibilities
Apply the same sequence to other schema changes
Backfills and structural changes must not require pausing user operations. Use bounded lock waits/retries and measure the actual latency impact; this is not a claim that arbitrary DDL is nonblocking.
During a representation transition, keep one explicit authority while old writers remain active. Where compatible dual maintenance is required, update database representations in the same transaction; prepare immutable external content before publishing its reference. Do not infer a complete chain from an unordered old object mapping: validate the complete ordered manifest. After old writers exit, finish and verify the backfill before switching authority. One completed backfill pass is not sufficient.
Acceptance criteria
Compatibility and operational impact
schema_versiondoes not make old code safe.The rollback window and schema contraction are separate. Stopping new-format writes does not remove previously written data. Before dropping old structures, confirm that no query, writer, compatible rollback version, or unfinished task still needs them.
Alternatives considered
schema_version: this cannot distinguish a structure permitted by SQL from an identity, manifest or protection contract understood by every accessor. Track required read contracts and permitted writes separately.Non-goals
A general migration platform and VM lifecycle redesign are outside this issue. Preserve Local/promotion protection and existing volume ownership. This issue does not select a shared volume schema, an OCI UUID algorithm, or a terminal layer-retention policy. The upgrade contract does not require lock-free DDL, VM live migration, or forced retirement of long-lived consumers within a deadline.
Contribution
I can provide more design details
Pre-submission checklist