Repository navigation
Description
Summary
Under sustained concurrent Cypher writes, AGE intermittently fails to resolve a label name and raises an undefined-table error for a relation whose name is not a label at all. The name is made of fragments of the data being written: agtype property keys, property values, and occasionally a single control byte equal to a label id.
The graph's label catalog is correct and unchanged throughout, so this does not look like catalog corruption. It looks like the label name is being read through a pointer that no longer refers to the label.
Version
- Apache AGE 1.7.0 (
PG17/v1.7.0-rc0) - PostgreSQL 17.10 (Debian 17.10-1.pgdg12+1)
- Linux x86_64, AGE loaded via
shared_preload_libraries
What happens
The error surfaces from a CREATE of an edge:
ERROR: relation "mygraph.\x01" does not exist
ERROR: relation "mygraph.<entity name fragment>" does not exist
ERROR: relation "mygraph.dfile_pathsource_idcreated_atdescriptionentity_type<entity name><filename><chunk id>" does not exist
ERROR: relation "mygraph.<text fragment><SEP><text fragment><binary bytes>" does not exist
The third example is the clearest. file_path, source_id, created_at, description and entity_type are the property keys of the edge being created, concatenated, followed by a property value and an identifier. \x01 is chr(1), which is the id of _ag_label_vertex in ag_catalog.ag_label for this graph.
So the resolver appears to be producing a name either from the raw label id or from memory adjacent to the agtype payload, instead of from the label catalog.
A second client-visible form, easy to miss
Not every occurrence reaches the client as an undefined-table error. In 7 of 39 occurrences the bytes in the invalid name are not valid UTF-8 at all, so the Postgres driver fails while decoding the error message itself and no does not exist ever reaches the application:
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x.. in position 60: invalid start byte
Worth stating because anyone monitoring for this by matching on does not exist, or on invalid memory alloc request size, will undercount it. I made exactly that mistake: for two days I matched one signature only, measured zero, and concluded the fault had stopped. It had not. It was running the whole time at roughly one occurrence per 20 documents.
The catalog is fine
Queried during and after the failures, unchanged throughout:
SELECT name, kind, id FROM ag_catalog.ag_label l
JOIN ag_catalog.ag_graph g ON g.graphid = l.graph
WHERE g.name = 'mygraph';
name | kind | id
------------------+------+----
_ag_label_vertex | v | 1
_ag_label_edge | e | 2
base | v | 3
DIRECTED | e | 4Four labels, exactly as expected. information_schema.tables for the graph schema likewise shows four tables. No label named anything like the strings in the errors has ever existed.
Workload shape
The write is an idempotent edge upsert. Edge properties are inlined in the CREATE clause because SET r += {...} does not persist edge properties on AGE (the endpoint ids are parameterised):
SELECT r FROM cypher('mygraph', $$
MATCH (source:base {entity_id: $src_id})
WITH source
MATCH (target:base {entity_id: $tgt_id})
WITH source, target
OPTIONAL MATCH (source)-[old:DIRECTED]-(target)
DELETE old
WITH source, target
CREATE (source)-[r:DIRECTED {`file_path`: "...", `source_id`: "...", `created_at`: 1790828551, `description`: "...", `entity_type`: "..."}]->(target)
RETURN r
$$, $1) AS (r agtype);Conditions when it occurs:
- 3 concurrent writers on separate pooled connections, each running the statement above in its own transaction
- Graph at roughly 500,000 vertices and 1,400,000 edges, and growing
search_pathincludesag_catalog, set per connection- Transaction-scoped advisory locks serialise writers on the same endpoint pair, so two sessions do not write the same edge concurrently. Different edges do proceed concurrently.
- Always on high-degree endpoints: the vertices involved are the most connected in the graph, appearing in a large share of all edges. Low-degree endpoints have not produced it.
- Some property values are large:
source_idcan hold a few hundred separator-joined identifiers.
Frequency
Roughly 3 to 5 failures per 100 documents ingested, where each document performs many edge upserts. Not deterministic, not tied to any particular endpoint pair.
It appeared only late in a large ingest, once the graph had grown to the size below. Early in the same ingest, with the same code and concurrency, it did not occur.
39 occurrences to date. That is a floor, not a total: it counts units of work currently in a failed state, and excludes occurrences that succeeded on a later retry or that I have already requeued and recovered.
Diagnostics
Gathered on the live instance that reproduces this.
Build and configuration
PostgreSQL 17.10 (Debian 17.10-1.pgdg12+1) on x86_64-pc-linux-gnu,
compiled by gcc (Debian 12.2.0-14+deb12u1) 12.2.0, 64-bit
age 1.7.0
shared_preload_libraries = age
Settings that seemed most relevant:
jit on
jit_above_cost 100000
jit_inline_above_cost 500000
jit_optimize_above_cost 500000
shared_buffers 128MB
work_mem 4MB
maintenance_work_mem 64MB
max_connections 100
max_locks_per_transaction 64
max_parallel_workers_per_gather 2
dynamic_shared_memory_type posix
huge_pages try
JIT is enabled. I have not yet tested with jit = off, but given the symptom is a pointer that stops referring to the label, it seemed worth surfacing early in case it narrows things for you. I can run that experiment and report back.
On JIT: it was enabled when I first wrote this up. I have since run the jit = off experiment, with the result under What I ruled out below. The instance now runs jit = off, so everything here comes from a jit = off build.
Graph scale
first capture 2026-10-09
vertices 531,452 736,775
edges 1,492,885 1,931,046
labels 4 4
The label catalog stays correct at the larger size: still exactly _ag_label_vertex, _ag_label_edge, base, DIRECTED. Growth changed the volume of work exposed to the fault, not its character.
Edge property sizes
The faulting operation inlines properties into CREATE, so payload size is a plausible factor. Distribution over all edges, as length(properties::text):
avg 350
p50 289
p99 1,332
max 73,715
So most payloads are small but the tail is three orders of magnitude larger.
Re-measured 2026-10-09, essentially unchanged despite the graph growing about 40%:
avg 356
p50 291
p99 1,401
max 73,715
The bad names, categorised
32 of the 39 occurrences carry a parseable invalid name; the other 7 are the decode form above, where no name can be recovered. Categorised by what the invalid name appears to contain. Described rather than quoted, since the real strings contain customer data, which is itself the point: the memory being read is the payload.
13 plain text fragment (entity name or filename)
7 chunk / task identifier fragment
5 agtype PROPERTY KEYS concatenated, in declaration order
4 non-ASCII or raw bytes
3 property VALUE including my field separator or markup
Length of the invalid name:
n=32 min=1 p50=17 avg=61 max=404
An earlier, smaller sample also produced an empty name, and a single control byte \x01 equal to the id of _ag_label_vertex in this graph.
Not one bad backend
Occurrences are spread across backends rather than concentrated in a poisoned session:
distinct backends that hit it ~10
distinct backends in the window 397
most occurrences in one backend 2
So a session does not appear to "go bad" and stay bad. Each occurrence looks independent.
No STATEMENT is logged with the error
log_min_error_statement = error, yet these errors appear in the log with no accompanying STATEMENT: line, unlike other errors from the same instance in the same window. I do not know whether that is meaningful to you, but it was unexpected and may indicate the error is raised in a context where the statement is not attached.
The faulting operation is known from the client side regardless: it is always the edge upsert shown under Workload shape above, never a read.
State at the moment of failure
I instrumented the instance to snapshot pg_stat_activity and pg_locks the instant either signature hits the log, and to keep a rolling 10 minute window of prior samples. Two faults landed six seconds apart on different backends. Snapshot at the first:
pid | state | wait_type | wait_event | xact_s | query_s | stmt_kind
---------+---------------------+-----------+---------------+--------+---------+-----------------
2367589 | idle in transaction | Client | ClientRead | 1629 | 1629 | sql_select
2369148 | idle in transaction | Client | ClientRead | 1629 | 1629 | sql_select
2369362 | idle in transaction | Client | ClientRead | 796 | 796 | sql_select
2367676 | idle in transaction | Client | ClientRead | 796 | 796 | sql_select
2369855 | active | LWLock | BufferMapping | 1 | 1 | age_edge_upsert
2371337 | active | LWLock | BufferMapping | 1 | 1 | age_other
2371338 | active | LWLock | BufferMapping | 1 | 1 | age_other
2369463 | active | LWLock | BufferMapping | 1 | 1 | age_other
2371329 | active | LWLock | BufferMapping | 1 | 1 | age_other
2371325 | active | LWLock | BufferMapping | 0 | 0 | age_other
2371336 | active | LWLock | BufferMapping | 0 | 0 | age_other
2371328 | active | IO | DataFileRead | 0 | 0 | age_other
2369460 | active | - | - | 1 | 1 | age_other
2369867 | active | - | - | 1 | 1 | age_other
Statements are reduced to a classification deliberately: pg_stat_activity.query holds the Cypher being written, which is the customer data this fault leaks, so I do not record query text anywhere.
Two things stand out. Eleven of sixteen client backends are waiting on LWLock: BufferMapping at the moment of the fault, so there is heavy concurrent buffer-mapping pressure. And four backends sit idle in transaction for 13 to 27 minutes on an identical statement; those are my pooled writers holding a transaction open across application-side work. I am not asserting either is causal, but both are live conditions a short benchmark would not reproduce.
Memory contexts of the faulting backend
The same instrumentation calls pg_log_backend_memory_contexts() on the faulting backend, which is still alive because it is pooled. This is the part I think is most worth your attention.
level: 0; TopMemoryContext: 97792 total in 5 blocks; 12504 free (31 chunks); 85288 used
level: 1; TopTransactionContext: 8192 total in 1 blocks; 7440 free (1 chunks); 752 used
level: 1; delete_vertex_htab: 16810032 total in 13 blocks; 8353992 free (45 chunks); 8456040 used
level: 1; ag_label (seq_name, graph) cache: 16384 total in 2 blocks; 6592 free (5 chunks); 9792 used
level: 1; ag_label (relation) cache: 16384 total in 2 blocks; 6720 free (4 chunks); 9664 used
level: 1; ag_label (graph, id) cache: 16384 total in 2 blocks; 6720 free (4 chunks); 9664 used
level: 1; ag_label (name, graph) cache: 16384 total in 2 blocks; 6720 free (4 chunks); 9664 used
level: 1; ag_graph (namespace) cache: 8192 total in 1 blocks; 616 free (0 chunks); 7576 used
level: 1; ag_graph (name) cache: 16384 total in 2 blocks; 6720 free (4 chunks); 9664 used
delete_vertex_htab is 16.8 MB and sits at level 1, a direct child of TopMemoryContext, while TopTransactionContext holds 752 bytes. So session-lifetime memory is carrying 16.8 MB of delete bookkeeping, and it is not reset when a transaction aborts.
That placement looks deliberate rather than accidental, in src/backend/executor/cypher_delete.c on PG17:
css->vertex_id_htab = hash_create(DELETE_VERTEX_HTAB_NAME,
DELETE_VERTEX_HTAB_SIZE, &hashctl,
HASH_ELEM | HASH_FUNCTION);hashctl.hcxt is never set and HASH_CONTEXT is not passed, so hash_create places the table in TopMemoryContext. It is destroyed in EndCustomScan, which is correct on the normal path, but an error path that skips EndCustomScan would leave it behind, and 16.8 MB of accumulation is consistent with that.
This matters for my workload because the statement is an upsert: it runs OPTIONAL MATCH (source)-[old:DIRECTED]-(target) DELETE old before the CREATE. Every faulting statement therefore goes through this delete path.
What I ruled out
- Catalog corruption.
ag_labelis correct before, during and after. - A DDL storm. My client library was calling
create_graph()on every pool checkout, around 31,000 failed calls an hour against an existing graph. I suspected the repeated failed DDL was invalidating cached label information and removed it entirely. The failure rate did not change, and per unit of work it did not improve at all: 3.3 failures per 100 documents the day the DDL was removed, 5.0 the following day. The DDL storm is not the trigger. - JIT.
jitwas set tooffand reloaded on 2026-10-07, with no other change:
documents failures per 100 documents
48h before (jit=on) 354 4 1.13
~49h after (jit=off) 208 10 4.81
The rate did not fall. I am not claiming jit = off made it worse: over the same window the mean document size in my queue grew substantially, and larger documents mean more edge upserts and larger payloads each, which raises exposure independently. The conclusion I draw is that JIT is not the trigger, and the rate stayed inside the band originally reported. I left jit = off in place.
- A missing or renamed label. The labels in the errors never existed.
- My own string building. The endpoint ids are bound parameters and the property literal is JSON-escaped. The strings in the error are not a quoting artefact of mine; they are the contents of the properties I am legitimately writing, appearing where a label name should be.
A candidate I cannot test myself: #2517 and the PG17 delete path
Combining the memory-context dump with a source comparison, there is a specific difference between master and PG17 in the delete path that my statement exercises on every execution.
master bounds the per-row delete caches to per-tuple memory. PG17 does not:
/* master, src/backend/executor/cypher_delete.c */
old_context = MemoryContextSwitchTo(econtext->ecxt_per_tuple_memory);
...
hashctl.hcxt = CurrentMemoryContext;
qual_cache = hash_create("delete_qual_cache", 8, &hashctl, ...);
idx_hashctl.hcxt = CurrentMemoryContext;
index_cache = hash_create("delete_index_cache", 8, &idx_hashctl, ...);
...
MemoryContextSwitchTo(old_context);
/* PG17, same function: no switch, no per-tuple bound */
hashctl.hcxt = CurrentMemoryContext;
qual_cache = hash_create("delete_qual_cache", 8, &hashctl, ...);That appears to be #2517, Bound per-row memory in writable clauses, merged to master on 2026-09-14. It is not in the line I run:
I run AGE 1.7.0, PG17/v1.7.0-rc0
PG17 branch head 2026-08-26 (#2517 merged 2026-09-14, base master)
PG17 cypher_create.c } last changed 2026-01-20 (#2309)
PG17 cypher_utils.c }
There is also no 1.8.0 on the PG17 line, so I cannot get this by upgrading within PG17.
I want to be careful about how strongly I put this. It is a hypothesis with a mechanism and two pieces of supporting evidence, not a diagnosis. I have already had one plausible-sounding theory on this bug turn out to be wrong: I was confident the create_graph() DDL storm was the trigger, removed it, and the failure rate did not move. So I am not claiming #2517 explains this. I am saying it is in the right function, in the right clause, concerns exactly the kind of allocation lifetime that would produce a label name read from recycled memory, and is absent from my build.
Two questions:
- Does Bound per-row memory in writable clauses #2517 look like it could explain a label name resolved from adjacent memory, or is it unrelated?
- If it is a plausible fit, is a PG17 backport planned?
If it is not planned, I will cherry-pick it onto PG17 locally, build, and run it against the workload that reproduces this at about one occurrence per 20 documents, then report the rate back. That should give a clean signal at no cost to you. Say so if you would rather I test something else.
Impact
Each occurrence aborts the transaction and fails the unit of work. In a long-running ingest this means permanent, silent data loss unless the caller retries, and the error is not distinguishable from a genuine schema problem by its type.
Reproduction and what I can offer
I do not have a minimal standalone reproduction, and I want to be straightforward about why: the fault needs a graph of substantial size and sustained concurrency before it appears. Early in the same ingest, with identical code, concurrency and data shape, it does not occur. It began only once the graph passed roughly half a million vertices.
What I do have is a workload that reproduces it reliably and repeatedly at about 3 to 5 failures per 100 units of work, on an instance I control and can instrument. Everything above was gathered proactively rather than waiting to be asked.
Still on offer:
- cherry-pick and test Bound per-row memory in writable clauses #2517 against the live workload, as above
- capture a stack trace with debug symbols, if you can suggest where to break. One caveat on the memory-context dumps already above: the error aborts the transaction, so by the time it reaches the log the executor context has been reset, and a post-hoc dump may understate what was live at the moment of the fault. If you would rather I break before unwind, tell me where
- shorten the long-lived open transactions, or reduce concurrency, if isolating either is useful
- try a specific patch against the live workload
Tell me which is most useful and I will run it. If none of it helps without a minimal reproduction, say so and I will put effort into building one instead.
@jrgemignani @crdv7 apologies for the direct mention, and please redirect me if there is a better owner. I am mentioning you two because of what you have each touched rather than at random: ag_cache.c on PG17 last changed in Fix issue 2245 - Creating more than 41 vlabels causes crash, and my label catalog stays correct throughout while the name comes back wrong, which is what made me suspect the cache rather than the catalog; and #2517 is the candidate above.
If either of you has triage rights, could the bug label be added? I cannot label on this repo and the issue is currently unlabelled.
Activity
crdv7 commentedon Nov 10, 2026
Thanks for the detailed diagnostics. #2351 is more directly relevant to this issue than #2517 : it copies the label names collected during DELETE initialization, keeping them valid after the catalog scan ends.
Label names outlive the scan that provides them
In
get_all_edge_labels_per_graph()on PG17/v1.7.0-rc0, the code stores the label-name pointers without copying their contents:These names refer to data in the scanned tuples. Neither
DatumGetName()norlappend()copies the name, and this heap-tuple slot does not hold an independent buffer pin.After the scan releases its pins, the buffers can be reused for other pages. However,
css->edge_labelsretains those addresses until DELETE shutdown:See
cypher_delete.candcreate_entity_result_rel_info().This can explain why
ag_labelremains correct while the relation name contains unrelated data. In this version, the shutdown check also runs for an edge-only DELETE: it does not skip opening the edge-label tables when the deleted-vertex set is empty.The relevant change is in #2351
#2351 added name copying in both the index-scan and sequential-scan paths:
See commit
b3a00eea. The important part for this defect is copying the name, rather than using an index.#2517 addresses other writable-clause memory-lifetime issues; it does not change this label-name collection code.
Minimal PG17 change
The name-copying change can be applied independently to the PG17 1.7.0 base, without bringing in the other index optimizations from #2351:
This gives the list its own copy of each name, so the names remain valid after the scan ends. It addresses this specific lifetime defect, but does not establish that every error in your workload has the same cause.
The hash-table cleanup issue is separate
Your observation about
delete_vertex_htabbeing underTopMemoryContextis valid. However,DELETE_VERTEX_HTAB_SIZEis 1,000,000, which is passed tohash_create()as an initial capacity estimate—not an actual entry count. A large context alone therefore does not establish repeated leakage.There is nevertheless an error-path cleanup defect:
If
check_for_connected_edges()raises an error, the subsequenthash_destroy()is skipped. This table is created withoutHASH_CONTEXT, so PostgreSQL allocates its private memory context underTopMemoryContext; normal query or transaction cleanup does not reclaim it.In the failure path described above, the invalid label name can trigger the error and leave the hash table allocated. Fixing the name lifetime does not fix cleanup for other errors that bypass
hash_destroy(). I have not measured accumulation across repeated failures or established how much of the reported memory growth this explains.Backport and remaining observations
In #2450, @jrgemignani described an intention to bring fixes to older PostgreSQL branches, down to PG14, without an ETA, and @MuhammadTahaNaveed offered to help with releases, starting with AGE 1.8.0 for PG15.
The copy-only change above is a focused workaround to evaluate on your existing version. Whether to backport this change, which branches to include, and when to release it are decisions for the AGE maintainers. I cannot confirm an official backport or release schedule.