Tasks introduced via 'sync' should trigger hooks
When using several instances of Taskwarrior on different devices (e.g. on a mobile phone with Android and on a computer), only locally added tasks trigger the on-modify hook.
Syncing means that tasks can be added from other sources and on-modify should be triggered when a new task comes in from a remote source. I see the exception made for sync to be counter-intuitive and cannot see a good reason for it.
Sorry, disagree. Tasks arriving via sync have already passed through any on-modify hook on the CLI, and shouldn't be modified again.
This would be true if the only possibility to add tasks would be to add them with the CLI or on a system that has hooks. This is not the case.
I was about to report this same issue.
I just started using taskwarrior+timewarrior (with the onModify hook to track time) yesterday and set up sync, also installing the android app. If I start/stop tasks in the android app, and sync both devices, my desktop computer hooks don't get executed, so timewarrior doesn't update time tracking. This is unfortunate and I don't see any workaround.
This is a pickle, because while this is a valid use case (i.e. a mobile TW client might not have a way of implementing hooks), it also means that the hooks scripts now can run multiple times for any given task (i.e. if the hooks are installed on two clients).
In that case we'd either have to require the hook implementation to be idempotent or implement some mechanism for that ourselves.
Any news on this?
As things stand, we don't have a good solution for this problem. Maybe a new hook entrypoint, on-sync could help here?
That would absolutely help. I think that's the best solution.
I "fixed" the issue in my desktop install by forcing on-modify for synced tasks. In my simple workflow it doesn't bring issues.
About the on-sync hook (which sounds good)... Does it mean timewarrior should be hooked both to on-modify and on-sync to work properly in my mobile+desktop setup?
Correct. You could just create a symlink to the on-modify hook. By doing that however, you should make sure the underlying hook is idempotent (meaning it's fine if it runs on the same task twice), as you can run into the problem where it would be first executed on first client during on-modify event and then again on the second client during on-sync event.
Related to #1790.
I think sync and hooks are fundamentally incompatible, since the hooks happen on one replica, and sync is between many replicas.
In practice, I think this is OK -- most people use one or the other. But I can see the opportunity for lots of trouble in an on-sync hook, as if that hook creates any further modifications then those, too, would get sync'd to other replicas, easily causing loops.