Skip to content

Conversation

@ellyxir
Copy link
Contributor

@ellyxir ellyxir commented Aug 19, 2025

  • add guard in normalizeAndDiff cell-link branch: when a link comes from query-result dereferencing and targets the same-doc immediate parent, embed a snapshot via tx.readValueOrThrow instead of writing the link
  • switch snapshot/alias reads to tx.readValueOrThrow for transaction consistency

Summary by cubic

Prevents a circular proxy loop when a dereferenced link targets its same-doc immediate parent by embedding a snapshot instead of writing the link. Also switches reads to tx.readValueOrThrow for transaction consistency, addressing Linear CT-773.

  • Bug Fixes
    • Collapse immediate-parent deref links to a JSON snapshot via tx.readValueOrThrow to avoid tight self-loops (e.g., obj.next -> obj).
    • Use tx.readValueOrThrow for alias/data reads to keep all reads within the active transaction.

- add guard in `normalizeAndDiff` cell-link branch: when a link comes from query-result
  dereferencing and targets the same-doc immediate parent, embed a snapshot via `tx.readValueOrThrow`
  instead of writing the link
- switch snapshot/alias reads to `tx.readValueOrThrow` for transaction consistency
@linear
Copy link

linear bot commented Aug 19, 2025

@ellyxir ellyxir marked this pull request as ready for review August 19, 2025 15:49
@ellyxir ellyxir requested review from seefeldb and ubik2 August 19, 2025 15:49
@ellyxir
Copy link
Contributor Author

ellyxir commented Aug 19, 2025

if you all prefer to remove the debugging, im happy to do that.

options,
seen,
);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Does your data looks something like this?

const doc: Cell<List> = {value: 1};
// point next to the top of the doc
doc.key("next").set(doc);

I think doc would look like:

{"value": 1, "next": {"/": {"@link1": {"id": "baed", "path": []}}}

normalizeAndDiff has the seen map, so I'm curious why it's not sufficient here.
Making the snapshot seems ok, since you're only using it to generate the diff (so you don't have to worry about being wrong if it gets out of sync), but I didn't get why it was required.

Is this a case where we're replacing an object with a link, and that replacement occurs on an $alias?

Copy link
Contributor Author

@ellyxir ellyxir Aug 19, 2025

Choose a reason for hiding this comment

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

we turn the "next" value into a link and it looks a bit like this:
[DEBUG][normalizeAndDiff::14:30:46.220] [BRANCH_CELL_LINK] Processing cell link at path=internal.#1.next link={"/":{"link@1":{"path":["internal","#1"],"id":"of:baedreidafjd3rgnpyyxxbwvvf75qc7vk2s5nzsbhw76djm4u2yhwkvptby","space":"did:key:z6MktpWYAnNacQL9AEkhqxaKR1qux7uU5rM6PjBvPst6LEWc"}}}

the problem is that it points to internal.__#1 which causes infinite loop when we traverse later. (and there is no js object for seen to keep track of here)

Copy link
Contributor

Choose a reason for hiding this comment

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

You can add the link to seen, but I think you've also added the object at ["internal", "#1"] to seen as well.
I think this is just that we don't handle circular links correctly everywhere (for example, one of my traverse functions is traverseDAG, since it does not handle them).
I think we're supposed to be supporting cycles, but I have no issue with disabling them here if that's the simplest approach.

@ellyxir
Copy link
Contributor Author

ellyxir commented Aug 19, 2025

@seefeldb Thanks! Addressed the nit — childPath is now computed lazily inside the debug lambda so it only runs when logging is enabled. Commit: 1d76ac5. Re the data: reads note: I switched those to tx.readValueOrThrow for consistency across the file; functionally equivalent for data: links.

@ellyxir ellyxir merged commit a9b512e into main Aug 19, 2025
8 checks passed
@ellyxir ellyxir deleted the ellyse/ct-773-patterns-fix-hacky-linkedlist-copy branch August 19, 2025 20:30
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.

4 participants