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
1 change: 1 addition & 0 deletions docs/operations/code-index-operations.md
Original file line number Diff line number Diff line change
Expand Up @@ -1345,6 +1345,7 @@ copy.
| `loom code compact [--table T] [--apply]` | measures, and with `--apply` runs, `OPTIMIZE … FINAL` on a code vector table once its physical copies per key reach `LOOM_CODE_COMPACT_MIN_RATIO` (1.5), and waits for the merge; bulk passes do it themselves after `LOOM_CODE_COMPACT_AFTER_BULK_ROWS` rows ([maintenance](./maintenance.md#compaction-and-optimize)) |
| `loom code warm <questions.txt>` | asks each question once to populate shared `code.ask` answers (text lines or JSONL with `question`); a valid answer hit avoids fresh synthesis, but query embedding can still cost |
| `loom code answers-purge` | retires stored `code.ask` answers; dry run until `--apply`. Normal reuse already checks the model and prompt, answer-key settings, maximum age and recorded source hashes |
| `loom code describe-reset` | returns live chunks whose description came from the fake LLM provider to structural context and re-embeds them; dry run until `--apply`. A later `describe` on a real provider picks the reset rows up again |
| `loom code repack` | rebuilds context packs for recently merged PRs in the current shape |
| `loom code crossref` | the SQL/shell test → implementing C++ reference pass (idempotent) |
| `loom code coverage-import [--dry-run]` | imports the newest per-test line coverage run of the configured source into the test map ([measured coverage](#measured-coverage)) |
Expand Down
1 change: 1 addition & 0 deletions docs/reference/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ python scripts/codegen/docs_reference.py
| `loom code repack` | Regenerate context packs for recently merged PRs in the current pack shape. | `--org`, `--namespace`, `--days`, `--limit`, `--dry-run` |
| `loom code describe` | LLM contextual one-liners for top-PageRank chunks. | `--org`, `--namespace`, `--top-pct`, `--limit`, `--max-usd`, `--suffix`, `--concurrency` |
| `loom code answers-purge` | Tombstone stored code.ask answers. | `--llm-model`, `--all`, `--apply`, `--dry-run`, `--org`, `--namespace` |
| `loom code describe-reset` | Reset live chunks whose description came from the fake LLM provider to structural context. | `--apply`, `--dry-run`, `--org`, `--namespace` |
| `loom code scip-full` | Full compiler-tier re-index by hand (the code_scip_full worker runs it weekly by default: heals the TU-cap degrades of per-merge deltas and any drift). | `--checkout`, `--jobs`, `--keep-delta`, `--apply-delta`, `--org`, `--namespace` |
| `loom code scip-lock-path` | Print the entry's compiler-tier lock file on this host. | `--org`, `--namespace` |
| `loom code entry-lock` | Run a command under the entry's compiler-tier lock (this host's file and the deployment's lease): exit 75 when another pass holds it, 3 when the lease is lost mid-run (the command is stopped). | `--org`, `--namespace`, `--tier`, `<command>` |
Expand Down
19 changes: 19 additions & 0 deletions server/cli/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
_coverage_import,
_crossref,
_describe,
_describe_reset,
_export_matrix,
_export_pairs,
_init,
Expand Down Expand Up @@ -333,6 +334,19 @@ def _add_answers_purge_parser(csub: argparse._SubParsersAction[argparse.Argument
p_purge.set_defaults(func=_cmd_answers_purge)


def _add_describe_reset_parser(csub: argparse._SubParsersAction[argparse.ArgumentParser]) -> None:
"""`loom code describe-reset`: clear fake-provider chunk descriptions."""
p_reset = csub.add_parser(
"describe-reset",
help="Reset live chunks whose description came from the fake LLM provider "
"to structural context. Dry run by default (counts and samples the "
"matches); --apply resets.",
)
add_apply_flags(p_reset, writes="reset the matched chunks")
_add_common(p_reset)
p_reset.set_defaults(func=_cmd_describe_reset)


def _add_github_backfill_parsers(csub: argparse._SubParsersAction[argparse.ArgumentParser]) -> None:
"""`backfill-reviews`, `backfill-assignees`, `backfill-items`: GitHub history fills."""
p_rev = csub.add_parser(
Expand Down Expand Up @@ -497,6 +511,7 @@ def register_code_cli(sub: argparse._SubParsersAction[argparse.ArgumentParser])
_add_pr_history_parsers(csub)
_add_describe_parser(csub)
_add_answers_purge_parser(csub)
_add_describe_reset_parser(csub)

_add_scip_full_parser(csub)

Expand Down Expand Up @@ -716,6 +731,10 @@ def _cmd_describe(args: argparse.Namespace) -> int:
return _run("describe", _describe(args))


def _cmd_describe_reset(args: argparse.Namespace) -> int:
return _run("describe-reset", _describe_reset(args))


def _cmd_scip_retry(args: argparse.Namespace) -> int:
return _run("scip-retry", _scip_retry(args))

Expand Down
69 changes: 69 additions & 0 deletions server/cli/code_maintenance.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,75 @@ async def _answers_purge(args: argparse.Namespace) -> int:
return 0


_FAKE_DESCRIPTION_PREFIX = "[fake-synthesis:"
_DESCRIBE_RESET_PREVIEW = 10 # matched chunks a dry run prints


async def _describe_reset(args: argparse.Namespace) -> int:
"""Return live chunks whose description the fake LLM provider wrote to
structural context: the description line leaves `context_text`, the row is
re-embedded, and a later `describe` on a real provider picks it up again.
The description prefix is the only marker: `code_chunks` records no model.
Only the served embedding model's label is reset, so the fresh vector is
that model's; other labels keep their rows."""
from server.code.domain.extract.context_text import build_context_text, with_description
from server.code.store.index import CodeRepo
from server.core.ch import get_client
from server.embedding.embedder import get_embedder

await connect_code_plane(get_client(), args)
org, ns = _identity(args)
repo = CodeRepo()
embedder = get_embedder()
rows = await repo._ch.query_all(
"""
SELECT * EXCEPT (embedding) FROM loom.code_chunks FINAL
WHERE org = {org:String} AND namespace = {ns:String}
AND embedding_model = {model:String}
AND context_source = 'llm'
AND startsWith(context_description, {prefix:String})
AND tombstoned_at IS NULL
""",
{"org": org, "ns": ns, "model": embedder.model_name, "prefix": _FAKE_DESCRIPTION_PREFIX},
)
if not rows:
print("no live chunks with a fake description matched")
return 0
if args.dry_run:
print(f"would reset {len(rows)} chunks to structural context")
for r in rows[:_DESCRIBE_RESET_PREVIEW]:
desc = " ".join(str(r.get("context_description") or "").split())[:100]
print(f" {r.get('path')}#{r.get('scope') or '-'}: {desc}")
if len(rows) > _DESCRIBE_RESET_PREVIEW:
print(f" … and {len(rows) - _DESCRIBE_RESET_PREVIEW} more")
return 0
reset = 0
for r in rows:
path = str(r.get("path") or "")
scope = str(r.get("scope") or "")
old_ctx = str(r.get("context_text") or "")
ctx = (
with_description(old_ctx, scope=scope, description="")
if old_ctx
else build_context_text(path=path, scope=scope, content=str(r.get("content") or ""))
)
vec = await embedder.embed(ctx)
row = CodeRepo.moved_of(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

P1 — describe-reset --apply can make a removed chunk searchable again. If ingestion tombstones a chunk after the reset reads it and while the embedding call is in flight, moved_of gives the saved live row a version newer than the tombstone. FINAL then returns the reset row with tombstoned_at = NULL. Coordinate the reset write with ingestion so it cannot publish a stale row. Add a regression test that tombstones the selected chunk during embedding and verifies it stays absent.

"code_chunks",
r,
context_description="",
context_source="structural",
context_text=ctx,
embedding=vec,
embedding_dim=len(vec),
)
await repo.insert_rows("code_chunks", [row])
reset += 1
print(f"reset {reset} chunks to structural context")
await _compact_after_bulk(reset, embedder.model_name)
return 0


@dataclass
class _DescribeRun:
"""One `loom code describe` run: its bounds, what it did and what it spent."""
Expand Down
7 changes: 5 additions & 2 deletions server/code/domain/extract/context_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,8 @@ def build_context_text(
def with_description(context_text: str, *, scope: str, description: str) -> str:
"""`context_text` with `description` set as its description line, every
other head line (signature, calls, callers) and the content kept: what
`build_context_text` would have produced with that description."""
`build_context_text` would have produced with that description. An empty
description removes the line instead of leaving a blank one."""
head, sep, content = context_text.partition("\n---\n")
if not sep:
return context_text
Expand All @@ -246,4 +247,6 @@ def with_description(context_text: str, *, scope: str, description: str) -> str:
rest = lines[at:]
if rest and not rest[0].startswith(("calls: ", "Called by: ")):
rest = rest[1:] # the description line already there
return "\n".join([*lines[:at], description.strip(), *rest]) + sep + content
desc = description.strip()
head_lines = [*lines[:at], *rest] if not desc else [*lines[:at], desc, *rest]
return "\n".join(head_lines) + sep + content
Loading
Loading