Skip to content

embed_docsite: replace per-directory GitHub fetch with Trees API + cache - #618

Closed
IZO-Ong wants to merge 11 commits into
OpenFn:mainfrom
IZO-Ong:git-cache
Closed

embed_docsite: replace per-directory GitHub fetch with Trees API + cache#618
IZO-Ong wants to merge 11 commits into
OpenFn:mainfrom
IZO-Ong:git-cache

Conversation

@IZO-Ong

@IZO-Ong IZO-Ong commented Aug 7, 2026

Copy link
Copy Markdown

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.py used to fetch docs/ and adaptors/ from OpenFn/docs by recursing into every directory via the Contents API (GET /repos/{owner}/{repo}/contents/{path}) with one request per directory, then downloading each file's download_url separately. Against the live repo that is 20 requests (16 directories under docs/, 4 under adaptors/) 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 on IndexError: 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.

  • Steady-state cost: a full run (general_docs + adaptor_docs + adaptor_functions) now spends 1 GitHub API request. Measured against the live repo: it comes back 304 when nothing changed, and 0 files are re-downloaded. Only files whose blob SHA actually moved get re-fetched, from raw.githubusercontent.com, which is not rate-limited.
  • Refreshing and reading are separate: 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 just adaptor_functions leaves the markdown corpus alone.
  • Degradation: if GitHub is unreachable or rate-limited, the cached copy is served and a warning is logged; only a failure with an empty cache is fatal (503 UPSTREAM_ERROR). A cached file missing from disk degrades to an ApolloError instead of an
    unhandled FileNotFoundError, and reading an unpopulated cache raises rather than reporting the docs as empty.
  • Syncs GITHUB_TOKEN (in .env.example) to the docs fetch, raising the limit from 60 to 5000 requests/hour.
  • New mode: {"refresh_cache_only": true} warms the cache for docs_to_upload without needing Pinecone/OpenAI keys, for pre-warming in CI or locally.
  • Known limitation: get_repo_tree raises if GitHub reports the tree as truncated (~100,000 files from Github's API). Not a concern at OpenFn/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!):

  • Yes, I have used AI
  • No, I have not used AI

You can read more details in our
Responsible AI Policy

IZO-Ong and others added 11 commits July 30, 2026 10:41
* 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>
@josephjclark

Copy link
Copy Markdown
Collaborator

Hey @IZO-Ong! Before I get too into this, why are you using the Tree API and not git clone?

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?

@IZO-Ong

IZO-Ong commented Aug 12, 2026

Copy link
Copy Markdown
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!

@IZO-Ong IZO-Ong closed this Aug 12, 2026
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.

embed_docsite: use git clone to download source files from repo

2 participants