Skip to content

feat(chat): pin a merged fork's reopen to the transcript it was merged from - #34274

Merged
bolichen97 merged 1 commit into
kirodotdev:mainfrom
unstablebrainiac:feat/fork-reopen-identity
Nov 10, 2026
Merged

bolichen97 merged 1 commit into
kirodotdev:mainfrom
unstablebrainiac:feat/fork-reopen-identity

Conversation

@unstablebrainiac

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: Reopening a merged fork from its merge card opens the exact fork that was merged, or says that fork is gone.

A merge card links back to the fork it came from by slot key. A key can be reused: the fork can be deleted and a new chat made under the same name, or a workflow slot can hold another transcript under it. Clicking the card's link would then open the wrong conversation, and nothing tells the user.

This is the backend half of #15957's "merged from" link, which needs a transcript identity it can check.

Why it matters

Without an identity check the dashboard cannot safely show the "merged from" link at all, so on main a merge card never links back to its fork.

Not a goal

What changed (motivation → approach → change)

A transcript's persisted created_at is its identity: a chat made later on the same key gets a new one. So the card records it, and a reopen hands it back for checking.

Part What it does
Card chat_merge_back.py writes the fork's created_at into mergedFrom.createdAt. sanitize_merged_from in slot_buffers.py keeps it (at most MERGED_FROM_MAX_CREATED_AT_CHARS) and reads a card written before the field existed as an empty identity, so earlier merges keep counting
Resume POST /api/chat/slots/{slot}/resume takes an optional expected_created_at (a non-empty string within that bound, else 400 invalid_expected_created_at). When the transcript it would return is another one, it answers 409 resume_identity_mismatch

The check runs on both resume paths. A live slot's answer goes through _pinned_live_outcome, which reads the identity of the transcript the slot holds, not the slot's construction stamp. A hydrated resume compares the metadata line it already reads. For an app caller the pin is judged only after _app_resume_refusal admits it, so a missing key and another owner's key both stay the same 404.

_pinned_live_outcome lives in a new owner, chat_api/resume_identity.py, composed into the chat_handlers facade like resume_window, which keeps resume.py under the 2,000-line cap. For the same cap the parent-turn outcome tests move unchanged from test_chat_merge_back_merge.py into test_chat_merge_back_merge_turn_outcome.py. The dashboard module spec documents the field and the new owner.

Backwards compatibility

Compatible: expected_created_at is optional and a resume without it behaves as on main. A merge card main wrote, with no createdAt, still parses and counts.

Removes nothing: the diff adds an optional request field, an optional card field and a refusal that only a caller sending the new field can get.

Tests

  • test_dashboard_chat_history.py (TestResumeExpectedIdentity, TestPinnedResumeOfALiveSlotBoundToAnOlderTranscript): a matching pin resumes, a mismatched or invalid one is refused, a live slot is judged by the transcript it holds, an app caller gets the same 404 for a missing and a foreign key, and an AST check fails if any live-slot probe in _resume_slot_from_history_noted returns without the pin.
  • test_chat_merge_back.py: the card records createdAt; sanitize_merged_from refuses a present non-string or over-long one and reads a missing one as "".
  • test_members_dm_thread_resume_and_reservation.py, test_slot_ownership_checkpoint.py: the pin on crewmate threads and app-owned slots.
  • test_chat_handlers_composition_contract.py: the facade surface with the new owner and parameter.
  • The remaining test edits add createdAt to card fixtures.

Manual verification

N/A: the only caller that sends expected_created_at is #15957's dashboard link, and the route behaviour is covered end to end against a real conversation log.

Related Issues

Part of #3816. #15957 builds on this.

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

@github-actions github-actions Bot added fork Pull request from a fork (external contributor) readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Nov 10, 2026
@unstablebrainiac
unstablebrainiac force-pushed the feat/fork-reopen-identity branch from 95481ea to 20e5d8c Compare November 10, 2026 03:39
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Nov 10, 2026
@unstablebrainiac
unstablebrainiac force-pushed the feat/fork-reopen-identity branch from 20e5d8c to ac6786e Compare November 10, 2026 03:54
@github-actions

github-actions Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review (fork) — ✅ no blocking findings

Reviewed e114ec74430285ec027459e32cc4fcd0d6d39a90 via the fork AI-review pipeline; updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] e114ec7

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Nov 10, 2026
…d from

A merge card records the fork transcript's persisted created_at as
mergedFrom.createdAt. Resume now accepts it as an optional
expected_created_at and answers 409 resume_identity_mismatch when the
transcript it would return is a different one, on both the live-slot and
the hydrate paths. Callers that omit it are unchanged.

The live-slot check lives in a new chat_api owner, resume_identity, so
resume.py stays under the line cap. The parent-turn outcome tests move from
test_chat_merge_back_merge.py into test_chat_merge_back_merge_turn_outcome.py
for the same reason.

Part of kirodotdev#3816.
@unstablebrainiac
unstablebrainiac force-pushed the feat/fork-reopen-identity branch from ac6786e to e114ec7 Compare November 10, 2026 05:27
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Nov 10, 2026
@github-actions

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5, fork) — ⏭️ skipped

Revision e114ec74430285ec027459e32cc4fcd0d6d39a90 touches no user-facing surface (no changes under website/ or committed screenshots), so the UX review was skipped. Does not block merge.

@github-actions

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5, fork) — ✅ PASS

Design-level review of e114ec74430285ec027459e32cc4fcd0d6d39a90 via the fork AI-review pipeline — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

Design-Verdict: PASS

No design-level concerns: the transcript's existing created_at is used as the pin, the field is optional on both the card and the request, and an older card still parses.

[DESIGN-REVIEWED] e114ec7

Description read

[DESCRIPTION-READ] 84431869f8358784a14d026a952e994e9089341ba75c4398210aa53942ecda54

That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5, fork) — ✅ PASS

Premise-level review of e114ec74430285ec027459e32cc4fcd0d6d39a90 via the fork AI-review pipeline — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

First-Principles-Verdict: PASS

Nothing blocks. The new request field and the new card field have no reader in this tree yet. Both can be withdrawn without breaking anyone, so this is a note.

Notes

Inventory (8 items) — 6 justified

Intent: let someone reopen a merged fork from its merge card and get the exact fork, or be told it is gone. This is an ADDITION (the backend half of #15957).

  1. Merge cards now record the fork's creation identity (mergedFrom.createdAt) — zero consumers, nothing reads it until feat(chat): merge a fork back into its parent chat #15957
  2. Resume accepts an optional expected_created_at and answers 400 when it is malformed — zero consumers
  3. A pinned resume of a different or missing transcript answers 409 resume_identity_mismatch, on both the live path and the hydrated path — justified
  4. Merge cards written before this change, with no createdAt, still parse and still count — justified
  5. An app's pin is judged only after the isolation check, so a missing key and another owner's key give the same 404 — justified
  6. The live-slot check moves into a new resume_identity.py owner to stay under the line cap — justified
  7. The parent-turn outcome tests move unchanged into a new test file for the line cap — justified
  8. The dashboard spec documents the field and the refusal — justified

[FIRST-PRINCIPLES-REVIEWED] e114ec7

Description read

[DESCRIPTION-READ] 963d93ecc8dd2ade797138417cb6335e2c490b92c6307360302a888d7ab9cf8d

That sha256 names the PR description this verdict read. Recompute it with .github/scripts/pr-description-capture.sh; if it differs, the description changed after this verdict was formed and any finding drawn from the description is unproven.

@github-actions

Copy link
Copy Markdown
Contributor

GPT 6.1 Review (fork) — ✅ no blocking findings

Reviewed e114ec74430285ec027459e32cc4fcd0d6d39a90 via the fork AI-review pipeline; updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] e114ec7

@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running labels Nov 10, 2026
@KiroCrewCaptain

Copy link
Copy Markdown
Collaborator

This adds a new concept, so it needs a design sign-off from a maintainer before it can merge. A maintainer will post the decision here. To propose a design, follow the request-for-change process in CONTRIBUTING.md (docs/request-for-change/).

Review result on e114ec7: no blocking findings. The review read the full source diff and checked these points:

  • All four live-slot resume paths go through _pinned_live_outcome. A refusal passes through unchanged, so a pin cannot reveal whether another owner's session exists.
  • On the hydrate path, an app caller's pin is judged only after _app_resume_refusal. A missing key and a foreign transcript give the same 404, and tests pin that.
  • A dashboard caller with a wrong pin is refused before any write.
  • sanitize_merged_from still accepts cards written before this change, which have no createdAt.
  • The 311-line test move is verbatim.

One thing done well: the live-slot tests set slot.created_at apart from the transcript's own identity. If someone later "fixes" the code to read the constructor stamp, a test goes red.

Context for the maintainer: #17165, the backend half of merge-back by the same author, is already on main. This PR extends it to the card and to resume, and #15957 is stacked on it.

Optional:

  • The route's 400 invalid_expected_created_at is tested only for an empty string. A parametrized case for a non-string value and for one over MERGED_FROM_MAX_CREATED_AT_CHARS would pin the other two branches (resume.py:604).
  • An unreadable metadata line gets the same 409 resume_identity_mismatch as a fork that is gone. A separate code would let a client offer a retry (resume_identity.py:56).
  • The new field has no caller until feat(chat): merge a fork back into its parent chat #15957 lands. Merging the two back to back keeps the goal visible. resume.py is also now 1966 lines, so the hydrate-path pin block could move into resume_identity.py.

@bolichen97 bolichen97 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving at e114ec7. Thank you.

  • A merge card now records the fork transcript's persisted created_at as mergedFrom.createdAt (chat_merge_back.py, from fork._disk_meta_created_at). slot_buffers.py reads it back bounded by MERGED_FROM_MAX_CREATED_AT_CHARS. A card written before this has no createdAt and still counts, so an older merge is not repeated.
  • The resume route takes an optional expected_created_at. A caller that omits it gets exactly main's behavior. A supplied one is checked before any slot is returned or published: an empty, non-string or over-long value answers 400 invalid_expected_created_at, and a transcript or live slot whose identity differs answers 409 resume_identity_mismatch. So a merge card's link opens the fork it came from and never a different chat that took the key.
  • _pinned_live_outcome (resume_identity.py) compares against the identity of the transcript the slot holds (_disk_meta_created_at, else the disk line), not slot.created_at, which is only the constructor's clock.
  • For an app caller, the pin is judged only after _app_resume_refusal admits the app, so a missing key and another owner's session both answer the same 404, and the pin cannot be used to tell them apart.
  • The new 400 and 409 apply only to the new optional field, so nothing main allows is refused. No regex.

All 94 checks on this head are green.

@bolichen97
bolichen97 merged commit 0b97b24 into kirodotdev:main Nov 10, 2026
94 checks passed
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Nov 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fork Pull request from a fork (external contributor)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants