Skip to content

fix(selfhost): expose queue snapshots on bindings - #1973

Merged
JSONbored merged 1 commit into
mainfrom
codex/fix-self-host-regate-backpressure-issue
Jul 1, 2026
Merged

fix(selfhost): expose queue snapshots on bindings#1973
JSONbored merged 1 commit into
mainfrom
codex/fix-self-host-regate-backpressure-issue

Conversation

@JSONbored

Copy link
Copy Markdown
Owner

Motivation

  • The self-host backlog guard reads snapshot() from env.JOBS, but the actual self-host JOBS binding only exposed send()/sendBatch(), so backlog introspection always returned empty and regate backpressure never applied.

Description

  • Add snapshot() to the SQLite and Postgres queue binding objects so production env.JOBS exposes introspection directly (src/selfhost/sqlite-queue.ts, src/selfhost/pg-queue.ts).
  • Rewire the durable queue wrappers to reuse the binding's snapshot() implementation (snapshot: binding.snapshot) so wrapper and binding behavior are identical.
  • Use type-safe casts for the binding shape to expose the new snapshot() method while keeping the external Queue surface compatible.
  • Extend unit tests to assert queueSnapshotFromBinding(q.binding) returns the same snapshot as the durable wrapper: tests updated in test/unit/selfhost-sqlite-queue.test.ts and test/unit/selfhost-pg-queue.test.ts.

Testing

  • Ran unit tests for the modified areas with npx vitest run test/unit/selfhost-sqlite-queue.test.ts test/unit/selfhost-pg-queue.test.ts test/unit/selfhost-queue-common.test.ts, and all ran green (3 files, 118 tests passed).
  • Ran npm run typecheck and the TypeScript build passed with no errors.
  • Attempted full local gate git diff --check && npm run test:ci, but the run was blocked by environment/network related issues: actionlint setup could not reach GitHub (DNS/EAI_AGAIN) and the WASM fallback flagged runner labels, so the full CI sequence did not complete locally.
  • npm audit --audit-level=moderate failed due to registry access (403 Forbidden) and npm run test:coverage was started but did not complete in this environment; both are environment-blocked rather than regressions in the change.

Codex Task

@loopover-orb

loopover-orb Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Tip

🟩🟩🟩🟩🟩🟩🟩🟩🟩🟩🟩🟩

✅ Gittensory review result - approve/merge recommended

Review updated: 2026-07-01 06:17:06 UTC

4 files · 1 AI reviewer · no blockers · readiness 86/100 · CI green · clean

✅ Suggested Action - Approve/Merge

  • safe to merge

Review summary
The change moves the existing self-host queue snapshot query onto the runtime binding and has the durable wrapper delegate to that same method, which matches the stated backpressure/introspection bug. The SQLite and Postgres implementations preserve the prior snapshot query and add tests that exercise `queueSnapshotFromBinding(q.binding)`, so the visible production path is wired correctly. The main remaining weakness is test precision: the Postgres test proves equivalent output from two mocked queries, but not that the wrapper and binding are intentionally sharing the same implementation.

Nits — 4 non-blocking
  • nit: test/unit/selfhost-pg-queue.test.ts:1341 duplicates the mocked result for `q.snapshot()` and `queueSnapshotFromBinding(q.binding)`, so the test would still pass if the wrapper kept a separate but equivalent query instead of delegating through `snapshot: binding.snapshot`.
  • nit: src/selfhost/pg-queue.ts:530 and src/selfhost/sqlite-queue.ts:476 rely on widened casts for the augmented binding shape; consider introducing a local `SelfHostQueueBinding` type to make the `snapshot()` extension explicit at the boundary.
  • In test/unit/selfhost-pg-queue.test.ts:1359, add a focused assertion such as `expect(q.snapshot).toBe(q.binding.snapshot)` if the intended contract is that the durable wrapper reuses the binding implementation exactly.
  • In src/selfhost/pg-queue.ts:527 and src/selfhost/sqlite-queue.ts:473, factor the augmented binding type into a named local/exported type so future self-host bindings do not have to rediscover the `Queue & { snapshot(...) }` cast pattern.
Signal Result Evidence
Code review ✅ No blockers 1 reviewer
Linked issue ⚠️ Missing No linked issue or no-issue rationale found.
Related work ✅ No active overlap found No same-issue or scoped active PR overlap found.
Change scope ✅ 20/20 Low review scope from cached public metadata (size label size:M; no linked issue context).
Validation posture ✅ 25/25 PR body includes validation/test evidence.
Contributor workload ✅ 10/10 Author activity: 68 registered-repo PR(s), 58 merged, 209 issue(s).
Contributor context ✅ Confirmed Gittensor contributor JSONbored; Gittensor profile; 68 PR(s), 209 issue(s).
Gate result ✅ Passing No configured blocker found.
Review context
  • Author: JSONbored
  • Role context: owner (maintainer lane)
  • Public audience mode: oss maintainer
  • Lane context: Repository registration is not available in the local Gittensory cache.
  • Public profile languages: not available
  • Official Gittensor activity: 68 PR(s), 209 issue(s).
  • PR-specific overlap: none found.
Contributor next steps
  • Treat this as maintainer-lane context rather than normal contributor-lane activity.
  • Explain no-issue PR.
  • Triage stale or unlinked PRs.
  • No action.
  • Link the issue being solved, or explicitly explain why this is a no-issue PR.
Signal definitions
  • Related work = same linked issue, overlapping active PRs, or title/path similarity.
  • Change scope = cached public metadata such as size labels, draft state, and review-burden hints.
  • Validation posture = whether the PR provides enough public validation/test evidence for maintainer review.
  • Contributor workload = public contributor activity and cleanup pressure, not a repo-wide quality failure.
  • Contributor context = public GitHub/Gittensor identity context; non-Gittensor status is not a blocker.

🟩 Safe / merged · 🟦 Advisory · 🟨 Held for review · 🟥 Blocked / closed


💰 Earn for open-source contributions like this. Gittensor lets GitHub contributors earn for the work they already do — register to start earning →.

Checked by Gittensory, a quiet PR intelligence layer for OSS maintainers.

  • Re-run Gittensory review

@loopover-orb loopover-orb Bot added gittensor gittensor:bug Gittensor-scored bug fix — scores a 0.05x multiplier. labels Jul 1, 2026
@codecov

codecov Bot commented Jul 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.57%. Comparing base (9e2f533) to head (236a722).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1973   +/-   ##
=======================================
  Coverage   95.57%   95.57%           
=======================================
  Files         218      218           
  Lines       24257    24257           
  Branches     8795     8795           
=======================================
  Hits        23184    23184           
  Misses        436      436           
  Partials      637      637           
Files with missing lines Coverage Δ
src/selfhost/sqlite-queue.ts 99.19% <100.00%> (ø)
🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@JSONbored JSONbored self-assigned this Jul 1, 2026
@JSONbored
JSONbored merged commit be006e8 into main Jul 1, 2026
13 checks passed
@JSONbored
JSONbored deleted the codex/fix-self-host-regate-backpressure-issue branch July 1, 2026 06:48
@github-project-automation github-project-automation Bot moved this from Todo to Done in gittensory - v1 roadmap Jul 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gittensor:bug Gittensor-scored bug fix — scores a 0.05x multiplier.

Projects

No open projects
Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant