Skip to content

fix: clear stale parsed cache on observation packets#505

Merged
Kpa-clawbot merged 2 commits intomasterfrom
fix/issue-504
Apr 3, 2026
Merged

fix: clear stale parsed cache on observation packets#505
Kpa-clawbot merged 2 commits intomasterfrom
fix/issue-504

Conversation

@Kpa-clawbot
Copy link
Copy Markdown
Owner

Summary

Fixes #504 — Expanding a packet in the packets UI showed the same path on every observation instead of each observation's unique path.

Root Cause

PR #400 (fixing #387) added caching of JSON.parse results as _parsedPath and _parsedDecoded properties on packet objects. When observation packets are created via object spread ({...parentPacket, ...obs}), these cache properties are copied from the parent. Subsequent calls to getParsedPath(obsPacket) hit the stale cache and return the parent's path, ignoring the observation's own path_json.

Fix

After every object spread that creates an observation packet from a parent packet, delete the cache properties so they get re-parsed from the observation's own data:

delete obsPacket._parsedPath;
delete obsPacket._parsedDecoded;

Applied to all 5 spread sites in public/packets.js:

  • Line 271: detail pane observation selection
  • Line 504: flat view observation expansion
  • Line 840: grouped view observation expansion
  • Line 1012: child observation selection in grouped view
  • Line 1982: WebSocket live update observation expansion

Tests

Added 2 new tests in test-frontend-helpers.js:

  1. Verifies observation packets get their own path after cache invalidation (not the parent's)
  2. Verifies observation path differs from parent path after cache invalidation

All 431 frontend helper tests pass. All 62 packet filter tests pass.

you added 2 commits April 3, 2026 02:39
…acket into observations

After PR #400 cached JSON.parse results as _parsedPath/_parsedDecoded on packet
objects, object spreads that create observation packets from parent packets
inadvertently copied the stale cache. This caused getParsedPath()/getParsedDecoded()
to return the parent's cached values instead of re-parsing from the observation's
own path_json/decoded_json.

Delete _parsedPath and _parsedDecoded after every spread site that creates
observation packets (5 locations in packets.js), forcing re-parse from the
observation's own data.

Fixes #504
The same delete _parsedPath/_parsedDecoded pattern was repeated at all 5
spread sites in packets.js. Extract into a shared clearParsedCache()
function in packet-helpers.js that:
- Deletes both cached properties
- Returns the object for inline use in map callbacks
- Is documented with the cache poisoning context (issue #504)

Also adds a dedicated test for clearParsedCache and updates existing
tests to use the helper instead of manual delete.
Copy link
Copy Markdown
Owner Author

@Kpa-clawbot Kpa-clawbot left a comment

Choose a reason for hiding this comment

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

Independent review

Verdict: Approve

Clean, well-scoped fix. The root cause analysis is correct — object spread copies the _parsedPath/_parsedDecoded cache properties from the parent, causing all observation packets to display the parent's path.

What's good:

  • Extracting clearParsedCache() into a shared helper in packet-helpers.js rather than inlining delete at each site — DRY and consistent
  • Helper returns the object, enabling inline use in .map() chains (lines 502, 838, 1981) — clean ergonomics
  • All 5 spread sites identified and patched
  • Tests exercise the actual packet-helpers.js module via vm.createContext (not copies) — consistent with codebase conventions
  • Tests cover both cache clearing mechanics and the end-to-end spread-clear-reparse flow

No must-fix items found. The change is minimal, correct, and well-tested.

@Kpa-clawbot Kpa-clawbot merged commit ad97c0f into master Apr 3, 2026
5 checks passed
@Kpa-clawbot Kpa-clawbot deleted the fix/issue-504 branch April 3, 2026 02:47
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.

Regression: expanding packet shows same path for every observation

1 participant