Repository navigation
A project's documents sync from the tracker's document store - #245
Merged
Merged
Conversation
zlareb1
force-pushed
the
feat/knowledge-source-tracker-docs
branch
2 times, most recently
from
November 4, 2026 01:49
dcfa892 to
2618653
Compare
8 of 9 tasks
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
force-pushed
the
feat/knowledge-source-tracker-docs
branch
from
November 4, 2026 02:21
9ad3dac to
3a6ddeb
Compare
This was referenced Nov 4, 2026
Merged
8 of 9 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related: #235
Changelog category (leave one):
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.addwithkind: "linear",config: {"project_ids": [...]}and a read-only API key); theknowledge_source_syncworker 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 asworker: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 inAuthorizationas it is (the API's personal keys take noBearerprefix), 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 untilhasNextPageis false, half a second between pages (PAGE_PACE_S);document(id) { id content updatedAt url }for one changed document, its answer read up toLOOM_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.typeandextensions.codeare read as well as the status: a429or any error typedratelimited(RATELIMITED) isRateLimited; a401or anauthentication errorisCredentialRefused; a message startingEntity not found(how the API answers an id the key cannot see) isNotFound, and only that: an answer that merely lacks theprojectordocumentobject is aLinearError(no_project,no_document), never evidence of absence, so such a lookup retires nothing and such a fetch waits; anything else with an error isLinearErrorwith 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 withoutpageInfo, 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, theRATELIMITEDcode with HTTP 429,first/after/pageInfopaging with a default page of 50, archived documents left out of connections by default,Document.contentbeing 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 refusesadd,rotateandcheckwithSOURCE_UNREACHABLE, a refused key withCREDENTIAL_REFUSED.documentscounts the first page of each project andmoresays 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 isBAD_CONFIG.Turn (
server/knowledge/app/source_sync_linear.py, dispatched by kind fromsource_sync._sync_one; the pass, bounds, leases, waits and state stay insource_sync):full(the first turn, a full request, the daily one) keeps only its role of granting given-up documents their retry.updatedAt) and address is skipped without a fetch. A changed one is fetched on its own and written throughknowledge.upsertwithingested_format: markdownand no original. Its address is itsurlwithout 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).failedand 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
contentin 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 issync_itemwith the folder's own checks (extractor served, listed size) asbefore_fetch, its write iswrite_documentwith the bytes and the extraction coverage, and its removal isretire_absentwith the folder lookup (_file_gone) asgone;tests/unit/test_knowledge_source_sync.pypasses 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 (fcarriesid,name,modifiedTime) through the shared sequence (no https address, unchanged skip, given-up skip, another writer's address, the kind's ownbefore_fetchchecks, the pass bound, thenfetch_and_write()answeringwritten/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 andknowledge.upsertevery kind writes with;retire_absent(src, listed, gone, run, turn): removal from a complete listing, with the kind's owngone(id)lookup (True gone, False no evidence, None stop);retire(src, uri),client_error(e)._repo_tag,_waiting,_may_writeand_WAIT_PASSESstay 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 onsource_sync. Besides that:KINDSand oneparse_configbranch, onePROBESentry, wire descriptions that named one kind, and the docs.Scope and risk
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 indocs/architecture/security.md, generated SDK and reference text.(org, namespace).Compatibility, rollout and rollback
knowledge.source.addacceptskind: "linear"; no field added or removed. Descriptions ofkind,config,credentialand the probe counts name the new kind.linearsource 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 recordscredential_invalidfor that turn without fetching or retiring anything; N's next turn records the real state. A build N-1knowledge.source.rotateof alinearsource and a build N-1knowledge.source.checkof one both answer 500 (N-1's probe table has nolinearentry, aKeyError); a build N server answers both. The worker is off by default.LOOM_KNOWLEDGE_SOURCE_SYNC_ENABLED.linearsources and their synced documents; the reverted worker treats them as above, andknowledge.source.removeretires 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 oftest_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 +RATELIMITEDand a plain 429 each end the turnrate_limited; a rate limit on a fetch stops the turn; an authentication error iscredential_invalid; a partial answer, a next page without a cursor or with the same one, and a page withoutpageInfoare 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 withrate_limitedorcredential_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.handle_knowledge_source_addstored the source after the probe (3 documents counted,moretrue, project ids normalised); pass 1 wrote 4 documents across 2 projects and 3 pages (knowledge.source.inspectover HTTP:ok, 4 seen, 4 changed;knowledge.get: tags, metadata, actorworker:knowledge-source-sync, classimportedinloom.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.searchfound the synced documents;knowledge.source.sync_nowaccepted the source.tests/integration/test_knowledge_sources.pyagainst 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 on261865366: 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 lintandmake typecheckpass 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 typecheckandmake test-unitpass; the integration suite passes if server behaviour changed.docs/reference/configuration.mdand thedocs/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).main; no merged migration is edited.hooks/,lib/,bin/,skills/,.mcp.json, the Codexplugin-defaults.json) bumps both plugin manifests' version, and no other open PR uses that version.npm --prefix frontend run build) and its tests pass, iffrontend/changed.docs/describe the system as it now is, and this description names any operator steps and wire changes.tests/unit/test_public_copy.py).git commit -s), as CONTRIBUTING.md asks.🤖 Generated with Claude Code