Repository navigation
🏤 refactor: Write Trigger Run Rows by Subject and Delivery - #18678
danny-avila wants to merge 2 commits into
Conversation
|
/quality check-all scopes=data-schemas |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Quality reportOutdated: this request is for an earlier PR commit. Gate: open. The selected checks completed. Scores and risk levels are advisory. Status: completed (success). Actions run, attempt 1.
Change riskTakeaway: Every changed line has a test. Highest CRAP among changed functions:
Refactor hints (highest CRAP first)
15 more functions below the threshold (or cut for size) are in report.md. CRAP = complexity² × (1 − coverage)³ + complexity Mutation testingTakeaway: 6 survivors; the most are in Score: killed by assertion, Killed/(Killed+Survived+NoCoverage); the Stryker score also counts timeouts.
Survivors (tests still passed after this change to the code; not confirmed bugs), most important first
|
| Check | Result |
|---|---|
| Change risk (data-schemas) | success |
| Mutation testing 1/4 (data-schemas) | success |
| Mutation testing 2/4 (data-schemas) | success |
| Mutation testing 3/4 (data-schemas) | success |
| Mutation testing 4/4 (data-schemas) | success |
| Mutation report (data-schemas) | success |
All data (quality-report artifact) · Run page
The gate opens only when the workflow, source selection, tooling verification, and every report job succeed. A report job fails on a failed test in its workspace's own Jest run, a tool error, a job timeout, or an incomplete mutation report, including a mutation shard that reaches its execution budget. A cancelled workflow keeps the gate closed. Scores are advisory. A change-risk file marked incomplete or unavailable, for example by a failed api/ source-alias suite, does not close the gate.
|
Codex Review: Didn't find any major issues. Keep it up! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
|
@codex review Please review the pull request at head ee56b3b. Since the last review only the spec changed: it gained tests for the refusals the run record classifies (a duplicate whose row is gone before it is read, an index name after more than one space, an error it cannot read) and for a settled run that recorded no receipts. No source file changed. |
|
/quality check-all scopes=data-schemas |
Quality reportOutdated: this request is for an earlier PR commit. Gate: closed. Blocked by: Mutation testing 1/4 (data-schemas) (cancelled), Mutation testing 2/4 (data-schemas) (cancelled), Mutation testing 3/4 (data-schemas) (cancelled), Mutation testing 4/4 (data-schemas) (cancelled), the workflow (cancelled). Status: completed (cancelled). Actions run, attempt 1.
The PR head moved after this run, so report details are omitted. Jobs (5)
The gate opens only when the workflow, source selection, tooling verification, and every report job succeed. A report job fails on a failed test in its workspace's own Jest run, a tool error, a job timeout, or an incomplete mutation report, including a mutation shard that reaches its execution budget. A cancelled workflow keeps the gate closed. Scores are advisory. A change-risk file marked incomplete or unavailable, for example by a failed |
|
Codex Review: Didn't find any major issues. What shall we delve into next? Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
Eight stored methods that change only a run's own row move behind the trigger run record, beside its readers, and are addressed by the same ref: reserve, detail, abort, abortSaved, claim, release, receipt and remove. The schedule methods (reserveStartedRun, setRunFireDetails, requestRunAbort, markRunAbortPersisted, markRunResumeClaimed, releaseRunResumeClaim, recordMCPToolAuthFailure, deleteScheduleRun) keep their signatures and call them. Every filter, update document and option reaches the database as it did before; the new spec records each command and passes against the unchanged schedule methods as well. Only schedules record runs. A write for a subject of any other kind sends nothing and answers as it would for a run that is not on record. Settling a run (its outcome, a skip, the schedule's bookkeeping) and the reconciliation sweeps stay schedule methods.
…n With No Receipts
ee56b3b to
57a71b4
Compare
|
/quality check-all scopes=data-schemas |
Quality reportGate: open. The selected checks completed. Scores and risk levels are advisory. Status: completed (success). Actions run, attempt 1.
Change riskTakeaway: Every changed line has a test. Highest CRAP among changed functions:
Refactor hints (highest CRAP first)
15 more functions below the threshold (or cut for size) are in report.md. CRAP = complexity² × (1 − coverage)³ + complexity Mutation testingTakeaway: 1 survivor; the most are in Score: killed by assertion, Killed/(Killed+Survived+NoCoverage); the Stryker score also counts timeouts.
Survivors (tests still passed after this change to the code; not confirmed bugs), most important first
|
| Check | Result |
|---|---|
| Change risk (data-schemas) | success |
| Mutation testing 1/4 (data-schemas) | success |
| Mutation testing 2/4 (data-schemas) | success |
| Mutation testing 3/4 (data-schemas) | success |
| Mutation testing 4/4 (data-schemas) | success |
| Mutation report (data-schemas) | success |
All data (quality-report artifact) · Run page
The gate opens only when the workflow, source selection, tooling verification, and every report job succeed. A report job fails on a failed test in its workspace's own Jest run, a tool error, a job timeout, or an incomplete mutation report, including a mutation shard that reaches its execution budget. A cancelled workflow keeps the gate closed. Scores are advisory. A change-risk file marked incomplete or unavailable, for example by a failed api/ source-alias suite, does not close the gate.
|
Codex Review: Didn't find any major issues. Keep it up! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
Summary
The record a triggered run leaves can be read by who the run acts for and the delivery that started it (#18674). It could still be written only by naming a schedule id and a scheduled time, in stored methods written for schedules. Code that holds a run's subject and delivery could find the run's row but could not reserve it, stop it, resume it or roll it back.
This moves the eight writers that change a run's own row and nothing else onto the same object as the readers, addressed by the same ref.
createTriggerRuns(mongoose)now also returnsreserve,detail,abort,abortSaved,claim,release,receiptandremove. The eight schedule methods (reserveStartedRun,setRunFireDetails,requestRunAbort,markRunAbortPersisted,markRunResumeClaimed,releaseRunResumeClaim,recordMCPToolAuthFailure,deleteScheduleRun) keep their names and signatures and call them, so no caller inpackages/apiorapi/changes.The database is sent exactly what it was sent before: the same commands, in the same order, with the same filter, update document and options, and the same handling of a duplicate key or a write that matched nothing. Nothing stored changes: no field, no index, no new meaning for an existing one.
Only schedules record runs today. A write for a subject of any other kind sends nothing and answers as it would for a run that is not on record.
Not in this pull request: settling a run (
recordRunOutcome,recordSkippedRun,finalizeBookkeeping), which also writes the schedule's card and counters, and the reconciliation sweeps with the stamp that goes with them (markRunsReconciled). Those stay schedule methods.Related to #18674, #18645.
How it works
Each writer is the body of the schedule method it came from, with the two columns that name a row taken from the ref. The schedule method is left as the call.
async function releaseRunResumeClaim(scheduleId, scheduledFor, capacitySlot) { - const released = await ScheduleRun().updateOne( - { scheduleId, scheduledFor, status: 'started', capacitySlot }, - { $set: { status: 'requires_action' }, $unset: { capacitySlot: 1, resumeClaimedAt: 1 } }, - { timestamps: false }, - ); - return (released.modifiedCount ?? 0) > 0; + return runs.release(occurrence(scheduleId, scheduledFor), capacitySlot); }What each writer sends, and what holds it to one winner:
reservereserveStartedRuninsertOnewithstatus: 'started'; onefindOneof the status only after a duplicatedetailsetRunFireDetailsupdateOneabortrequestRunAbortupdateOne, and onefindOneonly when it matched nothing. Otherwise oneupdateOne, and a second that only renews the stamp when the first matched nothingabortSavedmarkRunAbortPersistedupdateOne,timestamps: falseclaimmarkRunResumeClaimedfindOneAndUpdate,timestamps: falserequires_action; the same two unique indexes as a reservationreleasereleaseRunResumeClaimupdateOne,timestamps: falsestartedand the exact slot claimedreceiptrecordMCPToolAuthFailureupdateOnewith$addToSet,timestamps: false; onefindOneof a settled row only when no live row matchedremovedeleteScheduleRundeleteOneTwo things stay in the schedule methods because they are about schedules:
recordMCPToolAuthFailurestill chooses what to record when it is given only a server name, andreserveStartedRunstill accepts any column of the row.reservetherefore takes the row's stored columns as given and returns the stored row, which is what the schedule method must hand its callers.A subject that records no runs gets the answer that already means "no such run":
abort,releaseandreceiptanswerfalse,claimanswersnot-paused, anddetail,abortSavedandremovedo nothing.reservehas no such answer, so it returns{ conflict: 'unrecorded' }; it is typed so that a caller passing a schedule's ref never sees it.The duplicate-key classifiers and the two constants the writers use (
ACTIVE_RUN_STATUSES, the 30-minute bound on an unresolved stop) moved with them. The result typesStartedRunReservationandResumedRunReservation, which nothing outside the schedule methods file imported, are nowTriggerRunReservationandTriggerRunClaim.Two versions side by side: old and new replicas send the same commands and write identical rows, so they can share the collection in any order during a deploy.
Performance
No command is added, removed or changed, and no index serves a different query. A fire still makes one insert to reserve its run and one update once its request is accepted; a stop makes one or two; a resume makes one; a rollback makes one delete.
triggerRun.write.spec.tsrecords every command the eight schedule methods hand the driver and compares it, key order included, with a literal; the same 87 tests pass againstdev's unchangedschedule.ts(run locally by restoring the three source files fromdev). Added work per call: one small object for the ref and one function call. Not measured: latency, since the database work is identical.Type of change
Testing
Tested environments/configuration:
mongodb-memory-server, real indexes built byScheduleRun.init(), the clock held still so every stamp a writer takes is a known value.Automated tests:
packages/data-schemas/src/methods/triggerRun.write.spec.ts, 182 tests. Every test of a writer runs twice, once through the schedule method and once through the run record, with the same expectations.keyorsubscriptionsubject: every writer answers without sending a command and the collection is unchanged.schedule.methods.spec.ts,triggerRun.spec.tsandrunGrant.spec.tsinpackages/data-schemas(282 tests, 464 with the new spec); inpackages/api,fire.spec.ts,authorization/runtime.spec.ts,authorization/receipt.spec.ts,receipts.integration.spec.ts,barriers.integration.spec.ts,project.spec.ts,erasure.spec.ts,lifecycle.spec.ts,service.spec.tsandengine.spec.ts(448 tests, 4 Redis-only cases skipped as ondev); inapi/,Tools/mcp.spec.js,MCP.spec.jsandEndpoints/agents/initialize.spec.js(278 tests).$unset,timestamps: false, the stale bound and its direction, the status lists), each answer, each subject-kind check, and each argument a schedule method passes on.tsc --noEmitinpackages/data-schemasandpackages/api;npm run static-checks -- --against origin/dev.Live, on a server built from this branch (run before and again after the branch was rebased onto
devwith #18677 and #18673, same results):e2e/specs/mock/schedules-execution.spec.ts, 5 of 5, default deployment: a Run Now and a due occurrence reserve their run, record what the fire learned and settle; deleting a schedule while its run is active aborts it.aborted, the run settledinterruptedwith "Scheduled run was stopped", and a second Run Now of the same schedule then started and settledsuccess: the stopped run had given up the schedule's active place and its capacity slot.dev.requires_actionwith no tool call made; approving both calls resumed it, both calls ran, and it settledsuccess. The resume goes through the claim.Not exercised live: a resume that loses its claim, a released claim, and a rolled-back reservation. Those are covered by the stored-method and
packages/apisuites only.Quality report (
/quality check-all scopes=data-schemas; nopackages/apiorapi/source changed):57a71b450b: every changed line has a test; 3 of 3 files measured; the highest CRAP among changed functions is 10.0 (abort, complexity 10, 100% covered), thenmatchesRunDuplicateandreceiptat 8.0. Those complexities came with the code that moved.d936ea3a2b): 284 killed, 6 survived, 5 ignored as static, score 97.9%. None of the six was in a filter, an update document or an option. Five were in how a refusal from the database is read: a duplicate whose row is gone before its status is read, an index name after more than one space, an error with no code, and a message that is not text. The spec now covers each, and applying each by hand fails it.57a71b450b: 289 killed, 1 survived, 5 ignored as static, score 99.7%. Gate open.mergeScheduleMCPReceipts(terminal.mcp ?? [])with a one-element list holding a string, where a settled run recorded no outcomes. The line decides whether a settled run already holds every receipt it is sent, by whether merging them in adds an entry. The planted element can only absorb a receipt whose server, status and six other fields are all absent, which no receipt can be, so the answer isfalseeither way. It is not a fence and writes nothing.Screenshots / recordings
No user-facing change.
Risk / compatibility
dev.reserveStartedRuna row with no schedule id or time still gets a validation error and no write, with a different message; no caller does.