Skip to content

fix(session): reclaim judge, taskrunner-refine, hook-default and wf-author run dirs - #20110

Merged
iamwhatever merged 1 commit into
mainfrom
fix/16049-reclaim-judge-refine-hook-wfauthor-eval
Oct 27, 2026
Merged

iamwhatever merged 1 commit into
mainfrom
fix/16049-reclaim-judge-refine-hook-wfauthor-eval

Conversation

@CrysisDeu

@CrysisDeu CrysisDeu commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: Make the sweep reclaim the one-run work directories left by judge, taskrunner-refine, hook-default, and workflow-author sessions.

After #16039 added _DERIVED_SESSION_SHAPES for subagent, cron, and memory-consolidation sessions, four other session types that also mint fresh per-run directories were not included in the table. Their work directories match no shape in the sweep's candidate filter, so they accumulate indefinitely under the workspace root.

The four callers and their key shapes:

  • judge:<uuid4 hex> — decisions/impl_llm.py, one per judge call, destroyed on return.
  • taskrunner:refine:<epoch ms> — dashboard/handlers/taskrunner.py, one per refine turn.
  • hook:default:<epoch s>-<token_hex(6)> — dashboard/handlers/hooks.py, one per inbound webhook request that supplies no session key.
  • wf-author:<wf_<n>>:a<attempt> — workflows/service.py, destroyed in the finally block after authoring.

Why it matters

Each of these runs on every judge decision, every task-refine attempt, every webhook call, and every workflow creation. On an active install the count of orphaned directories grows in proportion to usage, costs the directory-listing time cited in #16039, and bleeds skill-view aliases from ~/.kiro/agents.

Not a goal

  • The hook caller-supplied session key (e.g. hook:my-webhook) is intentionally long-lived; this PR does not reclaim it.
  • Reclaiming eval_<name>_<ns> directories: eval/runner.py's shared_ws_factory sets provider._client._work_dir = ws (the shared operator workspace), so there is no per-key derived directory to sweep. Adding the shape would write .kirocrew-run-dir into the shared workspace and attempt a reclaim on it at shutdown. Left out intentionally.
  • Four issue-radar-* one-run shapes in apps/builtins/issue_radar/ (issue-radar-ai:…, issue-radar-pr-ai:…, issue-radar-reco:…, issue-radar-tagging:…) contain / and # in their keys, which complicate the dir-name derivation. They are a point-fix follow-on tracked in fix(session): reclaim issue-radar one-run work directories #23880.
  • Run directories named judge-<32 hex> created before this change (when the key used - as separator) carry no RUN_DIR_MARKER; the sweep has never touched unmarked directories and this PR does not change that. Those directories stay on disk as they are today. To clean them up manually: find ~/.kiro/crew/workspace -maxdepth 1 -regex ".*/judge-[0-9a-f]\{32\}" -empty -delete (removes only the empty ones the agent already stripped; inspect non-empty ones by hand).
  • Reclaiming memory-consolidation directories on Windows (tracked in doctor: count marked run folders the sweep keeps for their contents #16113) is out of scope.

What changed (motivation → approach → change)

The sweep already derives both _DISPOSABLE_SESSION_KEY_RE and DERIVED_NAME_RE from a single _DERIVED_SESSION_SHAPES table so the two regexes cannot diverge. Four session types emit keys that are not in that table, so their directories are never candidates.

The four new shapes are in the standard table (taskrunner:refine:…, hook:default:…, wf-author:…) and slot directly into 2-tuple table entries. The judge: key previously used - as separator but is changed here to : so it fits the standard table — nothing external required the old spelling. No existing entries change.

New pattern constants (_EPOCH_MS, _EPOCH_SECS, _TOKEN_HEX_6, _WF_RUN_ID, _WF_AUTHOR_ATTEMPT) name each sub-pattern so the table is self-documenting.

Intended? / Repro

Intended?: No. The _DERIVED_SESSION_SHAPES table was introduced in #16039 to cover subagent/cron/memory-consolidation; the issue #16049 explicitly documents the missing shapes as a follow-on. Code comments confirm the four session types are each fresh-minted per call.

Repro: By code reading — grep -n "_DERIVED_SESSION_SHAPES" src/kiro_crew/session_work_dir.py shows only the four original entries. grep -n "session_key.*judge-\|f\"judge-" src/kiro_crew/decisions/impl_llm.py shows the per-call key. The is_disposable_session_key("judge:" + "a" * 32) call returns False before this fix (verified in the new tests).

Backwards compatibility

Compatible: the change only adds new shapes to the table; no existing shape is removed or narrowed. The two compiled regexes now match a wider set of directory names and the sweep still requires the RUN_DIR_MARKER for any reclaim.

Removes nothing: the new pattern constants (_EPOCH_MS, _EPOCH_SECS, _TOKEN_HEX_6, _WF_RUN_ID, _WF_AUTHOR_ATTEMPT) are additive. No public symbol is removed or renamed.

Tests

test/test_session_work_dir.py — TestDisposableSessionKey:

  • Extended the parametrize list with True/False cases for every new shape, including boundary cases (too-short uuid hex, 12-digit epoch ms, 5-digit run id, non-hex chars).
  • test_judge_key_is_the_uuid4_hex_minted_by_impl_llm — calls uuid.uuid4().hex to produce a live judge: key and asserts it is disposable.
  • test_taskrunner_refine_key_matches_current_epoch_milliseconds — same with int(time.time() * 1000).
  • test_hook_default_key_matches_current_epoch_and_token — same with secrets.token_hex(6).
  • test_wf_author_key_matches_typical_allocator_run_ids — exercises run IDs wf_000001, wf_999999, wf_1000000 (the over-999999 case that produces 7 digits).
  • test_caller_supplied_hook_session_key_is_not_disposable — confirms a long-lived hook:my-webhook-session is never reclaimed.
  • Parametrize list extended with False cases for real long-lived key shapes: dashboard chat slot keys (chat-<counter>-<epoch s>), member DM slot keys (member-<slug>), member V2 slot keys with private memory store (member-<slug>.memory-<store>), and the member session alias form (dashboard:member-<slug>).
  • test_eval_keys_are_not_disposable — confirms that eval_* keys are never classified as disposable (documents the intentional exclusion).

Manual verification

N/A — unit coverage sufficient. All new shapes are exercised through is_disposable_session_key, DERIVED_NAME_RE.fullmatch, and _is_disposable_dir_name in the extended test suite.

Screenshots / video

N/A — backend-only change with no user-visible UI delta.

Related Issues

Fixes #16049

Pattern harvest

Rule candidate: session-work-dir
Pattern: When a new one-run session type is introduced that mints a per-run work directory, add its key shape to _DERIVED_SESSION_SHAPES in src/kiro_crew/session_work_dir.py. Both _DISPOSABLE_SESSION_KEY_RE and DERIVED_NAME_RE are compiled from that single table, so the key predicate and the directory-name filter cannot diverge. Use standard colon-separated components; directory names replace : with _ automatically.

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

@CrysisDeu
CrysisDeu requested review from a team and KiroCrewCaptain as code owners October 14, 2026 04:33
@CrysisDeu
CrysisDeu requested a review from mbriones98 October 14, 2026 04:33
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Oct 14, 2026
@CrysisDeu
CrysisDeu force-pushed the fix/16049-reclaim-judge-refine-hook-wfauthor-eval branch from 8fed9ea to 911d9de Compare October 14, 2026 04:37
@github-actions

github-actions Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision e1e56eef3efc00ea4b6c05139ae0a58d6a3166c6 touches no user-facing surface (no changes under website/ or committed screenshots), so the UX review was skipped. Does not block merge.

@github-actions

github-actions Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of e1e56eef3efc00ea4b6c05139ae0a58d6a3166c6 — 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 does not.

First-Principles-Verdict: PASS

Each new shape matches a key minted at one place in the source. The judge-→judge: rename has no other consumer in src/.

Notes

Inventory (6 items) — 5 justified

Intent: stop one-run judge, refine, default-webhook and workflow-author sessions from leaving work directories behind forever. FIX.

  1. The sweep now reclaims per-call judge session directories — justified
  2. The sweep now reclaims taskrunner refine-turn directories (taskrunner:refine:<ms>) — justified
  3. The sweep now reclaims default-webhook per-request directories (hook:default:<s>-<hex>); caller-supplied hook keys are kept — justified
  4. The sweep now reclaims workflow-author attempt directories (wf-author:wf_<n>:a<k>) — justified
  5. The judge session key separator changes from - to :; old judge- directories stay on disk — symptom-level: the shape table needs a manual entry for every one-run caller
  6. The acp-client spec and docstring list the new key shapes — justified

[FIRST-PRINCIPLES-REVIEWED] e1e56ee

Description read

[DESCRIPTION-READ] 7d6e6208e12fa9bbbb5b28c3c1138256c5e52fdd1da1b7f497b71f08ae2112d1

That sha256 names the PR description this verdict read. Recompute it with .github/scripts/pr-description-capture.sh; if it differs, the description changed after this verdict was formed and any finding drawn from the description is unproven.

@github-actions

github-actions Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of e1e56eef3efc00ea4b6c05139ae0a58d6a3166c6 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

Design-Verdict: PASS

Nothing blocks: the four shapes are added to the existing single table, and a reclaim still requires the marker.

Notes

  • Renaming the judge key from judge- to judge: changes the key's prefix shape. I grepped and found no reader that matches on judge-. Prefix classifiers such as history_reads and session_parts/policy now see a judge kind, which looks harmless and is easy to revert.
  • loader_config marks a directory disposable only when not cwd. If any of the four callers passes a cwd, its shape is a harmless no-op. That is worth one sanity check per caller.

[DESIGN-REVIEWED] e1e56ee

Description read

[DESCRIPTION-READ] 6a788eecdb5bcf18585f891ff2d362750b52ca159cf9da226bb597a07eb695d2

That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@CrysisDeu
CrysisDeu force-pushed the fix/16049-reclaim-judge-refine-hook-wfauthor-eval branch from 911d9de to 9719fc3 Compare October 14, 2026 04:53
@CrysisDeu CrysisDeu changed the title fix(session): reclaim judge, taskrunner-refine, hook-default, wf-author and eval run dirs fix(session): reclaim judge, taskrunner-refine, hook-default and wf-author run dirs Oct 14, 2026
@CrysisDeu
CrysisDeu force-pushed the fix/16049-reclaim-judge-refine-hook-wfauthor-eval branch from 9719fc3 to 6bd65aa Compare October 14, 2026 05:04
@github-actions

github-actions Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of e1e56eef3efc00ea4b6c05139ae0a58d6a3166c6 and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] e1e56ee

False positive or not applicable? A repository writer can comment:
/ai-review override gpt e1e56eef3efc00ea4b6c05139ae0a58d6a3166c6 false-positive: <reason, 20 to 500 characters>

@CrysisDeu
CrysisDeu force-pushed the fix/16049-reclaim-judge-refine-hook-wfauthor-eval branch from 6bd65aa to b081142 Compare October 14, 2026 05:16
@github-actions

github-actions Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

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

Review details

No findings.

[OPUS-REVIEWED] e1e56ee

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

False positive or not applicable? A repository writer can comment:
/ai-review override fable e1e56eef3efc00ea4b6c05139ae0a58d6a3166c6 false-positive: <reason, 20 to 500 characters>

@CrysisDeu
CrysisDeu force-pushed the fix/16049-reclaim-judge-refine-hook-wfauthor-eval branch 4 times, most recently from 3a46828 to 51f9ce5 Compare October 14, 2026 06:46
@CrysisDeu

Copy link
Copy Markdown
Contributor Author

Fixed: PR body updated. What changed now describes the _JUDGE_SHAPE_RE named-constant-plus-OR approach; Pattern harvest documents that a single non-standard-separator shape belongs in a named constant, not a generalised table extension; eval removed from Why it matters; backwards-compatibility no longer mentions the 3-tuple format. Head: 51f9ce5.

@CrysisDeu

Copy link
Copy Markdown
Contributor Author

Triggering readiness re-evaluation: all 111 CI checks now complete on head 51f9ce5.

@CrysisDeu
CrysisDeu force-pushed the fix/16049-reclaim-judge-refine-hook-wfauthor-eval branch 3 times, most recently from 03404de to 7c47b7d Compare October 14, 2026 08:18
@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running and removed readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention labels Oct 14, 2026
@CrysisDeu
CrysisDeu force-pushed the fix/16049-reclaim-judge-refine-hook-wfauthor-eval branch from 6409454 to f19f119 Compare October 14, 2026 08:29
@CrysisDeu

Copy link
Copy Markdown
Contributor Author

Fixed: PR body updated to match the current diff. The _JUDGE_SHAPE_RE reference removed from Backwards compatibility and Pattern harvest; Pattern harvest now describes the table-row approach; Tests section names only tests at this head; Backwards compatibility acknowledges pre-existing judge- dirs stay on disk (added to Not a goal with a manual cleanup note); five corrected to four session types.

@github-actions github-actions Bot removed the readiness: checking Automated validation is still running label Oct 14, 2026
@github-actions github-actions Bot added the readiness: passed Eligible automated validation passed for the current revision label Oct 14, 2026

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

REQUEST_CHANGES at f19f119. A human reviewer also needs to sign off, because this widens which work directories the sweep and shutdown reclaim delete (src/kiro_crew/session_work_dir.py, fed by the judge key change in src/kiro_crew/decisions/impl_llm.py).

  1. Wrong key in the spec. acp-client.md:258 says judge-<uuid4 hex>, but impl_llm.py:206 now mints judge:, and the new test pins the hyphen form as not disposable. Please change the spec to judge:<uuid4 hex>. Opus raised this on this head, and it has no reply yet.
  2. The description doesn't match the diff. The 08:38Z disposition says it was fixed, but the body still says 'five' session types and lists four. Pattern harvest also still proposes an AGENTS.md rule about a _JUDGE_SHAPE_RE constant that doesn't exist. Please correct both, or drop the harvest rule as First Principles suggests.
  3. The table comment stops mid-sentence after 'belong in this table;'.
  4. The issue-radar shapes are deferred as 'a point-fix follow-on' with no issue. Please open one and link it.

For the human reviewer: the generated hook:default:… key is returned to the caller, who can send it back. After this PR, that session's work dir is deleted at shutdown. Please confirm that is the intended contract.

— crew-pr-reviewer (r100)

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention merge conflict Branch has merge conflicts with its base — author must resolve before merge and removed readiness: passed Eligible automated validation passed for the current revision labels Oct 14, 2026
…uthor run dirs

Four session types mint fresh one-run work directories that _DERIVED_SESSION_SHAPES
did not cover, so their folders accumulated under the workspace root:
  - judge:<uuid4 hex> (decisions/impl_llm.py, separator changed from '-' to ':')
  - taskrunner:refine:<epoch ms> (dashboard/handlers/taskrunner.py)
  - hook:default:<epoch s>-<token_hex(6)> (dashboard/handlers/hooks.py)
  - wf-author:<wf_run_id>:a<attempt> (workflows/service.py)

Add them to the standard table with their exact key patterns. The judge key
previously used '-' as separator; changing to ':' lets it sit in the standard
table (colon in key, underscore in directory name) with no special-case literal.
A whole-repo grep of "judge-" as a string literal finds zero consumers outside
the minting line that was changed. Pre-existing unmarked judge-<hex> directories
on disk carry no RUN_DIR_MARKER; they are not counted or swept after this change
(the sweep has never touched unmarked directories from any build, and the doctor
census for the new judge shape reads judge_<hex> directory names).

Eval sessions are intentionally excluded: eval/runner.py shared_ws_factory sets
provider._client._work_dir = ws (a shared workspace).
Four issue-radar shapes with / and # in their keys are a follow-on fix.

Update acp-client.md to name the four new shapes in the disposable-directory
paragraph and clarify that the Windows/by-name walk restriction applies only to
memory-consolidation.

Tests: per-shape positive/negative cases; negative tests for eval_ keys, chat
and member long-lived slots.
@CrysisDeu
CrysisDeu force-pushed the fix/16049-reclaim-judge-refine-hook-wfauthor-eval branch from f19f119 to e1e56ee Compare October 25, 2026 00:04
@CrysisDeu

Copy link
Copy Markdown
Contributor Author

Addressed all four review points in e1e56ee (rebased onto current main):

  1. Wrong key in spec — acp-client.md now says judge:<uuid4 hex> to match the judge: separator the code mints. Commit e1e56ee.

  2. Description mismatch — Updated the PR description: changed "five" → "four" in both occurrences, removed the Pattern harvest section (it described a _JUDGE_SHAPE_RE approach that was not implemented; the table-row approach needs no separate constant), and removed all other stale references to _JUDGE_SHAPE_RE. The description now only names symbols and tests that exist at this head.

  3. Table comment truncated — Completed the sentence at session_work_dir.py (was: only standard colon/underscore entries belong in this table;; now ends: ...shapes whose directory names cannot be derived by replacing ':' with '_' go outside it.). Commit e1e56ee.

  4. Issue-radar shapes follow-on without an issue — Opened fix(session): reclaim issue-radar one-run work directories #23880 and linked it in the description ("a point-fix follow-on tracked in fix(session): reclaim issue-radar one-run work directories #23880").

Rebase conflict: impl_llm.py conflicted because main added _has_shared_runtime + run_bg_oneliner for the shared-runtime path alongside the existing _call_on_own_session. Resolution: keep main's structure and change judge- → judge: inside _call_on_own_session, so the key matches the table for both paths.

@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 merge conflict Branch has merge conflicts with its base — author must resolve before merge readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Oct 25, 2026
@iamwhatever

Copy link
Copy Markdown
Contributor

HOLD at e1e56ee for human review, not for a code defect.

All four points from my r100 review are fixed: the spec now says judge:<uuid4 hex> (acp-client.md:470), the description matches the diff, the table comment is complete, and the issue-radar follow-up is tracked in #23880. Every AI lane passed this head and CI is green.

Why a human must sign off: this widens which work directories the sweep and shutdown reclaim delete (session_work_dir.py:150-159) and changes the judge key so its directories become reclaimable (impl_llm.py:221). Deletion-scope changes are reserved for a person.

One contract question for that reviewer: the generated hook:default:… key (hooks.py:373) can be sent back by the caller as sessionKey. That session's directory is then treated as one-run and reclaimed. The handler already resets the session after each request, so this looks intended, but please confirm.

— crew-pr-reviewer (r125)

@iamwhatever
iamwhatever enabled auto-merge (squash) October 27, 2026 06:11
@iamwhatever
iamwhatever merged commit 78db8f1 into main Oct 27, 2026
116 of 117 checks passed
@iamwhatever
iamwhatever deleted the fix/16049-reclaim-judge-refine-hook-wfauthor-eval branch October 27, 2026 06:49
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Oct 27, 2026
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.

Run folders from judge, task-refine, hook and eval sessions are never reclaimed

2 participants