Skip to content

approvals: a hook refusal in the step after an approval answers 500 RESUME_FAILED after the decision is recorded, stranding the run and the record — surface the refusal as a 4xx before finalizing #34579

Closed

Description

@os-bob

What

An approval flow resumes after the approver's decision. If the next step is an update_record whose write is refused by a record hook (a business refusal declared in the hook's refusals catalogue, i.e. an ordinary 4xx-class refusal), then:

  • POST /api/v1/approvals/requests/{id}/approve answers 500 RESUME_FAILED (finalized, repairable);
  • the approver's decision has already been recorded before the resume ran;
  • the flow run is stranded: the record the flow should have moved stays where it was (here a plan stays submitted and its order stays in Special Approval);
  • only an administrator can repair it.

The approver receives no readable refusal, and the requester's record is stuck.

Repro (app project, 18.5.0)

  1. A special-approval flow on an allocation plan: approval node, then on approve an update_record that sets the plan to approved.
  2. The plan's beforeUpdate hook re-checks capacity at adoption and refuses (refuse('VALIDATION_FAILED', 'over_capacity')) when another order took the capacity while this plan waited.
  3. The director approves, and the call returns 500 RESUME_FAILED. The request shows as approved, the plan stays submitted, and the order is stuck.

Related but distinct, all closed: #13807 (reject returning 500 while its effect lands), #26477 (approving after the flow was deleted).

Expected

One of the following:

  • Preferred: run (or dry-run) the post-decision step before the decision is finalized. If that step's write is refused, answer the approver with the hook's localized refusal as a 4xx and leave the request pending, so the approver can reject instead.
  • At least: when a post-decision step is refused, do not strand the run. Route it down a declared failure edge, or mark the request as failed with the refusal text visible on the request, so the flow author can handle it without an administrator.

App side

The app does not throw at that step. Instead it bounces the plan back to the rep, marked over capacity, and releases the hold. This was a design choice made to stay within what the platform can do today. As a result the director never sees why, and the request still reads approved.

Activity

  1. objectstack-fleet commented on Nov 17, 2026

    @objectstack-fleet
    Contributor

    triage#1 · hotlong · session_01Q4EjjMnyLqJdzuktEmRPXH

    Path: none

    Triage: first touch → domain:server · p1 · theme: zh-CN customers (approvals) · 2026-11-17T02:45Z

    ⛔ Not a claim.

    Say an approval flow resumes after the approver decides, and the next update_record is refused by a record hook (an ordinary declared business refusal). Then approve answers 500 RESUME_FAILED after the decision is already recorded, and the run and the record are stranded. The approver sees a server error, the decision stands, and the business record never moves. Approvals are core to HotCRM and item 1 of the console core-UX epic #34571: p1. Expected: the hook refusal comes back as its 4xx refusal, with the run left in a state an admin can resolve.

  2. added
    bug
    domain:server
    pm:queue
    priority:p1
    on Nov 17, 2026
  3. objectstack-fleet commented on Nov 17, 2026

    @objectstack-fleet
    Contributor

    repo:objectstack#2 · os-steve · session_01ADHkmQ2SN4K183oqAvUajA

    Premise corrected · written at 2026-11-17T03:08Z · ⛔ not a claim

    Area o2-H read the code before claiming. This seat accepts the reading and narrows the card to the route that the rulings already on file allow. File and line references come from that area read and are re-checked by the dev at claim.

    The preferred route in the body conflicts with two maintainer rulings, so it is not dispatched.

    What is dispatched: the fallback, within those rulings.

    1. RESUME_FAILED on POST /api/v1/approvals/requests/{id}/approve carries the failed node's innerRefusal (ruling A screen flow whose write node is refused shows the end user the engine's raw node text, in English, with the node id and the object API name ("Node 'create_account' failed: create_record(crm_account) failed: …") #24914 B′: the hook's localized refusal text), as the runtime flow endpoint and the MCP gate already do. This widens a published error envelope: StrandedDecisionDetails in @objectstack/types, packages/spec/src/contracts/approval-service.ts and packages/rest/src/approvals-routes.ts. Clause-②: yes (widening). It owes a CONTRACT_REVIEW_TIER review.
    2. A flow author can already route a hook refusal on update_record down a declared fault edge: dag-traversal.ts routes run-time failures along fault edges (about lines 414 and 509), and only guard refusals are not routed. The PR pins that a hook refusal on the step after an approval follows a declared fault edge. It also teaches the fault edge where the approvals docs and skill describe resume failures, or names a Skills-docs: follow-up.

    Acceptance, narrowed: the approver gets the hook's readable refusal in the 500 answer, the decision stays recorded and repairable as #13807 B rules, and a flow with a fault edge on that step does not strand.

    维护者速读

  4. objectstack-fleet commented on Nov 17, 2026

    @objectstack-fleet
    Contributor

    repo:objectstack#2 · os-steve · session_01ADHkmSYe73LCZ6WxGFvcko

    Claim: PM loop · area o2-H · 2026-11-17T03:10Z
    Session: session_01ADHkmSYe73LCZ6WxGFvcko (area o2-H, which owns the card); the dev work runs in a card thread that reports to area o2-H
    Account: os-steve
    Branch: claude/project-thread-xczkxx (the card thread's branch, from origin/main)
    Worktree: the card thread's own checkout (session session_01ADHkmT4f9MMpnjemPU3Esb)
    Domain: domain:server
    Seat: repo:objectstack#2
    File surface: packages/plugins/plugin-approvals/src/approval-service.ts (resumeRecordedOutcome and the other RESUME_FAILED throws), StrandedDecisionDetails in @objectstack/types, packages/spec/src/contracts/approval-service.ts (docs of the envelope), packages/rest/src/approvals-routes.ts (the 500 body), their tests; a pin that a hook refusal on the step after an approval follows a declared fault edge (service-automation / approvals test); the approvals docs and skill text that describe resume failures, or a named Skills-docs: follow-up; root .changeset/**; spec generated baselines if the envelope's spec face moves (stop on breach; explain in the report)
    Container & model: M, mode:card-thread (card thread reporting to area o2-H), model: default judgement tier, effort: high; the contract face owes one CONTRACT_REVIEW_TIER review (L2 review seat)
    Clause-②: yes (widening: RESUME_FAILED on the approvals decision doors gains the failed node's innerRefusal)
    Metadata-protocol: none
    Responsibility: plugin-approvals decision doors (objectstack) | a hook's declared refusal on the step after a decision reaches the approver only as "could not be resumed" prose, while the runtime flow endpoint and MCP already carry innerRefusal (#24914 B′) | every approver whose post-decision step a record hook refuses, and every flow author who can route it down a fault edge but is never told
    Thread-read: 6936860860
    Premise: corrected 6936860860 (the seat narrowed the card to the fallback inside #13807 B and #13937 shape 4: status stays 500, the decision stays recorded and repairable, the envelope gains the hook's readable refusal, and a declared fault edge is pinned)
    Serial constraints cleared: open PRs read just now. #34545 (ctx.text, hook sentences) and #34592 (metadata-protocol compile cache) touch none of the files above by name; #34545 shares spec generated baselines (api-surface, json-schema.manifest, liveness), so the card thread runs git merge-tree against both heads before its PR and again before its final head.
    Pre-claim lane: domain:server — plugin-approvals, rest; seat 2 granted this card to area o2-H (relay 03:09Z).
    Pre-claim deps: no Blocked-by:.
    Prior rulings read: approvals,hook,refusal,step,approval,answers,resume_failed,recorded,stranding,record,surface,finalizing → 298 hits; ADR-0077 Decision §1, ADR-0148 D1, ADR-0144 D8, ADR-0145 D2, ADR-0148 D6, ADR-0019 D4; plus the rulings the code records: #13807 (decision batch #37, option B), #13937 shape 4, #24914 B′, #16472 option A; thread: none; repo: objectstack-ai/objectstack

  5. added
    pm:dispatched
    and removed
    pm:queue
    on Nov 17, 2026
  6. objectstack-fleet commented on Nov 17, 2026

    @objectstack-fleet
    Contributor

    repo:objectstack#2 · os-steve · session_01ADHkmT4f9MMpnjemPU3Esb
    os-dev-report

    {
     "issue": 34579,
     "status": "done",
     "branch": "claude/project-thread-xczkxx",
     "pr": "https://github.com/objectstack-ai/objectstack/pull/34619",
     "head": "95eae72668321d7f8eb2233f80753911e1202288",
     "session": "session_01ADHkmT4f9MMpnjemPU3Esb",
     "premise_still_valid": true,
     "premise_note": "Corrected premise 6936860860 holds (engine stranded exit carries innerRefusal/userMessage at run-resume.ts readCarriedRefusal; approvals serviceResume dropped them). Measured one narrowing of its wording: for a catalogue hook refusal, innerRefusal.message is the diagnostic `hook '<name>' threw: …` (SandboxError .message); the localized sentence is .userMessage. So the PR carries both, reusing the flow doors' pair (details innerRefusal + top-level userMessage).",
     "files_changed": [
      "packages/types/src/stranded-decision.ts",
      "packages/types/src/stranded-decision.test.ts",
      "packages/plugins/plugin-approvals/src/approval-service.ts",
      "packages/plugins/plugin-approvals/src/hook-refusal-after-decision.test.ts",
      "packages/rest/src/approvals-routes.ts",
      "packages/rest/src/rest-approvals-wire-codes.test.ts",
      "packages/spec/src/contracts/approval-service.ts",
      "content/docs/automation/approvals.mdx",
      "scripts/engine-double-contract.pinned.json",
      ".changeset/34579-resume-failed-carries-refusal.md"
     ],
     "line_budget": "+458 / -6, 10 files (PR read)",
     "tests": "hook-refusal-after-decision.test.ts 3/3; ablation (approval-service.ts at origin/main): case 1 red (expected {…(3)} to deeply equal {…(5)}), cases 2-3 green (fault-edge routing is existing engine behaviour, pinned). plugin-approvals 122 files/1723 pass; types 40/923; rest 419/8865 pass (373 skipped); typecheck types/plugin-approvals/rest exit 0.",
     "gates": "dispatch-gates at 95eae726: 125 derived, 125 run, all exit 0, 0 NOT-MEASURED, 0 UNRUN (/mnt/project-files/objectstack-seat2/34579-gates-ran.txt). merge-tree at 95eae726 clean vs origin/main 97defd6067, #34545 df9ac15c59, #34592 a6661f57e8.",
     "deviations": [
      "Package suites ran at ae18aa0c; 95eae726 changes only the two test files (re-run green) and the engine-double ledger.",
      "Review request to os-steve not sent (standard-order forbids MCP writes); assignee set by pr_create."
     ],
     "mcp_calls": "issue_read x2, pull_request_read x2 (get_check_runs, get); no write tool",
     "api_writes": "relay: pr_create (#34619, assignee os-steve), issue_patch (#34619 body r2), this os-dev-report comment; plus 2 git pushes",
     "open_questions": [
      {
       "question": "需契约复审",
       "options": [
        "Route a CONTRACT_REVIEW_TIER review of PR #34619 at head 95eae72668321d7f8eb2233f80753911e1202288 to the online review seat"
       ],
       "recommendation": "Clause-② yes (widening): StrandedDecisionDetails gains optional innerRefusal/userMessage; RESUME_FAILED 500 body gains them when present"
      },
      {
       "question": "userMessage beside innerRefusal (beyond the premise's wording)",
       "options": [
        "A: carry both (shipped) — the approver gets the hook's localized sentence",
        "B: innerRefusal only — approver sees the diagnostic text"
       ],
       "recommendation": "A; measured necessary for the acceptance line, same vocabulary as the flow doors"
      }
     ],
     "security_findings": "none",
     "out_of_scope_findings": [
      {
       "class": "c",
       "reach": "skills/objectstack-automation/references/state-machines-and-approvals.md",
       "evidence": "Skills-docs: follow-up owed — teach the fault edge after an approval step and the RESUME_FAILED refusal members"
      }
     ]
    }
  7. removed
    pm:dispatched
    on Nov 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugdomain:serverpriority:p1

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions