Skip to content

feat(skills): audit registered crons for a cheaper execution mode - #9592

Merged
bolichen97 merged 1 commit into
mainfrom
feat/cron-cost-optimize-skill
Sep 10, 2026
Merged

bolichen97 merged 1 commit into
mainfrom
feat/cron-cost-optimize-skill

Conversation

@bolichen97

@bolichen97 bolichen97 commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

What

Adds a cron-cost-optimize skill that audits already-registered cron jobs for a cheaper execution mode, and the two pieces of plumbing it needs to do that without reading anything it is not allowed to read.

Three shipped surfaces, all of them permanent:

  1. cron_list grows a json: true mode (_render_cron_list_json in mcp_cron.py, FieldSpec("json", bool) in CRON_LIST_SCHEMA). A machine-readable payload for a program rather than a reader, taking precedence over both verbose and the verbose shape ids implies. The two text renderers are untouched and byte-identical; all 64 pre-existing cron_list tests pass unmodified.
  2. A gateway-side run-history read (_fetch_history_stats). Permanent tool behavior, not a scan-time detail.
  3. The skill itself plus a stdlib-only scanner script that consumes the payload from (1).

Why the plumbing exists at all

A sandboxed skill script can read neither thing an audit needs, and the two failure modes are different:

  • crons.json IS sandbox-visible (a carve-out for mcp_cron), but reading it directly bypasses _owned_by ownership scoping, which would disclose other participants' job metadata. So the scan goes through the tool, which scopes.
  • cron-history is in sandbox._CREW_HIDDEN_LEAVES. On Linux the mask is a bind-mounted empty writable directory, so a naive reader succeeds, reports enabled, and returns zero records for every job — indistinguishable from a job that never fired. That silent-zero is why the read has to happen gateway-side over loopback with X-Internal-Secret (resolve_serving_port + read_local_secret, the same path cron_trigger uses) rather than in the script.

What crosses that boundary is COUNTS, not run text: a count cannot carry a credential. history is None — never an empty tally — for a job whose history could not be read, because a job with unknown history has not been shown to be idle and the consumer must tell those two apart. On a partial read, the jobs that were fetched keep their counts.

The scanner is biased toward the safe direction

A cron rewritten to a script that turns out to need a model fails silently: the job stays green and quietly stops doing its work. Over-matching a blocker costs a missed saving; under-matching costs a broken job. So the scan refuses rather than guesses in three cases:

  • The prompt arrived truncated (message_truncated), so a blocker could sit past the cut.
  • The prompt is in a language the scan cannot read. Every blocker is an English word list, so a non-English prompt matches none of them, and read naively that looks like a clean bill of health while pointing at the dangerous verdict. This limitation is stated in SKILL.md so the driving agent reads the prompt itself.
  • The run history is unknown rather than empty.

Payload bounds

_JSON_MAX_JOBS (100) caps the job count and _JSON_BYTE_BUDGET (88,000) caps the payload by measured serialized size, assembled incrementally. The byte bound is not redundant with the count bound: json.dumps escapes a non-ASCII character to a six-character \uXXXX, so 100 jobs with 400-character CJK prompts serialize to ~296,800 characters against MAX_RESPONSE_LEN (100,000) — and sanitize_response truncates with a blind tail slice that appends its notice outside the JSON grammar, so an over-budget payload would not parse at all. At least one record is always kept so a single oversize job is reported rather than dropped, and truncated is true when either bound shed a job.

Tested

157 tests across the new suites plus the existing cron_list and caller-identity suites. Every correctness fix in this PR was negative-controlled — the test was confirmed to fail with the fix removed — including the byte budget, the non-English refusal, and the plural skills blocker. mypy clean over 1388 files; flake8, black, isort and the builtin-skill scope gate clean. The gateway history fetch was verified live against a running gateway.

Docs: the cron_list section of docs/system-specs/modules/learn-cron-dashboard.md covers the json mode, its history semantics, and both bounds.

@bolichen97
bolichen97 requested review from a team and Zedmor September 9, 2026 00:02
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Sep 9, 2026
@github-actions

github-actions Bot commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Fable 5) — 🟡 CONCERNS

Design-level review of 1f8b4ec0783ba45ecdc3afe909c6aecac1c21d55 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

Design-Verdict: CONCERNS

The refusal-over-guess principle stops at script detection: Latin non-English prompts get high-confidence verdicts from English blocker lists that cannot read them.

Watch

The scanner hard-refuses CJK prompts but judges German/French ones on English word lists anyway — its own comment concedes a "fasse zusammen und entscheide" job "would be cleared for script mode precisely because the blockers could not see it", yet is_scannable_prose only tests for Latin script. A German job that depends on memory or a skill can come back enable-minimal-context with confidence: "high" (confidence there derives from run-count evidence, which cannot observe the blocker dimension) and an empty blocker list; the only mitigation is SKILL.md prose asking the driving agent to re-read such prompts — exactly the trust-the-prose posture the rest of the PR encodes deterministically. If the user accepts, the job silently loses memory/skills, the same quiet degradation the PR is built to prevent.
Clears when: the deterministic layer treats not-confidently-English Latin text like unreadable text (e.g. an English stopword-density check gating the refusal, or capping confidence at low/medium with an explicit "blockers could not be evaluated" note in the finding itself).

Suggestions

  • The noop_runs/same_every_run semantics (_NOOP_RE, _normalize_summary) are now frozen into the permanent cron_list json contract and its spec; consider documenting them as heuristic/subject-to-change so the skill can iterate the classifier without a tool-contract change each time.

[DESIGN-REVIEWED] 1f8b4ec

@github-actions

github-actions Bot commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

Opus 4.8 Review — ✅ no blocking findings

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

Review details

Based on my analysis of the diff and the single candidate:

Candidate 1 (Latin-script non-English prompt cleared for script rewrite): This is an intended, documented design behavior, not a defect. is_scannable_prose deliberately treats Latin-script text as readable and judges it on the English word lists — SKILL.md's "The scan only reads English prompts" section explicitly documents that "a German or French prompt can come back with an empty blocker set" and instructs the human to "Read those prompts yourself too before relaying a cheaper mode." The tool is read-only and the human applies every change; the test test_a_german_judgement_prompt_is_not_cleared_for_script deliberately pins only that the verdict is not high-confidence. The consequence is an advisory medium-confidence recommendation the human is told to double-check — not a reachable defect (no crash, no data loss, no security boundary crossed). The discovery pass itself scored it "low." It fails the 80+ bar and the fix (a positive English lexicon) would require new machinery. Dropped.

I re-derived the load-bearing security claims independently: ownership scoping happens upstream of _render_cron_list_json (confirmed by the TestOwnership behavior — list_jobs returns both sessions' jobs, only the owner's reaches the payload), history is fetched gateway-side over loopback with X-Internal-Secret, the sanitize-before-truncate order holds, and the byte budget keeps ≥1 record. No grounded defect in the changed lines.

No findings.

[OPUS-REVIEWED] 1f8b4ec

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

False positive or not applicable? A repository writer can comment:
/ai-review override fable 1f8b4ec0783ba45ecdc3afe909c6aecac1c21d55: <one-sentence reason>

@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 9, 2026
@github-actions

github-actions Bot commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Fable 5) — 🟡 CONCERNS

Premise-level review of 1f8b4ec0783ba45ecdc3afe909c6aecac1c21d55 — 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.

All load-bearing claims are verified: cron-history is in sandbox._CREW_HIDDEN_LEAVES (sandbox.py:285), the /api/crons/{id}/history?limit= endpoint exists and redacts summaries (handlers/cron.py:1658-1679), cron_trigger already uses the resolve_serving_port loopback path (mcp_cron.py:2707), MAX_RESPONSE_LEN is 100,000 with tail truncation (validation.py:79, 970), the 200-vs-30–55k token estimate is in-repo (mcp_cron.py:1187), skill scripts are an established pattern (12 sibling scripts), and every tool/CLI surface SKILL.md references exists. Here is the review:

First-Principles-Verdict: CONCERNS

The regex classifier ships three refusal branches patching a blindness it created itself — the consumer is a model that reads any language.

Not justified as shipped

  • Item 4 — symptom-level: the truncation, non-English, and Latin-non-English refusals (plus SKILL.md's repeated "read the prompt yourself") all patch one cause: linguistic judgement was put into English word lists (JUDGEMENT_RE/CONTEXT_RE) instead of the agent already driving the skill. The deterministic half (mode, history counts, thresholds) doesn't need them.
  • Item 7 — zero consumers: --min-runs is passed non-default by nothing (grepped min-runs: scanner, its tests, SKILL.md only).

What this change ships

Inventory (8 items) — 6 justified

Intent: help a user cut token spend on already-registered cron jobs by auditing them for cheaper execution modes — an ADDITION.

  1. A new cron-cost-optimize skill recommends a cheaper mode per registered cron — justified
  2. cron_list answers as a JSON document when asked (json: true) — justified
  3. Tool responses now carry per-job run-history counts, fetched over the gateway loopback — justified
  4. A regex verdict classifier that refuses truncated and non-English prompts — symptom-level: the refusals patch the word-list choice itself
  5. The JSON payload caps itself by count and measured bytes, flagging truncated — justified
  6. Prompts are cut at 400 chars with a message_truncated flag — justified
  7. Scanner --min-runs knob — zero consumers: nothing passes a non-default
  8. The cron spec doc gains the json mode section, same commit — justified

Watch

  • The pinned boundary claim doesn't match the code: test_cron_history_fold.py says "the fold happens gateway-side", but _fold_runs runs in mcp_cron after resp.read() — redacted run summaries do cross into the sandboxed process; only the tool response carries counts. Clears when: the docstring/description states the fold is client-side, or the fold moves behind /api/crons/{id}/history.
  • Item 4: the scan's linguistic verdicts duplicate what the driving agent does better; the deterministic value is the history counts and thresholds. Clears when: the prompt-classification branches move to the SKILL.md rubric, or the author names why the word lists must own that judgement (e.g. a measured inference cost).

Subtractions

  • Drop --min-runs from cron_cost_scan.py — zero non-default consumers (grepped min-runs); keep DEFAULT_MIN_RUNS = 5.
  • Shrink the scanner to its deterministic half: delete JUDGEMENT_RE, CONTEXT_RE, _LATIN_WORD_RE/is_scannable_prose and the two refusal branches; the SKILL.md already instructs the agent to judge the prompt in every case those regexes can't.

[FIRST-PRINCIPLES-REVIEWED] 1f8b4ec

@github-actions

github-actions Bot commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

GPT 5.6 Review — ✅ no blocking findings

GPT 5.6 completed its review of 1f8b4ec0783ba45ecdc3afe909c6aecac1c21d55 and found no blocking issues.

This comment is updated in place on each push.

Review details

FINDING -- src/kiro_crew/builtin_skills/cron-cost-optimize/scripts/cron_cost_scan.py:401 -- unknown history still yields "move-to-script", contrary to the stated refusal -> Fix: return leave-as-is when evidence.known is false. (origin: validation)
[GPT-REVIEWED] 1f8b4ec

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 1f8b4ec0783ba45ecdc3afe909c6aecac1c21d55: <one-sentence reason>

@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 9, 2026
@bolichen97

bolichen97 commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor Author

Superseded, and no longer a disposition record. It was written against head e1c325e3 where the scanner read crons.json directly. That code is gone: the scanner now consumes the cron_list json payload, so the tool applies _owned_by and the ownership-scoping gap this answered no longer exists in the diff. The original reasoning is kept below for the record.

It also claimed span= as a path and line rather than a pr_findings.py span identity, which the disposition gate correctly rejected. Removing the marker clears that violation without deleting the reasoning.


The finding holds: load_jobs reads crons.json directly and returns every job, with no _owned_by filter, disclosing other sessions' job names/IDs/schedules in a multi-user (Slack/Discord per-session) deployment.

The fix GPT names -- "read through a session-authenticated API that applies _owned_by" -- cannot be done from inside this script as a local edit. _owned_by is scoped by _authz_session_key(), which is a STRICT resolver that deliberately refuses the ambient KIROCREW_SESSION_KEY env var as an authorization source (its own docstring: that value is "agent-writable and therefore forgeable" -- tolerable for audit labeling, not for "deciding who may delete whose scheduled job"). A standalone script invoked via subprocess has no HMAC-verified caller block and no gateway-vouched identity to filter on, so reading os.environ["KIROCREW_SESSION_KEY"] locally and filtering by it would reintroduce a spoofable check, not close the gap.

Closing this for real needs a new gateway-mediated, ownership-scoped, machine-readable surface (an MCP tool returning structured JSON, or an HTTP route) that this script calls instead of opening crons.json itself -- the same missing piece Design Review's BLOCK on this PR names for cron-history (which is already OS-masked from every sandboxed shell, _CREW_HIDDEN_LEAVES). Building that surface is an architecture decision (shape, which tool/route, whether it's worth adding for this one skill) outside what I can decide unilaterally while driving this PR to green.

needs-a-decision: should cron_cost_scan.py gain a new gateway-mediated JSON surface for scoped job + history reads (extending cron_list or a dashboard route), or should this skill's scope be narrowed to single-session/local-only deployments with an explicit refusal/warning when session_keys other than the caller's own are present in the store?

@bolichen97

Copy link
Copy Markdown
Contributor Author

Disposition: needs-a-decision -- Blocker (cron-history is OS-masked from every sandboxed agent shell, exactly where SKILL.md tells the agent to run the scan)

The finding holds: cron-history is in sandbox.py's _CREW_HIDDEN_LEAVES ("bind-masked in every mode"; "every legitimate reader goes through the gateway" -- see security/paths.py:376-382 for the same rationale), so load_history's direct (home / "cron-history" / f"{job_id}.jsonl").read_text(...) cannot see real run history from inside the sandboxed shell SKILL.md instructs the agent to run this script from. It degrades silently to "history none recorded yet" / low confidence, which understates evidence the user actually has.

This shares its root cause with the GPT 5.6 BLOCKING finding on this same head (raw crons.json scan bypassing _owned_by session scoping): both need a gateway-mediated read path that does not exist today. cron_list (the existing MCP tool) renders human-readable text for chat display and carries no history stats; there is no JSON/structured surface for either scoped-job-list or per-job-history reads. No builtin skill script in this repo authenticates back to the gateway's own HTTP API today, so this would be new plumbing, not a call-site fix.

Design's own suggested fixes are exactly this: "extend the cron MCP tools or an HTTP route the skill queries" -- both real options, and picking between them (plus whether it's worth building for one skill) is a maintainer call, not something I should decide while driving CI green.

needs-a-decision: which surface should carry ownership-scoped job records + per-job history stats to a builtin-skill script running in its own sandboxed shell -- an extended cron_list MCP tool (adding a --json structured mode with history), a new dashboard HTTP route the script calls with a session-scoped token, or should this skill instead be scoped down (single-session use only, explicit "cannot read run history from here" degradation stated up front rather than silently)? The Watch item (schema re-spelling with no pinning test) is separable and can be fixed in this PR once the Blocker's resolution is known, since fixing it now risks touching code that gets replaced by whichever surface is chosen.

@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 9, 2026
@github-actions

github-actions Bot commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Fable 5) — ⏭️ skipped

Revision 1f8b4ec0783ba45ecdc3afe909c6aecac1c21d55 touches no user-facing surface (no changes under website/ or committed screenshots), so the UX review was skipped. Advisory — does not block merge.

@bolichen97

Copy link
Copy Markdown
Contributor Author

Both blockers are resolved in fd8cf8bb8, and they turned out to be one root cause: the scanner opened two paths a sandboxed process must not and cannot read.

The GPT finding was right about the store. Every cron MCP tool scopes a caller to the jobs it owns, via _owned_by against a gateway-vouched session key. Opening crons.json directly skipped that, so a non-owner sharing one data home saw every participant's job metadata. Worth noting why the read was even possible: crons.json is sandbox-visible only as a carve-out for mcp_cron itself.

The Design finding was worse than a degradation. cron-history is in _CREW_HIDDEN_LEAVES, and the two platforms fail differently. On macOS the store resolves to disabled. On Linux the mask is a bind-mounted EMPTY WRITABLE directory, so prepare() succeeds, enabled is True, and every read returns zero records. A job whose history was unreadable was therefore indistinguishable from a job that had never fired, which is fatal to this skill specifically, since its whole claim is that recorded runs rather than prompt wording are the evidence. Traced through the launcher and profile builders, not assumed.

The fix is the one surface both reviews named. cron_list gains a json flag:

  • Ownership comes for free: the filter already runs there against the strict session key. An unidentified caller still gets the scoped-empty sentence, and the script relays it verbatim rather than treating it as an error.
  • History is fetched from the gateway for the already-scoped ids only, over loopback with X-Internal-Secret, using the same port and credential resolvers as cron_trigger. Verified live against a running gateway, not just unit-tested.
  • Counts cross the boundary, not the run text they came from. A count cannot carry a credential, and folding gateway-side keeps the payload small.
  • A read that cannot happen sets history_available false and leaves every job's history null. Never an empty tally, because unknown and idle are different facts and conflating them was the defect.
  • The payload bounds itself and reports it. The response cap is a blind tail slice, which would hand a consumer an unparseable JSON document.
  • Every free-text field is sanitized before truncation, per job.

json wins over verbose and over the verbose that ids forces on, since it serves a program rather than a reader. Both text shapes are unchanged and all 64 existing cron_list tests pass untouched.

The scanner now reads that document on stdin and opens nothing. Its folding logic moved to cron_history_stats so the computation sits next to the data instead of being duplicated, leaving the script with only the judgement. An unreadable history is stated before any verdict, because every verdict then rests on wording alone.

Also picked up 2dc569968's intent: that commit fixed a Windows failure in test_default_location, and the home resolver it protected no longer exists, so the test went with it rather than being carried forward dead.

34 new tests across the three pieces. Full local run: 390 passing over the new suites plus the existing cron_list, caller-identity, frontmatter, skill-packaging and skill-home-path suites, the builtin-skill scope gate, black, isort, flake8, and mypy over the whole package.

@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 9, 2026
@bolichen97
bolichen97 force-pushed the feat/cron-cost-optimize-skill branch from fd8cf8b to 72765b2 Compare September 9, 2026 21:49
@bolichen97
bolichen97 requested a review from a team September 9, 2026 21:49
@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 9, 2026
@bolichen97
bolichen97 force-pushed the feat/cron-cost-optimize-skill branch from 72765b2 to 44fb4e2 Compare September 9, 2026 22:50
@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 9, 2026
@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: checking Automated validation is still running labels Sep 10, 2026
@bolichen97
bolichen97 force-pushed the feat/cron-cost-optimize-skill branch from e26746d to 105b3c9 Compare September 10, 2026 03:25
@bolichen97

Copy link
Copy Markdown
Contributor Author

Round 3. The two advisory findings are fixed on 105b3c9b3. The BLOCKING one I am rebutting rather than implementing, and its own adjudicator reached the same conclusion.

Fixed: function-local imports. json, urllib.request, read_local_secret, fold_runs and loopback_urlopen are now module-scope. Checked the two exemptions the rule carries before hoisting: no import cycle (none of the three modules imports mcp_cron), and no boot-path cost worth measuring, since config.loader was already imported here at module scope. This follows the repo's own precedent that the rule governs where the statement sits unless a cycle or a measured cost says otherwise.

Fixed: the description contradicted the partial-fetch behaviour. It said "every job's history is null" when a partial read keeps the history it did fetch. It now says each UNFETCHED job's history is null and states that a partial read keeps the rest. My own code comment and test_a_partial_fetch_leaves_the_unfetched_jobs_null already pinned the real behaviour, so the description was the wrong half.

Rebutting: --input does not expose credential files. Two independent reasons, and the adjudication FLAGGED this finding on the first of them:

  1. --input grants no capability beyond what the caller already has. The only caller is the agent's own shell tool, which can cat any readable path directly. The proposed fix — remove --input, take stdin only — does not remove the capability, it relocates it: cat ~/.aws/credentials | cron_cost_scan.py reaches exactly the same bytes through exactly the same privileges. A fix that leaves the described path open is not a fix.
  2. The path named in the finding is bind-masked. .aws is in _SENSITIVE_HOME_DIRS, hidden in every agent sandbox mode, so a sandboxed invocation reads a masked file and there are no credential bytes to echo. The exploit needs a caller who cannot already read the file yet controls the script's argv, in a run where credential homes are un-masked — and the sole caller is the sandboxed agent shell, so those two conditions cannot both hold.

There is also a correctness reason not to drop --input: SKILL.md deliberately routes the payload through a FILE rather than the command line, because a cron prompt containing backticks or $(...) would otherwise be executed by the shell. That is the same rule the five-whys skill follows for free text. Removing --input pushes callers toward either the unsafe command-line form or a cat pipe that reads the identical arbitrary path.

@bolichen97 this one needs your call, since only a repository writer can clear it:

/ai-review override gpt 105b3c9b3: --input reads with the calling shell's own privileges so it grants nothing beyond cat, and .aws is bind-masked in every sandbox mode, so the stdin-only fix would relocate the same read rather than close it.

Local state on 105b3c9b3: 149 tests passing across the new suites plus the existing cron_list and caller-identity suites, mypy clean over 1384 files, flake8, black, isort and the builtin-skill scope gate clean, and the gateway history fetch re-verified live after the import hoist.

@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 10, 2026
@bolichen97

Copy link
Copy Markdown
Contributor Author

/ai-review override gpt 105b3c9: --input reads with the calling shell own privileges so it grants nothing beyond cat, and .aws is bind-masked in every sandbox mode, so the stdin-only fix would relocate the same read rather than close it; authorized by bolichen as a repository writer.

@github-actions

Copy link
Copy Markdown
Contributor

Human judgment recorded

@bolichen97 marked the gpt AI finding as false positive, not applicable, or explicitly accepted for 105b3c9b3324080751bb8963d0af4643a236d7b8.

--input reads with the calling shell own privileges so it grants nothing beyond cat, and .aws is bind-masked in every sandbox mode, so the stdin-only fix would relocate the same read rather than close it; authorized by bolichen as a repository writer.

This decision applies only to this commit. A new push requires a new judgment.

@github-actions

Copy link
Copy Markdown
Contributor

Human judgment recorded, but the following reviewer lane(s) could not be re-run automatically: GPT 5.6. Re-run the lane's latest workflow run for 105b3c9b3324080751bb8963d0af4643a236d7b8 manually from the Actions tab.

@github-actions github-actions Bot added the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Sep 10, 2026
@bolichen97
bolichen97 force-pushed the feat/cron-cost-optimize-skill branch from 105b3c9 to 31e006a Compare September 10, 2026 03:51
@bolichen97

Copy link
Copy Markdown
Contributor Author

Rebased onto 160343495 to clear a merge conflict with main (mcp_cron.py import block, from PR #9773 moving _parse_time_string into cron.py). That conflict was the reason CI, GPT and the other reviews had not run on the previous head at all: a pull_request workflow runs against the merge ref, and while the PR was CONFLICTING that ref could not be created, so only the three pull_request_target workflows fired. The PR is MERGEABLE again and 39 checks are running.

The scanner file is byte-identical across the rebase, so the previously authorized override still applies unchanged and only needs re-anchoring to the new head:

/ai-review override gpt 31e006a: --input reads with the calling shell own privileges so it grants nothing beyond cat, and .aws is bind-masked in every sandbox mode, so the stdin-only fix would relocate the same read rather than close it; authorized by bolichen as a repository writer.

@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 merge conflict Branch has merge conflicts with its base — author must resolve before merge labels Sep 10, 2026
A cron job dispatched to the agent pays for its whole injected context on every
wake, whether or not the wake had anything to do. ASBX measured that cohort at 36
percent of all sessions, 93 percent of their cost spent re-loading static context
rather than reasoning, and 43 percent of runs concluding there was nothing to do.
Two cheaper modes already exist -- a script or command job takes no agent turn,
and an agent job with minimal_context keeps the agent but drops the bulk of the
context -- and neither reaches a job registered before its owner knew about them.

Adds a cron-cost-optimize skill and the deterministic scanner it drives, so the
audit itself costs no inference.

Both reads go through the gateway, because a sandboxed process must not and
cannot do either itself:

- The job store is ownership-scoped by cron_list against a gateway-vouched
  session key. Reading crons.json directly would skip that, so a non-owner
  sharing one data home would see every participant's job metadata. It is
  sandbox-visible at all only as a carve-out for mcp_cron itself.
- cron-history is masked outright, and the two platforms fail differently: on
  macOS the store resolves to disabled, but on Linux the mask is a bind-mounted
  EMPTY WRITABLE directory, so prepare() succeeds, enabled is True, and every
  read returns zero records. A job whose history was unreadable would be
  indistinguishable from one that had never fired -- fatal here, since the whole
  claim is that recorded runs rather than prompt wording are the evidence.

So cron_list gains a json flag. Ownership comes free from the filter already
running there. History is fetched from the gateway for the already-scoped ids
only, over loopback with X-Internal-Secret, using the same port and credential
resolvers as cron_trigger. Counts cross that boundary, not the run text they came
from: a count cannot carry a credential, and folding gateway-side keeps the
payload small. A read that cannot happen sets history_available false and leaves
each job's history null, never an empty tally, because unknown and idle are
different facts. The payload bounds itself and reports it, since the response cap
is a blind tail slice that would hand a consumer unparseable JSON. Every
free-text field is sanitized before truncation.

json wins over verbose and over the verbose that ids forces on, because it serves
a program rather than a reader. Both text shapes stay byte-identical and all 64
existing cron_list tests pass untouched.

The scanner reads that document on stdin and opens nothing. Its history folding
lives in cron_history_stats so the computation sits next to the data, leaving the
script with only the judgement. An unreadable history is stated before any
verdict, because every verdict then rests on wording alone.

Recommend, never auto-apply. A script rewrite drops the carried previous result:
build_cron_session_context prepends the last run's output only on the agent path,
and the job object inside a cron script exposes just its id and message, so a job
whose dedup relies on the agent recognising its own earlier answer silently starts
repeating itself. minimal_context injects no skill at all, so a job naming one
stops working. Judgement verbs match on stems and block a script rewrite outright,
because that failure mode is the silent one; an over-block only costs a missed
saving.

Verified read-only by a test that compares the tree and every mtime across a scan,
and the gateway fetch verified live against a running gateway.
@bolichen97
bolichen97 force-pushed the feat/cron-cost-optimize-skill branch from 31e006a to 1f8b4ec Compare September 10, 2026 04:11
@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 10, 2026
@bolichen97
bolichen97 merged commit 6d691b4 into main Sep 10, 2026
67 of 73 checks passed
@bolichen97
bolichen97 deleted the feat/cron-cost-optimize-skill branch September 10, 2026 06:16
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Sep 10, 2026
amadsalmon pushed a commit to amadsalmon/KiroCrew that referenced this pull request Sep 22, 2026
…rodotdev#9592)

A cron job dispatched to the agent pays for its whole injected context on every
wake, whether or not the wake had anything to do. ASBX measured that cohort at 36
percent of all sessions, 93 percent of their cost spent re-loading static context
rather than reasoning, and 43 percent of runs concluding there was nothing to do.
Two cheaper modes already exist -- a script or command job takes no agent turn,
and an agent job with minimal_context keeps the agent but drops the bulk of the
context -- and neither reaches a job registered before its owner knew about them.

Adds a cron-cost-optimize skill and the deterministic scanner it drives, so the
audit itself costs no inference.

Both reads go through the gateway, because a sandboxed process must not and
cannot do either itself:

- The job store is ownership-scoped by cron_list against a gateway-vouched
  session key. Reading crons.json directly would skip that, so a non-owner
  sharing one data home would see every participant's job metadata. It is
  sandbox-visible at all only as a carve-out for mcp_cron itself.
- cron-history is masked outright, and the two platforms fail differently: on
  macOS the store resolves to disabled, but on Linux the mask is a bind-mounted
  EMPTY WRITABLE directory, so prepare() succeeds, enabled is True, and every
  read returns zero records. A job whose history was unreadable would be
  indistinguishable from one that had never fired -- fatal here, since the whole
  claim is that recorded runs rather than prompt wording are the evidence.

So cron_list gains a json flag. Ownership comes free from the filter already
running there. History is fetched from the gateway for the already-scoped ids
only, over loopback with X-Internal-Secret, using the same port and credential
resolvers as cron_trigger. Counts cross that boundary, not the run text they came
from: a count cannot carry a credential, and folding gateway-side keeps the
payload small. A read that cannot happen sets history_available false and leaves
each job's history null, never an empty tally, because unknown and idle are
different facts. The payload bounds itself and reports it, since the response cap
is a blind tail slice that would hand a consumer unparseable JSON. Every
free-text field is sanitized before truncation.

json wins over verbose and over the verbose that ids forces on, because it serves
a program rather than a reader. Both text shapes stay byte-identical and all 64
existing cron_list tests pass untouched.

The scanner reads that document on stdin and opens nothing. Its history folding
lives in cron_history_stats so the computation sits next to the data, leaving the
script with only the judgement. An unreadable history is stated before any
verdict, because every verdict then rests on wording alone.

Recommend, never auto-apply. A script rewrite drops the carried previous result:
build_cron_session_context prepends the last run's output only on the agent path,
and the job object inside a cron script exposes just its id and message, so a job
whose dedup relies on the agent recognising its own earlier answer silently starts
repeating itself. minimal_context injects no skill at all, so a job naming one
stops working. Judgement verbs match on stems and block a script rewrite outright,
because that failure mode is the silent one; an over-block only costs a missed
saving.

Verified read-only by a test that compares the tree and every mtime across a scan,
and the gateway fetch verified live against a running gateway.
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.

2 participants