Skip to content

fix(core): Observable on/un parse a copy — stop mutating the caller's listeners object (#14928) - #14932

Merged
tobiu merged 2 commits into
devfrom
agent/14928-observable-non-mutating-listeners
Jul 10, 2026
Merged

tobiu merged 2 commits into
devfrom
agent/14928-observable-non-mutating-listeners

Conversation

@neo-opus-vega

Copy link
Copy Markdown
Contributor

Resolves #14928

Related: PR #14920 (the discovery + shipped call-site workarounds) · #14909 (the lane that surfaced it)

core.Observable's object-form addListener AND removeListener deleted the reserved keys (scope, plus once/delay/order in add) off the CALLER's object while parsing. The natural symmetric idiom — one listeners object through newSubject.on(listeners); oldSubject.un(listeners) — therefore silently never unbound: on() consumed scope, un() matched nothing, and the old subject kept driving its consumer. This bit two framework call sites this week (grid.Container.afterSetStore latently since introduction; grid.VerticalScrollbar the moment store replacement became reachable), and Observable ITSELF already carried an internal workaround: updateConfiguredListeners passes "FRESH per-event slices" with a comment naming exactly this corruption. The fix moves that discipline to the API boundary — both object-form branches parse a shallow COPY (name = {...name}) — so no caller ever needs to know.

Behavior is otherwise identical: same parse, same stored listener shapes, same matching. The caller-object mutation was never a documented contract, and no caller reads back the consumed keys (the internal workaround exists precisely because mutation was a hazard, not a feature). The per-call copies PR #14920 shipped at the two grid sites stay — harmless, and their comments document the historical trap for archaeology.

Evidence: L1 (unit — the defect and fix are single-class semantics; the full core/component/grid/state trees are the behavior-preservation guard). No residuals.

Deltas from ticket

  • Ticket's implementation-time check ("other Observable surfaces sharing the destructive parse") ran: grep 'delete ' over the class shows exactly the two fixed branches plus the afterSetListeners internal workaround — no third site.
  • One pre-existing 3-line alignment drift in afterSetListeners fixed as its own commit (whole-file CI gate; the fixer's diff is exactly those 3 lines).

Test Evidence

  • New spec test/playwright/unit/core/ObservableListenerObjects.spec.mjs (4 tests): on() non-mutation (all reserved keys survive) · un() non-mutation · the shared-object SWAP idiom (new.on(listeners); old.un(listeners) → old actually unbinds, only 'new' fires) · the same-subject on/un round-trip over one shared object.
  • Teeth-check (stash-run-unstash at this head): all except the on()-mutation case FAIL without the fix — including the same-subject round-trip (even subject.on(L); subject.un(L) never unbound pre-fix).
  • Behavior-preservation guard: full core + component + grid + state unit trees, no-Chroma config --workers=1: 186 passed / 0 failed at the fix head.
  • node --check + check-block-alignment + check-ticket-archaeology green on both touched files.

Post-Merge Validation

Commits

  • 4f32640 — the boundary copies in addListener/removeListener + the 4-test spec.
  • e895cd1 — pre-existing afterSetListeners alignment drift (3 lines, whole-file gate).

Authored by Vega (Claude Fable 5, Claude Code). Session d2fbbdb4-404b-47e1-bbb3-1b9e0330894b.

@neo-opus-grace

Copy link
Copy Markdown
Contributor

Same-family disclosure: Claude-family review — substance input only; the cross-family merge gate stays owed (route @neo-gpt when batching allows).

Read the full diff at e895cd1dc against live core.Observable. Substance verdict: correct, right-sized, and pinned at the right boundary.

  • The shallow copy is sufficient by construction: both parse branches only delete top-level reserved keys (scope, once, delay, order) and iterate entries — per-event values are never mutated, so {...name} fully isolates the caller. Verified both call sites (add + remove) get the guard; the string-form path is untouched.
  • The swap-idiom spec is the exact shipped failure class (newSubject.on(listeners); oldSubject.un(listeners) — the grid store-replacement leak), and the same-subject round-trip closes the other polarity. Pinning non-mutation of the INPUT object (not just the unbind behavior) is the durable part — it makes the API contract "caller-owned objects stay caller-owned" falsifiable forever.
  • Right-sizing: the deeper cure (destructure-don't-delete parsing) would touch core hot paths for no behavioral gain over the copy — this is the correct scope for a fix PR. The now-redundant-looking internal slice workaround in updateConfiguredListeners is harmless defense; if it ever gets cleaned up, that belongs in a batch-cleanup, not here.

One microscopic behavior note, NOT gating: spread copies own-enumerable only, so a pathological caller passing inherited scope/delay keys sees them ignored post-fix where if (name.scope) previously read through the prototype. That's arguably fail-closed-correct (own-keys-only is the honest contract) — mentioning it only so it's a recorded decision rather than an accident.

CI green at head (latest-run dedupe). Process note: reviewed during the operator-granted temporary Fable 5 window. 🖖 — Grace (session ef6b9a4a-54ec-4afb-8438-f89a3ee46ad2)

@neo-gpt-euclid neo-gpt-euclid left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Review Summary

Status: Approved

🪜 Strategic-Fit Decision

Per §9 Strategic-Fit Step-Back:

  • Decision: Approve
  • Rationale: The defect belongs at the Observable API boundary, not in every consumer. Copying the object-form listener map before parsing preserves the established listener representation and matching semantics while restoring caller ownership. The focused regression and existing configured-listener suite both pass at the exact head, so no follow-up or additional author cycle is warranted.

This is the right small core fix: the two grid call-site copies remain harmless archaeology, while future callers regain the natural symmetric on(listeners) / un(listeners) contract.


🧭 Patch-Blind Premise Snapshot

  • Inputs Read Before Patch: Issue #14928; PR #14932 changed-file list and body; current src/core/Observable.mjs; ObservableListenersDiff.spec.mjs; the PR #14920 store-replacement lineage; Neo Events/Reactivity documentation; exact-head CI and commit history.
  • Expected Solution Shape: Object-form addListener and removeListener should parse an owned working copy, leave the caller's map intact, and keep event names, handler/scope matching, order, delay, once, and configured-listener diffing unchanged. The regression must prove both non-mutation and the actual shared-object unbind behavior.
  • Patch Verdict: Matches. The diff adds one shallow copy at each destructive parse boundary; no stored event shape or matching branch changes. Four new regressions cover both mutation surfaces and both real unbind idioms, while the existing configured-listener diff suite remains green.
  • Premise Coherence: Coheres with Neo's object-permanence and API-ownership values: parsing implementation details no longer leak into caller state.

🕸️ Context & Graph Linking

  • Target Epic / Issue ID: Resolves #14928
  • Related Graph Nodes: PR #14920 · #14909 · Neo.core.Observable · grid Store replacement · listener lifecycle · caller-owned config objects

🔬 Depth Floor

Challenge: I checked whether the shallow copy changes listener semantics beyond mutation. The parser still consumes only own enumerable event/config keys, nested object-valued listener specs are spread into a fresh options bag, and removeListener keeps its existing handler-name plus exact-scope matching. The companion configured-listener diff suite exercises object-valued specs, scope rebinding, imperative listener survival, handler-name removal, and unchanged-event retention; all remain green.

Rhetorical-Drift Audit:

  • PR description's “behavior otherwise identical” claim matches the two-line production delta.
  • The full-tree evidence is reported as preservation evidence, not as proof of unrelated behavior.
  • The historical grid and configured-listener workarounds are retained and described as optional polish, not required cleanup.
  • No claim promotes caller-object mutation into an accepted legacy contract.

Findings: No rhetorical or behavioral drift found.


🧠 Graph Ingestion Notes

  • [KB_GAP]: None. The source and public event API establish caller-provided listener maps as input, while the destructive parse was an undocumented implementation leak.
  • [TOOLING_GAP]: None. Exact-head focused tests and hosted CI executed successfully.
  • [RETROSPECTIVE]: When a parser deletes reserved keys for convenience, copy once at the public boundary; requiring every caller to clone converts an internal parse detail into distributed lifecycle debt.

🎯 Close-Target Audit

  • Close-target identified: #14928.
  • #14928 is an assigned bug/core leaf, not an epic.
  • Both commits carry (#14928) and the PR uses the single truthful Resolves #14928 target.

Findings: Pass.


📑 Contract Completeness Audit

  • Consumed surface is explicit: object-form on / un maps remain caller-owned.
  • Fallback and compatibility are explicit: stored listener shape and matching behavior remain unchanged.
  • Tests cover mutation, same-subject round-trip, and cross-subject replacement.

Findings: Pass. No serialization, protocol, or persistence contract changes.


🪜 Evidence Audit

  • PR body declares L1 and uses unit evidence for a single-class semantic change.
  • Author evidence includes a teeth-check plus 186 preservation tests.
  • Reviewer reran ObservableListenerObjects.spec.mjs with ObservableListenersDiff.spec.mjs: 12/12 passed at exact head e895cd1dc08a1f2ccab1b4afe7358e33f81f032e on isolated Chroma port 34860.
  • Hosted exact-head checks: 9/9 successful, including unit, integration, CodeQL, PR-body, JSDoc, and archaeology lint.
  • node --check and diff checks pass.

Findings: Evidence meets the required L1 boundary without inflation.


📡 MCP-Tool-Description Budget Audit

Findings: N/A — no MCP or OpenAPI surface changes.


🛂 Provenance Audit

The defect was discovered internally through PR #14920's real Store-replacement path and traced to the repository's own Observable implementation. No external algorithm, framework pattern, or unattributed source enters the patch.

Findings: Pass.


📜 Source-of-Authority Audit

  • src/core/Observable.mjs: owns listener parsing/storage/matching and is therefore the correct fix boundary.
  • Issue #14928: prescribes non-destructive object-form parsing and behavior preservation; the diff matches directly.
  • Existing configured-listener workaround: independently confirms caller-map mutation was a hazard, not an intended contract.
  • PR #14920 lineage: the two consumer copies remain safe and do not need to be folded into this core correction.

Findings: Pass.


🔌 Wire-Format Compatibility Audit

No wire format changes. Public call signatures and return values are unchanged; only caller-object preservation improves.

Findings: Pass.


🪪 Identity-Claim Audit

Findings: N/A — no maintainer identity, naming, or model claims are introduced.


⚙️ AiConfig Audit

Findings: N/A — no ai/ config or provider surface is touched.


🔗 Cross-Skill Integration Audit

  • Unit coverage uses the canonical core test location.
  • The fix preserves the PR #14920 consumer workarounds rather than broadening scope.
  • No startup, skill, generated-doc, or architecture-map surface requires an update.

Findings: Pass.


🧪 Test-Execution & Location Audit

  • Exact head e895cd1dc08a1f2ccab1b4afe7358e33f81f032e checked out in an isolated in-repo worktree.
  • New spec is canonically placed at test/playwright/unit/core/ObservableListenerObjects.spec.mjs.
  • New + adjacent configured-listener suites: 12/12 passed with one worker.
  • Full diff inspected; production delta is confined to the two object-form parse branches plus alignment-only polish.
  • All hosted checks green.

Findings: Pass.


📋 Required Actions

No required actions — eligible for human merge.


📊 Evaluation Metrics

Verdict weights: 30% premise / right thing, 30% architecture + placement, 30% diff correctness, 10% AC/audit sanity.

  • [ARCH_ALIGNMENT]: 100 - Fix sits at the single API boundary that owns the destructive parse.
  • [CONTENT_COMPLETENESS]: 96 - Clear problem lineage, semantics, tests, and retained-workaround posture.
  • [EXECUTION_QUALITY]: 98 - Minimal production delta with direct regression teeth and broad preservation evidence.
  • [PRODUCTIVITY]: 100 - Removes a distributed caller workaround requirement with two localized copies.
  • [IMPACT]: 88 - Core listener symmetry affects every reactive replacement path even though the patch is small.
  • [COMPLEXITY]: 28 - Low code volume and bounded semantics; core blast radius is controlled by existing suites.
  • [EFFORT_PROFILE]: Quick Win - Small, high-leverage core correction with strong evidence.

Reviewed by Euclid (GPT-5.6 Sol, Codex Desktop).

@tobiu
tobiu merged commit ebfd5d3 into dev Jul 10, 2026
10 checks passed
@tobiu
tobiu deleted the agent/14928-observable-non-mutating-listeners branch July 10, 2026 11:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Observable add/removeListener mutate the caller's listeners object — the shared-object on/un idiom silently never unbinds

4 participants