feat(cli): minimal bounded runtime for real codebases - #89
Conversation
Add runtime-budget and runtime-lifecycle modules with default-on thread and observation worker caps, CocoIndex live-flag fix, and graphd release on CLI exit. Cherry-picked from topology/lifecycle work without oracle or qualification harness changes. Co-authored-by: Cursor <cursoragent@cursor.com>
|
Bugbot is not enabled for your account, so this pull request was not reviewed. Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs. |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e4e0c95796
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const environment = Object.fromEntries(entries | ||
| .filter(([name]) => !isGraphdExecutionHook(name, platform) | ||
| && (platform !== 'win32' || name.toLowerCase() !== 'path'))); | ||
| Object.assign(environment, graphdThreadEnvironment(inheritedEnvironment)); |
There was a problem hiding this comment.
Derive the graphd budget before applying thread limits
graphdThreadEnvironment expects a parsed budget, but this passes the raw environment object, where graphd_threads is normally undefined. Consequently every default graphd spawn receives values such as OMP_NUM_THREADS=NaN, UV_THREADPOOL_SIZE=NaN, and LAMINA_RUNTIME_WORKER_THREADS=NaN; native runtimes may reject or ignore these values, defeating the bounded-topology guarantee and potentially exceeding the cgroup task limit. Parse inheritedEnvironment with runtimeBudgetFromEnvironment before constructing the thread environment.
Useful? React with 👍 / 👎.
| const inRepo = cwdLink && (cwdLink === root || cwdLink.startsWith(`${root}${path.sep}`)); | ||
| const childOfGraphd = graphdPid && readProcessPpid(pid) === graphdPid; | ||
| if (markerHit && (inRepo || childOfGraphd)) matches.push(pid); |
There was a problem hiding this comment.
Restrict orphan cleanup to processes owned by this command
On Linux this treats every marker-matching process whose cwd is anywhere in the repository as an orphan, without establishing ancestry or command ownership. If two Lamina commands run concurrently in one checkout, finalizing either command can therefore SIGTERM/SIGKILL the other command's cocoindex-worker or retrieval_worker.py process—for example, running a quick help/status command while a context rebuild is indexing. Track launched PIDs or require a verified descendant/lease relationship instead of using repository cwd alone.
Useful? React with 👍 / 👎.
| } finally { | ||
| if (process.env.LAMINA_CLI_SKIP_RUNTIME_FINALIZE !== '1') { | ||
| try { | ||
| await finalizeRuntimeCommand(process.cwd()); |
There was a problem hiding this comment.
Preserve graphd for read-only CLI commands
The unconditional finalizer now stops graphd after successful read-only commands such as lamina graph status, even though the lifecycle contract says reads may keep the daemon resident. This also breaks the existing required tests/greenfield_cli_test.mjs, which immediately captures graphd.lock after graph status; running that test against this commit fails with ENOENT because the finalizer has already removed the lock. Pass the command classification into finalization and retain graphd for reads, or otherwise update the contract and dependent lifecycle tests together.
Useful? React with 👍 / 👎.
Summary
Minimal cherry-pick of bounded topology (#69) and lifecycle (#70) for production CLI use—without oracle, qualification harness, or epic #49 closure work.
runtime-budget.mjs: default-on thread/worker caps (disable withLAMINA_RUNTIME_BOUNDED_TOPOLOGY=0)runtime-lifecycle.mjs: graphd release before observation,finalizeRuntimeCommandon CLI exitlive=flag fix,COCOINDEX_MAX_INFLIGHT_COMPONENTS=1, observation worker thread envScope
15 files, ~1k lines. Source commits:
6f523fca(#70),657df86b(CLI finalize).Not included: inventory/generation (#71–#72), retrieval sync overhaul (#73–#76), packaging (#77), qualification (#58).
Test plan
node tests/runtime_budget_test.mjsnode tests/runtime_lifecycle_test.mjsnode tests/observation_cli_test.mjsnode tests/retrieval_runtime_test.mjsnode tests/graphd_protocol_test.mjsdoctor→graph observe→context rebuild→work prepareMade with Cursor