Skip to content

docs(kiloclaw): add data model spec for instances and subscriptions - #2461

Merged
jeanduplessis merged 5 commits into
mainfrom
docs/kiloclaw-datamodel-spec
Apr 15, 2026
Merged

docs(kiloclaw): add data model spec for instances and subscriptions#2461
jeanduplessis merged 5 commits into
mainfrom
docs/kiloclaw-datamodel-spec

Conversation

@jeanduplessis

@jeanduplessis jeanduplessis commented Apr 15, 2026

Copy link
Copy Markdown
Contributor

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_instance and kiloclaw_subscription tables 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

  • Introduces .specs/kiloclaw-datamodel.md covering 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.
  • Documents the migration path from current state to target invariants and lists items not yet implemented.
  • Adds the new spec to the AGENTS.md specs table so contributors know to consult it.

Human Verification

  • Manual review of spec rules.

Visual Changes

N/A

Reviewer Notes

Human Reviewer

  • Spec introduction — This is a new spec in .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.
  • Assumptions — The spec assumes early-bird backfill will be completed before enforcing creation-order rules. The "Not Yet Implemented" section calls out three areas where current behavior diverges from the spec's SHOULD-level guidance.

Code Reviewer Agent

Code Reviewer Notes
  • Documentation-only change — no code modified.
  • Spec uses RFC 2119 / RFC 8174 keywords (MUST, SHOULD, MAY) to distinguish hard invariants from aspirational rules.
  • The "Not Yet Implemented" section explicitly marks three items as not enforced in the current codebase.
  • AGENTS.md updated to register the new spec in the specs table.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Valid catch. Two changes address this:

  1. Rule 4 now explicitly states the invariant is eventually-consistent — a bounded creation window exists between instance INSERT and subscription INSERT during provisioning.
  2. 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.

@kilo-code-bot

kilo-code-bot Bot commented Apr 15, 2026

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: 1 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 1
SUGGESTION 0
Issue Details (click to expand)

WARNING

File Line Issue
.specs/kiloclaw-datamodel.md 225 Rule 19 still requires an infra-provider base resource for every instance, but the definition says only some providers have one.

Fix these issues in Kilo Cloud

Other Observations (not in diff)

None.

Files Reviewed (2 files)
  • .specs/kiloclaw-datamodel.md - 1 issue
  • AGENTS.md

Reviewed by gpt-5.4-2026-03-05 · 405,807 tokens

@pandemicsyn pandemicsyn left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

couple of changes inline just because the NF still will be landing in the next day or two.

Comment thread .specs/kiloclaw-datamodel.md
Comment thread .specs/kiloclaw-datamodel.md Outdated
Comment thread .specs/kiloclaw-datamodel.md Outdated
Comment thread .specs/kiloclaw-datamodel.md
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).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@jeanduplessis jeanduplessis Apr 15, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an acceptable gap/risk for now which will be handled at the provider integration layer.

@jeanduplessis
jeanduplessis merged commit 851b7d9 into main Apr 15, 2026
15 checks passed
@jeanduplessis
jeanduplessis deleted the docs/kiloclaw-datamodel-spec branch April 15, 2026 17:26
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.

2 participants