Skip to content

fix(dashboard): never resurrect a cleared project directory - #11910

Closed
rnoack1 wants to merge 1 commit into
kirodotdev:mainfrom
rnoack1:split/slot-project-claim
Closed

rnoack1 wants to merge 1 commit into
kirodotdev:mainfrom
rnoack1:split/slot-project-claim

Conversation

@rnoack1

@rnoack1 rnoack1 commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

Problem / Motivation

An empty project on a chat slot means two different things — never set, or deliberately
cleared
— and the slot stored only absence. Every later read therefore saw "unset" and
restored the previous directory, so clearing a project did not stick: the next turn bound the
very directory the slot had been moved off, and relative writes landed there.

Two mechanisms made it stubborn. The metadata merge is an upsert, which cannot delete a
key, so a truthy-only write silently retained the old value rather than clearing it. And a
provider handed a falsy work_dir binds to a concrete default and reports that path as its
own cwd, so comparing a raw stored "" against a live binding never matched — the slot
cold-started every turn instead of reusing its session.

Why it matters

A cleared project is a deliberate act with a security-adjacent consequence: it is how a slot
is moved off a directory. Restoring that directory afterwards puts the next turn's writes back
where the user asked them not to go, and does it silently, because nothing in the slot's state
records that a clear ever happened.

The same record carries a pending retirement arm, which had a second sharp edge: an arm was
dropped unconditionally, so a producer unwinding its own failed work could drop an arm a
concurrent producer had just written, letting that producer's in-flight start bind the wrong
project.

What changed

A cleared project is now an explicit marker rather than absence, so no read can mistake it for
"unset":

  • config/paths.py gains the marker and resolved_cwd, which puts both sides of every
    directory comparison through one definition — the same resolution a provider applies to its
    own work_dir. An empty cwd with no session key raises rather than guessing a root, because
    the provider factory resolves it to a per-session directory, not to the shared workspace.
  • The slot exposes the directory a claim must state as a tri-state: a real path, the cleared
    marker, or nothing at all.
  • Every producer that writes or restores slot metadata carries the marker — the persistence
    merge (writing both fields unconditionally), channel surfacing, fork, and the history
    record's own shape.
  • A retirement arm is scoped to the generation that wrote it. A producer retracting its own
    arm passes the generation it was given, and the drop no-ops if another producer has armed
    the same key in between, leaving that arm and its in-flight start alone.

The session-allocation core, the arm verbs on the session manager, the lifecycle refusal and
the key-binding helper are carried here as shared primitives so this change compiles and tests
standalone; they are identical to their copies in the sibling PRs.

Tests

15 new cases in test/test_chat_slot_project.py, covering: the tri-state answer for a set,
cleared and never-set project; the cleared marker surviving a restart and beating a project
that outlived its clear; a reselected project winning over a carried marker; the merge writing
both fields unconditionally; a second save overwriting the marker rather than omitting it; and
arm retraction leaving a concurrent producer's arm in place while still dropping its own.

Verified against a pristine checkout of the same base commit over a 466-file blast radius:
14 failed / 28064 passed on this branch versus 14 failed / 28049 passed on the control
— identical failing-test id sets, so zero new failures and zero accidental fixes. Each of the
15 added tests also passes individually, against a negative control confirming a nonexistent
test name collects nothing.

Six further cases from the same source change are deferred: they exercise the HTTP handler
layer, which is not carried here, and will follow once it lands.

A cleared project records an explicit marker rather than absence, so no later read can
mistake it for "unset" and restore the directory the slot was deliberately moved off.
@github-actions github-actions Bot added fork Pull request from a fork (external contributor) readiness: action required A blocking check or review needs attention labels Sep 18, 2026
@dwu96

dwu96 commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

👋 Hi! This PR is currently in draft status. Workflow runs won't be auto-approved until it's marked as ready for review.

When you're ready, click "Ready for review" and the workflows will be approved on the next cycle automatically.

@dwu96

dwu96 commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

👋 Hi! This PR is currently in draft status. Workflow runs won't be auto-approved until it's marked as ready for review.

When you're ready, click "Ready for review" and the workflows will be approved on the next cycle automatically.

5 similar comments
@dwu96

dwu96 commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

👋 Hi! This PR is currently in draft status. Workflow runs won't be auto-approved until it's marked as ready for review.

When you're ready, click "Ready for review" and the workflows will be approved on the next cycle automatically.

@dwu96

dwu96 commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

👋 Hi! This PR is currently in draft status. Workflow runs won't be auto-approved until it's marked as ready for review.

When you're ready, click "Ready for review" and the workflows will be approved on the next cycle automatically.

@dwu96

dwu96 commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

👋 Hi! This PR is currently in draft status. Workflow runs won't be auto-approved until it's marked as ready for review.

When you're ready, click "Ready for review" and the workflows will be approved on the next cycle automatically.

@dwu96

dwu96 commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

👋 Hi! This PR is currently in draft status. Workflow runs won't be auto-approved until it's marked as ready for review.

When you're ready, click "Ready for review" and the workflows will be approved on the next cycle automatically.

@dwu96

dwu96 commented Sep 24, 2026

Copy link
Copy Markdown
Contributor

👋 Hi! This PR is currently in draft status. Workflow runs won't be auto-approved until it's marked as ready for review.

When you're ready, click "Ready for review" and the workflows will be approved on the next cycle automatically.

@bolichen97

Copy link
Copy Markdown
Contributor

Consolidation with PR #11831: port one history.py line and four tests there

This branch and PR #11831 carry the same cleared-project code:

  • the marker-first claim_cwd (src/kiro_crew/dashboard/state.py:3189)
  • the project_cleared restore and persist sites in chat_persistence.py, channel_slots.py and chat_fork.py
  • settling_key / bind_linked_session_key / key_rebind_deferred in chat_utils.py
  • the RetireArm core in session_allocation.py, including supersede_arm_for_new_slot(only_generation=)

At this head the change does nothing yet:

  • Every write of project_cleared copies a value that was persisted or forked. Nothing ever sets the marker.
  • claim_cwd has no caller. chat_runner.py:5663 and :8988 still pass cwd=slot.project or None.
  • config/paths.py:385 imports session_default_cwd, but config/loader.py only has _session_work_dir (loader.py:527). That fails mypy and would raise ImportError on the cleared path.

PR #11831 fills all three gaps. It calls record_project() at the project writers, passes cwd=slot.claim_cwd at both claims and adds the loader rename. Its current head sits directly on origin/main. This branch is 817 commits behind and conflicts in 7 files.

What only this PR has:

Suggestion: make PR #11831 the host and port these items there instead of rebasing this branch. When porting:

From a full open-PR audit against origin/main c66f95b (2026-09-25); findings were checked by independent reviewers reading the code. Reply here if this is wrong.

@dwu96

dwu96 commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

👋 Hi! This PR is currently in draft status. Workflow runs won't be auto-approved until it's marked as ready for review.

When you're ready, click "Ready for review" and the workflows will be approved on the next cycle automatically.

Copy link
Copy Markdown
Contributor

Triage update (origin/main 5edf2fe, 2026-10-05): the 2026-09-25 consolidation advice still holds

Re-checked against the current head 1b7ba08 and main:

  • Merged PR fix(chat): persist a cleared project instead of retaining the old one #11701 (7224b78) already writes fields["project"] = slot.project unconditionally in _save_slot_to_history. That covers the project half of this PR's chat_persistence.py merge hunk. The project_cleared field, the marker, claim_cwd, RetireArm/only_generation and the history.py deferred-key entry are still not on main. Main covers part of this PR, not all of it.
  • The change is still inert at this head. Only the restore and fork paths assign slot.project_cleared (chat_persistence.py:1334,1940, channel_slots.py:462, chat_fork.py:970), and each one copies a value that was already persisted. claim_cwd (state.py:3189) has no caller.
  • config/paths.py:385 still imports session_default_cwd, which config/loader.py does not define (only _session_work_dir, loader.py:527). That fails mypy. It is not reachable at runtime today because no production caller passes cwd="".
  • The branch is now 2459 commits behind main and conflicts in 7 files.

The recommendation is unchanged: make #11831 the host and port this PR's unique parts there. Those are the history.py project_cleared meta-key entry (coordinate with #11813, which uses SLOT_OWNED_META_KEYS instead) and the four test classes listed in the earlier comment. Once they land, close this draft. Rebasing it is not worth it.

From a full open-PR audit; reply here if this is wrong.

@dwu96

dwu96 commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

👋 Hi! This PR is currently in draft status. Workflow runs won't be auto-approved until it's marked as ready for review.

When you're ready, click "Ready for review" and the workflows will be approved on the next cycle automatically.

@iamwhatever

Copy link
Copy Markdown
Contributor

Thank you @rnoack1 for this work.

Status check: the plan from 2026-09-25 and 2026-10-06 is to port this PR's unique parts into #11831 and close this one once they land.

At #11831's head (b6d591349), the history.py "project_cleared" deferred-key entry is there. Not there yet: TestClaimCwdTriState, TestArmRetractionIsScopedToItsOwnGeneration, TestTheArmRecordKeepsWhatSpendingMustNotDrop, and test_channel_linked_slot_defers_reset_on_its_channel_session. #11831 is also still open.

So I am leaving this open for now. No code or branch changes were made.

@iamwhatever

Copy link
Copy Markdown
Contributor

Closing this draft as part of stale-PR cleanup: it has had no activity for 14+ days. Nothing is lost. The branch stays, and you can reopen this PR (or open a fresh one rebased on main) whenever you pick it up again. Thanks for the work.

@iamwhatever iamwhatever closed this Nov 2, 2026
@github-actions github-actions Bot removed the readiness: action required A blocking check or review needs attention label Nov 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fork Pull request from a fork (external contributor) merge conflict Branch has merge conflicts with its base — author must resolve before merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants