All jobs

Add an Audit Log to a Quarkus API

Yes. An agent adds Hibernate Envers to your Quarkus app so every change to an entity is versioned, exposes a history endpoint, proves it with tests and opens a PR.

Run this on RushOpens the console with this prompt ready to send, in a Project that has your repository.

What the agent does

The agent clones the service into its own cloud sandbox and reads the persistence layer before it adds anything. In a Quarkus app like the hibernate-orm-panache-quickstart in quarkusio/quarkus-quickstarts, pom.xml imports the quarkus-bom at 3.40.1.1 and depends on quarkus-hibernate-orm-panache, quarkus-rest-jackson and quarkus-jdbc-postgresql, with quarkus-junit and REST Assured for tests. There are two entities with the same shape: FruitEntity extends PanacheEntity and is served by FruitEntityResource under /entity/fruits, and Fruit with a FruitRepository is served under /repository/fruits; both have a unique name column of length 40 and are marked @Cacheable. application.properties turns on SQL logging and loads import.sql, which inserts Cherry, Apple and Banana into each table and restarts the sequences at 4, and FruitsEndpointTest runs the same list-delete-list sequence against both paths.

The agent adds the quarkus-hibernate-envers extension to pom.xml and annotates both entities with @Audited, so Hibernate writes a row to fruitentity_AUD or fruit_AUD and to REVINFO inside the same transaction as every insert, update and delete. It sets quarkus.hibernate-envers.store-data-at-delete=true so a deleted fruit's last name is kept with its delete revision rather than nulled out, which is what makes the log readable later. Because the test and dev profiles have no datasource configured, Dev Services starts a PostgreSQL container and the schema is dropped and created on boot, so the audit tables appear without a migration; the agent notes in the pull request that a production database with a managed schema needs the two tables added by its migration tool.

Then it makes the history reachable. Each resource gets a GET {id}/history method that obtains an AuditReader from the injected EntityManager and returns a list of revisions, each with the revision number, its timestamp, the RevisionType as ADD, MOD or DEL, and the entity's state at that revision, mapped to a small FruitRevision record so the response does not leak Envers internals. It adds a RevisionListener that fills a custom revision entity with the caller's identity read from a request header the prompt names, so the log answers who as well as what, and documents that the header is a placeholder until the service has real authentication.

The proof follows the existing test. FruitsEndpointTest already deletes fruit 1 on each path; the agent extends performTest to rename fruit 2 with a PUT, then calls GET {path}/1/history and GET {path}/2/history and asserts a DEL revision still carrying the name Cherry and a MOD revision with the new name. It also asserts that fruits seeded through import.sql have no ADD revision, because import.sql bypasses Hibernate, and says so in the pull request so nobody expects a history for rows loaded that way. It runs ./mvnw test in the module, which boots Quarkus against the Dev Services PostgreSQL container, and reads the SQL log to confirm the _AUD inserts happen in the same transaction as the change.

Start it with one API call

POST https://api.phoenix.so/o/{org}/sessions with this body:

{
  "agent": "claude",
  "input": "Add an audit log to this Quarkus service with Hibernate Envers. Read pom.xml, src/main/resources/application.properties, import.sql, both Fruit entities, both resources and FruitsEndpointTest first. Add the quarkus-hibernate-envers extension, annotate FruitEntity and Fruit with @Audited, and set quarkus.hibernate-envers.store-data-at-delete=true. Add GET {id}/history to both resources, returning a list of FruitRevision records with revision number, timestamp, revision type and the entity state, built from an AuditReader on the injected EntityManager. Add a custom revision entity and RevisionListener that records the caller from an X-Actor header, documented as a placeholder for real authentication. Extend FruitsEndpointTest to rename a fruit with PUT, then assert the history of the deleted fruit has a DEL revision that still carries its name and the renamed fruit has a MOD revision, and assert seeded rows have no ADD revision. Run ./mvnw test with Dev Services, confirm the _AUD inserts appear in the SQL log, and open a pull request that lists the endpoints, the configuration, the test output and what a managed production schema must add.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
  1. Get an API key. In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
  2. Send the request. POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
  3. Read what came back. Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

What comes back

What comes back is a pull request on its own branch changing pom.xml and application.properties, both entity classes and both resources, and adding a FruitRevision record, a revision entity with its RevisionListener, and the new assertions in FruitsEndpointTest. import.sql and the existing endpoints keep their behaviour, so clients of /entity/fruits and /repository/fruits see no change except the new history path under each.

The description names the two audit tables and REVINFO, the property that keeps data at delete, the header the listener reads, and the ./mvnw test summary, and it includes the SQL log lines showing an _AUD insert in the same transaction as a delete. The transcript at GET /o/{org}/sessions/{id}/messages keeps the Dev Services container start and the full Maven output, so a reviewer can see the tests run against a real PostgreSQL rather than read that they did.

Before merging, a reviewer checks that the revision listener fails safe when the header is absent, that the history endpoint maps Envers types to plain strings, and that the migration note covers both _AUD tables and REVINFO with the sequence Envers expects. A follow-up on the same session can add the schema change to Flyway or Liquibase once the project adopts one.

Run it on every Linear issue labelled compliance

Add an automation to the Project with this prompt and a linear trigger on linear.issue.labeled, filtered to the compliance label. When someone labels an issue such as "keep a history of every change to orders", the trigger places the issue after the prompt, the run reads which entities the issue names, and the pull request links back to it. Only label changes made by a person in your Rush org fire the trigger, and the automation starts at most max_runs_per_hour runs in an hour.

From a script, the same body goes to POST /o/{org}/sessions with the repository in resources, the issue URL as a second resource, and a request_id that is a UUID v5 of the issue id so a retry returns the run already started. Give the key a webhook_url and every run the key starts posts run.completed with data.session_url, from which a handler reads the pull request link.

The use case this job follows, with its automation and trigger: Turn a Linear label into a PR.

Why run it on Rush?

An audit log is a correctness feature: a revision missing because a write path bypassed the entity manager, or a delete that nulls the data it was meant to preserve, is a log that lies. The agent proves the behaviour by changing and deleting rows against a real PostgreSQL started by Dev Services in its own sandbox, reading the SQL that Hibernate actually ran, and encoding each expectation as a test the next change has to keep passing.

The Maven output and the SQL log stay in the run's transcript, so a reviewer can see the _AUD inserts rather than trust the description. Several services can get the same change at once, each in its own sandbox and its own pull request, while the laptop that filed the issue stays free.

Frequently asked questions

Will the seeded rows have a history?

No. import.sql runs as plain SQL at startup and bypasses Hibernate, so Envers never sees those inserts and the first revision of a seeded fruit is its first change. The agent asserts this in the test and states it in the pull request so the gap is a known one rather than a surprise.

Does it need a database migration?

Not in dev and test, where Dev Services starts PostgreSQL and the schema is dropped and created on boot, so REVINFO and the _AUD tables appear by themselves. A production database with a managed schema needs them added by its migration tool, and the pull request lists the tables and the sequence to create.

Who does the log say made the change?

Whatever the RevisionListener reads from the request, which in this pull request is a header named in the prompt because the quickstart has no authentication. Once the service has a security identity, the listener changes to read it in one place and the stored revisions keep their shape.

Does auditing slow down writes?

Each audited insert, update or delete writes one extra row per audited entity plus a REVINFO row in the same transaction, and reads are unaffected. The SQL log the agent keeps shows exactly which statements were added, so the cost is visible rather than estimated.

More Quarkus jobs

The same job on other stacks

Keep reading