cbm_daemon_ipc_connection_peer_pid() had branches for Linux
(SO_PEERCRED), macOS (LOCAL_PEERPID) and NetBSD (LOCAL_PEEREID), but
FreeBSD defines none of them, so it fell through to `return 0`, and
runtime_accept_connection() closes every connection whose peer pid is
0: on FreeBSD the daemon rejected every client.
Read the peer credentials with getsockopt(SOL_LOCAL, LOCAL_PEERCRED)
into a struct xucred and accept only the expected layout version, the
caller's effective uid and a positive pid, mirroring the Linux branch.
The branch and its <sys/ucred.h> include compile only on FreeBSD.
Carried forward from #2492, which also raised three timeouts on every
platform; those are left out (CBM_STARTUP_TIMEOUT_MS covers slow hosts).
Co-authored-by: Yury Romanov <romanov@outlook.com>
Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
The frontend maintenance monitor probes for a maintenance request on
every cycle, and each probe try-acquires the maintenance marker lock (on
Windows that revalidates the whole ancestor directory chain). The quiet
no-maintenance cadence was raised from 10 ms to 250 ms because the 10 ms
loop burned a large share of a core for the life of every MCP session,
but nothing pinned that cadence: a regression back to the hot loop would
pass every suite.
The monitor now sleeps on a local idle_ms in its ABSENT branch and, under
CBM_ENABLE_TEST_SEAMS only, records that exact value immediately before
sleeping on it (cleared by cbm_daemon_frontend_test_observer_reset). The
new test starts an idle monitor, waits until a value is recorded, stops
the monitor and asserts the recorded sleep is at least 250 ms. Once set,
the recorded value is stable, so the verdict depends on neither elapsed
time nor scheduler cadence; the deadline is only a hang guard. Production
builds carry no seam code and sleep the same 250 ms as before.
The original test counted presence observations inside a 100 ms window,
which asserts a transient timing window; it is replaced by the recorded
cadence above.
Refs #2093
Distilled from #2215.
Co-authored-by: lorenzozanee <wyz0707@proton.me>
Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
Conflicts resolved:
- src/daemon/runtime.h: both sides add test seams at the end of the
CBM_ENABLE_TEST_SEAMS block. Kept main's connection-cap and HELLO-order
seams and placed this branch's fingerprint-cache seams after them; the
branch's added lines are unchanged.
- src/cli/hook_augment.c: kept main's re-arm guard, which opens the
timeouts log only once and keeps that descriptor. Dropped main's early
return and breadcrumb formatting after the open: this branch formats
the breadcrumb before the log path is resolved, so stderr gets it even
when the log cannot be opened. That formatting runs on every arm, so
main's re-arm comment now says the text above is refreshed, and the
#858 header comment now says the breadcrumb also goes to stderr.
Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
The fingerprint cache sat in every fingerprinting acquire, including
peer verification. Limit it to the process's own image: every acquire
site now passes the process id to the shared resolve step, which marks
a peer's key invalid, so a peer is never looked up, never committed,
and is hashed on every fingerprint. Re-hashing of verified peer copies
is handled by the runtime service's retained peer references (#2335).
The daemon's saving is unchanged: it hashes its own image once at start
instead of twice.
A process has one own image, so the cache drops from 8 entries to 1,
which removes the slot search and the round-robin eviction.
The cache comment no longer claims that SetFileTime cannot reset the
Windows change time; SetFileInformationByHandle can set it. Limited to
the own image, the key does not rely on it: Windows keeps a running
image locked against modification for as long as the process, and so
the cache, exists.
Test: daemon_runtime_process_fingerprint_caches_only_own_image spawns
this runner as a peer, whose image has the same file identity as the
own image, and asserts that two peer fingerprints cost two hashes, two
own fingerprints one more, and a later peer fingerprint one more again.
Before this change the second peer fingerprint was served from the
cache.
Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
Brings the branch up to main 9c19b5dd.
Two same-spot insertion conflicts, each resolved as the main version
of the file plus the own diff of this branch:
- src/daemon/application.c: the job struct gained watch_owners on main
and request_started_ms plus the request facts here; both kept.
- tests/test_daemon_application.c: main added the #1818
autoindex-skipped helpers where this branch added the worker resource
failure test; both kept, the test placed after the doc_candidates
test.
Everything else merged cleanly. src/main.c changed on both sides: main
(#2838) lowers the worker CPU priority inside the worker role block,
and this branch strips the publication fence flag before that block
and installs the fence after the worker role options; the hunks are
disjoint and both are kept. tests/test_pipeline.c gained the Next.js
route tests (#2747) on main and the publication gate test here, also
disjoint. No call site needed adapting: no new main code calls a
function this branch re-signed, and main re-signed none that this
branch calls.
Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
A worker resource limit is enforced by the supervisor, but only the worker
replaces the serving database, and it does so before the persistence
artifact export. A limit observed in that window stopped a worker that had
already published, and the response still said serving_index_preserved=true
while the previous index had been replaced.
Publication and resource termination now coordinate through a per-attempt
publication fence: a never-created path next to a reserved unique file in
the private worker directory, which both sides claim by creating it
exclusively (cbm_fopen "wbx": O_EXCL on POSIX, CREATE_NEW on Windows), so
exactly one of them can win.
- The worker claims it through a new pipeline publication gate that
cbm_pipeline_run calls once, after the last pre-publication check and
before the serving database is touched. Losing means the supervisor
already stopped the attempt for a limit: the run aborts before
publication and the previous generation stays in place.
- The supervisor claims it before it terminates the worker for a limit or
a failed RSS probe. Losing means the worker already committed to
publishing: the limit is no longer enforced for that attempt, which runs
to completion, and index.supervisor.resource_limit_after_publication is
logged instead. A claim that can be neither won nor lost is retried on
the next poll rather than risk stopping a committed worker.
- At terminal the supervisor settles the fence into
result.publication_committed. An unquiesced tree keeps the fence, so a
surviving member can never publish after the report.
serving_index_preserved now describes the request, not only its last
attempt: a servable index existed when the request began, no attempt of
the request committed to publishing (an earlier attempt can publish and
then crash into recovery), and that index is still servable. The direct
path and the daemon job both fold every attempt into these request facts;
cbm_mcp_index_worker_resource_response takes them as a third argument, and
NULL claims nothing.
The fence path travels as an optional last pair of the exact worker grammar
(--index-worker-publish-fence), accepted by the worker argv parser and by
the daemon bootstrap role check, stripped by the CLI and installed by both
worker entries.
Limits stay opt-in: without index_max_rss_mb or index_max_duration_seconds
there is no fence, no extra argv, no claim and no extra database read.
Graph content is unchanged either way.
RED (c78c077a plus only the new end-to-end test): a FIFO at the artifact
temp path holds the real worker after the rename, and the duration clock
crosses its limit only once the serving database has been replaced. The
supervisor stops the worker there and answers resource_limit_exceeded with
serving_index_preserved=true over a replaced database. GREEN: the worker
claimed first, the supervisor logs the limit as not enforced, and the
released worker finishes and reports the published index.
Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
Brings the branch up to main a5b248f47. Eight files conflicted, each a
same-spot insertion where main and this branch added lines next to the
same anchor. Each resolves to the main version plus the change of this
branch:
- src/cli/cli.h, src/cli/cli.c: CBM_CONFIG_IGNORE_WORKTREES and its
CONFIG_KEYS row next to the new doc_candidates key.
- src/mcp/mcp.c: the index_worktree schema property next to the new
doc_candidates property.
- README.md, docs/CONFIGURATION.md: the ignore_worktrees line and table
row next to the rewritten auto_watch entries and the new
doc_candidates and watch_non_git rows.
- src/git/git_context.c: the env-isolation comment after the new debug
stage marker, directly above cbm_popen_git.
- src/cli/hook_augment.c: the new SubagentStart cli_hint ahead of the
parent-graph check of this branch.
- tests/test_mcp.c: both RUN_TEST blocks; main already includes
str_util.h.
Per file, the lines changed against main equal the changes of this
branch against the merge-base.
Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
The recovery path replays the session context and UI settings on the
replacement daemon. It waited on the bootstrap connect budget, which only
bounds a probe (1 s in production), while main.c gives the first
set_context and set_ui_config the startup budget since eb294298e. A
replacement daemon whose UI save runs longer than a probe would end an
otherwise good recovery.
frontend_configure_client now waits on startup_timeout_ms. A test seam
records the budget the replay used, and the recovery fixture gives the
bootstrap distinct connect and startup budgets and exits 75 when the
replay waited on the wrong one. With the old budget exactly the three
recovery tests fail with exit 75; with the fix daemon_frontend is 17/17.
Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
A daemon started with `daemon start` now keeps a project watched after its
last owning MCP session closes, until the daemon stops, the project is
deleted, its directory disappears, or auto_watch is set to false. README
(the watcher paragraph and the index_repository row), the watcher_enabled
row of docs/CONFIGURATION.md and the comment above the index_status watch
provider still said every watch ends with its last session.
Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
Under `daemon start` the session watch release kept every watch whose last
subscriber left, so the daemon could keep watching after the session ended.
The same release also runs when a session's root stops being allowed by
workspace policy (an approval revoked, a boundary declared). That is not a
disconnect: the session is still open and its root is refused, so keeping
the watch there let a permanent daemon go on indexing a root the user had
just withdrawn.
application_release_session_watch_locked() now takes session_ending. The
cancel and close paths pass true and keep the daemon-owned watch exactly as
before; the workspace-policy branch of the watch refresh passes false and
removes the watch in both modes, as it did before permanent watches.
Test: daemon_application_permanent_workspace_release_still_ends_watch
revokes the sensitive-root approval of a permanent session's root and sends
one request; its synchronous refresh must end the watch (RED when the
policy branch passes true).
Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
Under `daemon start` a watch now outlives its last session. delete_project
from another session or the CLI removes the project's DB but meets no owner
of the watch: daemon MCP sessions carry no watcher pointer, so nothing
unwatches it, and the next change in that root re-indexed the deleted
project.
When a permanent watch has no subscribers, no job for its project is
running and its DB is gone, the watcher callback now removes the watch and
skips, the rule a session refresh already applies to a deleted project.
The running-job guard is needed because a full reindex unlinks the DB while
it rebuilds it: a second change during that rebuild must join the job, not
end the watch. Session-owned watches are unchanged.
Tests: daemon_application_permanent_watch_ends_when_project_db_is_deleted
(RED before: the deleted project was re-indexed) and
daemon_application_permanent_watch_kept_while_its_reindex_runs (RED
without the running-job guard: the second change ended the watch).
Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
Bring the permanent-daemon watch ownership change up to current main.
Three conflicts in src/daemon/application.c:
- Struct comments: keep main's index-record bookkeeping struct as is,
then the branch's comment on watch-job subscriptions describing the
permanent-mode ownership.
- application_release_session_watch_locked: main now releases every
watch membership a session holds. Keep that loop and apply the
branch's rule inside it: a permanent daemon keeps the physical watch
when its last subscriber leaves; non-permanent applications still
remove it.
- application_background_index_admit: watch_live keeps main's
application_watch_root_matches() and the index-args encoding that
follows it, and additionally admits a permanent watch with no
subscribers.
Ownership hand-off: main split application_background_index into
_admit and _wait, so the watcher-ownership flag set at admission could
no longer reach the terminal unsubscribe in the wait loop. _admit now
reports it through a bool out-parameter, application_background_index
passes it to _wait, and _wait releases the retained subscription once
when the job is terminal. The terminal block always breaks out of the
loop, so the old reset of the flag after that release is gone.
Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
src/main.c conflicted in two hunks of the stdio server startup. Both
keep the recovery structure of this branch and carry the startup budget
from main (eb294298e) into it:
- set_context: the inline main_session_context() + set_context() of this
branch stays (the recovery replay needs mcp_session_root and
mcp_allowed_root), with its endpoint free on the failure path; the
timeout bootstrap_config.startup_timeout_ms and the startup-budget
comment are taken from main.
- set_ui_config: the mcp_ui_* variables of this branch, declared above
the block, stay (they feed the replay); the timeout
bootstrap_config.startup_timeout_ms is taken from main.
Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
main moved 12 merges past this branch's last base (72c36044). One
conflict, in src/daemon/application.c: #2737 split
application_background_index() into admit/wait helpers and gave it
named result codes. Resolved by taking main's structure and keeping
this branch's one change there: the automatic job's args carry
_cbm_background after the policy call. The watcher path re-encodes
mode/persistence/doc_candidates into the same document, so the marker
survives the re-encode, and the job comparison still drops it.
The net diff against main is unchanged: the same 13 files and the
same added and removed lines as before the merge.
Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
When daemon-backed auto-indexing refuses a repository, the
daemon.autoindex.skipped warning reported the tracked-file count but not
the limit that caused the refusal. The MCP autoindex.skip event already
carries limit=<n> (#1466); add the same field to the daemon warning,
using the auto_index_limit value the admission check already used.
Admission behavior is unchanged.
daemon_application_auto_index_honors_tracked_file_limit now captures the
warning through a log sink and asserts reason=too_many_files, files=1 and
limit=0 as whole fields.
Fixes#1818
Signed-off-by: Gaurav Dubey <gauravdubey0107@gmail.com>
Match canonical Windows separators across watch ownership and admission,
drain all session watches when auto_watch is disabled, and retain the
resolved doc_candidates choice for later refreshes. Add deterministic
regressions for the five observed failures and an absent-option guard.
Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
Thank you for the Windows path fix and the careful pre-fix investigation. This uses the existing UTF-8 filesystem helpers so valid repository roots and cached graph databases are not mistaken for missing paths.
Contributor history and DCO are preserved.
Automatic jobs (session auto-index, watcher re-index) now carry
_cbm_background, and the job registry decides whether a new request may
join the job already running for its project by comparing the index
arguments after normalising defaults. An explicit index_repository for
the same root therefore stopped matching the automatic job and was
refused with "another index operation for this project is active with
different options" -- the refusal the repo_path separator fold
(9846c3f1) removed on Windows, now on every platform.
_cbm_background chooses the worker count and never what is indexed, so
drop it from the comparison the same way default-valued options are
dropped. The explicit request joins the running job again.
The new daemon_application test holds an auto-index job open with the
fake worker, checks that its args carry the marker, and sends an
explicit async index_repository for the same root. Without this change
it is refused as an options conflict; with it the request joins (one
worker start, one active job). The async fixture gains an optional
stored config so the test can enable auto_index.
Refs #1084
Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
main moved 1,029 commits past this branch's base (96c3f41c). Six
same-spot conflicts, each resolved by keeping both sides:
- src/mcp/mcp.c, index_run_supervised_path: the supervised worker args
keep main's doc_candidates forwarding and add _cbm_background after it.
- src/mcp/mcp.c, autoindex_thread: main's index_doc_candidates_apply()
runs first, then the committed-index headroom decision.
- src/pipeline/pipeline.c, run_extraction_phase: a frozen pipeline still
forces one worker and records its route; every other pipeline takes
cbm_pipeline_worker_count().
- src/pipeline/pipeline_incremental.c, run_extract_resolve: same shape,
the frozen check first, then the pipeline-aware count.
- src/pipeline/pipeline_incremental.c, closure_probe_surfaces: main's
def_count < 0 abort is kept; the surface rows borrow probe_ctx with the
pipeline set only around that one call, as before. probe_ctx never
allows spilling, so the result lookup takes the same branch it took
with a NULL context.
- tests/test_mcp.c: both RUN_TEST blocks are kept.
Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
Bring the branch up to current main (a2227157) so the PR checks run
against today's tree. Textually clean; no conflict resolution.
Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
Watchdogs now sample the OS-charged footprint instead of resident size on
Darwin, and index_max_duration_seconds covers the whole request so a
crash/hang respawn cannot reset the clock.
Signed-off-by: 刘冲 <mail@liuchong.dev>
Discovery limits bound what indexing accepts, not what it then costs. A
repository well inside those bounds can still exhaust the host through parser
memory, or simply never finish, and a supervised worker that hangs leaves the
parent waiting with nothing to report.
Add index_max_rss_mb and index_max_duration_seconds, enforced by the parent
against the worker process tree rather than the worker process alone, so a
runaway child cannot hide behind a small parent. Resident memory is sampled
through the platform interface on macOS, Linux and Windows. Crossing a limit
terminates the tree and yields one trusted, structured terminal result that
attributes the failure to the resource that caused it.
Both limits default to off. A measurement that cannot be taken fails the
attempt instead of passing it: a watchdog that quietly stops watching is
worse than no watchdog at all.
The shell fixture that stands in for the supervisor names the two new keys.
The worker accepts only a policy that spells out every key it knows, which is
what keeps a stale supervisor from starting a worker it cannot bound.
Signed-off-by: 刘冲 <mail@liuchong.dev>
The daemon keeps adjacency layers (store/graph_mem.h) resident across
requests -- 237 MB for the kernel -- with no end of life but LRU pressure.
- Idle eviction: a layer nobody has held for CBM_GRAPH_MEM_IDLE_EVICT_MS
(10 minutes, measured from its last release) is evicted on the next
request: cbm_mcp_handle_tool sweeps after releasing the request store, and
every acquire sweeps too. No timer thread. Ten minutes outlasts the gaps
between an agent's graph calls within one task, while a session that moved
on stops pinning the memory; a wrong guess costs one rebuild (1.2-1.5 s on
the 17 GB kernel index, tens of ms on ordinary repos). The clock is a test
seam (cbm_graph_mem_set_clock_for_testing), so tests move time instead of
waiting.
- Worker budget: application_worker_memory_slice_locked hands index workers
the aggregate minus the resident layer bytes (cbm_graph_mem_cached_bytes),
at least one byte per active job so a slice never reads as "no cap".
- Memory class: layers are charged to the new CBM_MEM_CLASS_GRAPH_CACHE
("graph_cache" in census and class logs) instead of STORE.
Responses stay byte-identical to the baseline on django and redis (tools
and Cypher) and on the kernel trace/hub and extra BFS/degree cases.
Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
Use existing UTF-8 filesystem inspection for watcher roots, .git markers,
and cached graph databases. Preserve symlink following and distinguish
confirmed absence from unavailable inspection before pruning projects.
Cover an existing Unicode root with zero prune grace and capture the
blocked-git test environment through the existing UTF-8 runtime helper.
Split the independently applicable bug fix from the original certified
EmbeddingGemma 2 contribution without changing its file contents.
Signed-off-by: H4M4CHi-ttr <42773515+H4M4CHi-ttr@users.noreply.github.com>
Doc-section -> code candidates (doc_link_candidates, #2574/#2610) are the
documentation-in-the-graph feature of this release. They now run by
default for full indexes and not for moderate or fast ones; an explicit
`doc_candidates` argument, or a `doc_candidates` setting the user set,
overrides the default either way in every mode.
- pipeline: the switch is unset/on/off; unset means on only when the
effective mode is full.
- MCP: forwards only an explicit choice (argument, then a user-set config
value) to daemon jobs and workers; daemon auto-index and watcher/UI jobs
now carry a user-set value too (their workers have no config, so
`doc_candidates false` was ignored there).
- fast + doc_candidates on runs the semantic pass's corpus phases and the
doc phase only: candidates, and still no SIMILAR_TO or
SEMANTICALLY_RELATED edges.
- config: `doc_candidates` joins the config key table (default `auto`);
`config set doc_candidates ...` was refused as an unknown key before.
README, docs/CONFIGURATION.md and the MCP schema describe the default.
Proof (macOS arm64, django fb11376):
full 11,304 rows · moderate 0 · fast 0 · full+off 0 · moderate+on 1 ·
fast+on 1 (moderate/fast discovery skips docs/) -- nodes and edges are
identical between on and off in every mode; fast+on adds 0 semantic
edges.
- New tests (RED on the old code): pipeline
pipeline_doc_candidates_default_follows_mode,
pipeline_doc_candidates_explicit_wins_over_mode,
pipeline_doc_candidates_fast_on_legacy_incremental; mcp
tool_index_repository_doc_candidates_follow_mode,
tool_index_repository_doc_candidates_forwarded_only_when_explicit;
daemon_application
daemon_application_programmatic_index_forwards_set_doc_candidates.
- mcp 374 passed (4 Windows-only skips), daemon_application 73 passed,
pipeline/store_arch/cli/runtime_settings/index_policy/pipeline_frozen
green on the release tree.
Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
Normalize Windows cache paths when reporting runtime settings and resolve
Git executables before spawning history queries. Keep executable lookup
results per thread and cover the ownership contract deterministically.
Support Git 2.43 while denying history-query network transports, and close
the activity database on daemon startup failure so Windows can clean up.
Validation: 463 native macOS tests, 421 Windows tests, 44 MSan UI tests,
and focused canonical lint passed. Production-only revert checks confirm
the repaired failures.
Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
Reconcile the complete Atlas and Lens stream with current main while retaining both histories. Preserve architecture functionality, current process and watcher safeguards, test infrastructure, and dependency security updates. Add coverage for Git-environment isolation combined with child-local overrides.
Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>