Ask
24

Home Assistant Tuya: "network error (-9999999) sign invalid" then re-auth

This has happened four times in a month and I cannot find a trigger.

Everything looks healthy. All the devices are online in Home Assistant, none of them go unavailable or unknown, the internet is up, DNS resolves, and the manufacturer's phone app controls the same devices normally.

The only way I find out is by sending a command. The first write to any device fails instantly with:

network error: (-9999999) sign invalid

and straight after that the integration raises Authentication failed. Please re-authenticate.

Reconfiguring the integration fixes it immediately, every time, with no other change. Then it runs fine for days.

I monitor connectivity, gateway and DNS lookups continuously and all of them were healthy through each failure, so I do not think this is my network. What actually goes stale here, and is there anything I can do other than notice and press reconfigure?

9 answers Share
Report

Answering anonymously, a moderator will review it first.

  • @race_conditions · 2w ago · 3 replies

    The thread on this has got as far as a plausible mechanism, and it is worth knowing because it predicts when you will see it.

    The guard around the token refresh is a plain boolean that means refresh already in progress, skip. That stops the same call path refreshing twice, but it does not make anything wait. A second caller arriving mid refresh sees the flag, skips, and carries on signing with the token that is being replaced underneath it.

    So it is a race, not a leak, and the odds go up with concurrency.

    27
    Share
    Reply

    Answering anonymously, a moderator will review it first.

    Report
    • @night_group_off · 2w ago

      Concurrency being the thing I have most of. My nightly automation turns off a group of eleven lights at once and that is roughly when this keeps happening.

      16
      Share
      Reply

      Answering anonymously, a moderator will review it first.

      Report
    • @race_conditions · 2w ago

      That is the shape, yes. One command at a time rarely trips it. Eleven fired together is eleven chances for one of them to land in the window.

      1
      Share
      Reply

      Answering anonymously, a moderator will review it first.

      Report
  • @token_refresh_ro · 2w ago · 3 replies

    The word to hold on to is sign. That error is not about reachability at all, it is the vendor rejecting the signature on your request. Your credentials are fine and so is your network, which is exactly why every network check you run comes back clean.

    Requests are signed with the current access token. When the token is refreshed and something is still holding the old one, the signature computed no longer matches what the server expects, and you get an instant rejection rather than a timeout. Instant is the tell. A network problem makes you wait.

    29
    Share
    Reply

    Answering anonymously, a moderator will review it first.

    Report
    • @night_group_off · 2w ago · 2 replies

      That explains why it is always the first command and never the state updates. Reads were working the whole time.

      17
      Share
      Reply

      Answering anonymously, a moderator will review it first.

      Report
      • @token_refresh_ro · 2w ago

        Right, and reconfiguring works because it throws away whatever is cached and gets a clean token. It is a fix in the sense that turning it off and on again is a fix.

        20
        Share
        Reply

        Answering anonymously, a moderator will review it first.

        Report
  • @monitors_all · 2w ago

    Practical mitigation until it is fixed upstream, since you cannot patch the vendor cloud: put a small delay between the commands in that group so they do not all hit the API in the same instant. Half a second between them was enough here. It is not elegant and it does not fix the underlying race, it just stops one automation from being the thing that reliably triggers it.

    1
    Share
    Reply

    Answering anonymously, a moderator will review it first.

    Report
  • @local_first_kim · 2w ago

    Longer answer nobody wants: the devices that keep doing this to you are the ones where a working light switch depends on a signature check in another country. Where a local protocol exists for the same hardware, moving to it removes this class of failure rather than reducing it.

    1
    Share
    Reply

    Answering anonymously, a moderator will review it first.

    Report
  • @reconfig_button · 2w ago

    Add a template sensor for the integration's auth state and alert on it. You cannot stop it yet, but you can stop finding out from a light that will not turn on.

    1
    Share
    Reply

    Answering anonymously, a moderator will review it first.

    Report