embed_docsite: replace per-directory GitHub fetch with Trees API + cache - #618
Closed
IZO-Ong wants to merge 11 commits into
Closed
embed_docsite: replace per-directory GitHub fetch with Trees API + cache#618IZO-Ong wants to merge 11 commits into
IZO-Ong wants to merge 11 commits into
Conversation
* Global chat: Add answer streaming to planner (OpenFn#573) * add segments * adjust events * add event type * adjust streaming * update readme * changeset --------- Co-authored-by: Joe Clark <jclark@openfn.org> * Bump the python-minor-patch group across 1 directory with 8 updates (OpenFn#601) Bumps the python-minor-patch group with 8 updates in the / directory: | Package | From | To | | --- | --- | --- | | [openai](https://github.com/openai/openai-python) | `2.45.0` | `2.48.0` | | [anthropic](https://github.com/anthropics/anthropic-sdk-python) | `0.116.0` | `0.119.0` | | [langchain-core](https://github.com/langchain-ai/langchain) | `1.4.9` | `1.5.1` | | [langchain-openai](https://github.com/langchain-ai/langchain) | `1.3.4` | `1.4.1` | | [sentry-sdk](https://github.com/getsentry/sentry-python) | `2.64.0` | `2.66.1` | | [langfuse](https://github.com/langfuse/langfuse) | `4.14.0` | `4.14.1` | | [opentelemetry-instrumentation-threading](https://github.com/open-telemetry/opentelemetry-python-contrib) | `0.64b0` | `0.65b0` | | [ruff](https://github.com/astral-sh/ruff) | `0.15.21` | `0.16.0` | Updates `openai` from 2.45.0 to 2.48.0 - [Release notes](https://github.com/openai/openai-python/releases) - [Changelog](https://github.com/openai/openai-python/blob/main/CHANGELOG.md) - [Commits](openai/openai-python@v2.45.0...v2.48.0) Updates `anthropic` from 0.116.0 to 0.119.0 - [Release notes](https://github.com/anthropics/anthropic-sdk-python/releases) - [Changelog](https://github.com/anthropics/anthropic-sdk-python/blob/main/CHANGELOG.md) - [Commits](anthropics/anthropic-sdk-python@v0.116.0...v0.119.0) Updates `langchain-core` from 1.4.9 to 1.5.1 - [Release notes](https://github.com/langchain-ai/langchain/releases) - [Commits](langchain-ai/langchain@langchain-core==1.4.9...langchain-core==1.5.1) Updates `langchain-openai` from 1.3.4 to 1.4.1 - [Release notes](https://github.com/langchain-ai/langchain/releases) - [Commits](langchain-ai/langchain@langchain-openai==1.3.4...langchain-openai==1.4.1) Updates `sentry-sdk` from 2.64.0 to 2.66.1 - [Release notes](https://github.com/getsentry/sentry-python/releases) - [Changelog](https://github.com/getsentry/sentry-python/blob/master/CHANGELOG.md) - [Commits](getsentry/sentry-python@2.64.0...2.66.1) Updates `langfuse` from 4.14.0 to 4.14.1 - [Release notes](https://github.com/langfuse/langfuse/releases) - [Commits](https://github.com/langfuse/langfuse/commits) Updates `opentelemetry-instrumentation-threading` from 0.64b0 to 0.65b0 - [Release notes](https://github.com/open-telemetry/opentelemetry-python-contrib/releases) - [Changelog](https://github.com/open-telemetry/opentelemetry-python-contrib/blob/main/CHANGELOG.md) - [Commits](https://github.com/open-telemetry/opentelemetry-python-contrib/commits) Updates `ruff` from 0.15.21 to 0.16.0 - [Release notes](https://github.com/astral-sh/ruff/releases) - [Changelog](https://github.com/astral-sh/ruff/blob/main/CHANGELOG.md) - [Commits](astral-sh/ruff@0.15.21...0.16.0) --- updated-dependencies: - dependency-name: openai dependency-version: 2.48.0 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: python-minor-patch - dependency-name: anthropic dependency-version: 0.119.0 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: python-minor-patch - dependency-name: langchain-core dependency-version: 1.5.1 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: python-minor-patch - dependency-name: langchain-openai dependency-version: 1.4.1 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: python-minor-patch - dependency-name: sentry-sdk dependency-version: 2.66.1 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: python-minor-patch - dependency-name: langfuse dependency-version: 4.14.1 dependency-type: direct:production update-type: version-update:semver-patch dependency-group: python-minor-patch - dependency-name: opentelemetry-instrumentation-threading dependency-version: 0.65b0 dependency-type: direct:production dependency-group: python-minor-patch - dependency-name: ruff dependency-version: 0.16.0 dependency-type: direct:development update-type: version-update:semver-minor dependency-group: python-minor-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump actions/setup-python from 6 to 7 (OpenFn#600) Bumps [actions/setup-python](https://github.com/actions/setup-python) from 6 to 7. - [Release notes](https://github.com/actions/setup-python/releases) - [Commits](actions/setup-python@v6...v7) --- updated-dependencies: - dependency-name: actions/setup-python dependency-version: '7' dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Handle routing failures (OpenFn#591) * add subagent mode and inspect tool * edits and tests * udpate subagent prompt * add navigation info * add langfuse tracing * rename inspect_workflow tool to edit_workflow * changeset * resolve conflict * update test fixtures * add coherence instruction * fix prompt for existing workflows --------- Co-authored-by: Joe Clark <jclark@openfn.org> * version: 3.1.0 --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: Hanna Paasivirta <hanna@openfn.org> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
…fresh_cache and read_docs
Collaborator
|
Hey @IZO-Ong! Before I get too into this, why are you using the Tree API and not I also think the theory behind that was to just pull the content we needed and ignore the rest. But presumably we're pulling so much content anyway that it's easier just to download it all? |
Author
|
I actually was working on this before seeing issue #182, so I was not aware of the git clone method. I was thinking about the git trees approach for a while, and I think the git clone method is probably better given that we can delegate the caching to git itself. I will probably close this PR and set up a new one with git clone, and maybe test the time taken between both of them! |
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.
Short Description
Replaces
embed_docsite's per-directory GitHub Contents API walk with a single Trees API call with an on-disk cache keyed by ETag and per-file blob SHA, cutting a full run of 20 GitHub API requests down to 1.Fixes #182
Implementation Details
github_utils.pyused to fetchdocs/andadaptors/fromOpenFn/docsby recursing into every directory via the Contents API (GET /repos/{owner}/{repo}/contents/{path}) with one request per directory, then downloading each file'sdownload_urlseparately. Against the live repo that is 20 requests (16 directories underdocs/, 4 underadaptors/) plus 191 unconditional file downloads, on every run, with no change detection. GitHub's unauthenticated limit of 60/hr therefore allowed three runs an hour, and the fourth failed without naming its cause: the rate-limit branch returned silently with an empty file list, and the caller then crashed onIndexError: list index out of range.#182 proposed fixing this with
git clone --depth 1. This PR takes a different route by using GitHub Trees API (GET /repos/OpenFn/docs/git/trees/main?recursive=1), which returns the entire file tree, path and blob SHA for every file in one request, plus a persistent on-disk cache (services/embed_docsite/docsite_cache/, gitignored) that stores the tree's ETag and each cached file's blob SHA.general_docs+adaptor_docs+adaptor_functions) now spends 1 GitHub API request. Measured against the live repo: it comes back304when nothing changed, and 0 files are re-downloaded. Only files whose blob SHA actually moved get re-fetched, fromraw.githubusercontent.com, which is not rate-limited.refresh_cache(docs_types)brings the whole corpus up to date in one conditional Trees request and runs once per run;read_docs(docs_type)then serves each docs type from disk without touching the network. Only the requested docs types are refreshed, so warming justadaptor_functionsleaves the markdown corpus alone.503 UPSTREAM_ERROR). A cached file missing from disk degrades to anApolloErrorinstead of anunhandled
FileNotFoundError, and reading an unpopulated cache raises rather than reporting the docs as empty.GITHUB_TOKEN(in.env.example) to the docs fetch, raising the limit from 60 to 5000 requests/hour.{"refresh_cache_only": true}warms the cache fordocs_to_uploadwithout needing Pinecone/OpenAI keys, for pre-warming in CI or locally.get_repo_treeraises if GitHub reports the tree astruncated(~100,000 files from Github's API). Not a concern atOpenFn/docs' current size (702 files).Tests: unit tests fully mocked (
services/embed_docsite/tests/unit/), plus integration tests over the real cached corpus (services/embed_docsite/tests/integration/test_docsite_cache_corpus.py, skipped unless the cache is warmed) which hold the read path to making no network calls at all.AI Usage
Please disclose whether you've used AI in this work (it's cool, we just want to know!):
You can read more details in our
Responsible AI Policy