[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M74XPS0CZ031R2YY44KC8JHY":3,"skill-same:01M74XPS0CZ031R2YY44KC8JHY":43},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":15,"categories":16,"keywords":17,"publishedAt":18,"linkOnly":19,"markdownContent":20,"markdownBody":21,"frontMatter":22,"refName":23,"commitSha":24,"skillDirectory":25,"forksCount":13,"repositoryHtmlUrl":26,"repositoryHomepageUrl":6,"ownerHtmlUrl":27,"ownerBlogUrl":6,"ownerDescription":6,"updatedAt":28,"install":29,"resources":42},"01M74XPS0CZ031R2YY44KC8JHY","swiftdata-rollback-attribute-restore",null,"A multi-object SwiftData save fails partway, the code calls context.rollback() expecting the batch to be undone, and the objects keep their new values anyway — because rollback() discards pending INSERTS and DELETES but does not revert attribute mutations on already-fetched @Model objects. Symptom: a failed batch edit leaves the UI showing values that were never persisted, and a later unrelated save flushes them. Use whenever writing a save path that mutates attributes on more than one fetched model before a single save(), or when an existing rollback-based error path is being reviewed or copied from an insert-shaped precedent.","abhijitbansal\u002Fclaude-skills","abhijitbansal","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F271802621?v=4","01M74XA5M33XYNJ2D2TJDS7W9E","01M74XA5MQ8GMWJW10ZJ4V0NVG",1,"MIT","https:\u002F\u002Fgithub.com\u002Fabhijitbansal\u002Fclaude-skills\u002Fblob\u002Fmain\u002Fplugins\u002Fios-dev\u002Fskills\u002Fswiftdata-rollback-attribute-restore\u002FSKILL.md",[],[],"2026-11-12 13:55:43",false,"---\nname: swiftdata-rollback-attribute-restore\ndescription: \"A multi-object SwiftData save fails partway, the code calls context.rollback() expecting the batch to be undone, and the objects keep their new values anyway — because rollback() discards pending INSERTS and DELETES but does not revert attribute mutations on already-fetched @Model objects. Symptom: a failed batch edit leaves the UI showing values that were never persisted, and a later unrelated save flushes them. Use whenever writing a save path that mutates attributes on more than one fetched model before a single save(), or when an existing rollback-based error path is being reviewed or copied from an insert-shaped precedent.\"\n---\n\n# `ModelContext.rollback()` Does Not Restore Mutated Attributes\n\n## Symptom\n\nA batch edit mutates attributes across several fetched `@Model` objects, then\nsaves. The save throws. The error path calls `context.rollback()` and reports\nfailure to the user. But:\n\n- the in-memory objects — and therefore the UI bound to them — still show the\n  new values;\n- nothing was persisted, so a relaunch shows the old values (the UI and the\n  store disagree);\n- worse, a later unrelated `save()` on the same context can flush those\n  lingering mutations, persisting a batch the user was told had failed.\n\n## Root cause\n\n`rollback()` resets the context's **pending changes graph** — inserted objects\nare discarded, deleted objects are restored. It is *not* an undo log for\nattribute writes on objects that were already fetched and registered. Those\nmutations happened on live model instances; there is no recorded prior value\nto restore, so nothing is restored.\n\nThis is precisely why an insert-shaped precedent does not transfer. Code like a\nbatch-import flush works correctly with `rollback()` because everything it\ntouches is a **pending insert** — discarding the graph genuinely undoes it.\nCopying that error-handling shape into an **attribute-mutation** batch produces\na rollback that reads correct and does nothing.\n\n## The fix: capture before mutating, restore explicitly on failure\n\n```swift\nfunc applyBatch(_ edits: [Edit]) throws {\n    \u002F\u002F 1. Capture previous values BEFORE the first mutation.\n    var previous: [PersistentIdentifier: Snapshot] = [:]\n    for edit in edits {\n        guard let object = fetch(edit.id) else { continue }\n        previous[edit.id] = Snapshot(name: object.name, quantity: object.quantity)\n    }\n\n    do {\n        for edit in edits { apply(edit) }\n        try context.save()\n    } catch {\n        \u002F\u002F 2. Restore explicitly. rollback() alone will NOT do this.\n        for (id, snapshot) in previous {\n            guard let object = fetch(id) else { continue }\n            object.name = snapshot.name\n            object.quantity = snapshot.quantity\n        }\n        context.rollback()   \u002F\u002F still worth calling — it handles pending inserts\u002Fdeletes\n        throw error\n    }\n}\n```\n\nThe snapshot is a plain value type holding only the attributes this batch\ntouches. Don't snapshot the whole model; restore only what you mutated.\n\n## Testing it — the part that usually gets skipped\n\nA test that saves successfully proves nothing. You need a **mid-batch failure**,\nwhich means making the save fail on demand:\n\n- reopen the same store through a second `ModelConfiguration(allowsSave: false)`\n  and mutate via that context — `save()` then throws for real, with no\n  production seam to build or maintain. Wrap the container in\n  `withExtendedLifetime`: a `ModelContext` does not retain its `ModelContainer`,\n  and a deallocated container fails the test for the wrong reason. This is\n  usually the cheapest option and the one to try first;\n- inject a validation-violating value partway through the batch, or\n- run against a context configured so the Nth write fails, or\n- extract the mutate-and-restore logic behind a seam whose `save` closure the\n  test controls.\n\nThen assert on **every** object in the batch, not just the first — the failure\nmode is partial, so a test checking only object 0 passes against the broken\nversion.\n\nVerify the test fails against the pre-fix code. A rollback-based error path that\nnever worked will still pass a test that only inspects the store rather than the\nin-memory objects.\n\n## Checklist\n\n- [ ] Prior values captured **before** the first mutation, not derived after\n- [ ] Restore loop covers every attribute the batch writes\n- [ ] `rollback()` still called for pending inserts\u002Fdeletes — additive here, not the fix\n- [ ] A mid-batch failure test exists, asserts on all objects, and fails against pre-fix code\n- [ ] The assertions target the UI's bound objects, not just a re-fetch from the store\n\n## Evidence\n\nCubby iOS, session 0062 (tech-debt wave, 2026-07-22): \"`ModelContext.rollback()`\ndoes NOT reset attribute mutations on fetched `@Model` objects — it only\ndiscards pending inserts; explicit previous-value capture\u002Frestore required.\"\n\nThe trigger was precedent transfer, exactly as described above: \"impl attempt 1\nfailed on the `flushImportBatch` precedent transferring wrongly.\" The import\npath's `rollback()` is correct — everything it touches is a pending insert — and\ncopying its error-handling shape into an attribute-mutation batch produced a\nrollback that read correct and did nothing.\n\nTwo process facts worth carrying over:\n\n- The missing restore was caught by an **adversarial verify round**, logged as \"a\n  real silent-persistence bug\", not by the implementing phase's own tests. A\n  rollback path that never worked passes any test that inspects only the store.\n- Coverage landed as a dedicated rollback test suite using the read-only-container\n  technique above; \"no production seam\" was needed.\n\nThe same wave also wrote the rule into that app's own `AGENTS.md`. That is the\nright split, not a duplication: the repo rule is local enforcement on a specific\nsave path, and this skill is the portable form. An app with an attribute-mutating\nbatch save should end up with both.\n\n## Related skills\n\n- `swiftdata-inmemory-test-harness` — the harness the mid-batch-failure test runs\n  inside: runner crashes, cross-suite races, and store-reset traps that will\n  otherwise be blamed on this test.\n- `swiftdata-cloudkit-model-rules` — model-level rules for the same store;\n  consult before adding or changing the attributes a batch edit mutates.\n- `ios-photo-sidecar-store` — where the rollback question gets genuinely harder.\n  A mutator that only reassigns references has nothing on disk to undo and can\n  legitimately keep-and-retry; one that wrote a sidecar file first must roll\n  back. Decide per mutator, and record which one it is.\n","# `ModelContext.rollback()` Does Not Restore Mutated Attributes\n\n## Symptom\n\nA batch edit mutates attributes across several fetched `@Model` objects, then\nsaves. The save throws. The error path calls `context.rollback()` and reports\nfailure to the user. But:\n\n- the in-memory objects — and therefore the UI bound to them — still show the\n  new values;\n- nothing was persisted, so a relaunch shows the old values (the UI and the\n  store disagree);\n- worse, a later unrelated `save()` on the same context can flush those\n  lingering mutations, persisting a batch the user was told had failed.\n\n## Root cause\n\n`rollback()` resets the context's **pending changes graph** — inserted objects\nare discarded, deleted objects are restored. It is *not* an undo log for\nattribute writes on objects that were already fetched and registered. Those\nmutations happened on live model instances; there is no recorded prior value\nto restore, so nothing is restored.\n\nThis is precisely why an insert-shaped precedent does not transfer. Code like a\nbatch-import flush works correctly with `rollback()` because everything it\ntouches is a **pending insert** — discarding the graph genuinely undoes it.\nCopying that error-handling shape into an **attribute-mutation** batch produces\na rollback that reads correct and does nothing.\n\n## The fix: capture before mutating, restore explicitly on failure\n\n```swift\nfunc applyBatch(_ edits: [Edit]) throws {\n    \u002F\u002F 1. Capture previous values BEFORE the first mutation.\n    var previous: [PersistentIdentifier: Snapshot] = [:]\n    for edit in edits {\n        guard let object = fetch(edit.id) else { continue }\n        previous[edit.id] = Snapshot(name: object.name, quantity: object.quantity)\n    }\n\n    do {\n        for edit in edits { apply(edit) }\n        try context.save()\n    } catch {\n        \u002F\u002F 2. Restore explicitly. rollback() alone will NOT do this.\n        for (id, snapshot) in previous {\n            guard let object = fetch(id) else { continue }\n            object.name = snapshot.name\n            object.quantity = snapshot.quantity\n        }\n        context.rollback()   \u002F\u002F still worth calling — it handles pending inserts\u002Fdeletes\n        throw error\n    }\n}\n```\n\nThe snapshot is a plain value type holding only the attributes this batch\ntouches. Don't snapshot the whole model; restore only what you mutated.\n\n## Testing it — the part that usually gets skipped\n\nA test that saves successfully proves nothing. You need a **mid-batch failure**,\nwhich means making the save fail on demand:\n\n- reopen the same store through a second `ModelConfiguration(allowsSave: false)`\n  and mutate via that context — `save()` then throws for real, with no\n  production seam to build or maintain. Wrap the container in\n  `withExtendedLifetime`: a `ModelContext` does not retain its `ModelContainer`,\n  and a deallocated container fails the test for the wrong reason. This is\n  usually the cheapest option and the one to try first;\n- inject a validation-violating value partway through the batch, or\n- run against a context configured so the Nth write fails, or\n- extract the mutate-and-restore logic behind a seam whose `save` closure the\n  test controls.\n\nThen assert on **every** object in the batch, not just the first — the failure\nmode is partial, so a test checking only object 0 passes against the broken\nversion.\n\nVerify the test fails against the pre-fix code. A rollback-based error path that\nnever worked will still pass a test that only inspects the store rather than the\nin-memory objects.\n\n## Checklist\n\n- [ ] Prior values captured **before** the first mutation, not derived after\n- [ ] Restore loop covers every attribute the batch writes\n- [ ] `rollback()` still called for pending inserts\u002Fdeletes — additive here, not the fix\n- [ ] A mid-batch failure test exists, asserts on all objects, and fails against pre-fix code\n- [ ] The assertions target the UI's bound objects, not just a re-fetch from the store\n\n## Evidence\n\nCubby iOS, session 0062 (tech-debt wave, 2026-07-22): \"`ModelContext.rollback()`\ndoes NOT reset attribute mutations on fetched `@Model` objects — it only\ndiscards pending inserts; explicit previous-value capture\u002Frestore required.\"\n\nThe trigger was precedent transfer, exactly as described above: \"impl attempt 1\nfailed on the `flushImportBatch` precedent transferring wrongly.\" The import\npath's `rollback()` is correct — everything it touches is a pending insert — and\ncopying its error-handling shape into an attribute-mutation batch produced a\nrollback that read correct and did nothing.\n\nTwo process facts worth carrying over:\n\n- The missing restore was caught by an **adversarial verify round**, logged as \"a\n  real silent-persistence bug\", not by the implementing phase's own tests. A\n  rollback path that never worked passes any test that inspects only the store.\n- Coverage landed as a dedicated rollback test suite using the read-only-container\n  technique above; \"no production seam\" was needed.\n\nThe same wave also wrote the rule into that app's own `AGENTS.md`. That is the\nright split, not a duplication: the repo rule is local enforcement on a specific\nsave path, and this skill is the portable form. An app with an attribute-mutating\nbatch save should end up with both.\n\n## Related skills\n\n- `swiftdata-inmemory-test-harness` — the harness the mid-batch-failure test runs\n  inside: runner crashes, cross-suite races, and store-reset traps that will\n  otherwise be blamed on this test.\n- `swiftdata-cloudkit-model-rules` — model-level rules for the same store;\n  consult before adding or changing the attributes a batch edit mutates.\n- `ios-photo-sidecar-store` — where the rollback question gets genuinely harder.\n  A mutator that only reassigns references has nothing on disk to undo and can\n  legitimately keep-and-retry; one that wrote a sidecar file first must roll\n  back. Decide per mutator, and record which one it is.\n",{"name":5,"description":7},"main","153711dd9432743d97f0b33b080ada5798ea623c","plugins\u002Fios-dev\u002Fskills\u002Fswiftdata-rollback-attribute-restore","https:\u002F\u002Fgithub.com\u002Fabhijitbansal\u002Fclaude-skills","https:\u002F\u002Fgithub.com\u002Fabhijitbansal","2026-11-07 12:59:51",{"source":8,"skillName":5,"commands":30,"prompt":40,"zipAvailable":41},[31,34,37],{"tool":32,"command":33},"npx","npx skills add abhijitbansal\u002Fclaude-skills --skill swiftdata-rollback-attribute-restore",{"tool":35,"command":36},"bunx","bunx skills add abhijitbansal\u002Fclaude-skills --skill swiftdata-rollback-attribute-restore",{"tool":38,"command":39},"pnpm","pnpm dlx skills add abhijitbansal\u002Fclaude-skills --skill swiftdata-rollback-attribute-restore","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fabhijitbansal\u002Fclaude-skills\u002Fblob\u002Fmain\u002Fplugins\u002Fios-dev\u002Fskills\u002Fswiftdata-rollback-attribute-restore\u002FSKILL.md",true,[],[44,51,58,65,72,79],{"skillNo":45,"name":46,"nameZh":6,"description":47,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":48,"categories":49,"keywords":50,"publishedAt":18},"01M74XTV2V7GZM8FDBXQZZ74VX","second-wind","Orchestrate long unattended Claude Code runs across multiple repos with the wind CLI. Use when the user wants to run Claude Code overnight, resume sessions after the 5-hour usage limit, run Claude in many repos at once via tmux, or says \"set up second wind\", \"wind up\", \"overnight run\", \"resume after limit\", \"usage limit orchestrator\".","https:\u002F\u002Fgithub.com\u002Fabhijitbansal\u002Fclaude-skills\u002Fblob\u002Fmain\u002Fplugins\u002Fsecond-wind\u002Fskills\u002Fsecond-wind\u002FSKILL.md",[],[],{"skillNo":52,"name":53,"nameZh":6,"description":54,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":55,"categories":56,"keywords":57,"publishedAt":18},"01M74XTPGN1HDQSKGCZZX0AZPC","structured-output-adaptive-thinking-token-bloat","A Claude API call using output_config.format (json_schema structured outputs) with thinking:{type:\"adaptive\"} burns most of its output budget on thinking (observed ~21k of ~24k tokens) without improving JSON quality, making the run up to ~5x more expensive than the same call with thinking omitted — use when calling the Messages API with a json_schema output format for extraction, ranking, classification, or summarization tasks, or when a schema-constrained call's usage.output_tokens is far larger than the returned JSON.","https:\u002F\u002Fgithub.com\u002Fabhijitbansal\u002Fclaude-skills\u002Fblob\u002Fmain\u002Fplugins\u002Fprompt-craft\u002Fskills\u002Fstructured-output-adaptive-thinking-token-bloat\u002FSKILL.md",[],[],{"skillNo":59,"name":60,"nameZh":6,"description":61,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":62,"categories":63,"keywords":64,"publishedAt":18},"01M74XTKTRHAMC2JFHQ1P1E6GR","review","Apply a code-review lens to a diff, branch, or file — find correctness bugs, security issues, and quality problems, ranked by severity, with a concrete fix for each. Use when the user says \"review this\", \"review my diff\", \"check this PR\", \"look this over before I commit\", or \"is this safe\". Skip when the user wants the code written, not reviewed.","https:\u002F\u002Fgithub.com\u002Fabhijitbansal\u002Fclaude-skills\u002Fblob\u002Fmain\u002Fplugins\u002Fprompt-craft\u002Fskills\u002Freview\u002FSKILL.md",[],[],{"skillNo":66,"name":67,"nameZh":6,"description":68,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":69,"categories":70,"keywords":71,"publishedAt":18},"01M74XTGGCW7GWDDHPEMJQC7Y1","refresh","Rebuild the prompt-craft command registry and usage profile, and print a summary of installed commands and your personalized recommendations. Use when you install or update plugins and want the advisor to pick them up immediately, or say \"refresh prompt-craft\", \"rebuild the command registry\".","https:\u002F\u002Fgithub.com\u002Fabhijitbansal\u002Fclaude-skills\u002Fblob\u002Fmain\u002Fplugins\u002Fprompt-craft\u002Fskills\u002Frefresh\u002FSKILL.md",[],[],{"skillNo":73,"name":74,"nameZh":6,"description":75,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":76,"categories":77,"keywords":78,"publishedAt":18},"01M74XTCNGNR4G19P3Z95KTHQJ","refactor","Apply a refactoring lens — restructure code without changing behavior, guarded by tests that pass before and after. Use when the user says \"refactor\", \"clean this up\", \"extract this\", \"simplify this\", \"reduce duplication\", or \"make this readable\" on existing working code. Skip when the change is meant to alter behavior (that's a feature or a fix).","https:\u002F\u002Fgithub.com\u002Fabhijitbansal\u002Fclaude-skills\u002Fblob\u002Fmain\u002Fplugins\u002Fprompt-craft\u002Fskills\u002Frefactor\u002FSKILL.md",[],[],{"skillNo":80,"name":81,"nameZh":6,"description":82,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":83,"categories":84,"keywords":85,"publishedAt":18},"01M74XT9FKXN3N106G7Q3X56XR","plan","Decompose a non-trivial task into an explicit, tracked plan with goals and per-step acceptance criteria before writing code. Use when the user says \"plan this\", \"break this down\", \"what's the plan\", or asks for a multi-step feature\u002Frefactor that touches more than one file. Pairs with plan mode. Skip for single-edit changes that need no decomposition.","https:\u002F\u002Fgithub.com\u002Fabhijitbansal\u002Fclaude-skills\u002Fblob\u002Fmain\u002Fplugins\u002Fprompt-craft\u002Fskills\u002Fplan\u002FSKILL.md",[],[]]