fix(api): start new IPNS entries at seq 1 to match client expectation#255
Conversation
Phase 16 added conflict detection via expectedSequenceNumber, but upsertFolderIpns created new entries with sequenceNumber='0' while the client computes newSeq = 0+1 = 1 and stores that. On the next publish the client sends expectedSeq='1', server has '0' → 409. The retry also fails because resolveRecord prefers the network IPNS record (which the client signed with seq=1) over the DB value (seq=0), so resync returns the same stale value and the retry gets 409 again. Fix: initialize new IPNS entries at seq='1' to match the IPNS record the client actually signed for first publish. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Entire-Checkpoint: 6374ba359bf4
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review infoConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
WalkthroughInitial FolderIpns sequenceNumber initialization changed from '0' to '1'; tests updated accordingly; and a data migration added to backfill existing non-root FolderIpns records from sequence_number '0' to '1'. package.json was also modified. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
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 |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #255 +/- ##
==========================================
+ Coverage 46.31% 46.68% +0.37%
==========================================
Files 106 106
Lines 8266 8255 -11
Branches 591 594 +3
==========================================
+ Hits 3828 3854 +26
+ Misses 4271 4233 -38
- Partials 167 168 +1
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@apps/api/src/ipns/ipns.service.ts`:
- Around line 227-233: Rows seeded previously with sequenceNumber = '0' and
latestCid != null will conflict with new publishes; add a one-time DB migration
or reconciliation to bump those rows to '1'. Implement a migration script (or DB
migration file) that runs the provided SQL to UPDATE folder_ipns SET
sequence_number = '1' WHERE sequence_number = '0' AND latest_cid IS NOT NULL AND
is_root = false, and/or add a reconciliation path in the service (where
folderIpnsRepository.create and any publish/update logic runs) that detects
existing records with sequenceNumber === '0' and latestCid !== null and
atomically updates sequenceNumber to '1' before proceeding. Ensure the migration
is idempotent and referenced in deployment/migration tooling so existing users
are unblocked.
There was a problem hiding this comment.
Pull request overview
Fixes an off-by-one sequence number mismatch between the API’s DB cache and the web client’s first IPNS publish, preventing false 409 Conflict errors after conflict detection (expectedSequenceNumber) was introduced.
Changes:
- Initialize newly created (non-root)
FolderIpnsDB entries withsequenceNumber: '1'instead of'0'. - Update IPNS service unit tests to expect the new initial sequence number for first-time publishes.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| apps/api/src/ipns/ipns.service.ts | Sets initial sequenceNumber for new IPNS tracking entries to '1' to align with the client’s first signed publish. |
| apps/api/src/ipns/ipns.service.spec.ts | Updates unit test expectations for new-entry publishing to reflect the new initial sequence number. |
Entries created before the seq='1' fix have seq='0' in the DB but the client stored seq=1n. This migration bumps non-root entries that have published content (latestCid IS NOT NULL) from '0' to '1'. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Entire-Checkpoint: b5da120786f5
Summary
expectedSequenceNumberon folder IPNS publishesupsertFolderIpnscreated new DB entries withsequenceNumber='0'but the client computesnewSeq = 0+1 = 1and stores thatexpectedSeq='1', server has'0'→ 409 ConflictresolveRecordprefers the network IPNS record (signed by the client with seq=1) over the DB value (seq=0), so resync returns the same wrong valuesequenceNumber='1'to match the IPNS record the client signed for first publishRoot Cause
The sequence number mismatch was invisible before Phase 16 because
expectedSequenceNumberwasn't sent. Phase 16 exposed the off-by-one between DB storage and client state.Note: Root folder entries created during vault initialization (seq='0', latestCid=null) are unaffected — their first actual publish goes through the UPDATE path which correctly increments.
Test plan
🤖 Generated with Claude Code
Summary by CodeRabbit
Bug Fixes
Tests
Chores