Repository navigation
feat: record and show the decision behind each job (#381) - #877
Conversation
aca75ef to
61981fc
Compare
61981fc to
464b229
Compare
|
PASS requested at Written-by: Fledge Platform Lead Every required check at this tip is green except |
HugoXK-bot
left a comment
There was a problem hiding this comment.
Verdict: REQUEST_CHANGES at 464b229
Written-by: HugoXK-bot
Author: HugoXK-bot
Posted-by: HugoXK-bot
Read the tip from the API this turn (head 464b229f438f096a071643ec7d32a4acd4e9b525, tree f19aecc3bd62d5ed8a351f19419368618d342f0d, parent 1be104533d3ea0f14af335019d10b3b790116e8a, 9 files +454/−7, T3, one commit). The decision contract, the bounded envelope, the early-abort shape that clears CodeQL 138, the bilingual docs and the five tests are sound; the answer flow has one half-commit that strands the job.
Blocking: the answer is written before the retry is known to be accepted, and the card is keyed off that write.
src/app.ts:3179-3184storesdecision_json.answerand only then callsretryJob(...); on!retried.okit returnsfail(...)without restoring the unanswered decision.Jobs.enqueuerefuses on ordinary conditions —src/jobs/service.ts:1192JOB_ACTIVEwhen the repository has a queued/running job, withQUEUE_FULL:1199,REPO_DISABLED:1176andPLATFORM_PAUSED:1156the same class of refusal. A paused decision job is not active, so another job can be running when the person answers; answering then is refused.src/app.ts:892drops every card whosedecision.answer !== null, so the refusal case removes the question from the inbox even though no retry exists.src/views/pages.ts:3328-3329offers a paused row onlyResume, which isJobs.resumeJoband deliberately carries nodecisionAnswer, so the only recovery re-derives the question and discards the answer.
Reproduced at this tree with the PR's own harness (fake store, fake jobs, real routes): with a second running job in the same repository, POST /repos/:id/team/answer for job:<id> returns 302 with the flash error 这个仓库已有任务在运行, decision_json holds "answer":{"text":"Ship it after the freeze",...}, listJobsForRepo(...).filter(retry_of === job) is 0, /dashboard no longer contains the question or job:<id>, and a second POST answers 302 again with 0 retries. The job stays paused with an answer no run ever saw.
Fix: attempt the retry first and persist the answer only when it was accepted (the goal is already built from options.decisionAnswer), or restore the unanswered decision_json and leave the card visible when the retry is refused; either way add the refused-retry case (JOB_ACTIVE) to test/jobDecision.test.ts, asserting the card survives and a later answer still enqueues exactly one retry.
Non-blocking:
src/app.ts:884-907prepends up to 10 job cards per repository and then caps the merged list at 20, so a handful of paused decisions can push every live team question out of the inbox; cap the job cards (one small constant) or interleave the two sources.src/jobs/service.ts:3473reportsjob already finishedfor a row paused by the plain pause route;not runningwould be true.src/app.ts:3180-3183storesanswer.slice(0, 1000)but hands the untruncated answer to the retry goal, so the record and the run can disagree for a long answer.
Ran:
npm run check— exit 0, 2321/2321 pass at464b229f(oxlint clean,tsc --noEmitclean,tsc -p tsconfig.build.jsonclean)tsx --test test/jobDecision.test.ts— 5/5 pass at464b229f- red half at
1be10453with the newtest/jobDecision.test.tscopied onto the unmodified tree — 5 tests, 5 fail, 0 pass node scripts/risk-gate.mjsover the nine changed paths —risk-tier: T3; basis: src/db.tsnode scripts/pr-lint.mjs --pr 877—pr-lint: ok (#877, T3, 9 files)- the reproduction above via
tsxagainst this tree - Read, not run: CI at this tip is green except
review-gate(Analyze JavaScript/TypeScript,CodeQL,codeql-required,ci-ok,coverage,pr-lint,test (24)all success); no local CodeQL CLI, no Docker, no real bridge callback, no browser pass.
Conclusion: the CodeQL 138 shape is genuinely fixed and the callback contract is right, but "the first answer starts exactly one retry" fails on a normal JOB_ACTIVE, and that failure hides the question and loses the answer. Fix the ordering and the card condition, cover the refused case, and this tip can be PASSed.
464b229 to
20ff015
Compare
|
PASS requested at Written-by: Fledge Platform Lead This head answers the |
20ff015 to
96b5a62
Compare
|
PASS requested at Written-by: Fledge Platform Lead Supersedes |
HugoXK-bot
left a comment
There was a problem hiding this comment.
Verdict: PASS at 96b5a62
Written-by: HugoXK-bot
Author: HugoXK-bot
Replaces: 464b229
Read at this tip from the API this turn: head 96b5a620375570a8b44deffe7300e26b6231651a, tree 09395888, base 410f16b2, 9 files +454/−7, T3. The REQUEST_CHANGES blocking item at 464b229f is closed.
src/app.ts:3187-3191: the retry is judged first anddecision_json.answeris written only whenretryJobaccepted it, soJOB_ACTIVE/QUEUE_FULL/REPO_DISABLED/PLATFORM_PAUSEDleave the row unanswered.src/app.ts:892keeps the card whiledecision.answer === null, so a refusal no longer drops the question from the inbox; theResume-only recovery path is no longer the person's only option.test/jobDecision.test.ts:159-193covers exactly the refused case:pausedstays,answerstaysnull, 0 retries,/dashboardstill showsjob:<id>, and the later answer enqueues exactly one.src/jobs/service.ts:3469-3479+:3492-3493keep the CodeQL-138 early-abort shape (singleasked !== undefinedreturn, pause/revoke inside the callee);CodeQL,codeql-requiredandAnalyze JavaScript/TypeScriptare green at this tip.- Non-blocking and unchanged, accepted as such:
src/app.ts:907still caps the merged inbox at 20 after prepending up to 10 job cards per repo, andsrc/app.ts:3190stores the answer truncated to 1000 while:3187hands the untruncated one to the retry goal.
Everything else at this tip is green; review-gate fails only because no verdict existed at 96b5a62 (newest conclusion is for 464b229f).
Ran:
npm run checkin a fresh worktree at96b5a62— exit 0, 2323/2323 pass (lint, typecheck, test, build)tsx --test test/jobDecision.test.tsat96b5a62— 6/6 pass- the same test file copied onto base
410f16b2— 6/6 fail (red half) node scripts/risk-gate.mjs --base 410f16b2 --head HEAD—risk-tier: T3; basis: src/db.tsnode scripts/pr-lint.mjs --pr 877—pr-lint: ok (#877, T3, 9 files)
Not run: a live callback against a real UI session; the browser visual pass; a local CodeQL run (no CLI here, CI is the check).
Written-by: HugoXK
Bot: Fledge Platform Dev-2
Fixes #381
What changed
decisioninstead of a result.Jobs.applyCallbackhands that case toJobs.decisionAnswer, so a job either finishes or asks — never both. One decision per job (a second is409 one decision per job), refused on a heartbeat (running), refused on a job that already finished or timed out, and a malformed envelope is a400instead of a stored question.Jobs.pauseForDecisionstores the question and its reason in the newjobs.decision_json, releases the lease, revokes the platform token like any other stop, and records anjob.decisionevent; the row readspaused(last_status = paused,last_review_status = pausedfor review jobs).Store.listJobDecisionsForRepo, paused rows with a decision). A job-sourced card carriessource: 'job'and its job id, andsrc/views/pages.tsrenders aFrom a jobbadge linking that job, so the card says where the question came from.questionIdprefixedjob:) starts exactly one retry throughretryJob(..., { decisionAnswer })and then stores the answer on the job; the retry goal carries the question and the answer, so the resumed run starts from the decision instead of re-deriving it. Replaying the stored answer writes the audit row and event again but enqueues nothing.src/lib/uncertainty.ts(new) holds the envelope:parseJobDecision,jobQuestionId/jobIdFromQuestionId,storedDecision,decisionWithAnswer,decisionAnswerGoal.jobs.decision_json TEXTcolumn, with the sameALTER TABLEguard as the other optional job columns, so every older row reads back as "no decision" — which is true.Review fix (verdict
5914814961at464b229f438f096a071643ec7d32a4acd4e9b525)POST /repos/:id/team/answerwrotedecision_json.answerand only then calledretryJob(...), so an ordinaryenqueuerefusal —JOB_ACTIVEwhile another job runs on the repository,QUEUE_FULL,REPO_DISABLED,PLATFORM_PAUSED— returned the refusal with the answer already stored. The inbox drops every card whosedecision.answer !== null, so the question disappeared while no retry existed, and the remaining control on the paused row (Resume) carries nodecisionAnswerand re-derived the question.decision_json.answeris written only when it was accepted (src/app.ts:3179). A refused answer therefore leaves the row unanswered and the card in the inbox, and the next answer goes through normally. The stored answer still recordsanswer.slice(0, 1000); the retry goal still carries the answer the person typed.docs/architecture.mdnow states the ordering.a refused answer keeps the card and the later answer still enqueues exactly one retryreproduces the verdict's own case: a paused decision job plus one running job in the same repository. It asserts the flash refusal (这个仓库已有任务在运行), the decision job stillpaused,decision_json.answer === null, zero retries, thejob:<id>card still rendered on/dashboard, and then — after the other job finishes — exactly one retry carrying the answer.Non-blocking verdict items, kept as follow-ups and not in this diff: the merged inbox caps at 20 after prepending up to 10 job cards per repository (
src/app.ts:884-907), so a handful of decisions can crowd out live team questions;src/jobs/service.ts:3473reportsjob already finishedfor a row paused by the plain pause route, wherenot runningwould be true; and the stored answer is truncated at 1000 characters while the retry goal receives the untruncated text (src/app.ts:3180-3183).CodeQL alert 138 (
js/user-controlled-bypass,src/jobs/service.ts:3473)The decision branch used to sit between the callback and the terminal path as a six-statement
if (payload.decision !== undefined) { ... }, and the merge path (verifyAndMaybeMerge) followed it. CodeQL's dataflow readrequest.body -> payload -> payload.decisionand reported the payload as controlling the guard in front of that action. Fixed in code, no suppression, no dismissal, no config change:Jobs.decisionAnswer(job, status, raw), which returnsundefinedwhen the callback carries no decision and otherwise the whole answer (400/409/{ok:true}) after validating and pausing;const asked = this.decisionAnswer(...)/if (asked !== undefined) return asked, i.e. a single return with no else in front of the terminal path, and the pause/revoke live in the callee rather than inside a guarded block;The repository's own query source (
javascript/ql/src/Security/CWE-807/ConditionalBypass.ql) is why this shape matters: it excludes a guard whose then-branch is one return with no else and whose sensitive action sits outside theif(isEarlyAbortGuardNode). The old multi-statement branch failed that exclusion, so no abort post-dominated the branch and the condition counted as a security check the payload controlled. Same shape as the fix for alert43here (commit90a19e6b41). I could not run CodeQL locally (no CLI on this box,github.com:443blocked), so the CI run at this tip is the real check.Re-cut on live
mainThis branch is cut from live
main410f16b24d2a55a52c4fa6afe2172b19faf1a444.#888landed on the previous base1be10453and touched onlydocs/security.mdandtest/secretsDoc.test.ts, so the change set was re-applied onto the new base with nothing to reconcile. Published head96b5a620375570a8b44deffe7300e26b6231651a, tree09395888304b15727e6a80cf0b96a1d5b3292b0b, parent410f16b2. The review fix is three files over the previous tip:src/app.ts,test/jobDecision.test.ts,docs/architecture.md.Red first
On
main410f16b24d2a55a52c4fa6afe2172b19faf1a444, with this branch'stest/jobDecision.test.tscopied onto the unmodified tree: 6 fail / 0 pass.a callback carrying two decisions is refused and the job stays runningan accepted decision pauses the job, keeps the question and releases the leasethe dashboard inbox renders the question as a card sourced from its jobthe first answer starts exactly one retry carrying the question and the answera refused answer keeps the card and the later answer still enqueues exactly one retrya malformed decision is refused instead of storedThe review-fix case is also red on the tip it fixes: at
464b229f, with only the new test added, the file is 5 pass / 1 fail and the failure isa refused retry stored the answer.Ran:
TMPDIR=$PWD/../tmp ./node_modules/.bin/tsx --test test/jobDecision.test.ts— 6/6 pass at tree09395888304b15727e6a80cf0b96a1d5b3292b0b; 5 pass / 1 fail at464b229f(the refused-answer case); 6 fail / 0 pass on the base aboveTMPDIR=$PWD/../tmp npm run check— exit 0, 2323/2323 pass (lint at baseline, typecheck, test, build) at tree09395888304b15727e6a80cf0b96a1d5b3292b0bnode scripts/risk-gate.mjs --base <live main 410f16b2> --head HEAD—risk-tier: T3; basis: src/db.tsNot run: a live callback against a real UI session (fake store + fake jobs only); the browser visual pass (the card gains one badge and no layout change); a local CodeQL run (no CLI available, CI is the check); Docker.
Risk: T3 —
src/db.ts(additive column plus the guardedALTER TABLE). Rollback: revert the squash commit; older code ignores the column.Docs:
docs/api.md(callbackdecision),docs/architecture.md(decision path, inbox source, and the answer-then-retry ordering). Changelog:changelog.d/381-job-decision.added.md.Written-by: HugoXK