GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(history): stream request index ingestion by luvs01 · Pull Request #1189 · lidge-jun/opencodex

Conversation

@luvs01

@luvs01 luvs01 commented Aug 7, 2026 •
edited by lidge-jun
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Collaborator

Summary

  • replace full-tail allocation with a reusable 64 KiB streaming reader;
  • assemble complete JSONL records across chunk boundaries with a 1 MiB projection limit;
  • retain partial final records until a later refresh completes them;
  • advance the indexed offset past complete malformed or oversized records while leaving the canonical usage log untouched;
  • preserve batched SQLite inserts and explicit statement finalization.

Why

The request-history index previously allocated size - indexedOffset bytes before parsing the appended tail. A large append could therefore create a proportional one-shot allocation even though the SQLite index is disposable and each record can be processed incrementally.

The new reader bounds transient input memory. A complete record above 1 MiB is intentionally omitted only from the derived SQLite projection; usage.jsonl remains canonical and is never truncated or rewritten. indexedRows continues to count successfully projected records.

Verification

  • Bun 1.3.14: tests/request-history-index.test.ts 20/20 passed.
  • Bun 1.4.0-canary.1 (b22e0e6d0): the same suite 20/20 passed.
  • Regressions cover a valid record crossing 64 KiB, an oversized valid record followed by an indexable record, exact offset accounting, canonical-log size preservation, and partial-line completion.
  • bun x tsc --noEmit: passed.
  • bun scripts/privacy-scan.ts: passed.
  • git diff --check: passed.
  • Independent read-only review found no blocking P0/P1 issue in offset, chunk, cleanup, or memory-bound behavior.

Checklist

  • Scope stays focused and avoids unrelated cleanup.
  • Docs or release notes were updated when needed. (The projection contract is documented in source and tests; no public API changed.)
  • Security-sensitive changes were reviewed for secrets, auth, and unsafe defaults.

Review readiness checklist

This PR stays in draft until every box below is ticked. Tick all four boxes once the requirements are met:

  • All CI tests are green on my local testing.

  • I pushed my PR to the latest dev commit.

  • I resolved all correct Codex and CodeRabbit findings.

  • My PR is ready for review.

Summary by CodeRabbit

  • Bug Fixes

    • Improved request-history indexing for large files by processing data in smaller chunks.
    • Correctly handles records that span read boundaries.
    • Skips oversized records without altering the canonical usage log.
    • Ensures incomplete trailing records are safely preserved for subsequent processing.
    • Maintains accurate indexing as additional portions of the history become available.
  • Tests

    • Added coverage for chunk-spanning records, partial records, and oversized-record handling.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

chatgpt-codex-connector[bot] reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@luvs01
fix(history): stream request index ingestion
6e7269d
@coderabbitai

coderabbitai Bot commented Aug 7, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The request-history indexer now reads the usage log in 64 KiB chunks. It preserves partial JSONL records, skips records above 1 MiB, tracks complete-record offsets, detects source changes, and closes resources. Tests cover partial, chunk-spanning, and oversized records.

Changes

Request-history ingestion

Layer / File(s) Summary
Bounded JSONL ingestion and cleanup
src/routing/history/indexer.ts
Lines 79–83 add read-chunk and maximum-record-size constants. Lines 217–280 replace whole-tail loading with chunked reads, fragment handling, oversized-record skipping, offset tracking, source-change detection, and batch commits. Lines 290–292 retain prepared-statement finalization during cleanup.
Chunk and oversized-record validation
tests/request-history-index.test.ts
Lines 2–29 add filesystem helpers and streaming constants. Lines 209–222 verify partial-line offsets. Lines 224–236 cover records spanning read chunks. Lines 238–252 cover oversized-record skipping, subsequent indexing, offset metadata, and canonical-log preservation.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant RequestHistoryIndexer
  participant SourceFile
  participant PreparedStatement
  participant RequestHistoryIndex
  RequestHistoryIndexer->>SourceFile: Read a 64 KiB chunk
  SourceFile-->>RequestHistoryIndexer: Return chunk bytes
  RequestHistoryIndexer->>PreparedStatement: Insert each complete valid record
  PreparedStatement->>RequestHistoryIndex: Store indexed rows
  RequestHistoryIndexer->>RequestHistoryIndex: Commit rows and next complete-record offset
  RequestHistoryIndexer->>PreparedStatement: Finalize during cleanup
Loading

Possibly related PRs

  • lidge-jun/opencodex#1004: Both changes modify request-history JSONL indexing in src/routing/history/indexer.ts and its tests.

Suggested reviewers: wibias

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: streaming request-history index ingestion.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
  • X
  • Mastodon
  • Reddit
  • LinkedIn

Comment @coderabbitai help to get the list of available commands.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

✅ Deterministic PR hygiene checks passed.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions

github-actions Bot commented Aug 7, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

⏳ DRAFT

  • review readiness checklist open (1/4 boxes ticked).

What to do

  • Tick all four boxes in the PR description once you're done (currently 1/4).

Review readiness checklist

  • ✅ All CI tests are green on my local testing.
  • ⬜ I pushed my PR to the latest dev commit.
  • ⬜ I resolved all correct Codex and CodeRabbit findings.
  • ⬜ My PR is ready for review.

1/4 boxes ticked.

This PR stays in draft until every box above is ticked.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot added the bug Something isn't working label Aug 7, 2026
@luvs01

luvs01 commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@coderabbitai

coderabbitai Bot commented Aug 7, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

coderabbitai[bot]
coderabbitai Bot reviewed Aug 7, 2026
View reviewed changes

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tests/request-history-index.test.ts`:
- Around line 228-243: Update the test “streaming refresh skips an oversized
record without changing the canonical log” to capture the canonical log contents
before queryRequestHistory() and compare them with the contents afterward, while
retaining the existing size assertion. Verify byte-for-byte content preservation
so equal-length truncate-and-rewrite defects are detected.
- Around line 214-226: Extend the streaming refresh test around
queryRequestHistory to cover an incomplete final JSON record: append the
serialized record without its newline, verify indexedOffset remains at the prior
complete-record offset, then append the newline and refresh again. Assert the
record is indexed exactly once after completion and remains available without
duplication.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 34a6df38-76b7-4f25-a981-c0e3a9031755

📥 Commits

Reviewing files that changed from the base of the PR and between 44dce33 and 6e7269d.

📒 Files selected for processing (2)
  • src/routing/history/indexer.ts
  • tests/request-history-index.test.ts

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread tests/request-history-index.test.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread tests/request-history-index.test.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

@luvs01
test(history): harden streaming index invariants
d5242a2
@lidge-jun
lidge-jun marked this pull request as ready for review August 8, 2026 09:16
@lidge-jun
lidge-jun requested review from Ingwannu, Wibias and lidge-jun as code owners August 8, 2026 09:16
@github-actions
github-actions Bot marked this pull request as draft August 8, 2026 09:17
@lidge-jun lidge-jun mentioned this pull request Aug 8, 2026
fix(history): stream request-history index ingestion (#1189) #1287
Merged
3 tasks done
@lidge-jun

lidge-jun commented Aug 8, 2026

Copy link
Copy Markdown
Owner

@luvs01 Republished this on current dev as #1287 — your branch was 300 commits behind, and the streaming reader is worth landing rather than letting it age out.

The rebase was clean; the commit is yours via Co-authored-by, and I changed none of the logic. On top of your own verification I ran the full suite on the rebased head (9991 pass / 0 fail) and an ablation that raises REQUEST_HISTORY_MAX_RECORD_BYTES to Number.MAX_SAFE_INTEGER, which fails exactly one of your tests — so the 1 MiB bound is provably load-bearing.

I'll close this one once #1287 lands. Nothing needed from you; if you'd rather drive it yourself, say so and I'll close #1287 instead.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

lidge-jun added a commit that referenced this pull request Aug 8, 2026
@lidge-jun @luvs01
fix(history): stream request-history index ingestion (#1189) (#1287)
2cb8edd
Replaces the full-tail allocation in the request-history indexer with a
64 KiB streaming reader. The previous `readCompleteTail` allocated
`size - indexedOffset` bytes in one shot before parsing, so a large append
created a proportional transient allocation even though the SQLite index is
a disposable projection.

Records are now assembled across chunk boundaries, and a complete record
above 1 MiB is omitted from the projection only. `usage.jsonl` stays
canonical and is never truncated or rewritten; `indexedRows` still counts
successfully projected records, and the indexed offset only advances past a
newline so a torn final record is re-read rather than skipped.

`insert.finalize()` remains unconditional in `finally` — an unterminated
prepared statement keeps the DB file busy on Windows after close.

Republished from #1189 by luvs01, whose branch was 300 commits behind dev.
Rebased onto f5147cb with no conflicts; authorship preserved below.

Co-authored-by: luvs01 <[email protected]>
@lidge-jun

lidge-jun commented Aug 8, 2026

Copy link
Copy Markdown
Owner

Landed on dev as 2cb8edd via #1287, with your Co-authored-by trailer intact through the squash — the commit is credited to you in the repository history.

Closing this one as superseded rather than stale. Thanks for the fix; the one-shot tail allocation was a real sharp edge.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@lidge-jun lidge-jun closed this Aug 8, 2026
@lidge-jun lidge-jun mentioned this pull request Aug 8, 2026
docs(devlog): record WP15, WP16, WP3, WP5 and lane D of the 2026-08-08 bug campaign #1307
Merged
3 tasks done
agentHits pushed a commit to agentHits/opencodex that referenced this pull request Sep 17, 2026
@lidge-jun @luvs01
fix(history): stream request-history index ingestion (lidge-jun#1189) (…
bcfbbb8
…lidge-jun#1287)

Replaces the full-tail allocation in the request-history indexer with a
64 KiB streaming reader. The previous `readCompleteTail` allocated
`size - indexedOffset` bytes in one shot before parsing, so a large append
created a proportional transient allocation even though the SQLite index is
a disposable projection.

Records are now assembled across chunk boundaries, and a complete record
above 1 MiB is omitted from the projection only. `usage.jsonl` stays
canonical and is never truncated or rewritten; `indexedRows` still counts
successfully projected records, and the indexed offset only advances past a
newline so a torn final record is re-read rather than skipped.

`insert.finalize()` remains unconditional in `finally` — an unterminated
prepared statement keeps the DB file busy on Windows after close.

Republished from lidge-jun#1189 by luvs01, whose branch was 300 commits behind dev.
Rebased onto 69a6ff9 with no conflicts; authorship preserved below.

Co-authored-by: luvs01 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@coderabbitai coderabbitai[bot] coderabbitai[bot] left review comments
@lidge-jun lidge-jun Awaiting requested review from lidge-jun lidge-jun is a code owner
@Ingwannu Ingwannu Awaiting requested review from Ingwannu Ingwannu is a code owner
@Wibias Wibias Awaiting requested review from Wibias

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

bug Something isn't working

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@luvs01 @lidge-jun
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.