deploy: frontend rollback, stale-vector regen, single-source phrases - #22
deploy: frontend rollback, stale-vector regen, single-source phrases#22Ocean82 wants to merge 1 commit into
Conversation
…-source phrases - deploy.sh: extract mirror_frontend(); rebuild+remirror frontend from PREV_COMMIT on health-check rollback so the live SPA matches the API. - intent-vectors.bin format v2: embed FNV-1a hash of the phrase set. Client rejects a binary whose hash no longer matches (falls back to runtime bootstrap); precompute self-skips when current, regenerates when stale. - deploy.sh always runs model:precompute when the model is present (was gated on file absence, which shipped stale vectors after a phrase edit). - Eliminate INTENT_PHRASES duplication: single source in shared/intentPhrases.js imported by both intentEmbeddings.ts and precompute-embeddings.mjs. - Update intentVectorsBin.test.ts to v2 format; add stale-hash and parity tests.
Reviewer's GuideHardens deployment consistency by restoring the frontend alongside a rolled-back server, and hardens intent-vector artifacts with a shared phrase source, hash-validated v2 format, automatic stale regeneration, and comprehensive format tests. Sequence diagram for deploy health-check rollbacksequenceDiagram
participant Deploy as deploy.sh
participant Git
participant Server
participant Frontend
Deploy->>Frontend: mirror_frontend()
Deploy->>Server: pm2 restart PM2_PROCESS
Deploy->>Server: health check
alt health check passes
Deploy-->>Deploy: deployment completes
else health check fails
Deploy->>Git: git reset --hard PREV_COMMIT
Deploy->>Server: npm ci
Deploy->>Server: npm run build
Deploy->>Server: pm2 restart PM2_PROCESS
opt FRONTEND_MIRRORED = true
Deploy->>Frontend: mirror_frontend()
end
Deploy-->>Deploy: die with rollback status
end
Sequence diagram for stale intent-vector regenerationsequenceDiagram
participant Deploy as deploy.sh
participant Precompute as model:precompute
participant Binary as intent-vectors.bin
participant Model as ONNX model
Deploy->>Precompute: run_model_step npm run model:precompute
Precompute->>Binary: read 16-byte v2 header
alt version 2 and hash matches
Precompute-->>Deploy: skip regeneration
else missing, v1, or stale hash
Precompute->>Model: load ONNX model
Model-->>Precompute: embeddings
Precompute->>Binary: write v2 header with phrasesHash and vectors
Precompute-->>Deploy: regenerated artifact
end
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: Comment |
There was a problem hiding this comment.
Hey - I've reviewed your changes and they look great!
Sourcery assessment
Needs a human reviewer. If the new deployment or rollback flow is wrong, it can leave a frontend/API version mismatch or cause a production outage, and the failed deployment may already have affected users before the script is reverted. Reverting the code restores the old behavior for future deploys, but it cannot undo an outage or inconsistent assets already served.
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Hardens the deploy pipeline. Three fixes plus verification.
1. Frontend rollback on failed health check
Previously a failed health check rolled back only the server (PM2), leaving the newly-mirrored frontend live against the old API. Extracted the build/mirror into
mirror_frontend()and reused it in the rollback path so the SPA is rebuilt fromPREV_COMMITto match the rolled-back server. Also added the rootnpm cithe frontend rebuild needs. The frontend restore is non-fatal (loud WARN on failure) so it can't block the server rollback.2. Stale intent-vectors.bin regeneration (binary format v2)
The precompute step only ran when the file was absent, so editing intent phrases shipped stale vectors. Now:
shared/intentPhrases.jscomputes an FNV-1a hash of the phrase set.deploy.shalways runsmodel:precomputewhen the model is present; the script self-skips cheaply (header read, before ONNX load) when current.3. Phrase-list drift (root-cause fix)
INTENT_PHRASESwas duplicated acrossintentEmbeddings.tsandprecompute-embeddings.mjs. Extracted to a singleshared/intentPhrases.jsimported by both, so drift is structurally impossible.Verification
tsc --noEmit: passes (addedshared/intentPhrases.d.tsfor types)vitest run src/ai/nlp: 145/145 pass, incl. rewritten v2 round-trip + stale-hash + parity testsnode --checkon new JS: cleanbash -n scripts/deploy.sh: cleanDeploy note
The v2 bump means the first server deploy after merge regenerates
intent-vectors.bin(existing v1 file is rejected). Until then the client falls back to the slower runtime bootstrap � safe degradation, not a breakage.Summary by Sourcery
Harden deployment rollback and intent-vector freshness while establishing a single source of truth for intent phrases.
Bug Fixes:
Enhancements:
Deployment:
Tests: