Skip to content

Harden shared search parity and runtime lease lifecycle - #176

Merged
Shengyu Fu (shengyfu) merged 4 commits into
mainfrom
shengyfu-shared-parity-and-lifecycle
Oct 6, 2026
Merged

Shengyu Fu (shengyfu) merged 4 commits into
mainfrom
shengyfu-shared-parity-and-lifecycle

Conversation

@shengyfu

Copy link
Copy Markdown
Member

Summary

  • Extend the existing shared-daemon fixture with bounded, seeded three-worktree sequences: independent edits, staged/unstaged/untracked changes, deletion/rename, committed divergence, ignores, restoration to the pin, reset/checkout/rebase, sparse/CRLF materialization, and daemon restart. Compare against --no-index and a simple independent membership/line model at acknowledged refresh barriers; require RPC backend identity and CLI shared-use counters so fallback cannot make parity pass.
  • Cover Unicode -F -i through base/overlay/ignore/restart states, hidden/filename-only membership, legitimate no-results, line/count/match/file output, and JSON semantics including offsets, submatches and totals. Native-watch coverage additionally requires event-driven publication before explicit refresh.
  • Add a reusable test-only process/lease supervisor with persisted caller-owned journals, simultaneous/repeated/lost-response attaches at limits, crash/timeout abandonment, explicit journal recovery, daemon restart with fresh tokens, budget release, and detach-before-move/remove while sibling queries continue. Bounded waits and owned-PID kill/reap guards; no expiry/GC or public SDK.
  • Fix a defect found by the new parity checks: both shared and ordinary JSON server replies omitted later match/context byte offsets. Request positional metadata whenever JSON output is selected. A focused scan/local/ordinary-server regression independently asserts UTF-8 offsets and spans.

Backwards-compatible opt-in two-layer design is unchanged. No cache/GC/migration redesign, Copilot integration changes, README changes or workflow changes. Based on verified main e9d55dbbf232f0e228695f15a640cf207d4b3348 (including #174).

Validation

Windows and native-ext4 WSL Linux, no DrvFS watcher tests:

Suite Windows Linux
tgrep-cli --bin tgrep 271 passed, 1 existing ignored; 4.73s 293 passed, 1 existing ignored; 1.84s
tgrep-cli --test ripgrep_compat 236 passed; 61.91s 236 passed; 4.92s
tgrep-cli --test shared_daemon 27 passed, 1 subprocess entry ignored; 138.15s 32 passed, 1 subprocess entry ignored; 18.63s
tgrep-core --test shared_worktrees 30 passed; 0.96s 29 passed; 0.10s
tgrep-core --lib worktrees::tests 25 passed; 9.80s 32 passed; 1.08s

cargo fmt --all -- --check and cargo clippy --workspace --all-targets -- -D warnings pass on both. Alternate Linux seed 7, two rounds per watch mode plus runtime exerciser: 3 passed, 1 subprocess entry ignored, 18.89s. Platform counts differ because existing tests are platform-gated.

Selectors and replay

cargo test -p tgrep-cli --test shared_daemon -- stateful:: runtime::
cargo test -p tgrep-cli --test ripgrep_compat indexed_json_preserves_utf8_match_and_context_offsets
TGREP_SHARED_SEED=7 TGREP_SHARED_ROUNDS=2 cargo test -p tgrep-cli --test shared_daemon stateful::

Default seed is 1742026, rounds 1; accepted rounds 1..16. Failures print seed/rounds/ordered operation log. The ignored runtime::runtime_client_process is invoked by the supervisor, not a standalone test. Readiness is not latest-disk proof; abandoned leases require runtime cleanup. No automatic expiry, storage GC, or claim of exhaustive fuzz coverage.

The independently verified production fix is isolated in 2b2d497cc945c33ba4674b71c04f2ffd65221aff so benchmark qualification can pin the optimized candidate without depending on test additions.

Shengyu Fu (shengyfu) and others added 2 commits October 5, 2026 22:54
Request per-row position detail for JSON output on both ordinary and shared server paths. Cover UTF-8 match/context byte offsets and submatches against scans and local indexes.

Co-authored-by: Copilot App <[email protected]>
Compose seeded three-worktree transitions against scan and independent membership/line oracles, require actual shared backend use, and combine real process recovery with persisted caller leases. Document bounded replay and runtime-owned cleanup contracts.

Co-authored-by: Copilot App <[email protected]>
Copilot AI balanced review requested due to automatic review settings October 6, 2026 06:01

Copilot AI left a comment

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.

Copilot review overview

🟡 Changes recommended

The runtime concurrency test does not guarantee queries overlap the worktree move/remove operations.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
What changed in this PR

Adds shared-daemon parity and lease-lifecycle coverage while fixing missing JSON offsets in server-backed searches.

Changes:

  • Request positional metadata for JSON server searches.
  • Add seeded worktree parity and runtime lease supervision tests.
  • Document the new exercisers and replay controls.
File Description
tgrep-cli/​src/​search.rs Requests offsets for JSON replies.
tgrep-cli/​tests/​ripgrep_compat.rs Tests UTF-8 JSON offsets across backends.
tgrep-cli/​tests/​shared_daemon.rs Integrates bounded process helpers and test modules.
tgrep-cli/​tests/​shared_daemon/​stateful.rs Adds seeded shared-search parity sequences.
tgrep-cli/​tests/​shared_daemon/​runtime.rs Exercises lease and process lifecycles.
SHARED_WORKTREE_INDEXES.md Documents the new test exercisers.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread tgrep-cli/tests/shared_daemon/runtime.rs Outdated
Keep queries active until lifecycle teardown completes and require phase-tagged successful replies before and after each operation, with deadline and disconnect cancellation.

Co-authored-by: Copilot App <[email protected]>
Copilot AI balanced review requested due to automatic review settings October 6, 2026 06:06

Copilot AI left a comment

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.

Copilot review overview

🔵 Needs a closer look

The subprocess cancellation path has a race that can panic when the child exits immediately before it is killed.

Review effort: Balanced
Findings: None

Resolved since last review (1)
Previously missed (1)

In code that hasn't changed since last review

Medium severity Avoid panic when child exits between try_wait and kill

tgrep-cli/​tests/​shared_daemon/​runtime.rs:36

There is a TOCTOU race between try_wait and kill: the child can exit after try_wait returns None, causing kill().unwrap() to panic even though cancellation is complete. This can replace the intended timeout diagnostics with an unrelated panic. Recheck the child status when kill fails, and only fail if it is still running.

Recheck exit status if killing a previously-running child fails, preserving timeout diagnostics when the child won the race. Exercise repeat cancellation after reaping.

Co-authored-by: Copilot App <[email protected]>
Copilot AI balanced review requested due to automatic review settings October 6, 2026 06:13
@shengyfu

Copy link
Copy Markdown
Member Author

Addressed the final-head review summary cancellation concern in 275e0af: if kill fails after try_wait observed a running child, recheck exit status and only fail if it remains running. Repeat cancellation after reaping is exercised too. Targeted runtime tests pass on Windows (10.62s) and native-ext4 Linux (1.84s); fmt/clippy pass. Prior head 390413f passed every automatic check, including all three OS test jobs; the follow-up gets normal automatic CI (no manual rerun executed).

Copilot AI left a comment

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.

Copilot review overview

🟢 Approval recommended

The production fix is focused and supported by comprehensive backend parity and lifecycle coverage.

Review effort: Balanced
Findings: None

@shengyfu
Shengyu Fu (shengyfu) merged commit df6a681 into main Oct 6, 2026
12 checks passed
@shengyfu
Shengyu Fu (shengyfu) deleted the shengyfu-shared-parity-and-lifecycle branch October 6, 2026 15:48
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.

2 participants