Skip to content

fix(sage): keep delivery state out of worker responses - #9087

Merged
iamwhatever merged 1 commit into
kirodotdev:mainfrom
Premshay:upstream/sage-posting-outbox
Nov 3, 2026
Merged

iamwhatever merged 1 commit into
kirodotdev:mainfrom
Premshay:upstream/sage-posting-outbox

Conversation

@Premshay

@Premshay Premshay commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: A worker's review response must not be able to set Sage's delivery state.

_persist_worker_response persists the worker-written record as-is. A response carrying posted_keys, post_ok, posted_review_id or a staged github_review_payload would be trusted later as if the driver had written it. That can mark findings delivered that were never posted, or skip the poster's own payload build.

Why it matters

Delivery state is the driver's to write. A reviewer that can write it can hide undelivered findings.

Not a goal

Interrupted-post reconciliation. Earlier revisions of this PR added a delivery-intent outbox and GitHub read-back. The First Principles review showed that main already replaces Sage's pending draft on retry, and that the remaining duplicate case is a recorded trade-off (a visible duplicate over a silently dropped finding). With no reproduction against main, that machinery is removed and main's post_recorded stays as it is.

What changed (motivation → approach → change)

  • worker_response.py drops delivery and posting fields (github_review_payload, pending_comments, posted_keys, posted_review_id, posted_comments, design_comment_posted, post_ok, post_error, post_partial) from a worker-written record before results.write_result.
  • test_delivery_response_boundary.py covers initial and follow-up responses, scoped and unscoped.

Backwards compatibility

Compatible. Only fields the worker should never have written are dropped; review content and existing records are unchanged.

Tests

test_delivery_response_boundary.py and test_response_handoff_regressions.py pass locally (12 passed). CI runs the full suite.

Manual verification

None; the change is confined to record persistence and covered by the focused test.

Related Issues

None.

Pattern harvest

Rule candidate: review-prompt
Pattern: a record written by a less-trusted party is persisted as-is, including fields only the trusted writer may own.

Checklist

  • One Conventional Commit
  • CI verification on the latest head
  • Self-review
  • No credentials or private integration changes

Agent-authored update by kirocrew-steward. Scope reduced per the First Principles review.

@Premshay
Premshay requested review from a team and krishdhasmana September 6, 2026 18:33
@github-actions github-actions Bot added fork Pull request from a fork (external contributor) readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Sep 6, 2026
@github-actions

github-actions Bot commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5, fork) — ✅ PASS

Design-level review of e39ed057d7ab5bf527f62b6c37ca0d1e4c557881 via the fork AI-review pipeline — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

Design-Verdict: PASS

No design-level concerns. The fix sits at the one point where worker output gets saved. The follow-up pass starts from the first-pass record, which has already been cleaned, so it cannot bring the delivery fields back. Nothing outside the worker relied on those fields.

Notes

  • The nine field names are a hand-written denylist inside _persist_worker_response. If the driver later adds a delivery field, a worker can set it again until someone remembers to add it here. Keeping one shared constant next to the driver's writers in review_driver.post_recorded would stop the two lists drifting apart.

[DESIGN-REVIEWED] e39ed05

Description read

[DESCRIPTION-READ] 389fa69bb1c69120e592b5677fc79150293d2adcaa3f59d5f10a124a20cd99de

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

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5, fork) — ✅ PASS

Premise-level review of e39ed057d7ab5bf527f62b6c37ca0d1e4c557881 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 does not.

First-Principles-Verdict: PASS

The fix strips worker-written delivery fields at the one place worker responses are persisted. Nothing blocks.

Notes

  • Item 1 — the worker contract still asks for a field this PR now drops: skills/sage-review/SKILL.md:547 tells the worker to emit "posted_comments": 0, and the new loop pops "posted_comments" before results.write_result. The worker is told to write delivery state the driver now owns. Subtraction: delete the "posted_comments": 0, line from the SKILL.md record template.

What this change ships

Inventory (2 items) — 2 justified

Intent: stop a review worker from marking findings as delivered (or replacing the poster's payload) by putting delivery fields in its response. This is a FIX.

  1. A worker response's posted_keys/post_ok/github_review_payload/… no longer reach the persisted record, for first-pass and follow-up responses alike. The poster reads cur.get("posted_keys") at review_driver.py:868. — justified
  2. A regression test showing that forged delivery fields are dropped, scoped and unscoped, first-pass and follow-up. — justified

[FIRST-PRINCIPLES-REVIEWED] e39ed05

Description read

[DESCRIPTION-READ] ffd8d112d22a010975d9f352d4dc9bcb9c282bd46defc83c968b94aef07268e5

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

Copy link
Copy Markdown
Contributor

GPT 6.1 Review (fork) — ✅ no blocking findings

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

Review details

No findings.
[GPT-REVIEWED] e39ed05

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

github-actions Bot commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review (fork) — ✅ no blocking findings

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

Review details

No findings.

[OPUS-REVIEWED] e39ed05

@Premshay
Premshay force-pushed the upstream/sage-posting-outbox branch from c8ed2b7 to 5f2656b Compare September 7, 2026 09:17
@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 7, 2026
@Premshay
Premshay force-pushed the upstream/sage-posting-outbox branch from 5f2656b to c710b76 Compare September 8, 2026 09:22
@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 8, 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: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Sep 10, 2026
@Premshay

Premshay commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor Author
  • Poster-count contract reversal remains blocked (span=f6066c0bb131)

needs-a-decision: Maintainers, explicitly approve replacing the pinned unconfirmed poster count/post_partial contract with confirmed-delivery-only counts, or require restoration of the original pin. The current Compatible claim is insufficient: the test reverses the reported count from1 to0 and removes post_partial. An atomic GitHub POST supports confirmed-only accounting but does not supply human acceptance of the changed contract. No approval or override is claimed.

AI-authored by kirocrew-steward (Codex). This is a hold, not a fixed finding.

@Premshay

Premshay commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor Author
  • Poster-count contract reversal remains blocked (span=ad3deb5188cf)

needs-a-decision: Maintainers, explicitly approve replacing the pinned unconfirmed poster count/post_partial contract with confirmed-delivery-only counts, or require restoration of the original pin. The current Compatible claim is insufficient: the test reverses the reported count from1 to0 and removes post_partial. An atomic GitHub POST supports confirmed-only accounting but does not supply human acceptance of the changed contract. No approval or override is claimed.

AI-authored by kirocrew-steward (Codex). This is a hold, not a fixed finding.

@Premshay

Copy link
Copy Markdown
Contributor Author

Updated to 85f013693: one commit on current main. Posted by the kirocrew-steward agent on behalf of @Premshay.

What changed since the previous head

  • Repair (from the earlier dispositions):
    • The unconfirmed poster count stays visible without confirming delivery or permitting cleanup.
    • A legacy batch retry no longer re-posts findings already delivered.
    • Interrupted recovery preserves an unrelated operation's draft instead of deleting it.
  • File-line cap: review_driver.py was 2,214 lines and test_post_comments.py 2,564. Whole definitions moved, unchanged (checked by AST identity), into sage_lib/delivery_intent.py and sage_lib/review_tasks.py. review_driver.py re-exports them under its existing import paths, so patch targets still resolve. The outbox tests moved to tests/test_post_comments_outbox.py.

Local evidence

  • 1,057 code_review_sage + outbox tests pass. TestDismissFinding::test_the_post_path_never_sends_a_dismissed_finding fails depending on xdist worker grouping, and fails the same way on clean main: test_consolidate.py leaves mock tasks in routes._TASKS.
  • Line cap, black gate, mypy, isort and flake8 pass.
  • Independent GPT review (gpt-6.1-sol, CI-extracted contract): no findings.

The recorded design decisions on this PR still stand for maintainers.

@Premshay

Copy link
Copy Markdown
Contributor Author

Agent update — fixed.

  • Worker delivery metadata cannot bypass redaction

Outcome: fixed. Fixed in 967cc6a. The port preserves main's capability-bound response intake, then strips delivery_intent, payload, selected/published keys and posting metadata before accepted records are persisted or returned. Shared-file adoption is no longer reviewer authority. Scoped and standalone initial/follow-up regressions cover all three retryable forged-intent states; legitimate driver intent still resumes. Parent independently ran 253 focused cases; three-module mypy and the 58-case wait ratchet pass.

@Premshay

Copy link
Copy Markdown
Contributor Author

Agent update — needs-a-decision.

  • Operation marker insertion remains prompt-dependent

Outcome: needs-a-decision. Maintainers: accept the documented poster marker instruction for this PR, or require Python to stage the exact outbound wire payload before the poster runs? No live marker-insertion capture was performed. This remains open and is not presented as fixed by the security repair.

@Premshay

Copy link
Copy Markdown
Contributor Author

Agent update — rebutted.

  • Recovery must not delete an unrecognized pending draft

Outcome: rebutted. An ABSENT result proves only that this operation is absent, not that another pending draft is disposable. Reusing watermark-clear in recovery could discard a different operation's findings after an interruption. test_recovery_never_watermark_deletes_another_operations_findings covers that refusal. Recovery therefore retains the selection and asks the user to resolve a blocking draft; a fresh explicit run retains main's existing watermark replacement contract.

@Premshay

Copy link
Copy Markdown
Contributor Author

Agent update — needs-a-decision.

  • Stage the exact wire payload

Outcome: needs-a-decision. Maintainers: should this PR also move marker insertion from the poster prompt into deterministic Python staging? That would remove a prompt compliance dependency, but the current port does not claim that work or a live post capture. The minimum recovery/security port remains separate from that decision.

@Premshay

Copy link
Copy Markdown
Contributor Author

Agent update — rebutted.

  • Base-failing interrupted-delivery evidence

Outcome: rebutted. test_lost_response_does_not_negate_confirmed_delivery fails against main's original post_recorded function: a failed dispatch response negates confirmed GitHub delivery. The new port accepts matching remote delivery despite that response and preserves operation identity across retry. GitHub's one-pending-review limit means the prior failure can also appear as a blocked retry rather than two simultaneous drafts; the description makes no simultaneous-draft claim.

@Premshay

Copy link
Copy Markdown
Contributor Author

Agent update — rebutted.

  • Fresh replacement and recovery have different evidence

Outcome: rebutted. A fresh explicit run deliberately replaces an earlier watermarked draft. A retry must reconcile the saved operation instead of discarding another selection that appeared while it was interrupted. Removing the exact-predecessor guard would reopen the tested deletion of another operation's findings. The port preserves that distinction and main's accepted-record restoration; it does not expand the frozen Goal.

@Premshay

Copy link
Copy Markdown
Contributor Author

Agent update — fixed.

  • Startup versus persistence wording

Outcome: fixed. The port no longer changes Sage backend runtime-start handling. The old startup-error split is absent from the current diff; persistence errors remain local to post_recorded and are redacted. The description names the actual recovery and intake changes.

@Premshay

Copy link
Copy Markdown
Contributor Author

Agent update — fixed.

  • Record byte cap and error handling

Outcome: fixed. The port retains main's existing bounded result writer unchanged; no result byte-cap change remains in this diff. Recovery persistence failures return a redacted per-change failure and retain retry records, preserving main's failure behavior.

@Premshay

Copy link
Copy Markdown
Contributor Author

Agent update — fixed.

  • Posting module ownership declared

Outcome: fixed. The description explicitly names delivery_intent.py and posting_recovery.py. review_driver.py retains existing exports, response intake and review orchestration. The modules isolate operation identity and remote reconciliation; they do not restore the obsolete shared-adoption model.

@Premshay

Copy link
Copy Markdown
Contributor Author

Agent update — needs-a-decision.

  • Stale predecessor coordinates can remain UNKNOWN

Outcome: needs-a-decision. Maintainers: retain the conservative UNKNOWN refusal when the head moved and predecessor positions cannot be resolved, with manual GitHub draft resolution, or require explicit historical-coordinate recovery before this PR lands? This advisory remains reproducible by source inspection and is not fixed.

@Premshay

Copy link
Copy Markdown
Contributor Author

Agent update — needs-a-decision.

  • A dismissed finding can remain in an indeterminate selection

Outcome: needs-a-decision. Maintainers: should dismissing a finding abandon/rebuild an indeterminate operation, or should pending-delivery findings be non-dismissible until reconciliation completes? Replaying the saved selection can currently include a later-dismissed finding. This is disclosed in the description and remains open; no fix is claimed.

@Premshay

Copy link
Copy Markdown
Contributor Author

Agent-authored CI follow-up in 3eddea6c5fd8ad1b6460eca4b158925afa9517a5: classified posting_recovery.py alongside Sage's app-owned redaction modules, with the matching security-spec note. Corrected the compatibility reader lines to the required ASCII -- format. These address the Static Ratchet and PR Hygiene failures reported by CI on 967cc6a7abd7b8db274a7df3f0e614536356f737; runtime recovery behavior is unchanged. No local checks ran. CI verification is pending.

@Premshay

Copy link
Copy Markdown
Contributor Author

Agent-authored update — fixed.

  • The marker is added by the LLM, so delivery proof depends on the LLM. buildposttask tells the poster to "

Outcome: fixed. The driver writes the marker-bearing wire payload into shared staging before dispatch. The prompt tells the poster to copy it verbatim; the LLM no longer inserts the marker. Retry construction strips any existing operation-marker line before appending exactly one. A regression assertion reads the staged record at dispatch and requires one marker.

Published head: c4dbda8e6e6f284d6458063727ccad0b3b6b5a05. No local checks ran; CI owns verification.

@Premshay

Copy link
Copy Markdown
Contributor Author

Agent-authored update — fixed.

  • If the driver stages the wire payload itself, the marker wording in the poster prompt and most of the mar

Outcome: fixed. The driver now stages the complete marked wire payload and the prompt no longer asks the poster to compose or append a marker. Marker-free canonical comparison remains necessary because GitHub changes separators and the accepted visible record remains marker-free.

Published head: c4dbda8e6e6f284d6458063727ccad0b3b6b5a05. No local checks ran; CI owns verification.

@Premshay

Copy link
Copy Markdown
Contributor Author

Agent-authored update — fixed.

  • Unresolved predecessor coordinates have an actionable remedy

Outcome: fixed. The error now identifies the predecessor review ID and instructs the operator to submit or delete that draft on GitHub before retrying. Recovery still refuses to infer content identity from the operation marker alone. Automatic re-projection onto an older diff is not added.

Published in c4dbda8e6e6f284d6458063727ccad0b3b6b5a05. CI verification pending; no local checks ran.

@Premshay

Copy link
Copy Markdown
Contributor Author

Agent-authored update — fixed.

  • Recovery does not resend subsequently dismissed findings

Outcome: fixed. The run's dismissed keys reach post_recorded. After read-back reports the saved operation absent, an overlap with its saved selection refuses redispatch and retains the intent. The error explains that the dismissal must be undone and the earlier operation reconciled before choosing a new selection. Fresh selections also exclude dismissed keys. This preserves uncertain delivery state instead of silently resending or abandoning it. A regression case asserts no dispatch on overlap.

Published in c4dbda8e6e6f284d6458063727ccad0b3b6b5a05. CI verification pending; no local checks ran.

@Premshay

Copy link
Copy Markdown
Contributor Author

Agent-authored update — fixed.

  • Stored recovery bypasses Python redaction

Outcome: fixed. Recovery rebuilds through pipeline.build_github_review_payload before read-back or staging, constructs the wire payload from that rebuilt result, and refuses unless its digest matches the saved operation. cur.github_review_payload is replaced with the rebuilt copy so the later staging path cannot restore the unchecked payload. Added scoped/unscoped stored-record refusal coverage.

Published in c1dde9229ade95d811f18209c187f50fa1182f44. CI verification pending; no local checks ran.

@Premshay

Copy link
Copy Markdown
Contributor Author

Agent-authored update — fixed.

  • Marker-only body incorrectly counts as a design comment

Outcome: fixed. Both confirmed-delivery branches strip operation-marker lines and whitespace before deciding design_comment_posted. An unscoped staged record carrying only the marker no longer counts as a visible design body.

Published in c1dde9229ade95d811f18209c187f50fa1182f44. CI verification pending; no local checks ran.

@Premshay

Copy link
Copy Markdown
Contributor Author

Agent-authored update — needs-a-decision.

  • Live recovery evidence and conflict exit remain unproved

Outcome: needs-a-decision. No live GitHub post/interrupt/reconcile run was performed. The operator directs CI-only verification, and creating or posting to a scratch PR was not authorized for this task. Mocked CI results are not claimed as live evidence. A CONFLICT/UNKNOWN operation still lacks an in-product abandon action. These design blockers remain open; the separate stored-payload redaction and marker-accounting fixes are published in c1dde92.

@Premshay

Copy link
Copy Markdown
Contributor Author

Agent-authored update — needs-a-decision.

  • Duplicate read-back remains

Outcome: needs-a-decision. _draft_confirmed and the operation-aware read-back are not consolidated in this repair. The proposed subtraction changes the recovery identity/predecessor contract; it is not claimed implemented. This blocker remains open for the maintainer decision on retaining that protocol or reducing the PR to the base content-confirmation path.

@Premshay

Copy link
Copy Markdown
Contributor Author

Agent-authored update — needs-a-decision.

  • Recorded duplicate-over-drop trade-off remains open

Outcome: needs-a-decision. The earlier comment records a deliberate duplicate-over-drop trade-off. This source repair does not establish that decision was wrong and does not supply authorization to reverse it. The predecessor/retry design concern remains open; no human override or readiness is claimed.

@Premshay

Copy link
Copy Markdown
Contributor Author

Agent update — kirocrew-steward, reviewed head 8bcede8.

Fixed: foreign accounts copying an operation marker no longer block reconciliation. The probe resolves the posting account first; duplicate markers from that account and changed payloads still conflict. An unverifiable login remains UNKNOWN.

Fixed: submitted inline comments use original coordinates when their original commit matches the recorded review commit. Pending position-only comments retain the pinned diff mapping. Range-start coordinates and sides participate in comparison.

Fixed: predecessor deletion requires its recorded operation marker, PENDING state and an exact content reread. It no longer requires a body watermark absent from finding-only drafts.

The earlier #9077 merge-order discussion is not a new request. The existing unused _draft_confirmed helper is a cleanup observation, not evidence these recovery fixes fail; I have left that deletion out of this repair.

I inspected the source and added regression coverage. CI flagged two formatting sites on the previous head; both were reformatted in this head. No local tests, lint checks or type checks ran; CI must verify this head. The live post/interrupt/reconcile exercise remains outstanding. Sensitive-path approval remains with maintainers; I am not claiming readiness or review clearance.

@Premshay

Copy link
Copy Markdown
Contributor Author

Agent update — kirocrew-steward, head 82eb76d.

Fixed account-switch recovery: the intent saves the posting login before dispatch, and reconciliation uses that identity. An account change cannot authorize redispatch. Legacy interrupted intents without a recorded identity remain indeterminate rather than assuming the current login.

Fixed predecessor replacement: both captured content and the deletion reread include start_line and start_side. Edited pending drafts remain protected, with an instruction to submit or delete before retrying. A recorded predecessor already submitted by its saved account is preserved regardless of human edits and no longer traps later posts in a digest conflict.

Fixed the standalone CLI import cycle with lazy imports. Removed the unused _draft_confirmed algorithm and moved its behavioral coverage to the production probe. The redundant fresh-path dismissal filter is also removed; recovered selections still check dismissed keys.

I inspected the source and added regression tests for these cases. No local tests, lint checks or type checks ran. CI flagged an import-order issue on the preceding head; that formatting edit is included here. CI and the live GitHub post/interrupt/reconcile exercise remain outstanding. This is not a claim of readiness or sensitive-path approval.

@Premshay

Copy link
Copy Markdown
Contributor Author

I've shrunk this PR to address the First Principles block.

I couldn't show a duplicate review on main. On retry, main already replaces Sage's pending draft review, so the outbox (delivery_intent.py, posting_recovery.py, the operation marker and its tests) was solving a problem I can't demonstrate. I've removed it.

What remains is one change in worker_response.py: posting fields (posted_keys, post_ok, github_review_payload and the rest) are dropped from a worker-written response before it is saved. Without that, a reviewer response could mark findings as delivered that were never posted. A focused test covers first and follow-up responses, with and without a run ID.

post_recorded on main is unchanged. Title and description are updated to match. The new head is bf0c74d670.

A worker response could carry posting and delivery fields that the
persisted record would then trust. These fields are now dropped
before persistence.

@iamwhatever iamwhatever 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.

Approving e39ed05.

The fix strips driver-owned delivery fields (posted_keys, post_ok, github_review_payload and the rest) from a worker-written record at the single persistence point, after the capability and schema checks and before results.write_result (worker_response.py#L194-L209). The poster reads posted_keys from that persisted record (review_driver.py#L868), so this closes the path where a worker could mark findings delivered. The follow-up path rebuilds from an already-stripped base record, and the new test covers first-pass and follow-up, scoped and unscoped. All checks on this head are green and every AI lane passed.

AI findings judged non-blocking

  • Design Review (note): hand-written field list could drift from the driver's writers. Does not block: the list covers every delivery field the poster reads from the result record today; posting_expected lives on the driver's per-change record (review_driver.py#L1841), not the worker record. A shared constant would be a nice follow-up.
  • First Principles Review (note): the worker template still asks for "posted_comments": 0 (SKILL.md#L547). Does not block: the field is not required by validate_result and is dropped before persistence, so nothing breaks; deleting the line is a cleanup.

— crew-pr-reviewer (r142)

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.

3 participants