Skip to content

Preserve source worker history through maintenance - #1573

Open
zlareb1 wants to merge 22 commits into
mainfrom
feat/mcp-external-source-history-prep-on-main
Open

zlareb1 wants to merge 22 commits into
mainfrom
feat/mcp-external-source-history-prep-on-main

Conversation

@zlareb1

@zlareb1 zlareb1 commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

Related: #1190
Related: #1209
Related: #1302

Changelog category

  • Improvement

Changelog entry

Preserve document source worker registrations through native maintenance and namespace retirement. Refuse a connected-account restore that cannot account for worker history. Connected-account restore no longer refuses every deployment that holds connected sources.

Why

A maintenance build needs to preserve source worker registrations even when it cannot read their payload. A native connected-account restore must stop before it ignores that history.

Scope and risk

A worker row, active or inactive, keeps its original kind markers, configuration and selection bytes in its history; this build decodes neither, and native serving and sync do not use them. knowledge.source.check, remove, update, rotate and sync_now refuse a worker source with SOURCE_NOT_SERVED, which does not clear on retry, before authorization and before any probe. Namespace retirement (namespace deletion and erasure, collection.delete, code.repo.remove) writes a worker row inactive with its credentials cleared and its stored bytes kept, and queues no cleanup, so a namespace erasure completes. Native connected-account history, inventory, cleanup and census match native rows only and never a row carrying any worker marker; such a row belongs to a worker connection, and the build that first creates worker rows must add their account cleanup and census. Native restore refuses before it inventories or mutates anything while worker history exists, and the deployment restore census counts worker rows. connected_history now returns string source ids: ClickHouse answers the UUID column with uuid.UUID, which made restore refuse any real connected history. Native account disconnect skips worker history, list and inspect withhold worker details, native sync refuses to write worker state, mirror discovery and its last eligibility read exclude worker history, and pending retirements stop if a reread finds worker history for the same source.

This preparation leaves active worker writes and enrollment disabled. Worker credential cleanup, deployment restore and mixed build qualification remain separate work. It introduces no account record, credential, API field or migration.

Compatibility, rollout and rollback

  • Wire: no changes.
  • Operator steps: none. Keep worker enrollment and source writes disabled until the owner lifecycle and restore are qualified.
  • Rollback: no persisted format or schema changes. Do not run worker maintenance with a build that does not recognize this history.

Tests

Focused tests cover raw inactive rows, worker rows decoding no config or selection, partial markers, native restore refusal, and a native row whose config cannot be decoded reading as empty without stopping the inventory. Check, removal, update and rotate refuse a worker source; check and removal before authorization, and update and rotate both before and after the lease (rotate's first refusal comes before any probe). Namespace retirement writes a worker row inactive with its credentials cleared and its history kept, while queueing nothing. Disconnect, sync, mirror and retirement tests check a worker marker seen before and after the source lease. Native owner erasure deletes native rows and its SQL excludes every worker marker. The ClickHouse fixture shows native owner erasure leaving worker and damaged worker history byte-identical. The analyzer corpus was regenerated (2,344 shapes). Locally on Python 3.12, Ruff and the focused unit, analyzer and package-contract tests pass; tests that need paths outside the task's sparse checkout, and the ClickHouse analyzer and storage suites, run in hosted CI.


Note

Medium Risk
Touches connected-account cleanup, erasure census, and restore gates alongside credential clearing; mistakes could leave worker residue or block legitimate restores until worker-aware tooling ships.

Overview
Introduces worker source discrimination (is_worker_source, ClickHouse WORKER_HISTORY / NATIVE_ACCOUNT_BINDING) so this build can preserve MCP/worker registry rows without interpreting their payload.

API & ops: knowledge.source.check, remove, update, rotate, and sync_now refuse worker-marked sources with SOURCE_NOT_SERVED (before auth/probes). List/inspect withhold worker details.

Lifecycle: Native disconnect, owner erasure, connected inventory/history/census, and mirror discovery exclude worker rows. Namespace retirement inactivates worker rows in place (credentials cleared, raw config/items kept, no retirement queue). Sync and pending retirements stop when a reread sees worker history.

Restore: Deployment/native connected restore fails fast if any worker history exists; restore residue census counts worker rows. Inserts may only rewrite inactive worker history, preserving original column bytes via WorkerSourceHistory.

Docs and tests (unit, CH integration, analyzer corpus) updated accordingly.

Reviewed by Cursor Bugbot for commit cf3b424. Bugbot is set up for automated code reviews on this repo. Configure here.

Signed-off-by: zlareb1 <lareb.zafar@clickhouse.com>
@vercel

vercel Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
loom-docs Ready Ready Preview Dec 1, 2026 9:00pm UTC
loom-telemetry Ready Ready Preview Dec 1, 2026 9:00pm UTC

Request Review

Signed-off-by: zlareb1 <lareb.zafar@clickhouse.com>
@zlareb1

zlareb1 commented Nov 26, 2026

Copy link
Copy Markdown
Member Author

Addressed the four independent review findings in 0c73ed65a40d2488dd93980b6fa4a07b3bba571e:

  • Worker history and namespace discovery now include partial markers for the exact account binding. The cleanup census refuses damaged rows that the exact deletion leaves behind. Native account cleanup excludes those rows.
  • Native removal and namespace retirement refuse before queueing cleanup or changing a worker source, including one identified by its legacy marker alone.
  • The worker projection refuses a mixed JSON selection instead of discarding its malformed members. The worker registration decoder still accepts the exact valid selection.
  • Inactive rewrites retain both original kind columns and the raw configuration and selection.

294 focused tests, Ruff, the function length gate, strict mypy and the generated analyzer check passed. The new ClickHouse fixture covers a namespace with only damaged history. Fresh independent review and hosted CI apply to this head.

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

Comment thread server/knowledge/store/sources.py Resolved
Signed-off-by: zlareb1 <lareb.zafar@clickhouse.com>
…rce-history-prep-on-main

Signed-off-by: zlareb1 <lareb.zafar@clickhouse.com>
@zlareb1

zlareb1 commented Nov 26, 2026

Copy link
Copy Markdown
Member Author

Fixed the native access findings in 66680306d3. Account disconnect skips worker registrations, including when the worker marker appears after taking the lease. List and inspect withhold worker details. Manual sync checks the current source and caller authority again under the lease before writing state.

The exact head e7f4864ef3 includes the current base. Ruff, the function length gate, analyzer inventory and 303 focused tests passed. Strict type checking passed on the changed modules. Fresh independent review and hosted checks are running.

Signed-off-by: zlareb1 <lareb.zafar@clickhouse.com>
@zlareb1

zlareb1 commented Nov 26, 2026

Copy link
Copy Markdown
Member Author

Fixed the checked mirror finding in 5959d223e6. The native source query excludes worker registrations during both discovery and the last eligibility read. This also covers legacy worker markers on rows that report shared credentials. A native shared control still serves.

Ruff, strict type checking, the function length gate, the analyzer inventory and 140 focused tests passed. The normal hosted run includes the ClickHouse inventory fixture. Fresh independent review is underway.

A worker marker can appear after a native turn starts. Stop before writing documents or sync state when the current registration carries that marker.

Signed-off-by: zlareb1 <lareb.zafar@clickhouse.com>
@zlareb1

zlareb1 commented Nov 26, 2026

Copy link
Copy Markdown
Member Author

fc233fcd34d6a9938d12d32a06bbbedc9cc8a219 rechecks that the registration is still native before document, turn state and extraction state writes. Before the fix, all three worker history cases failed while the three native controls passed. After the fix, all 275 focused tests passed, along with Ruff, type checking and the function length gate. Fresh independent review and hosted CI apply to this head.

Check the registration before retiring documents and again before clearing the request. The existing cleanup still handles a removed or replaced native registration.

Signed-off-by: zlareb1 <lareb.zafar@clickhouse.com>
@zlareb1

zlareb1 commented Nov 26, 2026

Copy link
Copy Markdown
Member Author

9bc7791578f82f97f96dce13bd8f1ede3b4abb8e keeps worker history out of pending retirement for both native and mirrored sources. Each path rechecks the current registration before retiring documents and again before clearing the request. All four refusal cases failed before the fix, while the two native controls passed. After the fix, 306 focused tests, Ruff, type checking and the function length gate passed. Fresh review and hosted CI apply to this head.

@zlareb1

zlareb1 commented Nov 26, 2026

Copy link
Copy Markdown
Member Author

Independent review approved 9bc7791578f82f97f96dce13bd8f1ede3b4abb8e with no findings. The review verified ten native and mirror retirement cases, including worker history at both rereads and cleanup of removed or replaced native sources. Hosted checks are still running.

Signed-off-by: zlareb1 <lareb.zafar@clickhouse.com>

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit d3f4ca1. Configure here.

Comment thread server/knowledge/app/sources.py Resolved
Preserve the raw config when it cannot be decoded so one worker row
cannot stop native sync. Reread the registration under the source lease
before recording a full sync request.

Signed-off-by: zlareb1 <lareb.zafar@clickhouse.com>
@zlareb1

zlareb1 commented Nov 27, 2026

Copy link
Copy Markdown
Member Author

Independent review of 30d1597106c99d7f40e1da8f742fa029be77679f: approved with no findings across the full diff. The reviewer confirmed that an unreadable worker config leaves the raw history intact and does not block native inventory, and that the full sync request checks the registration under the source lease before writing state. The independent run passed 556 focused tests. Hosted ClickHouse and integration checks are still running. This is the independent review receipt; GitHub approvals are still required.

zlareb1 and others added 11 commits November 28, 2026 08:51
A lagging replica can miss worker source history before native account
cleanup starts or during the final residue census. Require sequential
reads at both checks.

Signed-off-by: zlareb1 <lareb.zafar@clickhouse.com>
The rename test needs two distinct memory bodies. Give the prose case its own sentence so canonicalization keeps both setup rows.

Signed-off-by: zlareb1 <lareb.zafar@clickhouse.com>
shapes.txt is regenerated with python -m tests.analyzer.corpus --write.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: zlareb1 <lareb.zafar@clickhouse.com>
Worker source rows no longer decode their config or selection in this
build: nothing reads them, writes reuse the stored bytes, and decoding
depended on the interpreter's JSON nesting limit. A native row whose config
cannot be decoded reads as empty instead of stopping the source inventory.
Remove and namespace retirement refuse an active worker source with a
permanent SOURCE_NOT_SERVED instead of a retryable overload.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: zlareb1 <lareb.zafar@clickhouse.com>
… native rows

A namespace erasure, deletion or repository removal refused while the
namespace held a worker source, so the erasure saga stopped before it
erased anything. Retirement now writes a worker row inactive with its
stored bytes and nothing queued; knowledge.source.remove still refuses
one. The worker branches of connected restore, owner history and the
account predicate had no caller and are removed with their tests and
analyzer case; native account cleanup and its census never match a row
carrying a worker marker, and the erasure section says so.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: zlareb1 <lareb.zafar@clickhouse.com>
…bing

Namespace retirement writes a worker row inactive with its sealed
credentials cleared, as for every other source, so none outlives an erased
namespace. knowledge.source.rotate refuses a worker source before it sends
any probe. The native account predicate is a constant, the row decoder keeps
its original shape, and the ClickHouse fixture checks its control row.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: zlareb1 <lareb.zafar@clickhouse.com>
…irst

ClickHouse answers the UUID source_id column with uuid.UUID, which made a
connected restore refuse any real history; connected_history now returns
strings. knowledge.source.remove refuses a worker source before
authorization, as update, rotate and sync_now do, and their tests assert
the permanent refusal message. The source guide states that the build that
writes worker rows clears their credentials when it writes them inactive.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: zlareb1 <lareb.zafar@clickhouse.com>
A non-admin removing a worker source gets the permanent worker refusal,
since it comes before authorization; the ClickHouse fixture checks that
connected history answers string source ids from the real driver.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: zlareb1 <lareb.zafar@clickhouse.com>
The account restore section names the refusal while any source row carries
a worker marker. The worker refusal is raised inline, the list op reads
sync state as main does, worker_history_exists describes what it returns,
and the retirement and remove behaviours are separate tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: zlareb1 <lareb.zafar@clickhouse.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: zlareb1 <lareb.zafar@clickhouse.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: zlareb1 <lareb.zafar@clickhouse.com>
zlareb1 and others added 2 commits December 1, 2026 20:55
check was the one source op that answered a worker source with the
retryable not-served message; it now refuses first, as remove, update,
rotate and sync_now do. The rotate test covers the reread under the lease.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: zlareb1 <lareb.zafar@clickhouse.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: zlareb1 <lareb.zafar@clickhouse.com>

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.

1 participant