Skip to Content
Recodocs

Empty rows stay empty until an owner writes them

GET /v1/records returns each stored row's id and created_at. The model call returns a Decision, and assess rejects a policy_id or approval_id that is not a retrieved node of the required kind.

8 min read

An application can have a functioning record API without an AI agent. That distinction matters when assessing evidence: a deterministic list response demonstrates a data contract, not model reasoning.

A caller sends GET /v1/records. list_records opens a session, selects every Record ordered by created_at, and returns items from id and created_at. With no rows the body is {"items": []}. create_app builds that route through install_runtime and never constructs a model client. The question "What warranty term applies to case SC-882, and why?" belongs to scripts/context-graph-fundamentals.py: one structured call, then assess. The roadmap asks for a hand-curated synthetic corpus; this API does not load one. The warranty texts are the script's own fictional snapshot.

The claim is that this demo is a workflow plus one checked selection: the API may list only rows a governed owner stored, and assess rejects a policy_id or approval_id that retrieve did not keep with the required kind.

The argument

  1. The API has no model loop. create_app registers one handler, GET /records, on the records capability. That process does not choose a tool.
  2. The file and the caller are fixed before the query. COMPANY_INTELLIGENCE_DB_PATH must name a SQLite file. When COMPANY_INTELLIGENCE_SESSION_TOKEN is set, every /v1/* route requires a bearer, compared in constant time. GET /health does not.
  3. An empty list is the honest body. Record is one governed row, empty until a later owner records facts. The route does not seed a company.
  4. The model returns a Decision; assess admits it. ask_ai calls generate_structured once and returns that Decision. assess rejects a policy_id or approval_id that is not a retrieved node of the required kind, then checks citations and computes the dates. One checked call is not an agent loop.

Who is allowed to decide

The records route does not insert a row, and the model must not invent a row that does not exist. A route that was never registered cannot insert one, and a constructor that raises before the app exists cannot be reached by a later request. Those two stops belong to the API. The third stop, assess, belongs to the warranty script and never mounts on the router.

What crosses the records APIA caller sends GET /v1/records into a dashed API process. Inside, in order, are require_db_path, install_runtime, list_records, and a SQLite read of company_intelligence_record. A missing database path, an in-memory path, or a failed bearer check stops on the left. ask_ai and assess sit outside the process.CallerGET /v1/recordsTestClient, no body.Token unset in test.Refusedno DB path:memory: raises.401 if token fails.no items body.The APIcreate_apprequire_db_pathfile, or raiseinstall_runtimebearer on /v1list_recordsid, created_atsession_scopeSQLite readOutside the APIask_aione Decisionassesschecks ids, then datesseparate scriptRecordscompany_intelligence_recordid, created_atempty until an owner writesGETitemsselectrows
The records GET stays inside create_app. ask_ai is a separate script.

The dashed box is labeled The API, and the inner card is titled create_app. RuntimeSettings.load resolves the file through require_db_path, whose contract is to return the SQLite file the caller named and never invent a fallback. An empty value fails because COMPANY_INTELLIGENCE_DB_PATH is required. The string :memory: fails because the setting must name a SQLite file. A relative path resolves against the project root, not the working directory. Make's line COMPANY_INTELLIGENCE_DB_PATH ?= data/company_intelligence.db is a default for Make targets.

Inside the box the order is fixed. install_runtime receives one CapabilityModule, named records, wrapping a router whose only route is GET /records. list_records runs select(Record).order_by(Record.created_at) inside session_scope and maps each row to id plus created_at.isoformat(). The table is company_intelligence_record. The arrow back to the caller is items. The README states that the engine runs WAL with foreign keys ON and a 5 s busy timeout, and that writes use Database.write_session with BEGIN IMMEDIATE. The router never calls that method. The migration note says the product has no write route.

The orange card is titled Refused and lists a missing DB path, :memory:, a failed bearer, and "no items body." test_create_app_requires_db_path deletes COMPANY_INTELLIGENCE_DB_PATH and expects a RuntimeError matching COMPANY_INTELLIGENCE_DB_PATH is required. test_capabilities_require_bearer_when_token_set sets COMPANY_INTELLIGENCE_SESSION_TOKEN to secret-token. GET /v1/capabilities with no header expects 401 and {"detail": {"code": "unauthorized"}}. The same call with Authorization: Bearer secret-token expects 200 and capabilities equal to ["records"]. GET /health stays off that gate: the README returns {status, runtime, session_id, runtime_generation} without authentication, and RuntimeSettings.load uses runtime_mode or the string local.

The upper-right card lists ask_ai and assess; only ask_ai calls the model, and assess checks the returned ids. It does not choose a tool. ask_ai calls generate_structured once, with max_validation_retries=0, default model gpt-5.6-luna, reasoning_effort low, and max_output_tokens 2000. Instructions set policy_id null when evidence is missing or irreconcilable, set approval_id null when no verified approval applies, and leave expiry dates to Python. assess reads months from the named nodes and raises when the id is absent or the wrong kind, when a citation is missing or unknown, when an approval is not verified, or when an approval has no base policy. A null policy_id stays NEEDS_REVIEW; when a policy is set, status becomes WITHIN_TERM if start <= as_of < end, otherwise OUTSIDE_TERM. The README calls that one model call checked by trusted code, not an agent loop. The migration note says no component runs a model-driven decision loop.

test_version_prefix_is_not_hardcoded_in_route_modules fails if a handler path starts with /v. The message names the owner: versioned route prefixes belong to recohut_kit.runtime.install_runtime. The records path in this package is the string /records. test_capability_responses_are_derived_from_router_registries fails if a source dict sets the key capabilities to a list literal. The client list is that registry.

What the evidence shows

tests/test_health.py fixes the empty body, the bearer, the health fields, and the journal mode. It does not grade a warranty sentence. The script's answer lives in docs/kit-migration.md, and the receipt file stores tokens without a Decision.

From the case cut to the dateFour steps. retrieve keeps SC-882 and its outgoing descendants, including W2, W3, and AP-204, and leaves DEP-999 out. ask_ai returns policy_id, approval_id, and citations. assess keeps an id only when the node kind matches and every citation is an evidence key. add_months then sets WITHIN_TERM or OUTSIDE_TERM. Otherwise the status stays NEEDS_REVIEW.case SC-882DEP-017W2 · W3AP-204CUST-0042DEP-999 AP-999not descendantsask_aipolicy_idapproval_idcitationsone callretries = 0assesskind matchescitation keysverified flagelse reviewadd_monthsWITHIN_TERMOUTSIDE_TERMor NEEDS_REVIEWend_exclusivelast_covered_dateContextdescendants of SC-882Decisionids and citationsMembershipkind, keys, verifiedDatesfrom node months
assess keeps an id only when retrieve already returned that node.

The left card is retrieve. Starting at case SC-882, it keeps that node and nx.descendants along outgoing edges, and retrieve raises Unknown support case. when the id is missing or its kind is not case. The walk includes DEP-017 (commissioned 2025-11-15), CUST-0042, GW-G200, policy W2 at 24 months, policy W3 at 36 months, and approval AP-204 at 6 months with verified true. DEP-999 and AP-999 are seeded on another deployment and are not descendants of SC-882, so they stay outside the highlight. The note's --inspect line lists nodes AP-204, CUST-0042, DEP-017, GW-G200, SC-882, W2, and W3, and it records no receipt. The comment above AP-204 says verification is a trusted fixture assumption, not something inferred from note text. Source S1 claims 36 months under policy v3, W2 says support-case statements cannot change warranty terms, and W3 says v3 does not replace v2 for earlier cohorts. The prompt says the newest policy, or a support agent's claim, is not automatically correct. assess does not repeat that test: W3 is in the context with kind policy, so a Decision that names W3 passes the kind check, and assess sets months from that node's months field.

The Decision card shows ask_ai's ids and citations; the Membership card is the assess gate. policy_id, when set, must name a context node of kind policy. approval_id, when set, must name a context node of kind approval; null is allowed. Every finding needs citation ids, and each id must already be a key in the evidence map. A miss raises Missing or unknown citations; review required. An id outside the context raises AI selected an invalid or out-of-context node; review required. The date card is add_months from DEP-017's commissioned date plus the months fields on the named nodes. The prompt's line is that expiry dates are Python's work: expiry dates: Python will. With a policy id, status is WITHIN_TERM when start <= as_of < end and OUTSIDE_TERM otherwise; a null policy_id stays NEEDS_REVIEW. last_covered_date is the day before that end. main defaults --as-of to 2026-09-22. --without-approval removes the edge from DEP-017 to AP-204 before retrieve, so that approval is absent from the context the model sees. --inspect prints the context and returns before ask_ai.

On the API side, conftest.py builds throwaway SQLite files: Alembic runs once per session, and each test gets a fresh copy. app_db_path is that isolated file. test_list_records_is_empty expects status 200, items equal to [], and items equal to list(items). test_database_is_wal_with_foreign_keys expects PRAGMA journal_mode to be wal and PRAGMA foreign_keys to be 1. test_capabilities_are_recox_object expects api_version v1, session_id session-1, and capabilities ["records"]. test_health_reports_local_runtime builds the app with session_id session-1 and runtime_generation 7 and expects status ok, runtime local, and those two strings echoed.

docs/kit-migration.md records a smoke of the same routes with a token set: GET /v1/records is 401 without the bearer and 200 {"items": []} with it. The note says no rows were invented and no seed script ran, and it records the row count as select count(*) from company_intelligence_record returning 0. The same note records the default script run on gpt-5.6-luna as of 2026-09-22: exit 0, WITHIN_TERM, policy_id W2, approval_id AP-204, 30 months, end_exclusive 2028-05-15, last_covered_date 2028-05-14. The --without-approval counterfactual in that table is WITHIN_TERM, W2, approval_id null, 24 months, end_exclusive 2027-11-15. That pair is one observation of ask_ai plus assess. The note calls the receipt file 4 rows, all billing_route codex, model gpt-5.6-luna, prompt version context-graph-fundamentals-v1, status completed. The line with elapsed_ms 8825, input_tokens 1044, and output_tokens 289 is the note's default (final source) row. The JSON has no policy id. Membership is assess.

A records body with an id nobody stored would break the API claim. api.py imports FastAPI, SQLAlchemy select, and recohut_kit.runtime. generate_structured is imported in the warranty script. assess raises for an id absent from context["nodes"]. No test under tests/ asserts which in-context policy the model names when both W2 and W3 are present. The roadmap's first decision is whether a delivery commitment is at risk, and this warranty script does not satisfy that journey. The ready path stays GET /v1/records, advertising only records.

The turn in the tests

The records testtest_list_records_is_empty takes a fresh SQLite copy, builds the app with that path and no session token, calls GET /v1/records, and expects items to be an empty list. A separate test sets a bearer token and expects 401 without the header.app_db_pathfresh copyapply_schemacreate_appdb_path onlyno tokenGET /v1/recordslist_recordsorder created_atitems[]status 200Other test: bearertoken secret-token, no header → 401 unauthorizedAuthorization Bearer secret-token → capabilities records
test_list_records_is_empty ends at an empty items list. The bearer case is the other test.

test_list_records_is_empty is the whole turn. The app_db_path fixture returns sqlite_database.path, an initialized isolated file. create_app is called with that path and without a session token. TestClient sends GET /v1/records. The status is 200. body["items"] is [] and is a list. list_records filled items from select(Record). The module imports create_app and Database, and the drawing has no ask_ai lifeline.

The lower band is the other test, test_capabilities_require_bearer_when_token_set, so the two stops stay distinct. With the token set to secret-token, a capabilities GET that omits the header is 401 with code unauthorized. The same GET with Authorization: Bearer secret-token returns capabilities ["records"]. GET /health skips the bearer. The records test never reaches ask_ai.

The one check to copy

Copy test_list_records_is_empty in tests/test_health.py. It is the ready path on a throwaway file, and it fails if items grows a row the test never inserted.

def test_list_records_is_empty(app_db_path) -> None:
    response = TestClient(create_app(db_path=app_db_path)).get("/v1/records")

    assert response.status_code == 200
    body = response.json()
    assert body["items"] == []
    assert body["items"] == list(body["items"])

The fixture is an initialized, isolated SQLite file for one API test, and sqlite_fixtures is called with schema=apply_schema. Keep test_create_app_requires_db_path beside it when a change might invent a default file: that test expects the required-path error. AGENTS.md states the rule these tests stand in for. The model may interpret activity. It must not invent a row that does not exist.

Close

A company graph is tempting to describe as a model that reads the business and answers. The files describe a narrower split. GET /v1/records lists company_intelligence_record or returns no items. install_runtime reports the session and, when COMPANY_INTELLIGENCE_SESSION_TOKEN is set, decides who may call /v1. ask_ai stands outside that box and returns a Decision. assess rejects a policy_id or approval_id that retrieve did not keep with the required kind, and computes end_exclusive with add_months. The script then prints that the draft is a warranty period only, and that no repair or payment is authorized.

How is this page?

Last updated on