Skip to content

fix(chat): keep a deferred reset armed when its arm never settles - #11983

Closed
rnoack1 wants to merge 1 commit into
kirodotdev:mainfrom
rnoack1:split/unsettled-transfer-keeps-the-reset
Closed

rnoack1 wants to merge 1 commit into
kirodotdev:mainfrom
rnoack1:split/unsettled-transfer-keeps-the-reset

Conversation

@rnoack1

@rnoack1 rnoack1 commented Sep 19, 2026

Copy link
Copy Markdown
Contributor

Problem / Motivation

A deferred reset is consumed on the assumption that the key it was armed against is the
key the session now holds. A rebind that arrives inside the settle's own region is
parked rather than applied, so the settled key never moves — and the caller, seeing no
key change, treats the reset as delivered and clears the flag. The reset is then owed to
a binding nobody is on: the live key keeps the stale session for the rest of its life.

The settle is the only place this can happen, because it is the one window where a key is
resolved and then published as two separate steps.

Why it matters

The failure is silent and it does not self-heal. The flag is cleared, so nothing retries;
the session that should have been reset keeps serving the live key, carrying whatever
state the reset existed to discard. Because the observable symptom is "the key did not
change" — which is also the normal outcome of a parked rebind — the caller has no way to
tell a delivered reset from one that was dropped.

What changed

_consume_pending_reset no longer treats an unchanged key as proof of delivery. When the
transfer reports the arm unsettled, the reset is re-armed rather than cleared, so the
next turn retries against the key that actually landed.

The slot-allocation core, the arm verbs and the cleared-cwd marker are carried here
identically to their siblings so this change compiles and tests on its own.

Also folded in, because the carried call site forces it: _consume_pending_reset passes
refuse_only_on_active_turn=True, which narrows skip_if_busy to a declared turn so a
mere lifetime lease cannot refuse a reset the user asked for. Three existing assertions
pinned the old signature and are updated to the new one.

Tests

Two added cases in test/test_chat_slot_unsettled_reset.py:

  • a parked rebind leaves the reset armed for the live key — the reproduction;
  • a settled transfer still applies the reset — the positive control, so a fix that simply
    stopped consuming resets would fail here.

Break-armed: with the arm_settled clause removed from the guard, the reproduction fails
while the positive control still passes.

Full suite run against a pristine same-base control on an idle host: zero new
failures
, identical failing-id sets in both directions apart from one item in
test_session.py::TestCleanupLoopResilience, which flips on the control side and is a
TimeoutError rather than an assertion (314 passed across eight runs on both trees).

@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 19, 2026
@dwu96

dwu96 commented Sep 19, 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.

@github-actions github-actions Bot added the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Sep 19, 2026
@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.

3 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 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 bolichen97 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Requesting changes: resolved_cwd() imports a loader function that does not exist on this branch

This PR adds resolved_cwd() in src/kiro_crew/config/paths.py. At line 385 it does:

from kiro_crew.config.loader import session_default_cwd

return str(session_default_cwd(session_key))

The PR doesn't touch config/loader.py. At this head the loader defines _session_work_dir(session_key) (src/kiro_crew/config/loader.py:528) and has no session_default_cwd. origin/main doesn't have it either. The rename exists only in the open PRs PR #11813, PR #11831 and PR #11722, so rebasing onto main won't fix it.

What breaks

  • CI. Running mypy with the repo's config gives src/kiro_crew/config/paths.py:385: error: Module "kiro_crew.config.loader" has no attribute "session_default_cwd" [attr-defined]. Type check (mypy) (mypy src/kiro_crew/, .github/workflows/ci.yml:576-577) is a blocking step. No workflow has run yet because this is a fork draft, so the failure will appear once the PR leaves draft. If the PR merged like this, Backend Lint & Type Check would fail on main for every later PR.

  • Runtime. resolved_cwd("", "dashboard:x") raises ImportError: cannot import name 'session_default_cwd' from 'kiro_crew.config.loader' (reproduced). Every cleared-project path this PR adds goes through that call:

    • SessionManager.resolve_arm_cwd (src/kiro_crew/session.py:1661)
    • note_project_change("") (src/kiro_crew/session.py:1716)
    • _record_arm_cwd (src/kiro_crew/session_allocation.py:570)
    • transfer_retire_arm (src/kiro_crew/session_allocation.py:647)
    • _reacquire_and_validate with cwd="" (src/kiro_crew/session_allocation.py:882)

    At this head nothing sets slot.project_cleared = True, so production can't reach any of these yet. PR #11910 sets that marker and carries the same paths.py without the rename. If it lands before the rename, every turn on a cleared slot will raise this ImportError.

The new tests don't catch this. test/test_chat_slot_unsettled_reset.py replaces state.sessions with a MagicMock and stubs resolve_arm_cwd, so the real resolved_cwd("") never runs.

Smallest fix: there are two options. Carry the _session_work_dir -> session_default_cwd rename into config/loader.py here, as the sibling PRs do. Or have resolved_cwd call _session_work_dir until the rename lands. Either way, a test that calls resolved_cwd("", key) with no mocks would keep the import from breaking again.

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.

@bolichen97

Copy link
Copy Markdown
Contributor

Consolidation: the _consume_pending_reset fix here is already in PR #11831

PR #11831 has the same author and is at head c55977e71d. It is not a draft, it is 0 behind origin/main and it merges cleanly. It rewrites _consume_pending_reset in src/kiro_crew/dashboard/chat_runner.py the same way this PR does:

  • _settle_and_transfer_arm(state, slot, pending_key, slot.claim_cwd, _app_owned_rebind_denied(slot)): :5018 here, :6019 in fix(dashboard): keep a deferred project reset on the key its slot runs on #11831.
  • if pending_key != current_key or not arm_settled: points the flag at effective_session_key(slot) and arms a retry: :5036 here, :6025 there.
  • On both branches the reset runs inside settling_key(...), followed by rebound_mid_reset = key_rebind_deferred(slot) and the has_session(pending_key) split. Both claim sites pass cwd=slot.claim_cwd.

What #11831 has that this branch lacks

  • It re-authorizes the retargeted key before arming it (:6037-6042). Here the settle gate only runs when current_key != from_key (:897). So once :5049 points an app-owned slot's flag at a foreign key, the next consume settles on that same key and skips the check.
  • record_project (state.py:2362) raises project_cleared. Nothing on this branch sets it, so the new unsettled branch can only be reached from the test.
  • session_default_cwd in config/loader.py, which the review above found missing here.

What only this branch has

Suggestion: land this fix through #11831. Port the test file there: it only needs _consume_pending_reset, bind_linked_session_key(slot, key) and resolve_arm_cwd, and #11831 has all three with compatible signatures. Then decide refuse_only_on_active_turn once, in #11831, together with its matching pins. Rebasing this branch instead means resolving conflicts in 6 files at 787 commits behind, and dropping the #11707 hunks that main already has.

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.

A rebind landing inside the settle's own region is parked, so the settled key
never moves and only the unsettled report can catch it -- re-arm instead.
@rnoack1
rnoack1 force-pushed the split/unsettled-transfer-keeps-the-reset branch from 6a8a97c to fdfc50e Compare September 26, 2026 22:47
@github-actions github-actions Bot removed the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Sep 26, 2026
@dwu96

dwu96 commented Sep 26, 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.

@github-actions github-actions Bot added the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Sep 26, 2026
@dwu96

dwu96 commented Sep 28, 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.

10 similar comments
@dwu96

dwu96 commented Sep 28, 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 29, 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 29, 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 Oct 1, 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 Oct 1, 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 Oct 3, 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 Oct 4, 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 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.

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

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

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

Copy link
Copy Markdown
Contributor

Triage update (origin/main a92dde1a6c, PR head fdfc50ef55): overlaps open #11831; fold the unique parts into it or rebase

I checked the current head against main and the open sibling PRs.

I agree with the earlier consolidation suggestion. Port the test file into #11831, and decide refuse_only_on_active_turn there once, together with its pins. After that, this draft can be closed. If you want to keep this PR as a standalone fix, rebase it onto main and add #11831's retarget re-authorization. Without it, a rebound app-owned slot re-arms a foreign key that no later settle re-checks.

Automated open-PR triage, 2026-10-05. 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.

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

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

@github-actions github-actions Bot removed the readiness: action required A blocking check or review needs attention label Oct 27, 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