Skip to content

fix: close five monitor-ceiling and directive gaps left after #14371 - #14514

Merged
iamwhatever merged 2 commits into
kirodotdev:mainfrom
Pearcekieser:fix/monitor-ceiling-followups
Sep 28, 2026
Merged

iamwhatever merged 2 commits into
kirodotdev:mainfrom
Pearcekieser:fix/monitor-ceiling-followups

Conversation

@Pearcekieser

@Pearcekieser Pearcekieser commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: Monitor restart, stop refusals, directive notices and runtime-budget input all behave consistently after #14371, with no misleading errors, duplicate audit rows or silent refusals.

Five defects in code added by #14371 were deferred during its review and are listed in #14513. After an operator lowers the runtime ceiling, restarting a monitor fails with a 400 for a number the user never typed. An undecoded out-of-band directive frame is refused twice. A stale-wake stop is refused with arming wording and no visible notice. The MCP schemas advertise a fractional runtime type the validator rejects. The structured monitor API refuses 3600.0, which every other entry point accepts.

Why it matters

Operators who configure a lower ceiling cannot revive monitors from the dashboard. The audit trail double-counts denials. People get no signal when a stale wake's stop is refused. Agents reading the published schema can send values the server refuses.

Not a goal

What changed (motivation → approach → change)

Defect Change
Restart after a lowered ceiling returns 400 api_monitor_restart forwards a monitor whose budgets carry min(stored budget, runtime_ceiling_secs()), so the store's own check sees the clamped value; a ValueError from a ceiling change between the clamp and that check maps to an audited 400 with a code.
Undecoded OOB directive frame refused twice The native sub-agent branch settles its frame (clears _dir_tool, pops the pending entry) so it is refused once, and its audit row names the directive tool. The forged-marker branch leaves the pending entry in place, so an identified call whose marker does not decode still reaches the decode-failure path: one audit row, one notice, sentinel stripped.
Stale-wake stop uses arming wording and is not surfaced A wake-delivered stop is refused, with stop wording ("Monitor NOT stopped: ...") and a surfaced "⚠️ Automation loop NOT stopped:" row, when the wake's loop is no longer this session's monitor or when the current row is one a person paused (retained). A live wake still stops its own active loop.
MCP schema advertises number max_runtime_secs is "type": "integer" again; validate_runtime_secs still accepts JSON bodies that spell an integer as 3600.0.
Structured API refuses 3600.0 _bounded_int accepts an integral non-bool float and returns the int, so all five bounded fields (cadence_secs, max_agent_turns, max_tokens, max_provider_errors, max_runtime_secs) accept 3600.0; fractional and boolean values still get a 400 with code: invalid_monitor.

Backwards compatibility

None breaking. Each change narrows an error path added by #14371 or corrects its wording.

Tests

Each defect has a regression test that failed on main before its fix and passes after it:

  • test_autonudge_handlers_cov80.py: restart under a lowered ceiling, driven through the real authorizer and service, succeeds with the clamped budget; structured create and update accept 3600.0 for every bounded field and store the int, and refuse 3600.5 and true.
  • test_session_directive_input_digest.py: undecoded native and identified forged-marker frames each produce one denied audit row and one notice with the sentinel stripped; the native row names the directive tool.
  • test_monitor_directive_apply.py, against a real AutoNudgeService: a stale-wake stop of a replaced loop, or of a loop a person paused, is refused with stop wording and surfaced, and the paused row survives intact; a live wake stops its own active loop.
  • test_monitor_mcp.py: the published schemas declare integer; 3600.0 is still accepted.

Targeted suites (monitor, autonudge, directive, handler, MCP, transport, error-contract): 779 passed, plus 427 on the directive and transport suites after the documentation round. Every regression test drives the real service, not a mocked authorizer. flake8, black, mypy on touched sources and the comment-history gate are clean.

Manual verification

N/A: server-side paths only, all covered by the regression tests above.

Screenshots / video

Why no screenshot: No component or layout change. The only user-visible text change is the stop-refusal transcript row, which uses the existing refusal row style.

Related Issues

Fixes #14513. Follow-up to #14371.

Pattern harvest

Rule candidate: review-prompt
Pattern: When a gate is added to one branch of a dispatch (arm, revise, stop), check that every sibling branch gets matching wording, state cleanup and refusal surfacing.

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

@Pearcekieser
Pearcekieser requested a review from a team as a code owner September 27, 2026 18:51
@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 27, 2026
@github-actions

github-actions Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Fable 5, fork) — ✅ PASS

Design-level review of 2854906ff95063c4f3585495095fa06d53466edb 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

Verify the restart's silent clamp (7200→3600) is visible to the user somewhere — the response carries the new number but nothing says it changed.

Suggestions

  • When api_monitor_restart clamps a stored budget below what was armed, note the clamp in the response or a transcript row so the operator learns the loop restarted with a smaller budget than they originally typed.

[DESIGN-REVIEWED] 2854906

@github-actions

github-actions Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Fable 5, fork) — ✅ PASS

Premise-level review of 2854906ff95063c4f3585495095fa06d53466edb 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: PASS

Verify the restart clamp's silence: a stored 7200 budget quietly becomes 3600 with no notice to the operator — confirm #14513 agreed to that.

What this change ships

Inventory (7 items) — 7 justified

Intent: FIX — five deferred defects from #14371 (tracked in #14513): misleading restart 400s, doubled refusals, invisible stop denials, schema/validator mismatch.

  1. Restarting a monitor after the operator lowered the runtime ceiling now succeeds at the current ceiling — justified
  2. A store-raised error on restart returns a coded 400 instead of an unhandled 500 — justified
  3. An undecoded native sub-agent directive frame is refused once (one audit row, one note), and the row names the tool — justified
  4. A refused wake-delivered stop now says "Monitor NOT stopped" and posts a visible transcript notice; the gate's identity and retention checks are unchanged from base (_refuse_stale_wake_arm(require_current=True)) — justified
  5. MCP monitor schemas declare integer for max_runtime_secs, matching the validator that already refuses fractionals; no base test pinned number — justified
  6. All five bounded structured-API fields accept whole-number floats, the rule validate_runtime_secs's own docstring already pins; landing it in shared _bounded_int is smaller than a per-field case — justified
  7. Spec paragraph for the stop-refusal notice, same commit as the code (AGENTS.md mandate) — justified

Only one restart entry point exists (expected_existing_monitor_id= greps to 1 caller), so no unfixed clamp siblings; _WAKE_BOUND_MUTATIONS had 1 consumer, replaced in place.

[FIRST-PRINCIPLES-REVIEWED] 2854906

@github-actions

github-actions Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

GPT 5.6 Review (fork) — ✅ no blocking findings

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

Review details

No findings.
[GPT-REVIEWED] 2854906

@github-actions

github-actions Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5 Review (fork) — ✅ no blocking findings

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

Review details

Nothing blocks; the one unfixed sibling of the audit-name bug this PR fixes still writes a denied SEL row naming no tool.

FINDING — src/kiro_crew/dashboard/chat_runner.py:14014 — for an identified directive call whose marker fails to decode (the PR's own test_unclaimable_marker_on_an_identified_call_is_refused_once: mcp_server_name == CORE_MCP_SERVER, tool_name="monitor_start", sentinel + {not json), the identity gate at 13390-13399 files the name in _pending_dir_tool and writes nothing to _seen_tool_identity, so this branch's only denied audit row emits tool_name=_seen_tool_identity.get(event.tool_call_id, ("", ""))[1] = "" → SecurityEvent.operation="", and the marker path that handles the frame afterwards writes no row of its own → Fix: use the same expression the sibling hunk adopts 100 lines up — tool_name=_dir_tool or _seen_tool_identity.get(event.tool_call_id, ("", ""))[1] — here and at the provenance-ambiguous twin on 13929.

FINDING — docs/system-specs/modules/learn-cron-dashboard.md:2989 — the untouched "Monitor runtime ceiling" section still states a stored budget above the ceiling runs to its stored deadline, while min(monitor.budgets.max_runtime_secs, runtime_ceiling_secs()) in api_monitor_restart now silently rewrites a stored 7200 down to a lowered 3600 ceiling on the sole revival route (previously a 400), and no spec sentence says so → Fix: state the restart clamp in that section (and/or the restart-route paragraph at 3488) in this commit.

[OPUS-REVIEWED] 2854906

@Pearcekieser

Copy link
Copy Markdown
Contributor Author

Pushed 9ee35a7 on top of 1320c39. It fixes the three round-1 regressions and the First Principles float coverage; each fix has a test that failed on the previous head.

Two CI reds on this PR are inherited from main and reproduce on a clean origin/main (20ed6a1): the Electron Shell Tests port-owner-self-asserted-identity pins and the Frontend bnStyle Bengali-digits test. #14520 fixes both.

@Pearcekieser

Copy link
Copy Markdown
Contributor Author
  • Restart forwards the clamped budget

Disposition: fixed in 9ee35a7.
Restart now forwards a monitor whose budgets carry the clamped runtime (dataclasses.replace on the monitor and its budgets), so the store's own check sees the clamped value. The new test drives the real authorize_and_add_nudge and service: a stored 7200 budget under a 3600 ceiling restarts with 3600, where it previously raised and returned a 500.

@Pearcekieser

Copy link
Copy Markdown
Contributor Author
  • Decode-failure notice restored

Disposition: fixed in 9ee35a7.
The forged-marker branch no longer clears _dir_tool or pops the pending entry, so an identified call whose marker does not decode reaches the decode-failure path again: one denied audit row from the entry branch, one surfaced "Monitor was not set up." notice, and a tool result with the sentinel stripped and one verification instruction. The native-subagent branch keeps its clear, which its one-row test still pins; that path writes no SEL row, so no duplicate audit results.

@Pearcekieser

Copy link
Copy Markdown
Contributor Author
  • A stale wake cannot stop a person-paused loop

Disposition: fixed in 9ee35a7.
A stale-wake stop now also refuses a row that is inactive and not _stopped_row_is_replaceable (a person's pause, an empty reason), with stop wording and a surfaced refusal, so a wake can no longer delete a loop a person paused. A live wake still stops its own active loop. Tested against a real AutoNudgeService: the paused row survives intact.

@Pearcekieser

Copy link
Copy Markdown
Contributor Author
  • Restart forwards the clamped budget

Disposition: fixed in 9ee35a7.
Restart now forwards a monitor whose budgets carry the clamped runtime (dataclasses.replace on the monitor and its budgets), so the store's own check sees the clamped value. The new test drives the real authorize_and_add_nudge and service: a stored 7200 budget under a 3600 ceiling restarts with 3600, where it previously raised and returned a 500.

@Pearcekieser

Copy link
Copy Markdown
Contributor Author
  • Decode-failure notice restored

Disposition: fixed in 9ee35a7.
The forged-marker branch no longer clears _dir_tool or pops the pending entry, so an identified call whose marker does not decode reaches the decode-failure path again: one denied audit row from the entry branch, one surfaced "Monitor was not set up." notice, and a tool result with the sentinel stripped and one verification instruction. The native-subagent branch keeps its clear, which its one-row test still pins; that path writes no SEL row, so no duplicate audit results.

@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 labels Sep 27, 2026
@Pearcekieser

Copy link
Copy Markdown
Contributor Author
  • Stop gate keeps the retained-row refusal

Disposition: fixed in 9ee35a7.
The loosening is removed. A stale-wake stop now also refuses a row that is inactive and not _stopped_row_is_replaceable (a person's pause, an empty reason), with stop wording and a surfaced refusal, so a wake can no longer delete a loop a person paused. A live wake still stops its own active loop. Tested against a real AutoNudgeService: the paused row survives intact.

@Pearcekieser

Copy link
Copy Markdown
Contributor Author
  • Whole-number floats accepted for every budget field

Disposition: fixed in 9ee35a7.
The special case is gone: _bounded_int accepts an integral non-bool float and returns the int, so cadence_secs, max_agent_turns, max_tokens, max_provider_errors and max_runtime_secs all accept 3600.0, while fractional and boolean values are refused. The range check runs once. A parametrized test covers the five fields.

@Pearcekieser

Copy link
Copy Markdown
Contributor Author
  • Restart response names the clamped budget

Disposition: accepted-and-deferred.
Agreed it would make the clamp visible. The response contract is unchanged in this fix PR; a maintainer can track it with deferred-finding (as a fork contributor I cannot label issues).

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Sep 27, 2026
@Pearcekieser
Pearcekieser force-pushed the fix/monitor-ceiling-followups branch from 9ee35a7 to b21bd2f Compare September 27, 2026 21:04
@Pearcekieser

Copy link
Copy Markdown
Contributor Author

Pushed b21bd2f, which squashes the round-2 fixes into the second commit so the PR stays at two commits: the stop-gate comment and spec now describe stop refusals, native denial rows name the directive tool, and the description matches the code.

Two CI reds on this PR are inherited from main and reproduce on a clean origin/main (20ed6a1): Electron Shell Tests (port-owner-self-asserted-identity) and the Frontend bnStyle Bengali-digits test. #14516 fixes both. The earlier Windows backend shard 5 failure (test_crew_log_object_observed) is in code this PR does not touch and passes locally; this push re-runs it.

@Pearcekieser

Copy link
Copy Markdown
Contributor Author
  • Stop-gate comment names both checks

Disposition: fixed in b21bd2f.
The _STOP_DIRECTIVES comment no longer says the stop is gated on identity "and on nothing else"; it names both checks: the wake's loop must still be this session's monitor, and a person-paused (retained) row is refused. The _refuse_stale_wake_stop docstring already said so. The PR description is updated to match.

@Pearcekieser

Copy link
Copy Markdown
Contributor Author
  • Restart's coded 400 is declared

Disposition: fixed in b21bd2f.
The PR description now lists the restart route's except ValueError mapping to an audited 400 with code for the case where the ceiling changes between the clamp and the store's check.

@Pearcekieser

Copy link
Copy Markdown
Contributor Author
  • Float rule scope is declared

Disposition: fixed in b21bd2f.
The PR description now states that _bounded_int applies the whole-number-float rule to all five bounded fields, which is the shared-cause fix this lane asked for in round 1.

@Pearcekieser

Copy link
Copy Markdown
Contributor Author
  • Whole-number floats for every bounded field is intended

Disposition: rebutted.
Restricting the rule to max_runtime_secs would reintroduce the round-1 First Principles finding ("fixes only max_runtime_secs ... 4 sibling fields still refuse the whole-number floats the directive path accepts via int()"). JSON has one number type, and the directive path already accepts 3600.0 for these fields, so the API now agrees with it. Fractional and boolean values are still refused. The description now declares the five-field scope.

@Pearcekieser

Copy link
Copy Markdown
Contributor Author
  • The retained-row refusal on stops is required

Disposition: rebutted.
Removing the retention check reopens the round-1 Opus blocker: a person pauses the session's loop while its delivered wake is running, the wake calls autonudge_stop, passes the identity check alone, and svc.remove deletes the paused row irrecoverably. The stop contract is identity AND retention; the comment and description now say so, and a real-service test pins that the paused row survives.

@Pearcekieser

Copy link
Copy Markdown
Contributor Author
  • Native denial row names the directive tool

Disposition: fixed in b21bd2f.
The native sub-agent denial's audit row takes its tool name from _dir_tool (with the _seen_tool_identity fallback), because the identity gate files an identified call under _pending_dir_tool. The existing one-row test now asserts the denied row's tool name; it failed with tool_name: '' before the change.

@Pearcekieser

Copy link
Copy Markdown
Contributor Author
  • Stop refusals documented

Disposition: fixed in b21bd2f.
learn-cron-dashboard.md "Refusal visibility" and the _surface_arm_refusal docstring now list the stop refusal class and its ⚠️ Automation loop NOT stopped: prefix alongside arm and revision.

…dev#14371

Restart caps a stored budget at the live ceiling; undecoded out-of-band directive frames are refused once; stale-wake stops get an identity check with stop wording and a visible refusal; MCP schemas advertise integer runtimes again; structured API requests accept whole-number float runtimes.
…notices

A stale-wake stop refuses a person-paused row as the arm gate does; restart forwards a monitor whose budgets carry the clamped runtime; the forged-marker branch no longer clears the pending directive, so the decode-failure notice reaches the person; _bounded_int accepts whole-number floats for every monitor budget field; stop refusals are documented and native denial rows name the directive tool.
@Pearcekieser

Copy link
Copy Markdown
Contributor Author
  • Stale-wake stop retention check races a manual pause (session_directive_apply.py:523)

Disposition: accepted-and-deferred to #14535 (fixes #14533).
Confirmed: the identity-and-retention check runs without the service lock, _acquire_mutation_lock always yields, and svc.remove re-checks nothing, so a person's pause that lands in that window is deleted. The same check-then-remove sequence is on main via #14371, so it is fixed at the root in its own PR rather than here.
#14535 makes the stop a precondition-checked removal under the lock, and the unserialized removal refuses to run without the lock. A deterministic race test there fails on main for both monitor_stop and autonudge_stop.

@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 27, 2026
@iamwhatever
iamwhatever enabled auto-merge (squash) September 28, 2026 05:32
@iamwhatever
iamwhatever merged commit e4dd616 into kirodotdev:main Sep 28, 2026
100 checks passed
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Sep 28, 2026
@rubencu rubencu mentioned this pull request Sep 28, 2026
5 tasks done
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.

Monitor restart, stop refusals and runtime-budget input misbehave after #14371

2 participants