Repository navigation
feat(work-ledger): enforce the goal's item cap in code - #18111
Conversation
UX Review (Opus 5.5) — ⏭️ skippedRevision |
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS The agent that hits the cap can raise it itself with What this change shipsInventory (9 items) — 9 justifiedIntent: stop a goal conductor from creating more items than the goal's spend cap (20 by default) without someone deciding to allow it. This is a FIX: the cap was already promised by #16987's skill text but only the prompt enforced it.
[FIRST-PRINCIPLES-REVIEWED] d433d53 Description read[DESCRIPTION-READ] 664438311b38c5ec8f9a9dd218e91cc775989eabac748c6b3df9f206a41e1731 That sha256 names the PR description this verdict read. Recompute it with |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Check that the refusal text names [DESIGN-REVIEWED] d433d53 Description read[DESCRIPTION-READ] 7b56e2036acf16b17d9941ada817b2561c45c036f36bb40cb9ec8116252e40d8 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 |
GPT 6.1 Review — ✅ no blocking findingsGPT 6.1 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
Opus 5.5 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
7b1c424 to
91a0bfb
Compare
|
|
|
|
|
Self-review (crew-pr-reviewer, read-only): RECOMMEND APPROVE This moves the goal-conductor's 20-item spend bound from prompt-only prose into the work ledger (#17076, T2): a |
buluoray
left a comment
There was a problem hiding this comment.
Request changes at 91a0bfb45d9c5ab3d77b57076e0ac00e9fcbd62e. Enforcing the goal's item cap in the store is right, and the mechanics are sound: the check runs inside _create_item under _existing_conductor_lock with the header re-read (src/kiro_crew/work_ledger.py:1996, :2022), the counter moves in the same hold (:2062), and a refusal returns before any item is written. One upgrade problem blocks, because auto-merge is on and this is the last gate.
Blocking: existing goal boards are refused with a wrong count after upgrade
goal_items_used is created_total - goal_items_base (work_ledger.py:319-321), and a header written before this PR has no goal_items_base, so it loads as 0 (:363). On an upgraded board the "items this goal created" is therefore the board's whole lifetime total, every earlier goal included. Reproduced: one goal created 22 items, a second goal was then recorded the old way, and the next create is refused with this goal has created 22 items and its item cap is 20, although the current goal has created none. A board running a user-approved Round-0 plan larger than 20 (which the old skill text allowed) is likewise stopped at item 21.
The refusal is visible, but it interrupts conductor work that was running fine on main and asks the user to raise a budget on a number that is wrong. That breaks existing users on upgrade.
Fix: treat a header with no stored goal_items_base key as grandfathered: seed the base from the current created_total on first read (so the current goal starts counting from the upgrade), rather than defaulting to 0. Add a test that loads a pre-PR header with a non-zero created_total and asserts the next create succeeds.
Verified / fail-closed
_write_goal(:1914-1923) re-reads the header under the lock and onlynew_goal=Truemoves the base; a pre-counter board backfillscreated_totalfirst.- Rebuild (
:3407,:3474-3478) keeps a cached cap/base only when the cache is clean andgoal_versionmatches; otherwise cap 20, base clamped. Fail-closed. _stored_item_cap(:369): absent or out-of-range reads as the default. Queue boards (goal_version == 0) are unaffected.
Mutation: removing the cap check reddens 7 tests incl. test_the_goal_item_cap_refuses_the_twenty_first_create_by_default; removing the goal_version > 0 gate reddens test_a_board_that_never_records_a_goal_has_no_goal_item_cap; removing the new_goal base move reddens test_a_new_goal_starts_a_new_item_count.
Non-blocking follow-ups
- The goal-conductor skill's "Goal changes mid-flight" section should mention
new_goal=true, so a replaced goal does not inherit the old count. - A dirty rebuild resets a user-raised cap to 20 and the next refusal looks like a first hit; consider saying so in the refusal or in
work_ledger_read.
CI: 86 success, 14 skipped, 0 failing. Not run: full suite, Windows/macOS, a real model end to end.
91a0bfb to
0a778bd
Compare
|
@buluoray thanks, fixed in 0a778bd (rebased on main).
|
|
Follow-up: the same fix is now at de76739. It renames the constant to |
0a778bd to
de76739
Compare
de76739 to
5b50f4a
Compare
5b50f4a to
d433d53
Compare
buluoray
left a comment
There was a problem hiding this comment.
Approve. The prior blocking finding is fixed at d433d53485.
Prior finding: FIXED. A header that has no goal_items_base now reads as LEGACY_GOAL_BASE instead of 0 (work_ledger.py:372-377). goal_items_used reports 0 for that state (:329-330). The first create or goal write under the lock then settles the base to the board's current created_total (_settle_goal_base, :391-394, called at :1955 and :2044). A clean rebuild settles it against the rebuilt total (:3535-3536). So after the upgrade, an existing board's goal starts counting from the upgrade and no longer from the board's first create. I checked this by mutation. Putting the old 0 default back in from_dict makes test_an_upgraded_header_counts_its_goal_from_the_upgrade, test_a_goal_write_settles_an_upgraded_headers_count_start and test_a_clean_rebuild_of_an_upgraded_header_counts_from_the_upgrade fail. Turning _settle_goal_base into a no-op, removing the goal_items_used legacy guard, removing the settle in _create_item, or forcing the rebuild's legacy branch to 0 each makes at least one of those tests fail.
I also checked that the -1 sentinel never reaches disk. If it did, it would read back as 0 and bring the bug back. Every writer of conductor.json either settles the base first (_write_goal, _create_item, _rebuild_locked), writes a fresh header with base 0 (ensure_conductor), or runs only after a goal write has already settled it (mark_goal_recorded).
What I ran: the work-ledger, projection, tools and agent-refactor golden tests at this head (490 passed), plus the mutations above. CI on this head: 85 success, 13 skipped, 0 failure, 0 pending.
Non-blocking follow-ups
- Nothing tests the
_write_goalbackfill branch for a legacy header (:1951, thecurrent.goal_items_base == LEGACY_GOAL_BASEhalf). This is a board from before bothcreated_totalandgoal_items_basewhose first post-upgrade action is a goal write withoutnew_goal. If that condition is narrowed back tonew_goalonly, every test stays green, but such a board would settle its base at 0 and then backfillcreated_totalon the next create, which charges all earlier items to the current goal. Please add a test that strips both keys and then doesaction=goal round=N. - A rebuild from a dirty cache, or one whose
goal_versiondiffers from the fold, falls back to base 0 (:3533-3534). That means an upgraded board that goes through that path counts its whole history against the default cap. This is deliberate (it asks the user sooner), the cause is rare, and the refusal names its remedy (item_cap), so it is not silent. Still, consider using the rebuilt total for a legacy header on this path as well, so the upgrade case behaves the same here as everywhere else.
Upgrade impact: existing goal boards keep working. Their current goal gets the default cap of 20, counted from the upgrade. Queue boards that never record a goal (pipeline and security conductors) have no goal cap. Audience fit: the default path is unchanged for boards without a goal. Goal conductors gain a bound enforced in code, and the refusal tells the conductor how to raise it.
Problem / Motivation
Goal: A conductor cannot dispatch more than its goal's item cap (20 by default) unless someone raises the cap, because the work ledger refuses the extra create.
Since #16987 the goal-conductor skill says a goal holds at most 20 items when the user set no budget. Only the prompt says so. The ledger's own cap,
MAX_ITEMS_PER_CONDUCTOR, counts OPEN items, so a conductor that closes items as it goes can keep creating them with no limit.Why it matters
The cap is the spend bound for back-to-back rounds. A model that forgets or miscounts it keeps dispatching workers, and each one costs tokens and host memory. A bound that lives only in prose is not a bound.
Not a goal
MAX_ITEMS_PER_CONDUCTOR(open fan-out) or the stored bound (256).What changed (motivation → approach → change)
item_cap, default 20, range 1..256; enforced once the board has recorded a goalgoal_item_cap_reached(409) and writes nothingwork_ledger_record action=goal item_cap=Naction=goal new_goal=truewith the new goal text; rewording, rounds and cap raises keep the countThe store change is in
src/kiro_crew/work_ledger.py; the field is plumbed through the tool schema (src/kiro_crew/mcp_work.py,src/kiro_crew/validation.py) and the route (src/kiro_crew/dashboard/handlers/work_ledger.py). The count resets on an explicitnew_goalflag, not on everygoal_versionbump and not on a changed goal text. Round and cap writes also bumpgoal_version, so a reset there would hand out a fresh 20 every round; a text compare would let a reworded goal reset it. Pipeline and security conductors never record a goal, so their queue boards keep only the open and stored bounds.The cap is a forced checkpoint, not a hard limit: the refusal stops dispatch and tells the conductor to ask, but the same agent can raise
item_capor setnew_goal. It catches a model that forgets or miscounts; it does not prove a person agreed.work_ledger_readalso returnsgoal_items_usedso the round report can say "items used: N of <item_cap>".The goal-conductor skill (
src/kiro_crew/builtin_skills/goal-conductor/SKILL.md), the conductor prompt (src/kiro_crew/agent.py), the work-ledger doc (src/kiro_crew/docs/work-ledger.md) and the work-ledger RFC's error list now point at the code check. Hitting the cap is a needs-human spend stop: pause and ask, do not stop the loop. The agent-spec byte pins are updated for the new conductor prompt text.Backwards compatibility
Compatible:
item_capandnew_goalare new optional fields. A header written before this PR has no stored count start, so its current goal is a legacy header: it starts counting at the upgrade, and earlier goals' items are not charged to it. Boards that never record a goal (pipeline, security) are unchanged.Removes nothing: the new check only adds a refusal for creates past a per-goal count. No field, route or code is removed or renamed.
Tests
test/test_work_ledger.py: the 21st create is refused by default with a stable code (goal_item_cap_reached) and writes nothing; closed items still count; a raised cap admits more and keeps the count; round-only, same-text and reworded goal writes keep the count;new_goal=truestarts a new count and needs the goal text; a board with no recorded goal is not goal-capped; an out-of-rangeitem_capis refused; a bad stored value reads as the default. The open-cap tests raise the goal cap first so they still reach the 32-open bound.test_an_upgraded_header_counts_its_goal_from_the_upgrade); a goal write and a clean rebuild settle the start the same way.test/test_work_ledger_projection.py: a clean rebuild keeps the cached cap; a dirty rebuild drops a refused goal write's cap and count start. A board from before the create counter starts a new goal's count after its records (intest/test_work_ledger.py). Both fixes were checked by reverting them: each test fails.test/test_work_ledger_tools.py: over HTTP the cap answers 409goal_item_cap_reached,action=goal item_capraises it, the read showsitem_capandgoal_items_used, and 257 is refused 400. The code→status map includes the new code.test/test_agent_refactor_spec_bytes.py,test/test_agent_refactor_contracts.py: pins updated for the conductor prompt.Determinism: the new tests have no timing, randomness or threads. They ran green repeatedly under
-n 8(random worker assignment) alongside the full work-ledger set.Manual verification
N/A — unit and route tests cover the store and the HTTP path; there is no UI change.
Related Issues
Closes #17076
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)