Skip to content

fix(fleet): a closed fleet case keeps what it has but stops growing (#86) - #101

Draft
Jihair54 wants to merge 1 commit into
mainfrom
fix/86-closed-fleet-case-stops-growing
Draft

Jihair54 wants to merge 1 commit into
mainfrom
fix/86-closed-fleet-case-stops-growing

Conversation

@Jihair54

@Jihair54 Jihair54 commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #86. Draft until @SoFrexs is fine with the design in #86 (comment), chiefly the entity key change below; I'll rework it if not.

What changes. A fleet case whose status is outside ACTIVE_CASE_STATUSES (#84), that is resolved or false_positive, keeps its detections, entities and status, and stops growing. In lib/fleet-case-store.ts:

  • upsertGroup only looks up entities of active cases. A group whose entities only closed cases hold opens a new case, and a closed case is never a merge target or source.
  • withoutJudged drops detections already on a closed case before joinDetections. They are never moved into the new case, and they do not count toward the two agents a group needs.
  • The detection link checks the status again when it writes, because the console's status write (Console: case triage workflow + tamper-evident audit log #12) will not take the cron's advisory lock.
  • The merge is now mergeInto. It copies entities instead of re-pointing them, so two active cases that list one entity (a reopened case, later) merge without a key clash.

Schema. FleetCaseEntity goes from @@unique([tenantId, kind, key]) to @@unique([fleetCaseId, kind, key]), plus @@index([tenantId, kind, key]) for the lookup. The @@index([fleetCaseId]) is dropped, since the new unique key leads with it. The new case can then list an entity that its closed predecessor keeps, and the console still shows the closed case's entities (fleet-case-load.ts). "One active case per entity and tenant" is now held by the cron under its per-tenant lock. db push applies this without data loss, because every existing row stays unique under the new key, which is looser than the old one.

Tests (tests/integration/join-fleet-cases-cron.test.ts, "a closed fleet case (#86)"). The status is set on the row, since nothing writes FleetCase.status yet:

  • for resolved and for false_positive: a later sighting opens a new case standing on the new detections alone (their severity, their two agents). The closed case is byte-for-byte unchanged, and a second run changes nothing;
  • a judged detection does not count toward the two agents: one new agent alone opens nothing;
  • a bridge between an active case and a closed one leaves the closed one alone;
  • an investigating case still grows.

Tested

  • Locally against PostgreSQL 15 (docker-compose.test.yml):
    • join-fleet-cases-cron and fleet-cases-console pass: 23 and 9 tests.
    • With main's lib/fleet-case-store.ts and these tests, 4 of the 5 new tests fail. The one that still passes is "an investigating case still grows", which guards behavior that must not change.
    • The full integration suite: 494 passed and 6 skipped. The one failure, cases-detail "does not mark the narrative stale when no detection changed after generation", is flaky on main as well: it failed 1 run out of 3 with main's code, and 2 out of 3 on this branch. It does not touch fleet cases.
  • tsc --noEmit is clean after prisma generate.
  • eslint: only the max-lines-per-function warning on upsertGroup. It is already there on main, and this PR takes it from 72 to 76 lines.
  • Fleet unit tests: 81 passed.
  • CI is green: server, which includes the integration suite, the cross-OS unit jobs and dco.

🤖 Generated with Claude Code

)

join-fleet-cases attached a new detection to whichever fleet case
already held one of its entities, whatever that case's status, and a
merge kept the oldest case's status. Once #12 lets an analyst close a
fleet case, a false_positive verdict would carry onto every later
detection sharing an entity, and a resolved case would grow silently.

Closed means a status outside ACTIVE_CASE_STATUSES (#84):
- the entity lookup only matches active cases, so a group whose
  entities only closed cases hold opens a new case;
- detections already on a closed case are left out of the join: never
  moved, and not counted toward the two agents a group needs;
- a closed case is never a merge target or source. The detection link
  re-checks the status at write time, since the console's status write
  does not take the cron's lock.

FleetCaseEntity becomes unique per (fleetCaseId, kind, key), with an
index on (tenantId, kind, key) for the lookup, so the new case can list
an entity its closed predecessor keeps. "One active case per entity" is
held by the cron under its per-tenant advisory lock. A merge copies
entities instead of re-pointing them, so two active cases listing one
entity (a reopened case, later) merge without a key clash.

Fixes #86

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Jihair54 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fleet case join attaches new detections to a closed fleet case, carrying its verdict

1 participant