Skip to content

refactor(agent): give each project one runtime owned by a registry - #59

Merged
cooper (czxtm) merged 1 commit into
mainfrom
feat/agent-runtime-registry
Sep 23, 2026
Merged

cooper (czxtm) merged 1 commit into
mainfrom
feat/agent-runtime-registry

Conversation

@czxtm

Copy link
Copy Markdown
Member

Part 1 of per-request project selection (ADR 0005).

The agent rebuilt its executor, store, shell manager and watchers on every project switch. Each switch also added another goroutine reading the same fsnotify channel. And the config watcher took its directories from the agent's startup environment, which only describes the project the agent was started in.

With this change:

  • A runtimeRegistry in internal/agent/server owns one runtime per project root: executor, store, shell manager, flake watcher and config-file watcher.
  • The legacy s.exec / s.store / s.shellManager / s.flakeWatcher fields become aliases for the current runtime, set in reinitializeExecutor. Switching back to a project reuses its runtime instead of starting duplicate watchers.
  • Each runtime's config watcher derives its paths from the runtime's project root.
  • Idle runtimes other than the current one are evicted after 10 minutes, and shutdown stops them all.

Verification:

  • The lead's run before rebasing: the 5 new registry and config-watcher tests pass 3 times under -race. In the devshell, build and vet pass, and the only test failure in internal/agent is the known baseline one.
  • After rebasing onto main with feat(agent): add the v1 Connect foundation with AgentService and ProjectService #57: the rebase was clean and the patch is unchanged.
    • go build ./... and go vet ./internal/agent/... pass.
    • go test ./internal/agent/... fails only TestSetupAcknowledgementRequiresAuthAndProjectEvidence, which already fails on main.
    • The runtime and v1 tests pass 3 times together under -race.

Refs stackpanel-thq.8.1

The agent rebuilt its executor, store, shell manager and watchers on
every project switch, and each switch started another goroutine reading
the same fsnotify channel. The config watcher also took its state and
gen directories from the agent's environment, which only describes the
project the agent was started in.

A runtime registry now owns one runtime per project root. The legacy
current-project fields alias the current runtime, so switching back
reuses it instead of starting duplicate watchers. Each runtime has its
own config watcher with paths derived from its root, other projects'
runtimes are evicted after ten idle minutes, and shutdown stops them
all. Watchers still start only once the server is serving.

This is the ownership model per-request project selection (ADR 0005)
builds on: v1 handlers will resolve a project's runtime from the same
registry.

Refs: stackpanel-thq.8.1
@github-actions

github-actions Bot commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Preview pr-59 has been destroyed.

@czxtm
cooper (czxtm) merged commit 4fd7d53 into main Sep 23, 2026
13 of 14 checks passed
@czxtm
cooper (czxtm) deleted the feat/agent-runtime-registry branch September 23, 2026 13:51
@github-actions

Copy link
Copy Markdown
Contributor

Docs preview pr-59 has been destroyed.

@linear-code

linear-code Bot commented Sep 23, 2026

Copy link
Copy Markdown

ENG-842

This branch had an error being deployed

1 failed and 1 active deployments
docs-preview — 2f742e0d Deployed Sep 23, 2026 by czxtm via deploy #198
pr-59 — 2f742e0d Deployed Sep 23, 2026 by czxtm via deploy #213
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant