Skip to content

fix(cli): drain search retrieval writes before exit#1344

Closed
eloe wants to merge 1 commit into
garrytan:masterfrom
eloe:fix/search-cli-exit
Closed

fix(cli): drain search retrieval writes before exit#1344
eloe wants to merge 1 commit into
garrytan:masterfrom
eloe:fix/search-cli-exit

Conversation

@eloe

@eloe eloe commented May 24, 2026

Copy link
Copy Markdown

Summary

Closes #1343.

  • Drain pending last_retrieved_at write-backs before disconnecting one-shot search, query, and get_page CLI operations.
  • Route gbrain search modes|stats|tune through the search namespace before the legacy search <query> operation.
  • Add structural regression coverage for the cleanup drain and search namespace dispatch.

Test Plan

  • bun run src/cli.ts search "GBrain setup smoke test" exits 0 without hanging
  • bun run src/cli.ts search modes exits 0 and prints the search mode dashboard
  • bun run src/cli.ts query "GBrain setup smoke test" --no-expand exits 0
  • bun test test/fix-wave-structural.test.ts
  • bun run verify

Notes

The root cause was a fire-and-forget retrieval metadata write racing with PGLite disconnect in the one-shot CLI path. The command could print results successfully while leaving pending async work around the same engine. This PR tracks those write-back promises and drains them before disconnecting.

Drain pending last_retrieved_at write-backs before disconnecting one-shot search/query/get_page commands so PGLite CLI processes exit cleanly. Route search modes/stats/tune through the search namespace before legacy search <query>.
@eloe

eloe commented May 24, 2026

Copy link
Copy Markdown
Author

Closing this PR as duplicate / overlapping work.

I opened it before checking thoroughly enough for existing issues and PRs. Existing coverage:

I validated #1259 locally on PGLite:

  • bun run src/cli.ts search "GBrain setup smoke test" exits 0 in ~0.33s
  • bun run src/cli.ts query "GBrain setup smoke test" --no-expand exits 0 in ~0.38s
  • bun test test/fix-wave-structural.test.ts passes: 11 pass / 0 fail

One note from validation: #1259 intentionally does not fix gbrain search modes routing; that remains the scope of #1212. Our combined PR is therefore redundant rather than the right place to supersede the existing work.

@eloe

eloe commented May 24, 2026

Copy link
Copy Markdown
Author

Closing as duplicate of #1259 for the CLI hang and #1212 for search namespace routing.

@eloe eloe closed this May 24, 2026
@eloe

eloe commented May 24, 2026

Copy link
Copy Markdown
Author

Closing this PR as duplicate / overlapping work.

I opened it before checking thoroughly enough for existing issues and PRs. Existing coverage:

I validated #1259 locally on PGLite:

  • bun run src/cli.ts search "GBrain setup smoke test" exits 0 in ~0.33s
  • bun run src/cli.ts query "GBrain setup smoke test" --no-expand exits 0 in ~0.38s
  • bun test test/fix-wave-structural.test.ts passes: 11 pass / 0 fail

One note from validation: #1259 intentionally does not fix gbrain search modes routing; that remains the scope of #1212. Our combined PR is therefore redundant rather than the right place to supersede the existing work.

@eloe eloe deleted the fix/search-cli-exit branch May 24, 2026 05:29
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.

gbrain search can hang after printing results and search modes routes incorrectly

1 participant