Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
6e93d97
docs: RFC for application status model and migration (#108)
claude Nov 30, 2026
1a909a4
feat(applications): add stage/outcome/waitingOn columns alongside leg…
claude Nov 30, 2026
6b28269
feat(applications): map legacy status values to stage/outcome/waitingOn
claude Nov 30, 2026
dfa9717
fix(scheduler): stop overwriting closed, archived and draft applications
claude Nov 30, 2026
ffa7c05
feat(applications): backfill stage/outcome from legacy status on startup
claude Nov 30, 2026
f74901d
feat(applications): dual-write stage/outcome on status changes and ex…
claude Nov 30, 2026
5669561
docs(mcp): give each status a meaning and one rule for RH; fix Swagge…
claude Nov 30, 2026
f335e02
docs: phase 1 implementation plan for the status model (#108)
claude Nov 30, 2026
3825de0
Merge remote-tracking branch 'origin/main' into hugo/intelligent-wozn…
claude Nov 30, 2026
878795a
fix: keep ApplicationStatus enum, now used by assistant status aliase…
claude Nov 30, 2026
8d1d254
docs: design for the stage/outcome cutover (#108)
claude Dec 1, 2026
fddbb20
docs: backend and frontend plans for the stage/outcome cutover (#108)
claude Dec 1, 2026
66403c8
refactor(status): best-effort legacy conversion, drop NEEDS_REVIEW
claude Dec 1, 2026
046e4ab
feat(applications): resolve stage on every write; legacy records need…
claude Dec 1, 2026
234f2da
feat(applications): calculated ghosting replaces the nightly Ghosting…
claude Dec 1, 2026
d112e1c
feat(applications): dashboard, interview metrics and gamification rea…
claude Dec 1, 2026
590805e
feat(applications): filters, search and export use stage/outcome; leg…
claude Dec 1, 2026
ade9911
test: model drafts with the draft stage in the reminder IT
claude Dec 1, 2026
b60daab
feat(assistant): queries and aggregations use the stage/outcome phase…
claude Dec 1, 2026
a2398f9
feat(mcp): stage catalog, Update-Application-Stage and stage-aware to…
claude Dec 1, 2026
1c9c299
chore(dev): fake data seeder writes the stage model
claude Dec 1, 2026
dbbe033
fix(applications): echoed legacy status never reopens or regresses a …
claude Dec 1, 2026
6ecb411
test: clean webauthn challenges before deleting users in ApplicationC…
claude Dec 1, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 120 additions & 0 deletions docs/superpowers/plans/2026-11-30-application-status-model-phase1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
# Application Status Model — Phase 1 Implementation Plan

> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.

**Goal:** Stop the nightly scheduler from corrupting outcomes, add the approved stage/outcome/waitingOn model alongside the legacy `status` (expand + dual-write), and migrate every record whose mapping is deterministic, flagging the rest `NEEDS_REVIEW`.

**Architecture:** Legacy `status` stays the write contract (API, MCP, frontend unchanged). A pure `LegacyStatusMapper` derives `stage`/`outcome`/`waitingOn`/`statusMigration` from the legacy fields; `ApplicationService` and the scheduler call it on every status change (dual-write), and a startup backfill runs it once over rows not yet mapped. One rule set, unit-tested, no SQL duplicate.

**Tech Stack:** Spring Boot 4, JPA/Hibernate, Flyway (PostgreSQL only — `db/migration/postgresql`), JUnit 5 + Mockito.

**Spec:** `docs/superpowers/specs/2026-11-30-application-status-model-rfc.md`

## Global Constraints

- Never overwrite or delete `status`, `previous_status`, interview fields or `archived` during migration; `legacy_status` is an exact copy of `status`.
- Never invent dates, activities, `waiting_since` or an outcome that the legacy data does not state.
- Ambiguous legacy values map to `statusMigration = NEEDS_REVIEW` with `stage`/`outcome`/`waitingOn` null.
- Stable keys: stages `DRAFT, APPLIED, RECRUITER_SCREEN, HIRING_MANAGER, ASSESSMENT, INTERVIEW, OFFER`; outcomes `HIRED, REJECTED, ROLE_CANCELLED, WITHDREW`; waitingOn `COMPANY, CANDIDATE`; migration `MAPPED, NEEDS_REVIEW`.
- Flyway migrations go only in `src/main/resources/db/migration/postgresql/` (prod/dev locations); next version is `V40`.

## Review Focus

- Case/whitespace variants of legacy values (`rejected`, ` RH `) — expected to map like the canonical value. Test in Task 2.
- `Ghosting` whose `previous_status` is itself `Ghosting` or unknown text — expected `NEEDS_REVIEW`, no loop. Test in Task 2.
- Archived rows older than a month — expected untouched by the scheduler. Test in Task 3.
- Backfill rerun on restart — expected zero writes the second time. Test in Task 4.
- API clients that ignore the new response fields — expected no breaking change (fields are additive, `NON_NULL`). Covered by Task 5 mapper test.

---

### Task 1: Model enums + schema expand

**Files:**
- Create: `src/main/java/com/jobtracker/entity/enums/ApplicationStage.java`, `ApplicationOutcome.java`, `WaitingOn.java`, `StatusMigrationState.java`
- Create: `src/main/resources/db/migration/postgresql/V40__add_application_stage_outcome.sql`
- Modify: `src/main/java/com/jobtracker/entity/JobApplication.java` (fields + getters/setters)
- Keep: `entity/enums/ApplicationStatus.java` — since #119 the assistant query repository uses it for status aliases.

**Interfaces — Produces:** `JobApplication#get/setStage(ApplicationStage)`, `get/setOutcome(ApplicationOutcome)`, `get/setWaitingOn(WaitingOn)`, `get/setLegacyStatus(String)`, `get/setStatusMigration(StatusMigrationState)`; all `@Enumerated(STRING)`, nullable.

- [ ] Migration adds nullable `stage VARCHAR(32)`, `outcome VARCHAR(32)`, `waiting_on VARCHAR(16)`, `legacy_status VARCHAR(100)`, `status_migration VARCHAR(16)` plus `CREATE INDEX idx_app_status_migration ON job_applications (status_migration)`. No data changes in SQL.
- [ ] `mvn -q -DskipTests compile` passes. Commit.

### Task 2: `LegacyStatusMapper`

**Files:** Create `src/main/java/com/jobtracker/service/status/LegacyStatusMapper.java`, `StatusMapping.java`; Test `src/test/java/com/jobtracker/unit/status/LegacyStatusMapperTest.java`

**Interfaces — Produces:**
- `record StatusMapping(ApplicationStage stage, ApplicationOutcome outcome, WaitingOn waitingOn, StatusMigrationState state, String rule)`
- `static StatusMapping LegacyStatusMapper.map(String status, String previousStatus, boolean toSendLater, LocalDate applicationDate)`
- `static void LegacyStatusMapper.apply(JobApplication app)` — sets the five new fields (`legacyStatus = status`).

Rules (lookup by trimmed, case-insensitive value; aliases = V29 label, enum display name, enum constant name):

| Legacy | Result |
|---|---|
| null + `toSendLater` + no date | `DRAFT` MAPPED |
| null otherwise | NEEDS_REVIEW |
| `RH` with date | `APPLIED` |
| `RH` without date | NEEDS_REVIEW |
| `Pending HR Response`, `RH (Negociação)`/`RH_NEGOCIACAO`, `Tarde demais`/`TARDE_DEMAIS`, `Approved`, unknown | NEEDS_REVIEW |
| `Pending Hiring Manager Response`, `FIZ_A_HIRING_MANAGER_AGUARDANDO_ATUALIZACAO` + label | `HIRING_MANAGER` + `COMPANY` |
| `FIZ_A_RH_AGUARDANDO_ATUALIZACAO` + label | `RECRUITER_SCREEN` + `COMPANY` |
| `Technical Test`, `TESTE_TECNICO`, `Teste Técnico` | `ASSESSMENT` |
| `Pending Technical Test Response`, `FIZ_TESTE_TECNICO_AGUARDANDO_ATUALIZACAO` + label | `ASSESSMENT` + `COMPANY` |
| `ENTREVISTA_MARCADA`, `Entrevista marcada` | `INTERVIEW` |
| `Offer Negotiation` | `OFFER` |
| Rejected family (`Rejected`, `REJEITADO`, `Rejeitado`), no date, no previous | `DRAFT` (scheduler-expired draft signature; API forbids status without date) |
| Rejected family, previous maps to a non-terminal stage | that stage + `REJECTED` |
| Rejected family otherwise (has date) | `APPLIED` + `REJECTED` (last stage proven by the date) |
| Ghosting family, previous in Rejected family, has date | `APPLIED` + `REJECTED` |
| Ghosting family, previous maps to a non-terminal MAPPED stage | that stage + `COMPANY`, no outcome |
| Ghosting family otherwise | NEEDS_REVIEW |

- [ ] Write parameterized tests covering every row above plus the Review Focus cases (`" rejected "`, Ghosting→Ghosting). Run `mvn -q test -Dtest=LegacyStatusMapperTest` → FAIL (class missing).
- [ ] Implement; rerun → PASS. Commit.

### Task 3: Scheduler hotfix + dual-write there

**Files:** Modify `tasks/StaleApplicationsScheduler.java`, `repository/ApplicationRepository.java`; Test `unit/StaleApplicationsSchedulerTest.java`

**Interfaces — Consumes:** `LegacyStatusMapper.apply`.
**Produces:** `ApplicationRepository#findStaleActiveApplications(Collection<String> excludedStatuses, LocalDateTime updatedBefore)` — JPQL: `status IS NOT NULL AND status NOT IN :excluded AND archived = false AND updatedAt < :before`.

- [ ] Tests: drafts older than a week are not touched (`findByStatusIsNullAndUpdatedAtBefore` never called); terminal set passed to the query contains every Rejected/Ghosting/Approved/Tarde demais alias; a stale `Technical Test` becomes `Ghosting` with `previousStatus=Technical Test`, `stage=ASSESSMENT`, `waitingOn=COMPANY`.
- [ ] Remove the draft→Rejected branch; replace the ghosting query; call `LegacyStatusMapper.apply` after setting `Ghosting`. Drop the now-unused repository methods. Tests PASS. Commit.

### Task 4: Startup backfill

**Files:** Create `service/status/LegacyStatusBackfill.java`; Modify `ApplicationRepository` (`findTop500ByStatusMigrationIsNull()` + `countByStatusMigrationIsNull()`); Test `unit/status/LegacyStatusBackfillTest.java`

- [ ] `@EventListener(ApplicationReadyEvent.class) @Transactional public int run()` loops batches of 500 from `findTop500ByStatusMigrationIsNull`, applies the mapper, `saveAll`, logs counts per state; returns rows migrated. Rows are selected by `status_migration IS NULL`, so a second run writes nothing. Must not change `updatedAt` semantics for ghosting: set `updatedAt` back to its previous value before save is not possible with `@PreUpdate`, so use a bulk JPQL `UPDATE` per row instead of entity save (`ApplicationRepository#applyStatusMapping(UUID id, stage, outcome, waitingOn, legacyStatus, migration)` with `@Modifying`), leaving `updated_at` untouched.
- [ ] Tests: two batches then empty → returns total and calls `applyStatusMapping` once per row; second invocation with empty page writes nothing. PASS. Commit.

### Task 5: Dual-write in `ApplicationService` + API exposure

**Files:** Modify `service/ApplicationService.java` (`applyStatusChange` end → `LegacyStatusMapper.apply(app)`; also after `mapRequestToEntity`/patch date changes since `RH` depends on the date), `dto/application/ApplicationResponse.java` (append `String stage, String outcome, String waitingOn, String statusMigration`), `mapper/ApplicationMapper.java`, positional constructors in `ApplicationServiceTest`, `McpAnalyticsToolsTest`, `McpApplicationToolsTest`.

- [ ] Tests in `ApplicationServiceTest`: create with `RH` + date → entity `stage=APPLIED`, `statusMigration=MAPPED`, `legacyStatus=RH`; updateStatus to `Rejected` from `Technical Test` → `stage=ASSESSMENT`, `outcome=REJECTED`; patch status null → `DRAFT`.
- [ ] Implement; `mvn -q test -Dtest='ApplicationServiceTest,Mcp*Test'` PASS. Commit.

### Task 6: Contract hygiene (MCP + Swagger)

**Files:** `dto/application/ApplicationRequest.java`, `UpdateStatusRequest.java` (allowableValues = the nine V29 names + `TO_SEND_LATER`), `mcp/McpPromptsConfig.java`, `mcp/resources/McpApplicationCreationRulesResource.java`, `mcp/resources/McpApplicationStatusesResource.java` (bump `LAST_MODIFIED`, add one-line meaning per status).

Single rule everywhere: *`RH` = application sent (manual or automatic), no human recruiter contact implied. Omit status only for drafts not yet sent. Never use `Pending HR Response` unless a human recruiter actually replied.*

- [ ] Update tests asserting these strings (`McpApplicationCreationRulesResourceTest`, `McpPromptsConfigTest`); PASS. Commit.

### Task 7: n8n workflow `Candidaturas enviadas → Applywell`

- [ ] Replace "call List-Statuses once and use a valid status from its result" with: `status` must be exactly `"RH"`; remove `List-Statuses` from the tool list. Validate, publish, re-read to confirm.

### Task 8: Verification

- [ ] `mvn -B -ntp verify` locally for unit tests (integration tests need Docker → CI). Push, watch CI.

## Out of scope (needs brainstorm)

Frontend consumption of `stage`/`outcome`, a `NEEDS_REVIEW` review UI, new MCP tools (`Set-Application-Stage`, `Close-Application`), metrics/dashboard/gamification on the new model, activities table, computed ghosting indicator, contract phase.
Loading
Loading