Combining --report-cinderx and --report-glean panics and leaves a partially-written cinderx report
Describe the Bug
Passing --report-cinderx and --report-glean to a single pyrefly check panics, and the failure is worse than a crash: the cinderx side is left partially written, with a types/ directory but no index.json or class_metadata.json beside it. A consumer that only checks for types/ will read that as a successful run over a smaller codebase.
Either flag on its own is clean. The order of the two flags makes no difference.
Version: pyrefly 1.2.0 (via uvx [email protected]), macOS arm64.
Steps to reproduce
mkdir /tmp/pyrefly-repro && cd /tmp/pyrefly-repro
cat > mod.py <<'PY'
class Widget:
def apply(self, n: int) -> int:
return n + 1
def go(w: Widget) -> int:
return w.apply(1)
PY
pyrefly check --report-cinderx ./c --report-glean ./g .
Observed
ERROR Thread panicked, shutting down: panicked at pyrefly/lib/report/glean/convert.rs:1699:45:
called `Option::unwrap()` on a `None` value
PANIC Sorry, Pyrefly crashed, this is always a bug in Pyrefly itself.
Exit code 101. Afterwards:
./ccontainstypes/only —index.jsonandclass_metadata.jsonare missing./gis empty
Each flag alone on the same input exits 0 and writes its full output: ./c gets class_metadata.json, index.json, types/; ./g gets its Glean file.
Expected
Either both reports are written, or the combination is rejected up front with a message. A partially-written report directory is the part that bites, since it is indistinguishable from a complete one unless a consumer happens to check for the sidecar files.
Possible cause
Guessing from the source rather than from a build, so treat this as a pointer rather than a diagnosis: the panicking line looks like let ast = &*transaction.get_ast(handle).unwrap(); in pub fn glean(...). get_ast is retained only at Require::Everything (keep_ast, in pyrefly/lib/state/require.rs), so if the cinderx report requests a lower Require level and the two reports share one transaction's require levels, the Glean converter would find no AST to read. That would also explain why order does not matter.
Context
We run both reports over the same tree from a code-mapping tool — one for a per-expression type join, one for a symbol/reference index — and currently pay two full pyrefly check invocations because of this. Happy to test a fix.
Thank for reporting this! Would you mind sharing a bit more about what your are trying to do with the data? These features were not really built with the intention of working in concert IIRC. If we have a better idea of your use case, we might be able to consider a larger user story beyond just fixing the bug here.
Thanks — happy to explain.
I maintain a tool that builds a queryable map of a codebase — what calls what, which model attribute a screen reads, which guard sits on which endpoint — so that AI coding agents can navigate a project instead of grepping it. It is rebuilt on every run rather than stored, so the cost of a scan is the thing that constrains it.
Two of its layers both come from pyrefly over the same source tree, and they answer different questions:
-
--report-cinderxgives expression-level types, which is what lets an attribute access be attributed to the class that declares it. That is the cut a name-keyed scan cannot make, because the same attribute name is declared by many classes. -
--report-gleangives fully qualified declarations and references that carry their enclosing definition. That is what tells apart a method name several classes declare, which a bare-name reading folds into one.
Neither substitutes for the other, and I need both over the same tree. Because they crash together I run pyrefly twice, and that second pass is the single most expensive step in the whole scan.
On the wider story: what I actually want is one resolved-reference export for Python that external tooling can consume — qualified declarations, references carrying their enclosing definition, and expression-level types. TypeScript has SCIP for exactly this, and as far as I could find Python has no published equivalent; these two reports between them are the closest thing that exists. If that is a direction you would consider, a single stable export would be worth more to me than the two flags merely coexisting.
On the bug itself: either flag alone is clean on 1.2.0. Together the panic is at convert.rs:1699, and it takes the cinderx side down with it — the run leaves a types/ directory with no index.json beside it, which reads as a usable report right up until the join fails.
This context helps a lot - your use case caught my attention. I turned it into an RFC here for further discussion to see if there would be broader interest to build out the feature you requested: https://github.com/facebook/pyrefly/discussions/4692.
I am attempting to one-shot your bug, but if I get over my skis I will leave it to a team member to pick up.