Hotfix Deployment Workflow
Deploy an urgent fix directly to a production branch.
To port one commit already merged in development to several deploy branches, dispatch the hmis-deploy-porter agent (.claude/agents/hmis-deploy-porter.md), which runs this skill once per target.
Arguments
$0— Target production branch, or staging branch that serves production (e.g.,coop-production,rh-production,coop-staging,southernlanka-production)$1— Short description of the fix (e.g.,sequence-preallocation,critical-billing-fix)
Critical Rule
The branch name MUST end with -hotfix.
CI merge validation will block PRs from branches that do not end with -hotfix.
One open PR per production branch (including staging branches that serve production). If a PR targeting $0 is already
open, do NOT create a second one. Add the new fix to that PR's head branch,
push, and update the PR title/body so it lists every fix it carries (Step 1a).
Parallel PRs against the same production branch conflict with each other,
deploy in an unpredictable order, and each merge triggers a separate
production deployment.
**Confirm $0 is the exact branch actually deployed to the environment that
needs the fix before doing anything else.** Similarly-named branches serve
different environments and are not interchangeable — e.g. for COOP,
coop-production (pharmacy) and coop-staging (inward, live users) are two
distinct deployments. If there is any doubt which branch backs the environment
in question, ask the user rather than guess from the name. See the Common
Production Branches table below, and verify it is still accurate before
trusting it.
Step 1 — Stash Any Uncommitted Work
git stash
Step 1a — Check for an Existing Open PR on the Target Branch
git fetch origin
gh pr list --state open --base $0 --json number,headRefName,headRepositoryOwner,isCrossRepository,title
- An open PR exists: reuse it, even when another developer opened it.
Another author is not a reason to open a parallel PR: add your fix to their
branch and tell them. Only stop and ask if the open PR is not ready to take
more fixes (e.g. it is mid-review or scheduled to merge at a fixed time).
CI enforces this: single-deploy-pr fails every PR except the oldest open
one per deploy branch. Check out its head branch
(git checkout -B <headRefName> origin/<headRefName>), skip Step 2 but run
Step 2a, apply
the fix (Steps 3–6, pushing to <headRefName>), then in Step 7 run
gh pr edit <number> --title ... --body ... instead of gh pr create, so
the title and body cover every fix in the PR (one section per issue).
Do not rename the branch, even if its name only describes the first fix.
If isCrossRepository is true (the PR comes from a fork), its branch is
not on origin — stop and ask the developer how to proceed.
- No open PR: continue with Step 2 — but first check whether a remote
*-hotfix branch for this same fix already exists without an open PR
(git branch -r | grep -i hotfix). If one does, find out why before
creating a new branch: if its PR was merged, the fix may already be
deployed; if its PR was closed unmerged, it may have been abandoned or
targeted the wrong branch. Ask the user whether to reuse it (reopen / open a
PR from it) or start fresh — don't silently create a parallel branch.
Step 2 — Create Hotfix Branch from Production
git fetch origin
git checkout -b $1-hotfix origin/$0
Branch name format: <description>-hotfix
Examples:
sequence-preallocation-hotfixcritical-billing-fix-hotfixpersistence-tuning-hotfix
Step 2a — Sync `.gitignore` from `origin/development`
Deploy branches can lag development, and a stale .gitignore lets local artifacts (screenshots, tmp/, Playwright output) be staged by accident. Right after creating the branch:
git fetch origin +development:refs/remotes/origin/development # forced refspec; also works in a --single-branch clone
git checkout origin/development -- .gitignore
git diff --cached --stat # review; commit it with the fix, by explicit path
If .gitignore is already identical, nothing is staged. Never use git add -A or git add . anywhere in this workflow; stage explicit paths only.
Then sync the changeset guard, so the pre-push hook and the CI changeset-guard job run on this branch and its PR (the workflow has no branch filter, but a PR only runs workflows present on its head). Commit it on its own, before the fix:
GUARD_PATHS=".github/workflows/changeset_guard.yml .github/changeset-guard-patterns.txt scripts/changeset-guard.sh scripts/hooks/pre-push"
git checkout origin/development -- $GUARD_PATHS
git status --porcelain -- $GUARD_PATHS # only these paths
if ! git diff --cached --quiet -- $GUARD_PATHS; then
git commit -m "chore(ci): sync changeset guard from development" -- $GUARD_PATHS
fi
Pushing a change to .github/workflows/* needs a gh token with the workflow scope. Check gh auth status (the Token scopes line); if workflow is missing, run gh auth refresh -s workflow. Without it GitHub rejects the push. Then stop and ask the user; never drop the guard sync to get the push through.
If nothing is staged, the branch already has them. Without these files the local hook falls back to origin/development's copy, but CI does not.
Then remove stray gitlinks. Some deploy branches carry submodule entries with no .gitmodules URL (old .claude/worktrees/*, hmis.wiki, wiki-tmp), and CI checkout then fails with No url found for submodule path. List them and drop each one from the index, in its own commit:
git ls-tree -r HEAD | awk '$2=="commit"{print $4}' # must print nothing
git rm --cached <path> # for each path printed
git diff --cached --name-status # only D lines for those paths
git commit -m "chore: remove stray gitlink(s) so CI checkout works" # no pathspec: `-- <path>` re-adds it from the working tree
git ls-tree -r HEAD | awk '$2=="commit"{print $4}' # re-check: must print nothing
Step 3 — Apply the Fix
Make only the minimal changes required. Do NOT port unrelated features or refactors. Always compile the hotfix branch before opening the PR: PRs to deploy branches get no compile CI, and older branches often lack newer enum values or facade methods that a cherry-pick uses (2026-11-05: coop-staging lacked an InwardChargeType value; mp-production lacked AbstractFacade.updateByJpql).
A green compile does not prove a port. Also diff each changed method against development, and click the changed action once in the app and check its expected result.
Before editing persistence.xml, compare against the target production branch to understand the current state:
MSYS_NO_PATHCONV=1 git show origin/$0:src/main/resources/META-INF/persistence.xml # MSYS_NO_PATHCONV: Git Bash on Windows
Step 3a — Test on the Production Branch's Own Code
- Use a sibling clone, not a worktree:
git clone --branch $0 --single-branch https://github.com/hmislk/hmis.git ../$0, then setuser.name/user.email(a fresh clone can't commit). Do Steps 2–3 in the clone, so the build you test includes the fix. - Swap in local JNDI (unstaged), build, then deploy with
asadmin --port 9048 deploy --force=true --contextroot rh --name rh-3.0.0 target/rh-3.0.0.war. This replaces the developer's deployed build, so redeploy theirs when done. - If the menu is empty after login, sync the
Privilegesenum (see Playwright E2E §138), and ask whether the sync ships in the PR.
Step 4 — Pre-Commit Checklist
- [ ]
persistence.xmluses${JDBC_DATASOURCE}/${JDBC_AUDIT_DATASOURCE}— not hardcoded JNDI names (e.g.,jdbc/coop) - [ ] No credentials or sensitive files staged
- [ ] Changes are minimal — only what is needed for the hotfix
Note: The
persistence.xmlon production branches typically uses${JDBC_DATASOURCE}environment variable placeholders, while the local developmentpersistence.xmlhas hardcoded JNDI names (e.g.,jdbc/coop). Never copy the hardcoded JNDI name into the production branch.
Step 5 — Commit
git add <changed-files>
git commit -m "fix: <description of fix>
<Explanation of why this was needed and what it fixes.>
References issues #NNNN.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>"
Step 6 — Push
If you are reusing an existing PR (Step 1a), push its head branch:
git push origin <headRefName>
Otherwise push the new hotfix branch:
git push origin $1-hotfix
Step 7 — Create PR Targeting the Production Branch
Write the PR title and body to a file in tmp/ first and run the
hmis-public-guard subagent on it. Create the PR only after a PASS, with
--body-file in place of --body below.
gh pr create \
--title "fix: <description>" \
--base $0 \
--head $1-hotfix \
--label hotfix \
--body "..."
The PR must target $0 (the production branch), not development or master.
Every PR into a *-production or *-staging branch carries the hotfix label, so hotfixes are easy to tell apart from development PRs. When reusing an open PR (Step 1a), check the label is there: gh pr edit <number> --add-label hotfix.
If gh pr edit prints a "Projects (classic) is being deprecated" error, it changed nothing. Use gh api -X PATCH repos/hmislk/hmis/pulls/<n> -f title=... -F body=@file instead. That fallback does not add labels either, so also run gh api -X POST repos/hmislk/hmis/issues/<n>/labels -f "labels[]=hotfix". Whichever path you used, check the label is there: gh pr view <n> --json labels.
A hotfix PR is where hospital-specific detail leaks most easily, because the
whole point is that one hospital is affected. The body is public: state the
defect, the fix and the deploy note, and keep the affected-record counts,
production bill numbers, schema names and data-fix steps out of it — those go
to the developer directly or in tmp/. See
What May Go Into a GitHub Issue, PR, or Comment.
Step 7a — Plan the Merge Window (Several Hotfix PRs)
Merging is the user's call (or a scheduled-pr-merge job they approved).
When you plan or schedule several hotfix merges for one window:
- Stagger merges whose apps share a VM. Each deploy restarts an app on
Payara and loads the whole VM. Look up each branch's VM in the
(VM column) and give apps on the same VM separate slots, at least 30
minutes apart. Apps on different VMs may share a slot. The staging VM
counts too: its apps are live.
- One merge per deploy branch per window. The second PR to the same
branch can keep a red single-deploy-pr status after the first merges,
until the single_deploy_pr_sweep workflow re-runs. It runs when the deploy
of the first PR starts (about a minute), with a 15-minute schedule as
fallback, and a scheduled merge of it can stop on that status. Put both fixes in one PR
(Step 1a). If two PRs already exist, give the second a slot at least 20
minutes after the first, and before it merges confirm its
single-deploy-pr status is green; if not, run the sweep by hand
(gh workflow run single_deploy_pr_sweep.yml --ref development) and wait
for green.
Step 7b — Verify the Deploy Run
After each merge, check the deploy run's result. A login page that loads
proves nothing: it can be the old WAR still running.
gh run list --branch $0 --workflow <workflow file> --limit 3 --json databaseId,headSha,status,conclusion,createdAt
<workflow file>is the branch's deploy workflow from the deployment map
(e.g. coop_production_ci_cd.yml); without it the list mixes in other
workflows. The newest deploy run's headSha must be the merge commit, status must be
completed and conclusion must be success.
failure/cancelled: open the log (gh run view <id> --log-failed),
tell the user, and re-run only after you know why (gh run rerun <id>).
A re-run keeps the same run id; check attempt
(gh run view <id> --json attempt) when you watch for it.
- No run for the merge commit after a few minutes: there is nothing to re-run.
Tell the user; check the branch's workflow trigger and the Actions page
before anyone deploys another way.
- Then do one quick in-app check of the fixed function, starting from the
app root.
Step 8 — Restore Stashed Work
git checkout <your-previous-branch>
git stash pop
Step 9 — Clean Up Old Branch (Post-Merge)
After the PR is merged:
git branch -d $1-hotfix
Step 9a — Check Whether `development` Needs the Same Fix
Do this for every hotfix, immediately after it merges. A hotfix branch and
development drift apart the moment they diverge; skipping this step is how
they end up meaningfully different a few hotfixes later, with confusing
stale-file conflicts on the next migration or cherry-pick.
- If the hotfix's commits were cherry-picked from commits that already exist
in development (the common case when porting an already-merged
development fix forward to a lagging production branch), there is nothing
to do — development already has it.
- If any commit was written directly on the hotfix branch (a fix invented
there, or a follow-up discovered while hotfixing, as opposed to a
cherry-pick), check whether development's copy of the same file(s)
already contains it:
```bash
git log origin/development --oneline --grep="<distinctive phrase from the commit message>"
```
If it's missing, branch off origin/development (a normal feature branch,
not -hotfix — the target here is development, not a production
branch), re-apply the same change, and open a separate PR targeting
development. Do not fold this into the hotfix PR itself; they target
different branches.
- Either way, say explicitly in the hotfix PR body (or in a follow-up
comment) whether development already had the fix or needed a mirror PR,
and link that PR if one was opened. This is what a reviewer or the next
developer checks instead of re-deriving branch drift from scratch.
Common Production Branches
Verify against git branch -r before trusting this table — branches get
added/renamed, and similarly-named branches are NOT interchangeable.
| Hospital/Environment | Branch | Notes |
|----------------------|--------|-------|
| COOP — pharmacy | coop-production | |
| COOP — inward | coop-staging | Despite the "staging" name, COOP inward users run against it day to day (production DB). |
| Ruhunu hospital | rh-production | rh-staging is live again (since 2026-10-28) and writes to the same production DB. |
| Southern Lanka | southernlanka-production | The only live app. southernlanka-staging is not used (app disabled, checked 2026-11-06); don't hotfix it. |
| RMH | rmh-production | rmh-staging is not used (app disabled, checked 2026-11-06); don't hotfix it. |
| Others | suwani-production, asiripharmacy-production, digasiri-production, horizon-production, mp-production, roseth-production, ewc-production | mpold-production is decommissioned and bms-production is disabled; don't hotfix either. |
The old *-prod, *-prod-migrated and *-stg-migrated branches were retired on
2026-10-11 (archived as archive/2026-10-11/<branch> tags). Never target them.
CI's -hotfix head check does not yet run for these new targets (#24453) — follow
the naming rule anyway.
Full map: Deployment map.
If a hospital has more than one candidate branch and it is not obvious which
one backs the environment the user means, ask which one before branching —
guessing from the branch name alone has caused a wrong-target hotfix PR
before (it had to be closed and redone against the correct branch).
Reference
From CLAUDE.md (moved detail)
sync .gitignore first (git checkout origin/development -- .gitignore); mirror every merged hotfix into development unless its commits were cherry-picked from development (Step 9a).