8000 search: render an option's default and example, by forcing them at render time · Issue #305 · nixidae/nixidae · GitHub
[go: up one dir, main page]

Skip to content

search: render an option's default and example, by forcing them at render time #305

Closed

Description

@Lillecarl

What is missing

The detail pane of pynix search draws an option's name, type, description
and declarations. It draws no default and no example, which are the two
fields a reader most often wants after the description.

Why they are absent, and what that reason really covers

pynix/_options.py excludes them on purpose, and the module docstring gives
two reasons:

  1. The walk returns one Nix list, forced in one JSON pass. A single
    option whose default cannot evaluate aborts the whole fetch of all 24 941.
  2. A tryEval/deepSeq guard does not help, because tryEval "only
    prevents errors created by throw or assert", and an
    "attribute X missing" failure is a builtin-generated error that it does
    not catch.

Both are true, and both are about the bulk pass and about catching
inside Nix. Neither reaches a force of one option at render time, caught
on the Python side.

The measurement

One option at a time, through the bindings:

option default outcome cost
default = false; example = true; forced False, and True 0.7 ms
default = throw "nope"; forced caught as ThrownError --
default = ({}).absent; forced caught as EvalError --
default = { a = 1; b = [ 1 2 ]; }; forced {'a': 1, 'b': [1, 2]} 0.6 ms

The third row is exactly the failure that tryEval cannot catch. Across the
binding boundary it is an ordinary Python exception. The eval session stays
usable after both failures
, verified by reading a good default afterwards.

So the field can be forced per option, at the moment the pane draws it, and
an option that cannot answer costs its own pane a line and nothing else.

The blocker

No evaluator is alive while the interface runs. _impl/search.py opens
one inside async with eval_session(...) at line 309 and closes it before
browse() at line 257. On a warm cache _build_index never runs, so no
session opens at all -- which is the whole point of the cache.

The decision this needs

Rendering a default needs a session that outlives the index build. Two
shapes, and the difference is what a reader waits for:

  1. Open it when the interface opens. Simple. It pays the evaluation on
    every search, including the warm ones the cache exists to make instant.
    Measured on one NixOS configuration: about 5 s.
  2. Open it when a pane first needs a default. The first selection that
    wants one pays; every search that only reads names and descriptions stays
    instant. It needs the session to be built inside the interface, under a
    budget, and a pane that says it is still resolving.

A live evaluator also answers a second want: showing the configured value
of the selected option, not only its declaration.

Acceptance

  • The pane draws default and example when the option declares them.
  • An option whose default cannot evaluate says so, and costs no other
    option anything.
  • A search that reads only names and descriptions is no slower than now.
  • Tests cover the plain case, the throw case and the
    attribute-missing case.

Metadata

Metadata

Assignees

No one assigned

    Labels

    source: nanopynix

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0