Handle OOM-style definition clone failures safely#70
Open
Lihi-AI wants to merge 2 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR clarifies and hardens Loka’s no-exception allocation-failure policy for definition cloning/materialization by treating 0 returns as OOM-style failures, staging replacement clones before swapping owned definitions, and adding regression tests to pin “stable on failure” behavior.
Changes:
- Updated
WindowPropsassignment/setter paths to stage owned-definition clones and preserve the prior owned value if staging fails. - Hardened
WindowDefinition::create()to return0when owned definition cloning fails, and documented the intended nullable contract forclone()/create(). - Added focused regression tests plus documentation updates to codify the allocation-failure policy and migration targets.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/FlowDslTestMain.cpp | Updates test runner to call the new/renamed clone-failure regression tests. |
| tests/DefinitionCloneTests.hpp | Renames and expands clone-failure test declarations. |
| tests/DefinitionCloneTests.cpp | Adds OOM-style probe definitions, a null platform context, and new regression tests for failure propagation/stability. |
| docs/TODO.md | Notes remaining legacy clone seams that still blur “empty” vs allocation failure. |
| docs/ProgrammingGuide.en.md | Documents the “keep allocation failure narrow” policy and intended semantics of nullable clone() / create(). |
| common/app/scene/Node.hpp | Adds in-code documentation clarifying the allocation/nullable contract for node definition materialization. |
| common/app/scene/composition/NodeCompositionSnapshot.hpp | Refactors snapshot replacement to clone-then-swap behavior (used for diffing compositions). |
| common/app/core/WindowDefinition.hpp | Returns 0 from create() when owned-definition cloning fails (pre-window creation). |
| common/app/core/Window.hpp | Stages owned-definition clones in WindowProps copy/assignment and in scene()/menuBar() setters to preserve stable state on failure. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR defines and applies a narrow nullable contract for definition clone/create paths under Loka's no-exception policy.
WindowPropsdefinitions0fromWindowDefinition::create()when owned definition cloning failsSceneinstead of cloning it twiceclone()/create()results are reserved for allocation-style failure such as OOMWhy
clone() == 0previously mixed together “empty”, contract misuse, and allocation failure depending on the callsite. This change narrows the contract:Impact Scope
Affected:
WindowPropsowned root/menu definition copy, assignment, and replacementWindowDefinition::create()root-to-Scene ownership transfer and failure cleanupNodeCompositionSnapshotclone-failure invalidationNot affected:
Concrete implementations that still use plain
new, or whose constructors allocate internally, remain explicit TODO migration targets. This PR defines the meaning and owner-side handling of nullable results; it does not claim end-to-end allocator recovery is complete.Validation
cmake --build build/Testingctest --test-dir build/Testing --output-on-failurecmake --build build/Testing-ASanctest --test-dir build/Testing-ASan --output-on-failureHelloWorldmanual runtime checkRed evidence added during review hardening:
clone()twiceBoth are green in Testing and Testing-ASan after
8e76976.Closes #66.