Skip to content

[Bug]: async race in project.sync(): stale promise resolution clobbers newer state #22450

@CarloWood

Description

@CarloWood

Description

I ran into a problem where the TUI was seemingly not updated anymore (my prompt, after hitting enter, nor the reply from the model were visible) - see #21672 for details.

The reason for that turned out to be an out of sync project.instance as a result of the promise resolutions of async project.sync calls arriving -well- out of sync!

It seems obvious that the last call to project.sync() is the one that should be used to cache project.instance - not one that was done before that.

Plugins

personal plugins

OpenCode version

Latest github dev + personal patches

Steps to reproduce

I don't have anything to show a problem, as this is only noticeable when two calls to project.sync() happen in quick succession, which happens to be the case in my case because I am working on a patch that changes the directory as function of the used agent. As a result, upon a resume, sync is first called for the directory for the session as stored in the database and very shortly after for the resumed sessions agent, that in my case happens to use a different directory and therefore results in a different Instance to be returned.

The race is very real however and clearly incorrect.

Screenshot and/or share link

No response

Operating System

No response

Terminal

No response

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingcoreAnything pertaining to core functionality of the application (opencode server stuff)

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions