Skip to content

A project's documents sync from the tracker's document store - #245

Merged
zlareb1 merged 6 commits into
mainfrom
feat/knowledge-source-tracker-docs
Nov 4, 2026
Merged

zlareb1 merged 6 commits into
mainfrom
feat/knowledge-source-tracker-docs

Conversation

@zlareb1

@zlareb1 zlareb1 commented Nov 4, 2026 •

Copy link
Copy Markdown
Member

Related: #235

Changelog category (leave one):

  • New Feature

Changelog entry (one or two sentences a user of Loom can read without the diff; the release pull request collects these into the release notes):

A repository's maintainers can register a project tracker's projects as a document source (knowledge.source.add with kind: "linear", config: {"project_ids": [...]} and a read-only API key); the knowledge_source_sync worker writes each project's documents into the repository's documents and retires the ones the projects no longer have.

Why

The registry and the sync pass serve one kind, a shared folder. A project tracker keeps design notes as project documents, already in Markdown, and they belong beside the repository's other documents. This adds the second kind on the same contracts: a source's documents are the ones tagged source:<name> and written as worker:knowledge-source-sync, imported; trouble with one document waits for that document alone; removal needs positive evidence.

Client (server/clients/linear.py). One fixed host (https://api.linear.app/graphql), POST with the API key in Authorization as it is (the API's personal keys take no Bearer prefix), every id as a GraphQL variable, never in the query text. A key that is not printable ASCII without spaces is refused before any call; a pasted trailing newline is trimmed. Three queries:

  • project(id) { id documents(first: 50, after) { nodes { id title updatedAt url } pageInfo { hasNextPage endCursor } } }, paged until hasNextPage is false, half a second between pages (PAGE_PACE_S);
  • document(id) { id content updatedAt url } for one changed document, its answer read up to LOOM_KNOWLEDGE_SOURCE_SYNC_MAX_FILE_BYTES;
  • document(id) { id trashed archivedAt project { id } } for the removal lookup.

The API reports most failures as GraphQL errors, with HTTP 200 or 400, so each error's extensions.type and extensions.code are read as well as the status: a 429 or any error typed ratelimited (RATELIMITED) is RateLimited; a 401 or an authentication error is CredentialRefused; a message starting Entity not found (how the API answers an id the key cannot see) is NotFound, and only that: an answer that merely lacks the project or document object is a LinearError (no_project, no_document), never evidence of absence, so such a lookup retires nothing and such a fetch waits; anything else with an error is LinearError with a short reason: graphql_<type> for a typed GraphQL error whatever the status, http_<status> only for an untyped answer. An answer with any GraphQL error raises, even beside data, so a listing is never taken from a partial answer; a page that says another follows without a cursor, or with the same one, or without pageInfo, raises too. Whether a failure is a refusal (given up at once) or may pass (waits) is decided by the GraphQL error's type when there is one, since the tracker answers its internal errors with a 400 too, and by a 4xx status only when there is none. Errors carry the reason and status only, never the body.

The API shape was checked against the vendor's public GraphQL schema and developer documentation (endpoint and key header, errors[].extensions, the RATELIMITED code with HTTP 429, first/after/pageInfo paging with a default page of 50, archived documents left out of connections by default, Document.content being Markdown, trashed, archivedAt, project, url). No live credential was used.

Probe (source_probes._probe_linear). One page of every project, together; a project the key's account cannot see refuses add, rotate and check with SOURCE_UNREACHABLE, a refused key with CREDENTIAL_REFUSED. documents counts the first page of each project and more says when a project has more.

Config (parse_config). {"project_ids": [1 to 20 UUIDs]}, trimmed, lower-cased (the lookup compares a document's project with them as the API reports them) and deduplicated; any other key, a slug or a non-UUID is BAD_CONFIG.

Turn (server/knowledge/app/source_sync_linear.py, dispatched by kind from source_sync._sync_one; the pass, bounds, leases, waits and state stay in source_sync):

  • Every turn reads each project's whole document list, every page: a project's list is small, so there is no incremental listing. full (the first turn, a full request, the daily one) keeps only its role of granting given-up documents their retry.
  • A document whose stored copy has the listed revision (updatedAt) and address is skipped without a fetch. A changed one is fetched on its own and written through knowledge.upsert with ingested_format: markdown and no original. Its address is its url without the query; the link carries the title, so a renamed document is written at its new address and its old one retired (the same rule as a folder file whose link changed).
  • A document over the size bound or one the tracker refuses or no longer finds is given up on its revision at once; a 5xx, a timeout or an answer without data waits for that document for three passes; a write the store refuses is given up. A rate limit or a refused key ends the turn.
  • Removal: only when every project was read on every page is a stored document missing from the list looked up, and retired when the tracker reports it not found, trashed, archived or in none of the source's projects. A project the key cannot see, any other failure on a list page and a partial answer leave the turn failed and retire nothing, while the other projects' documents are still written. A stored document without a usable id is never looked up and never retired.

Deviation from the design it follows. The design read content in the listing itself. The listing here carries ids, titles, stamps and links only, and a changed document's content is fetched on its own: the revision skip then costs no content transfer, the size bound applies per document, a failure is that document's (the per-document wait), and the pass bound counts fetches the same way it does for a folder. A project's list is still read whole every pass, which is what makes absence evidence.

A shared interface for every kind's turn, and the folder turn moved onto it. The pieces a turn builds on are now public in server/knowledge/app/source_sync.py (in __all__). The folder turn was refactored onto them with its behaviour unchanged: its per-file sequence is sync_item with the folder's own checks (extractor served, listed size) as before_fetch, its write is write_document with the bytes and the extraction coverage, and its removal is retire_absent with the folder lookup (_file_gone) as gone; tests/unit/test_knowledge_source_sync.py passes unmodified. Other kinds rebase onto these names:

  • Pass (the pass's time and document bound), TurnResult;
  • start_waits(turn, detail), full_due(detail), capped(newest, listed_at) for a turn's start and stamp;
  • sync_item(src, f, uri, prior, run, turn, fetch_and_write, before_fetch=None): one listed item (f carries id, name, modifiedTime) through the shared sequence (no https address, unchanged skip, given-up skip, another writer's address, the kind's own before_fetch checks, the pass bound, then fetch_and_write() answering written/waiting/given_up/stop, and retirement of an old address);
  • give_up(f, turn, reason), wait(f, turn, reason, error), require_current(src) for a kind's fetch;
  • write_document(src, f, uri, content, *, ingested_format, original=b"", extra_metadata=None): the tags, metadata and knowledge.upsert every kind writes with;
  • retire_absent(src, listed, gone, run, turn): removal from a complete listing, with the kind's own gone(id) lookup (True gone, False no evidence, None stop);
  • retire(src, uri), client_error(e).

_repo_tag, _waiting, _may_write and _WAIT_PASSES stay private: only this module reads them. A kind is dispatched by _turn_of(kind) in _sync_one, which imports the kind's module lazily because that module builds on source_sync. Besides that: KINDS and one parse_config branch, one PROBES entry, wire descriptions that named one kind, and the docs.

Scope and risk

  • Touches: the new client and turn module, the shared sync helpers made public and factored (above), the probe, the config parser, KINDS, the turn dispatch, five wire field descriptions, docs/features/knowledge.md (a "Syncing a project's documents" section, the kind, config, probe and error-code text), the removal sentence in docs/architecture/security.md, generated SDK and reference text.
  • Leaves alone: the folder turn, the pass, the sync state's shape, the registry, the dashboard, issue text (issues reach Loom through the tracker plane).
  • Tenant isolation: unchanged; every statement is keyed by the source's own (org, namespace).
  • Erasure: no new table; synced documents live in the already-censused document tables.
  • Rate limits: one listing request per 50 documents per project per pass, one request per changed document and one per missing document; at the default 40 documents per pass and a 900 s interval this stays far under the API's per-key hourly limits.

Compatibility, rollout and rollback

  • Wire: knowledge.source.add accepts kind: "linear"; no field added or removed. Descriptions of kind, config, credential and the probe counts name the new kind.
  • Rolling upgrade: a linear source can only be added by a build N server. A build N-1 sync worker that meets one reads its key as a service account key and records credential_invalid for that turn without fetching or retiring anything; N's next turn records the real state. A build N-1 knowledge.source.rotate of a linear source and a build N-1 knowledge.source.check of one both answer 500 (N-1's probe table has no linear entry, a KeyError); a build N server answers both. The worker is off by default.
  • Operator steps: none. The worker still needs LOOM_KNOWLEDGE_SOURCE_SYNC_ENABLED.
  • Rollback: reverting leaves any registered linear sources and their synced documents; the reverted worker treats them as above, and knowledge.source.remove retires them.

Tests

No live vendor credential was used: every tracker response in the tests and in the run below is written by hand for the test (httpx MockTransport), never a recording of real content.

  • tests/unit/test_knowledge_source_sync_linear.py (40 cases, reusing the in-memory registry and document store of test_knowledge_source_sync.py): a first turn over two projects and three pages writes every document with its tags, metadata, actor and class; an unchanged document is not fetched; a renamed one moves; a document missing from a complete list is retired only when the lookup says not found, trashed, archived, in another project or in none, and kept when the lookup finds it in a source project; a project the key cannot see retires nothing and keeps the stamp while the other project's new document is written; a rate limit as HTTP 400 + RATELIMITED, HTTP 200 + RATELIMITED and a plain 429 each end the turn rate_limited; a rate limit on a fetch stops the turn; an authentication error is credential_invalid; a partial answer, a next page without a cursor or with the same one, and a page without pageInfo are no list; a 502 on one document waits three passes then gives up and is not fetched again; a document over the size bound is given up at once and tried again on a new revision; another writer's document is not fetched; the document bound cuts the turn; a credential that does not open calls nothing; a lookup answered without the document, with a 5xx, forbidden or an internal error retires nothing; a rate limit or an authentication error on a lookup stops the retiring with rate_limited or credential_invalid; a stored document without a usable id is never looked up or retired; a fetch answered without the document waits; a forbidden fetch (typed, with HTTP 200 or 400, or an untyped 403) is given up at once and not fetched again, while an internal error waits, with HTTP 200 or 400; the API key and the tracker's error text never reach the sync state, after a turn that runs both failing fetches and after a refused list; list pages are paced (the client's own pause, patched there).
  • tests/unit/test_linear_probe.py (20 cases): the request (host, key header without a prefix, ids as variables), counts and samples; each failure shape told apart with no body text in the error, including a project answered without its object (no_project); a key that cannot be a header and a document id that is not the tracker's are refused without a call; config parsing and its refusals.
  • tests/unit/test_knowledge_source_sync.py, test_knowledge_sources.py, test_gdrive_probe.py: unchanged and passing.
  • End to end on a private ClickHouse and server from this branch's first head (before the helpers were factored; the factoring is covered by the unchanged folder tests and the tests above), the tracker answered by a mock transport: handle_knowledge_source_add stored the source after the probe (3 documents counted, more true, project ids normalised); pass 1 wrote 4 documents across 2 projects and 3 pages (knowledge.source.inspect over HTTP: ok, 4 seen, 4 changed; knowledge.get: tags, metadata, actor worker:knowledge-source-sync, class imported in loom.documents); pass 2 fetched nothing; pass 3, after a rename, a deletion and a document dropped from the list but still in its project, wrote 1 and retired 2 (the renamed document's old address and the deleted one), kept the third; pass 4 with a project the key lost retired nothing (failed, project <id>: not_found); pass 5 rate-limited by a GraphQL error retired nothing (rate_limited); knowledge.search found the synced documents; knowledge.source.sync_now accepted the source.
  • tests/integration/test_knowledge_sources.py against that server: 8 passed.
  • make format, make lint, make typecheck (mypy gate at baseline), the generators (docs_reference, sdk_py_gen, sdk_py_client_gen, sdk_ts_gen, op_reach_census --check), test_public_copy.py, test_doc_links.py, test_package_contracts.py. The full unit suite on 261865366: 26450 passed, 20 skipped, 1 xfailed. The final head adds only tests, docs, a docstring, the kept HTTP status on a refused key and the folder turn's partials over it; the changed test files (test_knowledge_source_sync_linear.py, test_linear_probe.py, test_knowledge_source_sync.py, test_gdrive_probe.py, test_knowledge_sources.py: 236 passed), make lint and make typecheck pass on it.

AI assistance in the code (leave one; writing this description with AI is fine):

  • AI-generated (an agent wrote most of the diff): Claude Code; the error shapes, the removal evidence and the end-to-end run were checked against the vendor's public schema and the private server.

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

Checklist

  • make format-check, make lint, make typecheck and make test-unit pass; the integration suite passes if server behaviour changed.
  • Generated files are regenerated in this PR, not by hand: the SDK op tables, docs/reference/configuration.md and the docs/reference/ tables (python scripts/codegen/docs_reference.py), the reach manifest, schemas/schema.sql (make schema-dump) and the Codex plugin copies (python3 scripts/codegen/agent_plugin_sync.py).
  • A new migration is additive and numbered after the latest on main; no merged migration is edited.
  • A behaviour change to any file a plugin ships (hooks/, lib/, bin/, skills/, .mcp.json, the Codex plugin-defaults.json) bumps both plugin manifests' version, and no other open PR uses that version.
  • The frontend builds (npm --prefix frontend run build) and its tests pass, if frontend/ changed.
  • Docs under docs/ describe the system as it now is, and this description names any operator steps and wire changes.
  • Repository text has no dates, people, host names, internal namespaces, ticket or decision numbers; the history goes in this description (tests/unit/test_public_copy.py).
  • Commits are signed off (git commit -s), as CONTRIBUTING.md asks.

🤖 Generated with Claude Code

@zlareb1
zlareb1 force-pushed the feat/knowledge-source-tracker-docs branch 2 times, most recently from dcfa892 to 2618653 Compare November 4, 2026 01:49
zlareb1 and others added 6 commits November 4, 2026 02:20
A source of kind linear reads the documents of 1 to 20 projects of a project
tracker over its GraphQL API with a read-only API key. Every turn reads each
project's whole document list, skips a document whose stored revision and
address match, fetches and writes the changed ones as
worker:knowledge-source-sync, imported, tagged source:<name>, and retires a
stored document only when the list was read whole and a lookup reports it not
found, trashed, archived or in none of the source's projects.

A rate limit in any shape (a 429, or a GraphQL error typed RATELIMITED with
HTTP 200 or 400) and a refused key end the turn; a project the key cannot see,
a partial answer or a page without a cursor leave the turn failed and retire
nothing. Trouble with one document waits for that document alone, as for a
folder's files.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…lpers are shared

- An answer with no document or project object raises no_document or
  no_project, never NotFound: only the tracker's own not-found error counts
  as absence. Such a lookup retires nothing and such a fetch waits.
- List pages are paced half a second apart.
- The helpers every kind's turn builds on are public in source_sync: Pass,
  WAIT_PASSES, start_waits, full_due, capped, waiting, give_up, wait,
  may_write, require_current, client_error, and the factored sync_item (the
  skip, wait, other-writer and bound sequence for one listed item),
  write_document (tags, metadata and the upsert) and retire_absent (removal
  with a per-kind lookup). The folder turn uses them unchanged in behaviour.
- Tests cover lookups answered without the document, with a 5xx, forbidden
  or an internal error, rate-limited or refused; a stored document without a
  usable id; a refused fetch against an internal error; the key and the
  tracker's text kept out of the sync state; the page pacing.
- Docs: which GraphQL errors give a document up at once and which wait,
  no_document in the reasons, and when a deleted synced document comes back.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…tests run what they claim

- waiting, may_write and WAIT_PASSES are private again (_waiting,
  _may_write, _WAIT_PASSES): only source_sync reads them; the module
  docstring names the public helpers.
- The folder turn's lookup is a functools.partial, like the tracker turn's.
- The client pauses between pages through its own _sleep, which the pacing
  test patches instead of the process-wide asyncio.sleep.
- The key-leak test runs both failing fetches (asserted), then a refused
  list as a second pass, and checks the state after each.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
- LinearError.refused reads the GraphQL error's type when the tracker gave
  one and the 4xx status only when it gave none: the tracker answers its
  internal errors with a 400 too, and such a document now waits instead of
  being given up. The test adds a 400 internal error that waits.
- documents_page drops its unused page-size parameter.
- Docs say the type decides; a stray blank line goes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
- _raise_for labels a GraphQL error that carries a type graphql_<type> even
  on a 4xx or 5xx; http_<status> is left for an untyped answer. The test
  adds a 400 FORBIDDEN, given up as graphql_forbidden.
- The tracker section of the knowledge docs is rewrapped.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…urn uses partials

- Tests: an untyped 403 on a fetch is given up at once as http_403 and not
  fetched again; a next page with the same cursor and a page without
  pageInfo are no list.
- CredentialRefused keeps the status the tracker answered.
- LinearError's docstring says where `kind` comes from.
- The folder turn passes its fetch steps to sync_item as functools.partial,
  like the tracker turn; behaviour unchanged.
- Docs name the label of each refusal.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
@zlareb1
zlareb1 force-pushed the feat/knowledge-source-tracker-docs branch from 9ad3dac to 3a6ddeb Compare November 4, 2026 02:21
@zlareb1
zlareb1 merged commit b01d973 into main Nov 4, 2026
21 of 22 checks passed
@zlareb1
zlareb1 deleted the feat/knowledge-source-tracker-docs branch November 4, 2026 02:26
@pufit pufit mentioned this pull request Nov 4, 2026
9 tasks done
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