Get Started

Troubleshooting

When judgment rejects a call, it raises a structured error: LibError in Mojo or JudgmentError in Python (plus StoreError for Store catalog and publication failures). Match on error.kind (LibErrorKind or StoreErrorKind), not on the message text.

  • Refusals from the checking kernel have kind == LibErrorKind.KERNEL and put the kernel's specific reason in kernel_kind.
  • Failed calls are atomic: the session's rows, declarations, and proof state stay unchanged (work already spent before the failure stays spent).

The example below triggers several common errors and shows how to recover from each one:

Mojo

troubleshooting.mojo Download
"""Recognize common Session errors and recover through the public API."""

from std.testing import assert_true
from judgment import Session
from judgment_shell import LibError, LibErrorKind


def prove_with_budget(work: UInt64) raises LibError -> Bool:
    """Run a small proof in a session with the chosen work budget."""
    var s = Session(work=work)
    var truth = s.true_()
    var proof = s.theorem("truth_refl", truth == truth)
    proof.rfl()
    _ = proof.finish()
    return True


def main() raises:
    var s = Session()
    var prop = s.prop_type()

    # 1. Looking up a fact before it is declared raises NO_MATCH.
    var rejected = False
    try:
        _ = s.fact("P_refl")
    except e:
        rejected = e.kind == LibErrorKind.NO_MATCH
    assert_true(rejected)
    var p = s.prop("P")
    var p_proof = s.theorem("P_refl", p == p)
    p_proof.rfl()
    _ = p_proof.finish()
    assert_true(s.fact("P_refl").statement().same_as(p == p))
    print("NO_MATCH: declare a fact before looking it up")

    # 2. Mixing handles from two different sessions raises WRONG_KERNEL.
    var other = Session()
    var foreign = other.true_()
    rejected = False
    try:
        _ = s.eq_refl(s.base(), foreign)
    except e:
        rejected = e.kind == LibErrorKind.WRONG_KERNEL
    assert_true(rejected)
    assert_true(other.eq_refl(other.base(), foreign).statement().same_as(foreign == foreign))
    print("WRONG_KERNEL: use the owning session, or rebuild in the receiving session")

    # 3. Using a handle from a discarded transaction raises KERNEL.
    var tx = s.transaction()
    var old = s.prop("temporary")
    tx.discard()
    rejected = False
    try:
        _ = s.eq_refl(s.base(), old)
    except e:
        rejected = e.kind == LibErrorKind.KERNEL
    assert_true(rejected)
    # Recovery recreates the constant; old cannot be revived.
    var fresh = s.prop("temporary")
    assert_true(s.eq_refl(s.base(), fresh).statement().same_as(fresh == fresh))
    print("KERNEL: rebuild discarded handles, or retain them in commit")

    # 4. Using a fixed local variable in a sibling frame raises KERNEL.
    var root = s.base()
    var x = s.fix(root, "x", prop)
    var y = s.fix(root, "y", prop)
    rejected = False
    try:
        _ = s.eq_refl(y[0], x[1])
    except e:
        rejected = e.kind == LibErrorKind.KERNEL
    assert_true(rejected)
    var valid = s.eq_refl(x[0], x[1])
    var closed = s.forall_intro(x[0], valid)
    assert_true(len(closed.hypotheses()) == 0)
    print("KERNEL: prove in the local's frame, then generalize")

    # 5. Exhausting the session work allowance raises LIMIT.
    rejected = False
    try:
        _ = prove_with_budget(1)
    except e:
        rejected = e.kind == LibErrorKind.LIMIT
    assert_true(rejected)
    assert_true(prove_with_budget(100000))
    print("LIMIT: unfinished; a rebuilt request with more work succeeds")

Run from the repository root pixi run mojo run -I src docs/examples/troubleshooting.mojo

Output

NO_MATCH: declare a fact before looking it up
WRONG_KERNEL: use the owning session, or rebuild in the receiving session
KERNEL: rebuild discarded handles, or retain them in commit
KERNEL: prove in the local's frame, then generalize
LIMIT: unfinished; a rebuilt request with more work succeeds

Python

troubleshooting.py Download
"""Recognize common Session errors and recover through the public API."""

from judgment import Session, JudgmentError
from judgment import JudgmentError, LibErrorKind


def prove_with_budget(work):
    """Run a small proof in a session with the chosen work budget."""
    s = Session(work=work)
    truth = s.true_()
    proof = s.theorem("truth_refl", truth == truth)
    proof.rfl()
    _ = proof.finish()
    return True


def main():
    s = Session()
    prop = s.prop_type()

    # 1. Looking up a fact before it is declared raises NO_MATCH.
    rejected = False
    try:
        _ = s.fact("P_refl")
    except JudgmentError as e:
        rejected = e.kind == LibErrorKind.NO_MATCH
    assert rejected
    p = s.prop("P")
    p_proof = s.theorem("P_refl", p == p)
    p_proof.rfl()
    _ = p_proof.finish()
    assert s.fact("P_refl").statement().same_as(p == p)
    print("NO_MATCH: declare a fact before looking it up")

    # 2. Mixing handles from two different sessions raises WRONG_KERNEL.
    other = Session()
    foreign = other.true_()
    rejected = False
    try:
        _ = s.eq_refl(s.base(), foreign)
    except JudgmentError as e:
        rejected = e.kind == LibErrorKind.WRONG_KERNEL
    assert rejected
    assert other.eq_refl(other.base(), foreign).statement().same_as(foreign == foreign)
    print("WRONG_KERNEL: use the owning session, or rebuild in the receiving session")

    # 3. Using a handle from a discarded transaction raises KERNEL.
    tx = s.transaction()
    old = s.prop("temporary")
    tx.discard()
    rejected = False
    try:
        _ = s.eq_refl(s.base(), old)
    except JudgmentError as e:
        rejected = e.kind == LibErrorKind.KERNEL
    assert rejected
    # Recovery recreates the constant; old cannot be revived.
    fresh = s.prop("temporary")
    assert s.eq_refl(s.base(), fresh).statement().same_as(fresh == fresh)
    print("KERNEL: rebuild discarded handles, or retain them in commit")

    # 4. Using a fixed local variable in a sibling frame raises KERNEL.
    root = s.base()
    x = s.fix(root, "x", prop)
    y = s.fix(root, "y", prop)
    rejected = False
    try:
        _ = s.eq_refl(y[0], x[1])
    except JudgmentError as e:
        rejected = e.kind == LibErrorKind.KERNEL
    assert rejected
    valid = s.eq_refl(x[0], x[1])
    closed = s.forall_intro(x[0], valid)
    assert len(closed.hypotheses()) == 0
    print("KERNEL: prove in the local's frame, then generalize")

    # 5. Exhausting the session work allowance raises LIMIT.
    rejected = False
    try:
        _ = prove_with_budget(1)
    except JudgmentError as e:
        rejected = e.kind == LibErrorKind.LIMIT
    assert rejected
    assert prove_with_budget(100000)
    print("LIMIT: unfinished; a rebuilt request with more work succeeds")


if __name__ == "__main__":
    main()

Run from the repository root PYTHONPATH=bindings/python:docs/examples/python pixi run python docs/examples/python/troubleshooting.py

Output

NO_MATCH: declare a fact before looking it up
WRONG_KERNEL: use the owning session, or rebuild in the receiving session
KERNEL: rebuild discarded handles, or retain them in commit
KERNEL: prove in the local's frame, then generalize
LIMIT: unfinished; a rebuilt request with more work succeeds

Common runtime errors

Error kind and symptom Cause How to fix
NO_MATCH from fact(name) Name is not registered yet, or a checkout / rollback rewound past it Declare or prove it first, or list registered names with find(prefix).
WRONG_KERNEL You passed a handle created by a different Session Use the session that owns the handle, or move checked results via seal() / Session.open() or reuse().
KERNEL (stale handle) Handle came from a discarded transaction, an unretained commit, or a rolled-back snapshot After tx.commit(...), switch to the replacement handles on Retained. Rebuild discarded scratch terms from retained inputs.
KERNEL (out-of-scope local) A fixed variable was used outside its frame (for example, in a sibling branch) Finish the step inside the frame that fixed the variable, then generalize with forall_intro or discharge with imp_intro.
KERNEL or SHAPE from exact / change / convert Your evidence proves a different proposition, or the terms are not definitionally equal Compare proof.target() with step.statement(). Unfold opaque definitions explicitly or prove an equality step.
KERNEL or SHAPE from use Missing, misordered, or incompatible type arguments Check fact.type_params() and pass explicit type arguments in order.
SHAPE from intro / intro_var Called intro on a ∀, or intro_var on an implication Use intro("h") for P → Q / ~P, and intro_var("x") for ∀ x, ....
SHAPE from fix / bound_var Name is already bound at another frame or type, or starts with · (reserved) Pick a fresh variable name.
SHAPE (state precondition) Called snapshot() or fork() with an open transaction, or closed an outer transaction before an inner one Close inner transactions in LIFO order before snapshotting or forking.
LIMIT Session work allowance, Budget, or memory cap ran out The result is unknown, not false. Add work with add_work, pass a larger Budget, or raise set_memory_limit.
BAD_HANDLE (prebuilt core) Used a handle after it was freed or consumed (such as a finished Proof or Transaction) Stop using a consumed value after finish(), commit(), or discard().
BUSY (prebuilt core) Two threads called the same Session, object (Library, ScalarProfile), or Budget at the same time Serialize calls per session/object/budget, or give each thread its own Session.
CONFLICT (StoreErrorKind) Another writer published a newer library version since lib.change() opened Call change.rebase() and retry change.publish().

See the library error reference and kernel error reference for the full lists of error kinds.

Semantic notes on refusals and transactions

A refusal does not establish negation

If rfl() or change(...) fails, conversion (under the permitted unfolding set) did not equate the two terms; it does not prove they are unequal. A LIMIT error indicates only that the budget expired before the check completed. Increase the session allowance (work or add_work) and retry.

Transaction commits invalidate unretained handles

When tx.commit(expressions=[...], facts=[...]) succeeds, named theorems remain registered in the session, while handles allocated inside tx become stale unless explicitly retained. Replace them with the handles returned on Retained (see Lesson 5.1: Scoped work).

Build and environment issues

Symptom What to check
pixi not found Install Pixi and open a new shell with pixi on PATH.
mojo not found Run Mojo through pixi run --locked ... from the repository root (or with --manifest-path).
Python raises ImportError mentioning ABI or generator hash The prebuilt .so / .dylib is out of date relative to the generated client. Rebuild with pixi run build-core (and pixi run build-core-store if using Store).
Store call raises UNSUPPORTED in Python Python loaded libjudgment instead of libjudgment_store because Store was not built or is stale. Run pixi run build-core-store.
unable to locate module 'judgment' (Mojo) Use pixi run core-run PROGRAM.mojo for the prebuilt client, or pass -I src / -I build for direct-package builds.
Locked install reports manifest mismatch Keep pixi.toml and pixi.lock from the same repository commit.

When reporting an issue, include the Git commit hash, OS (Linux or macOS), the command you ran, the error kind and message, and a minimal reproducer using the public API.

judgment v1.0.0 for Mojo 1.2 · Apache License 2.0 with LLVM Exceptions · Source on GitHub