Repository navigation
fix(bearer-gh): coalesce monitor gist reads - #537
Merged
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR reduces duplicate GitHub Gist GET traffic in the GhBearer monitor receive path by introducing a short, per-user on-disk cache for recv_stream reads, intended to coalesce same-machine polling across multiple local agents while keeping write/verify behavior unchanged.
Changes:
- Add a per-user, cross-process cache for
gh api GET gists/<id>results used by the recv polling path, tunable viaAIRC_GH_GET_CACHE_SEC/AIRC_GH_GET_CACHE_DIR. - Route
GhBearer.recv_stream()through the cached GET helper while leaving send/patch/verify paths on fresh GitHub reads. - Extend unit tests to validate cache coalescing behavior and isolate caching effects in existing rate-limit tests.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| lib/airc_core/bearer_gh.py | Adds cache TTL/path/load/save helpers and uses cached GETs in recv_stream. |
| test/test_bearer.py | Adds a cache coalescing unit test and disables the cache in an existing secondary-rate-limit test for isolation. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+15
to
+20
| before same-machine coalescing. A short per-user cache merges concurrent | ||
| monitor reads for the same gist so four local agents do not all spend a | ||
| GitHub request on the same payload. ETag conditional GETs are a future | ||
| optimization (saves bytes, still counts toward primary rate limit per gh | ||
| docs); deferred until rotation pressure makes the read payload large | ||
| enough that bandwidth matters. |
Comment on lines
+208
to
+212
| def _save_cached_get(gist_id: str, gist: dict) -> None: | ||
| path = _get_cache_path(gist_id) | ||
| directory = os.path.dirname(path) | ||
| tmp = f"{path}.{os.getpid()}.tmp" | ||
| try: |
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.
Summary
AIRC_GH_GET_CACHE_SECand isolated in tests withAIRC_GH_GET_CACHE_DIRWhy
Windows observed the same gist fetched repeatedly in the governor audit. The governor prevents rate-limit damage, but duplicate monitor polling still wastes budget. This reduces the hot read path at the bearer adapter layer instead of adding more retries.
Validation
python3 -m py_compile lib/airc_core/bearer_gh.py test/test_bearer.pycd test && python3 -m unittest test_bearer.GhBearerRecvTests.test_recv_get_cache_coalesces_same_gist_reads test_bearer.GhBearerRecvTests.test_recv_yields_new_lines_per_poll test_bearer.GhBearerRecvTests.test_recv_handles_get_failures_by_polling_again test_bearer.GhBearerLocalBusTests.test_send_reports_delivered_when_gh_is_rate_limited_but_local_bus_wrotepython3 test/test_bearer.py./test/integration.sh python_units