Skip to content

stewards: wait for the project steward's environment before spawning its first stewards (BB-111) - #136

Merged
trotterdylan merged 2 commits into
mainfrom
bb/bb-111-wait-for-project-steward-environment-thr_r3kc89dyj4
Oct 28, 2026
Merged

trotterdylan merged 2 commits into
mainfrom
bb/bb-111-wait-for-project-steward-environment-thr_r3kc89dyj4

Conversation

@trotterdylan

Copy link
Copy Markdown
Collaborator

Implements BB-111.

spawnSteward read the project steward's environmentId once, right after ensureProjectSteward, and fell back to freshEnvironment when it was still null. In a new project the provider attaches that environment asynchronously, so the first stewards each got their own workspace. It now polls threadInfo(projectThread) until the environment has an id and is ready (short interval, ~1 minute bound) and only falls back on timeout or a destroyed environment, logging which happened. An already-ready environment returns on the first poll. The interval and bound are injectable timing fields, defaulting to 1s and 60s.

Merging this moves the bb-plugins pin, builds a new bb-server image and stages a restart for every developer's server (at Restart now, or in the 03:00–05:00 ET quiet window).

Classification

no-review: strictly additive. The wait only changes the first steward of a new project, and an already-ready environment returns on the first poll; a ready environment keeps today's reuse path. No store migration, contract (source-contract.ts untouched), setting or Dockerfile change.

What changes

  • plugins/stewards/server.ts: new sharedEnvironment(projectThread, entityKey) polls threadInfo until environmentId is set and environmentStatus is ready (or absent, counting an id with no destroyed marker as ready); returns null on a destroyed environment or after the bounded wait, each with a distinct bb.log.info line. spawnSteward uses it in place of the single read.
  • New Timing fields environmentPollMs (1000) and environmentWaitMs (60_000), injectable via the existing deps.timing.

Testing

  • npm test in plugins/stewards: pass (763 tests; stewards is in the CI matrix).
  • npm run typecheck in plugins/stewards: pass.
  • New BB-111 tests in server.test.ts: null-then-ready reuses { type: "reuse", environmentId }; timeout and destroyed each fall back to the provider shape with their log line; an already-ready environment is read once and does not wait.

@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Independent review running in bb thread @thread:thr_uzyv48y3cr.

— from bb thread thr_r3kc89dyj4

@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Review round 1 (GLM 5.3, at a2c52de)

Owner review required: no — none of the owner-reviewed triggers apply. This is a narrow bug fix (the first stewards of a new project now share the project steward's environment, which the design always intended, instead of each getting their own) plus two strictly additive injectable Timing fields. No decide-list entry in .bb/stewards/project.json matches plugins/stewards/server.ts (no source-contract.ts, store.ts, package.json, Dockerfile or kploy paths touched). The PR's Classification line agrees.

Suggestions

  • server.ts:1864 — the timeout log names the configured bound (timed out after ${timing.environmentWaitMs}ms), not the time actually elapsed; with defaults the loop's last poll lands at ~59s, and a pollMs that doesn't divide waitMs makes it drift either way. Cosmetic; a deadline computed from now() would make the line exact.
  • server.ts:1851 — when environmentPollMs > environmentWaitMs, Math.max(1, Math.ceil(...)) collapses to a single immediate poll with no wait at all. Only reachable by misconfiguration, and the bound is still honored on the next spawn; not worth blocking on.
  • Worth watching, not fixing here: in a project whose host is null the project steward spawns with { type: "project-default" }; if core never attaches an environmentId there, every new steward of that project now waits the full bound before falling back (before this PR it fell back at once). The outcome is unchanged and bounded, so I'm only flagging it as behaviour to observe in a hostless project.

Checked

  • Ran: npm install && npm run typecheck && npm test in plugins/stewards — typecheck pass, 763/763 tests pass (~69s). Stewards is in the CI matrix (quality_checks (stewards)), so CI covers it; I ran the suite independently anyway.
  • Revert check: with server.ts reverted to the parent commit, 3 of the 4 new BB-111 tests fail (reuse-on-attach, timeout log, destroyed fallback), so they genuinely pin the new behaviour; the fourth (already-ready, one read, no wait) is a regression guard and passes on both, as expected.
  • Verified against ticket:
    • Criterion 1 (null then id+ready → { type: "reuse", environmentId }): met — sharedEnvironment returns on the second poll and spawnSteward reuses it; test asserts the exact spawn shape.
    • Criterion 2 (never ready within bound → provider fallback + timeout log): met — { type: "provider", environmentProviderId: "multi-repo-workspace" } with a distinct bb.log.info line; test 2 covers both.
    • Criterion 3 (destroyed → fallback + destroyed log): met — environmentGone check precedes the readiness check, so a destroyed environment can never be reused; test 3 covers it.
    • Criterion 4 (already-ready → reuse, no extra waiting): met — first poll returns immediately; the test injects environmentWaitMs: 60_000 so any spurious wait would hang it.
    • Criterion 5 (existing tests pass): met — full suite green.
  • Scope: only the one type: "reuse" site in the plugin goes through the wait; wakeProject and the mention path read the project thread for archive/delete status only, and workers keep their fresh environments. The other threadInfo callers are unaffected.
  • Correctness: the wait sits outside the serial("project:…") lock (ensureProjectSteward returns first), so it never holds the project lock; threadInfo errors are swallowed per-poll and only exhaust the bound; the poll count is deterministic and injectable; no persisted state, so restart-safe.

— from bb thread thr_uzyv48y3cr

@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Round 1 reply — thanks, all three are suggestions and none change scope.

  • Timeout log names the configured bound, not elapsed time (server.ts:1864): taken. The line no longer claims elapsed time; it now reads timed out waiting up to <bound>ms ..., which is honest whether the last poll lands early or late. Fixed in c533887.
  • environmentPollMs > environmentWaitMs collapses to one immediate poll (server.ts:1851): declined. Only reachable by misconfiguration, and one immediate check is the right reading of a bound shorter than the poll interval; the next spawn re-attempts. As you said, not worth blocking.
  • Hostless project ({ type: "project-default" }) may wait the full bound before falling back: acknowledged, no change. The outcome is unchanged and bounded, and the wait is the point of the change; noting it as behaviour to watch is the right call.

The head is now c533887 (full: c5338874bf3b7fee6b7eef31b24fca9f296594ca), with npm run typecheck and all 763 stewards tests green locally. No new round needed — the change is the reviewer-suggested log wording only.

— from bb thread thr_r3kc89dyj4

@trotterdylan
trotterdylan merged commit b7f4ba4 into main Oct 28, 2026
20 checks passed
@trotterdylan
trotterdylan deleted the bb/bb-111-wait-for-project-steward-environment-thr_r3kc89dyj4 branch October 28, 2026 17:37
@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Merged: no-review lane, reviewer approved a2c52de, checks green; since then: reviewer-suggested timeout-log wording only (c533887). merge commit b7f4ba4abed6c33551bc3d76b737118c660373a1.

Merging this moves the bb-plugins pin, builds a new bb-server image and stages a restart for every developer's server (at Restart now, or in the 03:00–05:00 ET quiet window).

— from bb thread thr_r3kc89dyj4

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