Skip to content

fix(install): repair smart-explore runtime provisioning across IDEs#3095

Closed
rymalia wants to merge 2 commits into
thedotmack:mainfrom
rymalia:fix/smart-explore-runtime-provisioning
Closed

fix(install): repair smart-explore runtime provisioning across IDEs#3095
rymalia wants to merge 2 commits into
thedotmack:mainfrom
rymalia:fix/smart-explore-runtime-provisioning

Conversation

@rymalia

@rymalia rymalia commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Summary

Fix the shared installation path so smart-explore is actually functional after
installing claude-mem, and fail loudly when its runtime cannot be provisioned
instead of reporting success with silently broken tools.

Previously, the installer could report success while leaving tree-sitter-cli
without its platform executable. The MCP tools were registered and callable,
but structural parsing silently failed:

  • smart_search scanned files but returned zero symbols
  • smart_outline could not parse supported TypeScript files
  • smart_unfold could not locate symbols

This affected fresh installations across IDEs, including the current 13.9.1
release.

Root cause

Three independent failures combined to make smart-explore appear operational
while returning empty results.

  1. Plugin dependencies were installed with lifecycle scripts disabled.
    tree-sitter-cli requires its top-level install script to download the
    platform-specific executable, so only the npm package metadata was present.

  2. On Windows, even when tree-sitter.exe was present, the runtime resolver
    checked only the extensionless tree-sitter name and discarded it, falling
    through to a bare-PATH lookup that usually fails.

  3. Tree-sitter attempted to write compiled grammar artifacts under the user's
    cache directory, which managed environments may expose as read-only.

The parser caught Tree-sitter errors and returned an empty result, which hid
all three failures.

Changes

  • Run only the required top-level tree-sitter-cli install script after the
    script-suppressed dependency installation.
  • Validate the installed runtime with a bounded tree-sitter --version
    execution instead of checking only whether a file exists.
  • Reject missing, non-executable, corrupt, or non-responsive binaries.
  • Resolve tree-sitter.exe before the extensionless binary on Windows so a
    downloaded Windows executable is actually used.
  • Install the Codex plugin directly with codex plugin add after registering
    the local marketplace, removing the predictable Git-only marketplace upgrade failure from local Codex installations.
  • Write the Codex .install-version marker into the plugin cache only after
    runtime provisioning succeeds, so it is a truthful "runtime ready" signal
    rather than one seeded optimistically before installation.
  • Set XDG_CACHE_HOME to a writable process-local directory for Tree-sitter
    queries.
  • Add regression coverage for:
    • missing Tree-sitter executables
    • non-executable files
    • corrupt executables with invalid version output
    • Windows .exe resolution and bare-PATH fallback
    • local Codex marketplace installation and post-provision marker write
    • installation failure without runtime provisioning
    • parsing with an unwritable user cache
  • Regenerate the MCP server bundle.
  • Document npx claude-mem install --ide codex-cli in the README.

Scope and intentional behavior change

The runtime-provisioning and validation logic added here lives in the shared
installPluginDependencies / verifyCriticalModules path—not a Codex-only
branch. It runs for the standard npx claude-mem install flow and for repair
across supported IDEs, including Claude Code.

That is deliberate: the same silent-failure mode existed on every shared
installation path, so the fix and its validation apply everywhere.

  • Before: installation completed when tree-sitter-cli lacked a working
    executable. Core memory remained functional, but smart-explore silently
    returned empty or unparseable results.
  • After: a missing, non-executable, corrupt, non-responsive, or incorrectly
    installed Tree-sitter executable fails installation or repair.

smart-explore is the only feature that requires Tree-sitter; capture,
injection, recall, and the worker do not. This therefore converts some partial
successes into hard failures. That is intentional: a loud, correct failure is
preferable to reporting success with a broken installed feature, and uniform
behavior across IDEs is easier to support.

Newly blocked environments are platform-availability cases:

  • musl/Alpine, where the downloaded Linux prebuilt requires glibc and cannot
    execute;
  • platforms or architectures outside tree-sitter-cli's prebuilt matrix.

Deferred follow-up, not included here: if unsupported environments become a
significant support burden, Claude Code could warn and continue without
smart-explore while Codex remains strict. The paths are separable, so that can
remain an isolated policy change.

Also out of scope: parser.ts still degrades a runtime Tree-sitter query
failure to an empty result (#2910's third point). This PR fixes install-time
provisioning and validation so the binary is present and valid; surfacing a
runtime query failure in the tool result instead of returning empty is a
separate change.

Relationship to existing work

This change shares a root cause with an actively tracked cluster and supersedes
parts of two open PRs — flagged so it isn't reviewed in isolation.

Verification

  • Affected and installer-related tests pass (codex-cli-installer,
    install-non-tty, setup-runtime, parser, verify-critical-modules).
  • Full TypeScript typecheck passes.
  • Full build and bundle regeneration pass; the regenerated mcp-server.cjs
    contains the parser fix (Windows .exe resolution and process-local cache).
  • Fresh isolated Claude Code installation completed successfully through the
    shared installPluginDependencies path and provisioned a working
    tree-sitter 0.26.9 executable.
  • Verified end-to-end on a fresh local install + new Codex session: the
    installer wrote .install-version only to the Codex plugin cache (the
    marketplace root stayed marker-free), and the session did not emit
    "runtime not yet set up". Repeated with the Claude-cache marker temporarily
    removed to rule out the fallback path — the warning stayed absent, confirming
    Codex supplies the installed plugin root to the hook environment.
  • Injectable Windows resolver tests (tree-sitter-bin.test.ts) cover
    tree-sitter.exe preference, bare-PATH fallback, and non-Windows resolution.
  • isInstallCurrent regression test covers a same-version cache with a marker
    but an unusable tree-sitter-cli binary (the stale-cache repair path).
  • The existing marketplace peer-dependency fallback was exercised and completed
    successfully.
  • prepublishOnly runs the full build before publishing; the npm CLI is
    rebuilt from src/npx-cli/index.ts into dist/npx-cli/index.js. dist is
    included in the published package but intentionally gitignored, so no
    additional committed installer artifact is required.
  • A fresh MCP process successfully completed smart_search (symbols found),
    smart_outline (structure returned), and smart_unfold (implementation
    returned).
  • Worker restarted successfully and reports version 13.9.1.

Test-suite note

A full npm test run was attempted locally. Unrelated listener-based tests
cannot bind port 0 inside the managed workspace sandbox and time out during
setup. All tests covering the changed installation, parser, and platform paths
pass; CI should run the unrestricted full suite.

User impact

Codex users no longer receive a successful claude-mem installation with
silently broken smart-explore tools. Installation provisions and validates the
required runtime and fails clearly if it cannot.

Claude Code and other IDE users receive the same strict validation through the
shared install and repair paths. Environments without a working
tree-sitter-cli binary—musl/Alpine and architectures outside the prebuilt
matrix—now fail loudly instead of completing with smart-explore silently
broken.

This behavior is intentional; see "Scope and intentional behavior change."

@greptile-apps

greptile-apps Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR makes smart-explore runtime setup explicit and validated. The main changes are:

  • Provisions tree-sitter-cli after dependency install with scripts disabled.
  • Validates the Tree-sitter executable with a bounded --version check.
  • Fixes Windows resolution for package-local tree-sitter.exe.
  • Runs Tree-sitter queries with a process-local writable cache directory.
  • Installs the Codex plugin cache with codex plugin add and writes .install-version after runtime provisioning succeeds.
  • Adds tests for installer, Codex, parser, and binary-resolution paths.

Confidence Score: 4/5

The changes appear merge-safe, with focused installer and parser updates backed by targeted regression coverage.

The touched paths have tests covering provisioning, validation, Windows binary resolution, Codex installation, and writable cache behavior.

T-Rex T-Rex Logs

What T-Rex did

  • T-Rex performed a base verifyCriticalModules check and confirmed PASS for the missing executable, non-executable (EACCES), and corrupt stdout scenarios, and verified that the tree-sitter CLI binary was not exported.
  • T-Rex validated post-install behavior by triggering a head check that failed with Post-install check failed: unresolvable modules: tree-sitter-cli executable, then provisioned a working binary returning tree-sitter 0.99.1.
  • T-Rex produced a proof for a posted P1 finding, and the review comment contains the validation details.
  • T-Rex extended tests to include Windows resolver tests, but parser.test.ts failed because parseFile() returned [] under unwritable XDG_CACHE_HOME, despite Windows resolver tests passing.
  • T-Rex captured codex install marker progression, showing before state with base run and missing cache markers, and after state with version 88.0.0, explicit marker checks, and a README instruction.

View all artifacts

T-Rex Ran code and verified through T-Rex

Comments Outside Diff (1)

  1. General comment

    P1 Head parser still returns no TypeScript symbols under the unwritable-cache runtime scenario

    • Bug
      • The new targeted test smart file parser > extracts TypeScript symbols when the user cache is not writable fails on head: parsed.symbols.map(...) is [] instead of ["smartExploreProbe", "ProbeClass"]. This means the claimed end-to-end behavior that smart-file-read can parse supported TypeScript files after installation was not demonstrated in the actual runtime path.
    • Cause
      • The runtime query path in src/services/smart-file-read/parser.ts still degrades any tree-sitter query execution failure to an empty match map. In this environment the installed tree-sitter-cli binary cannot execute (GLIBC_2.39 requirement), so even with the new process-local XDG_CACHE_HOME, parseFile() silently returns a symbol-less folded view. This violates the requested contract that parsing succeeds under the bad user-cache setup.
    • Fix
      • Ensure the installed/provisioned tree-sitter runtime is executable on the supported target environments, or use a compatible bundled CLI/native path. Keep the process-local cache override, but add install/runtime validation that catches an unusable tree-sitter-cli binary before smart_search/smart_outline/smart_unfold degrade to empty symbol output.

    T-Rex Ran code and verified through T-Rex

Reviews (6): Last reviewed commit: "fix(install): repair stale-cache bypass ..." | Re-trigger Greptile

@greptile-apps

greptile-apps Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

T-Rex pricing update — T-Rex was free through June 2026. Effective July 1, 2026, T-Rex adds 2 credits on top of the standard 1-credit review (3 total). T-Rex settings

rymalia added a commit to rymalia/claude-mem that referenced this pull request Jul 1, 2026
Address review feedback on thedotmack#3095:

- isInstallCurrent treated a cache as current from node_modules + marker +
  version + Bun state alone, so a same-version cache with .install-version but
  a missing or broken tree-sitter-cli executable skipped
  installPluginDependencies and left smart-explore broken. Fail the fast path
  when the plugin declares tree-sitter-cli but its binary is unusable, forcing
  re-provisioning. (Reported by greptile.)

- Make getTreeSitterBin injectable and port thedotmack#2918's Windows resolver tests so
  the tree-sitter.exe / bare-PATH / non-Windows branches are actually covered.

Regenerate the MCP server bundle.
@rymalia

rymalia commented Jul 1, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the re-review. Both findings concern the explicitly documented, out-of-scope runtime silent-empty behavior rather than the changed installer paths.

On head 672f8199, the project's ubuntu-latest CI successfully ran the full bun test suite, including the unwritable-cache parser test. T-Rex's parse failure is caused by its Tree-sitter executable requiring unavailable GLIBC_2.39.

In the supported install flow, that executable fails the bounded tree-sitter --version validation and installation aborts. The T-Rex MCP harness bypassed installation and launched the server directly from the checkout, so it does not invalidate the installer guarantee.

We are intentionally retaining the parser assertion without a skip guard: silently passing when Tree-sitter cannot execute would conceal resolver and runtime regressions. Surfacing runtime query failures from MCP tools remains the separately documented follow-up from #2910 point 3.

@Retengart

Copy link
Copy Markdown

I prepared a clean sync branch for this PR since the current head is conflicting with main and I do not have UpdatePullRequest permission on this PR body.

Branch: https://github.com/Retengart/claude-mem/tree/pr3095-main-sync
Commit: f003fcb0 (Merge main into smart-explore runtime provisioning)

What it does:

Verification on the prepared branch:

  • npm run build
  • npm run typecheck:root
  • bun test tests/install-non-tty.test.ts tests/integration/codex-cli-installer.test.ts tests/setup-runtime.test.ts tests/services/smart-file-read/parser.test.ts tests/services/smart-file-read/tree-sitter-bin.test.ts tests/cli/verify-critical-modules.test.ts tests/gemini_provider.test.ts --timeout 15000

One important PR-body fix is still needed before merge: GitHub currently treats #2964 as a closing reference because the body contains the phrase should not close #2964 wholesale. Suggested replacement:

**tree-sitter slice**; refs #2964 but does not resolve the full tracker.

That keeps #2964 open as the broader tracker while this PR covers only the tree-sitter slice.

rymalia added a commit to rymalia/claude-mem that referenced this pull request Jul 1, 2026
Address review feedback on thedotmack#3095:

- isInstallCurrent treated a cache as current from node_modules + marker +
  version + Bun state alone, so a same-version cache with .install-version but
  a missing or broken tree-sitter-cli executable skipped
  installPluginDependencies and left smart-explore broken. Fail the fast path
  when the plugin declares tree-sitter-cli but its binary is unusable, forcing
  re-provisioning. (Reported by greptile.)

- Make getTreeSitterBin injectable and port thedotmack#2918's Windows resolver tests so
  the tree-sitter.exe / bare-PATH / non-Windows branches are actually covered.

Regenerate the MCP server bundle.
@rymalia rymalia force-pushed the fix/smart-explore-runtime-provisioning branch from 672f819 to a20bd2a Compare July 1, 2026 21:52
Comment on lines +549 to +550
enableCodexPluginConfig();
runCodexBestEffort(
['plugin', 'marketplace', 'upgrade', MARKETPLACE_NAME],
'Refreshed Codex marketplace and installed plugin cache.',
'Could not refresh Codex marketplace cache; reinstall or upgrade claude-mem from /plugins if Codex still uses old MCP config',
);
await installCodexPluginCache(marketplaceRoot);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 Enable after provisioning
enableCodexPluginConfig() writes ~/.codex/config.toml before installCodexPluginCache() has installed the plugin cache and validated tree-sitter-cli. If plugin add or runtime provisioning fails, the installer returns failure but leaves claude-mem@claude-mem-local enabled in Codex config, so new Codex sessions can try to load a plugin cache that is missing or not runtime-ready. Move config enablement until after the cache install/provision step succeeds, or roll it back on failure.

Artifacts

Repro: focused Bun test that drives installCodexCli with isolated HOME and failing fake codex plugin add

  • Contains supporting evidence from the run (text/typescript; charset=utf-8).

Repro: test output showing installer failure and enabled claude-mem@claude-mem-local in isolated config.toml

  • Keeps the command output available without making the summary code-heavy.

View artifacts

T-Rex Ran code and verified through T-Rex

@rymalia

rymalia commented Jul 1, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @Retengart — resolved the conflict on our side (rebased onto main 13.9.2, regenerated mcp-server.cjs from source rather than hand-editing, same approach as your sync branch) and applied your #2964 body fix. PR is green/mergeable again. And thanks for the catch on the closing keyword - whoops.

rymalia added a commit to rymalia/claude-mem that referenced this pull request Jul 1, 2026
Address review feedback on thedotmack#3095:

- isInstallCurrent treated a cache as current from node_modules + marker +
  version + Bun state alone, so a same-version cache with .install-version but
  a missing or broken tree-sitter-cli executable skipped
  installPluginDependencies and left smart-explore broken. Fail the fast path
  when the plugin declares tree-sitter-cli but its binary is unusable, forcing
  re-provisioning. (Reported by greptile.)

- Make getTreeSitterBin injectable and port thedotmack#2918's Windows resolver tests so
  the tree-sitter.exe / bare-PATH / non-Windows branches are actually covered.

Regenerate the MCP server bundle.

Co-authored-by: Alex V. <119082209+Retengart@users.noreply.github.com>
@rymalia rymalia force-pushed the fix/smart-explore-runtime-provisioning branch from a20bd2a to edae7a1 Compare July 1, 2026 23:29
rymalia added a commit to rymalia/claude-mem that referenced this pull request Jul 3, 2026
Address review feedback on thedotmack#3095:

- isInstallCurrent treated a cache as current from node_modules + marker +
  version + Bun state alone, so a same-version cache with .install-version but
  a missing or broken tree-sitter-cli executable skipped
  installPluginDependencies and left smart-explore broken. Fail the fast path
  when the plugin declares tree-sitter-cli but its binary is unusable, forcing
  re-provisioning. (Reported by greptile.)

- Make getTreeSitterBin injectable and port thedotmack#2918's Windows resolver tests so
  the tree-sitter.exe / bare-PATH / non-Windows branches are actually covered.

Regenerate the MCP server bundle.

Co-authored-by: Alex V. <119082209+Retengart@users.noreply.github.com>
@rymalia rymalia force-pushed the fix/smart-explore-runtime-provisioning branch from edae7a1 to 40bcc50 Compare July 3, 2026 03:33
rymalia and others added 2 commits July 4, 2026 17:17
Plugin installation suppressed dependency lifecycle scripts, leaving
tree-sitter-cli installed without its platform executable. The installer still
reported success, but smart_search returned zero symbols and smart_outline
could not parse supported files. On Windows the runtime resolver also ignored
the downloaded tree-sitter.exe because it checked only the extensionless name.

Tree-sitter queries additionally attempted to write compiled grammar data under
the user cache, which may be read-only in managed environments. Those failures
were suppressed as empty search results.

This logic lives in the shared install/repair path, not a Codex-only branch, so
the fix and its validation apply to every IDE.

Fix runtime provisioning by:

- running only tree-sitter-cli's required install script after the
  script-suppressed dependency install
- validating the binary through a timed `tree-sitter --version` probe
- resolving tree-sitter.exe before the extensionless name on Windows
- installing the Codex plugin directly from the registered local marketplace
- writing the Codex .install-version marker only after runtime provisioning
  succeeds, so it is a truthful "runtime ready" signal
- using a writable process-local cache for compiled Tree-sitter grammars
- failing installation when the runtime cannot be installed or validated
- adding installer, parser, and corrupt-binary regression coverage
- documenting the explicit Codex CLI installation command

Regenerate the MCP server bundle with the parser fix.
Address review feedback on thedotmack#3095:

- isInstallCurrent treated a cache as current from node_modules + marker +
  version + Bun state alone, so a same-version cache with .install-version but
  a missing or broken tree-sitter-cli executable skipped
  installPluginDependencies and left smart-explore broken. Fail the fast path
  when the plugin declares tree-sitter-cli but its binary is unusable, forcing
  re-provisioning. (Reported by greptile.)

- Make getTreeSitterBin injectable and port thedotmack#2918's Windows resolver tests so
  the tree-sitter.exe / bare-PATH / non-Windows branches are actually covered.

Regenerate the MCP server bundle.

Co-authored-by: Alex V. <119082209+Retengart@users.noreply.github.com>
@rymalia rymalia force-pushed the fix/smart-explore-runtime-provisioning branch from 40bcc50 to 65b90cb Compare July 5, 2026 00:27
thedotmack added a commit that referenced this pull request Jul 5, 2026
Community bleeding-edge batch 2.\n\nPR: #3095\nAuthor: rymalia\n\nSafety review: installer validates and provisions tree-sitter-cli with bounded execFile and Windows hidden spawn; no credential exfiltration or background telemetry added. Requires install/runtime, spawn-env, and smart-file-read tests.

# Conflicts:
#	plugin/scripts/mcp-server.cjs
thedotmack added a commit that referenced this pull request Jul 5, 2026
Community bleeding-edge batch 2 generated artifacts and integration fix.\n\nIncludes regenerated plugin bundles after merging #3112, #3108, #3099, #3095, #3061, #3055, #3006, #2998, #2945, #2944, #2890, #2889, #2887, #2830, and #2775.\n\nAdds plugin/sqlite to package.json files so the runtime modules from #3108 ship.\n\nHeld from batch 2 by safety review: #2710, #2531.\n\nVerification passed before commit:\n- npm install --no-audit --no-fund\n- npm run typecheck\n- npm run build\n- bun test\n- npm run lint:hook-io\n- npm run lint:spawn-env\n- npm run check:postinstall-allowlist\n- npm run test:agents\n- npm run test:infra\n- npm run test:sqlite\n- bun install --frozen-lockfile --ignore-scripts (plugin/)\n- focused Batch 2 regression bun test set\n- npm run smoke:clean-room\n- npm run e2e:server:docker
@thedotmack

Copy link
Copy Markdown
Owner

Merged into the community-edge branch — claude-mem's bleeding-edge release line. Closing here since your change now lives on that branch. See the branch model (community-edge → core-dev → main): https://docs.claude-mem.ai/branches . Thanks for the contribution! 🙏

@thedotmack thedotmack closed this Jul 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants