Harden engine error handling; 4x tests (24->136) and demos (5->20)#4
Open
cognis-digital wants to merge 1 commit into
Open
Harden engine error handling; 4x tests (24->136) and demos (5->20)#4cognis-digital wants to merge 1 commit into
cognis-digital wants to merge 1 commit into
Conversation
Engine hardening (public API unchanged): - Surface seed() failures as Status.ERROR (previously escaped as a raw exception, unlike check/revise) - fixes a real inconsistency. - Guard that check() returns a Verdict: a bare bool/None/tuple now yields a clear, stage-and-iteration-named TypeError (ERROR in run(), raised in cycle()) instead of a cryptic AttributeError deep in the loop. - Validate constructor args up front: non-callable check/revise/seed/ on_iteration raise TypeError; min_delta < 0 raises ValueError. Tests: 24 -> 136. New edge/error-path coverage for budget boundaries, plateau/min_delta corners, per-stage error surfacing, verdict-type guards, config validation, best-tracking with unscored candidates, the cycle() streaming form, the Verdict/Iteration/Result data model, and example convergence/divergence/error cases. Demos: 5 -> 20. Added error recovery, gradient descent, multi-rule normalizer, misuse guards, Collatz+budget, seed preprocessing, plateau early-stop, streaming audit log, any-state, retry-with-backoff, constraint repair, best-of non-convergent search, iterative summarizer, run()-vs-cycle(), and Newton-vs-bisection. run_all.py + docs/DEMOS.md + README updated; each exits 0.
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
Hardens the engine's error handling and roughly 4×s the tests and demos, with no change to the public API.
Engine hardening (
cyclework/engine.py)Three real fixes, all surfaced as the existing
Status.ERROR/TypeError/ValueErrorcontract:seed()failures now becomeStatus.ERROR. Previously a raisingseedescaped the engine as a raw exception — inconsistent withcheck/revise, both of which were already trapped. The seed is a stage too; it now fails the same honest way (with an empty trace, since nothing ran).check()is guarded to return aVerdict. Returning a barebool/None/tuple — the single most common misuse — used to surface deep in the loop as a crypticAttributeError: 'bool' object has no attribute 'ok'. It now produces a clear, stage- and iteration-namedTypeError(caught asERRORinrun(), raised directly incycle()).check/revise/seed/on_iterationraiseTypeError;min_delta < 0raisesValueError(joining the existingmax_iterations/patiencechecks).Tests: 24 → 136
New files
test_engine_edge.py,test_verdict_trace.py,test_examples_edge.pycover budget boundaries, plateau/min_deltacorners (incl. the strict->boundary), per-stage error surfacing, the verdict-type guard, config validation, best-tracking with unscored candidates and ties, thecycle()streaming form, the fullVerdict/Iteration/Resultdata model, and example convergence/divergence/error paths.Demos: 5 → 20
Added scenarios 6–20 (error recovery, gradient descent, multi-rule normalizer, misuse guards, Collatz+budget, seed preprocessing, plateau early-stop, streaming audit log, any-state, retry-with-backoff, constraint repair, best-of non-convergent search, iterative summarizer,
run()vscycle(), Newton vs bisection).run_all.py,tests/test_demos.py,docs/DEMOS.md,docs/ARCHITECTURE.md, andREADME.mdupdated. Every demo drives the real API, touches no network, and exits 0.Verification
The public surface (
Engine,Verdict,Result,Iteration,Status,cyclework.examples) is unchanged — existing code keeps working; the changes only make previously-undefined behavior explicit.