Gate brood/watch activation on brood prerequisites (no auto-brood without Portkey)#27
Conversation
…-brood without Portkey) nectar's design contract (brood-prereqs.ts / PRD-018k) is "brooding is dormant out of the box: auto-brood on boot runs only when Deep Lake creds resolve AND Portkey is explicitly enabled." But the gate was incomplete: cli.ts only omitted the DESCRIBE deps when Portkey was absent, while the structural brood (walk / mint / embed) still ran for any active project. So a bound project with no inference configured kicked off a full- codebase brood on boot, pegging CPU to no purpose (live-observed on the-apiary). Thread a `broodReady` predicate into LiveActiveProjects: when the brood prerequisites are not satisfied, resolve() reports zero active projects, so the supervisor stands up NO brood/watch context — the whole auto-brood stays dormant, not just the describe deps. cli.ts wires `broodReady: () => broodPrereqs.ready`. Default-safe (omitted => always ready), so the pre-existing suite is unchanged; new NEC-023 test covers dormant-without- Portkey and activation once satisfied. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
📝 WalkthroughWalkthroughThe daemon's brood/watch activation hook now returns ChangesBrood Readiness Gating
Estimated code review effort: 2 (Simple) | ~10 minutes Sequence Diagram(s)sequenceDiagram
participant Daemon
participant LiveActiveProjects
participant BroodPrereqs
Daemon->>BroodPrereqs: check ready (Deep Lake + Portkey)
BroodPrereqs-->>Daemon: ready = false
Daemon->>LiveActiveProjects: resolve()
LiveActiveProjects-->>Daemon: active = []
BroodPrereqs-->>Daemon: ready = true
Daemon->>LiveActiveProjects: resolve()
LiveActiveProjects-->>Daemon: active = [binding]
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/cli.ts`:
- Around line 1338-1343: The brood readiness check is currently captured as a
boot-time static value, so LiveActiveProjects.resolve() can stay permanently
disabled even after credentials appear later. Update the broodReady callback in
cli.ts to recompute the brood prerequisites each time it is invoked rather than
reading broodPrereqs.ready once, so a daemon that starts unready can become
ready without restart.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 2bad8ce8-8ee5-4c4d-ba0f-1b00e5bc981e
📒 Files selected for processing (3)
src/cli.tssrc/hive-graph/live-active-projects.tstest/live-active-projects.test.ts
| // PRD-018k / NEC-023: gate the WHOLE brood/watch activation on the brood prerequisites, not | ||
| // just the describe deps. Brooding is dormant out of the box: without Deep Lake creds AND | ||
| // Portkey enabled, resolve() reports zero active projects, so the supervisor auto-broods | ||
| // nothing (previously the structural brood — walk/mint/embed — still ran for any bound | ||
| // project even with no inference configured, pegging CPU to no purpose). | ||
| broodReady: () => broodPrereqs.ready, |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Map the file structure first
ast-grep outline src/cli.ts --view expanded > /tmp/cli_outline.txt
sed -n '1,220p' /tmp/cli_outline.txt
echo '--- snippets around brood prereqs / readiness ---'
rg -n "broodPrereqs|broodReady|resolveCredentials|credentialsWatch\.probe|LiveActiveProjects|credentialsPath|loadDeepLakeCredentials" src/cli.ts
# Print the relevant section with line numbers if file is reasonably sized
nl -ba src/cli.ts | sed -n '1270,1425p'Repository: legioncodeinc/nectar
Length of output: 6434
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo '--- src/cli.ts around brood wiring ---'
awk 'NR>=1280 && NR<=1405 { printf "%d:%s\n", NR, $0 }' src/cli.ts
echo '--- src/brood-prereqs.ts ---'
awk 'NR>=1 && NR<=220 { printf "%d:%s\n", NR, $0 }' src/brood-prereqs.ts
echo '--- src/hive-graph/live-active-projects.ts ---'
awk 'NR>=1 && NR<=260 { printf "%d:%s\n", NR, $0 }' src/hive-graph/live-active-projects.tsRepository: legioncodeinc/nectar
Length of output: 23729
Make broodReady live, not boot-time static. LiveActiveProjects.resolve() short-circuits to [] whenever this callback is false, so a daemon that starts before ~/.deeplake/credentials.json exists will never begin brooding after a later login. Recompute the prereqs inside the callback so the no-restart path can flip to ready.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/cli.ts` around lines 1338 - 1343, The brood readiness check is currently
captured as a boot-time static value, so LiveActiveProjects.resolve() can stay
permanently disabled even after credentials appear later. Update the broodReady
callback in cli.ts to recompute the brood prerequisites each time it is invoked
rather than reading broodPrereqs.ready once, so a daemon that starts unready can
become ready without restart.
Why
nectar's own contract (brood-prereqs.ts, PRD-018k) is: "brooding is dormant out of the box — auto-brood on boot runs only when Deep Lake creds resolve AND Portkey is explicitly enabled." But the gate was incomplete:
cli.tsonly dropped the describe deps when Portkey was absent, while the structural brood (walk the tree, mint file identities, compute embeddings) still ran for any active project.Live-observed: with the-apiary bound and no inference key configured, booting nectar kicked off a full-codebase brood and pegged CPU doing everything except the descriptions that are the point.
What
broodReadypredicate intoLiveActiveProjects: when the brood prerequisites aren't satisfied,resolve()reports zero active projects, so the supervisor stands up no brood/watch context — the whole auto-brood stays dormant, not just the describe deps.cli.tswiresbroodReady: () => broodPrereqs.ready.Tests
New
NEC-023case: dormant with creds + a binding but no Portkey; activates once prereqs are satisfied.tscclean; targeted + adjacent suites green (24/24 serial).Note: the nectar suite has a pre-existing flaky test under high parallel load (
api-router"started exactly one brood") unrelated to this change — passes serially and on a clean runner.🤖 Generated with Claude Code
Summary by CodeRabbit
nectar daemonnow stays dormant until all brood prerequisites are met, even if credentials and project bindings are present.