← Back to Pull requests

Guarantor: finish an issued firm offer after a stop; fail closed in the portfolio and at load #79

Open
unknown opened this pull request with 650 lines diff across 8 files
View on GitHub
unknown unknown commented on Nov 22, 2026 19:23 UTC
Author

One of four changes that make the Guarantor provider coordinator recoverable after a crash. This one covers firm-offer issuance and four small items from the same reviews. The Guarantor profile is incubation and not wired into the binary. The pinned ai dependency is unchanged.

1. A firm-offer issuance that stopped after the journal issued the offer could never finish

  • Wrong: resumeFirmOfferIssuancePlan reserved the plan's unsigned position again (guarantor_provider.go, ReserveUnsignedOffer(plan.Position)). When the earlier run had already made CommitFirmOffer, the stored position was the issued one, so the reservation failed with Guarantor offer identity conflicts with prior reservation (guarantor_journal.go, ReserveUnsignedOffer). An issuance that stopped between CommitFirmOffer and the authority's terminal transition stayed prepared at the authority for good.

  • Fix: the resume asks the journal for the plan's offer by its envelope digest (plannedFirmOfferIsIssued). An offer stored under that digest that is the plan's exact offer is neither reserved nor issued again, and the resume goes on to the terminal transition, the admission log and the plan's removal. An offer stored under that digest that is not the plan's is a conflict.

  • Found while testing it, same flow: a quote request repeated after its issuance had completed was refused with Guarantor admission semantic identity conflicts. The repeated call built a second action under the portfolio revision of the later call, with the same stable identity and another request digest. The request names an authority instance, and the journal holds the offer issued under it, so that offer is now returned (issuedFirmOffer): only if its envelope matches its record, its issuance is terminal at the authority and it still verifies for the request and Agreement of the call.
  • 2. Small items

    | item | wrong | now |
    |---|---|---|
    | portfolioFor amounts | a paid or defaulted amount that did not parse was counted as zero | the portfolio fails with the coverage and the amount named |
    | portfolioFor claim count | activeClaims += uint32(len(...)) | addGuarantorClaimCount, range-checked at both ends |
    | coverage key at load | a coverage's map key was never compared with its record's Agreement digest | a load refuses a coverage whose key is not a digest or is not the one its record names |
    | ResolveAdmission, SaveFirmOfferIssuancePlan | a closed or replaced journal was reported as an invalid resolution or plan | the journal's own error is returned |
    | pkg/tools/fs sandbox write | temporary file named .tmp-<pid>-<nanos>; two writers in one process could pick one name, and a failed create removed the name, which was the other writer's file | fileutil.CreateTemporaryFileRoot: the atomic write's random name with its retry; a name that could not be created is not removed |

    The test fixtures that stored a coverage with an empty record now store it under the Agreement its record names (testCoverageWithClaim, the durability fixture, commitTestGuarantorEvidence, the command package's inspection fixture).

    Tests

  • Lifecycle (TestGuarantorProviderIssuesReservedOfferAndLinearizesAcceptance and the other scenarios): the second offer's issuance stops before its terminal transition, with the plan stored, the offer issued and the action prepared (checked); the journal is opened from disk; the repeated issuance completes and returns the issued offer, the plan is gone, and repeating the completed issuance returns the same offer.

  • TestGuarantorPortfolioFailsOnAnAmountItCannotRead, TestGuarantorPortfolioClaimCountIsChecked, TestGuarantorJournalRefusesACoverageStoredUnderAnotherIdentity, TestGuarantorJournalReportsADetachedJournalAsThat (closed, and directory replaced).

  • TestSandboxWritesNeverCollideOnTheirTemporaryName (64 writers, 200 rounds, nothing left behind), TestSandboxTemporaryFileHasTheAtomicWriteName.
  • Before the fix, and red controls

    Development host, GOWORK=off GOFLAGS=-tags=goolm,stdjson, pinned tosctl, one run at a time.

    | tree | result |
    |---|---|
    | origin/main b5a9e54e plus the tests that build there | lifecycle: issue expiring offer after a stop between its journal commit and its terminal transition: state=prepared err=Guarantor offer identity conflicts with prior reservation; portfolio: four cases a portfolio was summed over an amount that cannot be read; identity: both mismatches loaded (got <nil>); detached: all four cases reported ... is invalid |
    | origin/main, sandbox write, five runs | 2 of 12800 concurrent sandbox writes failed, the first with: failed to open temp file: openat .tmp-...: file exists |
    | this head, the issued offer not recognized on resume | the same lifecycle failure as before the fix |
    | this head, the stored offer not returned, the key check, the amount check and the two error returns removed | lifecycle: repeating the completed issuance: state= err=Guarantor admission semantic identity conflicts; the three unit tests fail |

    TestGuarantorPortfolioClaimCountIsChecked and the temporary-file helper test need the new functions and cannot be built on the base.

    Verification

    At 0953b453: gofmt -l pkg cmd empty; go build ./...; go vet ./...; go test -p 4 -count=1 -timeout 30m ./pkg/earning/ ./pkg/servicebridge/... ./pkg/config/ ./cmd/openfox/... ./pkg/messengerauth/ ./pkg/actionauth/ ./pkg/fileutil/ ./pkg/tools/fs/: exit 0, 23 packages ok, pkg/earning 884.9 s. golangci-lint as the PR workflow runs it (--build-tags=goolm,stdjson --new-from-merge-base=origin/main): 0 issues.

    Known limits

  • Other journal methods still fold a closed or replaced journal into their own "invalid" message (beginAdmission, CommitFirmOffer, ExpireOffer, the commit methods of guarantor_decision_journal.go and others). Only the two named in the review are changed here.

  • A coverage loaded with an empty paid_atomic now fails the portfolio once its reservation is released; the load fills in only defaulted_atomic. Coverages the journal creates always carry both.

  • The restart in these tests closes the journal and opens it again in the same process.
  • Authored by Floria

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: chatgpt-codex-connector[bot] Review duration: 4m
    All Vouch review confidence checks passed
    Residual risk 0.42 = Change Risk (0.52) × (1 − Review Confidence (0.20)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 27% · Reviewer familiarity: 35%
    19%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #79"
    general weight: 0.35
    Assignees
    Unassigned
    Labels
    risk: medium confidence: 19.9% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52% (MEDIUM) · Higher = larger blast radius
    52%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 19.9% · Lower = rushed or shallow review
    19.9%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 41.7% · Moderate risk
    41.7%