Skip to content

feat(sinex): durable publication-obligation ledger and transport contract - #2873

Merged
Sinity merged 4 commits into
masterfrom
feature/feat/sinex-publication-obligation
Jul 14, 2026
Merged

Sinity merged 4 commits into
masterfrom
feature/feat/sinex-publication-obligation

Conversation

@Sinity

@Sinity Sinity commented Jul 14, 2026

Copy link
Copy Markdown
Owner

Summary

Implements the Polylogue-side half of polylogue-303r.2 ("Publish Sinex
materials and anchored observations with durable retry"): a durable
source.db publication-obligation ledger, a transport contract modeled on
Sinex's documented DurableEmissionReceipt/RawEnvelopeSettlement
primitives, an orchestration service, and a real adapter from live archive
Session reads into the already-shipped material_protocol.v1 encoder
(polylogue-303r.1). Defaults to off (zero transport work, zero obligation
writes) — standalone SQLite remains the permanent, canonical mode.

Problem

Before this PR, no Python code implementing any Sinex producer existed in
Polylogue — docs/sinex-interop.md's "low-volume bridge event" was aspirational
doc text with no implementation, confirmed by grep -rli sinex polylogue/ --include='*.py' turning up only material_protocol and doc references.
303r.2 needs the Polylogue side of a durable publish path: stage material
bytes, wait for a real receipt, and only then let a local projection treat
a revision as confirmed — with off/mirror/primary mode gating, crash-safety
between the local commit and the transport attempt, and idempotent retry.

Solution

polylogue/sinex/ (new package, 6 modules):

  • models.py — PublicationMode (off/mirror/primary), ObligationStatus,
    and ReceiptState. ReceiptState.unlocks_progress() only returns true for
    PersistedConfirmed/DurableDebt/SpoolAcceptedLossless, mirroring
    sinex-r6d.11's documented rule that a bare in-memory/NATS-publish accept
    must never be mistaken for a durable commit.
  • obligations.py — CRUD over sinex_publication_obligations, operating on
    a caller-supplied sqlite3.Connection so obligation creation composes
    into the same transaction as the revision it covers (design requirement).
  • transport.py — the SinexTransport protocol, NullTransport (off mode:
    any call is a loud TransportUsedInOffModeError, never a silent no-op),
    and LocalReferenceTransport — a contract-faithful in-process double with
    injectable fault points for crash/rejection/debt scenarios.
  • service.py — PublicationService: stage → attempt → mark, lag()/
    pending() for mirror-mode lag reporting, and an on_confirmed callback
    that fires only when a receipt actually unlocks progress.
  • material_adapter.py — builds a real SessionMaterial from a live
    Session domain read using the real Origin/Role/BlockType enums and
    native_id_from_session_id; lineage/usage/session-events are a declared
    gap (a FidelityGapInput names the omission), not silently dropped.

polylogue/storage/sqlite/: additive migration 010 adds
sinex_publication_obligations (source.db v9 → v10), keyed by
(object_id, protocol_version, revision_id, manifest_digest) — that 4-tuple
is both the SQL primary key and the transport idempotency key.

polylogue/config.py: new sinex_mode config key ([sinex] mode in
polylogue.toml, env POLYLOGUE_SINEX_MODE), default off.

Drive-by fix (polylogue/cli/commands/config.py): polylogue config --format json corrupted its own output whenever a config-inventory
description was long enough to exceed Rich's console width — console.print
without soft_wrap=True inserts a literal newline mid-line, turning a JSON
string into invalid JSON. sinex_mode's description was the first entry
long enough to trigger it (confirmed via a minimal, isolated
rich.console.Console reproduction before and after the fix), but the bug
predates this PR and would have hit the next long description regardless.

Rejected / deferred

Not implemented, per explicit upstream blocker (documented in
docs/sinex-interop.md and the package docstring): live Sinex JetStream
transport. As of this PR, sinex-4j2.1.1 (the Sinex-side consumer for this
exact contract) has not merged, and sinex-r6d.11 itself (the
DurableEmissionReceipt primitive the contract targets) is still open
upstream — there is no real endpoint to integrate against yet. This ships
wired to LocalReferenceTransport by default; pointing a real deployment at
live Sinex transport is cross-repo follow-up once those land. Full
end-to-end wiring into the live daemon ingest hot path (materializing every
changed session automatically) is also deferred — this PR delivers the
obligation/transport contract plus a real, callable staging path over live
archive data, not automatic background publication.

Verification

devtools test tests/unit/sinex -> 24 passed
devtools test tests/unit/storage/test_durable_migrations.py -> 33 passed
devtools test tests/unit/cli/test_config_command.py -> 10 passed
devtools test tests/unit/core/test_config.py tests/unit/core/test_config_inventory.py -> 100 passed
mypy polylogue tests/unit/sinex -> Success: no issues found in 947 source files
ruff format --check / ruff check (touched files) -> clean
devtools verify --quick -> 15/15 steps ok, exit_code 0 (also re-ran clean via the pre-push hook)
devtools render topology-projection && devtools render topology-status -> new polylogue/sinex/* modules owner=stable

Not run: devtools verify --all / the heavy CI test suite (skipped per-PR
by design; runs post-merge on master per this repo's CI policy).

Ref polylogue-303r.2.

Sinity added 3 commits July 14, 2026 02:38
Problem: polylogue-303r.2 needs a durable place to record that a
normalized-session material revision must reach Sinex before backed-mode
local projections may treat it as authoritative. The obligation row must
survive a crash between the local evidence commit and the transport
attempt, so it belongs in source.db (durable), not the disposable ops.db.

What changed: adds `sinex_publication_obligations` (source.db v9 -> v10,
additive migration 010) keyed by (object_id, protocol_version, revision_id,
manifest_digest) -- that 4-tuple is both the SQL primary key and the
transport idempotency key. Extends the existing durable-migration test
chain (v1/v2/v3/v7 fixtures) through the new version and adds direct
coverage that the migrated table accepts real inserts.

Verification: devtools test tests/unit/storage/test_durable_migrations.py
-> 33 passed. mypy --strict polylogue/storage clean on the touched files.
…tract

Problem: polylogue-303r.2 needs a real Polylogue-side producer for
Sinex-backed evidence mode that stages exact material bytes, publishes
anchored observations, and only advances a local projection after a
receipt actually unlocks progress -- replacing the never-implemented
metadata-only bridge (no Python code existed for it before this).

What changed: `polylogue/sinex/` adds
  - `models.py`: PublicationMode (off/mirror/primary), ObligationStatus,
    and ReceiptState modeled on Sinex's documented DurableEmissionReceipt
    (sinex-r6d.11) -- only PersistedConfirmed/DurableDebt/
    SpoolAcceptedLossless unlock progress, never a bare RawAccepted;
  - `obligations.py`: CRUD over the source.db obligation ledger, operating
    on a caller-supplied connection so obligation creation composes into
    the same transaction as the revision it covers;
  - `transport.py`: the `SinexTransport` protocol, `NullTransport` (off
    mode: any call is a loud bug, never a silent no-op), and
    `LocalReferenceTransport` (a contract-faithful in-process double with
    injectable fault points for crash/rejection/debt scenarios);
  - `service.py`: `PublicationService` orchestrates stage -> attempt ->
    mark, exposes `lag()`/`pending()` for mirror-mode lag reporting, and
    fires `on_confirmed` only when a receipt unlocks progress;
  - `material_adapter.py`: builds a real `SessionMaterial` from a live
    archive `Session` read, feeding the already-shipped material_protocol
    v1 encoder (polylogue-303r.1) with real ids/enums; lineage/usage/
    session-events are declared, not silently dropped (a FidelityGapInput
    names the omission).

`polylogue.toml`'s `[sinex] mode` (config key `sinex_mode`, env
`POLYLOGUE_SINEX_MODE`) defaults to `off`: zero transport work, zero
obligation writes, standalone SQLite remains canonical (operator
directive, docs/sinex-interop.md).

Scope/blocker (documented in docs/sinex-interop.md and the package
docstring): as of this PR, live Sinex JetStream transport is not
reachable -- sinex-4j2.1.1 (the Sinex-side consumer for this exact
contract) has not merged, and sinex-r6d.11 itself (the receipt primitive
the contract targets) is still open upstream. This package ships wired to
`LocalReferenceTransport` by default; pointing it at real Sinex transport
is cross-repo follow-up once those land.

Drive-by fix (discovered via this change): `polylogue config --format
json` corrupted its own output when any config inventory description
was long enough to exceed Rich's console width -- `console.print` without
`soft_wrap=True` inserts a literal newline mid-line, breaking a JSON
string into invalid JSON. Confirmed via direct Console reproduction
before and after the fix. `sinex_mode`'s description was the first entry
long enough to trigger it, but the bug preceded this change.

Verification:
  devtools test tests/unit/sinex -> 24 passed
  devtools test tests/unit/cli/test_config_command.py -> 10 passed
  devtools test tests/unit/core/test_config.py tests/unit/core/test_config_inventory.py -> 100 passed
  mypy --strict polylogue/sinex -> Success: no issues found in 6 source files
  ruff format --check / ruff check polylogue/sinex tests/unit/sinex -> clean
  devtools render topology-projection && devtools render topology-status (new modules owner=stable)

Ref polylogue-303r.2.
devtools verify --quick runs mypy --strict across the whole tree, not just
polylogue/ -- two test-only typing issues slipped past the earlier
`mypy polylogue/sinex`-scoped check:
  - dataclasses.replace(base, **overrides) with a dict[str, str] loses the
    per-field type information replace() needs; switched to explicit
    dataclasses.replace(base, field=value) calls per variant.
  - Message(role="user"/"assistant") passed plain str where the declared
    type is Role; the pydantic validator coerces it at runtime but mypy
    checks the static signature. Pass Role.USER/Role.ASSISTANT directly.

Verification: mypy polylogue tests/unit/sinex -> Success: no issues found
in 947 source files. devtools test tests/unit/sinex -> 24 passed.
devtools verify --quick -> 15/15 steps ok, exit_code 0.
@coderabbitai

coderabbitai Bot commented Jul 14, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

@Sinity, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 11 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: bd01a12b-1643-4822-bb57-72b63b3c4408

📥 Commits

Reviewing files that changed from the base of the PR and between 031d8d1 and 967a4b8.

📒 Files selected for processing (23)
  • docs/architecture.md
  • docs/plans/topology-target.yaml
  • docs/schema.md
  • docs/sinex-interop.md
  • docs/topology-status.md
  • polylogue/cli/commands/config.py
  • polylogue/config.py
  • polylogue/sinex/__init__.py
  • polylogue/sinex/material_adapter.py
  • polylogue/sinex/models.py
  • polylogue/sinex/obligations.py
  • polylogue/sinex/service.py
  • polylogue/sinex/transport.py
  • polylogue/storage/sqlite/archive_tiers/source.py
  • polylogue/storage/sqlite/migrations/source/010_sinex_publication_obligations.sql
  • tests/unit/core/test_config_inventory.py
  • tests/unit/sinex/__init__.py
  • tests/unit/sinex/test_material_adapter.py
  • tests/unit/sinex/test_models.py
  • tests/unit/sinex/test_obligations.py
  • tests/unit/sinex/test_service.py
  • tests/unit/sinex/test_transport.py
  • tests/unit/storage/test_durable_migrations.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/feat/sinex-publication-obligation

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Problem: reviewer of PR #2873 found that flipping [sinex] mode /
POLYLOGUE_SINEX_MODE to mirror/primary has zero observable effect --
no ingest, daemon, or CLI code path constructs a PublicationService
from config.sinex_mode. That is exactly the "configured failure as
silent no-op" anti-pattern polylogue.sinex's own design principle
rejects, and docs/sinex-interop.md, docs/architecture.md, and the
package docstring all implied more wiring exists than actually does
(e.g. "ships wired to a local reference transport", "mode ... gates
whether a revision gets a durable obligation row").

What changed:
- config.py: config_diagnostics() now emits a loud
  sinex_mode_not_yet_wired warning (mirror/primary configured but
  unconsumed) or sinex_mode_unrecognized error (typo'd value),
  surfaced through the already-reachable `polylogue config --format
  json` / effective_config_payload() diagnostics array. off mode
  stays silent. The _CONFIG_INVENTORY entry's reload_behavior is
  corrected from the unverifiable "daemon-loop" to "unwired", and its
  description states the gap explicitly.
- docs/sinex-interop.md, docs/architecture.md,
  polylogue/sinex/__init__.py: corrected claims that implied
  config.sinex_mode is consumed by a real (even if reference-only)
  call site; now state plainly that no production call site exists
  yet and point at the new diagnostic.
- tests/unit/core/test_config_inventory.py: 4 new tests proving the
  diagnostic fires for mirror mode, fires for an unrecognized value,
  and stays silent for off/default -- mutation check: reverting
  sinex_mode to "off" or removing the _sinex_mode_diagnostics() call
  makes test_effective_config_payload_reports_sinex_mode_not_yet_wired
  fail.

Deliberately NOT done (deferred, see polylogue-303r.2 notes): wiring
an actual PublicationService construction into ingest/daemon/CLI. That
is real production write-path work (staging obligations on every
material revision) that the bead's own notes already scope as
follow-up to 303r.2, not something to improvise inside a fix round;
live Sinex transport remains separately blocked on unmerged upstream
sinex-4j2.1.1 / sinex-r6d.11.

Verification:
- devtools test tests/unit/core/test_config_inventory.py -> 15 passed
- devtools test tests/unit/sinex tests/unit/cli/test_config_command.py -> 34 passed
- devtools verify --quick -> 15/15 steps, exit 0

Ref polylogue-303r.2

Co-Authored-By: Claude <[email protected]>
@Sinity

Sinity commented Jul 14, 2026

Copy link
Copy Markdown
Owner Author

Fix round addressing the reviewer's major finding (unwired sinex_mode config key producing zero observable effect):

  • config.py: config_diagnostics() now emits a sinex_mode_not_yet_wired warning when sinex_mode is mirror/primary (unconsumed by any code path today) and a sinex_mode_unrecognized error for typo'd values, surfaced through the already-reachable polylogue config --format json diagnostics array. off mode stays silent. Corrected the inventory entry's reload_behavior from the unverifiable "daemon-loop" to "unwired" and expanded its description to state the gap explicitly.
  • docs/sinex-interop.md, docs/architecture.md, polylogue/sinex/__init__.py: corrected wording that implied config.sinex_mode is already consumed by a real (even reference-only) call site -- now state plainly that no production call site exists yet and point at the new diagnostic.
  • tests/unit/core/test_config_inventory.py: 4 new tests proving the diagnostic fires for mirror, fires for an unrecognized value, and stays silent for off/default.

Deliberately not done: wiring an actual PublicationService construction into ingest/daemon/CLI. That's real production write-path work (staging obligations on every material revision), already scoped as follow-up under polylogue-303r.2's own notes ("full automatic wiring into the live daemon ingest hot path" listed as "Not attempted"), not something to improvise inside a fix round. Live Sinex transport remains separately blocked on unmerged upstream sinex-4j2.1.1 / sinex-r6d.11.

Verification:

  • devtools test tests/unit/core/test_config_inventory.py -> 15 passed
  • devtools test tests/unit/sinex tests/unit/cli/test_config_command.py -> 34 passed
  • devtools verify --quick -> 15/15 steps, exit 0

Ref polylogue-303r.2

@Sinity
Sinity merged commit d4a2be2 into master Jul 14, 2026
2 checks passed
@Sinity
Sinity deleted the feature/feat/sinex-publication-obligation branch July 14, 2026 08:11
Sinity added a commit that referenced this pull request Jul 14, 2026
## Summary

Closes three small pieces of independent-reviewer-flagged residual debt
from Wave 1's merged clusters (excision #2875, raw-identity #2877, sinex
evidence mode #2873). Done directly, without a separate
implementer/reviewer Workflow round, per operator instruction.

## Problem

Each item is a real gap an independent adversarial reviewer found in an
already-merged PR:

- **polylogue-re4a**: the excision-bypass regression test routed through
the pre-existing small-payload gate, never touching the new streaming
blob-ref gate it claimed to prove.
- **polylogue-iwth**: (1) the operator-judgment-guard test asserted only
fields that are deterministically identical whether or not the guard
fires, so it would pass even with the guard removed; (2)
`repair_duplicate_raw_identity`'s apply path skipped `RebuildLease`,
unlike its sibling actuators.
- **polylogue-ihwv**: sinex_mode's own fix was independently re-verified
correct (existing targeted tests green); two residual nits:
`material_adapter.py` silently dropped unrecognized blocks without
declaring a fidelity gap, and `ObligationStatus.PUBLISHING` was declared
but never written.

## Solution

- `tests/unit/sources/test_live_batch_support.py`: patch
`_STREAMING_FULL_INGEST_BYTES` down to 1 (existing pattern in this file)
so the excised/normal fixtures route through the blob-ref write path.
Verified as a genuine anti-vacuity check with an in-memory `mock.patch`
on `is_blob_hash_excised` (not a file edit to the production gate — the
auto-mode classifier correctly blocked that as a security-weakening
action).
- `tests/unit/storage/test_browser_capture_origin_repair.py` +
`polylogue/storage/repair.py`: added an `updated_at_ms`-unchanged
assertion — the one field `upsert_assertion`'s `ON CONFLICT` always
moves regardless of the guard, so it's the only observable proof the
guard short-circuited before writing. Verified as a genuine negative
control with an in-memory mock (side_effect returning `None` only for
the guard's own read, real behavior otherwise) — bypassing the guard
moves `updated_at_ms` as predicted. Wrapped
`repair_duplicate_raw_identity`'s apply block in
`RebuildLease(archive_root)`.
- `polylogue/sinex/material_adapter.py` + test:
`session_material_from_session` now emits a
`FidelityGapInput(gap_kind="dropped_block")` per dropped block. Extended
the existing fixture's assertions (it already had a
`"not-a-real-block-type"` block commented "must be dropped, not raise").
- `polylogue/sinex/obligations.py` + `service.py` + test: added
`mark_publishing()`, a pre-attempt transition distinct from
`mark_attempt` (no attempt_count/receipt outcome yet).
`PublicationService._attempt` now durably marks the obligation
`PUBLISHING` immediately before the transport call, in its own short
transaction, so a crash mid-attempt is now observably distinguishable
from a never-tried `pending` row — consistent with `pending()`/`lag()`
already including `PUBLISHING` in their filters.

## Verification

- `devtools test tests/unit/sources/test_live_batch_support.py -k
test_full_ingest_skips_durably_excised_content_without_aborting_batch` —
1 passed
- `devtools test
tests/unit/storage/test_browser_capture_origin_repair.py -k
test_record_conflict_blockers_never_clobbers_an_operator_judged_row` — 1
passed
- `devtools test
tests/unit/storage/test_duplicate_raw_identity_repair.py` — 13 passed
- `devtools test tests/unit/sinex/` — 25 passed
- `devtools verify --quick` — exit 0, all 16 steps green

Ref polylogue-re4a. Ref polylogue-iwth. Ref polylogue-ihwv.
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.

1 participant