freeCodeCamp / CodeAlly-CodeRoad-freeCodeCamp

10 stars 5 forks source link

Issue with auto launching / continuing a tutorial #33

Closed moT01 closed 2 years ago

moT01 commented 3 years ago

I was having an issue loading CodeRoad (0.17.2, but this issue probably started at 0.16.0 or 0.17.0) in the docker container we have set up to run tutorials locally. Basically, I would launch CodeRoad and it would auto load my last tutorial, and none of the files were there to continue the tutorial. And there was no way to start over - not even by rebuilding the container, strangely. I know we need something like this to work for continuing tutorials, and perhaps this will work on CodeAlly. I dug into it a little bit to try and figure out how it works - CR is using some kind of local storage in VS Code to save some sort of state or tutorial or something. And I think it may write something to a file as a second way to save the state - or maybe it only does that. Not sure exactly, but it's something along those lines.

I see three methods at the moment for running tutorials

  1. Locally, without docker (I really never use this method) Current behavior: -I open a workspace, start a tutorial -If I open the same workspace, it will continue the tutorial where I left off (auto load) -I can start new tutorial by creating a new workspace

    Not that big of an issue here. I can't start a different tutorial within a workspace - I have to create a new one. If a workspace breaks - maybe I delete the files or something, it's pretty much stuck.

  2. Locally, with docker (using the rdb-alpha repo) Current behavior: Similar to the above, except the container always loads the same workspace. So if it breaks, it's pretty stuck.

    It's not an immediate issue. I pinned the container to use 0.15.1 for now, so it doesn't auto load the tutorials. We could probably just leave it like that if we have to.

  3. CodeAlly Not sure exactly how it will work on CodeAlly. Does each container (tutorial) have its own workspace? That could potentially work - I can see people getting stuck if they delete the files there. There is a plan do have a CodeAlly dashboard where users can delete the containers I believe, so there would be that fallback.

I'm not sure what the solution is. Maybe we need some way for users to clear the storage? Or a way to truly start over if someone gets stuck - maybe a pop-up when continuing a tutorial, "Do you want to continue where you left off?" I know there already is something like that when running local tutorials. I don't see a clear solution that would work for all these methods at the moment. I'll keep pondering, maybe something will come.

AdamZaczek commented 3 years ago

The file-based progress storing feature has been added just a moment ago and it's probably not tested well yet. We pass CODEROAD_SESSION_STORAGE_PATH to the containers already @ShMcK . Could you check? I believe that's what caused the bug to appear. Once this works, tutorials progress will be stored across sessions @moT01

Edit: To debug:

  1. Run one playground project. Install coderoad.
  2. Run another after the first one starts. CodeAlly will close the first one's session.
  3. Run the first project again. It will be created in a new container.
ShMcK commented 3 years ago

Can you change the CODEROAD_SESSION_STORAGE_PATH to a relative path, like "../.local"? That removes the failure to load.

In the meantime, I'll look into why it's not writing to the directory.

AdamZaczek commented 3 years ago

I changed the path for the Coderoad storage file to a relative one. Let us know if it fixed the issue @moT01

moT01 commented 2 years ago

My main account is a little stuck right now. When I load up pretty much any tutorial, it goes to the CodeRoad loading screen: Screen Shot 2021-12-06 at 7 35 22 PM

I believe it's cause I have previously created containers with the names of those tutorials.

On my second account, I believe I haven't previously created those containers and it loaded up the first two tutorials I tried. Then, when I went to load the first one again, it showed that start up screen. So, I think the initial loading is working - just having issues continuing. It does seem to be loading the same container properly, so that's good.

I'm running out of tutorial names to open that will create new containers to test things - that dashboard to delete those old containers would be nice 😉

AdamZaczek commented 2 years ago

Looks like the progress reading across sessions is broken right now @ShMcK. I will enable deleting old projects for you @moT01. As for the 'restart the project' button, it's mostly ready. We're doing some infrastructure tests right now. We plan to finish it right after that.

AdamZaczek commented 2 years ago

Coderoad v0.17.2 does not read the progress correctly @ShMcK

Steps to reproduce:

  1. Visit: https://codeally.io/embed/?repoUrl=https://github.com/freeCodeCamp/learn-git-by-building-an-sql-reference-object&envVariables=CODEROAD_WEBHOOK_TOKEN=ofiasjdflasjdflkajsd
  2. Run code
  3. Progress in the tutorial Screenshot 2021-12-17 at 15 37 16
  4. Go to https://app.codeally.io/app/code
  5. Run another project
  6. Visit: https://codeally.io/embed/?repoUrl=https://github.com/freeCodeCamp/learn-git-by-building-an-sql-reference-object&envVariables=CODEROAD_WEBHOOK_TOKEN=ofiasjdflasjdflkajsd
  7. The tutorial will not be found and progress will be lost Screenshot 2021-12-17 at 15 39 56

Note:

  1. Coderoad also does not open automatically.
  2. Coderoad no longer crashes.
  3. It looks like we're almost there and the fix is simple.
ShMcK commented 2 years ago

@AdamZaczek I don't think the issue is CodeRoad related.

On launching a tutorial and completing the first lesson. It works (step 10.10) image

On relaunching a tutorial and completing the second lesson. It works (step 20.10). image

Created and ran a new unrelated project in a new container. image

Re-run the original project. The file changes are not up to date (see step 10.10 instead of 20.10) image

I suspect:

AdamZaczek commented 2 years ago

- users are allowed one active container at a time? If I launch a new container while another one is open, the first container is shut down. Yes - File changes in a container are preserved while the container is live, so I can reload the container and progress is up-to-date. Yes - BUT when a container is rebuilt, the container might launch with an older set of file changes. This is why I see an older version of progress. OR perhaps only the file changes in codeally/.local may be stale. No, I actually have the correct progress when I do:

cd ../../codeally/.local && cat coderoad_position.json

The progress file is there. It's just that the tutorial doesn't launch for me, as in the screenshot: image

ShMcK commented 2 years ago

@AdamZaczek new container restarts should auto-start in v0.17.3.

The logic checked for local storage first, then fell back to the file. I changed it to check the file first, then fallback to local storage.

AdamZaczek commented 2 years ago

This doesn't work for us, no matter what we try @ShMcK. Now it doesn't open the tutorial so we always have the state from the previously attached screenshot.

ShMcK commented 2 years ago

@AdamZaczek

For the auto-launch to occur, it requires an existing history or a CODEROAD_TUTORIAL_URL.

When I open the link (https://codeally.io/embed/?repoUrl=https://github.com/freeCodeCamp/learn-git-by-building-an-sql-reference-object&envVariables=CODEROAD_WEBHOOK_TOKEN=ofiasjdflasjdflkajsd) it no longer includes the tutorial url variable. Do you know if that is a recent change?

To check for the variable, run:

printenv | grep CODEROAD

If the missing URL is not the cause, let's set up a call sometime soon to sort this one out.

AdamZaczek commented 2 years ago

We did some digging. To recap:

  1. When we add a completely new project from the link: The CODEROAD_TUTORIAL_URL variable is there Coderoad does not auto-launch. Coderoad works after manually starting.

  2. When we continue an existing new project from the link: Some env variables, like CODEROAD_TUTORIAL_URL, are missing. Coderoad does not auto-launch. Coderoad does not work.

Auto launching is not affected by CODEROAD_TUTORIAL_URL missing. We will see if fixing CODEROAD_TUTORIAL_URL resolves the issue with Coderoad not working after launching manually.

AdamZaczek commented 2 years ago

Continuing tutorial works, thanks @ShMcK!

Now, it's only auto-launching that does not work yet.

ShMcK commented 2 years ago

@AdamZaczek I believe I found the cause. The activation event expects "codeally.json", which doesn't match on "codeAlly.json". The filename seems to have changed.

image

image

I tried changing the activation event to workspaceContains:/code[aA]lly.json. There are no docs on the pattern matching here, but I've found it does not use a typical regex.

I could add both patterns, or one of them, @AdamZaczek let me know which you prefer?

"workspaceContains:/codeally.json",
"workspaceContains:/codeAlly.json"

Otherwise, the easiest fix could be to maintain the previous file naming. The change on my end is minimal as well, so no worries there.


If you want to test the functionality to verify it will work:

  1. Follow the link: https://codeally.io/embed/?repoUrl=https://github.com/freeCodeCamp/learn-git-by-building-an-sql-reference-object&envVariables=CODEROAD_WEBHOOK_TOKEN=ofiasjdflasjdflkajsd

  2. Edit the extension package.json on line 79 via the terminal. Use a pattern that matches on the codeAlly.json file.

To edit the extension file with Nano:

nano ../../codeally/.local/share/code-server/extensions/coderoad.coderoad-0.17.3/package.json
  1. Call the ">Developer: Reload Window" action (cmd+shift+P).

  2. CodeRoad should auto-launch.

AdamZaczek commented 2 years ago

Awesome! We need to go for "workspaceContains:/codeAlly.json". Having "workspaceContains:/codeally.json" as an activation event as well will not hurt though!

AdamZaczek commented 2 years ago

I made a pull request @ShMcK: https://github.com/coderoad/coderoad-vscode/pull/556

ShMcK commented 2 years ago

Should be resolved with the release of 0.17.4.

jaroszpiotr91 commented 2 years ago

There is still issue with saving progress. Despite having CODEROAD_SESSION_STORAGE_PATH=../../codeally/.local env set and files created properly there, refreshing the editor makes CodeRoad start from the beginning. Moreover, after refresh it either stops working or behaves strangely until clicking the "Reset" button.

AdamZaczek commented 2 years ago

I can confirm, something works really strange @ShMcK 🤔 It seems like Coderoad overrides the progress file. Progress is there, I refresh the page, progress is gone. Screenshot: image

To reproduce:

  1. Run a tutorial https://codeally.io/embed/?repoUrl=https://github.com/freeCodeCamp/learn-git-by-building-an-sql-reference-object&envVariables=CODEROAD_WEBHOOK_TOKEN=ofiasjdflasjdflkajsd
  2. Make some progress
  3. Type cat ../../codeally/.local/coderoad_position.json
  4. Refresh the page
  5. Type cat ../../codeally/.local/coderoad_position.json See that the value changed.
moT01 commented 2 years ago

Thanks for looking into this so hard everyone. I was off last week, so I'm still getting caught up. Let me know if you need anything.

ShMcK commented 2 years ago

There's a line of logic that says "if a tutorial doesn't have an id, there is no tutorial". That tutorial does not have an id.

I can change that line to look for a tutorial version instead, I think that would be preferable.

ShMcK commented 2 years ago

It should auto-launch now and preserve the content on refresh in v0.18.3.

I also added ".freeCodeCamp" to files that trigger auto-launching to make this work. Ideally these files should be in a variable, but I think it should be fine for now.

AdamZaczek commented 2 years ago

Awesome, thanks @ShMcK ! We're adding the new coderoad to tutorials today.