Skip to content

refactor(unload): chain-aware restore for per-load ownership records #585

Description

@ss-o

Current limitation

Zi keeps runtime ownership records (functions, widgets, key bindings) per plugin ID and restores each plugin from its own snapshot on unload. #582 (squash 8bbd62c on next) fixed the same-plugin part of #113: a repeated load of one plugin keeps its records when no other plugin took a recorded widget or binding over in between. Three cases remain, all recorded on #113:

The root cause is that unload restores from per-plugin snapshots, not from an ownership chain, so it cannot tell who held a widget or binding immediately before the instance being removed.

Proposed improvement

Design, before any code, a chain-aware restore:

  1. A minimal per-load identity (for example a load counter stored with each record) for function, widget and bindkey records.
  2. An ownership chain per widget and per (keymap, key) binding: an ordered list of (load instance, previous value) entries, so unloading any instance in any order restores the immediately preceding live owner and relinks the next one.
  3. Detection of changes made without records: compare the recorded previous value with the live value at load and unload, and decide whether the chain treats such a change as a new owner or stops restoring.
  4. Compatibility: single-load behaviour, the hook ownership contract from fix(unload): track and remove plugin-owned hook callbacks #108, and the same-plugin behaviour pinned by tests/repeated-load-ownership.zsh from fix(unload): keep ownership across repeated loads of one plugin #582 stay unchanged; the public-contract manifest is checked for output or ordering changes.

Deliverable of this issue: a written decision (comment or ADR draft) with the data model, the unload algorithm, the test matrix (two-plugin widget and bindkey chains, interleaved same-plugin loads, out-of-order unload, linked main keymaps from #583, user change between loads) and an effort estimate, for the maintainer to approve before implementation. #113's remaining acceptance criteria move here; #113 can close once this design is delivered and implemented, or once the maintainer descopes it.

Self-service

  • I would be willing to implement this improvement.

Project policies

Activity

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

    area:ziZi core behavior, APIs, or documentation.status:triageAwaiting initial review or classification.type:maintenanceNon-feature maintenance, cleanup, or org work.

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions