Indexing modules¶
The pipeline that turns a folder of source files into indexed chunks: discover → hash-diff → chunk → embed → upsert.
noesis.core.chunker
¶
cAST split-then-merge chunking: AST nodes -> size-bounded chunks (Overview §4.4).
tree-sitter parses each file; adjacent sibling nodes are greedily merged into chunks within a token budget, any node over the max budget is split by recursing into its children, and over-budget leaves are split by lines. Missing language or grammar degrades to a line-based fallback — never an error. Canonical language names (core/languages.py) are passed straight to tree-sitter-language-pack; they resolve 1:1 today, and M5's LANGUAGE_MAP is the seam if that ever changes.
Hard invariant: concatenating chunk.text over a file's chunks, in order,
reproduces the file text exactly — byte-for-byte, no overlap. Whitespace and
comments between siblings attach to the following chunk, and every chunk
boundary is snapped to a line start, so start_line/end_line slice the
file's lines exactly.
Never split a function below its signature: a definition either fits whole in a chunk, or — only when it alone exceeds the max budget — is split via its own children behind a hard chunk boundary forced at the definition's start.
MIN_CHUNK_TOKENS = 300
module-attribute
¶
Soft floor: greedy merging aims to fill chunks at least this far.
MAX_CHUNK_TOKENS = 800
module-attribute
¶
Hard ceiling: only an indivisible single line may estimate above this.
Chunk(text, file_path, start_line, end_line, language, node_type, symbol_name, file_hash)
dataclass
¶
One retrieval unit of a file, with 1-based inclusive line bounds.
chunk_file(text, *, language, file_path, file_hash)
¶
Chunk one file's content; empty text yields an empty list.
Source code in src/noesis/core/chunker.py
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | |
noesis.core.languages
¶
Canonical language names, keyed by file extension.
This module is the single source for the project's canonical language
identifiers (stored in files.language). LANGUAGE_MAP (M5, §3.5) is the
explicit seam mapping each canonical name to (a) its tree-sitter-language-pack
grammar name and (b) its ast-grep language string — the two engines do not
share identifiers by contract, even where they coincide today. Keep this a
plain dict module.
EXT_TO_LANGUAGE = {'.py': 'python', '.pyi': 'python', '.js': 'javascript', '.jsx': 'javascript', '.mjs': 'javascript', '.cjs': 'javascript', '.ts': 'typescript', '.tsx': 'tsx', '.go': 'go', '.rs': 'rust', '.java': 'java', '.c': 'c', '.h': 'c', '.cpp': 'cpp', '.cc': 'cpp', '.cxx': 'cpp', '.hpp': 'cpp', '.hh': 'cpp', '.cs': 'csharp', '.rb': 'ruby', '.php': 'php', '.swift': 'swift', '.kt': 'kotlin', '.kts': 'kotlin', '.scala': 'scala', '.sh': 'bash', '.bash': 'bash', '.html': 'html', '.htm': 'html', '.css': 'css', '.json': 'json', '.yaml': 'yaml', '.yml': 'yaml', '.toml': 'toml', '.md': 'markdown', '.sql': 'sql'}
module-attribute
¶
LANGUAGE_MAP = {'python': LanguageMapping('python', 'python'), 'javascript': LanguageMapping('javascript', 'javascript'), 'typescript': LanguageMapping('typescript', 'typescript'), 'tsx': LanguageMapping('tsx', 'tsx'), 'go': LanguageMapping('go', 'go'), 'rust': LanguageMapping('rust', 'rust'), 'java': LanguageMapping('java', 'java'), 'c': LanguageMapping('c', 'c'), 'cpp': LanguageMapping('cpp', 'cpp'), 'csharp': LanguageMapping('csharp', 'csharp'), 'ruby': LanguageMapping('ruby', 'ruby'), 'php': LanguageMapping('php', 'php'), 'swift': LanguageMapping('swift', 'swift'), 'kotlin': LanguageMapping('kotlin', 'kotlin'), 'scala': LanguageMapping('scala', 'scala'), 'bash': LanguageMapping('bash', 'bash'), 'html': LanguageMapping('html', 'html'), 'css': LanguageMapping('css', 'css'), 'json': LanguageMapping('json', 'json'), 'yaml': LanguageMapping('yaml', 'yaml'), 'markdown': LanguageMapping('markdown', 'markdown')}
module-attribute
¶
LanguageMapping(grammar, ast_grep)
dataclass
¶
detect_language(path)
¶
Return the canonical language for path's extension, or None.
Source code in src/noesis/core/languages.py
56 57 58 | |
noesis.core.discovery
¶
File discovery: walk a project tree and yield indexable files.
Filters, in order: excluded directories, .gitignore (git semantics, nested files, negation), the secret skip-list, the generated-lockfile skip-list, symlinks, size cap, binary sniff. The secret skip-list is defense-in-depth on top of .gitignore — a secret file is skipped even when no .gitignore mentions it, so it can never enter the index (a retrievable surface) or M5 structural-search results.
logger = logging.getLogger(__name__)
module-attribute
¶
EXCLUDED_DIRS = frozenset({'.git', '.hg', '.svn', 'node_modules', 'dist', 'build', 'target', '.venv', 'venv', '__pycache__', '.mypy_cache', '.pytest_cache', '.ruff_cache', '.tox', '.eggs', '.idea', '.vscode'})
module-attribute
¶
SECRET_SKIP_PATTERNS = ('.env', '.env.*', '*.pem', '*.key', '*.p12', '*.pfx', '*.jks', '*.keystore', 'id_rsa*', 'id_ed25519*', 'id_ecdsa*', 'id_dsa*', '*.ppk', 'credentials*', '.netrc', '.npmrc', '.pypirc', '*.tfvars', 'secrets.*', '*.secret', '**/.aws/**', '**/.ssh/**')
module-attribute
¶
GENERATED_SKIP_PATTERNS = ('uv.lock', 'package-lock.json', 'npm-shrinkwrap.json', 'yarn.lock', 'pnpm-lock.yaml', 'bun.lockb', 'Cargo.lock', 'poetry.lock', 'Pipfile.lock', 'go.sum', 'composer.lock', 'Gemfile.lock', 'packages.lock.json', 'flake.lock')
module-attribute
¶
DiscoveryConfig(max_file_bytes=1048576, follow_symlinks=False, include_languages=None, extra_ignore_patterns=())
dataclass
¶
DiscoveryErrors(files=list(), dirs=list(), entries_seen=0, unscreened=list(), unidentified=list())
dataclass
¶
Non-fatal discovery failures, (root-relative path, message) pairs.
files: a file that exists but could not be screened (stat/read
error) — it is excluded from the results, but "absent from discovery"
must not be read as "deleted from disk" (same discrimination as H7).
dirs: a directory whose scandir failed mid-walk — its whole subtree
went unseen, so deletion evidence from this walk is untrustworthy.
The two lists above are about a path's EXISTENCE. The two below are not: the walk reached the directory and enumerated it fine, and every file in it is accounted for — what failed is an input to screening, so the result may be the wrong SHAPE rather than incomplete (ADR-58).
unscreened: a directory whose .gitignore could not be tested for or
read, so its ignore rules were never applied. Unlike every other failure
in this module this one runs in BOTH directions. The obvious half is
under-ignoring — excluded files reach the index, a retrievable surface.
The half that is easy to miss, and the reason this is not merely
cosmetic: git's last-match-wins semantics mean a deeper .gitignore can
NEGATE a shallower exclusion (*.log at the root, !important.log
in logs/). Lose the deeper spec and the outer exclusion stands
unopposed, the file drops out of the results, and "absent from
discovery" is read downstream as deletion. So this list DOES suppress
deletion — under its own directory prefix only, via the ADR-54
machinery — even though nothing about the walk was incomplete.
unidentified: a directory whose identity could not be established —
the follow_symlinks cycle-guard stat, or the per-child
is_symlink test. This one can only make the walk OVER-inclusive (a
subtree walked twice under two rel paths, or a symlink descended into
that would normally be skipped); it can never remove a path from the
results, so it is never deletion evidence and suppresses nothing.
Recorded anyway, so that no filesystem fault in this module is invisible.
entries_seen counts every file entry the walk enumerated, before
any filter runs. It is not an error, but it lives here because only the
caller that cares about the errors cares about it: an empty result with
entries_seen == 0 means the walk found nothing at all (an unmounted
or emptied root), while an empty result with entries_seen > 0 means
the tree is readable and populated and the filters — an ADR-42 scope
narrowing, .gitignore, the skip-lists — removed everything. Those two
are indistinguishable from the returned list alone, and change
detection must not treat the first as deletion.
files = field(default_factory=list)
class-attribute
instance-attribute
¶
dirs = field(default_factory=list)
class-attribute
instance-attribute
¶
entries_seen = 0
class-attribute
instance-attribute
¶
unscreened = field(default_factory=list)
class-attribute
instance-attribute
¶
unidentified = field(default_factory=list)
class-attribute
instance-attribute
¶
is_secret_path(rel_posix)
¶
True if a project-relative POSIX path matches the secret skip-list.
Source code in src/noesis/core/discovery.py
170 171 172 | |
discover_files(root, config=None, *, errors=None)
¶
Return sorted, POSIX-style relative paths of indexable files under root.
When errors is given, transient stat/read/scandir failures are recorded
there instead of vanishing silently — callers doing change detection need
them to tell "file errored" from "file deleted"; errors.entries_seen
additionally reports how many file entries the walk enumerated before
filtering, which is the only way to tell an unreadable root from a fully
filtered one. errors=None keeps the historical silent-skip
behavior.
Source code in src/noesis/core/discovery.py
362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 | |
noesis.core.gitfast
¶
Git candidate-set fast path (§3.2) — subprocess git CLI (ADR-23).
The fast path may only shrink the set of files that get hashed; it never
decides changed/unchanged on its own authority (§3.2 rule 1) — that stays
with the SHA-256 comparison in :mod:noesis.core.hashdiff. Any uncertainty
— no repo, git binary absent, in-progress merge/rebase, detached HEAD,
missing or unreachable anchor commit, non-zero git exit, timeout — returns
None and the caller falls back to the full hash-walk, silently for the
API caller and logged for the operator (rule 3).
Subprocess against the system git CLI is deliberate (rule 5 / ADR-23): zero Python deps, license-clean, and the ~10ms spawn cost is noise next to embedding. pygit2 remains the documented upgrade if profiling ever says otherwise.
logger = logging.getLogger(__name__)
module-attribute
¶
CandidatePathSet(paths)
¶
Bases: AbstractSet[str]
Candidate paths where an entry may denote a whole directory.
Git collapses some changes to a single directory entry: an untracked
nested repository is one dir/ line even under -uall, and a
submodule change is one gitlink path with no slash. Discovery does
descend into those directories, so a plain path-equality test would
carry their changed files forward as unchanged. Membership here also
matches any ancestor directory of the queried path — this only widens
the candidate set (more files hashed, never fewer), so rule 1 holds.
Source code in src/noesis/core/gitfast.py
57 58 | |
__slots__ = ('_entries',)
class-attribute
instance-attribute
¶
__contains__(rel)
¶
Source code in src/noesis/core/gitfast.py
60 61 62 63 64 65 66 67 68 69 70 | |
__iter__()
¶
Source code in src/noesis/core/gitfast.py
72 73 | |
__len__()
¶
Source code in src/noesis/core/gitfast.py
75 76 | |
__repr__()
¶
Source code in src/noesis/core/gitfast.py
78 79 | |
GitCandidates(candidates, head_commit, dirty_paths=frozenset())
dataclass
¶
Candidate changed set for one run.
candidates holds project-root-relative POSIX paths (same shape as
discovery output); head_commit is the HEAD sha the diff was taken
against — the anchor to store once the run completes (rule 4).
dirty_paths is the working-tree-dirty subset (staged + unstaged +
untracked, project-relative) — persisted with the anchor so a file
dirty at run N stays a candidate at run N+1 even after being reverted
to HEAD (H1).
resolve_head(root)
¶
HEAD commit sha, or None (not a repo, no commits yet, git absent).
Called even on full-walk runs of a git worktree so the next run has an anchor to fast-path from.
Source code in src/noesis/core/gitfast.py
113 114 115 116 117 118 119 120 121 122 | |
compute_candidates(root, anchor)
¶
Candidate changed set since anchor, or None → full hash-walk.
The set is git diff --name-status anchor..HEAD ∪
git status --porcelain (staged + unstaged + untracked), per §3.2
rule 2. Deleted paths are included; they are not on disk, so discovery
never yields them and the partition marks them deleted exactly as the
full walk would.
Source code in src/noesis/core/gitfast.py
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 | |
status_dirty_paths(root)
¶
Working-tree-dirty paths (staged + unstaged + untracked), project-root relative. Persisted alongside the anchor on a full-walk run so the H1 revert case is covered even when no git diff was computed. Returns None when root is not a usable git worktree (caller stores no dirty set).
Source code in src/noesis/core/gitfast.py
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 | |
noesis.core.hashdiff
¶
SHA-256 change detection: hash files, partition against stored state.
Hash is the source of truth for change detection (Overview §4.9). The M7 git
fast-path may later shrink the candidate set fed to partition, but never
replaces the hash comparison itself (expanded doc §3.2 rule 1).
DiffResult(new=(), changed=(), unchanged=(), deleted=(), hashes=dict(), errored=(), verified=0, skipped=0)
dataclass
¶
Partition of discovered files vs stored state (relative POSIX paths).
new = field(default=())
class-attribute
instance-attribute
¶
changed = field(default=())
class-attribute
instance-attribute
¶
unchanged = field(default=())
class-attribute
instance-attribute
¶
deleted = field(default=())
class-attribute
instance-attribute
¶
hashes = field(default_factory=dict)
class-attribute
instance-attribute
¶
Current content hash for every discovered file (new/changed/unchanged).
errored = field(default=())
class-attribute
instance-attribute
¶
(path, error) for files whose hash attempt failed non-fatally (the H7 carry-forward). The file's true state is UNKNOWN this run — callers must treat these like per-file failures: never advance the git anchor past them and re-queue them for retry, or a committed-then-errored file is carried forward as unchanged on every future fast-path run (stale forever).
verified = 0
class-attribute
instance-attribute
¶
Count of files where hash_file actually succeeded this run
(whether the result landed in new/changed/unchanged). NOT the same as
len(unchanged): an errored file with a prior hash is also carried
into unchanged (H7), so unchanged alone cannot tell a real
outage (every hash attempt failing) from ordinary steady state (nothing
changed).
skipped = 0
class-attribute
instance-attribute
¶
Count of files carried forward as unchanged purely because the git
fast path excluded them (not a candidate) — a deliberate, healthy skip,
never hashed and never in doubt. Distinct from verified because a
caller judging "did this run make zero real progress" must not count a
narrow candidate set (fast path correctly skipping most of the tree) as
equivalent to a whole-tree hashing outage: verified + skipped == 0
together with errored is a real "nothing in the whole discovered set
is in a known-good state" signal; verified == 0 alone is not, since
it is the fast path's steady-state norm.
hash_file(path)
¶
SHA-256 hex digest of a file's content, read in chunks.
Source code in src/noesis/core/hashdiff.py
18 19 20 21 22 23 24 | |
partition(root, discovered, stored, *, candidates=None, discovery_errored=())
¶
Partition discovered (relative POSIX paths under root) against
stored (path -> content_hash from the files table).
Files that vanish between discovery and hashing (FileNotFoundError / NotADirectoryError) are treated as deleted — the filesystem is ground truth at the moment it is read. A file that still exists but fails to open for another reason (permissions, transient network-fs error) is NOT treated as deleted: its stored hash is carried forward so its chunks are never purged (H7).
When candidates is given (git fast-path, §3.2), only discovered files
that are candidates — or unknown to stored — get hashed; the rest
carry their stored hash forward as unchanged. Candidacy only shrinks
the hashing work, never decides changed/unchanged by itself (rule 1):
every hashed file is still compared against stored, and deletions
fall out of discovery exactly as in the full walk.
discovery_errored lists (path, error) pairs for files discovery could
not screen (transient stat/read failure) and therefore excluded from
discovered — they get the same treatment as a hash-time OSError (H7):
surfaced in errored, stored hash carried forward, never deleted.
Source code in src/noesis/core/hashdiff.py
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 | |
noesis.core.indexer
¶
Indexing pipeline: discover → hash-diff → chunk → embed → upsert (§3.2).
Orchestrates the M1 spine (discovery, hashdiff, state) with the M2 pieces (chunker, Embedder, VectorStore). Dense channel only in M2 — the sparse/BM25 channel and RRF fusion land in M3; the git fast-path narrows the candidate set in M7. Embedding batches go through the Embedder Protocol at LOW priority so live queries preempt indexing (§3.8).
logger = logging.getLogger(__name__)
module-attribute
¶
ProgressFn = Callable[[int, int, int], None]
module-attribute
¶
IndexResult(project_id, run_id, files_total, files_indexed, files_deleted, chunks_written, fast_path_used=False, candidate_count=None, files_failed=0, failed_paths=(), unverified_suppressed=0, discovery_degraded=0)
dataclass
¶
project_id
instance-attribute
¶
run_id
instance-attribute
¶
files_total
instance-attribute
¶
files_indexed
instance-attribute
¶
files_deleted
instance-attribute
¶
chunks_written
instance-attribute
¶
fast_path_used = False
class-attribute
instance-attribute
¶
candidate_count = None
class-attribute
instance-attribute
¶
files_failed = 0
class-attribute
instance-attribute
¶
failed_paths = ()
class-attribute
instance-attribute
¶
unverified_suppressed = 0
class-attribute
instance-attribute
¶
discovery_degraded = 0
class-attribute
instance-attribute
¶
is_attributable_prefix(dir_rel)
¶
True when dir_rel is a root-relative prefix _under can test.
False for the three shapes that describe no subtree of this project: the
empty string, the <root> sentinel, and a path outside the root (an
absolute name, or one reached by ../) — which discovery records when
relative_to fails. Public because the promotion policy in jobs asks
the same question of a stored ledger row: an unattributable failure leaves
the whole index unverified, which no scoped run can make progress on.
Source code in src/noesis/core/indexer.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | |
discovery_config_for_project(conn, project_id)
¶
Build a project's persisted index scope (ADR-42) into a DiscoveryConfig. Returns None for an unknown project (caller falls back to the default walk). NULL columns map to DiscoveryConfig defaults, so an unconfigured project walks exactly as before.
Source code in src/noesis/core/indexer.py
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 | |
prepare_run(conn, embedder, root_path)
¶
Register (or re-open) the project and open a run row.
Split from :func:execute_run so the API can hand back
202 Accepted + run_id before indexing starts (§3.2).
Goes through :func:state.try_start_run — the same guard as
jobs.launch_index_run — and raises RuntimeError when a live run
already holds the project: returning that run's id would make this
caller execute it concurrently with its owner, the exact race the
guard exists to prevent.
Source code in src/noesis/core/indexer.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 | |
index_project(conn, store, embedder, root_path, *, batch_size=32, discovery_config=None, git_fast_path=True)
async
¶
Register, open a run, and index in one call (tests / CLI use).
Source code in src/noesis/core/indexer.py
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 | |
execute_run(conn, store, embedder, root_path, project_id, run_id, *, batch_size=32, discovery_config=None, git_fast_path=True, paths=None, force=False, unwalkable_quarantine_runs=5, on_progress=None)
async
¶
Index changes for an already-registered project under an open run.
Idempotent: chunk ids are content-derived and file state is only written after that file's chunks are safely in Qdrant, so an interrupted run re-processes only what is still out of date (Overview §5).
paths scopes the run to an explicit candidate set (the watcher's
pending files, ADR-40): only those files (plus anything unknown to
stored state) are hashed; deletions are still detected discovery-wide.
A scoped run disables the git fast path and NEVER advances
last_indexed_commit — the anchor may only move when the candidate
set was derived from a git diff against it, otherwise the next fast
path would silently skip files the watcher never saw (§3.2 rule 1).
force accepts a discovery result of zero files as real deletion evidence even when state still tracks files. Off by default: nothing observable distinguishes an emptied root from an unmounted one, so the assertion has to come from an operator (ADR-55). It relaxes nothing else — a directory that failed to scan still suppresses deletions under it.
unwalkable_quarantine_runs is how many consecutive runs a directory must
fail to be walked before the stored paths it hides stop being re-queued for
retry (ADR-56). 0 disables quarantine. It relaxes nothing about
deletion either: a quarantined subtree's files are still never purged, and
the run that finds the directory readable again re-hashes every one of
them. All it bounds is the pending_changes backlog, which under a
permanently unreadable directory could otherwise never drain (issue #25).
Source code in src/noesis/core/indexer.py
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 | |
noesis.core.jobs
¶
Job manager — one place both adapters launch and inspect index runs.
Part of the Core Engine's "Job/State manager" box (§3.1). REST
(POST /projects, POST /projects/{id}/reindex) and the MCP reindex
tool must behave identically (two thin adapters over one core), so this
module owns the single launch path: open a run row, hand back ids
immediately, and index in a background task tracked in ctx.jobs so the
app lifespan can cancel orphans on shutdown.
M8 additions (ADR-40): watcher-scoped launches (paths narrows the
candidate set, triggered_by records provenance), in-memory live
progress per run (ctx.progress, read by the dashboard — deliberately
not persisted: live progress of a dead process is meaningless), and
pending-change clearing once a run has examined the files.
logger = logging.getLogger(__name__)
module-attribute
¶
launch_index_run(ctx, root_path, *, paths=None, triggered_by='manual', force=False)
¶
Register (or re-open) the project and start indexing in the background. Returns the 202-style acceptance body shared verbatim by REST and MCP.
Fails fast with ValueError before touching state when root_path is
missing or not a directory (an agent gets the answer now instead of
polling a background failure), and on the mixed-model guard
(state.register_project). If a run is already running for this
project, launches nothing (a second concurrent index would race on the
same collection and state rows) and returns that run's id with
status: "already_running" — a distinct status so a scoped/watcher
caller can tell its launch was skipped and re-arm its retry (H3). A
real launch returns status: "accepted".
force is passed straight to :func:execute_run: it lets a discovery
result of zero files count as deletion evidence when state still tracks
files (ADR-55). Only an operator can make that call — nothing observable
separates an emptied root from an unmounted one — so it is never set by
the watcher, and the REST route is the only caller that exposes it. The
MCP reindex tool deliberately does not: its caller is an agent.
Source code in src/noesis/core/jobs.py
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 | |
run_progress(ctx, run_id)
¶
Live progress for a running run: percent, counts, elapsed, ETA. None when the run is not tracked (finished, or another process's). ETA is naive linear extrapolation over files processed — honest enough for a progress bar, no smoothing pretence.
Source code in src/noesis/core/jobs.py
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 | |
index_status(ctx, project_id)
async
¶
Latest run for a project, shaped identically for REST and MCP.
A registered project with no runs yet reports never_indexed with
the run fields nulled — a stable shape beats a shape-shifting one for
agent consumers.
Async so the quick state.* reads stay on the event loop (the shared
sqlite conn is loop-owned; a worker-thread read can interleave inside
another op's open BEGIN IMMEDIATE transaction) while only the
synchronous Qdrant count round-trip is pushed to a worker thread.
drift is reported only when the expected chunk total held still
across that round-trip and still disagreed with the store. The cost of
that rule is worth stating: while a run is actively committing, drift
reads False even if the store genuinely lost data — the first call after
the run settles reports it. A false negative for a few seconds beats a
false positive on every status poll during every index run.
unwalkable_dirs / quarantined_dirs (ADR-56) are the coverage half
of the same health picture: directories discovery could not walk, and the
subset that has failed long enough for their contents to stop being
re-queued. Both zero is the healthy state. Non-zero does not mean anything
was deleted — nothing under an unwalked directory is ever purged — it means
what is indexed there cannot be proven current.
embedder_assets/embedder_ready mirror /healthz's ADR-77/78
fields (issue #47 finding 4, PR #50 round-4 review) — this is the shared
REST/MCP status shape, so an MCP-only (stdio) caller with no HTTP surface
to poll can now see the same cold-start warm-up signal a REST caller gets
from /healthz. reranker_assets/reranker_ready are the same
pair for the optional cross-encoder (issue #52), "disabled" when the
reranker.enabled kill switch is off. Computed via
prefetch.model_readiness/reranker_readiness, the same functions
/healthz calls (PR #50 round-5 review) — not a second copy of the
readiness logic kept in sync by hand.
Source code in src/noesis/core/jobs.py
306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 | |