Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions docs/operations/code-index-operations.md
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,36 @@ docker exec loom-workers loom code backfill-prs --namespace code-myrepo --org ac
the work, since the unembedded rows are the embed phase's queue. `--commit <sha>` pins
the tree (and implies `--no-fetch`); `--concurrency N` parallelises files; `--limit N`
indexes a sample.
- One process parses and extracts at about one core. `--workers N` runs the index
phase's batches of 200 files and the edge pass in N more processes. Each worker is the
same command, started with the same arguments, so it runs as the command does: as
`background` traffic, under the command's query tag and operation, enrolled and
admitted for model work, with its own connection and `--concurrency`, its own
`cli.code.backfill` root span (stamped `loom.cli.worker`) and its own start and exit
log lines. The cursor moves past a batch once every earlier one is written, the header
batches are all written before the first source batch starts, and after a held batch
nothing more is handed out. A worker resolves names and imports against what it last
read of the index, so during the index phase it misses what the other workers are
writing; each worker reads the index again at the sources and at the edge pass, and
such a run owes the edge pass whatever the flags say (`--paths-file` and
`--no-edges-second-pass` runs included), so the pass binds them against the finished
index. One difference remains: a Python call or base class that resolves through
another file's inherited members reads the `inherits` edges the pass has rewritten so
far, which one process reads in tree order and the workers in the order they finish,
so a few such edges can carry another confidence (the same edge, its target found by
another rule). A later `loom code backfill` that finds the pass owed runs it; the
server's own first index does not. Each worker parses in its own child, so the run holds up to N
times the parse memory (`LOOM_CODE_PARSE_MEMORY_MB`) plus one server process per
worker. Stopping the command (SIGTERM or Ctrl-C, to the command or its whole process
group) or killing it stops every worker inside its batch before the worker retires,
and a worker that fails, its retirement included, fails the command with its batch
named, after the command has written its own end of the run.
- The first full backfill of a namespace also re-derives every file's edges after the
name table is complete, so cross-file references bind (`--no-edges-second-pass` skips
it). `--dialect-folder-pass` lets SQL files of undecided dialect take the dialect their
directory agrees on.
it). The run records that it owes the pass before its first batch and clears the record
once the pass is done, so a resumed run, or a rerun after an interrupted pass, still
runs it. `--dialect-folder-pass` lets SQL files of undecided dialect take the dialect
their directory agrees on.
- `backfill-prs` loads merged-PR history from GitHub, resumable by cursor and bounded by
GitHub's rate limit (`LOOM_CODE_PR_BACKFILL_MONTHS`, default 12). `backfill-reviews`
adds inline review comments, `backfill-assignees` requested reviewers, and
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ python scripts/codegen/docs_reference.py
| --- | --- | --- |
| `loom code` | Code intelligence plane operations. | |
| `loom code init` | Create the bare clone + seed state. | `--org`, `--namespace` |
| `loom code backfill` | Full-tree indexing (resumable). | `--org`, `--namespace`, `--phase`, `--embed`, `--include-poisoned`, `--allow-fake-embedder`, `--no-fetch`, `--limit`, `--commit`, `--paths-file`, `--concurrency`, `--edges-second-pass`, `--no-edges-second-pass`, `--dialect-folder-pass`, `--embedding-model-suffix`, `--context-callees`, `--callers-from` |
| `loom code backfill` | Full-tree indexing (resumable). | `--org`, `--namespace`, `--phase`, `--embed`, `--include-poisoned`, `--allow-fake-embedder`, `--no-fetch`, `--limit`, `--commit`, `--paths-file`, `--concurrency`, `--workers`, `--edges-second-pass`, `--no-edges-second-pass`, `--dialect-folder-pass`, `--embedding-model-suffix`, `--context-callees`, `--callers-from` |
| `loom code reconcile` | Content-based staleness check: paths whose chunks predate their last change at the branch head; --heal re-ingests them (watermark untouched). | `--org`, `--namespace`, `--heal`, `--limit`, `--max-commits`, `--no-fetch`, `--show` |
| `loom code compact` | OPTIMIZE ... FINAL a code vector table when its physical copies per key reach --min-ratio, and wait for the merge. | `--table`, `--min-ratio`, `--apply`, `--dry-run`, `--timeout-s` |
| `loom code reembed` | Write the namespace's live chunks under a second embedding model's label: in-database, resumable, no checkout. | `--org`, `--namespace`, `--embedding-model`, `--source-model`, `--prefix`, `--batch` |
Expand Down
8 changes: 5 additions & 3 deletions server/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@

The console entrypoint is `loom = server.cli:main`; `python -m server.cli`
runs the same `main` through `__main__`. `app` builds the parser tree and
dispatches; each command family lives in its own module and registers its
own subcommands:
hands the parsed command to `dispatch`; each command family lives in its own
module and registers its own subcommands:

access mint-token, revoke-token, claim-release
ch_setup ch-setup
code the `loom code …` tree (code-intelligence ingest and upkeep)
code_* its subcommand bodies: run, backfill, prs, scip, maintenance
demo demo
dispatch run_parsed: a parsed command in its own context, for `app` and
a process that runs a share of a command
deployment deployment
doctor doctor, report
doctor_client the `doctor --client` checks of this machine as a client
Expand All @@ -47,7 +49,7 @@
up up

Imports run one way: `app` imports the family modules; a family module never
imports `app`.
imports `app`. `dispatch` imports neither, and both may import it.
"""

from server.cli.app import main
Expand Down
70 changes: 3 additions & 67 deletions server/cli/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
import sys
from typing import Any

from server.cli._apply import add_apply_flags, dry_run_hint
from server.cli._apply import add_apply_flags
from server.cli.access import _add_mint_token_parser, _add_revoke_token_parser, _cmd_claim_release
from server.cli.cell import _add_cell_parser
from server.cli.dispatch import run_parsed
from server.cli.doctor import _DOCTOR_HELP, _add_doctor_flags, _cmd_doctor, _cmd_report, _version
from server.cli.hygiene import _add_namespace_hygiene_parsers, _add_namespaces_adopt_parser
from server.cli.import_brain import _add_brain_import_parser
Expand Down Expand Up @@ -51,7 +52,6 @@
)
from server.cli.tracker_feed import register_tracker_feed
from server.core.env_file import env_file_path
from server.wiring import wire


def _cmd_version(_args: argparse.Namespace) -> int:
Expand Down Expand Up @@ -89,68 +89,6 @@ def _load_dotenv_like_the_container() -> None:
)


def _dispatch(args: argparse.Namespace) -> int:
"""Run the parsed command. A one-shot command runs bound to its own
context: every write names its principal (the CLI has no auth context,
so `writer_actor()` would otherwise read '' on every import and backfill),
the reads run as `background` unless the command names a class of its own
(`--traffic-class`), and every ClickHouse query is tagged
`cli.<cmd>[.<sub>]`. Each binding is undone afterwards so an in-process
caller (a test) is left as it was.

`serve` runs unbound: it is a server, not a command. Its requests and
worker passes bind their own class and tag, and a process-wide
`process:cli:serve` actor would outrank the fallback of every tokenless
request and every worker write (`writer_actor` reads the pipeline actor
first)."""
if getattr(args, "cmd", "") == "serve":
return int(args.func(args))

from server.core.ch import query_tag_var
from server.core.pg import AuthorityMismatch
from server.llm import customer
from server.memory.domain.provenance import cli_actor, pipeline_actor
from server.observability.traffic_class import (
bind_background,
normalize_class,
reset_traffic_class,
)

token = None
if not normalize_class(getattr(args, "traffic_class", "")):
token = bind_background(f"cli:{getattr(args, 'cmd', '') or ''}")
path = (getattr(args, d, "") for d in ("cmd", "code_cmd", "subcommand"))
tag_token = query_tag_var.set(".".join(["cli", *filter(None, path)]))
try:
# A command for one org (`--org`, or `LOOM_CODE_ORG` for `loom code`) bills
# its model calls there; one that walks several orgs names each as it goes.
org = getattr(args, "org", "") or ""
if not org and getattr(args, "cmd", "") == "code":
from server.settings import settings

org = settings.code_org
# Its namespace too, when it names one: whose agent the identity headers name.
namespace = str(getattr(args, "namespace", "") or "")
with (
pipeline_actor(cli_actor(getattr(args, "cmd", ""))),
customer.cli_command(),
customer.for_org(str(org), namespace=namespace),
):
try:
rc = int(args.func(args))
except AuthorityMismatch as e:
print(f" ✗ {e}", file=sys.stderr)
return 2
if hint := dry_run_hint(args, rc):
# stderr: a command's --json output stays the only thing on stdout
print(hint, file=sys.stderr)
return rc
finally:
query_tag_var.reset(tag_token)
if token is not None:
reset_traffic_class(token)


# Subcommands registered by their own function (kept out of `main` for the
# function-length gate).
_SPLIT_PARSERS: tuple[Any, ...] = (
Expand Down Expand Up @@ -386,6 +324,4 @@ def main(argv: list[str] | None = None) -> int:
sub = parser.add_subparsers(dest="cmd", required=True)
for _add_parsers in _SUBCOMMAND_BUILDERS:
_add_parsers(sub)
args = parser.parse_args(argv)
wire()
return _dispatch(args)
return run_parsed(parser.parse_args(argv))
8 changes: 8 additions & 0 deletions server/cli/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
)
from server.cli.code_run import _identity, _run
from server.cli.code_scip import _entries, _entry_locked, _scip_delta, _scip_full, _scip_retry
from server.cli.ops import _positive_int
from server.code.domain.index.tier_health import COMPILER_TIERS


Expand Down Expand Up @@ -197,6 +198,13 @@ def _add_backfill_parser(csub: argparse._SubParsersAction[argparse.ArgumentParse
"the branch tip; leaves the git_head watermark and cursor untouched",
)
p_bf.add_argument("--concurrency", type=int, default=4)
p_bf.add_argument(
"--workers",
type=_positive_int,
default=1,
help="--phase index: processes that index the cursor batches and run the edge "
"pass, each with its own connection and --concurrency (1: this process)",
)
_add_backfill_pass_flags(p_bf)
p_bf.set_defaults(func=_cmd_backfill)

Expand Down
Loading
Loading