Skip to content

fix(bearer-gh): coalesce monitor gist reads - #537

Merged
joelteply merged 1 commit into
canaryfrom
codex/gh-bearer-read-coalesce
May 6, 2026
Merged

joelteply merged 1 commit into
canaryfrom
codex/gh-bearer-read-coalesce

Conversation

@joelteply

Copy link
Copy Markdown
Contributor

Summary

  • add a short per-user, cross-process cache for gh-bearer recv GETs keyed by gist id
  • keep send, batch send, and verify-after-write paths on fresh GitHub reads so write conflict behavior is unchanged
  • make the cache tunable with AIRC_GH_GET_CACHE_SEC and isolated in tests with AIRC_GH_GET_CACHE_DIR
  • document that same-machine monitor polls are coalesced so multiple local agents do not all fetch the same gist payload

Why

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.py
  • cd 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_wrote
  • python3 test/test_bearer.py
  • ./test/integration.sh python_units

Copilot AI review requested due to automatic review settings May 6, 2026 18:08
@joelteply
joelteply merged commit 5b5c2b7 into canary May 6, 2026
8 checks passed
@joelteply
joelteply deleted the codex/gh-bearer-read-coalesce branch May 6, 2026 18:09

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 via AIRC_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:
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.

2 participants