发布

  • fix(grep): enforce_time_budget option for zero-match searches (#826) (#827)

    frostbyte_neo 发布于 2026-09-08 18:53:07 +00:00

    • fix: enforce grep time budget on zero-match searches (#826)

    The plain/regex deadline check was gated on all_matches.len() > 1, so a
    search that matched nothing never aborted and scanned every candidate file.
    Removing the gate alone is not enough: both accounting paths overwrote
    files_consumed with the full slice length whenever no file matched, which
    zeroed out next_file_offset and lost the resume cursor.

    Workers now latch the abort in their map_init state and record the lowest
    index they skipped, so the resume cursor is the exact first unsearched file.
    Matches past that index are dropped and re-found on the next page, keeping
    paging free of both gaps and duplicates.

    Closes #826

    • fix(grep): gate zero-match time budget behind enforce_time_budget (#826)

    Per review: enforcing the budget on zero-match searches unconditionally
    changes behaviour for existing callers, who relied on a full scan when
    nothing matched. Make it opt-in instead.

    • GrepSearchOptions.enforce_time_budget, default false. Off keeps the
      historical plain/regex rule (budget dormant until matches exist).
    • Exposed as enforceTimeBudget (node/bun), enforce_time_budget
      (lua config + python kwarg), and new fff_live_grep_ex /
      fff_multi_grep_ex C symbols. The existing C symbols keep their exact
      signature and forward with false.
    • Fuzzy grep already enforced the budget unconditionally; unchanged.
    • Cursor accounting fix stays unconditional: an aborted page now reports
      how far it actually got instead of claiming the whole slice.
    • Never skip file 0, so an abort cannot emit next_file_offset == 0,
      which callers read as "done".
    • test(grep): move zero-match budget helpers to end of file

    Repo style: private helpers live at the bottom, plain comments not doc
    comments.

    • fix(python): declare enforce_time_budget in grep type stubs

    • refactor(grep): drop redundant budget_exceeded flag and tighten comments


    Co-authored-by: gustav-fff 286169375+gustav-fff@users.noreply.github.com
    Co-authored-by: Dmitriy Kovalenko dmtr.kovalenko@outlook.com

    下载附件