Text chat 17: core search (#267) #349

Manually merged
charles merged 0 commits from textchat-17-core-search into textchat 2026-11-13 00:30:20 +00:00
Owner

What this builds

fluxer-core::chat::search (spec §6.2 "Search", §3.7):

  • parse(&str, UtcOffset) -> SearchQuery: the original's query language (SearchQueryParser.ts:46-79, SearchUtils.ts): from:/-from:, mentions: (incl. everyone), in:/-in:, has: (forward -> snapshot), before:/after:/on:/during: and a..b ranges, last:, beforeid:/afterid:, pinned:, author-type:, link:, filename:, ext:, sort:, order:, scope:, any:, mature:, embed filters, quoted values and "exact phrases"; unknown keys stay text. Dates become snowflake bounds in the given offset.
  • SearchQuery::to_request(&App, page) -> SearchRequest: names resolved against the store, 25 per page, scope from menu/query limited to the channel's scope options, context_channel_id/context_guild_id, the sort menu wins over sort: (as applySortModeToParams).
  • Reducer: Edit/Submit/Page/Sort/Scope/Close; {indexing:true} polls at 1500 ms x 1.25^n capped at 5000 ms (indexing_poll_interval); stale answers and stale timers dropped; 10 recent searches, newest first, deduplicated.
  • Selectors (re-exported from selectors): search_results(&App) -> SearchResultsModel { total, page, pages, groups, state } (runs of consecutive same-channel results) and search_suggestions(&App, text, cursor) (Filters, Recent, Users, Channels, Dates, Values).

Testing

crates/fluxer-core/tests/chat_search.rs: parse_cases (table, well over 15 cases), request_scope_and_context, page_size_25, indexing_poll_backoff, grouping_runs_by_channel, recent_searches_kept_10, jump_from_result, plus date bounds in local offset, blank query, failure state, suggestion sections and an odd-input no-panic table. Uses the existing fixtures/rest/search_results.json / search_indexing.json. FLUXER_SCREENSHOT_TESTS=1 cargo xtask ci green locally.

Deviations

  • SearchResultsState has a Results variant besides the plan's Idle | Loading | Indexing | Empty | Error.
  • chat_ports.rs::stubs_emit_nothing now skips UserAction::Search (search is no longer a stub).
  • The indexing test was tightened after the failing-test commit (the poll timer is fired before results arrive; an unawaited answer is dropped).
  • Recent searches are not yet loaded from / saved to LocalSettings::chat.recent_searches, and Search::utc_offset is UTC until the runtime sets it: that wiring lives in app.rs/persist.rs/chat/state.rs (outside this task's files) and is tracked in #315. Relative dates (today, last:2d) resolve against the newest message id the store knows (no clock, #109).
  • Review of #349 addressed (commit 2cf6ba9): date conversions are checked (checked_to_offset), so far-year instants in a non-UTC offset no longer panic (cases added to odd_input_never_panics for offsets ±14 h and ±25:59:59 and far-past/far-future nows); an instant typed with a zone now ends its during:/on: day in that zone (DateSpec::Instant { at_ms, offset }, test during_an_instant_ends_with_its_day_in_its_zone); the plan records the extra Results variant for Text chat 30.

Follow-ups

  • #353: search answers carry no effect id, so a superseded answer can be kept as the current results (needs the ApiResult shape changed outside this task).
  • #315: persist recent searches and give the store the local UTC offset.

Closes #267

🤖 Generated with Claude Code

## What this builds `fluxer-core::chat::search` (spec §6.2 "Search", §3.7): - `parse(&str, UtcOffset) -> SearchQuery`: the original's query language (`SearchQueryParser.ts:46-79`, `SearchUtils.ts`): `from:`/`-from:`, `mentions:` (incl. `everyone`), `in:`/`-in:`, `has:` (`forward` -> `snapshot`), `before:`/`after:`/`on:`/`during:` and `a..b` ranges, `last:`, `beforeid:`/`afterid:`, `pinned:`, `author-type:`, `link:`, `filename:`, `ext:`, `sort:`, `order:`, `scope:`, `any:`, `mature:`, embed filters, quoted values and `"exact phrases"`; unknown keys stay text. Dates become snowflake bounds in the given offset. - `SearchQuery::to_request(&App, page) -> SearchRequest`: names resolved against the store, 25 per page, scope from menu/query limited to the channel's scope options, `context_channel_id`/`context_guild_id`, the sort menu wins over `sort:` (as `applySortModeToParams`). - Reducer: Edit/Submit/Page/Sort/Scope/Close; `{indexing:true}` polls at 1500 ms x 1.25^n capped at 5000 ms (`indexing_poll_interval`); stale answers and stale timers dropped; 10 recent searches, newest first, deduplicated. - Selectors (re-exported from `selectors`): `search_results(&App) -> SearchResultsModel { total, page, pages, groups, state }` (runs of consecutive same-channel results) and `search_suggestions(&App, text, cursor)` (Filters, Recent, Users, Channels, Dates, Values). ## Testing `crates/fluxer-core/tests/chat_search.rs`: `parse_cases` (table, well over 15 cases), `request_scope_and_context`, `page_size_25`, `indexing_poll_backoff`, `grouping_runs_by_channel`, `recent_searches_kept_10`, `jump_from_result`, plus date bounds in local offset, blank query, failure state, suggestion sections and an odd-input no-panic table. Uses the existing `fixtures/rest/search_results.json` / `search_indexing.json`. `FLUXER_SCREENSHOT_TESTS=1 cargo xtask ci` green locally. ## Deviations - `SearchResultsState` has a `Results` variant besides the plan's `Idle | Loading | Indexing | Empty | Error`. - `chat_ports.rs::stubs_emit_nothing` now skips `UserAction::Search` (search is no longer a stub). - The indexing test was tightened after the failing-test commit (the poll timer is fired before results arrive; an unawaited answer is dropped). - Recent searches are not yet loaded from / saved to `LocalSettings::chat.recent_searches`, and `Search::utc_offset` is UTC until the runtime sets it: that wiring lives in `app.rs`/`persist.rs`/`chat/state.rs` (outside this task's files) and is tracked in #315. Relative dates (`today`, `last:2d`) resolve against the newest message id the store knows (no clock, #109). - Review of #349 addressed (commit 2cf6ba9): date conversions are checked (`checked_to_offset`), so far-year instants in a non-UTC offset no longer panic (cases added to `odd_input_never_panics` for offsets ±14 h and ±25:59:59 and far-past/far-future nows); an instant typed with a zone now ends its `during:`/`on:` day in that zone (`DateSpec::Instant { at_ms, offset }`, test `during_an_instant_ends_with_its_day_in_its_zone`); the plan records the extra `Results` variant for Text chat 30. ## Follow-ups - #353: search answers carry no effect id, so a superseded answer can be kept as the current results (needs the `ApiResult` shape changed outside this task). - #315: persist recent searches and give the store the local UTC offset. Closes #267 🤖 Generated with [Claude Code](https://claude.com/claude-code)
# Conflicts:
#	crates/fluxer-proto/README.md
#	crates/fluxer-proto/src/gateway/events.rs
#	crates/fluxer-proto/src/models/channel.rs
#	crates/fluxer-proto/src/models/mod.rs
#	crates/fluxer-proto/src/models/settings.rs
#	crates/fluxer-proto/tests/models_roundtrip.rs
# Conflicts:
#	crates/fluxer-proto/tests/models_roundtrip.rs
Refs #267

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

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

Independent review: Text chat 17 (core search), head 8535597

I reviewed only git diff 9fcc13d..origin/textchat-17-core-search (search.rs, selectors/mod.rs, chat_ports.rs, chat_search.rs, README).

What checks out

  • Plan Step 1 tests all exist and assert what the plan asks: parse_cases (36 cases covering from/-from, has:image, has:forward→snapshot, before/after/during/on, in:, pinned:true, sort:relevance, quoted values, unknown key kept as text), request_scope_and_context, page_size_25, indexing_poll_backoff (1500, 1875, 2343, 2929, 3662, 4577, 5000, 5000), grouping_runs_by_channel (runs, not buckets), recent_searches_kept_10, jump_from_result. The indexing test change after the failing-test commit only adds checks (it is stricter).
  • Interfaces: search::parse(&str, UtcOffset) -> SearchQuery, SearchQuery::to_request(&App, page) -> SearchRequest, selectors::search_results / search_suggestions with SearchResultsModel { total, page, pages, groups, state } and ResultGroup { channel_id, messages } (plus channel) all exist and are re-exported from selectors.
  • Constants match the original: RESULTS_PER_PAGE 25, SEARCH_HISTORY_LIMIT 10 / DISPLAY 5, poll 1500 × 1.25 ≤ 5000.
  • Scope logic follows resolveSearchScope (SearchScopeResolution.ts) and getScopeOptionsForChannel exactly: the override, then parsed scope:, then the active scope, each only if offered, falling back to current. The menu's sort always wins (applySortModeToParams). Date bounds follow parseQuery (before→start, after→end, during→start..resolveDuringUpperBound, ranges, later filter wins).
  • Invariants: no new dependency, no I/O, no file data, URLs or secrets. No new fixtures (it uses the existing search_results.json / search_indexing.json).
  • FLUXER_SCREENSHOT_TESTS=1 cargo xtask ci in a clean review worktree: all steps passed.

Findings

  1. [blocking] Typed query panics the reducer once the local offset is not UTC. during_upper_bound (search.rs:1392-1394) calls OffsetDateTime::to_offset, and time 0.3.55 panics there when the result is out of range. parse("on:9999-12-31T23:00Z", offset!(+1)).id_bounds(None) panics at search.rs:1394 (I confirmed it with a scratch test). Search::Submit → build → id_bounds runs inside App::apply, so as soon as the runtime sets Search::utc_offset (#315 / Text chat 21), typing that query crashes the client. odd_input_never_panics uses +14 but has no far-year instant, so it does not catch this. Fix: use checked_to_offset (or convert the date in the offset without to_offset) and add the case to odd_input_never_panics. While you are there, also make the to_offset in DateSpec::resolve and date_words checked.

  2. [minor] A superseded search's answer is shown as the current one. ApiResult::SearchResults carries no effect id or request (Task 10's shape), and answer accepts the first answer after any submit. Example: submit "first", then "second"; if the first answer arrives first, it is kept as the results of "second" and the real answer is dropped (confirmed with a scratch test). Sort, page and scope changes made while a search is in flight hit the same problem. The real fix needs the event to carry the EffectId (or the request), which is outside this task's files. Please open a follow-up/bug before merge.

  3. [minor] Recent searches are not persisted and the offset stays UTC. Already tracked in #315. Link it from the PR body as a follow-up.

  4. [minor] Interface deviation: SearchResultsState has an extra Results variant besides the planned Idle | Loading | Indexing | Empty | Error. It is additive and needed, but please record it in the plan's interface notes for Text chat 30.

  5. [minor] The "now" stand-in (#109). Relative dates resolve against the max channel.last_message_id, which MESSAGE_CREATE keeps current. On a quiet account, today, last:2d and week resolve days in the past. This is documented in the README and #315, so it is acceptable until #109 lands.

  6. [minor] An instant with an explicit zone ends at the end of the day in the local offset. For on:2024-05-01T10:00+09:00, resolveDuringUpperBound in the original takes the end of the day in the parsed zone (Luxon setZone). Here it is taken in the local offset. This is a small divergence.

Verdict: changes requested. There is 1 blocking finding (#1: a one-line checked conversion plus a test case). CI is green locally.

## Independent review: Text chat 17 (core search), head 8535597 I reviewed only `git diff 9fcc13d..origin/textchat-17-core-search` (search.rs, selectors/mod.rs, chat_ports.rs, chat_search.rs, README). **What checks out** - Plan Step 1 tests all exist and assert what the plan asks: `parse_cases` (36 cases covering from/-from, has:image, has:forward→snapshot, before/after/during/on, in:, pinned:true, sort:relevance, quoted values, unknown key kept as text), `request_scope_and_context`, `page_size_25`, `indexing_poll_backoff` (1500, 1875, 2343, 2929, 3662, 4577, 5000, 5000), `grouping_runs_by_channel` (runs, not buckets), `recent_searches_kept_10`, `jump_from_result`. The indexing test change after the failing-test commit only adds checks (it is stricter). - Interfaces: `search::parse(&str, UtcOffset) -> SearchQuery`, `SearchQuery::to_request(&App, page) -> SearchRequest`, `selectors::search_results` / `search_suggestions` with `SearchResultsModel { total, page, pages, groups, state }` and `ResultGroup { channel_id, messages }` (plus `channel`) all exist and are re-exported from `selectors`. - Constants match the original: RESULTS_PER_PAGE 25, SEARCH_HISTORY_LIMIT 10 / DISPLAY 5, poll 1500 × 1.25 ≤ 5000. - Scope logic follows `resolveSearchScope` (`SearchScopeResolution.ts`) and `getScopeOptionsForChannel` exactly: the override, then parsed `scope:`, then the active scope, each only if offered, falling back to `current`. The menu's sort always wins (`applySortModeToParams`). Date bounds follow `parseQuery` (before→start, after→end, during→start..`resolveDuringUpperBound`, ranges, later filter wins). - Invariants: no new dependency, no I/O, no file data, URLs or secrets. No new fixtures (it uses the existing `search_results.json` / `search_indexing.json`). - `FLUXER_SCREENSHOT_TESTS=1 cargo xtask ci` in a clean review worktree: **all steps passed**. **Findings** 1. **[blocking] Typed query panics the reducer once the local offset is not UTC.** `during_upper_bound` (search.rs:1392-1394) calls `OffsetDateTime::to_offset`, and time 0.3.55 panics there when the result is out of range. `parse("on:9999-12-31T23:00Z", offset!(+1)).id_bounds(None)` panics at search.rs:1394 (I confirmed it with a scratch test). `Search::Submit` → `build` → `id_bounds` runs inside `App::apply`, so as soon as the runtime sets `Search::utc_offset` (#315 / Text chat 21), typing that query crashes the client. `odd_input_never_panics` uses +14 but has no far-year instant, so it does not catch this. Fix: use `checked_to_offset` (or convert the date in the offset without `to_offset`) and add the case to `odd_input_never_panics`. While you are there, also make the `to_offset` in `DateSpec::resolve` and `date_words` checked. 2. **[minor] A superseded search's answer is shown as the current one.** `ApiResult::SearchResults` carries no effect id or request (Task 10's shape), and `answer` accepts the first answer after any submit. Example: submit "first", then "second"; if the first answer arrives first, it is kept as the results of "second" and the real answer is dropped (confirmed with a scratch test). Sort, page and scope changes made while a search is in flight hit the same problem. The real fix needs the event to carry the `EffectId` (or the request), which is outside this task's files. Please open a follow-up/bug before merge. 3. **[minor] Recent searches are not persisted and the offset stays UTC.** Already tracked in #315. Link it from the PR body as a follow-up. 4. **[minor] Interface deviation: `SearchResultsState` has an extra `Results` variant** besides the planned `Idle | Loading | Indexing | Empty | Error`. It is additive and needed, but please record it in the plan's interface notes for Text chat 30. 5. **[minor] The "now" stand-in (#109).** Relative dates resolve against the max `channel.last_message_id`, which MESSAGE_CREATE keeps current. On a quiet account, `today`, `last:2d` and `week` resolve days in the past. This is documented in the README and #315, so it is acceptable until #109 lands. 6. **[minor] An instant with an explicit zone ends at the end of the day in the local offset.** For `on:2024-05-01T10:00+09:00`, `resolveDuringUpperBound` in the original takes the end of the day in the parsed zone (Luxon `setZone`). Here it is taken in the local offset. This is a small divergence. **Verdict: changes requested.** There is 1 blocking finding (#1: a one-line checked conversion plus a test case). CI is green locally.
Review of #349: convert instants with checked_to_offset (during:, relative
dates, date suggestions), so a far-year instant in a non-UTC offset no longer
panics the reducer; an instant's during: now ends with its day in the zone it
was typed in (Luxon setZone), via DateSpec::Instant. Plan note for Text chat 30:
SearchResultsState has the extra Results variant.

Refs #267

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts:
#	crates/fluxer-core/tests/chat_ports.rs
Refs #267

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

Independent review: Text chat 17 (core search), head c1a1526

Scope: git diff b87bcd9..origin/textchat-17-core-search (search.rs, selectors/mod.rs, chat_ports.rs, chat_search.rs, README, plan note).

Checked

  1. Plan Step 1 tests exist and assert the right values: parse_cases has 36 cases (from/-from, has:image, has:forward -> snapshot, before/after/during/on, in:, pinned:true, sort:relevance, quoted values, unknown key kept as text). Also request_scope_and_context (scope current, context channel and guild ids, 25 per page, the sort menu wins), page_size_25 (31 results give 2 pages, page 401 and page 0 are refused), indexing_poll_backoff (1500, 1875, 2343, 2929, 3662, 4577, 5000, 5000, matching ChannelSearchPolling.ts), grouping_runs_by_channel (runs, not buckets), recent_searches_kept_10 and jump_from_result.
  2. Interfaces: parse(&str, UtcOffset) -> SearchQuery, SearchQuery::to_request(&App, page) -> SearchRequest, selectors::search_results and selectors::search_suggestions(&App, text, cursor) -> Vec<SuggestionSection> all exist as planned. Two additions, neither breaks a consumer: ResultGroup has an extra channel field, and SearchResultsState has an extra Results variant (recorded in the plan for Text chat 30).
  3. Invariants:
    • No new dependency. time was already a fluxer-core dependency.
    • No I/O and no clock: relative dates are read against the newest snowflake.
    • No new fixtures; the tests use the existing search_results.json and search_indexing.json.
    • KNOWN_KEYS, matchFilterKeyAt, the quote characters and channel_id + channel_ids match SearchQueryParser.ts and SearchUtils.ts:210.
    • Server data and user input cannot panic the client: date conversions use checked_to_offset, the cursor is clamped to a char boundary, and slicing is bounded. odd_input_never_panics covers offsets up to ±25:59:59 and far-year nows.
    • LocalSettings::chat.recent_searches is left untouched, so the settings file still round-trips.
    • No secrets, URLs or paths.
  4. Review Focus: none of the items belongs to Text chat 17.
  5. FLUXER_SCREENSHOT_TESTS=1 cargo xtask ci in a fresh review worktree: all steps passed (livekit-interop skipped by default).

Findings

  • minor: recent searches are only kept in memory and Search::utc_offset stays UTC until the runtime sets it. The spec says "kept locally". This is deferred and tracked in #315.
  • minor: a superseded search answer is not matched to its effect id, so it can replace the newer search's results. Tracked in #353.

The merge-conflict resolutions in selectors/mod.rs and chat_ports.rs are correct: both sides are kept.

Verdict: approve. No blocking findings and local CI is green.

## Independent review: Text chat 17 (core search), head c1a1526 Scope: `git diff b87bcd9..origin/textchat-17-core-search` (search.rs, selectors/mod.rs, chat_ports.rs, chat_search.rs, README, plan note). **Checked** 1. Plan Step 1 tests exist and assert the right values: `parse_cases` has 36 cases (from/-from, has:image, has:forward -> snapshot, before/after/during/on, in:, pinned:true, sort:relevance, quoted values, unknown key kept as text). Also `request_scope_and_context` (scope `current`, context channel and guild ids, 25 per page, the sort menu wins), `page_size_25` (31 results give 2 pages, page 401 and page 0 are refused), `indexing_poll_backoff` (1500, 1875, 2343, 2929, 3662, 4577, 5000, 5000, matching `ChannelSearchPolling.ts`), `grouping_runs_by_channel` (runs, not buckets), `recent_searches_kept_10` and `jump_from_result`. 2. Interfaces: `parse(&str, UtcOffset) -> SearchQuery`, `SearchQuery::to_request(&App, page) -> SearchRequest`, `selectors::search_results` and `selectors::search_suggestions(&App, text, cursor) -> Vec<SuggestionSection>` all exist as planned. Two additions, neither breaks a consumer: `ResultGroup` has an extra `channel` field, and `SearchResultsState` has an extra `Results` variant (recorded in the plan for Text chat 30). 3. Invariants: - No new dependency. `time` was already a fluxer-core dependency. - No I/O and no clock: relative dates are read against the newest snowflake. - No new fixtures; the tests use the existing `search_results.json` and `search_indexing.json`. - `KNOWN_KEYS`, `matchFilterKeyAt`, the quote characters and `channel_id` + `channel_ids` match `SearchQueryParser.ts` and `SearchUtils.ts:210`. - Server data and user input cannot panic the client: date conversions use `checked_to_offset`, the cursor is clamped to a char boundary, and slicing is bounded. `odd_input_never_panics` covers offsets up to ±25:59:59 and far-year nows. - `LocalSettings::chat.recent_searches` is left untouched, so the settings file still round-trips. - No secrets, URLs or paths. 4. Review Focus: none of the items belongs to Text chat 17. 5. `FLUXER_SCREENSHOT_TESTS=1 cargo xtask ci` in a fresh review worktree: all steps passed (livekit-interop skipped by default). **Findings** - minor: recent searches are only kept in memory and `Search::utc_offset` stays UTC until the runtime sets it. The spec says "kept locally". This is deferred and tracked in #315. - minor: a superseded search answer is not matched to its effect id, so it can replace the newer search's results. Tracked in #353. The merge-conflict resolutions in `selectors/mod.rs` and `chat_ports.rs` are correct: both sides are kept. **Verdict: approve.** No blocking findings and local CI is green.
charles manually merged commit 188f780de1 into textchat 2026-11-13 00:30:20 +00:00
Sign in to join this conversation.
No description provided.