Generation-stamped config epochs with NATS broadcast and per-message echo for cross-pod cache reload coherence
Project description
3tears-epoch
Generation-stamped configuration epochs with NATS broadcast and per-message echo for cross-pod cache-reload coherence.
Why
Multiple in-memory configuration caches across the platform need to stay coherent across pods on admin writes:
- a model capabilities registry (registered at startup from the
modelstable) - a catalog cache (
gateway_models+gateway_providers+gateway_credit_rates) - per-tool MCP RBAC grants
Pure NATS broadcast (push) ships with a missed-message hole: a pod that didn't receive the broadcast (subscriber blip, pod just started during the window, JetStream redelivery edge) stays stale. Pure polling (pull) is correct but expensive on hot paths.
This package combines both: a strictly-monotonic generation number (epoch) per subject, durable in Postgres, broadcast best-effort via NATS, and echoed in every relevant response message so consumers detect staleness on the next read and lazy-pull. Push for speed, pull for correctness.
This is the standard pattern from etcd mod_revision + watch, K8s resourceVersion + informer, Envoy xDS version_info + ACK, DNS SOA serial + secondary refresh.
Identity
The unit of identity is the NATS subject path. Each consumer:
- Defines or uses an existing
Subjectbuilder for the configuration domain it owns (e.g.Subjects.capabilities_epoch()->capabilities.epoch). - Calls
EpochClient.bump(subject, payload=...)after committing the row mutation that motivates the reload. - Subscribes via
EpochListener.subscribe(subject, on_bump=...)from sibling pods.
The platform.config_epochs row PK is the subject path string. Postgres is the source of truth; the NATS broadcast is best-effort. A subscriber that missed every broadcast still catches up on the next request whose response echoes the higher epoch (per-message echo is consumer-side wiring; the framework supplies the building blocks).
Wire envelope
EpochBumpMessage is a frozen Pydantic v2 model:
subject_path: stris the namespaced subject the bump targets (matches the row PK)epoch: intis the new strictly-monotonic valuepayload: dict[str, Any] | Noneis an opaque hint for the consumer's reload callback (e.g.{"model_id": "...", "action": "create"})
The framework never inspects payload. Consumers parse if useful, ignore if not. The hint exists so a domain that only changes one row can avoid reloading the entire derived view.
Postgres
CREATE TABLE IF NOT EXISTS config_epochs (
subject_path TEXT PRIMARY KEY,
epoch BIGINT NOT NULL DEFAULT 0,
payload JSONB,
date_updated TIMESTAMPTZ NOT NULL DEFAULT now()
);
bump(subject, payload) runs INSERT ... ON CONFLICT (subject_path) DO UPDATE SET epoch = config_epochs.epoch + 1, payload = $2, date_updated = now() RETURNING epoch. Atomic; concurrent bumps from different writers serialize on the row lock.
Migration ships as a PLATFORM-scope PackageMigrations registration so consumers wire it via the canonical MigrationRunner alongside the rest of their platform tables.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file 3tears_epoch-0.17.7.tar.gz.
File metadata
- Download URL: 3tears_epoch-0.17.7.tar.gz
- Upload date:
- Size: 20.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9ab6ee420b885e2660056e46608f0c1ed4288a9b56c6b5a8d2762a8231cd552f
|
|
| MD5 |
57bc41c95caef8cab528bc7de07281eb
|
|
| BLAKE2b-256 |
bfed39c2493f03639c6353101e69b79f48de06c2242b7db2bbf64aa3de60a0a9
|
Provenance
The following attestation bundles were made for 3tears_epoch-0.17.7.tar.gz:
Publisher:
release.yml on pacepace/3tears
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
3tears_epoch-0.17.7.tar.gz -
Subject digest:
9ab6ee420b885e2660056e46608f0c1ed4288a9b56c6b5a8d2762a8231cd552f - Sigstore transparency entry: 2195081489
- Sigstore integration time:
-
Permalink:
pacepace/3tears@b6cd5c2bbcd6e83824561a45f359e4aaa70ac53b -
Branch / Tag:
refs/tags/v0.17.7 - Owner: https://github.com/pacepace
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@b6cd5c2bbcd6e83824561a45f359e4aaa70ac53b -
Trigger Event:
push
-
Statement type:
File details
Details for the file 3tears_epoch-0.17.7-py3-none-any.whl.
File metadata
- Download URL: 3tears_epoch-0.17.7-py3-none-any.whl
- Upload date:
- Size: 14.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3e43f6ae1c75d918848e71e16a374918c06e5f4dafa2a5c13bb803e4a0ebb8b3
|
|
| MD5 |
a634f53ae3a1a9bcd13d4fc2394d2baf
|
|
| BLAKE2b-256 |
e4f99a1f855bc264fe46527c22fcca38c85ad8e4997035ec4a262501bd8fbbb0
|
Provenance
The following attestation bundles were made for 3tears_epoch-0.17.7-py3-none-any.whl:
Publisher:
release.yml on pacepace/3tears
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
3tears_epoch-0.17.7-py3-none-any.whl -
Subject digest:
3e43f6ae1c75d918848e71e16a374918c06e5f4dafa2a5c13bb803e4a0ebb8b3 - Sigstore transparency entry: 2195081504
- Sigstore integration time:
-
Permalink:
pacepace/3tears@b6cd5c2bbcd6e83824561a45f359e4aaa70ac53b -
Branch / Tag:
refs/tags/v0.17.7 - Owner: https://github.com/pacepace
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@b6cd5c2bbcd6e83824561a45f359e4aaa70ac53b -
Trigger Event:
push
-
Statement type: