Repository navigation
fix(rosettify): merge steps by id in plan upsert entire_plan - #455
isolomatov-gd merged 3 commits into
Conversation
plan upsert <file> entire_plan merged phases by ID with the generic merge patch, which replaces array values. A patch whose phase carried a steps array replaced the stored steps of that phase: steps the patch did not name were deleted, with their status. FR-PLAN-0015 requires an existing phase to merge its steps by ID, and the phase target already did that. The phase-target logic moves into applyPhasePatch, and entire_plan uses it for every phase that is already in the plan. A new phase is appended whole, as before. A step without id in the patch of an existing phase is now rejected with missing_id, the error the phase target gives; before, entire_plan stored it in place of the old steps. Signed-off-by: Serghei <43180231+xyrolle@users.noreply.github.com>
Patch bump for the change on this branch, made with scripts/bump_versions.sh. Signed-off-by: Serghei <43180231+xyrolle@users.noreply.github.com>
Rosetta Triage ReviewSummary: This fixes the data loss in Type / Priority: Bug; Medium. Findings:
Caveats:
Recommendation: Recommend approval for the code change, with the version bump coordinated before the second merge. Automated triage by Rosetta agent |
There was a problem hiding this comment.
Thank you @xyrolle. The merge by id matches FR-PLAN-0015 (3), and the tests cover kept, patched and appended steps. One change, please:
- Add an acceptance criterion to FR-PLAN-0015 in
docs/REQUIREMENTS/rosettify/PLAN.md:entire_planon an existing phase keeps its stored steps and merges the patch steps by id. Add one line todocs/REQUIREMENTS/CHANGES.md.
… rosettify to 3.2.12 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: isolomatov-gd <isolomatov@griddynamics.com>
Addressed: we finished the requested changes on the branch (95b1779).
|
Thank you @xyrolle. We finished this PR: merged |
…_plan with griddynamics#455; bump rosettify to 3.2.13 Merges main (incl. griddynamics#455) into the PR branch. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: isolomatov-gd <isolomatov@griddynamics.com>
Impact
rosettify plan upsert <file> entire_plannow merges thestepsof an existing phase by id:Before, a
stepsarray in the phase patch replaced the stored array. Steps the patch did not name were deleted, with their status. The call succeeded, so the caller got no signal. The only trace was the backup file.A step without
idin such a patch is now rejected withmissing_id, and nothing is written. Before, it was stored in place of the phase's steps.entire_planand the phase target (upsert <file> <phase-id>) now patch an existing phase the same way.Fixes #393.
Before and after
The reproduction from #393:
All three commands exit 0 before and after. Output of the third command, then the stored steps of
p1ine.json.Before (
mainat 74e2f14):After:
s3has nostatusin either output. That is #390, which has its own PR.Over MCP (
tools/callonrosettify --mcp), the same three calls, then three more on the same file:upsert entire_plan(the patch above), step ids in the results3s1,s2,s3show_status p1{"id":"p1","name":"P1","status":"open","steps":[{"id":"s3","name":"S3","status":"open"}]}{"id":"p1","name":"P1","status":"in_progress","steps":[{"id":"s1","name":"S1","status":"complete"},{"id":"s2","name":"S2","status":"open"},{"id":"s3","name":"S3","status":"open"}]}upsert entire_planwith{"phases":[{"id":"p1","steps":[{"name":"no id","prompt":"x"}]}]}p1,{"name":"no id"}isError: true,{"error":"missing_id"}upsert p1with{"steps":[{"name":"no id","prompt":"x"}]}isError: true,{"error":"missing_id"}What changed
cmdUpsertinsrc/rosettify/src/commands/plan/upsert.tsmoved intoapplyPhasePatch(phase, patch). Its logic is unchanged: mergestepsby id withmergeById, merge-patch the other fields. The phase-target branch now calls it.entire_planuses it.applyEntirePlanPatchwalks the patch phases. For an id that is already in the plan it callsapplyPhasePatch. For a new id it appends a copy of the patch, as before. A phase withoutidgivesmissing_id, as before.mergeById.mergeByIdpatches an existing item with the genericmergePatch, and RFC 7396 replaces arrays. That is the defect. An existing phase needs the phase rule of FR-PLAN-0015 instead.upsert entire_planon a missing file runs the same function. It starts from a plan without phases, so a phase in the patch is appended whole, unless the same patch already added that id.How it was verified
Tests. New file
tests/unit/plan/upsert-entire-plan-steps.test.ts, 14 cases.in_progress.upsert p1 <patch>and asupsert entire_plan {"phases":[{"id":"p1", …patch}]}: the error and the stored phases are equal. The six are a new step, a named step with a phase field, an emptystepsarray, a removed field withoutsteps, a step without id, and a step id that another phase holds.missing_idfor a step of an existing phase and for a phase: the file bytes are unchanged and no backup is made.Checks.
npm ci,npm run typecheck,npm run buildandnpm run test:coveragepass on Node 24.mainat 74e2f14Mutation runs. I changed
upsert.tsonly, kept the tests, and ran the three upsert test files (63 tests). Every failure is an assertion failure.upsert.tsas onmainentire_planpatches an existing phase with the generic mergemissing_idcheck for a phaseapplyPhasePatchuses the generic merge forstepsapplyPhasePatchdrops the other phase fieldsThree new tests pass on
maintoo: the two-way comparison for a patch withoutsteps, the one for a step id held by another phase, andmissing_idfor a phase.Comparison with
main. I ran 20,000 random command sequences (163,757 commands) against a build ofmainand a build of this branch. The sequences mixcreate, everyupserttarget,upsert-with-template,update_status,next,show_statusandquery. After each command I compared the result and the plan file.entire_planpatch that names a phase already in the plan and carries astepsarray for it.The two paths against each other. For 20,000 random stored plans and phase patches I sent the patch both ways and compared the error, the stored phases and the write result.
mainBuilt CLI and MCP. The outputs in "Before and after" come from the built binary of each side.
Behaviour changes to note
Each row is a run of the built CLI. The patch is the
phasesitem sent toupsert <file> entire_plan. In rows 1 to 3,p1holdss1(complete) ands2(open). In row 4,p1holdss1, and a step ofp2depends ons1.p1main{"id":"p1","steps":[]}p1has no stepss1(complete) ands2stay{"id":"p1","steps":[{"id":"s1","name":"S1 again"}]}p1holds only{"id":"s1","name":"S1 again"}s1is renamed and keepspromptandcomplete;s2stays{"id":"p1","steps":[{"name":"no id","prompt":"x"}]}s1ands2; one more backup{"error":"missing_id"}; file unchanged; no backup{"id":"p1","steps":[{"id":"s3","name":"S3","prompt":"x"}]}{"error":"unknown_dependency"}s3is appended afters1entire_planpatch no longer removes steps from an existing phase. FR-PLAN-0015 defines no step removal through upsert.idin the patch of an existing phase is rejected withmissing_id. The phase target already rejected it.entire_planpatches thatmainrejected are now accepted: the last row above.maindeleted the step that another step depends on, and validation then failed.Out of scope
s3above is stored withoutstatusanddepends_on. I merged this branch with the [Bug]: rosettify plan steps added by upsert-with-template have no status or depends_on #390 fix locally and ran the full suite: 1,685 tests pass, ands3is stored as{"status":"open","depends_on":[],"id":"s3","name":"S3","prompt":"x"}.depends_on([Bug]: rosettify plan next never applies phase depends_on, with or without --target #394). Arrays other thanstepsare still replaced.Version bump:
rosettify3.2.9 → 3.2.10, in its own commit. The PR for the #390 fix bumps to the same number, so whichever merges second needs the next number. I will update it then. The two PRs merge cleanly in either order.