Skip to content

sync: preserve knowledge base vectors and refine context accounting - #126

Merged
Luhaozhu merged 1 commit into
mainfrom
sync/ce-2026-08-27-context-sandbox
Aug 28, 2026
Merged

sync: preserve knowledge base vectors and refine context accounting#126
Luhaozhu merged 1 commit into
mainfrom
sync/ce-2026-08-27-context-sandbox

Conversation

@Luhaozhu

Copy link
Copy Markdown
Contributor

Community edition sync derived from the upstream development tree.

Knowledge base collections are never dropped implicitly

get_or_create_collection used to drop and recreate the collection whenever the
stored dense vector dimension could not be read or did not match the current
embedding model. A transient Milvus outage was therefore enough to silently
delete every indexed vector.

The collection is now preserved in all three cases — unreadable schema, missing
dim metadata, and a genuine dimension mismatch — and the operation aborts with
an explicit error so an operator can verify the embedding configuration and
re-index deliberately. Four regression tests cover the new behaviour.

Tool definitions are accounted for as system tokens

Tool schemas are sent on every request as part of the fixed instruction surface;
they are not evidence that the model executed a tool. Counting them in the
tools bucket inflated the tool share of the context panel. They now belong to
the system bucket in both the measured and the post-compaction estimated
snapshot.

The snapshot schema is bumped to context-usage.v2, and the frontend parser
rejects v1 snapshots so old and new accounting rules are never mixed in one
panel.

Also included

  • Sandbox provider is pinned to the service event loop, fixing repeated sandbox
    rebuilds caused by cross-loop calls.
  • SANDBOX_ARTIFACT_MAX_BYTES becomes the single size limit for every sandbox
    file transfer, including /myspace write-back.
  • Sandbox myspace directories are created as the sandbox runtime user, so
    agents can write into them.
  • Streaming output can be selected and copied while it streams, and scrolling up
    is no longer forced back to the bottom.
  • Cancelling a chat run keeps the partial answer already produced.

Verification

Generated with scripts/build_ce.py; brand, LICENSE, required-runtime-file and
binary-allowlist gates all pass. Backend tests for the touched areas pass
upstream.

Knowledge base collections are no longer dropped implicitly. When the stored
dense vector dimension cannot be read, or differs from the current embedding
model, the collection is preserved and the operation aborts with an explicit
error so an operator can verify the embedding configuration and re-index on
purpose. Previously a transient Milvus outage was enough to silently wipe
every indexed vector.

Context usage accounting moves tool definitions out of the "tools" bucket.
Tool schemas are part of the fixed instruction surface sent on every request,
not evidence that the model executed a tool, so they are now counted with the
system prompt. The snapshot schema is bumped to context-usage.v2 and the
frontend rejects v1 snapshots to avoid mixing the two accounting rules.

Also included: sandbox provider event-loop affinity, a single size limit for
all sandbox file transfers, sandbox myspace directories created as the sandbox
runtime user, streaming selection and scroll fixes, and partial answer
retention when a chat run is cancelled.
@Luhaozhu
Luhaozhu merged commit 5f53dcd into main Aug 28, 2026
5 checks passed
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