The sync agent finds its modules by a route nobody can see - #865
Merged
sridharkalaibala merged 2 commits intoSep 17, 2026
Merged
Conversation
Promote develop to main: the announcement reaches a window that can play it
The agent declares bson, dotenv and mongodb and ships with none of them. Verified on a real installed app: resources/sync-agent/ holds package.json, src/ and sync-config.json, and no node_modules at all. It works anyway, and the reason is three files apart from each other, none of which mentions the others. server.js puts the API's node_modules on process.env.NODE_PATH, for the API. sync-agent-manager spawns the agent with ...process.env. The agent inherits that and resolves its three packages from the API's copy, which already carries all of them. So cloud sync depends on the API having started first, on a variable set for a different purpose, and on a spread operator. Remove any one and it dies with MODULE_NOT_FOUND on a customer machine and nowhere else. That is not a complaint about the design - a second copy of mongodb in the installer would be real weight for no gain. It is a complaint about the coupling being invisible, which is the shape of every fault found in this app today: correct code silently relying on something nobody could see from where they were standing. Pinned rather than rewired. Cloud sync is load-bearing and a test costs nothing, while changing a working spawn costs a shop's orders if it is wrong. The packaging step also stops calling the normal case a warning. It printed "WARNING: agent copied without node_modules - run npm install in the Cloud agent first" on every correct build, and following that advice would have made every installer larger to fix nothing. A warning that fires when everything is right is one people learn to scroll past, and then the real one scrolls past too.
Contributor
|
Merged to Try it at https://develop.posnic.io, or run it yourself: git fetch origin develop && git checkout develop
npm install && npm --prefix api install
npm run dev # then http://localhost:3000When you have tested it, say what you did and what happened, and set Reporting that something is broken is as useful as fixing it. It is |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Found by auditing the other packaging steps for the staleness trap that caused tonight's silent installer. This is not that trap, but it is the same family: correct code quietly relying on something invisible from where anybody is standing.
What is actually happening
The sync agent declares
bson,dotenvandmongodb, and ships with none of them. Verified on the installed app here:And it works. The log shows it syncing:
91 order(s) arrived from the cloud,sync collections now 22.The reason is three files apart from each other, none of which mentions the others:
src/server.jsbootstraps the in-process API and puts the API's ownnode_modulesonprocess.env.NODE_PATH. It does that for the API.src/sync-agent-manager.jsspawns the agent with...process.env.NODE_PATHand resolves all three packages from the API's copy, which already carries every one of them.So cloud sync depends on the API having started first, on a variable set for a different purpose, and on a spread operator that reads like boilerplate. Remove any one and it dies with
MODULE_NOT_FOUNDon a customer machine and nowhere else.Why this is pinned and not rewired
Shipping a second copy of
mongodbinside the installer, to duplicate one the API already has, would be real weight for no gain. The design is fine. The invisibility is the problem.Cloud sync is load-bearing and this works today, so a test costs nothing while changing a working spawn costs a shop's orders if I get it wrong. Four tests hold the three links, including one that fails if the agent ever grows a dependency the API does not carry, which would otherwise surface as a sync that stopped, at night, on a till.
And a warning that fired when everything was right
The packaging step printed, on every correct build:
Following that advice would have made every installer larger to fix nothing. A warning that fires when everything is right is one people learn to scroll past, and then the real one scrolls past too. It now says where the modules actually come from.
Zero assertion failures across the desktop suite.