Skip to content

fix(watch): sync the checkouts agents work in on a machine set up for hosted MCP - #167

Merged
escott- merged 1 commit into
mainfrom
fix/bridge-links-checkouts-agents-use
Oct 12, 2026
Merged

escott- merged 1 commit into
mainfrom
fix/bridge-links-checkouts-agents-use

Conversation

@escott-

@escott- escott- commented Oct 12, 2026 •

Copy link
Copy Markdown
Member

Problem

On a machine set up for hosted MCP, the sync bridge never watched a checkout the machine had not linked before. It watches only folders in ~/.contextstream/mappings.json that also carry a verified .contextstream/config.json, and nothing in hosted mode creates those for a new folder:

  • hosted init cannot write local files,
  • the background link audit (link.rs) only re-checked folders already in mappings.json,
  • connect needs a token minted in the dashboard.

Seen on 2026-10-12 after a fresh install on Oct 6: the bridge heartbeat showed target_count: 0 for six days, so nothing on the machine was uploaded. Claude Code on the contextstream repo reported "The ContextStream index is 131 hours stale and from another branch, and it has no exact hit for the gate's wording" and fell back to grep. SessionStart said "Project index not found yet" for every repository, because it reads indexed-projects.json, which hosted mode never writes. contextstream-mcp link on the folder showed not linked, with a strong match (same Git repository).

Change

  • Discovery (link.rs): known_folders() also includes the Git checkouts agent sessions worked in, from session-scopes.json. The automatic repair rules are unchanged: link only when the Git repository names the project, never into an isolated workspace, never a pinned folder. Temporary paths and agents' task worktrees (.claude/worktrees/) are skipped.
  • Prompt audit (watch.rs, post_tool_use.rs): when an init/context result lands for a checkout with no verified link to the resolved project, the hook writes a one-shot watch.link-audit marker. The bridge takes it on its flush tick and runs the audit then, not at the next six-hourly tick. It skips while an audit is running and keeps a 10-minute cooldown, because a folder no project matches asks on every turn. Like the reload marker, it holds no path or scope.
  • First sync covers the checkout (link.rs): relink() marks the root for one durable full scan. Before this, a newly watched target uploaded only paths edited after linking, so the server kept other machines' copies of everything else.
  • SessionStart (session_start.rs): when the legacy registry knows nothing, it reports whether this checkout is synced, not linked (with contextstream-mcp link --fix, or --project-id when nothing matches), or linked with no bridge running (with the doctor repair command).

Behaviour change to review

The bridge will now link a Git checkout an agent works in when its repository matches a project with strong evidence, and upload it, without anyone running link or connect. Before, the automatic audit applied the same rule only to folders that had been linked before. Ambiguous matches are still left alone; in the live check, coflow and contextcode stayed unlinked because several projects fit.

Verification

  • cargo clippy -p mcp-server --all-targets -- -D warnings: clean.
  • cargo test -p mcp-server: all suites pass (1075 lib tests plus the integration suites), including the new tests:
    • link::tests::{registry_folders_come_from_mappings_and_the_local_index, session_folders_are_where_agent_sessions_worked, agent_task_worktrees_are_recognised}
    • watch::tests::link_audit_request_needs_a_running_bridge_and_waits_out_a_running_audit_or_cooldown
    • hook_handlers::post_tool_use::tests::a_git_checkout_without_a_verified_link_asks_the_bridge_for_an_audit
    • hook_handlers::session_start::tests::an_unlinked_git_checkout_is_reported_as_not_synced
  • Live, read-only link --all on the affected machine: 1.0.17 checks only contextmail and contextstream; this build also finds coflow, contextcode and contextmail-mobile from agent sessions.
  • Remediation on that machine with the released 1.0.17 (link --fix, bridge reload, hosted refresh): the bridge went to target_count: 1, and the index moved to this machine and branch (11,926 → 12,089 files).

Release

Owner decision cc199133 holds mcp-server releases until the Agent Coach Kit work is done; this PR does not change that.

🤖 Generated with Claude Code


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need.

… hosted MCP

A machine set up for hosted MCP never linked a checkout it had not linked
before. The sync bridge watches only folders listed in mappings.json with a
verified .contextstream/config.json. Hosted init cannot write local files,
the background link audit only re-checked folders already in mappings.json,
and connect needs a dashboard token. On a fresh install the bridge ran with
target_count 0 for six days, nothing on the machine was uploaded, and agents
got search results from other machines' copies (another branch, 131 hours
old) and fell back to grep.

- The link audit also checks the Git checkouts agent sessions worked in
  (session-scopes.json). It still links only on strong evidence: the Git
  repository names the project, not an isolated workspace, not pinned, not
  a temporary path or an agent's task worktree.
- A hook that sees an agent working in an unlinked checkout asks the bridge
  for that audit at once (watch.link-audit marker, 10-minute cooldown)
  instead of waiting up to six hours.
- A folder linked by link or the audit gets one covering full scan, so the
  server receives its branch and edits, not only edits made afterwards.
- SessionStart says whether the checkout is synced, not linked (with the
  link --fix command) or linked with no bridge running, instead of "Project
  index not found yet" for every repository on hosted MCP.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Code review skipped — your organization has no extra usage available to pay for this review.

If your organization's extra usage balance is empty, an organization admin can add extra usage credits at claude.ai/admin-settings/usage. If its monthly spend limit was reached, an admin can raise it on the same page. If neither applies, contact Anthropic support.

Once extra usage is available, someone with write access to this repository can comment @claude review on this pull request to trigger a review.

@escott-
escott- merged commit 05ab56c into main Oct 12, 2026
0 of 9 checks passed
@escott-
escott- deleted the fix/bridge-links-checkouts-agents-use branch October 12, 2026 21:38
escott- added a commit that referenced this pull request Oct 12, 2026
Bumps the workspace, npm package, MCP Registry metadata and the boundary
self-test to 1.0.21. Adds the 1.0.21 changelog: the hosted gateway no
longer reads or writes its own disk for a caller's path (339f5d5) and
never replaces its own binary (ddcae54); per-request tool surfaces on the
gateway (5c42d4b); hosted search rooted at the session's checkout (#168);
the hooks lose the hidden attribution block (4879e0b); the sync bridge
links the checkouts agents work in (#167); entity visibility, filing and
reply fixes (901a2fc); whole-word skill matching (6bbf26b); stdio resume
and closed-pipe fixes (#166); the setup review-card gap (074c45f); opt-in
coaching turns (053d961; its API route eb4430485 is in the live backend);
and quinn-proto 0.11.19 in Cargo.lock (87d6488). No open PRs were left out.

Checked on ovh-desktop against main 87d6488 plus this change:
- cargo fmt --all --check
- cargo clippy --locked --workspace --all-targets -- -D warnings
- cargo test --locked --workspace --all-targets: 3223 passed, 0 failed,
  21 ignored
- account_connection_smoke: 9 tests
- cargo audit --deny warnings (403 crates, no advisories) and cargo deny
  --locked check (duplicate warnings only)
- on a clean archive: release_contract metadata and resolve-version for
  tag v1.0.21, public_boundary, the four script tests, the adoption and
  grounding tests, npm test (6 passed)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: escott- <escott05@gmail.com>
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.

1 participant