Skip to content

fix(chat): persist a cleared project instead of retaining the old one - #11701

Merged
iamwhatever merged 1 commit into
kirodotdev:mainfrom
rnoack1:split/project-cleared-plumbing
Sep 22, 2026
Merged

iamwhatever merged 1 commit into
kirodotdev:mainfrom
rnoack1:split/project-cleared-plumbing

Conversation

@rnoack1

@rnoack1 rnoack1 commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

Carved from #7161 under an authorised split. That PR is +12601 across 89 files; this is one
reviewable behaviour from it, cut off the current main tip.

Rescoped at c2b19577. The previous revision also added a project_cleared marker,
claim_cwd, CWD_CLEARED, resolved_cwd and default_workspace_dir. First Principles Review
blocked it, and the finding was correct on inspection: that chain was inert in both directions —
every project_cleared = True was a restore-from-disk site, so nothing ever originated the
marker, and claim_cwd had no production reader (the runtime.py comment asserting
chat_runner: cwd=slot.claim_cwd was false; chat_runner.py never referenced it). All of it is
removed here. What remains is the one change that fixes a real defect, plus the rename it needs.

The five files that carried only the removed chain are now byte-identical to main
(paths.py, state.py, chat_fork.py, channel_slots.py, spec_builder/backend/runtime.py),
verified by hash rather than by diff shape.

Problem / Motivation

A forced save of a message-less slot has no transcript window to write, so it reaches disk
through update_metadata_if — an upsert, which can add or overwrite a key but cannot delete
one. project was written only when non-empty:

if slot.project:
    fields["project"] = slot.project

So clearing a project left the previous directory on the metadata line, and the next restore read
it back as though the user had never cleared it.

Why it matters

This is the newborn path, not a corner case. session_create persists folder_id at birth, so an
empty tab already has a metadata line, and a project set and then cleared before the first
message
is persisted only by this merge. The user clears the project, restarts, and the session
rebinds the directory they removed — with relative writes landing in the former tree and nothing
to signal it.

The same function already states the invariant this violated:

Clearable fields are written even when empty — the merge cannot delete a key, and rehydrate
treats a falsy value as cleared (unfiled / untagged / unpinned / untitled / default mode).

project was simply not in that family. Its sibling memory_store is, and carries an equivalent
comment explaining why.

What changed

fields["project"] is now written unconditionally, joining the clearable family the merge already
enumerates (folder / tags / pin / title / mode / memory_store).

The full-save meta_line path deliberately keeps its if slot.project: guard. That path writes a
complete replacement line, where an omitted key is already falsy-as-cleared; only the merge path
needs the explicit empty value. The asymmetry is the point, not an oversight.

loader._session_work_dir is renamed to session_default_cwd, with its call sites in
cli_server.py and slack/gateway.py updated. The name was already imported across modules
despite the leading underscore, which advertised a privacy it did not have. The _session_work_dir
methods on AcpClient and AcpRuntime are unrelated and untouched.

path ± kind
test/test_cleared_project_not_resurrected.py +85 tests — the cleared project must not be restored
test/test_cli_server_more_coverage.py +19/−2 test update for the rename
src/kiro_crew/config/loader.py +11/−2 the rename
src/kiro_crew/slack/gateway.py +6/−6 rename call sites
src/kiro_crew/dashboard/chat_persistence.py +5/−2 the fix
src/kiro_crew/cli_server.py +4/−4 rename call site
docs/system-specs/modules/config.md +1/−1 drops the renamed symbol from the workspace-root docs
total +119/−13 7 files

The behavioural change is 2 lines of chat_persistence.py; everything else is the rename, its doc
reference and tests.

Tests

test/test_cleared_project_not_resurrected.py (new) drives the real merge branch — a message-less
slot whose metadata line already names a directory, then cleared and force-saved:

  • Clearing overwrites the stored directory. Break-armed: restoring the if slot.project:
    guard fails this test with the stale directory still on disk
    (project='.../scoped'), so it detects the defect rather than merely passing.
  • A live project survives the same merge — the positive control that keeps the unconditional
    write from being a blanket blanking. Still passes under the reverted guard, so it isolates the
    defect to the cleared case.

Reaching the fixed branch needs a genuinely message-less slot: window is slot.messages, and a
save with any window takes the full-save path instead. A first attempt at this test appended a
message and silently exercised the wrong branch — update_metadata_if fired zero times. The
committed version asserts not slot.messages as a precondition so that cannot regress unnoticed.

test/test_cli_server_more_coverage.py asserts the task runner binds the per-session default under
the taskrunner's own key, which is what makes the rename load-bearing rather than cosmetic.

Manual verification

N/A — unit coverage is sufficient.

Every failure in the local gate is pre-existing in this environment. The 12 files that failed give
87 failed / 7 errors on this branch and 87 failed / 7 errors on a pristine upstream/main
worktree at the same tip — identical, and none of the 12 is in a module this PR touches. The cause
is environmental: a global Conventional-Commits commit-msg hook rejecting the temp-repo
git commit -m 'init' fixtures those suites build.

The related set for the changed modules is green: 708 passed across the persistence, fork,
spec-builder, slot-project and channel-slot suites, plus 220 across the taskrunner and
project-alias suites. black --check is clean on the new file — checked directly, because the
repo's black gate is baselined and a newly added file is outside its scope. check_agent_sdk_boundary,
check_subprocess_encoding and check_sync_io_in_async pass. The per-file coverage gate needs a
full coverage report and was not reproduced locally; that remains CI's.

Pattern harvest

Rule candidate: semgrep
Pattern: clearable field written under a truthiness guard into an upsert merge

Concretely if <slot>.<attr>: fields["<attr>"] = <slot>.<attr> inside _fresh_fields. The merge
is an upsert, so a guarded write cannot express a clear and the stale value survives silently. The
function already documents the invariant in prose and already has a correct sibling
(memory_store), which is precisely why a mechanical check is worth more than the comment: this
field was added to the enumeration without anyone noticing it needed the unguarded form. A cheaper
variant of the same rule is a test-level assertion that every key in the full-save meta_line
enumeration which is clearable also appears unguarded in _fresh_fields.

Related Issues

Carved from #7161.

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

1 similar comment
@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.

@rnoack1
rnoack1 marked this pull request as ready for review September 18, 2026 10:49
@rnoack1
rnoack1 requested review from a team and chenmingwei23 September 18, 2026 10:49
@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 18, 2026
@github-actions

github-actions Bot commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

GPT 5.6 Review (fork) — ✅ no blocking findings

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

Review details

FINDING -- PR description:1 -- promised "session_default_cwd" rename and five related files are absent from the diff -> Fix: remove those stale claims from the description.
[GPT-REVIEWED] 6b9f19a

@github-actions

github-actions Bot commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Fable 5, fork) — ✅ PASS

Design-level review of 6b9f19a0c3e704db31c2d1ae19100f29a78fcce7 via the fork AI-review pipeline — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

Design-Verdict: PASS

Nothing to check.

[DESIGN-REVIEWED] 6b9f19a

@github-actions

github-actions Bot commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Fable 5, fork) — 🟡 CONCERNS

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

First-Principles-Verdict: CONCERNS

The description declares a 7-file change including a rename; the GitHub-computed diff ships 2 files — five described files and the rename don't exist here.

Not justified as shipped

  • Item 3 — framing contradicted by the diff: the description says "loader._session_work_dir is renamed to session_default_cwd, with its call sites in cli_server.py and slack/gateway.py updated" and tables +119/−13 across 7 files, but the authoritative diff carries only chat_persistence.py (+5/−2) and one new test; base still has _session_work_dir at src/kiro_crew/config/loader.py:536 and session_default_cwd appears nowhere in src/ (grepped both, 0 hits for the new name). A reader approves a rename that never ships — and its described call-site list also misses the third importer, src/kiro_crew/apps/builtins/auto_improvement/spine/crew_runner.py:11.
    Clears when: the description's "What changed" section matches this head's 2-file diff, or the rename commit is actually pushed (covering all 3 importers).

What this change ships

Inventory (3 items) — 2 justified

Intent: a project cleared before a session's first message must stay cleared after restart — a FIX.

  1. Clearing a project on a message-less tab now survives restart; previously the removed directory rebound — justified
  2. New test pinning the cleared case, with a live-project positive control — justified
  3. Described rename _session_work_dir → session_default_cwd and 5 more files — framing contradicted by the diff: declared but absent from it

[FIRST-PRINCIPLES-REVIEWED] 6b9f19a

@github-actions

github-actions Bot commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

Opus 4.8 Review (fork) — ✅ no blocking findings

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

Review details

No findings.

[OPUS-REVIEWED] 6b9f19a

@rnoack1
rnoack1 force-pushed the split/project-cleared-plumbing branch from 06fa444 to c2b1957 Compare September 19, 2026 18:56
@rnoack1 rnoack1 changed the title fix(chat): distinguish a cleared project from one never set fix(chat): persist a cleared project instead of retaining the old one Sep 19, 2026
@rnoack1
rnoack1 force-pushed the split/project-cleared-plumbing branch from c2b1957 to 30f8147 Compare September 19, 2026 19:29
@github-actions github-actions Bot added the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Sep 20, 2026
@rnoack1
rnoack1 force-pushed the split/project-cleared-plumbing branch from 30f8147 to b01d2ec Compare September 22, 2026 01:12
@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 merge conflict Branch has merge conflicts with its base — author must resolve before merge readiness: checking Automated validation is still running labels Sep 22, 2026
@rnoack1
rnoack1 force-pushed the split/project-cleared-plumbing branch 2 times, most recently from 543316e to ca3bec1 Compare September 22, 2026 05:17
@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 readiness: checking Automated validation is still running labels Sep 22, 2026
@rnoack1
rnoack1 force-pushed the split/project-cleared-plumbing branch from fbcfd64 to f7b4789 Compare September 22, 2026 07:18
@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 22, 2026
@rnoack1
rnoack1 force-pushed the split/project-cleared-plumbing branch from f7b4789 to 27f9162 Compare September 22, 2026 08:13
@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 22, 2026
@rnoack1
rnoack1 force-pushed the split/project-cleared-plumbing branch from 27f9162 to d1a9a45 Compare September 22, 2026 09:15
@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 22, 2026
The metadata merge is an upsert that cannot delete a key, so writing `project` only
when non-empty left the cleared directory on disk for the next restore to rebind.
@rnoack1
rnoack1 force-pushed the split/project-cleared-plumbing branch from d1a9a45 to 6b9f19a Compare September 22, 2026 10:07
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: passed Eligible automated validation passed for the current revision and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Sep 22, 2026
@iamwhatever
iamwhatever enabled auto-merge (squash) September 22, 2026 17:23
@iamwhatever
iamwhatever merged commit 7224b78 into kirodotdev:main Sep 22, 2026
96 checks passed
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Sep 22, 2026
@rnoack1
rnoack1 deleted the split/project-cleared-plumbing branch September 24, 2026 18:15
wknight1 pushed a commit to wknight1/KiroCrew that referenced this pull request Oct 5, 2026
…kirodotdev#11701)

The metadata merge is an upsert that cannot delete a key, so writing `project` only
when non-empty left the cleared directory on disk for the next restore to rebind.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fork Pull request from a fork (external contributor)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants