Skip to content

fix: resolve a gated loop's bare PR number from its own session log - #17490

Merged
chenmingwei23 merged 1 commit into
mainfrom
fix/bare-pr-number-probe-14488
Oct 7, 2026
Merged

chenmingwei23 merged 1 commit into
mainfrom
fix/bare-pr-number-probe-14488

Conversation

@buluoray

@buluoray buluoray commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: A gated loop that names its pull request as a bare PR <number> gets a probe, as long as its own session has already named that pull request's repository, instead of firing blind on its timer forever.

A monitor_start loop whose instruction says Babysit PR 14361 (no URL, and no URL in judge.targets) builds no monitor. probes.targets.infer selects a subject only from a full URL, and _PR_BARE requires a #, so PR 14361 is not even seen. Loop W5 on the live gateway fired 7 of 7 ticks on the plain timer with zero evidence items: no check state and no comment body ever reached the wake judge.

Why it matters

The loop looks armed and gated but observes nothing. Every interval spends a turn whether or not anything changed, and the wake judge that exists to read reviewer comments never gets any. Agents write PR <number> routinely even with the babysit skill's full-URL rule in front of them, and a hand-written monitor_start has no skill at all.

Not a goal

  • Inferring the repository from the project's git remote or any default repository (explicitly out of scope in the design ruling).
  • Changing how a text with a URL or an owner/name#N shorthand is resolved, including the existing ambiguity rules.
  • Resolving a bare number in judge.targets entries; only the instruction is resolved.
  • The pre-existing case PR 14361; blocked on <URL for #7>, where hash-less PR 14361 is invisible to the ambiguity guard and the loop gates on fix(sandbox): bypass toolbox shim to fix nested sandbox failure on macOS 26 #7. It is pinned by a test asserting the current answer.

What changed (motivation → approach → change)

Symptom → cause → change:

  • Cause. The instruction carries the number and the fact that it is a pull request, but not the repository, and nothing else was consulted.
  • Approach (per the issue's design ruling, 2026-10-03). Take the repository from the loop's own session transcript: a full /pull/<number> URL, or owner/name#<number>, with that exact number. If the transcript names none, or names two repositories, guess nothing and keep today's timer.
  • probes/targets.py (the one grammar): bare_pull_request_number finds exactly one PR <n> / PR #<n> / pull request <n> in a text that names no URL and no shorthand. resolve_bare scans context strings for that number in exactly one repository (case-folded); an issues/ link never matches. No host is pinned (host_key="default") because the instruction named none, which is also what lets a stored monitor reproduce the arm's answer. infer gains an optional context callable, called at most once and only for a bare-number text. Every existing caller passes none and gets the same answer as before.
  • autonudge_service/subject.py: infer_subject resolves the instruction through _resolve_instruction. On arm and retarget it reads the bound session's transcript through the guarded derive_messages (dashboard:<slot> for a dashboard loop, the key itself for a channel loop; a withheld transcript leaves the loop ungated). A stored loop (loop_subject, used by the gate, the post-poll rebinding and the terminal settlement) passes monitor_target= and resolves against its own monitor's target instead, so a tick reads no transcript on the event loop, the binding cannot drift as the log grows, and no module-level cache is needed.
  • autonudge_judge.parse_targets(..., watched=): the judge's collector cannot re-read the transcript, so for this one shape (no brief list, and the instruction's bare number equals the gh-pr monitor's number) it admits the monitor's own subject. Without this the probe would read the PR but the judge tick would still return "no usable target". Both callers (judge_tick.py, slack/gateway.py) pass watched_pr_subject(loop).
  • The babysit skill's gating bullet and docs/system-specs/modules/babysit-pr-watch.md now describe the bare-number rule. The skill still tells the agent to write the URL.

Backwards compatibility

Compatible: every new parameter is optional and defaults to the old behaviour, and a text that infers today infers the same subject. The only behaviour change is that a bare-number loop whose own transcript names exactly one repository for that number now gets a monitor instead of none.

Removes nothing: the change only adds a resolution source and an optional keyword. No validator is tightened, and no key, kind, record or function is removed or renamed.

Tests

  • test/test_probe_targets.py (+12): hash-less, hash and pull request spellings resolve from a URL in the log; no context still means no subject; a shorthand-only log resolves unpinned; URL + differently-cased shorthand for one repo is one repo; two repos refuse; other numbers or an issues/ link refuse; two bare numbers refuse without reading the log; a text that decides by itself (URL, shorthand, ambiguity, no PR) never reads the log; an unreadable log refuses rather than raising; the pre-existing PR 14361; blocked on <URL #7> residual is pinned at its current answer.
  • test/test_autonudge_bare_pr_number.py (new, 13): infer_monitor arms a gh-pr monitor from the session log under the dashboard: key, and a channel loop reads its own key; no match / two repos / a withheld transcript leave the loop ungated; no slot or a URL message never reads the log; a stored loop resolves the arm's exact subject from its monitor without reading the log, even after the log changes, and a monitor for another number resolves nothing; the judge collects the monitor subject only for a matching bare number; watched_pr_subject ignores a non-PR monitor; one test against the real ConversationLog under a temp KIROCREW_HOME.
  • Red on base: run against origin/main @ 9bf943b, the behavioural test test_the_real_conversation_log_is_read_under_the_dashboard_key fails with assert (None is not None), meaning no monitor is armed. The rest fail on the missing API.
  • Mutation matrix (each applied alone; every one reddens at least one test): infer ignores context (10 red), transcript key without the dashboard: prefix (3), collector ignores watched (1), first repository wins (2), stored loop reads the log instead of its monitor (2), # required (10), two bare numbers allowed (1), URL-in-text not excluded (1), issues/ links admitted (1), unguarded read_messages (5), case-sensitive slugs (1).
  • Run: timeout 900 python3 -m pytest -n0 test/test_probe_targets.py test/test_autonudge_bare_pr_number.py -x -q → 42 passed. The contract suites that CI caught on the first head (test_autonudge_refactor_contract.py, test_transcript_derivation_seam.py, test_review_repair_routing_skill.py) pass locally: 450 passed together with the two files above.

Manual verification

N/A: unit coverage exercises the real ConversationLog read path and the arming/tick/judge functions. No live gateway loop was armed. Read cost was measured on this host: an 84 MB transcript took 0.58 s cold, which is why ticks resolve from the stored monitor and never read the transcript.

Related Issues

Closes #14488. Follow-up to #14470 / #14480.

Pattern harvest

Not generalizable: the gap is specific to the bare-number spelling that the URL-only subject grammar deliberately never selected. The fix reuses that one grammar instead of introducing a new rule elsewhere.

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 (new tests pass locally; the wider suite is left to CI)
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

Contribution License Agreement

Contributions are accepted under the project's Apache-2.0 license.

@buluoray
buluoray requested a review from a team as a code owner October 6, 2026 19:10
@buluoray
buluoray requested a review from iamwhatever October 6, 2026 19:10
@buluoray
buluoray force-pushed the fix/bare-pr-number-probe-14488 branch 2 times, most recently from 2510e25 to 6dd7fdd Compare October 6, 2026 19:58
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Oct 6, 2026
@github-actions

github-actions Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — 🟡 CONCERNS

Premise-level review of 7303e95cfbcb5d20a741587ff409e9234e8fd262 — 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: CONCERNS

infer gets a lazy context callable whose laziness nobody uses. Both callers pass a list they already read, wrapped in a lambda.

Not justified as shipped

  • Item 6 — one consumer, generalized: the docstring says the parameter is "a callable so that the common text … never pays for reading a log". In this diff the log is never read inside infer. Grepping context= across src/kiro_crew finds 2 call sites, both in subject.py: context=lambda: stored and context=lambda: texts. Both wrap a list that was already read, in read_session_texts or from the stored monitor. The try/except around context() is guarding a read that this diff moved out of infer, yet its comment still says the log is "read … on every tick".
    Subtraction: delete the context parameter, its branch and the try/except from targets.infer. Have _resolve_instruction call targets.resolve_bare(message, texts) directly. infer_subject already returns early for WORK_LEDGER, and needs_session_texts already skips it.
    Clears when: infer has its old signature and both call sites use resolve_bare.

What this change ships

Inventory (8 items) — 7 justified

Intent: a loop told "Babysit PR 14361" actually watches that pull request instead of firing blind on its timer. This is a FIX (#14488, design ruling linked, a test that fails on base).

  1. A bare PR <n> loop gets a gh-pr monitor, taking the repository from its own transcript — justified
  2. A stored loop resolves its bare number from its monitor's target, so ticks read no transcript — justified
  3. The wake judge collects the monitor's subject for a bare-number instruction (parse_targets(watched=)) — justified
  4. The monitor_start ack reads the transcript, so it names the subject the loop will carry; the read is skipped under directive replay — justified
  5. Retarget reads the transcript before taking the lock and uses it only if the message and session still match — justified
  6. targets.infer gains a lazy context callable — one consumer, generalized: both callers pass lists they already read
  7. _gh_pr_target pulled out as a helper, with an unpinned-host branch — rides along
  8. The babysit skill's gating bullet and the spec describe the bare-number rule — justified

[FIRST-PRINCIPLES-REVIEWED] 7303e95

Description read

[DESCRIPTION-READ] e01d68bab01a7aa73ea0140f9db772cd4710865dee85e40d490165f778bb1545

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 6, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — 🟡 CONCERNS

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

Design-Verdict: CONCERNS

The repository for a bare PR <n> can come from untrusted text in the transcript, and the subject it produces is unpinned, so a loop can quietly watch, and be retired by, the wrong pull request.

Watch

  • Where the repository comes from. _session_texts takes every row's content from derive_messages and filters by nothing except type. That includes tool output, fetched pages, fork diffs and, for a channel loop, other people's messages. If the session never wrote the real URL, resolve_bare takes the one other/repo#14361 it finds there. The loop then gates on a pull request nobody named: it stays quiet on the real one, and when the wrong one merges, the terminal settlement can deactivate the watch. The "exactly one repository" rule only helps when the real URL also appears.
  • No host pin. _gh_pr_target(..., host=None) keys the subject as "default" even when the transcript gave a github.com URL. That brings back the ambient GH_HOST re-pointing hazard that the URL path's pin exists to stop. The reason given is to fit the stored-monitor format, not to reduce harm.

Clears when: resolve_bare reads only user- and assistant-authored rows (or the decision to include tool and channel rows is stated and pinned by a test), and a repository taken from a github.com URL keeps its host pin, or the description says why losing it is acceptable.

[DESIGN-REVIEWED] 7303e95

Description read

[DESCRIPTION-READ] e2e7b5e2b5247b79959c56ac3a06896aeca70faafb46cb25adbf2f1684ba7b75

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.

@github-actions

github-actions Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

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

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 7303e95

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

@github-actions

github-actions Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

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

Review details

No findings.

[OPUS-REVIEWED] 7303e95

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

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

@buluoray
buluoray force-pushed the fix/bare-pr-number-probe-14488 branch from 6dd7fdd to 8dbcd05 Compare October 6, 2026 22:48
@buluoray

buluoray commented Oct 6, 2026

Copy link
Copy Markdown
Contributor Author

Disposition of the review findings on 6dd7fddcf7. They are addressed in 8dbcd0575d.

GPT 6.1 BLOCKING, and the matching Opus 5.5 advisory: subject.py:118 reads the transcript on the event loop. Fixed.

  • Inference no longer reads a transcript. infer_subject and infer_monitor take a session_texts argument. With a bare number and no texts, they resolve nothing.
  • subject.read_session_texts is the only reader. It is a blocking guarded derive_messages read, and it returns None without reading unless the instruction is a bare PR <number> with a session key and the watch is not a work-ledger watch.
  • mutations._add_unserialized and _update_unserialized run read_session_texts with asyncio.to_thread before they take self._lock, then pass the result in. The retarget uses that result only when the loop still has the message and slot the read was taken for. Otherwise the bare number resolves nothing, the same as when the log is unreadable.
  • The retarget's old_probe now resolves against the current monitor (monitor_target=watched_pr_subject(loop)), so it does not read the log.
  • The monitor_start ack in mcp_tools/control.py is a synchronous tool handler and runs off the gateway loop. It reads the texts there, so the ack and the armed loop report the same gate.
  • New tests: test_inference_itself_never_reads_a_transcript, plus test_the_service_arm_reads_the_log_off_the_event_loop and test_the_service_retarget_reads_the_log_off_the_event_loop. The last two drive the real AutoNudgeService and assert that derive_messages ran on a thread other than the loop's thread.
  • Mutations: making the arm read synchronous, making the retarget read synchronous, dropping session_texts from the arm, and dropping it from the retarget each turn exactly one test red.
  • The Opus point that strict-mode OnLoopPersistError would be swallowed no longer applies, because the read never runs on the loop.

Design Review CONCERNS: a bare-number subject has no host pin. Kept on purpose; I'm recording it here as an accepted risk. The stored monitor target is a canonical owner/name#N, which cannot carry a host. A stored loop reproduces its subject from that target without reading the log again. If the arm pinned github.com from URL evidence, the stored-loop path could not reproduce the pin. The gate would then see the two disagree and fire on every tick, which is exactly the failure this PR fixes. With no pin, the probe follows the operator's gh configuration. That is what Target already documents for every shorthand subject. test_a_hashless_bare_number_resolves_from_a_url_in_the_session_log pins the current answer: even when the log spells a github.com URL, host_key == "default" and the config has no host key. Carrying a host on the stored monitor would be a monitor-schema change, which belongs in its own follow-up.

First Principles: PASS. Its note is the same host-pin point, covered above.

@buluoray
buluoray force-pushed the fix/bare-pr-number-probe-14488 branch from 8dbcd05 to 7303e95 Compare October 7, 2026 01:02
@buluoray

buluoray commented Oct 7, 2026

Copy link
Copy Markdown
Contributor Author

GPT 6.1 BLOCKING at 8dbcd0575d (mcp_tools/control.py: directive replay reads the transcript on the gateway event loop): confirmed and fixed in 7303e95cfb.

  • Verified: api_session_directive calls mcp_core.derive_directive synchronously, which re-runs monitor_start on the gateway loop; the handler's read_session_texts only shapes the ack text, which the replay discards.
  • Fix: the handler skips the read when mcp_core.directive_capture_active() is true (the bot's suggested fix). The applier still reads the log via asyncio.to_thread before taking the lock.
  • Tests: test_the_gateway_replay_never_reads_the_log_on_its_event_loop (replay derives the same directive and reads nothing) and test_the_tool_run_reads_the_log_to_shape_its_ack (positive control). Replacing the guard with False reddens the replay test. 258 pass across the bare-PR, probe-target, directive-queue, retained-stop and directive-digest files.
  • CodeQL neutral: "1 configuration not found" (/language:python default setup on main) -- a repo configuration notice, not a finding on this diff.

@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running labels Oct 7, 2026
@chenmingwei23
chenmingwei23 merged commit bd6d0b9 into main Oct 7, 2026
147 of 148 checks passed
@chenmingwei23
chenmingwei23 deleted the fix/bare-pr-number-probe-14488 branch October 7, 2026 04:14
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Oct 7, 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.

gated loop naming its PR as a bare 'PR <number>' gets no probe, so it fires blind forever

2 participants