Sync 5 Inkeep OSS Changes#713
Merged
Merged
Conversation
* chore(open-knowledge): shared timing/port/tmpdir helpers Add a browser-safe sleep() to core utils and migrate the five production call sites that re-declared it (file-lock, handoff dispatch, embedder, single-file session, terminal consent). Promote the parameterized getFreePort() into a shared app test helper used by both the integration harness and the stress helpers. Add a withTempDir() test helper (mkdtemp plus rm -rf in finally) and migrate two exemplar perf test files; other call sites migrate opportunistically. Compose the repeated drift-guard bash chain in package.json as check:drift:guards without changing any effective command sequence. * test(open-knowledge): cover shared port/tmpdir helpers, tighten sleep bound Address review feedback on the shared-helpers hygiene PR: - Add free-port.test.ts and temp-dir.test.ts so the two new test helpers' behavioral contracts are guarded (getFreePort port-range + explicit family; withTempDir happy path plus cleanup-on-throw, its raison d'etre). - Tighten sleep.test.ts lower bound from 50% to ~80% of nominal (>= 16 for a 20ms sleep) so a halved-delay regression is caught while staying flake-safe. - Drop the redundant identity ternary in getFreePort now that loopbackHost is already narrowed to the '127.0.0.1' | '::1' union. * chore(mirror): sync OK check strip rule with check:drift:guards refactor The check/check:full:parallel/check:drift refactor into check:drift:guards changed the OK package.json check value, but the copybara manifest's HEAD-drift strip rule (replacement #0) still held the old inline chain, so its before: matched 0 times and Monorepo Structural Validation failed the manifest HEAD-drift guard. Update the before: to the refactored check value and regenerate the bara.sky. Verified: head-drift guard passes (checked=21), mirror-includes clean, and a simulated mirror transform confirms check:drift:guards ships leak-free (golden-reference/md-audit/md-conformance internals stay stripped). GitOrigin-RevId: ba365caa65eff929d728079b488dad339ae2d72e
* perf(server): bound the exec tool mtime safety sweep Scope the pre/post mutation sweep to the paths the command's own tokens can touch (operands, glob prefixes, attached flag values) instead of statting up to 1000 arbitrary files across the whole corpus on every call. Commands that implicitly operate on the cwd (bare ls, find, recursive grep with no dir) keep the whole-tree sweep, and a capped sweep now discloses partial coverage via a warning instead of silently posing as a full safety net. * fix(server): scan whole tree for recursive grep with -e pattern deriveScanRoots left the -e/--regexp pattern value in the operand list, so a dead scan root was seeded and the empty-operand whole-tree fallback the JSDoc promises never fired. grep -rn -e pattern therefore covered no files instead of the cwd, silently narrowing the mtime safety sweep for a common command form. Drop pattern values from operands however they are supplied, so the fallback fires, and pin the fail-safe with regression tests plus two suggested coverage additions. GitOrigin-RevId: f3e0d044b4c81fb4e86d711b6a3632c62aaf4f91
* feat(server): sampler wiring plus runtime and queue-depth gauges Add cloud-operator observability to the OK server telemetry layer: event-loop delay p50/p99 and CPU utilization gauges, external and arrayBuffers memory sections, a loaded-documents gauge, and pull-based queue-depth gauges for pending persistence stores and the bridge drain backlog. Stamp the errorResponse correlation UUID on the active span so traces join against client-reported instances. Pin the standard OTEL_TRACES_SAMPLER env contract with tests and document that sampling also thins the local bug-bundle span sink. All additions are zero-overhead when telemetry is disabled and use bounded-cardinality labels only. * fix(server): drain workload gauge providers on init failure, address review Addresses PR review feedback on the observability quick-wins: - Init-failure leak (blocking): createServer() now drains the pull-based workload gauge providers from the catch handler, not just destroy(). A throw after registration no longer leaves closures capturing a half-torn-down hocuspocus/persistence in the process-global registries. The drain is idempotent (splice(0)), so destroy()'s later drain is a no-op. - Move PersistenceQueueDepths to persistence.ts so the domain module owns the type and telemetry depends on persistence, not the reverse. - Rename ok.docs.loaded to ok.server.docs.loaded: it is a server-instance-wide gauge and belongs in the ok.server.* tier alongside the process-health metrics, not a subsystem prefix like the queue/backlog gauges. - Rename __resetServerMemoryGaugeForTests to __resetServerRuntimeTelemetryForTests since it now resets the memory, event-loop, and CPU instruments. - Harden the two runtime-gauge tests: poll instead of a fixed 120ms sleep for the event-loop histogram, and collect twice explicitly in the CPU test to remove the cross-test ordering dependency. GitOrigin-RevId: e29df3182c8883da628279eafb5845b3408339e6
* perf(app): coalesce PageListContext refetches on CC1 files pushes Route the push-triggered full-corpus refetch (/api/pages plus the recursive /api/documents walk) through the same createRefreshScheduler pattern FileTree uses, behind a 300ms trailing coalescing window. A bulk agent write streams CC1 files pushes about 10x/sec and each one refired the whole fetch pair plus every derived index rebuild; a burst now produces one refetch and a sustained storm refreshes about 3x/sec. The initial mount load, focus/visibility refreshes, and the exposed refetch() stay immediate, and the requestId latest-wins guard is unchanged. * docs(app): clarify PageListContext coalescing comments and add tests Reword the coalescing-window docblock and mount-effect comment so they describe the arm-once timer sitting in front of createRefreshScheduler (which fires its first request eagerly) rather than implying the same shape as FileTree. Fix the causal 10x/sec phrasing in the source and test headers to say the push rate is capped at one per 100 ms debounce window, align the test-header invocation to bun run test:dom to match the sibling suites, and add coverage for unmount cancelling the armed window and a focus refetch firing immediately while the window is armed. GitOrigin-RevId: 33e1a61068dcb5064909d5214b6180a52deab4cd
* feat(diagnostics): crash capture record + MCP stderr log mirror A fatal server crash now writes a synchronous last-crash.json under .ok/local/ plus one fatal JSONL line in the server log sink, so bug-report bundles can say why the server died instead of just 'not running'. Wired via an observe-only uncaughtExceptionMonitor in bootServer, preserving Node's default crash semantics (covers unhandled rejections under the default throw mode). Both bundle levels collect the record. The global MCP stdio server's [mcp] stderr diagnostics are now mirrored to ~/.ok/logs/mcp.<date>.log (desktop-convention retention: 7-day age + 45 MB aggregate sweep, scoped to mcp files), which the standard bundle's user-log scan already collects. Host-visible stderr stays byte-identical; mirror failures are swallowed and self-disable, never breaking the MCP server. * fix(diagnostics): address crash-capture review feedback Re-ensure the MCP stderr mirror's logs dir on write failure so an externally removed ~/.ok/logs recovers on the next write instead of counting down to a permanent self-disable, matching the desktop logger's recovery posture. Adds a mid-session dir-removal recovery test. Document last-server-crash.json as a deliberate latest-crash-only truncate write and pin the contract with a test: the append-mode JSONL sink preserves the full crash timeline (root cause included) that the bundle also collects, so a restart loop loses nothing. Rename last-crash.json to last-server-crash.json for symmetry with its complementary sibling last-server-exit.json (inside vs outside view of the same server death). Reword the changeset so the mirror's retention reads as pruned at each startup by a 7-day age window and an aggregate size cap, not a live in-session ceiling. GitOrigin-RevId: 485e5be5bad92b65d229b209190fe3904f1085c8
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Copybara-translated 5 Inkeep OSS changes. Rebase-merge this PR so the prepared commits land directly on public main.
Commits: