docs(kiloclaw): add data model spec for instances and subscriptions - #2461
Conversation
| transaction as the mutation, a change log failure that aborts | ||
| the transaction is acceptable — the entire operation will be | ||
| retried. When no enclosing transaction exists, a change log | ||
| failure MUST NOT prevent the mutation from succeeding; the |
There was a problem hiding this comment.
WARNING: This exception breaks the audit-trail invariant
Earlier rules say every subscription mutation MUST have a change log entry and that the log is the authoritative history. Allowing the mutation to succeed when the log write fails means the system can permanently miss entries unless the spec also requires retry or reconciliation semantics.
There was a problem hiding this comment.
Valid concern. Rule 15 now requires retry or reconciliation for out-of-transaction change log failures, with a bounded-time SLA for backfilling missing entries. The mutation still proceeds (availability over consistency for the business operation), but the audit trail gap must be closed within a defined window — not silently dropped.
| 21. The kiloclaw CF worker service MUST be the sole creator of | ||
| `kiloclaw_instance` records. No other service or application | ||
| MAY insert rows into this table. | ||
| 22. After the instance record has been committed to the database, |
There was a problem hiding this comment.
WARNING: This creation order conflicts with rule 4
Rule 4 says an instance record MUST NOT exist without a subscription record, but this sequence commits the instance row before the billing service creates the subscription row. Unless both records are created atomically, the database temporarily contains the orphaned state that the spec says must never exist.
There was a problem hiding this comment.
Valid catch. Two changes address this:
- Rule 4 now explicitly states the invariant is eventually-consistent — a bounded creation window exists between instance INSERT and subscription INSERT during provisioning.
- Rule 22 now requires subscription creation within the same provisioning request (bounding the window) and mandates retry or remediation marking on failure, so orphaned instances cannot be silently ignored.
Code Review SummaryStatus: 1 Issues Found | Recommendation: Address before merge Overview
Issue Details (click to expand)WARNING
Other Observations (not in diff)None. Files Reviewed (2 files)
Reviewed by gpt-5.4-2026-03-05 · 405,807 tokens |
…rify creation window
pandemicsyn
left a comment
There was a problem hiding this comment.
couple of changes inline just because the NF still will be landing in the next day or two.
Co-authored-by: Florian Hines <syn@neonronin.sh>
| The creation order below reflects the target lifecycle. This order | ||
| MUST be enforced only after the existing data model has been brought | ||
| into the desired state (rules 1–6 satisfied, early-bird backfill | ||
| complete). |
There was a problem hiding this comment.
WARNING: Rule 19 becomes impossible for providers without a base resource
The new Infra Provider Base Resource definition says only some providers have this top-level resource, but rule 19 now requires one for every instance before the row can exist. That makes the precondition unsatisfiable for providers that do not expose a base resource and turns a provider-specific concept into a universal invariant.
There was a problem hiding this comment.
This is an acceptable gap/risk for now which will be handled at the provider integration layer.
Note
This is the first in a series of PRs that will work to satisfy the data model contract this spec introduces. The spec is therefore forward-looking and does not reflect the state of the codebase at this moment.
Summary
Adds a business-rule spec for the KiloClaw data model — the
kiloclaw_instanceandkiloclaw_subscriptiontables and the invariants all consumers must follow.Why this change is needed
Multiple services (web app, kiloclaw CF worker, kiloclaw-billing, background jobs) operate on instances and subscriptions without a single source of truth for the rules governing record existence, immutability, lookup patterns, and creation order. This leads to ambiguity about what the system must guarantee and makes it harder to evaluate changes for correctness.
How this is addressed
.specs/kiloclaw-datamodel.mdcovering record immutability (including GDPR anonymization), the instance–subscription pairing invariant, early-bird backfill requirements, multi-instance support with per-context limits, primary-key-based lookup rules, a subscription change log spec with actor tracking and transaction semantics, and the target record creation order with partial-failure handling.Human Verification
Visual Changes
N/A
Reviewer Notes
Human Reviewer
.specs/. Review the business rules (especially rules 4–6 on instance–subscription pairing and the early-bird exception, rules 12–18 on the subscription change log, and rules 19–23 on creation order) for accuracy against current system behavior and intended direction.Code Reviewer Agent
Code Reviewer Notes