Skip to content

fix(lazurio): Buddy's window makes Buddy's project when the folder appeared after the startup - #253

Merged
immakermatty merged 3 commits into
mainfrom
lazurio/buddy-project-after-startup
Nov 22, 2026
Merged

immakermatty merged 3 commits into
mainfrom
lazurio/buddy-project-after-startup

Conversation

@immakermatty

@immakermatty immakermatty commented Nov 21, 2026 •

Copy link
Copy Markdown

What

On the shared Chat server (Buddy GEN4), POST /api/lazurio/buddy/thread now makes Buddy's project when it finds none over the declared Buddy folder and the folder exists now. It then finds or makes Buddy's thread as before, so the first window open after the folder appears gets the thread without a restart.

Why

Lazurio/LazurioPlatform#1179. The server made Buddy's project only in its startup (ensureManagedFolderProject in managedFolderStartup.ts), and only when the Buddy folder already existed at that moment. When a Personal Environment moves from Buddy GEN3 to GEN4, the shared T3 Code restarts about 2 minutes before Lazurio creates ~/Buddy. No project was made, the route answered no-project, and Buddy's window showed "Buddy se teprve instaluje." until the next server restart.

How

  • managedFolderStartup.ts exports ensureBuddyProjectIfPresent(buddyFolder): the startup's existing folder check plus ensureBuddyProject (bootstrap titled Buddy, unarchive, restore Buddy's threads), returning whether the folder was there. The startup calls it in the same place, still inside the catchCause that keeps Buddy's part from stopping the Folder's Chat. Nothing was copied.
  • buddySurfaceThread.ts: resolveSharedBuddyThread goes through findSharedBuddyThreadMakingProject. On no-project it calls ensureBuddyProjectIfPresent. If the folder is absent it returns the original no-project unchanged. Otherwise it reads the project again and continues.
  • buddySurfaceThreadRoute.ts passes the route layer's ProjectService, SecureRandom and FileSystem to the resolver. On the server these come from the runtime's guarded layerProjectService, so the managed-folder guard still canonicalizes the Buddy folder path.

Two first requests at once

projects.bootstrap reads by workspace root and then creates under a fresh random commandId, so the commandId alone does not deduplicate. What serializes it is ProjectService.commit: it holds a per-workspace-root KeyedLock and re-reads the active owner of the root inside the lock. The second create is rejected with ProjectConflictError. The lazy path treats that failure as "someone else made it" and reads the project again, so both requests end with the same single project. The thread itself was already idempotent, because its id and command derive from the project id. This gives the same guarantee as the startup's path, since it uses the same function and lock, within one server process.

Why only the thread route

findSharedBuddyThread is also called by buddySignal.ts (the signal read) and buddySurfaceDays.ts (the days list). Both are read-only GETs and already treat no-project as "no thread yet" (noThread / { days: [] }). The thread POST is the one call that already writes, needs the orchestration operate scope, and is what Buddy's window waits on. Putting creation into sharedBuddyProject would turn those reads into writers that need ProjectService too, and fix nothing visible: once the window's POST has made the project, both reads find it. So the lazy creation sits in resolveSharedBuddyThread only.

Tests

  • New in buddySurfaceThread.test.ts: the Buddy folder is absent when ensureManagedFolderProject runs, then created. Two concurrent resolveBuddyThread() calls get the same result, there is exactly one project over the folder (titled Buddy, not archived), and it has one thread on the Lazurio project's model. This test fails on origin/main with BuddyThreadUnavailable: no-project … is not in this T3 Code yet.
  • The existing no-project case now removes the Buddy folder first. It still asserts no-project, plus not-buddy without a declared folder, and that no project was made.
  • buddySurface.testkit.ts gives layerBuddyServer the runtime's real layerProjectService over the same database. It uses managedFolder.testkit.ts's stubs for workspace paths and metadata, which are now exported. agentCli.test.ts's mocked route gets an empty ProjectService mock.

Commands, run from apps/server:

  • vp run typecheck: passes (exit 0).
  • vp test run src/lazurio/buddySurfaceThread.test.ts src/lazurio/managedFolderStartup.test.ts src/lazurio/buddySignal.test.ts src/lazurio/buddySignalRead.test.ts src/lazurio/buddySurfaceDays.test.ts src/lazurio/buddySurfaceGuards.test.ts src/lazurio/buddyPrompt.orchestrator.test.ts src/lazurio/buddySteer.orchestrator.test.ts src/lazurio/agentCli.test.ts src/lazurio/managedFolder.test.ts src/lazurio/managedFolderGuards.test.ts: 11 files, 98 tests passed.

From the repo root, vp run check:changed passes format, lint, knip, graphql and typecheck. In its test step, src/provider/AgentContextBudget.test.ts fails with codexAdditionalContextBytes measured 8835 against a budget of 7324. It fails the same way with origin/main's sources, and nothing in this diff touches model-facing text. It is a pre-existing failure, not caused by this change.

Scenario proof in the real app

scripts/scenarios/buddy-window-opens-after-folder-appears.e2e.ts runs a managed Environment on its own loopback dev stack (real server, Vite web client, headless Chromium) with a temporary T3 home under the checkout's gitignored .t3. T3CODE_LAZURIO_FOLDER points to a folder that exists. T3CODE_LAZURIO_BUDDY_FOLDER points to a sibling folder that does not exist when the server starts. T3CODE_LAZURIO_BUDDY_ORIGIN is the page's own origin, so the page is Buddy's window. Once the server has printed its pairing link (after the startup's lazurio.project phase) and answers through Vite, the scenario creates the Buddy folder and opens the window. It then asserts that "Buddy is still being set up." is gone and that the composer is shown. The scenario gets its own stack because a managed Folder would change every other scenario's server.

Where the scenario lives (Fork CI allowlist)

Fork CI lets the overlay change an upstream file under apps/, packages/ or scripts/ only if the file is on the allowed_upstream_changes allowlist in lazurio-fork-ci.yml, or lies in the overlay's own apps/*/src/lazurio/. The first version added the scenario under scripts/scenarios/ and changed scripts/scenarios/start-app.ts to export a startWebStack helper. Neither file was on the allowlist, so the check failed on 9d04320525. Of the three ways out:

  • Leave upstream files untouched, where possible. start-app.ts is upstream's again, byte for byte. The scenario starts its stack itself with what start-app.ts already exports (start and prepareHome), the way upstream's second-server.ts starts a second server.
  • Move the scenario into apps/server/src/lazurio/: not possible. e2e reads scenarios only from scripts/e2e.config.ts's tests: "scenarios/**/*.e2e.ts". A scenario also imports e2e, @e2e-dev/web and the fixtures (t3.ts, e2e.config.ts), which resolve only inside the scripts package. The runbook's rule for overlay tests (docs/operations/lazurio-fork-release.md: a test goes into its own test file or into apps/*/src/lazurio/) has no place a scenario could run from.
  • So the one new file is on the allowlist, in the "Buddy's project beside the managed Folder" group, with that reason: scripts/scenarios/buddy-window-opens-after-folder-appears.e2e.ts. It is a new file and changes no upstream code.

Command, from the repo root:

vp run scenarios:prove scripts/scenarios/buddy-window-opens-after-folder-appears.e2e.ts --base 4a51029c1ced8f1bd36538ec18378bb45b2bd183 --head HEAD

The run on the current head exited 0 with verdict Proven: the scenario fails on base 4a51029c1c and passes on head 2d30a1c31d.:

  • Base 4a51029c1c (origin/main): failed with ASSERTION_FAILED: expect.toBeHidden … observed: visible (match count 1). The window stays at "Buddy is still being set up."
  • Head 2d30a1c31d: passed. The window opens Buddy's thread with the "Message Buddy…" composer.
Base 4a51029c1c Head 2d30a1c31d
Base 4a51029c1c: Buddy's window stays at "Buddy is still being set up." Head 2d30a1c31d: Buddy's window opens Buddy's thread with its composer

The captures are in a gist. They were uploaded from the earlier proof run on 9d04320525. The run on 2d30a1c31d produced byte-identical captures on both sides (checked with cmp), so the images stand for this head too. The tool's full output (proof.json, proof.md, the base failure capture and both videos) was written to scripts/.e2e/prove/ of the run's checkout. That folder is gitignored and is not part of this PR.

The allowlist step of Fork CI was also run locally. The same git diff --name-only pipeline over UPSTREAM_SHA..HEAD, with the workflow's own allowlist, passes. node --test scripts/lazurio-release-contract.test.mjs passes 56/56; it checks that the allowlist has only exact, existing, unique files.

Not covered

  • The lazy path runs on the thread POST only. Before the first window open after the folder appears, the signal and days reads still report "no thread yet", as they do today.
  • The startup's other Buddy step, unarchiving the threads of an earlier project while the folder is absent, stays startup-only. It does not apply here, because the route only makes the project when no project exists.
  • The race guarantee comes from the in-process lock. As for the startup, two server processes over one database are not covered.

Agent: environment a480495c-25e0-4e51-828b-1dbf1b77d62f · T3 thread d27e5511-ab1d-4892-a9a9-0ec9646d4834
🤖 Generated with Claude Code

…peared after the startup

The shared server made Buddy's project only in its startup, and only
when the Buddy folder already existed then. On a move from Buddy GEN3 to
GEN4 the server restarts before Lazurio creates the folder, so the
thread route answered no-project and the window waited forever
(LazurioPlatform#1179).

The thread route now makes Buddy's project with the startup's own
ensureBuddyProjectIfPresent when it finds none and the folder exists,
then finds the thread as before. A folder that is still absent answers
no-project as before. Of two first visits at once, the folder's lock
lets one bootstrap win and the other finds its project.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@agentrozjedemeai agentrozjedemeai left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blocking: Please add and run the required real-app scenario proof for this web-reproducible bug: start without the Buddy folder, create it after server startup, and show the window failing on the base and opening on this head with vp run scenarios:prove. The focused test covers the resolver, but it does not verify the route and window together; the PR explicitly says that runtime and browser proof is missing. AGENTS.md requires this proof for a bug reproducible in the web client.

Non-blocking: I could not independently run the focused tests or check:changed because vp is unavailable in this review environment. The PR reports the focused tests passing and a pre-existing failure in check:changed; I could not independently verify those results.

— Pablo

… appears

The scenario runs a managed Environment on its own dev stack: the
Folder exists when its server starts, the Buddy folder is made once the
server is up, and the page at Buddy's origin must open Buddy's thread
with its composer instead of "Buddy is still being set up."
(LazurioPlatform#1179). start-app.ts lends it the web stack it starts
for every scenario, now startWebStack.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@agentrozjedemeai agentrozjedemeai left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blocking: Please bring the new scenario files into the fork overlay policy and make the required Server and web compatibility check pass. Its current run fails before testing because scripts/scenarios/buddy-window-opens-after-folder-appears.e2e.ts and scripts/scenarios/start-app.ts are not on the overlay allowlist: https://github.com/Lazurio/t3code/actions/runs/44958333013/job/137011325257. This check is required by the main ruleset.

The earlier request for a real-app base/head scenario is addressed by the added scenario and the reported proof. I inspected the scenario and evidence; I could not independently rerun the tests because vp is unavailable here, and did not independently run the browser proof.

— Pablo

…s untouched

Fork CI refused the scenario commit: the overlay changed start-app.ts
and added a scenario under scripts/, neither on the allowlist. The
scenario now starts its managed stack itself with start-app.ts's own
exports, start and prepareHome, so start-app.ts is upstream's again. The
scenario file stays in scripts/scenarios/, the one folder e2e reads
scenarios from and where their fixtures and dependencies resolve, and
joins the allowlist with that reason.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@agentrozjedemeai agentrozjedemeai left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The overlay allowlist now includes the scenario and start-app.ts matches the base again. The previously failing overlay check step passes on this head; the full Server and web compatibility job is still running and must finish green before merge.

Non-blocking: I verified the allowlist locally and the diff has no whitespace errors. I could not independently rerun the scenario or release-contract tests: vp and the installed dependencies are absent here. The PR reports a successful base/head scenario proof.

— Pablo

@immakermatty

Copy link
Copy Markdown
Author

Owner's consent, passed on by the coordinator.

Matěj (immakermatty) wrote in the thread of his Buddy on 2026-11-22 at 08:45:27 UTC, verbatim: „1177 ano, 253 sluč“. He was answering the coordinator's morning overview, item 7: „Oprava ‚Buddy se teprve instaluje‘ v Chatu. Je schválená kontrolorem a nic nevydává: ‚253 sluč‘.“

Read at 08:46Z: head 2d30a1c31df5785721f92cee780a2503e7cb9070, approved by the reviewer on this exact head at 2026-11-21 22:56:15Z after its last commit (22:52:29Z); merge state CLEAN, required checks green; compare main...head: behind 0. The merge releases nothing; the release of T3 Code that carries it stays the Owner's decision. Merged by Matěj's Buddy in his name.

Agent: environment ec61b02f-e7cf-44e6-80a5-d4b92ded247c · T3 thread mcp:launch:2297b37bd31380a8953b034ac8539284233971bdb8297bc031929491016c1740

@immakermatty
immakermatty merged commit 94a7fff into main Nov 22, 2026
7 checks passed
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.

2 participants