feat(opencode)!: keep server state per workspace #84
No reviewers
Labels
No labels
bug
cannot reproduce
duplicate
enhancement
help wanted
invalid
need info
need triage
need verification
not a bug
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
claudiomaradonna/azkaban!84
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "feat/opencode-workspace-state"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Why
opencoderuns OpenCode in a container of its own per launch, with theidentity's state folder mounted into it. OpenCode 2.x expects one
background server per user to own sessions, permissions, and tool
execution, and it keeps that server's registration and database in the
state every launch shared. A launch therefore met a registration that
points into another container, or ran a second server on the same
database, and the session lists of every project mixed, since each
workspace appears as
/workspace. The only way to keep projects apartwas an
--accountper project, each with a login of its own.Closes #83
What changed
Each workspace gets a folder of its own in the state folder in use, the
identity's or the account's:
workspaces/<name>-<hash>, named after theworkspace folder and a 12-character prefix of the SHA-256 of its path.
It holds the server's registration (
state) and its database (db,which the launcher names through
OPENCODE_DB). Login, configuration,and cache stay shared, so a new project needs no login. A launch names
the folder on standard error.
One container at a time serves a workspace's folder. The container is
named
azkaban-opencode-<hash>after that folder, and any other launchon the workspace stops with a message that names the container and the
command that removes one a session left behind. This replaces the
podman execjoin the issue proposed, which would have run the secondlaunch with the first one's mounts, network, and variables.
The adapter contract gains two optional fields, described in
docs/adding-a-client.md:AZK_CLIENT_CONTAINER_NAME, the name thecore gives the container and checks with the engine before a real run,
and
AZK_CLIENT_STATE_ENV, a variable the adapter sets and the coredrops from every environment file with the warning it gives for the
workspace marker.
OPENCODE_DBin an identity'senvor a workspace's.env.opencodeis dropped that way.Breaking: sessions OpenCode wrote before this change stay in
data/opencode.dbof the state folder, which launches no longer read. Aworkspace that is moved or renamed starts with an empty history.
How to verify
Setup is the one in
AGENTS.md: the repository needs nothing installedfor the first scenario. Base
6b5e210, branch tipe3cc683.The launch a workspace gets, run on both revisions, from a checkout
of each:
On the base it prints one line, the state every workspace shares:
/tmp/try/home/.azkaban/state/default/opencode/state:/home/opencode/.local/state/opencode.On the branch it prints the workspace's own
stateanddbmountsbelow
.../opencode/workspaces/app-<hash>/,--name,azkaban-opencode-<hash>, andOPENCODE_DB=/home/opencode/.local/share/opencode-db/opencode.db. Runas written on both revisions, with those results.
On a host with rootless Podman and the OpenCode 2.x image, with
opencodelinked to the branch'sbin/azkabanas above:opencode <project-a> -- session list: it lists only the session ofproject A.
opencode <new-project> -- auth list: it shows the login thestate folder already holds.
opencode <project-a>in a secondterminal: it stops with
container 'azkaban-opencode-...' already serves this workspace.The maintainer ran these on a host at
f319d38, before the reviewfixes, and reported that all worked; the output was not kept, and they
were not run again on the tip.
Untested:
make test-e2e, the release gate, whose OpenCode state nowcarries the
dbmount andOPENCODE_DB; the machine the work ran onhas no Podman. Expected: it passes. Untested: macOS with Apple
container. Expected: the same behavior as on Linux.
Checks run on the tip:
make lint && .agents/hooks/shellcheck.sh repo && make test, 337 tests, 0 failures. Each regression test the change adds,extends, or rewrites fails on
6b5e210at its assertion.Considerations
headless
runincluded, so a supervisor that starts two at once onone workspace now sees the second one stop. Review suggested
documenting different accounts as the way to run them together; the
maintainer chose to leave that out.
bring them back, since none was tried on a host; the maintainer chose
to leave the text at that.
--nameas the container'sID and does not say that it refuses an ID in use. Until that is tried
on a Mac, two launches that start together there rest on the
launcher's own check alone.