Skip to content

Add captured conflict backlog management - #2158

Open
PRAZPC wants to merge 17 commits into
ClickHouse:mainfrom
PRAZPC:feat/2077-captured-conflict-management
Open

PRAZPC wants to merge 17 commits into
ClickHouse:mainfrom
PRAZPC:feat/2077-captured-conflict-management

Conversation

@PRAZPC

@PRAZPC PRAZPC commented Dec 4, 2026 •

Copy link
Copy Markdown

<!-- Linked issues and pull requests. -->

Closes: #2077

Changelog category (leave one):

  • New Feature
  • Improvement
  • Performance Improvement
  • Backward Incompatible Change
  • Bug Fix (user-visible misbehavior in a release)
  • Critical Bug Fix (data loss, cross-tenant read, auth bypass)
  • Build/Testing/Packaging Improvement
  • Documentation (changelog entry is not required)
  • CI Fix or Improvement (changelog entry is not required)
  • Not for changelog (changelog entry is not required)

Changelog entry

Adds configurable, provenance-aware conflict management for automatically captured memories. Loom can automatically settle eligible resolver-approved updates, retain an auditable restoration path, and help users manage remaining conflicts through backlog statistics, bulk review, and SessionStart notifications.

Why

Coding-agent integrations automatically capture observations, extracted facts, and session summaries into Loom namespaces. As automatic capture becomes more frequent, similar or contradictory memories accumulate faster than namespace owners can review them.

The existing resolver handles sufficiently clear cases, but uncertain conflicts remain in the Review queue. This makes genuine disagreements harder to identify and leaves agents exposed to conflicting memories during retrieval.

This change extends the existing memory and conflict-resolution infrastructure to make automatically captured conflicts manageable without removing human oversight.

The implementation introduces trusted capture provenance so that automatic resolution is based on server-validated integration identity rather than caller-supplied metadata. Namespace owners can opt into automatic settlement of eligible resolver-approved updates for trusted captured memories, while genuine contradictions, uncertain judgements, mixed-source conflicts, and unknown-provenance memories remain subject to conservative review.

The change also improves visibility into the remaining backlog, provides bulk acceptance of current resolver suggestions, and notifies users when their namespace requires attention.

Scope and risk

The implementation touches the following areas:

  • Authentication and scoped capture credentials for trusted integration provenance.
  • Memory write and storage paths for persistent capture-origin metadata.
  • Namespace configuration for captured-memory conflict policies.
  • Existing conflict resolver and worker for eligible automatic settlement.
  • Existing automatic supersession, audit, and restoration mechanisms.
  • Conflict-list and mentor statistics.
  • Review Queue APIs and frontend components for bulk resolution.
  • Coding-agent SessionStart notification hooks.
  • Database migration and generated schema, SDK, and plugin artifacts.

Security and data-integrity safeguards:

  • Capture origin is established through server-validated credentials, not arbitrary client-supplied actor or source metadata.
  • Automatic settlement is restricted to eligible resolver update judgements and configured confidence thresholds.
  • Caller-written, mixed-source, unknown-provenance, protected, and contradictory memories retain conservative handling.
  • Bulk decisions validate the latest resolver audit record and both memory revisions before applying a resolution.
  • Administrative bulk resolution remains outside MCP.
  • Automatic retirements use the existing audit and Undo lifecycle.
  • Backlog statistics respect namespace and read-scope filtering.

The implementation deliberately leaves the general retrieval architecture, namespace curation functionality, and unrelated MCP administration behaviour unchanged.

Potential risks: Credential lifecycle and provenance validation, concurrent memory updates during automatic settlement, ClickHouse mutation consistency, stale bulk-review suggestions, and restoration when newer memory revisions exist. These paths are covered by focused tests and the ClickHouse resolver integration suite.

Compatibility, rollout and rollback

Wire changes

  • Extends conflicts.list with conflict backlog statistics broken down by resolver state and provenance.
  • Adds trusted capture-origin claims and associated scoped capture credential issuance/validation.
  • Adds namespace-level captured-memory conflict policy configuration.
  • Adds an administrator-only bulk operation for accepting eligible resolver suggestions, returning individual outcomes.
  • Extends mentor backlog information and supported SessionStart notification behaviour.

The generated API schemas and SDK artifacts reflect the operation and model changes in this PR. Existing privileged conflict-resolution operations are not exposed through MCP.

Operator steps

  • Apply the additive database migration 125_captured_conflict_provenance.sql using the normal Loom migration procedure.
  • Deploy the updated server and compatible integration components.
  • Provision scoped capture credentials through the authorized namespace administration flow for integrations that should use trusted automatic capture.
  • Enable the captured-memory conflict policy explicitly for namespaces that want automatic settlement.
  • Existing namespaces retain their previous behaviour by default.
  • Legacy records without verified capture provenance remain unknown and are not automatically treated as trusted plugin captures.
  • No historical provenance backfill or re-index is required.

Rollback

Disable the captured-memory automatic settlement policy before rolling back the application.

The migration is additive. Rolling back the application does not automatically remove the provenance columns, audit records, or retired-memory history created by the feature. Existing automatic settlements remain recorded and should be restored through Loom's existing Undo mechanism when appropriate.

Do not drop the migration's stored data as part of an application rollback.

Tests

Current revision

  • Focused unit and simulation tests: 38 passed.
  • Focused ClickHouse integration cases: 9 passed across two runs. They cover audit retry safety, both reviewed-head races, confidence threshold round-tripping, schema-version provenance gating, and both losing-row lock modes.
  • Ruff format and lint checks on 16 changed Python files: passed.
  • make typecheck: passed. The server mypy gate reported 0 errors; strict Python SDK typing passed on 75 source files.
  • make schema-check: passed after replaying 102 migrations from an empty ClickHouse. schemas/schema.sql matches the applied schema.
  • uv run --locked python scripts/ops/simulate_captured_conflicts.py: passed all checks for the seven-day light, steady and surge scenarios. No false automatic settlements or genuine contradictions were settled.
Scenario Default review backlog New policy
Light 372 141
Steady 975 328
Surge 1,965 645

The modeled review capacity was 2,000 pairs per sitting. All six scenarios stayed within that capacity.

Not completed

  • The N-1/N Docker gate could not archive its base commit because Git could not resolve the linked worktree metadata path.
  • The Review Queue test command could not start because vitest was not recognized in the configured shell. The full frontend suite and production build are not verified on this revision.

Reproduction:

uv run --locked python scripts/ops/simulate_captured_conflicts.py

Detailed assumptions and results are documented in docs/features/memory/captured-conflict-simulation.md.

AI assistance in the code

  • None

  • AI-assisted (completion, or questions while writing it):: I drove the system design, provenance and conflict-resolution logic, code review, debugging, and end-to-end verification, while relying on AI to scaffold the core modules, handlers, test/simulation suites, and PR documentation.

  • AI-generated

  • I can explain every line of this diff and how it interacts with the rest of Loom.

Checklist

  • Local format, lint, type checks and focused tests pass. The full frontend suite remains incomplete for this revision.
  • Generated files were regenerated and checked, including SDK, plugin/documentation artifacts and schemas/schema.sql.
  • The additive migration is ordered after current main, and its generated schema passed make schema-check.
  • Plugin versions are 1.2.188; the other open manifest bump checked is 1.2.187.
  • The frontend test suite and production build are not verified on this revision.
  • Relevant documentation describes the new captured-memory policy, provenance, audit and simulation behaviour, including operator steps and compatibility.
  • Repository public-copy checks passed; no unnecessary dates, people, host names, internal namespaces, or decision numbers are included in the user-facing documentation.
  • Both commits are signed off.
  • CLA signature is recorded.

Note

High Risk
Changes credential issuance, memory conflict policy, and admin bulk resolution with automatic retirements—security-sensitive paths where stale suggestions or mixed-version rollouts could mis-settle conflicts if guards fail.

Overview
Introduces trusted provenance for plugin-captured memories via server-signed service-account credentials (capture_origin on writes), plus namespace captured_conflict_policy / confidence settings so owners can keep captured conflicts in review by default or opt into automatic settlement of eligible resolver update judgements.

Adds conflicts.bulk_accept (admin, audited) and extends conflicts.list / mentor.brief with row-based backlog splits (resolver state × captured vs caller vs unknown). Migration 125_captured_conflict_provenance.sql adds the storage columns; rollout/rollback rules document fencing when live captured rows exist.

The Review queue gains backlog summary, resolver-suggestion selection (hash + revision checks), and bulk accept; namespace settings and token minting expose capture credentials and policies without resending unchanged fields on unrelated saves. Claude Code gets a throttled SessionStart review notice; docs and a seven-day simulation script describe behavior and limits. SDK/plugin/schema artifacts are regenerated (427 ops).

Reviewed by Cursor Bugbot for commit a5c3725. Bugbot is set up for automated code reviews on this repo. Configure here.

Signed-off-by: Project Manager <cprazwal@gmail.com>
@cla-assistant

cla-assistant Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@vercel

vercel Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
loom-docs Ready Ready Preview Dec 6, 2026 10:44am UTC
loom-telemetry Ready Ready Preview Dec 6, 2026 10:44am UTC

Request Review

@cursor cursor Bot 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.

Stale Bugbot comment from a previous run.

Comment thread server/memory/app/conflicts_ops.py Resolved
@zlareb1 zlareb1 self-assigned this Dec 4, 2026

@zlareb1 zlareb1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Bulk acceptance can retire a revision the operator never reviewed, and capture trust can survive a human edit. Please address the inline findings and the two open review threads. GitHub also reports a merge conflict with main, which already uses migration 120.

Comment thread server/memory/app/conflicts_ops.py Resolved
Comment thread server/auth/jwt.py Resolved
Comment thread server/memory/store/rows.py Resolved
Comment thread frontend/src/api/admin.ts Resolved
Comment thread server/memory/store/rows.py Resolved
Comment thread server/memory/api/models_conflicts.py Resolved
Comment thread server/insights/store/mentor.py Resolved
Signed-off-by: Project Manager <cprazwal@gmail.com>
The resolver audit determines the winner direction, and a bulk acceptance must not retire a peer whose content changed after review. Preserve the signed capture origin through full-row reads and unrelated namespace saves so later conflict review remains accurate.

Signed-off-by: Project Manager <cprazwal@gmail.com>

@cursor cursor Bot 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.

Stale Bugbot comment from a previous run.

Signed-off-by: PRAZPC <cprazwal@gmail.com>
Signed-off-by: PRAZPC <cprazwal@gmail.com>

@zlareb1 zlareb1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The updated retirement checks the losing head at write time, and the capture claim, migration and dashboard visit changes address earlier findings. Bulk acceptance still fails to bind the winning revision to the retirement. GitHub confirms a conflict with main.

Comment thread server/memory/app/conflicts_ops.py Resolved
…conflict-management

Signed-off-by: PRAZPC <cprazwal@gmail.com>

# Conflicts:
#	docs/reference/operations.md
#	docs/reference/status.md
#	schemas/schema.sql
#	sdk/go/wire/models.gen.go
#	sdk/ruby/lib/clickhouse/loom/generated/ops.rb
#	sdk/rust/src/wire_models.rs
#	sdk/typescript/src/generated/ops.ts
#	tests/unit/test_schema_baseline.py

@cursor cursor Bot 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.

Stale Bugbot comment from a previous run.

Signed-off-by: PRAZPC <cprazwal@gmail.com>
Signed-off-by: PRAZPC <cprazwal@gmail.com>
Signed-off-by: PRAZPC <cprazwal@gmail.com>
@PRAZPC

PRAZPC commented Dec 5, 2026 •

Copy link
Copy Markdown
Author

I merged main into this branch and pushed 979cb84. The branch includes the current base, and the local merge is clean. I regenerated the Go and Rust models; they include the bulk-accept models and the current skill operations. GitHub is still showing those two files as conflicted. Could you refresh the status or let me know what conflict it is seeing?

@zlareb1 zlareb1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Bulk acceptance now checks both reviewed heads at the write fence. The new SessionStart behavior also needs a distinct version in both shipped plugin manifests.

Comment thread server/memory/store/rows.py Resolved
Comment thread server/memory/app/conflicts_ops.py Resolved
Comment thread server/memory/app/conflict_resolver.py Resolved
Comment thread server/memory/app/conflicts_ops.py Resolved
Signed-off-by: Project Manager <cprazwal@gmail.com>
Carry authenticated capture provenance through namespace snapshots, gate captured policy until all live instances understand it, and enforce both reviewed heads and active delete locks at the bulk retirement fence.

Signed-off-by: Project Manager <cprazwal@gmail.com>
@PRAZPC

PRAZPC commented Dec 5, 2026

Copy link
Copy Markdown
Author

Fixed in 46a94ba. Bulk acceptance fences both reviewed heads at the write, and the ClickHouse replacement-race test covers a stale head. Both plugin manifests are now 1.2.188; the open manifest PR I checked is at 1.2.187.

@cursor cursor Bot 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.

Stale Bugbot comment from a previous run.

Comment thread server/memory/app/provenance.py Resolved
Comment thread server/memory/app/conflicts_ops.py Resolved

@zlareb1 zlareb1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The rollout gate still admits an old resolver. The heartbeat reports the highest migration in the build, and main already has migration 128, so the < 125 check accepts a replica that cannot enforce captured-row provenance. Gate the policy on resolver support and cover mixed-build retirement. A locked loser also still returns “Conflict is no longer open” while both rows remain conflicted. Rollout finding · Locked-row finding

Use the instance heartbeat ID to distinguish resolvers that understand captured provenance during mixed-version deployments. Return a protected result when a lock blocks bulk retirement at the write fence.

Signed-off-by: Project Manager <cprazwal@gmail.com>
An older resolver treats rows without a capture claim under its general policy. Return a retryable backend-unavailable response before writing a signed capture request until every live instance advertises resolver support.

Signed-off-by: Project Manager <cprazwal@gmail.com>
@PRAZPC

PRAZPC commented Dec 6, 2026

Copy link
Copy Markdown
Author

Fixed in 8ae03d6 and 07ca202. Bulk acceptance reports a locked loser as protected when the write fence sees its lock. Captured writes pause with a retryable response until every live instance advertises resolver support, so an older resolver cannot see unmarked capture rows during rollout. Unit tests cover the legacy, supported and mixed cases, and ClickHouse tests verify that blocked writes leave no rows.

@zlareb1 zlareb1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The locked-pair result now distinguishes a protected loser from a stale conflict. The rollout gate still misses a path that writes captured rows. GitHub also reports a merge conflict with main.

Signed-off-by: Project Manager <cprazwal@gmail.com>

# Conflicts:
#	docs/reference/operations.md
#	docs/reference/status.md
#	frontend/src/api.ts
#	frontend/src/api/conflicts.ts
#	frontend/src/views/admin/ReviewQueue.test.tsx
#	integrations/claude-code-plugin/.claude-plugin/plugin.json
#	integrations/codex-plugin/.codex-plugin/plugin.json
#	sdk/ruby/lib/clickhouse/loom/generated/ops.rb
#	sdk/rust/src/wire_models.rs
#	sdk/typescript/src/generated/ops.ts
#	tests/unit/test_lineage_and_snapshot_fidelity.py
Signed-off-by: Project Manager <cprazwal@gmail.com>
Signed-off-by: Project Manager <cprazwal@gmail.com>

@zlareb1 zlareb1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The snapshot restore now checks resolver support before it writes captured rows. Capture tokens, inline retirement, and the worker still have paths that bypass the captured policy. GitHub reports a merge conflict with main.

minted = delegated.mint(
sa_subject,
reads_as_creator=personal,
capture_origin=capture_origin or None,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

P1 — The service account can mint a capture token while an older replica still accepts writes. That replica ignores the new claim, writes an unmarked row, and lets the older resolver act on it. Fence capture token use through the mixed-version window and cover a new token routed to an older replica. Rollback also needs a fence for already captured rows because the old resolver ignores the captured policy.

captured_update = bool(
action in (cr.FLAG, cr.RETIRE)
and cr.captured_update_eligible(
policy=why.get("captured_conflict_policy", ""),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

P1 — This uses policy read before the judge call. If an owner switches to manual_review while the call waits, the resolver can still retire a row under the old policy. The pair locks protect rows and leave namespace settings writable. Check the current policy and confidence floor under a fence that covers retirement, and test a setting change while the judge is in flight.

Captured writes carry a server-stamped `capture_origin` from a verified service-account token;
request fields cannot set it. The supported origins are `claude-code` and `codex`. The
namespace's `captured_conflict_policy` defaults to `manual_review`, and its
`captured_conflict_confidence` defaults to 0.98. With `manual_review`, a captured update stays

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

P1 — The documented manual-review guarantee has an inline exception. Under newest_wins, check_on_commit can classify a templated update as refines, and the commit retires the peer before the resolver sees it. Cover the inline path with the captured policy and test a captured update against a templated peer.

"""An omitted settings field keeps the row read under account_change; an explicit
field value is the administrator's edit. Fresh rows use the field's default."""
if field in input.model_fields_set:
return getattr(input, field)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

P2 — The register input accepts explicit null for both captured settings. This passes null to non-nullable registry columns, so a valid request can fail during insert. Give explicit null a defined meaning or reject it in validation, and test the stored values after registration.

Signed-off-by: Project Manager <cprazwal@gmail.com>

@cursor cursor Bot 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.

Cursor Bugbot has reviewed your changes using default effort and found 2 potential issues.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit a5c3725. Configure here.

if await conflicts_repo.has_live_captured_rows(input.org, input.namespace, ch=ch):
raise ValidationError(
"default_conflict_policy must remain manual_review while captured rows are live"
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Policy fence misses live credentials

High Severity

Changing default_conflict_policy is blocked only when a captured row is already visible. A capture credential is checked only at issue time and does not hold the namespace claim across later writes, so the policy can move off manual_review before the first captured row, or after the last one is tombstoned. Those later writes still stamp capture_origin. A rollback build never reads that field, and its newest_wins path can retire the new rows. The new templated-substitution guard does not cover that build.

Additional Locations (2)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit a5c3725. Configure here.

'pending_judgement',
toUnixTimestamp(e.conflict_checked_at) = 2, 'resolver_judged',
'cosine_only'
) AS judgement,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Backlog mislabels older resolver marks

Medium Severity

count_conflict_backlog treats only the owed and judged sentinels as resolver states. A conflicted row whose conflict_checked_at is a real timestamp, the stamp an older resolver left, falls through multiIf into cosine_only. Those rows are still on the unjudged recheck queue, so "Awaiting resolver judgement" undercounts them and "Cosine-only" includes rows a resolver already stamped.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit a5c3725. Configure here.

This branch has not been deployed

No deployments
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.

Conflicted rows from automatic capture outgrow what a person can review

2 participants