Skip to content

fix(kap-server): verify indexed search results against session sources - #3631

Open
wbxl2000 wants to merge 7 commits into
mainfrom
qer/search-deleted-sessions
Open

fix(kap-server): verify indexed search results against session sources#3631
wbxl2000 wants to merge 7 commits into
mainfrom
qer/search-deleted-sessions

Conversation

@wbxl2000

@wbxl2000 wbxl2000 commented Sep 7, 2026

Copy link
Copy Markdown
Collaborator

Related Issue

Related to #3543 and #3630. Replaces the search-index deletion machinery from #3544. #3630 has merged; this branch includes the current deletion API baseline.

Problem

A deleted session can remain in a writer's unsynchronized index or another process's stale read-only view. Scheduling another sync does not give a time bound, and a deletion ledger creates a second persistence protocol whose compaction, reader lag, and ID reuse must all be coordinated.

What changed

  • Bind indexed messages and titles to their source session directory's filesystem identity (device, inode, and birth time). Validate each distinct source while querying and filter missing or replaced sources before pagination, including read-only workers. Filesystems without a positive inode and birth time cannot provide this verification, so their indexed results remain hidden until the source can be verified and reindexed. Query source checks share a single outstanding filesystem operation per worker. A timed-out request retains that permit until its stat settles; waiting queries expire without issuing more filesystem work or retaining waiters. Later queries perform fresh checks rather than reuse old results. Source checks share the query deadline; a stalled source returns only already-verified results with incomplete: deadline.
  • Sessions skipped during indexing are excluded from the indexed count and reported in persisted degraded status, including read-only readers; recovery clears the status.
  • Read titles from the source session metadata and keep them with that identity. A stale session-list snapshot cannot attach an old title to a recreated session. Normal renames update displayed titles without rewriting unchanged message documents; damaged optional title metadata does not stop message indexing.
  • Reuse the existing writer sync to remove stale documents and rebuild sessions whose source identity changed. Old index entries without an identity remain hidden until that session is reindexed. Query state is captured before asynchronous source checks so a concurrent read-only refresh cannot cause access to a closed database handle.

There is no deletion ledger, expiry window, background deletion retry, or cross-process acknowledgement protocol. This change validates indexed search results when queried; it does not synchronously erase every disk copy or retract responses from queries already in progress. The separate live-transcript search path is unchanged. Physical index cleanup still requires a successful writer sync, while stale indexed rows cannot bypass the source check.

Validation

  • Full kap-server suite: 1,324 passed, 1 pre-existing skip. Final search suites including unavailable-identity and stalled-source regressions: 159 passed.
  • A combined integration smoke test with feat(kap-server): expose session deletion with serialized cleanup #3630 passed: real REST deletion, a stale read-only search worker, deleted journal removal, WebSocket notification/re-subscription, and same-ID recreation.
  • kap-server TypeScript check, root lint, and comment policy passed (existing warnings, no errors).
  • Regressions cover worker and inline backends, read-only stale views without a writer sync, filtering before pagination, same-ID recreation with a stale summary, legacy-index migration, normal renames, unreadable source directories, missing filesystem identity fields and recovery, corrupt optional metadata, read-only refresh during a blocked source check, delayed source reads that succeed or fail after the query deadline, and repeated concurrent searches while one source check remains blocked.

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue (external PRs: the issue must have a maintainer's /approve).
  • I have added tests that prove my feature works.
  • Ran gen-changesets skill, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update. This corrects existing search behavior without adding a CLI invocation or configuration option.

@changeset-bot

changeset-bot Bot commented Sep 7, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: c3b0da0

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@moonshot-ai/kimi-code Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@wbxl2000

wbxl2000 commented Sep 7, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@pkg-pr-new

pkg-pr-new Bot commented Sep 7, 2026

Copy link
Copy Markdown
pnpm dlx https://pkg.pr.new/@moonshot-ai/kimi-code@c3b0da0
npx https://pkg.pr.new/@moonshot-ai/kimi-code@c3b0da0

commit: c3b0da0

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 41a1f2c8eb

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread packages/kap-server/src/search/indexCore.ts Outdated
@wbxl2000

wbxl2000 commented Sep 7, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3ea3c627e5

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread packages/kap-server/src/search/indexCore.ts Outdated
@wbxl2000

wbxl2000 commented Sep 7, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Already looking forward to the next diff.

Reviewed commit: a30e2c8973

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@wbxl2000

wbxl2000 commented Sep 7, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3a1bbdaaae

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread packages/kap-server/src/search/indexCore.ts Outdated
@wbxl2000

wbxl2000 commented Sep 7, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 95c7a63d91

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread packages/kap-server/src/search/indexCore.ts Outdated
@wbxl2000

wbxl2000 commented Sep 7, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Breezy!

Reviewed commit: c3b0da0127

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

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