Skip to content

Preserve source worker history through maintenance - #1573

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

zlareb1 wants to merge 9 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 inactive document source worker registrations through metadata updates. Refuse a connected-account restore that cannot account for worker history.

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

An inactive worker row keeps its original kind markers, configuration and selection bytes. Protected readers can read current registrations and refuse malformed selections. Native serving and sync do not use them. History and census include partially marked worker rows for the exact tenant, owner and connection. Cleanup stops if any damaged rows remain; native account cleanup leaves them alone. Native restore refuses worker history before it inventories or mutates the native accounts. Native source removal and namespace retirement stop before queueing worker cleanup. Native account disconnect skips worker history, list and inspect withhold worker details, and native sync refuses to write worker state. Checked mirror discovery and its last eligibility read exclude worker history even when the row reports shared credentials. A background sync turn also stops before document, turn state and extraction state writes if its reread finds worker history. The full sync request also rereads the registration under the lease before it writes state. Pending native and mirror retirement requests 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, the active selection, partial markers, scoped erasure and census, and native restore refusal. Tests cover native removal, namespace retirement, account disconnect, list, inspect and sync. The disconnect and sync tests also check a worker marker seen after acquiring the source lease. Mirror tests keep a valid native control and refuse a worker marker both at discovery and after discovery. Background sync tests verify all three write paths preserve native behavior and refuse the same registration after it gains a worker marker. Retirement tests check the worker marker before deleting documents and again before clearing the retirement request. The analyzer corpus was regenerated. Store tests verify that protected reads preserve a valid selection, reject mixed selections, and keep the raw config when the decoder cannot read it. A valid native source remains readable beside that worker record. The full sync request tests cover native writes and refusal when the registration changes to worker history before the lease is acquired. The ClickHouse fixture now covers a namespace containing only damaged worker history, with a separate connection as a control. On 30d1597, Ruff, the function-length gate, strict mypy, and 571 focused tests passed. The generated analyzer corpus matched all 2,315 checked-in shapes. The ClickHouse analyzer and storage suites run in hosted CI.

AI assistance in the code

  • AI-generated with Codex. Checked source decoding, scope predicates, restore refusal and the generated analyzer diff.

  • I can explain every line of this diff and how it interacts with the rest of Loom.

Checklist

  • Local format, lint, type checks and focused tests pass.
  • Analyzer shapes were regenerated from the statement builders.
  • Commits are signed off.

Note

High Risk
Touches connected-account erasure, restore, census, and source lifecycle gates—mistakes could leave residue, skip cleanup, or mutate worker history incorrectly.

Overview
Introduces worker source history as a first-class lifecycle: MCP/worker rows are detected via is_worker_source, keep raw config_json/items_json on inactive rewrites (WorkerSourceHistory), and use shared ClickHouse predicates (WORKER_HISTORY, source_account_match) for census, erasure, restore inventory, and connected-owner queries.

Native paths now refuse or skip worker rows: account disconnect/revoke, source remove/update/sync/rotate, namespace deactivation, mirror active_sources, and retirement/sync background jobs either block, hide API details, or stop writes when a worker marker is present. Sync uses current_native_source so turns do not update state for worker registrations.

Restore and cleanup: deployment restore errors if worker history exists without worker-aware handling; worker slot restore routes through worker_connection_id. Partially damaged worker markers remain visible for scoped erasure while native connected inventory explicitly excludes them.

Tests and analyzer shapes were extended for worker metadata, erasure predicates, and integration fixtures.

Reviewed by Cursor Bugbot for commit 30d1597. 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 Nov 27, 2026 12:25am UTC
loom-telemetry Ready Ready Preview Nov 27, 2026 12:25am 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.

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