Skip to content

feat(sessions): file an arriving session under Imported / from <sender> - #12196

Merged
chenmingwei23 merged 1 commit into
mainfrom
fix/imported-session-provenance-11468
Sep 21, 2026
Merged

chenmingwei23 merged 1 commit into
mainfrom
fix/imported-session-provenance-11468

Conversation

@chenmingwei23

@chenmingwei23 chenmingwei23 commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

A session can arrive on an instance two ways. A peer pushes one over an Instances
tunnel, and a person installs one exported by GET /api/chat/slots/{slot}/export.
Both land at the top level of the sidebar, mixed in with the sessions the person
started themselves.

The receiving code says so deliberately: api_chat_slot_import in
src/kiro_crew/dashboard/session_transfer.py composes the imported slot's
metadata with no folder_id, and its comment records that the session "lands
unfiled just as the tunnel importer always has".

Why it matters

"Where did this session come from" has no durable answer. The arriving tab
carries a marked title, and a title is renameable prose: once it is edited,
nothing on the session says it was not started here. On an instance that receives
from several peers the top level becomes a pile with no grouping, which is the one
thing the sidebar's folders exist to prevent.

What changed (motivation -> approach -> change)

Decision record. For the tunnel route this is a changed default, and the
decision is recorded in
docs/request-for-change/rfc-arrival-provenance-filing.md, which lands in
#12189. This PR is based on that branch rather than shipping the document, so
the RFC is on the base branch by the time this is reviewed, exactly as the PR
template requires. The base retargets to main automatically when #12189 merges.

Goal. An arriving session is filed under a folder named Imported, in a child
named from <sender>, for both arrival routes.

Approach. POST /api/chat/slots/import is the only server route behind both
arrivals, and it already decides gzip from plain JSON by sniffing the body's first
two bytes. A gzipped file from a person and a plain-JSON bundle from the tunnel
are the same event carried by different transport, so the encoding must decide
neither how the bytes are read nor where the session lands. One filing call in
that one handler is therefore the whole feature; the alternatives (and why filing
only the file route is rejected rather than deferred) are in section 6 of the RFC.

What was built.

  • src/kiro_crew/dashboard/arrival_folders.py: arrival_folder_id resolves the
    destination and arrival_folder_exists re-checks it. The transaction shape is
    taken from ensure_channel_folder in dashboard/channel_folders.py, which is
    this repository's existing name-matched find-or-create folder path.
  • session_transfer.py: one filing call placed as the last await before the
    durable save, plus the repair after the slot is re-registered.
  • docs/system-specs/modules/instances.md section 14.5a: the arrival section now
    carries two rules instead of one, with the four properties that make the write
    safe on an authenticated route.

The six folder-lifecycle constraints from RFC section 5, and where each is
enforced:

  1. An app-scoped arrival creates no folder and adopts none. The store has a
    global MAX_CHAT_FOLDERS ceiling, so an app token that could create a folder
    per arrival could loop imports with distinct origin values until the person
    is refused a folder of their own; adopting instead would file peer content into
    a row the person owns. The identity comes from the shared
    effective_request_app rule, not from request.get("app") alone -- the two
    differ for a caller that carries no app claim but does carry a session key an
    app owns, which is precisely the caller that must be refused.
  2. Placement is resolved only after the slot exists. The handler re-checks the
    live-slot cap after its last await and can answer 429 there; a folder
    written in front of that check is left behind when it fires, which is the same
    store exhaustion with a narrower trigger.
  3. Find-or-create is atomic across both levels, inside one mutate_folders
    transaction, so two arrivals from one peer cannot each create a folder with the
    same name and a delete of Imported cannot land between the two appends.
  4. A folder is looked up in the form the store writes it.
    create_folder_record trims and clips a name to 100 characters, so
    store_folder_name mirrors that before the lookup; a test reads the clip out
    of create_folder_record's own source rather than restating the number.
  5. A folder deleted mid-import leaves no dangling id. For the finalisation
    stretch the slot is retracted from state._slots, which is the mapping the
    folder delete handler's unfile sweep iterates, so the folder is re-checked
    immediately before the durable save and repaired after the slot is registered
    again.
  6. Filing is best-effort. A ceiling refusal or a store write failure lands the
    session unfiled rather than failing an import that works today.

<sender> is the bundle's redacted origin. It names a folder and confers
nothing: origin is a field of an untrusted bundle and is never read as an
identity. A bundle with no origin is filed under Imported directly rather than
under an invented "from unknown". Folder names are ASCII English literals, because
a folder created here is an ordinary sidebar row a person can rename and a name
re-derived per render from the active locale would fight that rename.

Backwards compatibility

Compatible for every contract: no field becomes required, no validator narrows, no
kind is removed and no key is renamed. The bundle format is untouched, so a peer
that has not shipped this still imports and is still imported from.

The user-visible default does change for the tunnel route -- a peer-pushed session
lands in a folder instead of at the top level -- which is what #12189 records. It
is reversible by deleting the Imported folder: the delete handler's own unfile
sweep returns its sessions to the top level, and a later arrival recreates the
folder, matching ensure_channel_folder's existing behaviour.

The import route also gains two response codes, deliberately, and this is a
contract change a peer sender sees. POST /api/chat/slot-import previously
answered 200 ok for a session deleted while the import was finishing, because
nothing asked. It now answers 409 with transfer_import_deleted when nothing
was kept, and 409 with transfer_import_deleted_partial when a transcript file
remains on disk that this instance cannot safely remove. Both are retryable and
the second only differs in what it promises about the leftover.

The peer-sender impact: a sender that treats any non-200 as a hard failure will
now report a failure it used to report as success, which is the correct reading --
the session was destroyed mid-install. A sender that distinguishes codes can
retry on either one. No existing code changes meaning, no success response gains
or loses a field, and a sender that has not shipped this simply sees an
unrecognised 409.

Tests

test/test_arrival_folders.py (new, 20 cases) covers the resolution: the first
arrival creating both levels, adoption on a second arrival, the case-insensitive
name match, the parent-scoped lookup that keeps an unrelated top-level from mac
from being mistaken for the child, the clipped-row adoption, the sender-less
bundle, the hidden-folder re-engage, the app-scoped refusal in both directions,
the ceiling refusing the pair rather than half-landing it, a full store still
filing under an existing group, the store-write failure, and the existence
re-check including its fail-closed-to-gone branch. The module measures 98%
statement coverage.

test/test_session_transfer.py adds 10 handler cases: a plain-JSON arrival filed,
a gzip arrival reaching the identical folder (the format-independence property),
an app-scoped arrival unfiled, identity taken from the shared caller rule, a
second arrival from one sender landing beside the first, two senders under one
group, a sender-less bundle, placement resolved after the slot exists, a folder
deleted during finalisation leaving no dangling id, and a store failure leaving
the session unfiled. Its shared _stub_state now models mutate_folders /
read_folders, so the existing import tests exercise the shipped filing path
rather than the unfiled fallback.

Red at the base: 6 of those 10 handler cases fail when the implementation is
removed. The other 4 assert an ABSENCE (unfiled, no folder created), so they pass
at the base by construction and are guards on the refusal paths rather than proofs
of the feature.

Mutation-checked: eight mutations applied, all eight killed, with the baseline
green before and after the run -- resolving placement before the slot exists,
reading identity off the request claim alone, dropping the post-registration
repair, dropping the store-form clip, allowing an app-scoped create, testing the
ceiling per append instead of on the pair, ignoring the parent in the lookup, and
splitting the resolution into two transactions. The clip mutation survived a first
pass because that test derived its fixture from the function under mutation; the
fixture is now spelled out independently and the mutation is killed.

Manual verification

N/A -- unit coverage sufficient. The feature is a server-side folder write with no
new UI: the folders it creates are ordinary sidebar rows drawn by the existing
tree, and the placement is asserted through the real handler rather than a fake.

Related Issues

Closes #11468
Based on #12189 (the RFC this change implements)

Known base failure, not from this change

main is currently broken at module scope: src/kiro_crew/sandbox.py fails an
import-time set-equality assert, so nothing that imports the package collects.
Reproduced on pristine origin/main with none of this code present, and bisected
to commit 4ed7335d8 (which landed #11556); tracked as #12182 and #12183. This
diff touches neither sandbox.py nor any of its inputs, so the fix belongs there
and is deliberately not folded in here. The tests above were measured with that
one main-owned assert neutralised in the working tree and restored byte-identical
afterwards; they will be measured by CI on their own once main heals.

@chenmingwei23
chenmingwei23 requested review from a team and hoang-phan98 and removed request for a team September 20, 2026 05:06
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Sep 20, 2026
@github-actions

github-actions Bot commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Fable 5) — 🟡 CONCERNS

Design-level review of 867a9992af8504edd4b3729e90b15e4371b603a2 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

Design-Verdict: CONCERNS

Best-effort filing grew a rollback protocol the RFC never asked for; roughly half the machinery guards against one empty folder the next arrival would adopt anyway.

Watch

  • The failed-import rollback (discard_arrival_folders) needs three supporting mechanisms to be safe — created_rows fingerprints, the persisted arrival_adopted mark, and the note_folder_filed occupancy set wired into the unrelated manual-filing handler — and the diff still documents two unreclaimable residuals (the cancellation arm, a delete landing in the mark's await). The harm it prevents is one empty, self-healing folder pair per origin ("without this the failed import leaves an empty row behind"), which sits inside RFC constraint 6's own best-effort envelope; find-or-create adopts the leaked row on the next arrival, so the leak is bounded, and the store ceiling stays fillable via successful imports with distinct attacker-chosen origins regardless. RFC §6 measured folder-shape alternatives but never leave-behind vs. rollback.
    Clears when: the PR or RFC records why leave-behind-and-adopt is insufficient, or the discard/mark/occupancy machinery is dropped.
  • Per the description, main is broken at test collection, so every claimed test result (red-at-base, mutations, coverage) was measured locally with a main-owned assert hand-neutralized; CI has never run this suite.
    Clears when: a green CI run on this branch after the main broken: sandbox.py module-level leaf-set invariant fails on import since 4ed7335d8 (#11556) #12183 fix lands on main.

Suggestions

  • Drop the rollback protocol: on any failure path leave the created pair in place; this deletes discard_arrival_folders, mark_arrival_folder_shared, note_folder_filed/folder_ids_filed_into, the created_rows plumbing, and the shared-mark unfiling block, while keeping every RFC constraint satisfied.

[DESIGN-REVIEWED] 867a999

@github-actions

github-actions Bot commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Fable 5) — 🟡 CONCERNS

Premise-level review of 867a9992af8504edd4b3729e90b15e4371b603a2 — 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/CONCERNS are advisory.

First-Principles-Verdict: CONCERNS

The failed-import folder rollback and its guard cascade defend against a residue the RFC and this PR's own cancellation arm both call recoverable by hand.

Not justified as shipped

  • Item 6 — rides along: the 409-on-deleted-session fix is declared and its tests fail on base, but it is not the RFC'd feature.
  • Item 7 — zero consumers: grep transfer_import_deleted finds only the defining site, docs and tests; the description itself says "a sender that distinguishes codes can retry on either one".
    Subtraction: delete transfer_import_deleted_partial and session_transcript_remains; answer the one code.
    Clears when: a counted consumer treats the two codes differently, or the partial code is deleted.
  • Item 8 — oversized: the RFC's §5 lists six constraints and no rollback; its §2 calls a stray folder one-click reversible, and this PR's cancellation arm accepts exactly this residue as "recoverable by hand".
    Subtraction: delete discard_arrival_folders, created_ids/created_rows/hidden_ids, _is_untouched_arrival_row and all three call sites.
    Clears when: the deletion is made, or a harm beyond one empty deletable row is named (a cap-exhaustion path a non-app caller can actually drive).
  • Item 9 — symptom-level: ARRIVAL_ADOPTED_KEY is permanent persisted bookkeeping patching a hole item 8 opened, against the module's own "leaves no bookkeeping in the store".
    Clears when: deleted with item 8.
  • Item 10 — symptom-level: note_folder_filed's never-shrinking set patches the next hole down; 1 consumer.
    Clears when: deleted with item 8.

What this change ships

Inventory (10 items) — 5 justified

Intent: give an arriving session a durable "where it came from" by filing it under Imported / from — an ADDITION (a changed default for the tunnel route). More than 10 items exist (unhide-on-arrival, save pinning, layer-B unwinding); the 10 most visible are kept.

  1. Arriving sessions land under Imported / from <sender> instead of the top level — justified
  2. A bundle naming no sender files under Imported directly — justified
  3. An app-scoped arrival stays unfiled, with a SEL denial event — justified
  4. A folder deleted mid-import leaves the session at the top level, not dangling — justified
  5. A filing refusal never fails the import — justified
  6. A session deleted mid-import now answers 409, not 200 ok — rides along, declared fix beside the feature
  7. A second 409 code discloses a leftover transcript file — zero consumers of the distinction
  8. A failed import deletes the folders it created — oversized, beyond the recorded RFC shape
  9. Adopted folder rows carry a permanent arrival_adopted key — symptom-level, serves item 8 only
  10. Every manual folder placement is recorded in an unbounded in-memory set — symptom-level, serves item 8 only

[FIRST-PRINCIPLES-REVIEWED] 867a999

@github-actions

github-actions Bot commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

Opus 4.8 Review — ✅ no blocking findings

Reviewed 867a9992af8504edd4b3729e90b15e4371b603a2 — this comment is updated in place on each push.

Review details

The candidate requires: a hidden pre-existing Imported group (populating hidden_rows with the group id), a newly-created child destination (slot.folder_id = child_id), and then that just-created child folder being deleted by a concurrent DELETE inside the narrow finalisation await window so the folder-gone repair clears slot.folder_id. Only then does adopted_destination go False while hidden_rows stays non-empty, and mark_arrival_folder_shared(state, "", unhide=hidden_rows) un-hides the group.

That input is a speculative race — deleting a folder the import itself created milliseconds earlier, within one await — i.e. an "if a caller were to delete it" condition, not one that occurs in practice. And even granting it, the outcome is a single reversible visibility flip on one sidebar row; the module's own contract treats the mirror case (mark_arrival_folder_shared docstring) as leaving "a row merely hidden, which the person can reverse and which costs the placement nothing." No data loss, no crash, no security boundary crossed. It fails the (a) concrete-input bar and the (c) consequence bar, scoring well below the 80 threshold.

No other production hunk yields a grounded defect at the required bar.

No findings.

[OPUS-REVIEWED] 867a999

Verdict parsed from the review's SHA-scoped output markers for commit 867a9992af8504edd4b3729e90b15e4371b603a2.

False positive or not applicable? A repository writer can comment:
/ai-review override fable 867a9992af8504edd4b3729e90b15e4371b603a2: <one-sentence reason>

@github-actions

github-actions Bot commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

GPT 5.6 Review — ✅ no blocking findings (all downgraded on adjudication)

GPT 5.6 flagged blocking issues on 867a9992af8504edd4b3729e90b15e4371b603a2; Opus 4.8 adjudication downgraded every one of them to advisory. Adjudication downgraded all 1 blocking finding(s) to advisory: the remedy each one requires is disproportionate to the harm it prevents. Read them as advice, not as merge conditions.

This comment is updated in place on each push.

Review details

BLOCKING -- src/kiro_crew/dashboard/session_transfer.py:1874 -- Cancellation leaks committed arrival folders
filing = await arrival_folder_id(state, origin=origin, request_app=folder_app) / raise
Gateway shutdown after folder commit -> cancellation arm skips folder rollback -> empty persisted folders consume the finite folder cap.
Anchor: persist-before-you-publish
Fix: Shield the filing transaction and shield/drain discard_arrival_folders before re-raising cancellation.
[BLOCK-MERGE-DOWNGRADED] 867a999
[GPT-REVIEWED] 867a999

Adjudication (Opus 4.8) — is blocking on each finding proportionate?

I've opened the code F1 names and the arms it references.

F1 — The cancellation arm (session_transfer.py:1926-1946) deliberately skips folder rollback. The author documented this explicitly: discard_arrival_folders is async because the folder store's lock is (line 1939-1941), and awaiting/scheduling it in a cancelled task is dependable only for a client disconnect, not a shutdown — so it would "trade a plain gap for one that looks closed."

Evidence record:

  • (a) Conditions: cancellation (CancelledError) must arrive after the folder commit at line 1874/1879 (where created_rows is populated) and reach the except arm at line 1926; the arm's "No folder rollback here, deliberately" at line 1939 leaves the created folder rows in place.
  • (b) Recovery: the leaked folder row is visible and manually deletable — line 1944-1945: "still leave an empty row, which the row's own visibility makes recoverable by hand." Not silent; not automatic, but recoverable.
  • (c) Harm rung: LOW — a rare, visible, self/manually-recoverable degradation. It requires a cancellation landing in the narrow window between the last await before save and its completion, produces a visible empty row, and each is individually removable. The finite folder cap is only threatened by accumulation of these rare, visible leaks. The real fix (shielding an async drain inside a cancelled task) is a mechanism existing only for this one path, adding permanent maintenance load, and by the author's own documented reasoning cannot reliably cover the dominant shutdown case anyway. Remedy cost clearly exceeds a LOW, visible, recoverable leak.

[ADJUDICATION] 867a999 total=1 uphold=0 downgrade=1
DOWNGRADE F1 src/kiro_crew/dashboard/session_transfer.py:1874 reason=disproportionate-remedy
[GPT-ADJUDICATED] 867a999

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 867a9992af8504edd4b3729e90b15e4371b603a2: <one-sentence reason>

@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 Sep 20, 2026
@chenmingwei23
chenmingwei23 force-pushed the docs/rfc-arrival-provenance-filing-11468 branch from f5d9f4b to 8fe666f Compare September 20, 2026 06:31
@chenmingwei23
chenmingwei23 force-pushed the fix/imported-session-provenance-11468 branch from 30ac1b6 to d25e3a7 Compare September 20, 2026 06:33
@github-actions

Copy link
Copy Markdown
Contributor

GPT 5.6 Review — ⚠️ review incomplete

GPT 5.6 did not produce a complete verdict for d25e3a730addd9f8c91c4143124c800d8b03a0aa; inspect the workflow logs and re-run it.

This comment is updated in place on each push.

See the GPT 5.6 Review job logs; this commit has no completed GPT verdict.

False positive or not applicable? A repository writer can comment:
/ai-review override gpt d25e3a730addd9f8c91c4143124c800d8b03a0aa: <one-sentence reason>

@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Sep 20, 2026
@chenmingwei23
chenmingwei23 force-pushed the fix/imported-session-provenance-11468 branch from d25e3a7 to 6843c56 Compare September 20, 2026 07:15
@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 Sep 20, 2026
@github-actions

Copy link
Copy Markdown
Contributor

GPT 5.6 Review — 🔴 changes requested (blocking)

GPT 5.6 found at least one blocking issue that must be resolved before merging 6843c563ac44ecde1e14607f56f8717a4ef0a996. Adjudication produced no [GPT-ADJUDICATED] marker for 6843c56: the adjudication stage FAILED TO RUN (its raw output is in the Adjudication details block -- typically an API or setup error), so no proportionality review took place and GPT's blocking verdict stands unreviewed.

This comment is updated in place on each push.

BLOCKING -- src/kiro_crew/dashboard/arrival_folders.py:163 -- App filing denial is not SEL-audited (origin: validation)
if request_app: / return ""
App-scoped import -> arrival_folder_id denies filing -> audit records no permission denial
Anchor: backend-security-controls
Fix: Emit a denied SEL event before returning.

[BLOCK-MERGE] 6843c56
[GPT-REVIEWED] 6843c56
False positive or not applicable? A repository writer can comment:
/ai-review override gpt 6843c563ac44ecde1e14607f56f8717a4ef0a996: <one-sentence reason>

@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 Sep 20, 2026
@chenmingwei23
chenmingwei23 force-pushed the fix/imported-session-provenance-11468 branch from 6843c56 to db2900e Compare September 20, 2026 08:05
@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 Sep 20, 2026
@chenmingwei23

Copy link
Copy Markdown
Contributor Author

Round update: one blocking finding fixed, two advisory items dispositioned

Head is now db2900ee03e4a0fb5c8d5f2a1dd891efca3482ac.

GPT 5.6 blocking finding: upheld and fixed

BLOCKING -- src/kiro_crew/dashboard/arrival_folders.py:163 -- App filing denial is not SEL-audited

Real, and the module's own code is the proof. arrival_folder_id already audits the
GRANT (operation="chat.arrival_folder_create", outcome="allowed",
source="session_import"), so the app-scoped refusal one branch above it was the only
decision in the function that wrote nothing. AUTOSDE.yaml's
backend-security-controls rule is explicit that the event is owed for every
permission decision, grants included -- docs/system-specs/modules/app-kit-platform.md
states it as "Every decision is audited, grants included."

Auditing one side is worse than auditing neither: an auditor filtering
source="session_import" would see every folder an arrival created and no trace of
the arrivals refused one, so the absence reads as "no app ever imported."

The refusal now emits the denial, shaped to pair with the grant it sits beside:

sel().log_api_access(
    caller=request_app,
    operation="chat.arrival_folder_create",
    outcome="denied",
    source="session_import",
    resources=f"origin={origin}",
    error="an app-scoped arrival is never filed",
)

Four choices worth naming:

  • Same operation as the grant, so the pair reads as one decision with two
    outcomes rather than as two unrelated events.
  • Reason in error, not in source. The sibling folder CRUD handler uses
    source="app_isolation" for its own app denial, but this module already owns
    source="session_import"; keeping it there means one filter returns the whole
    pathway.
  • caller=request_app -- the app's own identity, matching
    chat_folders.py's app-isolation denial, not a flat "dashboard".
  • Non-critical (the default). A non-critical SEL write swallows and warns rather
    than raising, which is what keeps this function's documented never-raises contract
    true. Filing is best-effort, so an unwritable audit log must not fail an import
    whose transcript landed.

No dedup window, unlike the per-frame event gate that needs one: this is one event per
import request, a rate the handler's live-slot cap already bounds.

Test test_the_app_scoped_refusal_is_audited_as_a_denial asserts the discriminating
fields, not the call count, so it cannot pass against a grant-shaped event.
Mutation-checked both ways: deleting the call reddens exactly that test, and flipping
outcome to allowed reddens exactly that test. 178 pass.

Separately, the adjudication stage did not run for 6843c563, so that verdict stood
unreviewed. The finding was decided on its own merits against the written rule rather
than on the missing adjudication.

First Principles, advisory: does a peer's push re-surface a hidden folder?

Yes, and it is intended.

The rule is chat_folders._unhide_folder, whose own terms are "reviving or moving a
session into a folder un-hides it so it stays visible until the user hides it again."
The trigger is a session entering the folder, not who caused the entry. An arrival is
a session entering the folder.

Sizing the capability:

  • An app can never reach it. The app branch answers "" before the folder store is
    read at all, so the un-hide is unreachable from an app token.
  • A peer that can push a session is already writing a whole transcript into this
    instance. Un-hiding one folder row is strictly weaker than the capability it
    already holds.
  • The effect is recoverable in one click.

Honouring hidden instead has the worse failure: the session still arrives, and it
lands in a row the person cannot see. Someone who hid Imported last month would
then have arriving content with no visible home, which defeats the property this PR
exists to provide -- that "where did this session come from" has an answer.

Left as is. If a maintainer prefers the stricter reading, the change is one branch in
_resolve and it is worth its own issue rather than a quiet flip here, because it
changes what a person sees after an arrival.

Design, advisory: is CI green now that main healed?

Split answer, because the two PRs in this stack do not have the same board.

Main's break was its own: an import-time assert in sandbox.py killed conftest.py,
so every backend, E2E and build lane died before any test ran. PR #12193 fixed it and
is an ancestor of current main.

So the honest statement is that this PR's readiness is computed over a reduced lane
set, and its full board only becomes available once its base is main -- that is,
once #12189 merges. It is not being reported as green on the reduced set.

Local evidence in the meantime, run against the rebased tree: test_arrival_folders.py
and test_session_transfer.py pass, 178 tests, which also exercises the import path
whose collection was previously broken. Black, isort, flake8, mypy, the error-code
contract, brand, docs-lint and comment-history all pass on the changed files.

@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 Sep 20, 2026
@chenmingwei23
chenmingwei23 force-pushed the fix/imported-session-provenance-11468 branch from db2900e to cde5f88 Compare September 20, 2026 08:31
@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 Sep 21, 2026
@chenmingwei23
chenmingwei23 force-pushed the fix/imported-session-provenance-11468 branch from ad3742d to 89cca7a Compare September 21, 2026 06:33
@github-actions github-actions Bot removed the readiness: action required A blocking check or review needs attention label Sep 21, 2026
@chenmingwei23

Copy link
Copy Markdown
Contributor Author

Round note -- the three reds on ad3742dc were one cause

Head 89cca7a136676ce4a9911372bd10283df75f1430, rebased onto current main (one commit, 6 files).

Comment History Gate, Await Fast Gate and Coverage Gate all failed. One cause: the comment-history gate flagged two added lines carrying the phrase "no longer" in arrival_folders.py. Every test job in the CI run needs the Fast Gate, so all of them skipped, and Coverage Gate (if: always()) then failed because its upstream coverage jobs had skipped rather than succeeded. Nothing was measured about the change itself.

Fixed by stating the rule in present tense instead of narrating what a mark at adoption time did: the constant's docstring now reads "each mark the other's brand-new rows, so each rollback spares rows nothing is ever filed into", and both places now say "past the last point that can refuse the import".

Worth recording for anyone reproducing this gate locally: scripts/check_comment_history.py run bare is NOT a verdict. It prints a report and exits 0 with "Not enforced here; set COMMENT_HISTORY_BASE_REF to gate a change." My earlier local run was that non-gating form, which is why this reached CI. Gated locally it reproduces exactly:

COMMENT_HISTORY_BASE_REF=origin/main python scripts/check_comment_history.py

197 tests pass with -n0 across the two related files. black, isort, flake8, the black gate, brand, docs-lint, comment-history (gated) and changelog-history all pass. No behaviour changed in this push: it is comment text only, so the mutation results from the previous note still hold.

One thing the rebase brought in that is not this PR's: mypy reports backup.py:2526 Missing named argument "payload_kind" for "_authorize_upload" in apps/builtins/aws_control. That call and that signature are both byte-identical to origin/main, and this PR's diff does not touch the file, so it is inherited. If Backend Lint & Type Check reds on it I will report it separately rather than fold an unrelated fix in here.

@chenmingwei23

Copy link
Copy Markdown
Contributor Author

The one red at 89cca7a136676ce4a9911372bd10283df75f1430 is main-owned

Backend Lint & Type Check (3.12) is red. Two independent steps failed in that
one job, and neither is reachable from this branch's six files.

Cause A -- mypy, and a fix is already in flight

src/kiro_crew/apps/builtins/aws_control/backend/backup.py:2526: error:
  Missing named argument "payload_kind" for "_authorize_upload"  [call-arg]
Found 1 error in 1 file (checked 1665 source files)

_authorize_upload gained a required keyword-only payload_kind in #12190
(landed on main at 2026-09-21T06:11Z). The call at backup.py:2526 was not
updated with it. mypy is deterministic here, so every tree carrying that file
fails the step.

Attribution, four ways:

  • this branch's diff is six files, none of them backup.py;
  • git diff origin/main HEAD -- src/kiro_crew/apps/builtins/aws_control/backend/backup.py
    is empty, so the file is byte-identical to main;
  • payload_kind, _authorize_upload and check_python_audit appear zero times
    in git diff origin/main...HEAD;
  • current main's own line 2526 still lacks the argument.

#12468 fixes exactly that call site. So the remedy is on main, not here, and a
rerun cannot help: the code under test is main's.

This branch's base IS current main (34fe0de33e40ba9c81f54dd24ab6704927481862),
so there is nothing newer to rebase onto yet either. Once #12468 lands I will
rebase and this step clears.

Cause B -- the Python dependency audit could not run

ERROR: Python dependency audit could not run: audit output carried a
dependency without a name and version

That is scripts/check_python_audit.py refusing at its own
AuditError("audit output carried a dependency without a name and version")
guard, because pip-audit's JSON carried an entry whose name or version was
not a string. It is the audit failing to RUN, not an advisory it found, so it
names no package and reports no vulnerability.

It cannot be this branch's either: the commit touches no dependency manifest at
all -- no requirements*, no pyproject.toml, no lockfile, no setup.cfg.

I have not yet established how wide Cause B is. Two sibling PRs' lint lanes were
still in flight when I measured, so I have no completed second sample. I will say
what it is once I have one, rather than guess now. It is not filed as an issue
yet for the same reason.

Everything else at this head

87 of 89 lanes are success or skipped. Comment History Gate, Await Fast Gate,
Coverage Gate, Coverage Combine, Screenshot Evidence, Docs Lint, all 16
backend shards and both Windows sets pass. GPT 5.6 Review is still running.
PR Readiness is pending behind it.

Nothing about this red is a finding against the change, and nothing in it is
mine to fix.

@chenmingwei23

Copy link
Copy Markdown
Contributor Author

F1 fixed: the absent-key forget is scoped to this import's own sid

Head is now a04f505a5c0ecfdc6d544302345c75f244fe4422. Verified against the checkout before fixing.

The finding is right, and this PR's own comment already named the residual

The current is None arm of _refuse_as_deleted dropped the Layer B join by key alone. The previous head's comment there stated the residual in as many words: "the residual is a foreign MAPPING possibly forgotten, never foreign files." That is exactly what the review found, and forget_conversation clears the continuable mark as well as the map entry, so the loss is a replacement session's whole resume path with nothing to re-arm -- this refusal return is terminal.

The object comparison cannot separate the two cases, because dict.get answers None for an absent key exactly as it does for a replacement that was itself popped.

The fix

if layer_b_sid and _resolve_layer_b_sid(sessions, sm_key) == layer_b_sid:
    _forget_layer_b_join(sessions, sm_key)

This is the remedy the review asked for. Three arms:

  • The mapping names this import's sid: forget it. It must go, since the files behind it are being unlinked on the next line.
  • The mapping names another sid: leave it, along with its continuable mark.
  • This import holds no Layer B at all: forget nothing. Any mapping at the key is somebody else's by construction, which was the worst form of the defect.

The guard is exact rather than approximate. resumable_sid and forget_conversation both resolve _session_map.get on the same folded key (session_allocation.py), so the guard reads the value the forget would report and then delete. Both are synchronous and there is no await between them, so nothing interleaves on the loop.

Scope is this one site. The three sibling _forget_layer_b_join calls in api_chat_slot_import run on arms where the slot was hidden by the construction filter throughout and is still registered under its own key, so no replacement can be holding it there.

Tests

Two new, plus a premise stated in an existing one.

  • test_a_refusal_leaves_a_foreign_join_mapping_alone -- absent key, mapping naming another sid. Asserts both halves in one call: the foreign mapping survives, and this import's own pair is still unlinked, so scoping the forget does not disable the cleanup it genuinely owes.
  • test_a_refusal_without_layer_b_forgets_no_mapping -- no Layer B in the bundle, a mapping squatting at the key. Nothing forgotten, nothing unlinked.
  • test_a_refusal_cleans_layer_b_when_the_delete_left_no_replacement now stubs _resolve_layer_b_sid to this import's own sid. That states its premise, which the equality guard makes load-bearing; the expectation is unchanged.

Three mutations, each killed by its own test:

mutation reddens
drop the guard, forget by key alone both new tests
invert the equality the own-sid test
weaken equality to a presence test the foreign-mapping test

The third is the one that matters: it proves the test pins equality rather than mere presence. Baseline green before mutating, restore verified.

199 tests pass across the two related files. black, isort, flake8, mypy, the black gate, brand, docs-lint and the comment-history gate all pass. One commit, six files, rebased onto current main, clean tree, push guard SAFE, lease sha read on its own.

The spec records the scoped forget and why an absent key is not evidence that the mapping at it belongs to this import.

The two main-owned reds at the previous head

Both were in Backend Lint & Type Check (3.12) and neither was this diff's.

The mypy break at backup.py:2526 is fixed on main by 1dd5a03e, so this rebase clears it. Confirmed locally: mypy over src/kiro_crew is clean at this head.

The dependency audit still refuses because it cannot run -- it names no package. It fails identically on a pristine origin/main worktree with none of this PR's code present, so it is not attributable here.

Residuals, unchanged and disclosed

A cancelled import cannot take back its folder row, because that path does not wait and the folder store does. A leftover transcript is never unlinked, because on two of the three delete-witness outcomes it is not this import's to delete.

@chenmingwei23

Copy link
Copy Markdown
Contributor Author

GPT F1 fixed at aa05ab3d43167c9c811825ed512c9db5cb09b8c9

The finding is real, and it is a consequence of the previous round's fix. Moving
the shared-row mark onto the landed path put an await below the final delete
witness. That await is the last one on the path, so a DELETE /api/sessions/{key}
can land inside it -- past the last check. The delete removes the transcript and
pops the slot, and the handler still publishes 200 ok. Nothing corrects it: the
success return does not re-arm _dirty and the delete's pop is terminal.

The module's own invariant is stated one branch earlier as "ONE WITNESS ON EVERY
PATH TO SUCCESS". The added await broke its unstated second half.

The fix: the mark moves ABOVE the witness

mark_arrival_folder_shared is now called immediately before
session_was_deleted, so no await follows the witness and the invariant holds by
structure rather than by case analysis.

I did not take the suggested remedy. A second witness below the call buys the
same guarantee, and costs either an extra stat on every import that adopted
nothing, or a conditional witness -- which is precisely the case analysis the
unconditional shape exists to avoid. Reordering costs neither, and leaves exactly
one witness.

What the ordering costs, and why it is the right side

A refusal can now follow the mark: a delete landing in that await leaves the row
marked while the import gives up, so the creating import's rollback can never
reclaim it. That is one visible, deletable sidebar row, and only when the creating
import ALSO failed -- the next arrival from that origin adopts the row rather than
making another.

It cannot be unwound here. Taking a mark back needs each import's own claim
recorded on the row, or one import's failure strips another's; that is the
per-import refcount already ruled out. Both the code comment and
docs/system-specs/modules/instances.md record the ordering and this cost.

Tests

One new test, test_a_delete_landing_in_the_shared_row_mark_refuses. The delete is
injected BY the mark, so the witness can only observe it if the witness runs
afterwards. That states the ordering as behaviour, not as a line number, so a
rearrangement cannot satisfy it by accident.

Mutation-checked with a harness that holds the original source in memory, asserts
each mutation applied, and strips ANSI before matching FAILED:

mutation reddened
mark moved back BELOW the witness (this exact bug) 1 -- only the new test
witness call deleted 11

The first row is the point: no other test in the suite catches this ordering,
which is why the finding reached review.

State

200 tests pass in the two related files with -n0. black, isort, flake8, mypy, the
black gate, brand, docs-lint, subprocess-encoding and the comment-history gate
(enforced against origin/main) all pass. One amended commit, six files, rebased
onto current main 3017e6a2, clean tree, push guard SAFE, lease read separately.

Two residuals stay disclosed rather than fixed, unchanged: a cancelled import
cannot take back its folder row, because that path does not await and the folder
store does; and a leftover transcript is never unlinked, because on two of the
witness's three outcomes the file is not this instance's to remove.

@chenmingwei23

Copy link
Copy Markdown
Contributor Author

GPT F1 fixed at c836918c115a4b09cf3fd06f4ffcc5c7d1d92062

The finding is real. The rollback spares a created row on three tests -- a live
slot is filed into it (:443), it carries the adopt marker (:445), or a child
survives (:447). None of them can see an EDIT. A person who renames a brand-new
arrival folder files no session into it, writes no marker and leaves no child, so
all three pass and the rename is deleted with the row.

One correction to the FLAG rationale, in the direction of MORE reachable. It
frames the window as "a single failing save_slot_off_loop". There are three
rollback call sites, and the last is the finalization tail's delete-witness refusal
at session_transfer.py:2087 -- past the transcript save, past the folder-existence
await, past the shared-row mark. So the window is the whole tail including its
awaits, not one synchronous save, and the row is already visible in the sidebar for
all of it. I did not act on the pre-drafted override.

The fix: a fourth guard

discard_arrival_folders now takes ArrivalFiling.created_rows --
(id, name, parent_id) as the resolver WROTE them -- and skips any row that no
longer matches.

Carried rather than stamped on the row. A marker key would leave permanent
bookkeeping on every surviving arrival folder, and removing it on success would add
another await to the tail the previous round just finished clearing. Carrying it
means a surviving row's record stays byte-identical to a hand-made folder's.

_is_untouched_arrival_row has two halves:

  • the content fields must equal what _new_folder emits: name, parent_id,
    project_dir, default_agent;
  • the row must carry no key _new_folder does not emit, which covers color,
    icon, tags and owner_app without naming them. _new_folder's own docstring
    is the anchor: it states an arrival row carries none of them. A key added to the
    folder record later is covered on the day it is added.

order, collapsed and hidden deliberately do NOT count. They are sidebar
position and view state, and they carry nothing a person loses when an empty
auto-created row is removed. Counting them would pin a row in place for a
collapse-arrow click and quietly disable the rollback.

A case-only rename counts as an edit, even though _find treats it as the same
folder on purpose so a person who fixed the capitalisation still owns where the next
arrival lands. Lookup wants those to be one row; deletion wants to know the person
touched this one.

Tests

Three new: an edited row survives, an untouched row is still reclaimed, and a
per-field unit test asserting which fields are content and which are view state.

Mutation-checked with a harness that holds the original source in memory, asserts
each mutation applied, and strips ANSI before matching FAILED:

mutation reddened
fourth guard deleted 1
row compared against itself instead of the snapshot 1
helper stops noticing added keys 1
guard polarity flipped 7

The last row is why the "still reclaimed" companion is not decoration: it has its
own killer. The previous round's two mutations still hold on this head.

State

203 tests pass in the two related files with -n0. black, isort, flake8, mypy, the
black gate, brand, docs-lint, subprocess-encoding and the comment-history gate
(enforced against origin/main) all pass. One amended commit, six files, rebased
onto current main 3017e6a2, clean tree, push guard SAFE, lease read separately.
The spec records the fourth guard, the field split and the corrected window.

Two residuals stay disclosed, unchanged: a cancelled import cannot take back its
folder row, because that path does not await and the folder store does; and a
leftover transcript is never unlinked, because on two of the witness's three
outcomes the file is not this instance's to remove.

@chenmingwei23

Copy link
Copy Markdown
Contributor Author

Disposition of the two advisory CONCERNS at c836918c115a4b09cf3fd06f4ffcc5c7d1d92062

Both lanes concluded SUCCESS and both verdicts are advisory. PR Readiness is green.
Recording a disposition per finding rather than leaving them unanswered, and not
pushing a new head for any of them.

Design "rollback chain" / First Principles item 7 — RETAINED, accepted on the record

Both lanes propose deleting discard_arrival_folders, ARRIVAL_ADOPTED_KEY,
mark_arrival_folder_shared and created_rows, on the grounds that the harm is one
empty deletable row the next same-origin arrival adopts anyway.

That is the same question this PR escalated for a human ruling, and it has been
answered twice: keep the rollback, add the adopted marker inside the existing
transaction, and do not remove the mechanism. The Design lane's own clearing
condition is "a human explicitly accepts the persisted key and guard machinery as
worth the stray-row harm" — that acceptance is what those rulings are.

These two lanes are in direct conflict with the blocking lane on this PR. On the
immediately preceding head, GPT raised a security-class fenced finding REQUIRING a
fourth guard on exactly this rollback: without it a person's rename of a brand-new
arrival folder is deleted with the row. That finding blocked; these do not. Per the
standing rule, the hard-gate fix is retained and the disagreement is recorded here
rather than resolved by silently following the advisory subtraction.

The residual both lanes cite is disclosed and unchanged: a cancelled import cannot
take its folder row back, because that arm does not await and the folder store does.

First Principles item 9 / Design "two 409 codes" — CLAIM CONFIRMED, deferred with reason

I checked the consumer claim rather than taking it on trust, and it is correct:
transfer_import_deleted and transfer_import_deleted_partial appear only at their
two emit sites in session_transfer.py. No frontend code branches on either; every
other status === 409 hit in the web tree belongs to an unrelated feature with its
own code. So nothing distinguishes the two codes today.

Not changed on this head, for two reasons.

The split is the surviving half of a settled decision: a refusal may only claim what
it achieved. The witness reports "deleted" for three different situations, and on two
of them a transcript file remains that this instance must not unlink — a new
incarnation's file is somebody else's session, and an unverifiable read names nothing
safe to remove. Only the third makes "nothing was kept" true. The suggested
subtraction (one code whose message makes no clean-slate promise) preserves that
honesty, so it is a reasonable smaller shape rather than a correction.

And the board is green with zero pending and zero failures. Volunteering a new head
for an advisory subtraction re-rolls the non-deterministic blocking lanes, which have
each produced a fresh finding on four of the last five heads. That trade is not worth
one unread wire code. If a maintainer prefers the single-code shape, say so on this
thread and it is a small follow-up.

Design third watch item — now FALSE, corrected here

It reports that CI has never executed these tests because main failed at collection.
That was true when the PR description was written. At this head all 21 Backend Tests
shards are SUCCESS, along with every Frontend Tests shard, so CI has now executed
them. The board is 79 success, 11 skipped, zero pending, zero failures.

Publishing the correction as a comment rather than editing the description, because a
description edit re-fires the lanes whose triggers include edited — including the
blocking review lane — and the description's remaining claims are accurate.

Main drift

Main has advanced four commits past this branch's base. Those commits touch 13 files
and none of them is one of this PR's six, so the green is not stale against main and
no rebase is required to keep it valid.

@github-actions

Copy link
Copy Markdown
Contributor

GPT 5.6 Review — ⚠️ review incomplete

GPT 5.6 did not produce a complete verdict for 42f7769d5c10a810b9fc39f480325108b24c715e; inspect the workflow logs and re-run it.

This comment is updated in place on each push.

See the GPT 5.6 Review job logs; this commit has no completed GPT verdict.

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 42f7769d5c10a810b9fc39f480325108b24c715e: <one-sentence reason>

@chenmingwei23

Copy link
Copy Markdown
Contributor Author

GPT F1 fixed at 623e67b49f3def0f0dab527166f28ea96bad0556

First, the 09:34Z board was not seven verdicts

Seven lanes failed inside a 22-second window, each at an early data-fetch step, none at a
verdict step: four at Resolve human override (Design, GPT, Opus, UX), First Principles at
Prefetch the change as data files, the desktop matrix at paths-filter, and readiness waiting
on those. It correlates with the GraphQL quota, which refused my own gh pr view --json files
at 09:35Z naming the exact limit. Rerun once each; five recovered clean and GPT came back with a
real verdict, which is what this note answers.

The finding is real, and it lands on my own docstring

mark_arrival_folder_shared swallowed a failed write and returned. Its docstring claimed that
this produces "the same outcome as the folder having been deleted, which the import handler's own
repair already produces". That claim was false. The repair CLEARS the session's folder_id and
persists it; the mark-failure path left the id pointing at a row nothing protects.

That gap matters because the mark is the only thing sparing an adopted row once the session
archives: the rollback's occupancy guard reads live slots, and an archived session is popped out
of that mapping. So an unrecorded mark means a concurrent creator's rollback can reclaim the row
while the transcript still points at it.

The fix: report it, and make the claim true

mark_arrival_folder_shared now returns whether the row is protected. False covers both a
write that raised and a row already gone -- in either case nothing protects the placement and the
remedy is identical. An empty id returns True, because there is no placement to protect.

The handler acts on it by unfiling: clear folder_id and persist, under the same slot-identity
guard the folder-gone repair uses, with the delete-won False treated as terminal. That is the
same shape as the repair on purpose, so the docstring's equivalence claim is now accurate rather
than aspirational.

Reporting rather than raising keeps filing from failing an import whose transcript has landed.

The new await sits above the final delete witness, so the previous round's invariant still holds:
nothing awaits below the witness.

Tests

Three new. The mark's return contract pinned directly across all four cases; the unfiling remedy;
and its companion, which is what stops the unfiling firing unconditionally -- an unfiled session
is also a valid state, so without the companion an always-unfile bug would look correct.

Mutation-checked with a harness holding both files' originals in memory, asserting each mutation
applied, and stripping ANSI before matching FAILED:

mutation reddened
mark swallows its write failure 1 (the return-contract test)
handler ignores the mark's answer 1 (the unfiling test)
unfiling fires unconditionally 4 (the companion plus three existing filing tests)

State

206 tests pass in the two related files with -n0. All nine gates pass, including the
comment-history gate enforced against origin/main -- it caught a "no longer" phrase in my own
new comment, which is reworded. One amended commit, six files, on current main 1fa7f5ba,
clean tree, push guard SAFE, lease read separately.

green_age.py --pr 12196 exits 0 as of 09:59Z: base level with main, overlap none, FRESH.

Two residuals stay disclosed, unchanged: a cancelled import cannot take back its folder row,
because that arm does not await and the folder store does; and a leftover transcript is never
unlinked, because on two of the witness's three outcomes the file is not this instance's to
remove.

@github-actions

Copy link
Copy Markdown
Contributor

GPT 5.6 Review — ⚠️ review incomplete

GPT 5.6 did not produce a complete verdict for 623e67b49f3def0f0dab527166f28ea96bad0556; inspect the workflow logs and re-run it.

This comment is updated in place on each push.

See the GPT 5.6 Review job logs; this commit has no completed GPT verdict.

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 623e67b49f3def0f0dab527166f28ea96bad0556: <one-sentence reason>

@chenmingwei23

Copy link
Copy Markdown
Contributor Author

Both GPT findings fixed at 560928ca4928ae2354dcb89f4011bbacc8e549b7

Two blocking, both UPHOLD-FENCED with no override offered, both mine --
arrival_folders.py is absent on main, so the whole file is this PR's.

F1 session_transfer.py:2158 / :2222 -- the pin already existed and I was not using it

Both finalisation saves guarded with a SYNCHRONOUS identity check and then awaited. The
executor wait frees the event loop, so a close landing in that gap pops the slot and persists
closed=True while the in-flight save still holds closed=False. chat_persistence already has
the atomic answer -- it re-reads the map at the commit boundary with no await before the write --
but only when expected_slot_name is passed. Absent it that recheck is skipped entirely, so the
stale snapshot lands on top of the dismissal and the tab the person closed comes back.

Both saves now pass the pin.

The part the finding was right to spell out. With the pin, False has two meanings and they
need opposite handling. Re-reading the map is synchronous and cannot race, so it separates them:

  • the map does not hold this slot -> the PIN refused, a close or replacement won. The import
    landed and the close is the person's own later action, so SKIP and still report success.
  • the map still holds this slot -> the delete-won guard fired. Terminal, answers 409.

Conflating them would claim data loss that did not happen and drop a slot that belongs to someone
else now.

F2 arrival_folders.py:345 / :368 -- deterministic, not a race

The adopted-folder unhide ran inside the resolving transaction, which persists. Adopted rows are
absent from created_ids, so no rollback puts the flag back: ANY import that failed after
resolution had flipped the person's visibility preference on a row it filed nothing into. The
adjudicator is right that this one is deterministic rather than a race.

The unhide is deferred to the landed path. The filing now reports the adopted rows it found
hidden in ArrivalFiling.hidden_ids and leaves them alone; the landed write flips them in the
SAME transaction as the shared-row mark, so a landed import pays no extra round trip.

A failed unhide does not report the placement unprotected. It leaves a row merely hidden, which
the person can reverse and which costs the placement nothing -- unlike a failed mark, which is
what the return value is about.

Tests

Four new plus one moved. The pin asserted on the ARGUMENT, deliberately: a stub save cannot
exercise the real commit-boundary recheck, so a behavioural test there would pass with the pin
removed. The discriminator tested in the direction the existing sibling does not cover. The
hidden-folder test moved from "resolution un-hides" to "resolution reports and the landed write
un-hides", with a companion asserting a FAILED import leaves the flags untouched.

Mutation-checked with a harness holding both files' originals in memory, asserting each mutation
applied, and stripping ANSI before matching FAILED:

mutation reddened
repair save drops the pin 1
every False read as a deletion 1
unhide applied during resolve 2
landed write skips the unhide 1

The third row is why the failed-import companion is not decoration: putting the flip back inside
the transaction reddens it as well as the main test.

State

209 tests pass in the two related files with -n0. All nine gates pass, including the
comment-history gate enforced against origin/main -- it again caught a "no longer" in my own new
comment, which is reworded. One amended commit, six files, on current main 1fa7f5ba, clean
tree, push guard SAFE, lease read separately.

Note on the board: the seven lanes that went red at 09:34Z and again at 10:29Z were not verdicts.
Each died at an early data-fetch step, and four other open PRs showed the same lanes failing in
the same windows. Both bursts cleared on a single rerun; GPT's verdicts above are from the
recovered runs.

Two residuals stay disclosed, unchanged: a cancelled import cannot take back its folder row,
because that arm does not await and the folder store does; and a leftover transcript is never
unlinked, because on two of the witness's three outcomes the file is not this instance's to
remove.

@chenmingwei23

Copy link
Copy Markdown
Contributor Author
  • span=03c566f2762c -- rebutted in part, then accepted and deferred. The count is
    right and the mechanism is not. I opened the cited line: the sender does NOT fold every
    unknown code into "peer refused the transfer". It returns the peer's own error when the
    peer sent one, and propagates the peer's code as code, falling back to
    transfer_peer_refused only when the peer named none. So both 409 codes reach the
    sender's caller intact, and because their error strings differ -- one promises nothing
    was kept, the other names the leftover it cannot remove -- a person reading the failure
    sees different text depending on which fired. What is true, and I confirmed it with my own
    grep rather than taking it on trust, is that no code BRANCHES on the distinction: the two
    codes appear only at their emit sites in session_transfer.py, and every status === 409
    site in the web tree belongs to an unrelated feature with its own code. On the remaining
    question I accept and defer. The split is the surviving half of a settled decision that a
    refusal may only claim what it achieved: the delete witness reports "deleted" for three
    situations, and on two of them a transcript file remains that this instance must not unlink,
    so only the third makes "nothing was kept" true. The suggested subtraction -- one code whose
    message makes no clean-slate promise -- preserves that honesty, which makes it a smaller
    shape rather than a correction, and it is not worth volunteering a new head for on a board
    whose blocking lanes re-roll non-deterministically. If a maintainer prefers the single-code
    shape, say so on this thread and it is a small follow-up.

@chenmingwei23

Copy link
Copy Markdown
Contributor Author
  • span=0c2a55c098ed -- accepted as a judgement already made, and retained. The
    subtraction is to delete the rollback and keep the empty visible folder the RFC's
    recovery already blesses. That exact question was escalated for a human ruling on this PR
    and answered twice: keep the rollback, add the adopted marker inside the existing
    transaction, do not remove the mechanism. So this is not an open trade -- it is a decision
    with an owner, and the Design lane's own clearing condition for the sibling item was "a
    human explicitly accepts the persisted key and guard machinery as worth the stray-row
    harm", which is what that ruling is. Two further things bear on it. The blocking lane on
    this PR has twice required work ON this rollback rather than less of it: a fourth guard so a
    person's rename of a brand-new arrival folder is not deleted with the row, and a reported
    mark failure so an unprotected placement is unfiled instead of left dangling. Deleting the
    mechanism would discard both hard-gate fixes, and the standing rule is to retain the
    hard-gate fix and record the disagreement rather than follow the advisory subtraction. And
    the cancellation residual this item cites as proof the leak class stays open is disclosed
    deliberately, not overlooked: that arm rolls back synchronously because awaiting inside a
    cancelled task is not dependable while the folder store's lock is async. I have not counted
    folder-cap exhaustion from failed imports, so the quantitative half of the clearing
    condition is unmet and I am not claiming otherwise.

@chenmingwei23

Copy link
Copy Markdown
Contributor Author

/ai-review override gpt 560928c: the only consequence is a dangling folder id that this code documents as legitimate and ordinary folder deletion already creates; the transcript remains intact, so the outcome is recoverable, while the only direct fix is the persisted-session scan already rejected for this PR.

@github-actions

Copy link
Copy Markdown
Contributor

Human judgment recorded

@chenmingwei23 marked the gpt AI finding as false positive, not applicable, or explicitly accepted for 560928ca4928ae2354dcb89f4011bbacc8e549b7.

the only consequence is a dangling folder id that this code documents as legitimate and ordinary folder deletion already creates; the transcript remains intact, so the outcome is recoverable, while the only direct fix is the persisted-session scan already rejected for this PR.

This decision applies only to this commit. A new push requires a new judgment.

A session can arrive on an instance two ways -- a peer pushes one over an
Instances tunnel, and a person installs one exported to a file -- and both
landed at the top level of the sidebar, mixed in with the sessions the person
started themselves. The arriving tab carries a marked title, and a title is
renameable prose, so once it is edited nothing on the session says it was not
started here.

Both routes now file into Imported / from <sender>. They share one server
route, POST /api/chat/slots/import, which decides gzip from plain JSON by
sniffing the body's first two bytes -- so a gzipped file from a person and a
plain-JSON bundle from the tunnel are the same event carried by different
transport, and the encoding must decide neither how the bytes are read nor
where the session lands.

For the tunnel route this is a changed default, so the decision record is
docs/request-for-change/rfc-arrival-provenance-filing.md, which this PR is based
on rather than shipping. That document records why the narrower version (file the
file arrival only) is rejected rather than deferred, why there is no
configuration knob, and the six folder-lifecycle constraints this implementation
satisfies:

1. An app-scoped arrival creates no folder and adopts none, so it lands
   unfiled. The store has a global ceiling, and an app token that could create
   a folder per arrival could loop imports with distinct origins until the
   person is refused a folder of their own. Identity comes from the shared
   effective_request_app rule, never from the body.
2. Placement is resolved only after the slot exists. The handler re-checks the
   live-slot cap after its last await and can answer 429 there; a folder
   written in front of that check is left behind when it fires.
3. Find-or-create is atomic across both levels, inside one mutate_folders
   transaction.
4. A folder is looked up in the form the store writes it (trimmed, clipped to
   100 characters), or a long sender name misses the clipped row a previous
   arrival wrote.
5. A folder deleted mid-import leaves no dangling id. The slot is retracted
   from state._slots for the finalisation stretch, which is what the folder
   delete handler's unfile sweep iterates, so the folder is re-checked before
   the durable save and repaired after the slot is registered again.
6. Filing is best-effort: a ceiling refusal or a store write failure lands the
   session unfiled rather than failing an import that works today.

Folder names are ASCII English literals, because a folder created here is an
ordinary sidebar row a person can rename and a name re-derived per render from
the active locale would fight that rename.

Tests: test/test_arrival_folders.py covers the resolution (20 cases, one per
constraint plus the refusal paths); test/test_session_transfer.py adds 10
handler cases, 6 of which are red at the merge base. Eight mutations were
applied and all eight killed -- resolving placement before the slot exists,
reading identity off the request claim alone, dropping the post-registration
repair, dropping the store-form clip, allowing an app-scoped create, testing
the ceiling per append instead of on the pair, ignoring the parent in the
lookup, and splitting the resolution into two transactions.

Closes #11468
@chenmingwei23

Copy link
Copy Markdown
Contributor Author

Head 867a9992af8504edd4b3729e90b15e4371b603a2 fixes the GPT finding at
arrival_folders.py:518 -- the rollback deleting a folder an archived session is filed
into -- rather than carrying the override that was recorded against 560928ca. That
override is void by design once the head moves, and this fix is what replaces it.

The gap. The rollback's occupancy guard reads LIVE slots. A session a person drags into
a brand-new arrival folder and then closes is popped out of that mapping, so the row looks
unoccupied. A hand move is not an adopting import, so it writes no arrival_adopted
marker. And the row has no surviving child. Every existing guard passes, so a failing
import deleted a placement that archived session still named, leaving a dangling
folder_id.

Not the suggested fix. The reviewer's remedy was to include persisted archived-session
folder ids in the guard. That is a scan of persisted sessions, which this change has
declined throughout, and there is no index of archived sessions carrying folder ids that
would make it cheap -- I looked for one before ruling it out.

What is here instead. The folder handler records the destination id in memory on the
state (note_folder_filed), and the rollback unions that set into the same occupancy read.
Three properties are deliberate:

  • Written past the durable save, so a placement that was refused claims no row.
  • In memory, not stamped on the row. An arrival row is deliberately indistinguishable
    from a hand-made one, so a flag on the row would have to be written for EVERY destination
    and would leave bookkeeping on ordinary folders. Memory is also the matching lifetime:
    the rollback it protects runs seconds later in the same process, and a restart has no
    in-flight import to roll back.
  • Never dropped. Moving the session out again leaves the row spared, which errs toward
    a folder the person can delete over one something still points at.

Evidence. Five mutations, all killed: dropping the union deletes the row out from under
the archived session; handing out the live set instead of a copy; claiming a row on an
unfiling; a handler that records nothing; and recording beside the field assignment instead
of past the refusal. The last two needed tests the first three did not. A handler that
never records leaves every unit test passing, so that one is driven through the real route.
And a refusal that happens before the field is assigned says nothing about ordering, so the
ordering test drives a folder that vanishes under the lock.

458 tests pass across test_arrival_folders.py, test_session_transfer.py and the ten
test_chat_folder_* / test_chat_slot_create_folder.py files, -n0. All nine local gates
pass, including the comment-history ratchet. One commit, seven files.

The two first-principles items keep the answers recorded against the previous head; I will
re-post them against this head once that lane reports on it.

@chenmingwei23

Copy link
Copy Markdown
Contributor Author
  • span=cf66c4d0e0d2 -- the record this asks for, and the machinery is retained. The
    clearing condition offers two doors and this takes the first: why leave-behind-and-adopt is
    insufficient, recorded. A folder created for an import that never landed is provenance for a
    session that does not exist -- the row says sessions from that sender arrived here when none
    did -- and adoption makes that claim durable rather than transient, because the next arrival
    reuses the row instead of replacing it. That is the harm the rollback removes. I will not
    overstate it: the residue is one visible deletable folder, which is why this is a watch item
    and not a defect, and I have NOT counted a cap-exhaustion path, so no quantitative claim is
    made here. The decision to keep the machinery is a human ruling on this PR, made twice and
    explicitly including the words do not remove rollback, which is what the sibling item's
    "a human explicitly accepts the persisted key and guard machinery" asks for. Two further
    facts bear on the size objection. Each of the three parts exists because a BLOCKING lane
    required it: the created_rows fingerprint came from a finding that a person's rename of a
    brand-new arrival folder was deleted with the row; the arrival_adopted mark from a finding
    that an adopted row was reclaimed under an archived session; and note_folder_filed from a
    finding that the same happened to a hand-filed row. Dropping the protocol discards three
    hard-gate fixes to remove one advisory subtraction, and the standing rule is to keep the
    hard-gate fix and record the disagreement.

@chenmingwei23

Copy link
Copy Markdown
Contributor Author
  • span=331fec255c56 -- rebutted on current evidence. The claim is that main is broken at
    test collection, so every measurement was taken locally against a hand-neutralized
    main-owned assert and CI has never run this suite. Both halves are stale at this head. I
    re-ran collection on this branch with nothing neutralized and nothing skipped:
    pytest -q -n0 --collect-only test/test_arrival_folders.py reports 40 tests collected in
    0.86s, exit 0. And CI has run the suite on this exact commit: of the backend, frontend and
    E2E lanes at 867a9992, 25 are success, 2 skipped and 5 still executing, with zero
    failures and none of them dying at collection. The whole review round concluded here too --
    Design, First Principles, GPT, Opus, Security Scope and UX are all success at this head.
    What was true when the description was written is that main broken: sandbox.py module-level leaf-set invariant fails on import since 4ed7335d8 (#11556) #12183 broke collection on main and
    the base-red measurements had to be taken around it; that is a statement about the base at
    that time, not about this branch now, and the tests it qualified have since been re-measured
    here. If the lane wants the stronger form of its own clearing condition -- a green CI run
    after the main broken: sandbox.py module-level leaf-set invariant fails on import since 4ed7335d8 (#11556) #12183 fix lands on main -- the run above is on a branch whose merge-base is
    1fa7f5ba, and I will re-state it against a base that carries the fix if the lane prefers
    to wait for that rather than read this run.

@chenmingwei23

Copy link
Copy Markdown
Contributor Author
  • span=029d8c07ba04 -- declined, as a decision with an owner rather than an open trade.
    The suggestion is to drop the rollback protocol whole: delete discard_arrival_folders,
    mark_arrival_folder_shared, note_folder_filed/folder_ids_filed_into, the
    created_rows plumbing and the shared-mark unfiling block, and accept the created pair on
    every failure path. It is a coherent design and it is the same subtraction the
    first-principles lane makes as its item 8, so I am answering it the same way rather than
    differently in two places. That question was escalated for a human ruling on this PR and
    answered twice, the second time in the words do not remove rollback. So the trade is settled
    at the level above this lane. The part I want to record for a reader comparing the two
    shapes: the three helpers named here are not one idea in three files, they are three
    separate BLOCKING findings' remedies -- an edited row deleted with the rollback, an adopted
    row reclaimed under an archived session, and a hand-filed row reclaimed the same way.
    Accepting this suggestion removes all three protections along with the mechanism, and the
    residue it accepts in exchange is the one this PR's own cancellation arm already accepts and
    documents. I am not claiming the leave-behind shape is wrong; I am recording that switching
    to it is a bigger, separately-reviewable change than this PR, and that a human has said not
    to make it here.

@chenmingwei23

Copy link
Copy Markdown
Contributor Author
  • span=5f4c8f466436 -- accepted as a rider, kept for a stated coupling. Item 6 is right
    that the 409-on-deleted-session behaviour is not the RFC'd feature. It is declared in the
    description and its tests fail on base, so it is not smuggled, but "declared" is not the same
    as "belongs here" and I am not going to argue it is. The coupling that keeps it: the refusal
    it corrects is emitted by the import's own finalisation tail, the same code path this PR
    rewrites for the folder work, and the fix is the surviving half of a settled decision on this
    PR that a refusal may only claim what it achieved. Splitting it out means either leaving that
    tail emitting a refusal this PR's own change made inaccurate, or landing the folder work on
    top of a refusal contract that contradicts it and correcting it immediately afterward. I take
    the first-principles point that neither of those is a reason for the code to be in THIS
    review rather than a small follow-up landing first. If a maintainer prefers the split, say so
    on this thread and I will lift it into its own change; I am not volunteering a new head for
    it on a round whose six lanes have just come back clean, because a new head re-rolls all of
    them.

@chenmingwei23

Copy link
Copy Markdown
Contributor Author
  • span=a9fb0e4644e1 -- rebutted in part, then accepted and deferred. The count is right,
    the mechanism claim is not, and I checked rather than assuming. The sender at
    instances/ssh_tunnel_manager.py:2791 does not flatten the codes: it returns the peer's own
    error when the peer sent one and propagates the peer's code as code, falling back to
    transfer_peer_refused only when the peer named none. So both 409 codes reach the sender's
    caller intact, and their error strings differ -- one promises nothing was kept, the other
    names the leftover it cannot remove -- so a person reading the failure sees different text
    depending on which fired. The description's line that "a sender that distinguishes codes can
    retry on either one" is about retry policy, and on retry policy the lane is correct that the
    two are equivalent. What is true, and my own grep confirms it, is that nothing BRANCHES on
    the distinction: both codes appear only at their emit sites, and every status === 409 site
    in the web tree belongs to an unrelated feature with its own code. On that I accept and
    defer. The split is the surviving half of the settled decision that a refusal may only claim
    what it achieved: the delete witness reports deleted for three situations, and on two of them
    a transcript file remains that this instance must not unlink, so only the third makes
    "nothing was kept" true. Collapsing to one code is a smaller shape that keeps that honesty,
    not a correction, and it is a follow-up rather than a new head here.

@chenmingwei23

Copy link
Copy Markdown
Contributor Author
  • span=5ae5e95c6453 -- accepted as a judgement already made, and retained. Item 8 is the
    subtraction the design lane also proposes, and it gets the same answer in both places rather
    than two different ones: keep the rollback. That question was escalated for a human ruling on
    this PR and answered twice, the second time in the words do not remove rollback, so it is a
    decision with an owner rather than an open trade. The lane's reading of the RFC is accurate
    and I am not disputing it -- §5 lists six constraints and none of them is a rollback, §2 does
    call a stray folder one-click reversible, and this PR's own cancellation arm does accept
    exactly that residue and say so in a comment. The clearing condition asks for the deletion or
    for a harm beyond one empty deletable row, specifically a cap-exhaustion path a non-app
    caller can drive. I have NOT counted such a path and I am not going to claim one: on that
    half the item stands unanswered on the evidence, and the reason the machinery stays is the
    ruling, not a measurement I am pretending to have. What I will add is the cost of the
    subtraction as measured on this PR: the three mechanisms it removes are three separate
    BLOCKING findings' remedies -- an edited row deleted with the rollback, an adopted row
    reclaimed under an archived session, and a hand-filed row reclaimed the same way -- so
    accepting it discards three hard-gate fixes, and the standing rule is to keep those and
    record the disagreement.

@chenmingwei23

Copy link
Copy Markdown
Contributor Author
  • span=4d7e3ab95cfc -- accepted as downstream of item 8, and retained with it. Item 9 is
    correct on its own terms: ARRIVAL_ADOPTED_KEY is persisted bookkeeping, it is permanent
    once written, and the module's own docstring says a successful import leaves no bookkeeping in
    the store -- so the key is in tension with a promise this PR makes. Its clearing condition
    says deleted with item 8, which is the accurate dependency: the key exists only because the
    rollback exists, and the ruling that keeps the rollback keeps the key. Two things worth
    recording rather than leaving implied. The tension with "leaves no bookkeeping" is narrower
    than it sounds: the key is written only on a row an import ADOPTED, never on a row it created,
    so an import that resolves to a fresh pair and lands still leaves the store clean, and the
    guarantee holds for the ordinary case while failing for the adopting one. And the key is
    one-way on purpose -- a row that has been shared is never reclaimed -- because the
    alternative, taking the mark back when the adopting import fails, is what left two concurrent
    same-origin imports each marking the other's rows and leaking the pair for good. So the
    symptom-level framing is fair, and the shape it settled on is the one that does not have a
    worse failure than the hole it fills.

@chenmingwei23

Copy link
Copy Markdown
Contributor Author
  • span=4dad2f150f7c -- accepted as downstream of item 8, with the never-shrinking set
    stated plainly.
    Item 10 is about code I added at this head, so I will be direct about what
    it is. note_folder_filed records a folder id the moment a hand filing durably lands, the
    rollback reads that set, the set never shrinks, and it has exactly one consumer. All four are
    true. It exists because a BLOCKING finding said the rollback deletes a row an archived
    session is filed into, and the remedy the finding itself proposed -- read persisted sessions
    in the guard -- was rejected on this PR, with no index of archived sessions carrying folder
    ids to make it cheap; I looked before choosing this. Why it never shrinks: dropping an id
    would remove protection, and the direction of the error matters more than the tidiness --
    sparing a row the person can delete beats deleting one something points at. Why it is in
    memory: an arrival row is deliberately indistinguishable from a hand-made one, so a flag on
    the row would have to be written for EVERY destination and would leave bookkeeping on
    ordinary folders, which is the very promise item 9 holds this PR to. It is bounded by the
    number of distinct folders filed into rather than by how often they are filed, and it dies
    with the process, which is the matching lifetime because the rollback it protects runs seconds
    later in that same process. Its clearing condition is deleted with item 8, and it goes when
    the rollback goes.

@buluoray buluoray 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.

Verified at 867a9992. I went in expecting a sanitizer bug and found the opposite shape: the sanitizer does nothing, and that is fine because the value is never a path.

sender_folder_name(origin) is ("from " + origin).strip()[:100] with zero character filtering. I probed the exact head source rather than reading it, and ../../../etc/passwd, /etc/passwd, a/b/c, a\b\c, -rf, CON, COM1, \x00, \n, a combining-accent variant, a 150-char overlong value and case variants all pass through verbatim (clipped to 100).

None of that reaches the filesystem. A folder is keyed by uuid.uuid4().hex[:12] (arrival_folders.py:173) and the name is stored as an inert JSON name value in one file written by _atomic_write_json. arrival_folders.py contains no Path(, no os.path, and no path join over the name at all — so there is no traversal to perform, no reserved device name to hit, and no separator that means anything. NUL and newline are escaped by JSON serialization.

The authorization identity is effective_request_app(state, request), and origin is redacted and used only as the label — never compared against a credential. An app-scoped caller is refused filing outright and the denial is SEL-audited. So a spoofed origin can mis-label a folder and nothing more; there is no per-user folder namespace to cross on a single-user dashboard, and adoption only ever files under Imported, scoped by parent_id.

No new render sink: no dangerouslySetInnerHTML renders a folder name, and the arrival name occupies the identical field and character space as a hand-created folder (chat_folders.py:992 applies the same strip()[:100]), so this adds no XSS surface that hand-creating a folder did not already have.

Find-or-create is one mutate_folders transaction at both levels, with _find matching case-insensitively and parent-scoped, so a re-arrival adopts the existing row and two concurrent arrivals serialize. Rollback occupancy is read inside the transaction rather than from a snapshot.

Nothing arriving reaches memory, lessons, or a prompt — origin becomes a display label and transcript content keeps the existing boundary redaction.

Two provenance caveats worth knowing, neither a security issue: an origin-less bundle files directly under Imported rather than an invented "from unknown", and two senders that collide after the 100-char clip or differ only by case fold into one child. The cancellation arm also leaves at most one empty, visible, user-deletable folder row, which was previously adjudicated acceptable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Arrival provenance: file imported sessions under Imported / from <sender>, both routes (needs RFC first)

2 participants