flua-bug-updateView-alias.md).Proposals are ordered by time saved, not by implementation cost. P1 and P2 are the big ones; P3–P5 are cheap and mostly docs.
Why. The aliasing bug surfaced as the single line
Callback error: lost reference in the QA log. The Python traceback
(lua54.pyx frames + the failing flua call site) was invisible without
patching bindings.py. Diagnosis required bisecting the payload by hand and
pickling it for offline replay — several hours of monkey-patching that a
flag would have collapsed into one run.
Spec.
--debug:bridge=true (or --trace-bridge), usable via the
--%%debug:bridge=true directive and flua -D bridge alike.api_call
(i.e. the _PY.api path) — or any lua.table_from conversion — flua
must:
1. Log the full Python traceback (all frames, not truncated) to the
normal log and to the --log json stream as a structured field
(traceback_python), so the JSON log is machine-parseable.
2. Dump the offending payload to a deterministic file:
/tmp/flua-bridge-fail-<unix-ts>.json (fallback to .pkl if the
payload contains non-JSON types, with a log line stating why).
The dump happens before the exception propagates into Lua.
3. Print one summary line naming the file and the Lua-visible error:
bridge error: lost reference @ GET /devices?parentId=5000, payload dumped to /tmp/flua-bridge-fail-1729890000.json.Where. The table_from call sites in src/flua/bindings.py
(api_call, api_hc3, device_for, …). Wrap once behind a helper so all
sites share the behavior.
Agent value. Run once → load the dump → ddmin the structure → root cause. No manual instrumentation, no backups.
Acceptance criteria.
--debug:bridge produces a
log containing the full lua54.pyx traceback and a dump file whose
table_from(recursive=True) raises in a fresh LuaRuntime.Why. The handshake bug ("connects, no events") was invisible from
outside: flua's client buffered the auth_required frame that arrived in
the same TCP segment as the HTTP 101, then waited for a recv that never
came. The QA-side debug channel could not see the client's buffer or frame
boundaries; diagnosis required reading websocket.py and building a custom
test server.
Spec.
--debug:ws=true.buffered N bytes after connect when the response contains more
than the HTTP headers (the exact signal that would have exposed the
bug in one run);auth/token payload contents in the trace.Where. src/flua/websocket.py, gated on the same debug-flag plumbing
as --debug:http.
Acceptance criteria.
EchoWsServer(initial_frame=…) fixture added for the 0.1.86 regression
test) with --debug:ws logs the buffered-bytes line and the parsed
frame without any QA-side code.flua --tool state)Why. "Where did this object get aliased into the store?" required
identity scans over state.devices and route replay via undocumented
Python imports (flua.api.state.SimState, flua.api.request.ApiRequest,
route functions). Agents will keep needing this entry point; it should be a
tool, not folklore.
Spec.
flua --tool state [--db file.json] [--aliases] [--verify-tree]:--aliases: walk all state containers and report every object
reachable from more than one path, printing all paths (the
STORE-DUP output this session hand-rolled);--verify-tree: exit non-zero if state contains shared references or
cycles (see P7); prints the offending paths.SimState + ApiRequest(segments=[...], query={}, body=...) + the route
function, with one worked example.Where. New tool under src/flua/tools/ (or extend an existing state
tool); docs in USAGE.md.
Acceptance criteria.
--aliases prints both paths
(properties.uiView[1].components[0].options and
view.presetSelector.options) with no QA running.Why. "lost reference" is opaque: the installed lupa ships no .pyx
source, and the root cause required fetching lupa 2.6 from GitHub and
reading py_to_lua_table. A mapping from lupa error → likely cause → flua
invariant violated would have pointed at aliasing immediately.
Spec.
| lupa error | cause | flua invariant |
|---|---|---|
lost reference |
payload contains a shared (aliased) or cyclic structure; or a freed/lapsed lupa object crossed the bridge | engine state and bridge data are JSON trees; no lupa proxies in engine data |
cannot mix objects from different Lua runtimes |
object passed between runtimes | one runtime per QA |
TypeError: cannot convert … |
non-plain type reached table_from |
lua_to_python output is plain JSON types |
_plain_key/_plain_value
sanitization, _fresh_copy, plugin_update_view deepcopy).flua-troubleshooting skill (.github/skills/) with the
agent loop this session converged on:
1. enable --debug:bridge (P1) and rerun → get traceback + dump;
2. load the dump in a fresh LuaRuntime, minimize (ddmin-style) to
the smallest failing structure;
3. compare against the cheatsheet table → identify the invariant
violated;
4. locate the violating route/state write and fix it; add a regression
test.pip install --force-reinstall flua==<version>; discover the live path
with pip show flua.Acceptance criteria.
--log jsonWhy. --log json already exists and is the agent-friendliest
interface, but bridge errors arrive as a one-line message with no
structured fields.
Spec.
Callback error / Error in bootstrap lines carry:
error_type (the Python exception class), error_path
(api_call@/devices?... or similar), traceback_python (full string,
when available — free if P1 lands), and dump_file (when P1 produced
one).Where. Logging layer for Lua callback errors; ties into P1.
--verify-tree)Why. The aliasing bug would have been self-reporting at write time:
plugin_update_view stored one list object into two state paths, and
nothing noticed until table_from failed ~20 minutes later in QA terms.
The fix (0.1.87) adds a copy.deepcopy at one site, but the class of bug
is "state stopped being a JSON tree" — worth an invariant.
Spec.
state.devices/variables; report objects reachable from
two paths or cycles with both paths. Identity-scan cost is O(state) and
sim state is small.flua --tool state --verify-tree
(P3) plus a manual _FLUA.verifyTree() for in-QA calls.bindings.py, one flag; highest value per line.--debug:http.