Skip to content

Registration groups, source retargeting, and state-passing handlers #738

Closed

Description

When a DoxReloaded button moves to a new parent, it removes its old source-bound handlers and registers new ones. That code (a List<MessageRegistrationHandle> plus a RemoveRegistration loop) appears 3 times: UnityButton.cs:268 and :454-488, MoveAnimationHandler.cs:69 and :138-144, ButtonSpriteInitializer.cs:45 and :112-146.

Handler fields in 4 files are cached with the comment "Converted once: a reparent listens again, and each conversion would allocate."

3.3.0 offers RemoveRegistration and UnregisterAll only (MessageRegistrationToken.cs:1425, :2066). Churn cost is tracked in #502.

Ask:

  • A disposable token.CreateGroup() whose Dispose removes every handle in it.
  • token.RetargetSource(handle, GameObject newSource).
  • A (TState state, static handler) registration overload, so a handler needs no capturing delegate.

Why: pooled and reparented objects are common, and each one tracks handles by hand.

From Ambiguous-Interactive/DoxReloaded#1172.

DISCLOSURE: LLM-GENERATED TEXT

Activity

  1. wallstop commented on Nov 11, 2026

    @wallstop
    CollaboratorAuthor

    Contract investigation begins (2026-11-11). Baseline: current token supports individual removal and whole-token cleanup, but has no group, source-retarget or state-passing overloads. Question: can pooled/reparented owners express these operations without application-owned handle loops or capturing handlers, while preserving frozen dispatch and retryable cleanup?

    Proposed acceptance contracts for the isolated candidate:

    • token.CreateGroup() returns a reference owner. group.Add(handle) enrolls a registration belonging to that token and returns the handle. Duplicate enrollment is harmless. Disposal removes all enrolled registrations, continues past cleanup failures, retains failed obligations for retry, and becomes idempotent only after successful cleanup. Adding after disposal starts is rejected. Unrelated handles remain active.
    • RetargetSource keeps the handle, handler, priority and token ownership for a source-bound broadcast handler/post-processor. A disabled token changes its staged source only. An active token moves that registration; old in-flight callbacks keep their original binding/diagnostic source, and nested/later emissions observe the new route. Stale/foreign/non-source handles are rejected without changing registrations. Same-source retarget is a no-op. Registration/teardown failures must preserve explicit retryable ownership and avoid duplicate activation.
    • State-passing handler overloads accept explicit state plus a reusable/static delegate for all ordinary route kinds, including source-bound/target-bound and context-free routes. State binding is a registration cost, not a promise of allocation-free registration. Steady-state dispatch must remain allocation-free; state/callback exceptions and teardown follow existing token behavior.

    RED: compile/behavior probes against the baseline production API. GREEN: parameterized public-behavior tests, reentry/failure/cleanup/stale-handle/diagnostic-origin tests, portable full scopes and Unity screening. Compare exact previous identities/outcomes and preserve failures. Stop on ownership ambiguity, inventory loss or unexplained allocation changes. Evidence: ignored .artifacts/session502/groups and progress/session-502.md. This comment opens investigation; no implementation or closure is claimed.

  2. wallstop commented on Nov 11, 2026

    @wallstop
    CollaboratorAuthor

    Private screening update: the group API has 25 passing portable cases, including a real RED/GREEN reentrant-ownership regression. When a cleanup callback disables and re-enables its token, removal can succeed while a newly accepted cleanup remains under the old handle. The group now retains that obligation for its next disposal pass instead of losing group ownership.

    Explicit-state bindings now have 51 passing portable cases across all five route shapes with and without post-processing. They cover copied struct state, shared reference state, null state, null-handler rejection, independent bindings to one static callback, selective removal, Enable replay and whole-bus retargeting. Registration creates an adapter/delegate; no zero-allocation registration claim. Native and dispatch-allocation checks remain pending.

    The source-retarget contract is being screened next. It changes the staged source while each already accepted callback retains its immutable invocation binding. Same-source moves are no-ops; unsupported/stale handles return false. A move of the registration currently being accepted by a custom bus throws before mutation because its cleanup handle does not exist yet; moving a later queued entry remains supported. Reentrant token disable/removal takes precedence over activation. Cleanup accepted after a cancellation remains reachable through the original handle for a subsequent public cleanup pass. Failed new-source activation restores old staging and attempts old-source recovery; both failures must be reported if recovery also fails. No public push, native qualification or issue completion yet.

  3. wallstop commented on Nov 11, 2026

    @wallstop
    CollaboratorAuthor

    The private candidate now passes 122 focused portable cases: group ownership (40), explicit state (51), and source moves (31). Two GameObject overload cases and 20 Unity allocation rows still need native execution.

    Failure analysis found three concrete classes: a group could discard ownership before an in-flight acceptance returned its cleanup; final late cleanup could leave empty-token diagnostic history; and checked compilation could overflow when validating a non-token handle with slot -1. The candidate retains pending ownership, clears diagnostics after the last orphan cleanup, and uses an explicit unchecked bounds conversion.

    Retained causal observations under .artifacts/session502/groups/ include 50 fresh-process reproductions for the ownership and diagnostic failures, plus 50 checked-build overflow reproductions. Fixed immutable observers pass 10 fresh processes. Controls remain green. No test thresholds, skips, retries, or timeouts changed. The controlled ownership reversion is a minimal source mutation, not a historical parent.

    An intermediate full run passes 1,339 generator, 1,867 docs, and 36,443 portable runtime cases. Actual production extraction proves all 442 earlier snippet bodies remain covered despite shifted ordinal names. Final qualification now includes six more registration-family cases, four real-API guide guards, and two checked-build guards: expected totals are 1,339 / 1,873 / 36,449. The full tracked source manifest is compared before and after that run.

    No public branch or PR yet. Unity allocation, lifecycle, all-version CI, container, and final review remain acceptance gates. No throughput or registration-allocation improvement is claimed.

  4. wallstop commented on Nov 11, 2026

    @wallstop
    CollaboratorAuthor

    The final pre-native candidate passes 1,339 generator, 1,873 docs, and 36,449 portable runtime cases, retaining all earlier cases and outcomes. Full npm passes 1,481 Node plus 100 Python cases. Strict docs build on Python 3.11 and 3.13. Actual tarball validation passes at 379 entries.

    The first native focused run found one real Unity-only defect: 123 cases passed, but the null GameObject source case threw inside InstanceId conversion. The new overload promised that null selects EmptyId; the existing general Unity conversion dereferences its input. Fifty actual native API calls reproduce the same null failure, while all fifty explicit EmptyId controls pass. These are repeated calls with fresh token/bus/LeakWatcher in one editor process, not fifty editor processes.

    The candidate now handles null before conversion. The fixture also constructs its expected empty identity explicitly rather than repeating the invalid null conversion. Delivery/count assertions are unchanged, and a dated remark records the cause. Ten actual native calls and ten EmptyId controls pass after the fix. The full focused native run and full managed checks are being repeated. Original failed result and cleanup evidence remain at .artifacts/unity-mcp/s502-subscription-focused.json; causal calls and patch are under .artifacts/session502/groups/native-null-* and null-fix.patch.

    A transient Pipeline socket disconnect after the initial refresh is retained separately. Fresh passive state, loaded new symbols, newer assembly timestamps, and a compiler-error-free bounded log tail establish the subsequent native run used the candidate. No transport workaround, skipped test, threshold change, or native performance claim.

  5. wallstop commented on Nov 11, 2026

    @wallstop
    CollaboratorAuthor

    Delivered in the 4.0 source through PR #744, merged as e60d23fe29ff51222b09c5fd2a1bfa0e2998a5fe.

    The change adds selective registration groups, stable source moves, and explicit-state callbacks. Cleanup remains retryable after failure or reentrant cancellation. Source moves follow the bus owned by accepted cleanup and preserve enabled state after nested failures. The ownership guide is live; its site and packaged-README repository link both return HTTP 200 with the final examples.

    All eight final-head workflows passed at 644c3e2e: static checks, both containers, all four supported Unity versions in Editor/PlayMode/IL2CPP standalone, performance, formatting and docs. Every licensed job completed cleanup and runner completion. CodeRabbit approved that exact head after the 36-file behavior review and the unchanged 92-file formatting bridge; all eight threads are resolved. The squash merge preserves the exact qualified source tree.

    Local qualification passes 1,339 generator, 1,879 documentation and 36,528 portable runtime cases; native Runtime passes 31,194 plus the same existing skip, bounded Editor 1,015 plus the same skip, and 20 warmed explicit-state emission cases remain zero-GC. Earlier case inventories remain, with causal frozen failure/recovery controls retained. Registration costs and throughput improvements are not claimed. This source merge does not publish 4.0 or qualify the separate manual shipping-fidelity matrix.

    Post-merge verification also passed: all four Unity versions and modes, both performance suites and their cleanup gates, static CI, containers and documentation. All 12 per-version/mode report pairs preserve exact case names, outcomes, labels, skip reasons and multiplicity; all 203 feature cases pass in each PlayMode and IL2CPP report. The 24 report archives match GitHub's digests. Established automation then changed only the generated performance page/baseline in befd8c55; its static CI and documentation deployment passed too. No PR remains open. Local final receipts: pr744/postmerge-ci/case-inventory-comparison.json and final-remote-gate.json.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions