Repository navigation
feat(sessions): file an arriving session under Imported / from <sender> - #12196
Conversation
Design Review (Fable 5) — 🟡 CONCERNSDesign-level review of 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
Suggestions
[DESIGN-REVIEWED] 867a999 |
First Principles Review (Fable 5) — 🟡 CONCERNSPremise-level review of 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
What this change shipsInventory (10 items) — 5 justifiedIntent: 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.
[FIRST-PRINCIPLES-REVIEWED] 867a999 |
Opus 4.8 Review — ✅ no blocking findingsReviewed Review detailsThe candidate requires: a hidden pre-existing 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 ( 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 False positive or not applicable? A repository writer can comment: |
GPT 5.6 Review — ✅ no blocking findings (all downgraded on adjudication)GPT 5.6 flagged blocking issues on This comment is updated in place on each push. Review detailsBLOCKING -- src/kiro_crew/dashboard/session_transfer.py:1874 -- Cancellation leaks committed arrival folders 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 ( Evidence record:
[ADJUDICATION] 867a999 total=1 uphold=0 downgrade=1 False positive or not applicable? A repository writer can comment: |
f5d9f4b to
8fe666f
Compare
30ac1b6 to
d25e3a7
Compare
GPT 5.6 Review —
|
d25e3a7 to
6843c56
Compare
GPT 5.6 Review — 🔴 changes requested (blocking)GPT 5.6 found at least one blocking issue that must be resolved before merging 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) [BLOCK-MERGE] 6843c56 |
6843c56 to
db2900e
Compare
Round update: one blocking finding fixed, two advisory items dispositionedHead is now GPT 5.6 blocking finding: upheld and fixed
Real, and the module's own code is the proof. Auditing one side is worse than auditing neither: an auditor filtering 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:
No dedup window, unlike the per-frame event gate that needs one: this is one event per Test Separately, the adjudication stage did not run for First Principles, advisory: does a peer's push re-surface a hidden folder?Yes, and it is intended. The rule is Sizing the capability:
Honouring Left as is. If a maintainer prefers the stricter reading, the change is one branch in 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
So the honest statement is that this PR's readiness is computed over a reduced lane Local evidence in the meantime, run against the rebased tree: |
db2900e to
cde5f88
Compare
ad3742d to
89cca7a
Compare
Round note -- the three reds on
|
The one red at
|
F1 fixed: the absent-key forget is scoped to this import's own sidHead is now The finding is right, and this PR's own comment already named the residualThe The object comparison cannot separate the two cases, because The fixif 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 guard is exact rather than approximate. Scope is this one site. The three sibling TestsTwo new, plus a premise stated in an existing one.
Three mutations, each killed by its own 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 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 headBoth were in The mypy break at The dependency audit still refuses because it cannot run -- it names no package. It fails identically on a pristine Residuals, unchanged and disclosedA 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. |
GPT F1 fixed at
|
| 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.
GPT F1 fixed at
|
| 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.
Disposition of the two advisory CONCERNS at
|
GPT 5.6 Review —
|
GPT F1 fixed at
|
| 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.
GPT 5.6 Review —
|
Both GPT findings fixed at
|
| 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.
|
|
|
/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. |
Human judgment recorded@chenmingwei23 marked the gpt AI finding as false positive, not applicable, or explicitly accepted for
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
|
Head The gap. The rollback's occupancy guard reads LIVE slots. A session a person drags into Not the suggested fix. The reviewer's remedy was to include persisted archived-session What is here instead. The folder handler records the destination id in memory on the
Evidence. Five mutations, all killed: dropping the union deletes the row out from under 458 tests pass across The two first-principles items keep the answers recorded against the previous head; I will |
|
|
|
|
|
|
|
|
buluoray
left a comment
There was a problem hiding this comment.
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.
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_importinsrc/kiro_crew/dashboard/session_transfer.pycomposes the imported slot'smetadata with no
folder_id, and its comment records that the session "landsunfiled 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
mainautomatically when #12189 merges.Goal. An arriving session is filed under a folder named
Imported, in a childnamed
from <sender>, for both arrival routes.Approach.
POST /api/chat/slots/importis the only server route behind botharrivals, 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_idresolves thedestination and
arrival_folder_existsre-checks it. The transaction shape istaken from
ensure_channel_folderindashboard/channel_folders.py, which isthis repository's existing name-matched find-or-create folder path.
session_transfer.py: one filing call placed as the lastawaitbefore thedurable save, plus the repair after the slot is re-registered.
docs/system-specs/modules/instances.mdsection 14.5a: the arrival section nowcarries 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:
global
MAX_CHAT_FOLDERSceiling, so an app token that could create a folderper arrival could loop imports with distinct
originvalues until the personis 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_apprule, not fromrequest.get("app")alone -- the twodiffer 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.
live-slot cap after its last
awaitand can answer429there; a folderwritten in front of that check is left behind when it fires, which is the same
store exhaustion with a narrower trigger.
mutate_folderstransaction, so two arrivals from one peer cannot each create a folder with the
same name and a delete of
Importedcannot land between the two appends.create_folder_recordtrims and clips a name to 100 characters, sostore_folder_namemirrors that before the lookup; a test reads the clip outof
create_folder_record's own source rather than restating the number.stretch the slot is retracted from
state._slots, which is the mapping thefolder 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.
session unfiled rather than failing an import that works today.
<sender>is the bundle's redactedorigin. It names a folder and confersnothing:
originis a field of an untrusted bundle and is never read as anidentity. A bundle with no
originis filed underImporteddirectly rather thanunder 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
Importedfolder: the delete handler's own unfilesweep 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-importpreviouslyanswered
200 okfor a session deleted while the import was finishing, becausenothing asked. It now answers
409withtransfer_import_deletedwhen nothingwas kept, and
409withtransfer_import_deleted_partialwhen a transcript fileremains 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-
200as a hard failure willnow 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 firstarrival creating both levels, adoption on a second arrival, the case-insensitive
name match, the parent-scoped lookup that keeps an unrelated top-level
from macfrom 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.pyadds 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_statenow modelsmutate_folders/read_folders, so the existing import tests exercise the shipped filing pathrather 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
mainis currently broken at module scope:src/kiro_crew/sandbox.pyfails animport-time set-equality assert, so nothing that imports the package collects.
Reproduced on pristine
origin/mainwith none of this code present, and bisectedto commit
4ed7335d8(which landed #11556); tracked as #12182 and #12183. Thisdiff touches neither
sandbox.pynor any of its inputs, so the fix belongs thereand 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.