Skip to content

Harden engine error handling; 4x tests (24->136) and demos (5->20)#4

Open
cognis-digital wants to merge 1 commit into
masterfrom
harden-and-expand
Open

Harden engine error handling; 4x tests (24->136) and demos (5->20)#4
cognis-digital wants to merge 1 commit into
masterfrom
harden-and-expand

Conversation

@cognis-digital

Copy link
Copy Markdown
Owner

Summary

Hardens the engine's error handling and roughly 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 / ValueError contract:

  1. seed() failures now become Status.ERROR. Previously a raising seed escaped the engine as a raw exception — inconsistent with check/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).
  2. check() is guarded to return a Verdict. Returning a bare bool/None/tuple — the single most common misuse — used to surface deep in the loop as a cryptic AttributeError: 'bool' object has no attribute 'ok'. It now produces a clear, stage- and iteration-named TypeError (caught as ERROR in run(), raised directly in cycle()).
  3. Constructor validation up front. Non-callable check/revise/seed/on_iteration raise TypeError; min_delta < 0 raises ValueError (joining the existing max_iterations/patience checks).

Tests: 24 → 136

New files test_engine_edge.py, test_verdict_trace.py, test_examples_edge.py cover budget boundaries, plateau/min_delta corners (incl. the strict-> boundary), per-stage error surfacing, the verdict-type guard, config validation, best-tracking with unscored candidates and ties, the cycle() streaming form, the full Verdict/Iteration/Result data 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() vs cycle(), Newton vs bisection). run_all.py, tests/test_demos.py, docs/DEMOS.md, docs/ARCHITECTURE.md, and README.md updated. Every demo drives the real API, touches no network, and exits 0.

Verification

$ pytest -q
136 passed
$ PYTHONUTF8=1 python demos/run_all.py   # exit 0

The public surface (Engine, Verdict, Result, Iteration, Status, cyclework.examples) is unchanged — existing code keeps working; the changes only make previously-undefined behavior explicit.

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.
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