M6-S3 — Import sessions, overrides and typed failures
Section titled “M6-S3 — Import sessions, overrides and typed failures”| Module | M6 — Extension design |
| After this session you can | Drive an import through its session states from a script, change a resource with an override, and predict each typed failure before it happens. |
| Time | 63 min with a facilitator · about 63 min on your own |
| Before you start | M6-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 deeper | The 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”The session
Section titled “The session”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 anupdateIdentifier. - 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-idheader, 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.
Configuring a session
Section titled “Configuring a session”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>/payloadPATCH /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.
Execute, and what can stop it
Section titled “Execute, and what can stop it”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>".
-
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" -
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.jsonexport SID=$(jq -r '.result.sessionId' session.json) UID_=$(jq -r '.result.updateIdentifier' session.json) -
Read the state:
curl -s "$BASE/api/packaging/v1/import/$SID/status" -H "x-app-token: $REL" | jq '.result.status'. It isvalidated. -
Read the report’s summary: every resource is
EXISTING, because you import into the space the package came from. -
Read the same session in the web app’s import screen (Packages › Import): the wizard shows your session, because it reads the same API.
-
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.
✓ Practice (4 min) — The session
Section titled “✓ Practice (4 min) — The session”A release script posts the package ZIP as the body of POST /api/packaging/v1/import/validate. The
answer is 400. What is wrong?
Check your answer
The correct answer is B. Open the explanation under each option to see why.
A session’s status is completed. The release script reports success. What should it have read first?
Check your answer
The correct answer is B. Open the explanation under each option to see why.
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?
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
-
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') -
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. -
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.jsonUID_=$(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') -
Read the payload again:
isOverrideistrueandpackagedPayloadholds the original. -
Set Tell the CMMS to
OVERWRITEwithPATCH …/configand a one-itemmappingslist (sourceTypeDataReaction,sourceId$RID,actionOVERWRITE, the existingtargetIdfrom the session), carryingUID_. Keep the new identifier. -
Execute:
curl -s -X POST "$BASE/api/packaging/v1/import/$SID/execute" -H "x-app-token: $REL" | jq '.result'. You get a job id. -
Poll the status every few seconds until it is
completed; then readjq '.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. -
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)
- Wrong credential. Repeat step 2’s
GETwith the workbench token$TOKEN(Larkspur Workbench, system View). - Stale identifier. Repeat step 5 with the identifier you had before step 5.
- Structural override. Open a new session as in the demo (new
SID, newUID_), take the same reaction’s payload and change its defining entity’s id to Spare Parts’s id, thenPATCHit. - Cancel, then execute. Cancel that new session (
POST …/cancel), then call…/executeon it. - No file id. Call
…/import/validatewith the body{}. - Put Tell the CMMS’s address back in the designer.
Contain the credential
- 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 see | What to do |
|---|---|
| Step 1 answers 409 | The 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 address | Compare new.json with the payload: the jq path may have created a new key instead of changing the existing one. |
completed with one error | Read 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 200 | Your workbench token holds system Admin; use a token below Admin to see the refusal. |
| Every call answers 400 about the space | You 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”An override changes a view’s dataEntity so the view is created on another entity in the target. What
does the API answer?
Check your answer
The correct answer is B. Open the explanation under each option to see why.
An operator cancels a running import after 30 of 80 resources. What is the state of the target space?
Check your answer
The correct answer is C. Open the explanation under each option to see why.
A session has been importing for 20 minutes and nothing changes. What does the platform do, and what
do you do?
Check your answer
The correct answer is A. Open the explanation under each option to see why.
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?
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.