Skip to content

M6-S3 — Import sessions, overrides and typed failures

Section titled “M6-S3 — Import sessions, overrides and typed failures”
ModuleM6 — Extension design
After this session you canDrive an import through its session states from a script, change a resource with an override, and predict each typed failure before it happens.
Time63 min with a facilitator · about 63 min on your own
Before you startM6-S2 and its asset-maintenance.zip. Larkspur Lab, Rami Aziz signed in, the workbench API window and the lab’s mail catcher. The package contract card.
Go deeperThe import API · Generating a package: overrides · Long-running work

◆ Orientation (1 min) — The import as a wire contract

Section titled “◆ Orientation (1 min) — The import as a wire contract”

The import wizard you used in ACE is a client of an API. Larkspur’s release pipeline will be another: a script that promotes each package from Larkspur Lab to production, sets the values that differ, and stops with a clear reason when something is wrong. In this session you write that script’s steps by hand, against a real session, and break it on purpose in five ways. You also meet the program’s most powerful credential, the one imports require, and decide how to contain it.

▤ Concept (5 min) — A session, its states and its gates

Section titled “▤ Concept (5 min) — A session, its states and its gates”

An import is a session kept by the packaging service, one per attempt. Four facts govern every call:

  • The package is not posted to the import. You upload the ZIP to the storage service first (POST /api/storage/v2/files?temp=true), then open the session with the file’s id (POST /api/packaging/v1/import/validate, body {fileId, fileName, importStrategy}). The packaging service downloads the file itself, validates it and answers with the session id, a validation report and an updateIdentifier.
  • Every import, execution, override and mapping route needs a system-level Admin grant since 1.10. Edit on every module is not enough: a caller below system Admin gets 403.
  • The space comes with the request. Past the gateway, the target space travels as the x-space-id header, which the gateway sets from the request’s host (overwriting anything the client sent). A request that reaches the packaging service without it is refused with 400; a session that belongs to another space answers 403.
  • Sessions expire. One that is not updated for seven days is deleted.
stateDiagram-v2
  [*] --> validating: open the session (file id)
  validating --> validated: report produced
  validating --> failed: unreadable package or incompatible schema
  validated --> importing: execute (atomic claim)
  importing --> completed: every mapping processed, errors or not
  importing --> failed: unrecoverable error, cancel, or stuck 15 minutes
  validated --> failed: cancel
  completed --> importing: retry
  failed --> importing: retry (never after a cancel)

What to notice: completed means “processed”, not “succeeded”, and failed is also where a cancellation lands. Read the result, not the state.

Between validation and execution you decide, per resource, what happens. The strategy sets them all at once: merge new only creates new resources and skips existing ones, overwrite all creates new and overwrites existing ones, manual leaves each decision to you. Per resource the action is CREATE, OVERWRITE or SKIP; a SKIP on an existing resource still records its id mapping, so other resources that point at it are rewritten to it (the wizard calls this Map). Records the design points at, such as an owner group, get KEEP, REMAP, NULL or AUTO_CREATE. Dependencies outside the package must be given a target. Since 1.10, mapped fields whose source cannot be matched need your decision too.

Every write carries the updateIdentifier you last received, and every successful write returns a new one. A stale identifier is refused with 409 STALE_UPDATE_IDENTIFIER: someone else changed the session. That code is different from the other 409s, which mean the session is in the wrong state.

Overrides: one package, one value per environment

Section titled “Overrides: one package, one value per environment”

A payload override replaces one resource’s packaged JSON, for this session only, at execution time and before remapping, so you write it in the package’s own ids:

GET /api/packaging/v1/import/<session>/resource/<type>/<source id>/payload
PATCH /api/packaging/v1/import/<session>/resource/<type>/<source id>/payload {payload, updateIdentifier}
DELETE /api/packaging/v1/import/<session>/resource/<type>/<source id>/payload?updateIdentifier=…

The GET answers the payload the execution will use, whether it is an override, and the packaged original while an override is active. An override is a content hook, never a structure hook: the fields that say where a resource lives (an entity’s module, a view’s entity, a reaction’s defining entity) are fingerprinted at validation and an override that changes one is refused with 400. A payload over 2 MB is refused with 413. Saving an override on a resource that failed resets it to pending, so a retry picks it up: the override API doubles as the repair loop.

POST …/execute checks, in order: the session was not cancelled (409 IMPORT_SESSION_CANCELLED); if it is already completed or failed, it behaves as a retry; every dependency needed by a resource that will be written has a target (400); every mapped field that needs a decision has one (409); every record reference has an action (400 VALUE_REFERENCE_ACTION_UNSET); a plan limit can refuse the run before anything is written. Then it claims the session with an atomic validated → importing move, so two concurrent executes never run twice. It answers {jobId, sessionId}: the work is queued on a background job, and you poll GET …/import/<session>/status until the state is terminal.

The result tells the truth that the state hides: counts of created, overwritten, skipped, cascadeSkipped and errors, the per-resource outcomes, and since 1.10 import warnings for what the import changed instead of failing (an index dropped, a file that did not transfer, a mapped field left as declared). A retry re-attempts only what failed or was cascade skipped. A cancel stops between resources, keeps what was already written, and is final.

Two rules come from elsewhere in the platform. Each imported reaction is checked against the person confirming the import, who needs Developer access on its entity; one they may not author is skipped and the rest lands. An imported Function is provisioned in the target like any new Function record.

▶ Guided demo (10 min) — Upload, validate, read the report

Section titled “▶ Guided demo (10 min) — Upload, validate, read the report”

Starting state. Larkspur Lab. The application user Larkspur Release exists with system Admin (the seed creates it); its token is in the lab’s mail catcher. In the API window: export REL="<the Larkspur Release token>".

  1. Upload the package:

    Terminal window
    FILE=$(curl -s -X POST "$BASE/api/storage/v2/files?temp=true" -H "x-app-token: $REL" \
    -F "file=@asset-maintenance.zip" | jq -r '.result[0].id'); echo "$FILE"
  2. Open the session in manual mode:

    Terminal window
    curl -s -X POST "$BASE/api/packaging/v1/import/validate" -H "x-app-token: $REL" \
    -H 'Content-Type: application/json' \
    -d "{\"fileId\":\"$FILE\",\"fileName\":\"asset-maintenance.zip\",\"importStrategy\":\"MANUAL\"}" > session.json
    export SID=$(jq -r '.result.sessionId' session.json) UID_=$(jq -r '.result.updateIdentifier' session.json)
  3. Read the state: curl -s "$BASE/api/packaging/v1/import/$SID/status" -H "x-app-token: $REL" | jq '.result.status'. It is validated.

  4. Read the report’s summary: every resource is EXISTING, because you import into the space the package came from.

  5. Read the same session in the web app’s import screen (Packages › Import): the wizard shows your session, because it reads the same API.

  6. Open the session document: curl -s "$BASE/api/packaging/v1/import/$SID" -H "x-app-token: $REL" | jq '.result | {status, importStrategy, n: (.resourceMappings | length)}'.

Screenshot pending The API window with the validate answer: the session id, the validation report summary and the update identifier What to notice: the session exists before anything is imported; the report is computed against the target space as it is now.

PracticeChoose one answer.

A release script posts the package ZIP as the body of POST /api/packaging/v1/import/validate. The answer is 400. What is wrong?

  1. Explanation for A

    ✗ Incorrect

    Not this one: a missing grant is a 403, not a 400. See the session.

  2. Explanation for B

    ✓ Correct

    Correct: validate takes {fileId}, and a missing file id is a 400. See the session.

  3. Explanation for C

    ✗ Incorrect

    Not this one: an incompatible schema produces a session in failed, not a refused request. See the session.

Check your answer

The correct answer is B. Open the explanation under each option to see why.

PracticeChoose one answer.

A session’s status is completed. The release script reports success. What should it have read first?

  1. Explanation for A

    ✗ Incorrect

    Not this one: completed fires when every mapping was processed, possibly with errors. See execute, and what can stop it.

  2. Explanation for B

    ✓ Correct

    Correct: the truth is in the result; a completed session may still carry per-resource errors and warnings. See execute, and what can stop it.

  3. Explanation for C

    ✗ Incorrect

    Not this one: progress shows how far the job went, not whether each resource landed. See execute, and what can stop it.

Check your answer

The correct answer is B. Open the explanation under each option to see why.

PracticeChoose one answer.

Two operators configure the same session from two scripts. The second script’s PATCH …/config answers 409 with STALE_UPDATE_IDENTIFIER. What should it do?

  1. Explanation for A

    ✗ Incorrect

    Not this one: the identifier it sent is stale, so the same request will keep failing. See configuring a session.

  2. Explanation for B

    ✓ Correct

    Correct: a stale identifier means someone else wrote; reload, reconcile, then write with the identifier you just received. See configuring a session.

  3. Explanation for C

    ✗ Incorrect

    Not this one: that is the response to a state 409, which carries a different code. See configuring a session.

Check your answer

The correct answer is B. Open the explanation under each option to see why.

⛏ Lab (35 min) — Promote one changed reaction, then break the script five ways

Section titled “⛏ Lab (35 min) — Promote one changed reaction, then break the script five ways”

Goal. Using the demo’s session, import only Tell the CMMS, with its address changed by an override, and leave everything else untouched. Then provoke five typed failures and record each.

Before you start. The demo’s REL, SID and UID_ variables. Find Tell the CMMS’s source id in the session: curl -s "$BASE/api/packaging/v1/import/$SID" -H "x-app-token: $REL" | jq -r '.result.resourceMappings[] | select(.normalizedName | test("tell_the_cmms")) | .sourceId' and export RID=<that id>.

Promote one reaction

  1. Set every resource to skip with merge new only (nothing is new here):

    Terminal window
    UID_=$(curl -s -X PATCH "$BASE/api/packaging/v1/import/$SID/strategy" -H "x-app-token: $REL" \
    -H 'Content-Type: application/json' -d "{\"strategy\":\"MERGE_NEW_ONLY\",\"updateIdentifier\":\"$UID_\"}" \
    | jq -r '.result.updateIdentifier')
  2. Read Tell the CMMS’s payload: curl -s "$BASE/api/packaging/v1/import/$SID/resource/DataReaction/$RID/payload" -H "x-app-token: $REL" > rp.json, and find the address in its Call API options.

  3. Write the override, changing only the address to the lab stub’s /v2/work-orders:

    Terminal window
    jq '.result.payload | (.actions[0].options.apiUrl) |= sub("/work-orders$"; "/v2/work-orders")' rp.json > new.json
    UID_=$(jq -n --slurpfile p new.json --arg u "$UID_" '{payload: $p[0], updateIdentifier: $u}' \
    | curl -s -X PATCH "$BASE/api/packaging/v1/import/$SID/resource/DataReaction/$RID/payload" \
    -H "x-app-token: $REL" -H 'Content-Type: application/json' -d @- | jq -r '.result.updateIdentifier')
  4. Read the payload again: isOverride is true and packagedPayload holds the original.

  5. Set Tell the CMMS to OVERWRITE with PATCH …/config and a one-item mappings list (sourceType DataReaction, sourceId $RID, action OVERWRITE, the existing targetId from the session), carrying UID_. Keep the new identifier.

  6. Execute: curl -s -X POST "$BASE/api/packaging/v1/import/$SID/execute" -H "x-app-token: $REL" | jq '.result'. You get a job id.

  7. Poll the status every few seconds until it is completed; then read jq '.result.importResult | {created, overwritten, skipped, cascadeSkipped, errors, importWarnings}'. Screenshot pending The status answer of the finished session: completed, with one resource overwritten, the rest skipped, no errors and no warnings What to notice: the state says the job finished; only the counts say that exactly one resource changed.

  8. In the designer, open Tell the CMMS: its address ends with /v2/work-orders. Nothing else changed.

Break it five ways (record status, code and kind for each)

  1. Wrong credential. Repeat step 2’s GET with the workbench token $TOKEN (Larkspur Workbench, system View).
  2. Stale identifier. Repeat step 5 with the identifier you had before step 5.
  3. Structural override. Open a new session as in the demo (new SID, new UID_), take the same reaction’s payload and change its defining entity’s id to Spare Parts’s id, then PATCH it.
  4. Cancel, then execute. Cancel that new session (POST …/cancel), then call …/execute on it.
  5. No file id. Call …/import/validate with the body {}.
  6. Put Tell the CMMS’s address back in the designer.

Contain the credential

  1. Open Larkspur Release in Administration › Organization › Users. Write three containment measures you would apply to it, and the one thing it must never be used for.

Check.

  • The session went validated → importing → completed, with one resource overwritten and none created.
  • Only Tell the CMMS changed, and only its address.
  • Step 9 was refused with 403.
  • Step 10 was refused with 409 STALE_UPDATE_IDENTIFIER.
  • Step 11 was refused with 400 for a structural change.
  • Step 12 was refused with 409 IMPORT_SESSION_CANCELLED.
  • Step 13 was refused with 400, and step 15 lists three measures.

Pass condition. Your notes hold the promotion’s result counts and a five-row table of failures with status, code and kind (credential, concurrency, structure, state, request), each matching the session’s prediction.

If something goes wrong

What you seeWhat to do
Step 1 answers 409The session left validated (an earlier execute?). Open a new one as in the demo.
Step 3’s PATCH answers 400 although you changed only the addressCompare new.json with the payload: the jq path may have created a new key instead of changing the existing one.
completed with one errorRead importErrors: a reaction the confirming user may not author is skipped; Larkspur Release is system Admin, so check the entity id instead.
Step 9 answers 200Your workbench token holds system Admin; use a token below Admin to see the refusal.
Every call answers 400 about the spaceYou are calling a host that does not resolve to the Larkspur space; set BASE to your Larkspur Lab address, the one you exported before the lab began.
Model answer

The promotion. Merge new only turned every existing resource into a skip that still maps its id. The override replaced Tell the CMMS’s payload for this session only, before remapping, so you wrote it in package ids; the mapping then asked to overwrite that one resource. Execute claimed the session and queued the job; the result showed one overwritten, the rest skipped, no errors.

The failures. (9) 403: the token’s user is below system Admin, which every import route needs, a credential-level refusal of access. (10) 409 STALE_UPDATE_IDENTIFIER: someone (you) wrote since that identifier was issued, a concurrency refusal. (11) 400: a reaction’s defining entity is fingerprinted at validation, and an override may change content, not structure. (12) 409 IMPORT_SESSION_CANCELLED: a cancellation is final, a state refusal. (13) 400: validate needs a file id, a malformed request.

The credential. Larkspur Release can change every module of the space, so contain it: an expiry date and a named owner; used only by the release pipeline, from its own runner, never from a laptop; the token kept in the pipeline’s secret store and regenerated after each release train; and its use reviewed in the audit trail. It must never be used for day-to-day integration reads: those get their own narrow application users.

◇ Worked scenario (2 min) — The import that half-worked at night

Section titled “◇ Worked scenario (2 min) — The import that half-worked at night”

The nightly promotion of Quality and Compliance to Larkspur’s production reported completed. In the morning, Tariq Saleh finds that the Supplier Scorecard aggregate is missing, and so are two pages. Decide at each step before you read on.

Step 1. What did the result say? The script logged only the state. You read the session’s result: created 3, overwritten 41, errors 1, cascadeSkipped 4. The error is on the entity Corrective Actions: a field type the target refused. The four cascade-skipped resources are its hard dependents: two views, the aggregate (which joins it) and a page that shows the aggregate.

Step 2. Why only now? The lab had been upgraded to a newer 1.10 patch than production, and the field’s configuration uses an option production does not accept. The import was right to refuse it.

Step 3. Repair without a new package. The session is completed, which accepts a retry. You read the failing payload with the override GET, remove the unsupported option in an override, save it, which resets Corrective Actions to pending, and call retry. The retry re-attempts only the failed and cascade-skipped resources: five resources land, nothing else is touched.

Step 4. Fix the pipeline. You change the script to fail the release when errors or cascadeSkipped is not zero, to print the per-resource outcomes and warnings, and to refuse to start when the two environments’ release lines differ, a rule you add to the governance plan from M1-S2.

The lesson: a promotion script that reads the state is a script that reports success for a broken release. Read the result, gate on its counts, and use the override and retry loop to repair in place.

✓ Practice (5 min) — Failures and repairs

Section titled “✓ Practice (5 min) — Failures and repairs”
PracticeChoose one answer.

An override changes a view’s dataEntity so the view is created on another entity in the target. What does the API answer?

  1. Explanation for A

    ✗ Incorrect

    Not this one: where a resource lives is fingerprinted at validation and cannot be overridden. See overrides.

  2. Explanation for B

    ✓ Correct

    Correct: overrides change content, never structure; moving a resource is a mapping decision, not an override. See overrides.

  3. Explanation for C

    ✗ Incorrect

    Not this one: the session accepts overrides between validation and execution; the payload itself is refused. See overrides.

Check your answer

The correct answer is B. Open the explanation under each option to see why.

PracticeChoose one answer.

An operator cancels a running import after 30 of 80 resources. What is the state of the target space?

  1. Explanation for A

    ✗ Incorrect

    Not this one: a cancel stops the import between resources; it does not undo what landed. See execute, and what can stop it.

  2. Explanation for B

    ✗ Incorrect

    Not this one: resources are written as the job runs; deletion only removes the session record. See execute, and what can stop it.

  3. Explanation for C

    ✓ Correct

    Correct: written resources remain, the session ends in failed, and since 1.10 a cancel is final. See execute, and what can stop it.

Check your answer

The correct answer is C. Open the explanation under each option to see why.

PracticeChoose one answer.

A session has been importing for 20 minutes and nothing changes. What does the platform do, and what do you do?

  1. Explanation for A

    ✓ Correct

    Correct: a session stuck in importing past the recovery window is failed, and a failed session accepts a retry. See the session.

  2. Explanation for B

    ✗ Incorrect

    Not this one: recovery moves a stuck session to failed, and a delete is refused while importing. See the session.

  3. Explanation for C

    ✗ Incorrect

    Not this one: nothing restarts automatically; a retry is your decision, and it re-attempts only what did not land. See execute, and what can stop it.

Check your answer

The correct answer is A. Open the explanation under each option to see why.

PracticeChoose one answer.

A release pipeline opens import sessions with an application user that has Edit on every module of the target space and system View. Since the upgrade to 1.10 every call is refused. What do you recommend?

  1. Explanation for A

    ✗ Incorrect

    Not this one: import routes need a system-level Admin grant; Developer does not reach it. See the session.

  2. Explanation for B

    ✗ Incorrect

    Not this one: a person’s account in a pipeline mixes identities and survives the person’s departure badly. See the lab’s containment.

  3. Explanation for C

    ✓ Correct

    Correct: imports require system Admin, so the answer is a narrowly used and closely watched credential, not a weaker one. See the lab’s containment.

Check your answer

The correct answer is C. Open the explanation under each option to see why.

↺ Recap (1 min) — A release you can script

Section titled “↺ Recap (1 min) — A release you can script”

You can now drive an import from a script, from the storage upload to a result you gate on, change one value per environment with an override, predict the typed refusals, and contain the credential that imports require. Next, M6-S4: step back from the surfaces to the map of every extension point, and the test any extension must pass to keep the platform no-code.