8000 gini system documentation by mohd-adnaan · Pull Request #86 · citelab/gini · GitHub
[go: up one dir, main page]

Skip to content

gini system documentation - #86

Merged
anrl merged 10 commits into
masterfrom
adnaan/dev
Sep 10, 2026
Merged

anrl merged 10 commits into
masterfrom
adnaan/dev

Conversation

@mohd-adnaan
Copy link
Copy Markdown
Collaborator

claue.md: wrote the project context file: lineage, architecture, run pipeline, house style, & an honest inventory of what works / is parked / is broken(it will save tokens)
fixed a segfault class : every ui/ background call let a worker-thread closure own the last reference to a QWidget, so PySide destroyed widgets off the GUI thread; added run_off_gui() and swept 74 sites across 20 files. Measured 20/30 crashes → 0/30.
added CI (.github/workflows/tests.yml): the repo had three publish workflows and nothing running its 3,389 tests; now runs on every push/PR, Python 3.10 + 3.12, headless.
took three red CI runs to land it: twice I blamed apt package names when the real cause was apt-get update (both exit 100), once I added a file and didn't re-run the suite.
finished the July Zig removal: deleted dead build.zig, 6 tracked 1-byte .zigobj.o.tmp files, 2 stale wheels; widened the .gitignore pattern that let them through.
rewrote ARCHITECTURE.md — the README calls it "the full map" and it still described zig build, "35 passing" tests, and a layout that moved in August.
found upstream was 50 commits ahead and merged it — git status said clean, nothing local hinted at it.
deferred to upstream on the overlap: they'd found the same widget bug independently and fixed it better (LivePollMixin, join-based); trap_lab.py is now byte-for-byte theirs.
fixed two tests that only ever passed on a Mac: docker_state() had an injectable run but called shutil.which first, so five tests asserted "Docker is healthy" when they meant "Docker is installed"; both pre-existing upstream, found by the new CI.
fixed a Linux-only thread leak : ControlServer.stop() relied on closing a socket to wake a blocked accept(), which is BSD behaviour, not portable.
verified on both platforms — Linux/no-Docker 3367 passed, macOS/Docker 3370 passed, 0 failed either way.

mohd-adnaan and others added 10 commits September 9, 2026 00:06
A new developer inherits this repo with no way to tell the working parts from the parked ones, and
no way to tell either from the ones that were designed and never built. The docstrings are excellent
and the commit messages are better than most, but neither answers "where am I" — and the one
document that tries, ARCHITECTURE.md, still describes a Zig build that was removed in July.

So: the lineage (GINI 3 -> gini5 -> the 2026 rewrite, which landed as one squashed commit and
therefore has no design history to read), the run pipeline, the four container images, the house
style, and — the part that took the longest to establish — an honest inventory of the state.

Three things in that inventory are worth naming here, because they are not discoverable by reading:

  * app/features.py already IS the parked-capability spec; ten capabilities are off because the
    Teaching Center v1 rewrite removed the v0 endpoints, and each entry lists what must come back.
  * docs/LEARNER_MODEL_DESIGN.md specifies domain/learner.py, which was never written. The Twin's
    consumption seam duck-types against a shape nothing produces.
  * Six design documents cited in module docstrings are not in this repo at all.

Nothing here is new work or a change of direction. Where the tree and a doc disagree, this file
says which one the tree agrees with, and leaves both alone.
`pytest tests/test_trap_lab.py` crashed 20 times in 30 runs, always somewhere else: a bus error
here, a segfault there, in a different test each time, and never when the crashing test ran alone.
That shape says memory, not logic.

It was ownership. Every background call in ui/ was the same four lines —

    def work():
        txt = self._src()
        if not self._closed:
            self.ready.emit(txt)
    threading.Thread(target=work, daemon=True).start()

— and `work` closes over `self`. A parentless dialog is owned by Python, so once the GUI side drops
its last reference (a lab window replaced, a test function returning) the closure is the only owner
left. The widget's refcount then reaches zero while the WORKER THREAD's frame is being torn down,
and PySide destroys a QWidget off the GUI thread, which Qt forbids. Measured before the fix: 30 of
30 open/close cycles destroyed the widget on a worker thread, 0 on the GUI thread.

Worth saying plainly, because the guard looks like it covers this and does not: `self._closed` was
never the problem. It is a Python attribute and reads perfectly well after the C++ object is gone.
Nor is a weakref inside the closure a fix on its own — dereferencing it to emit re-creates a strong
reference on the worker thread, and the teardown can land there instead.

So `run_off_gui` pins the owner in a GUI-thread registry for the duration of the call, and the
worker releases it by emitting to a singleton reaper that lives on the GUI thread. The worker drops
its own reference BEFORE asking for that release, so no interleaving leaves it holding the last one.
Exceptions are caught rather than propagated for the same reason and no other: an escaping exception
keeps a traceback, a traceback keeps the frame, and the frame is the reference being got rid of.

All 72 call sites across 20 files, because a fix applied to the one file that happened to crash
leaves the same landmine in nineteen others. The sites are otherwise untouched — same thread, same
daemon semantics, same guards inside `work` — so the diff is one line each, and `threading` is now
imported by nothing in ui/ but worker_host itself.

It lives beside WorkerHost as rule 4. Rules 1-3 are the same lesson learned about QThread; this is
the plain-thread half, and keeping them apart is how the next person re-derives one of them.

After: 0 crashes in 30 runs, and the full suite green — 2934 passed, 22 skipped, 0 failed
(unchanged pass count, so nothing regressed). Verified on Python 3.13.13 / PySide6 6.11.2.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
There are three workflows in this repo and all three publish. Nothing has ever run the suite
automatically, so the only gate was `release.sh` running it on the machine of whoever cut the
release — real, but once per release and in one place. Everything merged between two releases was
covered by whoever remembered, and pushing a tag then ships to PyPI on the strength of that.

The crash fixed in the previous commit is the argument for this one. It was a segfault that
appeared roughly one run in three, in a different test each time, and never in the test that
actually caused it. That is precisely the class of bug a person does not catch by running the suite
once before a release, and precisely what a job that runs on every push does catch.

Two lines in here are load-bearing rather than boilerplate, so they are commented where they sit:

  * `fetch-depth: 0`. A shallow clone has no tags; setuptools-scm then builds gini-core as
    0.1.dev1; that does not satisfy gini-toolkit's `gini-core>=6.3.2`; and pip resolves the floor
    by downloading the PUBLISHED core over the top of the checkout. CI would have gone green
    against PyPI's domain model instead of the branch's, and said nothing. It is the same trap
    dev.sh already exists to keep humans out of.
  * installing through `./scripts/dev.sh install` rather than a hand-written pip line, so the
    command the README gives contributors is the command CI proves still works.

Checked rather than assumed, because a workflow that is red on day one teaches people to ignore it:

  * every file parses under 3.10 syntax, and none of the 3.11/3.12-only APIs are used, so the
    floor leg of the matrix should pass;
  * the three tests that mention QtWebEngine only parse import nodes — they never construct a
    QWebEngineView — so no Chromium system libraries are needed;
  * a runner has no container runtime, so the expected result is 2931 passed / 25 skipped rather
    than the 2934 / 22 seen locally. Verified by re-running the suite with docker off PATH.

No lint job. `ruff check` reports 746 errors on this tree today; adding it would make the first run
red, and a CI that is always red is one nobody reads. That cleanup is its own piece of work, and a
lint job belongs beside this one when it is finished.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The first run of the new workflow died on `apt-get install`, exit 100, on both matrix legs, before
a single test ran. Exit 100 is apt's "unable to locate package": one of the five names I listed
does not exist on the current `ubuntu-latest` image. I cannot say which — job logs need admin
rights on this repo and the annotations only carry the exit code.

Guessing a different name would have been the obvious move and the wrong one. The names are not
the point, they drift (the t64 transition renamed a batch of them in 24.04), the runner image
moves underneath this file without notice, and I have no way to verify a guess except by pushing
again. An
8000
y name I picked would be right until it was not.

So the step no longer asserts a list of packages. It tries each, prints the ones that are missing,
and cannot fail the build; the gate moves to a new step after the install that asks the question
actually at stake — does Qt start? — and fails naming the missing .so, which is the thing you need
in order to fix it. A rename now costs a line of log output instead of a red build, and a genuinely
absent library still stops the run, with a better error than apt would have given.

Checked locally rather than by pushing again: every run block passes `bash -n`; the heredoc in the
new step survives YAML dedent and executes (prints "offscreen"); and with a stubbed apt-get that
exits 100 on one package, the loop reports MISSING and the step still exits 0 under `bash -e`,
which is the shell GitHub uses and the exact interaction that broke.

Also printing the runner's PRETTY_NAME, because the first thing the next person will want to know
is which Ubuntu they are actually on.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Second red run, same step, and this time the loop inside it could not have been the cause — a
stubbed apt-get proved locally that a missing package exits the loop cleanly. That leaves the one
command in the step I had not guarded: `apt-get update`.

Which means the previous commit's reasoning was wrong. `apt-get update` also exits 100, not for a
missing package but for failing to reach a single repository mirror — routine on a runner. Exit 100
from `update` and exit 100 from `install` are indistinguishable from outside the log, and with no
admin rights to read the log I read the code I had just written rather than the command above it.

The fix the last commit reached for was still the right shape, only under-applied: guard everything
or guard nothing. So the step now sets `set +e`, reports an unclean update instead of dying on it,
and ends in an explicit `exit 0` so a later edit has to mean it to make this failable. The gate
stays where it belongs, on "Qt starts headless", which asks the only question that matters and
answers it with the name of the missing library.

Simulated both failure modes locally before pushing this time — apt-get update exiting 100 AND a
package missing, together, under `bash -e`: the step reports both and exits 0.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Third red run, and this one was the suite itself — the only part of the workflow that was doing its
job. Two tests in test_packaging.py enumerate `.github/workflows/*.yml` and assert that each file
builds exactly one distribution and that release.sh names it. Both were true when every workflow
was a publisher. `tests.yml` uploads nothing, so both broke.

The tests were right to fire. Their assumption was simply out of date, so they now say what they
mean: no workflow may build MORE than one distribution — still checked across every file, since a
non-publishing one is where a stray second `outdir dist/` would be easiest to add unnoticed — and
there must be at least one publisher per distribution. The release-script rule scopes to publishers,
because a workflow that uploads nothing has nothing to under-report.

`_publish_workflows()` keys on `outdir dist/` rather than a filename convention, so a new publish
workflow is covered the day it lands, and it asserts the list is non-empty: without that, a filter
that matched nothing would turn both callers into loops over an empty list — green, checking
nothing. Scoping a test is how a test quietly stops existing.

Mutation-checked, because changing a test to accommodate your own change deserves proof it still
bites: a workflow building two distributions fails; release.sh dropping a publisher's name fails;
hiding every publisher trips the vacuous-pass guard.

The honest note is on how this was found. It was not a Linux problem and never had been. I added a
file to the repo and did not re-run the suite — three pushes, two of them chasing apt, and the
answer was one command I had skipped on my own machine. The suite is green here now, before this
push rather than after it: 2934 passed, 22 skipped.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Both matrix legs pass at ca38233 — 3.10 and 3.12, apt through suite. Recording it so the file does
not keep describing a workflow whose state is unknown.

The note worth keeping is the one that has nothing to do with workflows: test_packaging.py asserts
over the CONTENTS of .github/workflows/, so adding any file there touches the suite. Adding a file
to this repo can break the tests, not only editing code — which is the whole reason this took four
runs instead of one.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The July revert (0f07f46, "remove Zig, revert to C") took out the build but left its shadow in two
places, and the second one matters more than the first.

The files: backend/build.zig is still here and builds nothing, and six *.zigobj.o.tmp* objects are
still TRACKED under src/grouter — one byte each, and inside the Docker build context. They survived
because .gitignore says `*.zigobj.o`, which does not match a `.tmpXXXXXXX` suffix; the pattern is
now `*.zigobj.o*`. Two v6.0.0 wheels under frontend-ng/dist go with them: `dist/` has been ignored
for a while, but ignoring a path does not untrack what is already in it, and releases have been
built by GitHub Actions for four versions now.

The document: ARCHITECTURE.md is what the README points at for "the full map", and it had drifted
into telling a new reader several things that are not true — build the router with `zig build`, the
gRouter "is still being ported to Zig (Z3/Z4)", a pytest suite of "35 passing", and a frontend-ng
tree with domain/ inside it, which moved to core/ when gini-core was split out in August. A map
that names a build system nobody can run is worse than no map, because it is believed.

So it is rewritten against the tree rather than patched: all three distributions and why the
namespace split forces dev.sh install, the four images this repo builds, the C-not-Zig decision
with a pointer to the reasoning preserved in build.sh, the run pipeline, and the legacy tree with
its "referenced by nothing" claim re-verified rather than inherited. Every number in it was checked
— 71 domain modules, 2,956 tests, ~23k lines of C, 17 manual pages, four workflows — as were the
paths, because the old file's counts are how it lost trust in the first place.

MIGRATION.md is left exactly as it is. It describe
8000
s a rename that never happened and invites its
own deletion, but it is a plan Mahesh may still intend, and that is his call rather than a cleanup.

Suite run BEFORE this push, since removing files can break tests as easily as adding them:
2934 passed, 22 skipped.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
…y overlap

Fifty commits and seven tags had landed upstream since this branch was cut, with no local sign of
it: git status said clean, and the only tell was PyPI's gini-core sitting four minor versions ahead
of the newest local tag.

One conflict, and it is the interesting part. 39ef5c8 shows Mahesh's session found the SAME widget
bug independently, root-caused it more rigorously than I did — isolation rather than inspection,
0/20 crashes with the workers made synchronous — and wrote it up as known issue #17, as a CLASS of
bug across ~18 files rather than one lab. Their remedy is LivePollMixin: `_closed` set first, and
the worker JOINED in stop_polling(), with a weakref plus bounded join for the one-shot catch that
can block ten seconds.

Their fix is better than mine where the two meet, so trap_lab.py here is now byte-for-byte theirs.
A join is a guarantee. It also closes the death mode run_off_gui does not: an emit() into a dialog
that deleteLater() is destroying, where C++ teardown ignores the Python reference I pin. I had
dismissed the weakref approach in an earlier message; theirs is not a bare weakref, and the join is
the part I did not think of.

What this branch still carries is the sweep — which #17 says is needed and which that commit
deliberately did not bundle. It now covers 74 sites including three that arrived with the merge,
and the threads are named after their owner so upstream's new _no_leaked_threads fixture can say
which face leaked instead of "Thread-47". It is a floor under the unconverted faces, not a
substitute for #17's rule, and CLAUDE.md now says so in those words. Whether it merges as-is or
gets redone in the LivePollMixin idiom is a call for Mahesh, not for me.

Every count in CLAUDE.md and ARCHITECTURE.md re-derived afterwards, because merging fifty commits
invalidated all of them: 2,956 → 3,389 tests, 71 → 72 domain modules, 58 → 62 ui modules, 8 → 17
known issues. Both files now carry a note telling the reader to re-derive rather than cite, and the
workflow comment no longer hard-codes a pass count — a number in a comment is a lie with a
timestamp on it.

Suite on the merged tree: 3369 passed, 20 skipped, 0 failed.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The new CI went red on the merged tree, both legs, at the suite. Reproduced in a Linux container:
five failures in test_bootstrap/test_setup and one thread-leak error in test_control. Then checked
the thing I keep failing to check — the same container on plain origin/master, none of my commits —
and got the identical six. They are pre-existing, and CI found them the first time this suite ever
ran on a machine without Docker.

Both are the same species: a test that passes because of what the developer's machine happens to
have, and nothing in the test says so.

runtime.docker_state() takes an injectable `run` and then calls shutil.which("docker") first, which
is not injectable. So a caller injecting a perfectly healthy fake Docker still got "missing" if the
machine had no docker binary, and five tests asserting a healthy Docker were really asserting that
Docker was installed. A partial seam is worse than none, because it looks injected. Absence is now
read from `run` itself: a missing executable already announces itself precisely, as
FileNotFoundError, from inside the seam. shutil is no longer imported there.

The two tests that monkeypatched runtime.shutil.which are rewritten onto `run`, which is a better
test of the same intent — it exercises the mechanism instead of describing how the function is
written — and a third is added to pin the property, so a `which` cannot creep back in without
something failing.

ControlServer.stop() had the same shape one layer down, and its own docstring stated the
assumption: close the listening socket underneath a blocked accept() and "the resulting OSError
ends the thread". That is BSD behaviour, not portable. On Linux the call can stay parked in the
kernel because it entered the wait before the descriptor went away, so two runtime threads
outlived the test and the leak guard caught them. The accept loop now owns a timeout and re-reads
its own flag, which needs nothing from the platform; the close stays, since it also refuses new
connections at once. Accepted connections get settimeout(None) explicitly — a console session must
block, not time out mid-command — and the per-connection threads are named after their socket.

Verified on both, since the whole point is that one machine is not evidence:
  Linux, no Docker (the CI condition):  3367 passed, 23 skipped, 0 failed
  macOS, Docker running:                3370 passed, 20 skipped, 0 failed

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@mohd-adnaan
mohd-adnaan requested a review from anrl September 10, 2026 14:33
@anrl
anrl merged commit 67d1ee0 into master Sep 10, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
6462

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

0