Intermittent failure setting project properties to completed: false

I have a relatively large script that is triggered by Hazel and moves projects through a life cycle. The projects’ property ‘completed by children’ is set to true to hide them when they’re inactive. When the script adds a new task to a completed project, it’s supposed to set the project to completed: false. Then, it assigns a new task to the project.

From time to time, the ‘completed’ property toggle doesn’t stick. I (and my staff) are pulling our hair out because the result is tasks that need completing but that are hidden in our perspectives because they are inside a completed project. The new task never fails to attach to the appropriate project, which is making the bug harder for me to find.

Here’s the code

tell application "OmniFocus"
		tell front document
			if flattened project ClientName exists then
				set PotentialClientProject to flattened project ClientName
				set the properties of PotentialClientProject to {completed:false}
				tell conflictCheckFolder
					make new project with properties {completed by children:true, name:ClientName, sequential:false, completed:false}
					set PotentialClientProject to result
				end tell
			end if
			tell PotentialClientProject
				make new task with properties {name:taskName, due date:todayOrNextBusinessDay, note:"Phone " & ClientPhone, context:phoneContext, completed:false}
			end tell
			delay 0.2
			set the properties of PotentialClientProject to {completed:false, status:active}
		end tell
	end tell

As you can see, I’m throwing the set completed: false toggle in everywhere I can in an effort to figure out and prevent this error. I’d appreciate any thoughts on why this is happening and how to prevent it.

As I mentioned, this is intermittent, and I don’t yet see a pattern to help explain why this is happening or not. In all cases, hazel is not throwing an error.

I can’t say that I’ve ever used the set the properties of process like you have there. I typically would do it like this:

set completed of PotentialClientProject to false
set status of PotentialClientProject to active

They don’t have to be combined into a single line like you have above. Maybe try a different syntax?