Repository navigation
feat(pg): Positions, Arguments and citations on PostgreSQL (L-R-1 #634, PR 3) - #938
Conversation
Port Positions, Arguments and Stances to the PostgreSQL domain with SQLite's rules, codes and messages: field revisions, ordered targets with verdicts (self-targets and cycles refused under the per-Library target lock, a targeted record refuses its delete), ordered citations with the #60 section 8.5 Work/Version pin rules, and deletes that tombstone every owned scope. A Work delete removes its citations and advances each citing Argument's argument-sources. Research Note writers share the Concepts and Arguments their markup names. CREATE_ARGUMENT and SET_ARGUMENT_SOURCES join the Work merge's peer writers and run SERIALIZABLE; the sync protocol guards their cited Works against a merge. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017jgbjrTtg1i9iUrndjRxvp
PG integration (CRUD, lists, pins, isolation, races including Work delete vs citation), sync decision tables and ledgering, and SQLite/PG parity for the facade and the sync families. Pinned isolation and not-ported lists follow the new families. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017jgbjrTtg1i9iUrndjRxvp
…nd Arguments Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017jgbjrTtg1i9iUrndjRxvp
Architecture Inside the changed components — 2 viewsComponent view — Research domain and persistence Internal modules and persistence for positions, arguments, targets, and citations. Component view — Semantic sync integration Sync ledger integration and handlers for positions and arguments. Data flow The other flows — 1 sequence
Review ✨ Nothing flagged · reviewed Tip Open a diagram on the canvas, then press W or click play to walk through the change one step at a time 🪧 More tips
Thanks for using PR Lens! It's free for OSS. If it helped, a star helps other teams find it. |
This comment has been minimized.
This comment has been minimized.
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Position operations and synchronization backend/domain/research/positions.py, backend/sync/handlers/position.py, backend/db_manager.py, tests/pg/test_arguments.py, tests/pg/test_arguments_sync.py |
Adds Position create, read, update, delete, and sync operations. Deletion refuses Positions referenced by Arguments or Stances and advances both field scopes before removal. |
Argument rules, targets, and operations backend/domain/research/arguments.py, backend/domain/research/__init__.py, tests/pg/test_arguments.py |
Adds Argument persistence, target validation and cycle checks, revision-aware updates, and deletion constraints for note and target references. |
Citation references and Work lifecycle backend/domain/research/arguments.py, backend/domain/works/*, backend/sync/protocol.py, backend/sync/handlers/argument.py, tests/pg/test_arguments.py, tests/pg/test_arguments_sync.py |
Adds Version-pinned citation handling and Work-delete cleanup. Work deletion removes citations and advances source-list revisions. Research Note writes share references to Concepts and Arguments. |
Facade, sync registration, and parity validation backend/db_manager.py, backend/pg_facade/research.py, backend/sync/handlers/{argument,position}.py, backend/sync/protocol.py, tests/pg/*sync.py, tests/test_arguments_parity.py, pyrightconfig.typed-slice.json, scripts/check_invariants.py, tests/test_engineering_invariants.py |
Exposes the new operations through the facades and sync registry. Argument creation and source updates use SERIALIZABLE isolation. Adds sync, parity, and typed-slice coverage. |
Priority:
Estimated code review effort: 4 (Complex) | ~60 minutes
Change: Feature
Sequence Diagram(s)
sequenceDiagram
participant Client
participant ResearchMixin
participant ResearchDomain
participant PostgreSQL
Client->>ResearchMixin: Submit Position or Argument command
ResearchMixin->>ResearchDomain: Delegate operation
ResearchDomain->>PostgreSQL: Validate references and apply changes
PostgreSQL-->>ResearchDomain: Return records and revisions
ResearchDomain-->>ResearchMixin: Return operation result
ResearchMixin-->>Client: Return result
Possibly related issues
- Fooftilly/PRKS issue 788: This PR adds PostgreSQL Argument-to-Work citations, which the issue identifies as a prerequisite for showing incoming Argument links on Works. It does not add the Work UI or graph projection.
- Fooftilly/PRKS issue 614: This PR implements the PostgreSQL Research slice listed as outstanding in the implementation checklist.
Possibly related PRs
- Fooftilly/PRKS#937: Adds the PostgreSQL Concepts slice that this PR extends, using the same research package, facade, sync registry, and reference-sharing model.
- Fooftilly/PRKS#820: Defines Work lifecycle guards and merge peer-writer requirements used by this PR’s cited-Work checks and peer-writer additions.
Suggested reviewers: claude
Merge Risk: 
Minimal · up to 4327e
-
This change adds PostgreSQL Position and Argument operations, sync handlers, and citation cleanup on Work deletion. No actionable merge-blocking issue was found. The PR reports passing PostgreSQL, parity and SQLite tests, plus clean lint and type checks.
Pre-merge checks: 
6 · 
2
-
Failed checks: 2 warnings Passed checks: 6 passed-
Full details: Prks Engineering Invariants
-
Explanation
No explicit invariant violation found. The PostgreSQL slice remains outside the running HTTP backend, as required by README.md. The new research code scopes library data with library_id; the only unscoped verdict query uses the schema’s explicitly global seed table. Argument deletion checks canonical work_notes markup, not the derived index or graph, and the changed paths add no sensitive logging. Work deletion and citation cleanup also match the updated AGENTS.md research contract.
Full details: Ui Design Contract
-
Explanation
The pull request changes only backend, synchronization, configuration, documentation, and test files. The authoritative diff contains no frontend or user-visible UI files, so the DESIGN.md interaction contract does not apply.
-
Full details: Docstring Coverage
-
Explanation
Docstring coverage is 29.41% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 187 functions across 18 files. (2 skipped: 2 unsupported.)
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
Full details: Offline And Sync Coherence
-
Explanation
The PostgreSQL sync path introduces a terminal response that the offline client cannot consume. The PR adds
WORK_MERGEDchecks forCREATE_ARGUMENTandSET_ARGUMENT_SOURCESinbackend/sync/protocol.pyandbackend/sync/handlers/argument.py; the new PG tests confirm a 409WORK_MERGEDresponse. However,frontend/js/argument-state.jsaccepts onlyWORK_NOT_FOUND/ENTITY_NOT_FOUNDfor source operations and omitsWORK_MERGEDfor creates.sync-runtime.jstherefore treats the valid 409 asinvalid_response, resets the operation to pending, and retries it. This conflicts with the local-first design, which requires merged-Work operations to settle as terminal outcomes. The new tests cover the server response but not client recovery.Resolution
Teach the Argument create and source sync handlers to accept and terminally record
WORK_MERGED, preserve and displaytarget_work_id, and add the code to sync diagnostics. Add browser/client regression tests for both operations that verify no retry loop, conflict/diagnostic visibility, and correct dependent-operation handling. Keep the PostgreSQL tests for the 409 ledger response.
-
Finishing Touches: 💡 2
-
📝 Generate docstrings: 💡
-
- Commit to this branch
- Create a new PR
🛠️ Fix failing CI checks: 💡
-
- Commit to this branch
- Create a new PR
🧪 Generate unit tests (beta)
-
- Commit to this branch
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
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.
Comment @coderabbitai help to get the list of available commands.
This comment has been minimized.
This comment has been minimized.
Filter citation authors to Work-scoped roles and the primary Version's, as roles.credits_by_work does, so another Version's Author never shows. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017jgbjrTtg1i9iUrndjRxvp
|
@coderabbitai review |
✅ Action performed
|
Summary
This PR ports Positions, Arguments and Stances to the PostgreSQL domain and sync protocol. It is the third L-R-1 slice, after Concepts (#937).
It keeps SQLite's rules, error codes and messages, imported from
argument_sync.py,position_sync.pyandresearch_network.py.Positions (
backend/domain/research/positions.py)position-field), read, list and delete.position_in_use).Arguments and Stances (
backend/domain/research/arguments.py)kindfilter).ARGUMENT_SOURCE_VERSION_REQUIRED), and so does an ambiguous re-match of a stored citation.ON UPDATE CASCADEforeign key.Work delete.
commands.delete_worknow removes the Work's citations and advances each citing Argument'sargument-sources(arguments.release_work). It takes the WorkFOR UPDATE, then the citing Arguments in id order. Order gaps are kept, as with SQLite's cascade.Concurrency
backend/domain/research/__init__.py:FOR KEY SHARE.FOR KEY SHARE.works/notes.py, a Work create with a note) share the Concepts and Arguments their markup names, so a concurrent delete cannot slip past the in-use check.CREATE_ARGUMENTandSET_ARGUMENT_SOURCESjoinPEER_WRITERSof the Work merge and run SERIALIZABLE, both in sync and in the facade.lifecycle.guardon their cited Works, so a citation of a merged Work is refused withWORK_MERGED.Sync and facade
backend/sync/handlers/position.pyregisters 3 families andargument.pyregisters 5. A foreign id is refused withFORBIDDENand is not ledgered.backend/pg_facade/research.pygains 15@portedmethods, andPRKSDatabasegains thin delegators so the facade can port them.Related issues
Refs #634
Scope / non-goals
research_network, so there is no API cutover.research.reindex_work) and graph projection, planned for later L-R-1 PRs.Validation
All checks below were run locally:
tests/pg(scripts/test-postgres)scripts/test-postgres --parity), including the newtests/test_arguments_parity.pytests/pg/test_arguments.pytests/pg/test_arguments_sync.pytest_argument_sync,test_position_sync,test_research_network,test_engineering_invariants,test_api_contract_positions, concept and argument parityscripts/check_invariants.pyMigration / compatibility impact
There is no schema change: this uses
130_research.sqlfrom #936. The documented PG/SQLite differences inbackend/pg_facade/research.pyare:argument-sources.Risks / follow-up
Remaining L-R-1 work:
research.reindex_workjob.server.pyroute switch.Checklist
Generated by Claude Code
Summary by CodeRabbit