Skip to content

feat(kb): storage usage bar with byte cap on the KB card - #1108

Merged
DerrickF merged 1 commit into
developfrom
feat/kb-usage-bar
Sep 14, 2026
Merged

DerrickF merged 1 commit into
developfrom
feat/kb-usage-bar

Conversation

@DerrickF

Copy link
Copy Markdown
Contributor

What

Shows a storage usage bar on each agent's knowledge-base card so users can see how much of their managed-KB byte cap they are consuming — part of keeping managed-KB storage cost visible (Req 12.11).

The cap

There are two configured limits (per-owner tier: 100 MB standard / 1 GB elevated; per-KB ceiling: 500 MB). The binding one is effective_cap = min(owner tier, per-KB ceiling), already computed in byte_cap.py. Since it is one KB per agent this phase, that single number is what the bar shows against.

Backend

  • KbUsage model (engine, storedBytes, reservedBytes, cap, elevated) added to DocumentsListResponse — folded into the existing GET /assistants/{id}/documents response, no extra round-trip.
  • _resolve_kb_usage reads the KB_Record once. Managed → reports bytes + effective_cap; legacy S3-Vectors → cap: null (uncapped), zeroed counters. Best-effort: a record-read failure returns null rather than failing the documents list.
  • elevated is READ from elevatedByteCap, never written.

Frontend

  • Usage bar on the KB card, under the Uploaded Documents header.
  • Managed: X of Y used, fill turns green < 75%, yellow 75–90%, red ≥ 90%.
  • Legacy: uncapped, so X stored with a small green sliver — no misleading full/empty bar.

Tests

  • Backend (tests/routes/test_documents.py): managed-with-cap, elevated flag, legacy-uncapped, and the read-failure-doesn't-break-the-list path. Run locally — all green; adjacent byte-cap/chunk-inspector route tests still green; ruff clean.
  • Frontend (knowledge-base-section.component.spec.ts): green/yellow/red thresholds, reserved-bytes counted, uncapped-legacy, render + create-mode gating.

Verification note

Backend tests were run locally (green). The frontend spec was not runnable locally on this host (fresh worktree, and the borrowed node_modules store broke type resolution) — relying on CI to run the Angular suite. Not deployed.

Fold KB storage usage into the documents-list response so the agent's
knowledge-base card can show how much of the byte cap is in use.

Backend:
- Add KbUsage model (engine, storedBytes, reservedBytes, cap, elevated)
  to DocumentsListResponse.
- _resolve_kb_usage reads the KB_Record once: managed KBs report their
  bytes and the binding effective_cap (min of owner tier and per-KB
  ceiling); legacy S3-Vectors KBs are uncapped (cap=null). Best-effort so
  a record-read failure never breaks the documents list.

Frontend:
- Usage bar on the KB card: 'X of Y used' for managed KBs, green/yellow/red
  at <75/75-90/>=90% of the cap; legacy KBs show 'X stored', always green,
  no denominator.

Tests: backend route tests for managed/legacy/failure paths; frontend
component specs for the thresholds and the uncapped legacy case.
@DerrickF
DerrickF merged commit 9987469 into develop Sep 14, 2026
6 checks passed
philmerrell added a commit that referenced this pull request Sep 15, 2026
`_resolve_kb_usage` interpolated `assistant_id` — a user-controlled path
parameter — straight into a `logger.warning` f-string, so `\r`/`\n` in it could
forge additional log lines (CodeQL `py/log-injection`, alert #864, medium).

New in this release: the sink arrived with the KB storage usage bar (8fb4f8f,
#1108), on a branch parallel to the #1098 sweep that sanitized every other
instance — so the release was about to ship a regression against a rule it
enforces elsewhere. Fixed to that sweep's own convention: `%s` lazy formatting
with `scrub_log()` on each user-influenced value.

Scanned every logger call this release ADDED for the same shape; the rest carry
exceptions, ints, or already-scrubbed values. The pre-existing f-string logger
calls elsewhere in the tree are deliberately left alone — that is a sweep, not
release-branch work.

Backend suite: 8626 passed, 3 skipped.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This was referenced Sep 15, 2026
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