Crash in PostCategory.lookup ("nil is not a valid object ID") after a quick status change from the post list

オープン
#26,316 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
52/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
objective-c, swift
領域
mobile

調査の方向性

Build the Jetpack scheme and use docs/simulator-sign-in.md to set up the simulator. Follow the listed steps with Network Link Conditioner, then inspect PostRepository.update, PostHelper.merge, and the PostCategory.lookup stack path to check whether the post is deleted while the PATCH is in flight. Report whether the repro is reliable and, if confirmed, the cause and a fix approach.

索引モデルが issue の本文から書いたものです。

説明

[Status] Needs Plan [Type] Crash Core Data Posts + Pages

Likely shares a root cause with #26317, #26318, #26319, #26320. See #26323: posts are deleted locally by a first-page list sync while still in use.

Sentry: JETPACK-IOS-1JSW

Sentry snapshot (as of Oct 30, 2026)

  • Fatal NSInvalidArgumentException: nil is not a valid object ID. First seen Mar 21, 2026. 373 events from 149 users in total.
  • Last 30 days by release:
    • 27.3: 138 events, 78 users
    • 27.2: 12 events, 10 users
    • 27.1: 2 events
  • This got worse in 27.3. 27.3 has about 4.2× as many users reporting any error as 27.2 (2,388 vs 573 in 30 days). This crash is at about 7.8× on 27.3, so it's roughly twice as frequent per user.
  • Devices: iPhone only, with no iPad events. Mostly iOS 26.3–26.6 and 27.0.x.

Stack (crashing thread)

PostCoordinator.performChanges closure (PostCoordinator.swift:252) → PostCoordinator.update (:156) → PostRepository.update (PostRepository.swift:216) → +[PostHelper updatePost:withRemotePost:inContext:overwrite:] (PostHelper.m:89) → updatePost:withRemoteCategories: (:113) → PostHelper.createOrUpdateCategory (PostHelper+Metadata.swift:42) → PostCategory.lookup (PostCategory+Lookup.swift:19) → NSManagedObjectContext existingObjectWithID: throws.

createOrUpdateCategory passes blog.objectID. The blog comes from post.blog, which is nil here. existingObject(with:) then raises an Objective-C exception, which the try? in the caller can't catch.

Breadcrumbs (6 recent 27.3 events)

In all 6, the crash happens just as a quick PATCH (POST …/posts/{id}?context=edit) returns, after the user started it from the post list:

  • 3 of 6: a context-menu action from the Published tab, with an 18-byte body. That's {"status":"draft"}, i.e. Move to Draft (PostCoordinator.moveToDraft).
  • 2 of 6: Publish from the Drafts tab via PublishPostViewController, with a 20-byte body (status → publish).
  • 1 of 6: a Post Settings save from the list's context menu (42–98 byte body).
  • In every one, the same list status (status=publish,private or status=draft,pending) was re-fetched while the PATCH was in flight. Several events show the list polling every few seconds.

Candidate cause (hypothesis, not confirmed)

  1. The user changes a post's status from the list. The PATCH starts, and the server applies it right away.
  2. The list for the old status re-syncs. The post isn't in the response anymore, so PostRepository (purgeExisting: deleteOtherLocalPosts) → PostHelper.merge (PostHelper.m:193) deletes the local post.
  3. The PATCH response arrives. PostRepository.update calls PostHelper.update(post, …) on the deleted object. post.blog is nil, so it crashes.

Possible fixes:

  • In PostRepository.update, return early after the await if post.isDeleted or post.managedObjectContext == nil.
  • Make PostHelper updatePost:withRemoteCategories: skip the update when post.blog is nil.
  • Exclude posts with an update in flight from the purge.

Why 27.3 is worse is unclear. Nothing in the 27.2→27.3 range (e7c3606158…b2234d0688) touches PostRepository, PostCoordinator or the purge. #25970 only changed PostCategoryService create, which isn't on this path. The frequent list polling seen in the breadcrumbs is worth checking.

Repro to try, in order

  1. Setup: a WordPress.com site with a few published posts and drafts. Use Network Link Conditioner (host) with ~3 s latency so the PATCH stays in flight.
  2. Move to Draft: Posts › Published › long-press a post › Move to Draft. Immediately pull to refresh the Published list.
  3. Publish: Posts › Drafts › context menu › Publish › confirm. Immediately pull to refresh the Drafts list.
  4. Repeat steps 2 and 3 about 10 times. Add an Exception breakpoint, plus a breakpoint where PostHelper.merge deletes posts, to confirm the post is deleted before PostRepository.update resumes.

Event IDs

  • 47cf73bc5efd408f99dc69bda3765d25: Move to Draft, Published tab
  • 330d0c02d72e46858ac56b3c6cdd1e8b: Move to Draft, Published tab
  • ed467d1d01f740b2bbe4891bbbda9933: Publish from Drafts
  • fc8a713c1270408a9933b50a00baa747: Post Settings save, then Publish from Drafts
  • 864cdb7293b8437197cecd2a7a314574: Post Settings save from the Published tab

Build the Jetpack scheme and sign in using docs/simulator-sign-in.md, with bundle ID com.automattic.jetpack.

When you're done: post the results here. If you now have reliable steps, remove [Status] Needs Repro. If you found the cause and a fix approach, remove [Status] Needs Plan and add [Status] Ready for Dev. Remove Simulator Testable when you're finished.


Generated by Claude Code

主要言語
Swift
スター
3.9k
フォーク
1.2k
平均マージ
1日 23時間
マージ済み PR(30日)
136

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

wordpress-mobile/WordPress-iOS のほかの issue

wordpress-mobile/WordPress-iOS の issue をすべて見る

似ている issue

Swift の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。