{"record":{"id":"5d55150fd83e2245","repo":"t8y2/dbx","slug":"etcd-invalid-revision","errorCode":"ETCD_INVALID_REVISION","errorMessage":"ETCD_INVALID_REVISION: revision was already compacted at ","messagePattern":"ETCD_INVALID_REVISION: revision was already compacted at ","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"agents/drivers/etcd-go/maintenance.go","lineNumber":32,"sourceCode":"\treturn json.Unmarshal(raw, target)\n}\n\nfunc (s *etcdSession) compact(params map[string]json.RawMessage) (any, error) {\n\trevision, err := requiredPositiveLong(params, \"revision\")\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tclient, err := s.activeClient()\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tctx, cancel := context.WithTimeout(context.Background(), rpcTimeoutSeconds*time.Second)\n\t_, err = client.Get(ctx, \"\\x00\", clientv3.WithRange(\"\\x00\"), clientv3.WithCountOnly(), clientv3.WithRev(revision))\n\tcancel()\n\tif err != nil {\n\t\tif errors.Is(err, rpctypes.ErrCompacted) {\n\t\t\tif compacted, ok := compactedRevisionOf(client, \"\\x00\"); ok {\n\t\t\t\treturn nil, errors.New(\"ETCD_INVALID_REVISION: revision was already compacted at \" + longString(compacted))\n\t\t\t}\n\t\t\treturn nil, errors.New(\"ETCD_INVALID_REVISION: revision was already compacted\")\n\t\t}\n\t\treturn nil, err\n\t}\n\tcurrentCtx, currentCancel := context.WithTimeout(context.Background(), rpcTimeoutSeconds*time.Second)\n\tcurrent, err := client.Get(currentCtx, \"\\x00\", clientv3.WithRange(\"\\x00\"), clientv3.WithCountOnly())\n\tcurrentCancel()\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tif revision > current.Header.Revision {\n\t\treturn nil, errors.New(\"ETCD_INVALID_REVISION: revision is newer than the current revision\")\n\t}\n\tcompactCtx, compactCancel := context.WithTimeout(context.Background(), rpcTimeoutSeconds*time.Second)\n\tdefer compactCancel()\n\tif _, err := client.Compact(compactCtx, revision); err != nil {\n\t\treturn nil, err","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/agents/drivers/etcd-go/maintenance.go#L14-L50","documentation":"compact first probes the requested revision with a count-only Get at that revision; if etcd replies rpctypes.ErrCompacted, the revision has already been compacted server-side. When compactedRevisionOf succeeds in reading the current compacted revision, the error message includes it: \"ETCD_INVALID_REVISION: revision was already compacted at <N>\". This distinguishes 'too old' from the newer-than-current case handled separately.","triggerScenarios":"Calling compact (via handle) with a revision lower than the cluster's current compacted revision; maintenance.go:32 returns this exact message after compactedRevisionOf reports the compact point.","commonSituations":"Re-running a compaction script that already succeeded; compacting to a revision captured long ago while periodic auto-compaction advanced the compacted frontier; coordinating multiple operators who compact concurrently.","solutions":["Parse the compacted revision from the message and only request revisions > that value.","Read the current revision (e.g. a Get's header.revision) and compact from current minus your desired history window.","Make the compaction job idempotent: treat 'already compacted at N' as success and skip.","Coordinate with etcd's --auto-compaction-mode/retention so manual compaction is rarely needed."],"exampleFix":"// before: stale revision from hours ago\nagent.call(\"compact\", {\"revision\": 42})\n\n// after: derive from current revision\nhead, _ := agent.call(\"get\", {\"key\": \"cfg/a\"})\nrev := head[\"revision\"].(int64) - 1000 // keep window\nif rev > 42 { agent.call(\"compact\", {\"revision\": rev}) }","handlingStrategy":"validation","validationCode":"head, _ := agent.call(\"get\", map[string]any{\"key\": \"\\x00\", \"countOnly\": true})\ncurrent := head[\"revision\"].(int64)\nif targetRev < current-retainWindow { /* already inside compacted region risk */ }\n// only compact revisions you recently observed on THIS cluster","typeGuard":null,"tryCatchPattern":"_, err := agent.call(\"compact\", map[string]any{\"revision\": rev})\nif err != nil && strings.Contains(err.Error(), \"already compacted\") {\n    return nil // idempotent: compaction already progressed past rev\n}","preventionTips":["Compact from currentRevision - retentionWindow, never a stale hard-coded revision.","Store compaction checkpoints and refresh them each run.","Enable etcd auto-compaction so manual compaction is a fallback only."],"tags":["etcd","compaction","revision","maintenance"],"backgroundTag":"revision-compacted","analyzedSha":"c0390bff16418b651f4728520d99adf8ce48829a","analyzedAt":"2026-09-05T23:05:10.900Z","contentChangedAt":"2026-09-05T23:05:10.900Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}