Skip to content

[codex] Structure persistence error correlation#3439

Merged
juliusmarminge merged 3 commits into
mainfrom
codex/structure-persistence-error-correlation
Jun 20, 2026
Merged

[codex] Structure persistence error correlation#3439
juliusmarminge merged 3 commits into
mainfrom
codex/structure-persistence-error-correlation

Conversation

@juliusmarminge

@juliusmarminge juliusmarminge commented Jun 20, 2026

Copy link
Copy Markdown
Member

Summary

  • add one bounded persistence-error correlation shape for session, pairing-link, and thread identifiers
  • attach safe identifiers at auth-session, pairing-link create/revoke, and provider-runtime mapping boundaries
  • decode repository rows individually where an identifier is available so corrupt-row failures retain correlation
  • preserve existing error messages and immediate SQL/schema causes

Why

Persistence failures identified the repository operation but often could not be tied back to the affected session, pairing link, or provider thread. This adds safe correlation without recording credentials, tokens, subjects, payloads, or timestamps.

Safety

The correlation schema permits exactly one of sessionId, currentSessionId, pairingLinkId, or threadId. Pairing-link credential-based reads intentionally remain uncorrelated. Error messages continue to derive only from the existing operation/detail/issue fields.

Validation

  • vp test run apps/server/src/persistence (14 files, 22 tests)
  • vp test run apps/server/src/persistence/Errors.test.ts apps/server/src/persistence/RepositoryErrorCorrelation.test.ts (2 files, 5 tests)
  • vp check (0 errors; 20 existing warnings)
  • vp run typecheck

Note

Low Risk
Observability and error-shaping only; success paths and public error message format are unchanged, with correlation limited to non-secret identifiers.

Overview
Adds a bounded PersistenceErrorCorrelation shape (sessionId, currentSessionId, pairingLinkId, or threadId) on PersistenceSqlError and PersistenceDecodeError, so failures can be tied to an entity without putting credentials, subjects, or payloads in messages.

Auth sessions, pairing links, and provider session runtime repositories now read Unknown raw SQL rows and decode in a second step. That lets per-row decode failures carry the row’s id (e.g. corrupt listActive / list data). SQL and encode-path errors get correlation where the input already has a safe id; pairing-link lookups by credential still omit correlation on the query error path.

New RepositoryErrorCorrelation.test.ts integration tests assert correlation fields are set and that error text does not leak sensitive values.

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

Note

Add correlation fields to persistence errors in auth and runtime repositories

  • Adds a PersistenceErrorCorrelation union type to Errors.ts, allowing PersistenceSqlError and PersistenceDecodeError to carry an optional correlation payload (e.g. sessionId, pairingLinkId, threadId).
  • Refactors DB queries in AuthSessions, AuthPairingLinks, and ProviderSessionRuntime repositories to return raw rows (unknown-typed fields), then decode them explicitly post-query so decode errors can be correlated to the offending row's ID.
  • Adds a test suite in RepositoryErrorCorrelation.test.ts verifying correlation fields are present and that sensitive values do not leak into error messages.

Macroscope summarized 0e3803e.

@coderabbitai

coderabbitai Bot commented Jun 20, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: a6d3dbff-7352-4dfb-859f-02ab8950ee91

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/structure-persistence-error-correlation

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

@github-actions github-actions Bot added vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. size:L 100-499 changed lines (additions + deletions). labels Jun 20, 2026

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

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 high effort and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix prepared a fix for the issue found in the latest run.

  • ✅ Fixed: Unbounded list decode correlation
    • Removed { concurrency: "unbounded" } from ProviderSessionRuntimeRepository.list's Effect.forEach so decode errors are reported sequentially in query sort order, making error correlation deterministic and consistent with AuthSessions.listActive.

Create PR

Or push these changes by commenting:

@cursor push 9f31b83ea5
Preview (9f31b83ea5)
diff --git a/apps/server/src/persistence/ProviderSessionRuntime.ts b/apps/server/src/persistence/ProviderSessionRuntime.ts
--- a/apps/server/src/persistence/ProviderSessionRuntime.ts
+++ b/apps/server/src/persistence/ProviderSessionRuntime.ts
@@ -280,19 +280,16 @@
         ),
       ),
       Effect.flatMap((rows) =>
-        Effect.forEach(
-          rows,
-          (row) =>
-            decodeRuntimeRow(row).pipe(
-              Effect.mapError((cause) =>
-                PersistenceDecodeError.fromSchemaError(
-                  "ProviderSessionRuntimeRepository.list:decodeRows",
-                  cause,
-                  { threadId: row.threadId },
-                ),
+        Effect.forEach(rows, (row) =>
+          decodeRuntimeRow(row).pipe(
+            Effect.mapError((cause) =>
+              PersistenceDecodeError.fromSchemaError(
+                "ProviderSessionRuntimeRepository.list:decodeRows",
+                cause,
+                { threadId: row.threadId },
               ),
             ),
-          { concurrency: "unbounded" },
+          ),
         ),
       ),
     );

You can send follow-ups to the cloud agent here.

Reviewed by Cursor Bugbot for commit 1f0f376. Configure here.

Comment thread apps/server/src/persistence/ProviderSessionRuntime.ts Outdated
macroscopeapp[bot]
macroscopeapp Bot previously approved these changes Jun 20, 2026
@macroscopeapp

macroscopeapp Bot commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Approved

Adds correlation IDs to persistence errors for debugging/tracing without changing runtime behavior. The changes are mechanical additions of error metadata with comprehensive test coverage.

You can customize Macroscope's approvability policy. Learn more.

@macroscopeapp macroscopeapp Bot dismissed their stale review June 20, 2026 21:10

Dismissing prior approval to re-evaluate ba1abed

@juliusmarminge juliusmarminge force-pushed the codex/structure-persistence-error-correlation branch from ba1abed to d305837 Compare June 20, 2026 22:42
juliusmarminge and others added 2 commits June 20, 2026 15:48
Co-authored-by: codex <codex@users.noreply.github.com>
Co-authored-by: codex <codex@users.noreply.github.com>
@juliusmarminge juliusmarminge force-pushed the codex/structure-persistence-error-correlation branch from d305837 to 2582cf0 Compare June 20, 2026 22:50
Co-authored-by: codex <codex@users.noreply.github.com>
@juliusmarminge juliusmarminge merged commit 57d25c9 into main Jun 20, 2026
16 checks passed
@juliusmarminge juliusmarminge deleted the codex/structure-persistence-error-correlation branch June 20, 2026 23:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L 100-499 changed lines (additions + deletions). vouch:trusted PR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant