Skip to content

fix(kb): scale kb-ingest timeout default with input size - #177

Open
asachs01 wants to merge 1 commit into
mainfrom
fix/kb-ingest-timeout-scaling
Open

fix(kb): scale kb-ingest timeout default with input size#177
asachs01 wants to merge 1 commit into
mainfrom
fix/kb-ingest-timeout-scaling

Conversation

@asachs01

@asachs01 asachs01 commented Sep 5, 2026

Copy link
Copy Markdown

Summary

  • The flat 600s (KB_INGEST_TIMEOUT_DEFAULT_MS) default in ingestKnowledgeBase ETIMEDOUT on two independent agents' MEMORY.md files (analyst: 476 chunks/97k tokens; adoption: 323 chunks) — both confirmed fixed only by manually setting KB_INGEST_TIMEOUT_MS=1800000. Since MEMORY.md only grows over an agent's lifetime (several fleet agents are already 400-550KB), every long-lived agent eventually hits this wall.
  • Scale the default with total input byte size (1.5ms/byte, a deliberately generous rate grounded in the one real data point — a several-hundred-KB file succeeding within the 30min manual override), floored at the existing 600s minimum (no behavior change for small files) and capped at 1h (so a huge/malformed input still fails loud instead of hanging indefinitely).
  • KB_INGEST_TIMEOUT_MS still wins outright when explicitly set — this only changes what "default" resolves to.

Closes task_1787849190389_13577787 (cortextos bus list-tasks).

Test plan

  • npx tsc --noEmit clean
  • npm run build clean
  • npx vitest run tests/unit/bus/knowledge-base.test.ts — 14/14 pass (8 existing + 6 new: floor-unchanged-for-small-input, scales-up-for-large-input, capped-at-1h, env-override-still-wins, unreadable-path-skipped-not-fatal, multi-path-sizes-sum)
  • Full npx vitest run — only pre-existing unrelated failures (dashboard next/server import errors in this worktree, one known-flaky chokidar watcher test per CLAUDE.md's 2026-07-28 flaky-test note), none touching this file

🤖 Generated with Claude Code


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

Summary by CodeRabbit

  • Bug Fixes
    • Knowledge-base ingestion timeouts now scale with the total size of input files.
    • Timeouts enforce minimum and maximum limits for more predictable processing.
    • Unreadable inputs no longer prevent timeout calculation.
    • A configurable environment setting can override the calculated timeout.

The flat 600s default ETIMEDOUT on two independent agents' MEMORY.md
files (analyst 476 chunks, adoption 323 chunks), both confirmed fixed
by manually raising KB_INGEST_TIMEOUT_MS to 30 min. Since MEMORY.md
only grows over an agent's lifetime, every long-lived agent eventually
hits this wall at the flat default — several are already 400-550KB.

Scale the default with total input byte size (1.5ms/byte) instead of
picking one bigger flat number, floored at the existing 600s minimum
and capped at 1h so a huge input still fails loud rather than hanging
indefinitely. KB_INGEST_TIMEOUT_MS still wins outright when set.

Closes task_1787849190389_13577787.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Sep 5, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: fc573189-1e9c-4f62-9af1-9e29716144d5

📥 Commits

Reviewing files that changed from the base of the PR and between e44bf20 and d618ce3.

📒 Files selected for processing (2)
  • src/bus/knowledge-base.ts
  • tests/unit/bus/knowledge-base.test.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 7 remain after this review.


📝 Walkthrough

Walkthrough

Knowledge-base ingestion now sizes its default timeout from readable input bytes. The timeout remains bounded by a 60-second floor and one-hour cap. KB_INGEST_TIMEOUT_MS overrides the calculation. Unit tests cover scaling, limits, overrides, stat failures, and cumulative inputs.

Changes

Knowledge-base ingest timeout

Layer / File(s) Summary
Timeout sizing and validation
src/bus/knowledge-base.ts, tests/unit/bus/knowledge-base.test.ts
The ingest timeout uses readable input sizes at 1.5 ms per byte, with a 600-second minimum and one-hour maximum. A positive KB_INGEST_TIMEOUT_MS value overrides the calculation. Stat failures do not abort ingestion. Tests cover these cases and cumulative input sizes.

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

Merge Risk: ⚪ Minimal · up to d618c

Knowledge-base ingestion timeouts now scale with readable input size while preserving bounded defaults and explicit overrides. The change is covered for its intended sizing and failure-handling behavior, with no current merge-blocking risk identified.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: scaling the default knowledge-base ingest timeout with input size.
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.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/kb-ingest-timeout-scaling

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

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