---
id: STATE-ACC-BAT-003
title: Posting job
object: DOM-ACC-BAT-003
product_area: accounting
module: batches
revision: 1
status: draft
design_intent: confirmed
origin: >-
  DESIGN D6 (posting is a durable job) and Andrew D7 of 2026-10-15 (a write the
  database refuses fails the job, no compensation), recorded at
  services-accounting:docs/migrations/batch-posting/DESIGN.md#D6 and
  modules/batches/services/jobs/batch-posting-job-tasks.ts (header)
implementation_evidence: observed
source_sha:
  services-accounting: f47cb263875bbc0c5640fba7dae6785ec32695f8
  react-console: baf6dae382d6f41dce976c7f848667ccc37e076f
states:
  - name: pending
    meaning: A durable submission exists before workflow execution begins.
  - name: running
    meaning: The workflow is processing its published checking and writing phases.
  - name: succeeded
    meaning: >-
      Accounting committed and the task completed step settlement, with batch
      outcomes retained in the result.
  - name: failed
    meaning: >-
      Workflow failure was recorded; whether accounting changed depends on
      whether failure preceded or followed commit.
transitions:
  - from: pending
    to: running
    trigger: The workflow invokes its working task.
    guard: Submission committed before workflow start.
    side_effects:
      - Publish the phase definition and mark the checking phase running.
    who: The durable workflow and Accounting task
    provenance: observed
    source: >-
      services-accounting:modules/batches/services/jobs/batch-posting-job-tasks.ts:postBatchesOperation
  - from: running
    to: succeeded
    trigger: Accounting commits and the task settles its phases.
    guard: Required completion writes succeed.
    side_effects:
      - 'Complete checking, record collected progress and complete writing.'
      - >-
        Report document-level Error batches in the result without treating them
        as workflow failure.
    who: The Accounting working task
    provenance: test
    source: >-
      services-accounting:modules/batches/tests/integration/services/posting/rebuilt-posting-edges.integration.spec.js#posts
      January, puts April in error naming the application whose credit's batch
      is not posted, and May in error as April's dependent
  - from: running
    to: failed
    trigger: A transactional write or whole-request admission check refuses execution.
    guard: The failure occurs before accounting commit.
    side_effects:
      - Rollback restores prior accounting and batch state.
      - >-
        Record a safe failure summary and fail the workflow through its failure
        handler; the refusal is not retried.
    who: The Accounting task and workflow failure handler
    provenance: test
    source: >-
      services-accounting:modules/batches/tests/integration/services/jobs/deployed-task-handler.integration.spec.js#fails
      the job on a step the database refuses: refused once, recorded by the
      failure task, the batch open and nothing written
  - from: pending
    to: failed
    trigger: Execution fails before the working task runs or reaches its timeout.
    guard: No accounting task has committed.
    side_effects:
      - Record workflow failure without changing batch accounting.
    who: The durable workflow failure path
    provenance: observed
    source: >-
      services-accounting:modules/batches/services/jobs/batch-posting-jobs.ts:batchPostingWorkflow
  - from: running
    to: failed
    trigger: Post-commit phase settlement fails and recovery cannot complete.
    guard: The accounting transaction has already committed.
    side_effects:
      - >-
        Retain completed posting or unposting even if the workflow records
        failure.
    who: The task workflow and failure handler
    provenance: inferred
    source: >-
      services-accounting:modules/batches/services/jobs/batch-posting-job-tasks.ts:postBatchesOperation;
      FND-ACC-BAT-039
invalid:
  - from: failed
    to: running
    why: >-
      The job registration provides no user retry operation; recovery requires
      another submission.
  - from: succeeded
    to: running
    why: >-
      No user retry is registered; a new request for a set still posted by the
      completed job returns that existing job.
  - from: running
    to: pending
    why: Cancellation is not offered by the posting job registration.
invariants:
  - INV-DOM-ACC-BAT-003-02
  - INV-DOM-ACC-BAT-003-03
concurrency: >-
  Batch locks serialize equivalent submissions and are reacquired for accounting
  execution. An unsuccessful workflow start can leave a Pending job indefinitely
  because no reconciler is registered. Post-commit recovery does not undo the
  ledger; its exact outcome is unproved and can include recorded job failure.
evidence:
  - >-
    services-accounting at f47cb263:
    modules/batches/services/jobs/batch-posting-jobs.ts,
    batch-posting-job-tasks.ts, batch-posting-steps.ts;
    services/persistence/batch-posting-jobs.ts;
    aws/logic/batch-posting.step-functions.ts; db/batch-posting-jobs.table.ts
---

# Posting Job

## The Lifecycle

```mermaid
stateDiagram-v2
  [*] --> pending: persist submission
  pending --> running: execute workflow
  pending --> failed: start-path execution failure
  running --> succeeded: commit and settle
  running --> failed: admission, write or settlement failure
  succeeded --> [*]
  failed --> [*]
```

Posting and unposting use separate job families with the same execution shape.

## Transitions Explained

Accounting commit and job completion are separate boundaries. The transition rows distinguish rollback before commit from settlement failure after it. A batch-level generation refusal can appear in a successful job result.

## What Cannot Happen

The registration exposes no user retry or cancellation. A Failed status therefore cannot be read as proof that accounting remained unchanged. Staff must inspect the batch outcome when post-commit settlement did not finish.

## Concurrency and Timing

The workflow allows twenty minutes and its working task fifteen. Batch locking protects overlapping accounting execution, but it does not provide missing start reconciliation or guarantee post-commit settlement recovery.
