Skip to content

fix(history): keep stateless cron runs out of the session search window - #34173

Merged
unstablebrainiac merged 1 commit into
mainfrom
unstablebrainiac/fix/history-search-window-skip-crons
Nov 10, 2026
Merged

unstablebrainiac merged 1 commit into
mainfrom
unstablebrainiac/fix/history-search-window-skip-crons

Conversation

@unstablebrainiac

@unstablebrainiac unstablebrainiac commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: Session search finds older chats on a host that runs a stateless cron job every few minutes.

Session search reads only the newest session.search_scan_window transcripts (default 2000). A stateless cron job writes a new cron:<job id>:<run id> transcript on every fire, and each one takes a window slot. On one real host 7,510 of 8,990 transcripts are stateless runs. A 2000-file window there reaches back five days, so a chat from last week is never searched, open or archived. The run-transcript prune (#31757) now keeps 20 tagged runs per job, but it never removes an untagged run, and every run written before the ephemeral tag existed is untagged.

Why it matters

Anyone with a frequent stateless cron loses content search over most of their history. The dashboard History filter, search_chat_history and the channel session picker all share this window, so "where did that chat go?" returns nothing on every surface.

Not a goal

  • Changing the default window size or how the window is counted for conversations.
  • Hiding stateless runs from the History listing or from a bare title: search.
  • Deleting the untagged runs the prune keeps.
  • Changing persistent cron sessions (cron:<job id>) or sequential-agent sessions (cron:<job id>:<agent>).

What changed (motivation → approach → change)

Stateless cron runs no longer take a slot in the session search window, so the window's slots go to conversations.

Part Change
Key test cron_service/identity.py gains is_stateless_cron_run_key, beside the code that mints the key. It matches cron:<8 hex>:<8 hex> in the live and the transcript-stem spelling.
Window history_search.py drops those keys before slicing the window in the search, the warm-up and the index backfill. They are also left out of the eligible count, so the "older sessions were not searched" note does not count them.
Chat tabs A new_chat_per_run run that opened its own chat tab is tagged cron_run="tab" and stays searchable. history_search_listing.py copies cron_run onto the listing row so the window can read it.
Spec docs/system-specs/modules/history.md states the rule.

A persistent job keeps one transcript that can hold a real conversation, so it stays searchable. A sequential-agent session (cron:<job id>:<agent>) looks like a run only when the agent's name is eight lowercase hex characters. That one case is left out of the window too.

Backwards compatibility

Compatible: no config key, API field or stored data changes; only which transcripts a content search reads.

Reader: src/kiro_crew/dashboard/handlers/sessions_parts/history_reads.py:api_sessions_search -- chat -- the History filter no longer returns untabbed stateless run transcripts for a content query; the listing and a bare title: search still show them
Reader: src/kiro_crew/mcp_tools/sessions.py:search_chat_history -- subagent -- returns conversations and persistent cron sessions; a stateless run is still readable with get_chat_session by key
Reader: src/kiro_crew/history.py:ConversationLog.search_sessions -- crew page -- the federated instance search and the channel session picker call the same ranking and get the same rows

Tests

test/test_session_search_scan_window.py:

  • TestStatelessCronRunsTakeNoWindowSlot locks in that newer runs do not push chats out of a window of two, that persistent and sequential-agent cron sessions are still searched, that a run tagged tab is searched while an ephemeral one is not, and that the index backfill indexes a tabbed run and no other run.
  • TestStatelessRunKey checks the predicate against keys minted by build_cron_session_context, both spellings, and near-miss keys.

Proof: PROVEN test/test_session_search_scan_window.py::TestStatelessCronRunsTakeNoWindowSlot::test_newer_runs_do_not_push_chats_out_of_the_window, test/test_session_search_scan_window.py::TestStatelessCronRunsTakeNoWindowSlot::test_persistent_and_agent_sequence_cron_sessions_are_searched, test/test_session_search_scan_window.py::TestStatelessCronRunsTakeNoWindowSlot::test_a_run_that_opened_its_own_chat_tab_is_searched, test/test_session_search_scan_window.py::TestStatelessCronRunsTakeNoWindowSlot::test_the_backfill_never_indexes_a_run (head 8838d88)

Determinism: the new tests passed 5 of 5 repeats, in a shuffled order, and under -n 4 with the whole file.

Manual verification

On the host described above, a read-only count with is_stateless_cron_run_key over its session directory: today the 2000-file window ends at a file modified Nov 4; with runs left out, all 1,480 remaining transcripts fit in the window. No UI changes, so nothing else to check by hand.

Related Issues

Closes #34135

Sibling sweep

Swept: git grep -nE "_facade_search_scan_window()|search_scan_window()" -- src/
Sibling: src/kiro_crew/history_search.py -- changed here

Pattern harvest

Not generalizable: the window is the only newest-N cap in the tree that a per-fire writer can fill.

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

@unstablebrainiac
unstablebrainiac force-pushed the unstablebrainiac/fix/history-search-window-skip-crons branch from c70ad29 to 0ad9138 Compare November 9, 2026 23:12
@github-actions

github-actions Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision 8838d8895f31ea393a70614c91a5e454adce7d0f touches no user-facing surface (no changes under website/ or committed screenshots), so the UX review was skipped. Does not block merge.

@github-actions

github-actions Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of 8838d8895f31ea393a70614c91a5e454adce7d0f and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 8838d88

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 8838d8895f31ea393a70614c91a5e454adce7d0f false-positive: <reason, 20 to 500 characters>

@github-actions

github-actions Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of 8838d8895f31ea393a70614c91a5e454adce7d0f — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

Design-Verdict: PASS

No design-level blocker: the window exclusion goes after the cause, and the description lists and accepts the reader that loses content-search hits.

Notes

  • _searchable drops untabbed stateless runs from content search on every host, including hosts where the window has spare slots, so a search for what a cron report said finds nothing. Ordering conversations first and letting runs fill whatever slots are left would remove the crowding and keep that recall.
  • The filter also runs on the keys= path (_app_search → _AppOwnedKeys), so an app can no longer content-search its own stateless cron runs. That path is a scoped lookup, not the shared window, so consider skipping the filter when keys is set.

[DESIGN-REVIEWED] 8838d88

Description read

[DESCRIPTION-READ] 5c7f6c19e587957ebfbd86a8fa82aa49f86209504d2bdc4afd9413775b19fda4

That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed 8838d8895f31ea393a70614c91a5e454adce7d0f — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 8838d88

Verdict parsed from the review's SHA-scoped output markers for commit 8838d8895f31ea393a70614c91a5e454adce7d0f.

False positive or not applicable? A repository writer can comment:
/ai-review override fable 8838d8895f31ea393a70614c91a5e454adce7d0f false-positive: <reason, 20 to 500 characters>

@github-actions github-actions Bot added the readiness: action required A blocking check or review needs attention label Nov 9, 2026
@github-actions

github-actions Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of 8838d8895f31ea393a70614c91a5e454adce7d0f — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

First-Principles-Verdict: PASS

The fix targets the window that stateless runs were filling. The new key predicate restates a run-key regex the prune already has, which is a note, not a blocker.

Notes

  • Item 5 — duplicate of src/kiro_crew/cron_service/run_residue.py:56: the new _STATELESS_RUN_KEY (cron[:_][0-9a-f]{8}[:_][0-9a-f]{8}) is a second copy of the cron_<8 hex>_<8 hex> shape. The prune's _RUN_TRANSCRIPT already holds it (two patterns grepped for that shape; the regex CRON_SESSION_RE in validation_parts/input_bounds.py is a looser third). If one changes and the other does not, the prune and the search will disagree about which keys are runs. Subtraction: delete _RUN_TRANSCRIPT's copy of the shape and have prune_stale_run_transcripts match through is_stateless_cron_run_key on the stem, so only one pattern remains.

What this change ships

Inventory (6 items) — 5 justified

Intent: let people with a frequent stateless cron job find older chats in session search. FIX.

  1. Content search (History filter, search_chat_history, channel picker, federated search) no longer reads untabbed stateless cron run transcripts — justified
  2. Older chats that were pushed out of the 2000-file window are now searched — justified
  3. The "older sessions were not searched" note no longer counts stateless runs — justified
  4. Index warm-up and backfill skip stateless runs — justified
  5. New public predicate is_stateless_cron_run_key — duplicate of run_residue._RUN_TRANSCRIPT shape
  6. A new_chat_per_run run with its own tab stays searchable, because the listing row now carries cron_run — justified

[FIRST-PRINCIPLES-REVIEWED] 8838d88

Description read

[DESCRIPTION-READ] 39b7b41bde71740f3db5cd6e67f2c1692c848562074f32102e873d87b36e7d3d

That sha256 names the PR description this verdict read. Recompute it with .github/scripts/pr-description-capture.sh; if it differs, the description changed after this verdict was formed and any finding drawn from the description is unproven.

@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Nov 9, 2026
@unstablebrainiac
unstablebrainiac force-pushed the unstablebrainiac/fix/history-search-window-skip-crons branch from 0ad9138 to 8838d88 Compare November 10, 2026 00:50
@unstablebrainiac

Copy link
Copy Markdown
Contributor Author

Rebased: main moved in docs/system-specs/modules/history.md and other history/session files since this head went green (4bbbc50 -> 73e3275); CI re-running.

@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running labels Nov 10, 2026
@Zedmor

Zedmor commented Nov 10, 2026

Copy link
Copy Markdown
Contributor

Code change approver recommendation: Approve

Automated, not a person, and not a review: a maintainer still decides.

decider-v3c@217fe607 · p_defect 0.12 · router R0 (approves only when p_defect <= 0.12, on changes of at most 400 changed lines) · head 8838d8895f · 145 changed lines

Why: the decider approves with p_defect 0.12 <= 0.12 and every rail passes.

Approve. The PR stops stateless cron run transcripts (cron:<8hex>:<8hex>) from using up slots in the session search window, so older chats are searched again. The filter runs before every window slice (search, warm-up, index backfill) and before the count behind the 'not searched' note. A grep found no other window slice in src/. Runs already in the search index are dropped by the backfill's existing cleanup of keys outside the window, and no transcript is deleted. The cron_run='tab' tag is already written on main (cron_delivery.py:183) before a tab is published. It now reaches listing rows through _apply_metadata, which both the cached listing and the direct scan use. The app-scoped keys= path loses nothing, because cron transcripts have no app owner. The key predicate matches exactly what gets created. New tests would fail without the change, and the spec is updated. Remaining concerns (legacy untagged tab runs, the duplicated regex) are deliberate or minor.

If this recommendation is wrong, reply here; the replies are how the approver is evaluated.

@unstablebrainiac
unstablebrainiac enabled auto-merge (squash) November 10, 2026 01:47

@KiroCrewCaptain KiroCrewCaptain left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Tier 1 auto-approve: fix (5 files). Criteria: no conflict, no requested changes, security path denylist clean, design-doc gate clean, security checklist all-NO, no reviewer-lane findings, readiness signal fresh for this head SHA, declared category matches the diff. Category: bug fix; session search leaves untabbed stateless cron run transcripts out of its scan window, so frequent cron runs no longer push older chats out of search, with tests. Spec files changed as a ride-along (a minority of the diff on both file count and changed lines), not reviewed as a design decision: docs/system-specs/modules/history.md.

@unstablebrainiac
unstablebrainiac merged commit d503d56 into main Nov 10, 2026
99 of 101 checks passed
@unstablebrainiac
unstablebrainiac deleted the unstablebrainiac/fix/history-search-window-skip-crons branch November 10, 2026 02:05
bolichen97 pushed a commit that referenced this pull request Nov 10, 2026
…ow (#34173)

Backport note: history_search_listing.py is not on release (the listing
split of #29452 is unreleased), so its cron_run metadata projection is
dropped. Release's three window call sites read list_sessions(), not
list_sessions_indexed(), and get the _searchable filter as they are. The
cron_run == "tab" exemption serves the per-run chat tab of #31139
(unreleased), so _searchable drops every stateless run by key alone; the
docstrings, history.md and the test lose the tab sentences, the tab-run
test is dropped and the backfill test expects the two chats only.

(cherry picked from commit d503d56)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

readiness: passed Eligible automated validation passed for the current revision

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Session search misses older chats once stateless cron runs fill the scan window

3 participants