Skip to content

feat(autonomy): re-promote a demoted cell once its predicate is met again - #12394

Merged
kyle-sexton merged 6 commits into
mainfrom
feat/q-demote-reearn
Nov 2, 2026
Merged

kyle-sexton merged 6 commits into
mainfrom
feat/q-demote-reearn

Conversation

@kyle-sexton

@kyle-sexton kyle-sexton commented Nov 2, 2026 •

Copy link
Copy Markdown
Member

Refs: #12434
Refs: #11022

Decision record: owner decision Q-DEMOTE (a), recorded on #11022 (#11022 (comment)) and in the owner-decisions record (melodic-software/architecture#17); the owner confirmed that record in their own words ("Keep it (Recommended)") on 2026-11-02.

Summary

Owner decision Q-DEMOTE (a), recorded in #12434 (#12434): the owner answered "go w/ recommended" in the hub session on 2026-11-01 at 21:4xZ, choosing "(a) Recommended: the cell re-promotes once it meets the existing promotion rule again, counted from the demotion ... No new threshold, no settings write." After a demotion, a promotable cell now re-promotes from run evidence once it meets its existing predicate again, counted from the demotion. Before this change it stayed unpromoted until a person re-ratified the binding. No new threshold, no settings or binding write, and the lane-writable refusals are unchanged.

Fix

  • Publisher (publish-promotion-evidence.mjs, operator-side, the lane cannot write its output):
    • Every contrary event gets discovered, the publish run's time the first time it appears in the file, kept forever. A run stamps at least one second after the prior generated_at, and refuses when its clock is behind the prior publish.
    • An event from a file written before this change is stamped once, on the first publish over that file, with that file's generated_at rounded up to a second. publish() allows exactly that one change (a prior contrary event with no discovered gaining that value); every other changed, added or removed discovered is refused, as a dropped contrary event already is.
    • Once the existing report() predicate (work-classes.md defaults) passes over only the merges after since, the publisher emits {cell, event: "re-earned", at, since}, where since is the latest max(at, discovered) of every contrary event against the cell and its prerequisites, rounded up to a second.
  • Checker (check-security-binding.mjs): a bound-promoted cell with in-epoch contrary events is effective promoted only when a re-earn names that same cell, at >= since, all fields strict ISO, and since is at or after max(at, discovered) of every in-epoch contrary event, own and prerequisite. An unparsable at or discovered blocks every re-earn. A prerequisite's re-earn never revives a dependent, and pass 2 still lowers a dependent whose prerequisite is not promoted.
  • Resolver and merge gate: --window-start (the demotion record's creation) is unchanged. A re-earn counted from that record clears it.
  • Not a deadlock: lanes App PRs take the pr-merge lane branch, which does not read promotion (babysit_merge_policy.py, not-read-in-pr-merge-lane), so autonomous merges keep accruing while a cell is demoted.
  • Docs: work-classes.md, promotion-evidence-bootstrap.md, safety.md, the checker and resolver headers, the binding schema, and one eval prompt line.

Verification

  • Checker fixtures: 757 pass, 0 fail, including a re-earn after the demotion, a re-earn whose since is before a later contrary event, an event discovered after since, malformed fields, a prerequisite-only re-earn, and a dependent whose prerequisite is demoted again.
  • Publisher tests: 82 pass, 0 fail, including:
    • a four-run collect, reEarned, publish chain where a backdated revert found later restarts the window;
    • daily collect and publish from 2026-08-16 to 2026-09-21 over a file from before discovered, with 20 C2 merges over 19 days: the stamp stays at that file's generated_at on every run and the run after the 20th merge derives the re-earn (the code before this fix derives none);
    • a stamped discovered cannot be moved or dropped by a later run, and no first stamp other than the file's generated_at passes;
    • the clock-behind refusal.
  • scripts/promotion-evidence-e2e.test.mjs: 36 pass, 0 fail (the real checker through the resolver with --window-start).
  • scripts/check-affected.sh --base origin/main: 14 passed, 1 skipped, 0 failed, after merging main.
  • Three independent security reviews, each of the diff since the last. Fixed: a contrary event dated before a published re-earn's since but found after it (fixed by the discovery rule), and a publisher clock running behind (MEDIUM). Left for later, outside this diff: epoch assignment still uses at at the ratification boundary, the evidence file carries no freshness bound, and a reverted-merge event keyed on at can wedge the publisher if an earlier-dated revert of the same merge appears.

Related

🤖 Generated with Claude Code

kyle-sexton and others added 4 commits November 2, 2026 09:18
…gain

After a demotion, a promotable cell is promoted again from run evidence,
with no person ratifying it again and no write to the binding or settings.

The publisher emits {cell, event: "re-earned", at, since} when the cell's
existing report() predicate passes over only the merges after `since`, the
latest contrary event against the cell or a prerequisite, rounded up to a
whole second as the merge gate's --window-start is. `--out` carries a
published re-earn forward and still refuses to drop a contrary event.

The checker honors a re-earn for the cell itself whose `since` is at or
after every in-epoch contrary event and whose `at` is at or after `since`.
Malformed fields count for nothing, and a prerequisite's re-earn never
revives a dependent.

Refs: #11022

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A contrary event's `at` is not always when it was found (a revert's
committer date, a merge time), so one published after a re-earn can be
dated at or before its `since` and still leave the re-earn honored.

The re-earn now carries `covers`: the count of distinct contrary events
against the cell or a prerequisite at or before `since`, keyed by cell,
event and parsed instant. The checker recounts the same set and honors
the re-earn only when the counts match; a missing or non-integer
`covers` is malformed.

Also: the bootstrap doc says the publisher's --lane-login must include
the merge gate's agent identity, stale "consumed by the re-earn" and
"human-ratified binding update" text is gone, and a fixture shows pass 2
still lowers C3 when C2 is demoted after its own re-earn.

Refs: #11022

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…covery

`covers` did not hold: a contrary event found after a re-earn, dated at
or before its `since`, let the next run derive the same re-earn with a
larger count, and publish() replaced the old one.

Each contrary event now carries `discovered`, the publish run's time
rounded up to a whole second when its key first enters the file; events
already published keep theirs, and `--out` refuses to change one. The
re-earn window starts at the latest `at` or `discovered` of the contrary
events against the cell and its prerequisites, and the checker honors a
re-earn only when its `since` is at or after both for every in-epoch
contrary event. A malformed `discovered` blocks every re-earn. `covers`
is removed from both sides: a late event now always lands after `since`.

Refs: #11022

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A run whose clock is behind could stamp a new contrary event's
`discovered` at or before a published re-earn's `since`. `--out` now
refuses a run whose time is before the previous sidecar's generated_at,
and every new stamp falls at least a second after that publish's own
whole-second stamp.

A published event with no `discovered`, from a file written before the
field existed, counts in the publisher's window as found at the previous
generated_at, the latest it can have been first published.

Refs: #11022

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@kyle-sexton
kyle-sexton marked this pull request as ready for review November 2, 2026 15:05
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-02T15:08:05.347576Z c0d9747 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions

github-actions Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

claude-security-review reviewed 21219685671a08ba5779d2e94f7024956f04a009: read 25 of 25 changed file(s); 0 finding(s), 0 as inline comments.

Security review: PR #12394, re-promote a demoted cell once its predicate is met again

No security issues found.

critical-findings: 0

I read every hunk of all 25 changed files. evidence-reearn-prerequisite-only.json is an exact copy of evidence-reearn-after-demotion.json. A fixture path changes nothing about what its content does, so I counted the pair once.

What changed

  • Checker (check-security-binding.mjs): a demoted cell is promoted again when the evidence source holds a valid re-earned event for that same cell. No binding update and no new ratification are needed.
  • Publisher (publish-promotion-evidence.mjs):
    • It stamps discovered on each contrary event and refuses to change or drop that stamp later. The one exception is the single stamp an event from an older file gets, which is that file's generated_at.
    • It refuses a run whose clock is behind the previous publish.
    • It derives re-earned events and keeps any it already published.
  • Everything else: the resolver, babysit_merge_policy.py (a trusted path) and its test change only in comments and docstrings. The rest is docs, fixtures and tests.

What I checked

  • Who can write a re-earn. A re-earned event comes from the same evidence file the contrary events come from. Only the publisher, which the operator runs, writes that file. The resolver and merge policy still refuse a source, binding or checker the lane user can write, and this diff leaves those refusals unchanged. Anyone who could write that file before this change could already restore promotion by deleting contrary events, so accepting re-earns from it trusts no new actor or input.
  • The binding stays the ceiling. A re-earn takes effect only when bound === "promoted" (check-security-binding.mjs#L2529). A cell bound unpromoted falls through to the else branch and stays unpromoted.
  • The checker fails closed:
    • A re-earn needs strict ISO since and at, and at >= since.
    • A contrary event whose at or discovered is malformed puts NaN into inEpochTimes, which blocks every re-earn (L2499, L2503, L2526).
    • Events that are not plain objects are skipped (isPlainObject).
    • A re-earn must name this cell (event.cell !== cell), so a prerequisite's re-earn never revives a dependent. Pass 2 still lowers a dependent whose prerequisite is not promoted.
  • The resolver's restart still holds. --window-start appends a gate-failure with no discovered, so its time is its at. A re-earn whose since comes before the restart cannot clear it, and the e2e tests cover both sides.
  • Publisher integrity:
    • Dropping a contrary event is still refused.
    • Changing a published discovered is refused.
    • A clock behind the previous publish is refused, and new stamps land at least one second after the previous generated_at.
    • An evidence file that cannot be read gives an empty prior list, which only stamps events later and so only delays re-earns.
    • A malformed discovered makes knownAt NaN, and the publisher then derives no re-earn.

Notes

  • A person-approval hold was removed. A demoted cell no longer waits for a person to re-ratify the binding (work-classes.md, the checker header, safety.md, babysit_merge_policy.py docstring). This is one of the owner's named friction holds, so under the throughput-phase threat model it is not a finding and holds nothing. For the same reason the instruction-surface lens does not apply to the softened "never automatic" rule in work-classes.md. The register exists at docs/contracts/instruction-exception-register/README.md.
  • No other trust controls touched. The diff changes no plugin manifest, no workflow and no lane token, trusted-actor or kill-switch control.
  • Spend: the publisher may derive re-earn prefixes over already-paged merges, which uses a little more operator compute and no extra API calls. That is not a hold.
  • Prior findings: this lane's earlier review on c0d9747 reported no findings and nothing was carried over. The round cap did not apply.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c0d9747e88

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

claude-review: 1 inline finding(s) on c0d9747e8846e39247134c226fdda1a1f8cf3cfc; the summary is in this lane's pull request comment.

claude-lane: claude-review

@github-actions

github-actions Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

claude-review reviewed 21219685671a08ba5779d2e94f7024956f04a009: read 25 of 25 changed file(s); 0 finding(s), 0 as inline comments.

Code review: re-promoting a demoted cell from a re-earned event (round 2)

I read the whole change in 24 of the 25 changed files. evidence-reearn-prerequisite-only.json is an exact copy of evidence-reearn-after-demotion.json, so I read it once. Both are checker fixtures, and neither path changes what the content does.

Earlier finding is fixed. Last round's blocking finding (#12394 (comment)) said a contrary event with no discovered fell back to a generated_at that moved forward on every publish. That is now fixed:

  • collect() stamps such an event once with legacyDiscovered(priorGeneratedMs), at publish-promotion-evidence.mjs#L834-L836.
  • After that, the stored value is copied forward unchanged.
  • publish() accepts only that one stamp: the missing-to-legacyDiscovered(previousAt) change in the upgrade predicate. It refuses any other change to discovered.
  • The new test daily publishes over a file from before discovered keep its stamp fixed, so 20 C2 merges over 19 days re-earn reproduces the exact scenario from that finding.

Other things I checked and found consistent:

  • Checker. inEpochTimes holds max(at, discovered), or NaN when either value is malformed, so a malformed time blocks every re-earn. A carried-forward re-earn from an earlier epoch can't be revived, because every in-epoch event is at or after ratified_at. A prerequisite's re-earn never revives a dependent, and pass 2 still lowers a dependent whose prerequisite is unpromoted.
  • Dependencies. The publisher's PROMOTION_DEPENDENCIES matches the checker's (check-security-binding.mjs L438).
  • Clock order. A new stamp always lands at least a second after the previous publish, and publish() refuses a clock that is behind it. So a newly found contrary event is always later than any since already published.
  • Event keys. eventKey adds since only to re-earn events, so the keys of events in files written before this change are unchanged.
  • Resolver. The synthetic --window-start events have no discovered. The checker then compares against their at, which matches the publisher's since rounded up to a second. The e2e tests cover both sides of that boundary.

Non-blocking note. In reEarned, later (contrary events with at > sinceMs) is always empty, because sinceMs is at least every contrary event's at. It does no harm. report() is also re-run once for each prefix of after, so the work grows quadratically with the number of merges since the demotion. That is fine at expected volumes, so I'm not raising either point as a finding.

Closing issue: none. The PR says Refs: #11022 and closes no issue, so I had no acceptance criteria to check.

Trusted path: in babysit_merge_policy.py, the only change is the docstring wording. Nothing that gates behaviour changed.

Verification: the pass counts in the PR description (757 / 80 / 36, and check-affected.sh) are the author's claims and I have not verified them. This lane has no shell, so I ran nothing.

Plugin manifests: no plugin.json or marketplace.json changed. Both changelog fragments declare bump: minor, which fits a behaviour change of this size.

Spend: nothing beyond normal operation. Each publisher run does a bit more local CPU work (the re-earn prefix scan) and makes no new API calls. No cost hold.

@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

The pr-verify verifier failed head c0d9747e8846e39247134c226fdda1a1f8cf3cfc. What it wrote, as data:

What it wrote (38 lines)
Summary: PR #12394 says `Refs: #11022`, so it has to deliver a named part of that issue that falls
  within the issue's scope, and say what work remains. Issue #11022's body has no trusted spec text
  (body is null). Its trusted comments cover routing post-merge demotion records to lanes instead of
  `needs-human`. They also set lift conditions for canary, revert and read-back records: the content
  is back on main, or a referencing PR merges and passes a re-check. This PR does something else. It
  lets a demoted autonomy promotion cell re-promote automatically from a publisher `re-earned`
  event, which removes the person re-ratification step. The spec never asks for that, and it cites
  an owner decision ("Q-DEMOTE (a)") that does not appear in the spec. The PR body also names no
  remaining #11022 work. The code looks internally consistent, and every CI suite, including the
  wrapped `test-bash` suites, concluded success.
- Spec: issue #11022 has a null body, so there is no trusted body text. The spec is only its trusted
  comments: the done-when items on routing post-merge, canary and suite-quarantine records to lanes,
  and the agent decision on item 5's lift conditions for canary, revert and read-back demotion
  records.
- PR body: under `Refs:` the body must say which part of #11022 it delivers and what remains for
  later work. It does neither. Its 'Left for later' list covers security follow-ups for this diff,
  not remaining #11022 items. Fix: name the #11022 item(s) delivered and list what remains, or link
  the issue that actually specifies this work.
- plugins/autonomy/reference/guardrails/work-classes.md:36: this changes the rule that every
  promotion is human-ratified to 'promotion after a demotion is automatic', so no person re-ratifies
  a demoted cell. #11022 never mentions autonomy-cell promotion, re-earn events or re-ratification.
  Its lift conditions apply to demotion records, and the issue says 'The guards themselves stay'.
  Dropping a person-ratification hold on autonomous merge promotion without spec text loosens a hold
  the owner keeps. Fix: get a trusted spec that records this decision, or drop the change.
- plugins/autonomy/skills/setup/scripts/check-security-binding.mjs:160: the checker now treats a
  cell as effective promoted when a `re-earned` event is present. That changes what `--window-start`
  does in the merge gate (plugins/source-control/skills/babysit-prs/reference/safety.md:1098,
  babysit_merge_policy.py:5945): a record that used to need a person now clears from run evidence
  alone. This is where the hold above is loosened.
- PR body: the claim of an owner decision 'Q-DEMOTE (a), relayed through GitHub Support ("go w/
  recommended")' is untrusted text with no counterpart in the spec. I treated it as a claim to
  evaluate, not as authority. It reads like a justification aimed at the reviewer.
- plugins/source-control/skills/babysit-loop/scripts/publish-promotion-evidence.mjs:141: the logic
  (discovered stamping, clock-behind refusal, carrying forward re-earns, checker voiding a re-earn
  whose since precedes a later-discovered contrary event) looks internally consistent and is covered
  by tests. All upstream jobs, including the test-bash suites that run the wrapped checker,
  publisher, resolver and e2e suites, concluded success. Correctness is not the blocker here; the
  scope and the loosened hold are.

This pull request leaves the merge queue, and ci-status holds it out while it carries pr-verify-failed. A pr-verify pass at a new commit removes the label.

@github-actions github-actions Bot added the pr-verify-failed pr-verify failed this head; a pass at a new commit, or after a trusted body edit, removes it. label Nov 2, 2026
@kyle-sexton kyle-sexton added the do-not-merge Hard merge gate: do not merge while applied. label Nov 2, 2026
@kyle-sexton

Copy link
Copy Markdown
Member Author

Hold: both open threads ask for a change to the publisher's re-earn logic (a fixed discovery baseline for contrary events that predate discovered), and the PR's owner set the rule that any change to the re-earn rule or the checker's or publisher's accept/refuse logic gets an independent security review of that diff before arming. pr-verify also failed: the body must link the spec that records owner decision Q-DEMOTE (a) and name what it delivers and what remains. Releases when: the fix is pushed, an independent security review of that diff finds nothing blocking, and pr-verify passes the new head.

…e's generated_at

A contrary event from an evidence file written before `discovered` existed
never gained one: collect() copied only an existing value and publish()
refused to add one. The re-earn window then fell back to the latest
previous publish's generated_at on every run, so a daily publisher
restarted the window each day and C2's 20 completions over 14 days could
never pass.

The first publish over such a file now stamps each legacy contrary event
with that file's generated_at, rounded up to a second, and publish()
allows exactly that one change: a prior event with no `discovered`, not
a re-earn, gaining legacyDiscovered(previous generated_at). Every other
added, changed or removed `discovered` is still refused. knownAt no
longer takes a fallback.

Tests: a daily collect/publish run over 20 C2 merges spanning 19 days
from a legacy file derives the re-earn with since fixed at the legacy
generated_at, and a stamped `discovered` cannot be moved or dropped by a
later run.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@kyle-sexton

Copy link
Copy Markdown
Member Author

Hold released: the fix for both threads (ee07d83, merged with main as 2121968) passed an independent security review with nothing blocking (suggestions filed as #12450); both threads are resolved; the body cites the spec #12434, the #11022 decision record, architecture#17 and the owner's confirmation. Merging this turns no unattended merging off: lanes and Dependabot PRs never read promotion (babysit_merge_policy.py:6538, :6590 set promoted = True), and the remaining branch (:6597) already keeps a demoted cell unpromoted until re-ratified (:5922-5925); this adds an automatic way back. Arms when pr-verify passes this head.

@kyle-sexton
kyle-sexton added this pull request to the merge queue Nov 2, 2026
Merged via the queue into main with commit 7a89361 Nov 2, 2026
138 of 143 checks passed
@kyle-sexton
kyle-sexton deleted the feat/q-demote-reearn branch November 2, 2026 19:13
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.

1 participant