Skip to content

Gate brood/watch activation on brood prerequisites (no auto-brood without Portkey)#27

Merged
thenotoriousllama merged 1 commit into
mainfrom
fix/nectar-brood-prereq-gate
Jul 5, 2026
Merged

Gate brood/watch activation on brood prerequisites (no auto-brood without Portkey)#27
thenotoriousllama merged 1 commit into
mainfrom
fix/nectar-brood-prereq-gate

Conversation

@thenotoriousllama

@thenotoriousllama thenotoriousllama commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

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.ts only 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

  • Thread a broodReady predicate into LiveActiveProjects: 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.ts wires broodReady: () => broodPrereqs.ready.
  • Default-safe: omitted ⇒ always ready, so the pre-existing suite is unchanged.

Tests

New NEC-023 case: dormant with creds + a binding but no Portkey; activates once prereqs are satisfied. tsc clean; 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

  • Bug Fixes
    • nectar daemon now stays dormant until all brood prerequisites are met, even if credentials and project bindings are present.
    • Prevents watch/activation flows from starting when inference readiness is unavailable, avoiding unexpected background work for bound projects.
  • Tests
    • Added coverage for the dormant-to-active transition when prerequisites are initially unmet and later become ready.

…-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>
@coderabbitai

coderabbitai Bot commented Jul 5, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The daemon's brood/watch activation hook now returns broodPrereqs.ready instead of always allowing activation, ensuring brood phases stay dormant when Deep Lake credentials or Portkey are unavailable. A new integration test verifies dormancy-to-activation transition based on the readiness gate.

Changes

Brood Readiness Gating

Layer / File(s) Summary
Gate daemon brood activation on prerequisites
src/cli.ts, test/live-active-projects.test.ts
The broodReady hook now returns broodPrereqs.ready, preventing brood/watch activation without Deep Lake/Portkey readiness; a new test confirms dormancy while unready and activation once ready flips true.

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]
Loading

Possibly related PRs

  • legioncodeinc/nectar#25: Related credentials-driven lifecycle and daemon health wiring that interacts with the same brood readiness gating logic.

Poem

A rabbit checked the brood's dark den,
"Not ready yet," it thought, and then—
Deep Lake keys and Portkey's light
must both shine bright before takeflight.
Now dormant stays till all is clear,
then hop! the brood springs forth in cheer. 🐇✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: gating brood/watch activation on prerequisites, including the Portkey-dependent dormant behavior.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/nectar-brood-prereq-gate

Comment @coderabbitai help to get the list of available commands.

@thenotoriousllama thenotoriousllama merged commit 6044857 into main Jul 5, 2026
5 of 6 checks passed
@thenotoriousllama thenotoriousllama deleted the fix/nectar-brood-prereq-gate branch July 5, 2026 15:01

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between 5c3ced7 and af006e0.

📒 Files selected for processing (3)
  • src/cli.ts
  • src/hive-graph/live-active-projects.ts
  • test/live-active-projects.test.ts

Comment thread src/cli.ts
Comment on lines +1338 to +1343
// 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,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 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.ts

Repository: 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.

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