isStale on a signed agreement after content drift), automatically archive that agreement document and automatically create a new agreement for the same inspection + template in pending status with up-to-date merged content so it can be signed—without waiting for staff to use Recreate Outdated or manual archive.Agreement.isStale (with staleAt). status remains pending, viewed, signed, or declined in attik-backend/src/models/agreementSchema.ts; there is no separate outdated enum value—staleness is orthogonal to status.attik-backend/src/events/bullmq/agreementStaleWorker.ts compares regenerated content to signedContentHash (or legacy content hash) and sets isStale / staleAt on signed agreements when content would differ; it does not archive, does not enqueue a replacement pending row, and does not cancel comms by itself.attik-frontend/src/app/tools/inspections/[id]/components/Agreements.tsx exposes Recreate Outdated, which calls POST /agreement/manual (implemented in attik-backend/src/routes/agreements.ts) to add pending rows when a template has a signed + stale agreement and no non-stale row; archive is a separate PATCH action (handleSetArchived). The new bar is automatic archive + automatic recreate at the moment an agreement becomes outdated.rejectIfActiveAgreementExists in attik-backend/src/routes/agreements.ts treats active as not archived, not stale, not declined—stale rows already do not block a new instance, but unarchived stale signed rows may still interact with reminder and portal list behavior until archived and superseded.inspection.agreement.present and inspection.agreement.signed are recomputed from active Agreement documents when rows change (attik-backend/src/events/streamHandlers/agreementStream.ts with agreementLockStateFromDbLean in attik-backend/src/util/functions/agreements/agreementLockSync.ts). Flow conditions use agreement-signed and agreement-present via attik-backend/src/util/functions/actionFlows/attributePathResolver.ts; handleEventTriggerdByBull drives scheduled email and sms.attik-backend/src/util/functions/agreements/autoGenerateAgreements.ts creates missing template agreements and regenerates unsigned content when charges change; it does not implement delete-on-service-removal or the new archive + replace on stale behavior—decision needed for interaction with charge streams.agreementStaleWorker (attik-backend/src/events/bullmq/agreementStaleWorker.ts) so that when a signed agreement first becomes isStale, the system can archive that document (today PATCH allows archived only for signed rows—see attik-backend/src/routes/agreements.ts PATCH /:id) and then create a pending replacement equivalent to POST /agreement/manual (template merge via mergeAgreementBlocksToContent, InspectionFullPopulatedForFlow, hashContent—same route file).pending per template per transition and safe behavior if staff or other jobs also mutate rows—decision needed (compare to existing rejectIfActiveAgreementExists and queue dedup in queueAgreementStaleCheck).handleEventTriggerdByBull and time-based steps so archived + superseded rows no longer satisfy unsigned signing nudges; relate to inspectionStream / chargeStream callers of queueAgreementStaleCheck.attik-backend/src/util/functions/activity/agreementHandlers.ts logs isStale changes—consider whether automated archive/create should emit clearer audit trails.Agreements.tsx — staleAgreementsNeedingRecreation, handleRecreateOutdated, handleSetArchived may become partially redundant or need copy/UX updates if the server always performs the two steps.templateIdsBlockedByActiveAgreements (attik-frontend/src/util/agreements/templateIdsBlockedByActiveAgreements.ts) must stay consistent with backend active definition if automation changes timing of stale vs archived.AgreementsNeeded.tsx and portal lists — confirm tasks and client surfaces match single active signing obligation per template after automation.isStale is cleared (worker unmarks stale if content matches again)—whether to leave archived history vs other product rules.attik-backend/src/models/agreementSchema.tsattik-backend/src/routes/agreements.ts — rejectIfActiveAgreementExists, POST /manual, PATCH /:id (archive rules)attik-backend/src/events/bullmq/agreementStaleWorker.tsattik-backend/src/events/streamHandlers/agreementStream.tsattik-backend/src/util/functions/agreements/agreementLockSync.tsattik-backend/src/util/functions/actionFlows/attributePathResolver.tsattik-backend/src/util/functions/actionFlows/handleEventTriggerdByBull.tsattik-backend/src/util/functions/agreements/autoGenerateAgreements.tsattik-frontend/src/app/tools/inspections/[id]/components/Agreements.tsxattik-frontend/src/components/task-check/AgreementsNeeded.tsxPlease authenticate to join the conversation.
Completed
Main App
About 1 month ago
Linear
Get notified by email when there are changes.
Completed
Main App
About 1 month ago
Linear
Get notified by email when there are changes.