PocketIC errors forcing `dfx start --clean` - losing local NNS neuron state on WSL2

I’m developing a canister that integrates with the NNS (creating and managing neurons) and running into persistent PocketIC errors on my local testnet.

The errors look like: ``` ERROR: Failed to initialize PocketIC: HTTP status client error (400 Bad Request) for url (http://localhost:43963/instances) ERROR: Failed to initialize PocketIC: HTTP status client error (400 Bad Request) for url (http://localhost:46757/instances)

Environment:

  • OS: Ubuntu on WSL2 (Windows)
    -Ubuntu VERSION_ID=“24.04”
  • dfx – version 0.29.2
  • node --version v22.13.1
    -npm --version 10.9.

Working with local NNS neurons (created via governance canister)

Current Workaround:
Running `dfx start --clean` resolves the PocketIC errors, but this wipes all local state including the NNS neurons I’ve created for testing, forcing me to recreate them each time.

My Questions:

  1. Are there known stable version combinations** (dfx, WSL, etc.) that minimize PocketIC initialization issues?

  2. What’s the root cause of these PocketIC 400 errors, and can they be prevented without using `–clean`?

  3. For WSL2 users specifically:** Are there any known configuration tweaks or workarounds for PocketIC stability?

What I’ve Tried:

  • `pkill -f pocket-ic` before restart - `rm -rf ~/.cache/dfinity/pocketic`
  • Checking for port conflicts (none found)
  • `dfx stop` followed by `dfx start` (errors persist)

My testing workflow requires neurons to mature over several days, so losing state makes testing difficult.

Any guidance on 1: either preventing the PocketIC errors or, 2: preserving local NNS state would be greatly appreciated.

Note that I am a bit unexperienced with these types of testing, so the ideal solution should be as simplistic as possible. I read there is a testnet called playground, but things there are only persistent for 20 minutes so that would not allow me to conduct multi-day testing.

I think ideally, if there are known stable versions of these software when the issues wont appear over days, even if I start and stop dfx, that would be ideal.

ERROR: Failed to initialize PocketIC: HTTP status client error (400 Bad Request) for url (http://localhost:45257/instances)
ERROR: Failed to initialize PocketIC: HTTP status client error (400 Bad Request) for url (http://localhost:43753/instances)
ERROR: Failed to initialize PocketIC: HTTP status client error (400 Bad Request) for url (http://localhost:34709/instances)
ERROR: Failed to initialize PocketIC: HTTP status client error (400 Bad Request) for url (http://localhost:32857/instances)
ERROR: Failed to initialize PocketIC: HTTP status client error (400 Bad Request) for url (http://localhost:46125/instances)

My testing workflow requires neurons to mature over several days, so losing state makes testing difficult.

Why not use pic.advance_time() to achieve that in a milisecond?

How are you running PocketIC? Have you tried using pic-js?

PicJs has a guide for this: Working with the NNS | ICP JS SDK Docs. Could this work for you?

1 Like

Thanks
But I think it would not be diligent enough

I am new to PocketIC and have not tried using pic-js
This process will probably take quite a few days to figure out :grimacing:

I guess I will have to try the ICP JS SDK Docs - Working with the NNS if there is no easier solution.
Thanks for recommending it

1 Like

Could you please set

export RUST_LOG=debug

and pass --verbose to dfx start in order to get more details about the errors you’re getting?

This might not be the issue at all, just sharing some previous experience in case it might actually be related:

  • does dfx v0.29.2 use PocketIC (v10+) which auto-saves the state?
  • if not, could it be that because of WSL2, for some reason the job that’s supposed to run when the process ends to save the state is not being performed? like not detecting Control+C

I have also experienced the error
PocketIC: HTTP status client error (400 Bad Request)
A few times with the latest DFX
Not exactly sure the repro steps but I think it happens after my computer wakes up from sleep mode, windows using WSL2. Restarting the computer does not help, I have to run a --clean on dfx which fixes it

1 Like

Thank you all for the support—really appreciated :man_mage: :call_me_hand:

I’ve been testing the pic-js method of forwarding time programmatically. Everything works except I’m unable to disburse maturity back to my wallet from the NNS.

Is this expected behavior, or should I resolve this before moving to main net testing?

Thanks :santa_claus: :sparkles:

Invalid request expiry:
Minimum allowed: 2025-12-20 18:55:54 UTC
Maximum allowed: 2025-12-20 19:01:24 UTC
Provided expiry: 2025-12-20 18:55:00 UTC

It seems that perhaps (?) running Ubuntu on a windows with certain dfx version may cause this?

Do you think that a MAC environment might avoid / resolve the issue? Or would it work to just adjust my powershell / dfx / wsl versions to some kind of known to work versions, to ensure I can start and stop dfx without having corrupted / having to clean my state?

I think it would be ideal for me to run testing over two weeks, given what I am building.