[ENG-1369] Sync non text assets automatically#754
Conversation
|
This pull request has been ignored for the connected project Preview Branches by Supabase. |
5d7fac8 to
45f23fa
Compare
86649ac to
a0c2ff4
Compare
50b4542 to
cad2844
Compare
a0c2ff4 to
b256a86
Compare
b256a86 to
aeb91ff
Compare
| ): Promise<void> => { | ||
| const published = nodes.filter( | ||
| (n) => | ||
| ((n.frontmatter.publishedToGroups as string[] | undefined)?.length ?? 0) > | ||
| 0, | ||
| ); | ||
| for (const node of published) { | ||
| try { | ||
| await publishNode({ | ||
| plugin, | ||
| file: node.file, | ||
| frontmatter: node.frontmatter as FrontMatterCache, | ||
| }); | ||
| } catch (error) { | ||
| console.error( | ||
| `Failed to sync published node assets for ${node.file.path}:`, | ||
| error, | ||
| ); | ||
| } | ||
| } |
There was a problem hiding this comment.
🔴 syncPublishedNodesAssets unintentionally publishes nodes to the current user's group
syncPublishedNodesAssets filters nodes by checking if publishedToGroups has any entries (line 574-577), then calls publishNode for each. However, publishNode always publishes to the current user's group (myGroup at publishNode.ts:79), not to the groups the node was originally published to.
Detailed Explanation
If a node was published to group A but the current user's group is group B (e.g., the user changed groups, or publishedToGroups was set by a different mechanism), then:
syncPublishedNodesAssetsseespublishedToGroups = ["groupA"]→ length > 0 → passes filterpublishNodefetchesmyGroup = "groupB"fromgroup_membershipexistingPublish.includes(myGroup)→["groupA"].includes("groupB")→falseskipPublishAccessbecomesfalse- The full publish flow runs:
SpaceAccessupsert,ResourceAccessupsert, schema publish — all for group B - At line 189-195, frontmatter is updated:
publishedToGroups = ["groupA", "groupB"]
This means a routine background sync silently publishes the node to a group the user never explicitly chose to publish to. The intent of syncPublishedNodesAssets is only to ensure non-text assets are in storage, not to expand the set of groups a node is published to.
Impact: Nodes could be unintentionally shared with groups the user didn't explicitly publish to, which is a data exposure concern.
Prompt for agents
The syncPublishedNodesAssets function should only sync non-text assets for nodes that are already published to the current user's group, rather than calling the full publishNode function which may publish to new groups as a side effect. There are two approaches to fix this:
1. (Preferred) Extract the file sync and cleanup logic from publishNode into a separate function (e.g., syncNodeAssets) that only handles uploading non-text attachments and cleaning up stale FileReferences, without any publish access or frontmatter modification logic. Then call this new function from syncPublishedNodesAssets instead of publishNode.
2. (Simpler) In syncPublishedNodesAssets, after fetching the current user's group, filter the published nodes to only include those whose publishedToGroups already contains the current user's group. This prevents publishing to new groups but still reuses publishNode.
Was this helpful? React with 👍 or 👎 to provide feedback.
There was a problem hiding this comment.
That is a real issue. Not urgent for holehouse, but I'm for fixing it now, it's not that much trouble.
|
I would that we looked at file modified dates; many would not be worth republishing. But that's an optimization, so it could be left for another task (in which case let's define it.) |
| if (existingReferencesReq.error) { | ||
| console.error(existingReferencesReq.error); | ||
| return; |
There was a problem hiding this comment.
🟡 Early return on FileReference query error silently succeeds, leaving DB and frontmatter in inconsistent state
When the FileReference query at line 164-168 fails, the function returns at line 171 without throwing. This silently skips both the cleanup (lines 200-211) and, critically, the frontmatter update at lines 213-219.
Root cause and impact
On first-time publish (commonGroups.length === 0), the access-publishing block (lines 121-159) runs successfully—granting SpaceAccess, ResourceAccess, and publishing the schema. Then the FileReference query fails, and the function returns void (no error).
The caller in apps/obsidian/src/utils/registerCommands.ts:246-253 treats a resolved promise as success:
publishNode({ plugin, file, frontmatter })
.then(() => { new Notice("Published"); })
.catch((error: Error) => { new Notice(error.message); });So the user sees "Published", but:
publishedToGroupsin the local frontmatter is never updated to include the new group.- Non-text assets are not uploaded.
- Because frontmatter lacks
publishedToGroups, the automatic asset sync insyncPublishedNodesAssets(apps/obsidian/src/utils/syncDgNodesToSupabase.ts:573-577) will filter this node out, so assets will never be synced automatically in subsequent syncs either.
The node is accessible in the DB (access granted) but its assets are permanently missing until the user manually retries the publish command.
Impact: On a transient DB error during the optimization query, the user gets a false success notification and the node's assets are never uploaded.
Prompt for agents
In apps/obsidian/src/utils/publishNode.ts lines 169-171, instead of returning early when the FileReference query errors, either throw the error (so the caller can report it to the user) or fall through to skip the optimization and proceed with the unconditional asset upload and frontmatter update. One approach: when the query fails, set existingReferencesByPath to an empty object (so all assets are re-uploaded) and continue execution rather than returning. This way the cleanup and frontmatter update on lines 200-219 still execute.
Was this helpful? React with 👍 or 👎 to provide feedback.
f9ad104 to
35b48ce
Compare
maparent
left a comment
There was a problem hiding this comment.
I'm happy with what you did, but made changes on my own, please review my changes and approve before this gets added!
35b48ce to
3b7fec1
Compare
Uh oh!
There was an error while loading. Please reload this page.