Skip to content

POST /api/packets INSERTs on the server's read-only handle and always returns 500 #223

Description

@dborup

Relates to #215, #222

Problem

handlePostPacket (cmd/server/routes.go, POST /api/packets, behind requireAPIKey) writes transmissions, observers and observations through s.db.conn. The server opens that handle with mode=ro (Kpa-clawbot#1283).

  • In production every call fails with attempt to write a readonly database and returns 500, with the raw SQLite error text in the response.
  • Route tests pass only because they run against a writable test DB.
  • The handler also inserts without a by-hash lookup, so a repeated packet would violate transmissions.hash UNIQUE even on a writable DB.

This was confirmed in the #222 review with a probe: OpenDB (mode=ro) plus a POST with a valid key returns 500, and the DB stays unchanged. In practice the endpoint has been dead since the read/write split.

Options

  • (a) Hand the packet to the ingestor so the write happens where all writes live, e.g. via a queue or command table, or by republishing it over MQTT.
  • (b) Remove the endpoint and its OpenAPI entry, if nothing uses it.

In both cases:

  • remove routes.go from knownServerWriteSQL;
  • extend TestServerHasNoPacketTableWrites to forbid INSERT everywhere in cmd/server;
  • add a test that POSTs against an OpenDB (mode=ro) store.

Acceptance

  • No write SQL left in cmd/server outside the documented exceptions (ping_score_history.go, backup.go).
  • The endpoint either works through the ingestor or is removed, and the OpenAPI spec matches.
  • A read-only-handle test pins the behaviour.
  • No raw SQLite error text in API responses.

Activity

  1. added a commit that references this issue on Oct 5, 2026
  2. dborup commented on Oct 5, 2026

    @dborup
    OwnerAuthor

    Fixed by #231 (merged as 2a7877ac).

    POST /api/packets and its handler, helpers, OpenAPI entry, docs, proto and tool references are removed. PayloadJSON in cmd/server is removed too. One unified guard now forbids INSERT, UPDATE, DELETE and REPLACE on the packet tables everywhere in cmd/server, and an OpenAPI orphan-description test was added.

    Note: in production wiring, POST /api/packets now falls through to the SPA catch-all (200 index.html). That is tracked in #233.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions