Skip to content

fix(queue): preserve JSONL boundaries when recovering inflight rows - #371

Open
DivyamTalwar wants to merge 1 commit into
activeloopai:mainfrom
DivyamTalwar:fix/session-queue-recovery-boundaries
Open

DivyamTalwar wants to merge 1 commit into
activeloopai:mainfrom
DivyamTalwar:fix/session-queue-recovery-boundaries

Conversation

@DivyamTalwar

@DivyamTalwar DivyamTalwar commented Sep 21, 2026 •

Copy link
Copy Markdown

Summary

Fixes #370.

When an upload fails, requeueInflight() appends the old inflight bytes directly to the producer replacement queue. If that replacement ends in a partial JSON record or a complete record without its trailing newline, the first recovered row is concatenated to it. The next drain treats the combined line as malformed and loses a previously durable row.

Change

Inspect and append through the same a+ descriptor and insert a separator only when the nonempty replacement queue is unterminated. Reuse the existing newline helper; close the descriptor in finally and remove inflight only after append succeeds. Empty and already terminated queues do not gain an extra byte.

Regression evidence

The five-case negative-control matrix has three failing cases and two passing controls on unchanged source. With the patch, all five pass. Tests exercise failed uploads with partial/complete/terminated replacement tails, stale inflight recovery, and absent replacement queues, then verify row identities and no second-flush replay. The Linux surrounding run passes 48 tests; independent macOS review passes 43 queue and append-atomicity tests.

Version Bump

No release is requested from this contributor PR. Package versions and the lockfile are unchanged.

Test plan

  • Negative control reproduces the defect against unmodified production source.
  • New and surrounding focused regressions pass locally.
  • Exact commit 728aa7de466e51ba05174eb5ec7e92576456a48b passes the full Node 22/Linux suite with coverage: 5854 tests passed, zero failed.
  • Typecheck, build, duplication check, and critical-only OpenClaw bundle audit pass in the isolated Linux gate.
  • No release/version bump requested.

Exact commands, logs, and validation artifacts. This is an independent branch gate, not a result borrowed from a stacked feature branch.

Limits

This is a record-boundary fix, not an outage-isolation, queue-capacity, cross-workspace migration, or distributed-lock redesign. Crash-after-append-before-removal and disk-failure semantics are unchanged. Existing open PRs #61 and #65 were checked at their actual head source: both still perform the unseparated append and do not include this fix.

The full isolated macOS baseline is not clean (19 failures and 10 skips before these changes); a clean full macOS suite is not claimed. Local scoped evidence and the full Linux gate are reported separately. Regression tests use synthetic files and mocked network/worker boundaries, not real user credentials, customer transcripts, or live model calls.

Summary by CodeRabbit

  • Bug Fixes

    • Improved session queue recovery after interrupted or failed flushes.
    • Preserved partial queue records without combining them with recovered records.
    • Prevented duplicate or empty records during repeated recovery attempts.
    • Ensured recovered records remain intact when queue files are missing or contain incomplete lines.
  • Tests

    • Added coverage for recovery with partial, complete, and newline-terminated queue records.

@coderabbitai

coderabbitai Bot commented Sep 21, 2026 •

Copy link
Copy Markdown

Review Change StackReview Change Stack

Understand this PR’s impact

Explore downstream dependencies and potential security impact with Blast Radius.

View blast radius →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: activeloopai/hivemind/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 9cb6c583-756d-4069-a30a-2d9bd1b3abfe

📥 Commits

Reviewing files that changed from the base of the PR and between ce30de7 and 728aa7d.

📒 Files selected for processing (2)
  • src/hooks/session-queue.ts
  • tests/claude-code/session-queue.test.ts

Included review availability: Your plan provides up to 4 included reviews per hour; 1 remains after this review.


📝 Walkthrough

Walkthrough

The queue recovery path now checks the existing queue tail before appending inflight content. It adds a separator only when required and closes the shared file descriptor after the append. Tests cover partial, complete, terminated, stale, and absent queue states.

Changes

Session queue recovery

Layer / File(s) Summary
Record-boundary recovery
src/hooks/session-queue.ts, tests/claude-code/session-queue.test.ts
requeueInflight uses one a+ descriptor, adds a newline only for an unterminated tail, and closes the descriptor in finally. Tests verify row recovery and inflight cleanup across queue-tail states.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~15 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: efenocchi

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: preserving JSONL record boundaries during inflight row recovery.
Description check ✅ Passed The description includes the required Summary, Version Bump, and Test plan sections. It explains the defect, implementation, regression coverage, validation results, and release intent.
Linked Issues check ✅ Passed Issue #370 requires a separator only for a nonempty unterminated queue tail. requeueInflight() opens the replacement queue with a+, checks the tail with endsWithNewline, and appends through the …
Out of Scope Changes check ✅ Passed The diff changes only inflight recovery in src/hooks/session-queue.ts and adds focused regression tests in tests/claude-code/session-queue.test.ts. The tests directly support issue #370 record-bou…
  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR

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

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

This branch has not been deployed

No deployments
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.

Recovering an inflight session batch can concatenate rows with an unterminated queue tail

1 participant