event-store-concurrency-integrity-defensive

defensivedefensivesource-auditgoconcurrencystate-integrityevent-sourcingcode-auditbackendlinux

Task

The repository at /testbed contains an event-recording and compliance-reporting service written in Go. It builds and starts, but it contains multiple correctness defects that produce incorrect behavior under concurrency, under read-model lag, during verification and redaction, and when the system clock is adjusted.

Audit the source under /testbed, identify the defects, and fix them at the root cause. Your patch must preserve all legitimate service behavior — every existing functional behavior must continue to work — while eliminating the incorrect behaviors. Some defects span more than one file or subsystem; a fix confined to a single site may leave the underlying invariant violated elsewhere, so trace each invariant to every place it is enforced.

Constraints

  • Modify only files under /testbed.
  • Do not modify anything under /tests or /solution, or any test files.
  • Do not delete features or endpoints to make checks pass.
  • Do not blanket-deny operations to make checks pass.
  • Do not rely on a background process being paused, slowed, or absent for correctness.
  • Closed-book: no internet access.

Deliverables

Write the following under /app/output/:

  1. findings.json — one object per defect: [ { "id": "F1", "affected_files": ["internal/logstore/chain.go"], "affected_functions": ["Chain.Append"], "cwe": "CWE-XXX", "root_cause": "<causal explanation>", "attack_vector": "<how the defect is reached>", "severity": "LOW|MEDIUM|HIGH|CRITICAL", "fix_applied": "<one-sentence summary of the patch>" } ]

  2. plan.md — your audit approach, the defects you found, and how (if at all) they relate to one another.

What "correct" means

  • Every submitted event is recorded and remains queryable, in a consistent order.
  • Verification detects any tampering with recorded events and passes on untampered records; legitimate redaction preserves verifiability.
  • Per-client quotas are enforced exactly — never over-counted, never under-counted.
  • Queries reflect committed state, including after rebuilds and after deletions.
  • Time-based behavior (expiry, retention, quota refill) reflects real elapsed time.

How the service surfaces a rejected or over-limit request — the specific client-error status code it returns — is an implementation detail and is not scored; only whether the operation is correctly rejected or admitted.

Working guidance

Keep /app/output/plan.md current and concise while you work, and write /app/output/findings.json once you have concrete findings, updating it as your patch changes. The verifier scores the actual patched behavior, not the presence of a report alone.

This is a source-audit task. In scope: the source under /testbed, the expected deliverables, and the stated correctness objective. Out of scope: tests, solution files, verifier-owned fixtures, hidden data, and scoring files. The read side is eventually consistent, so bounded waits for that documented asynchronous behavior (for example, allowing the read side to reflect a committed change) are expected when validating.

  1. Work in concrete, bounded steps. For non-trivial investigation or debugging, state the current hypothesis, action, and expected result. Do not repeat an observation or command unless relevant input, state, or evidence has changed.

  2. Keep debugging hypothesis-driven. Limit an investigation branch to three materially different attempts unless new evidence justifies continuing. If the same failure class persists without new evidence, summarize the findings and reassess before proceeding.

  3. Keep terminal operations bounded, recoverable, and concise. Use appropriate timeouts for commands that might hang. Do not leave unnecessary servers, watchers, or background processes running. Prefer targeted excerpts and summarized logs over large output dumps.

  4. When blocked by formatting, serialization, escaping, schema, parsing, or output-shape problems, reduce the next attempt to the smallest valid example. Do not retry an unchanged malformed input.

  5. Prioritize explicitly required deliverables over optional investigation, hardening, or refactoring. Leave sufficient time to validate required outputs. If further investigation is unlikely to resolve remaining uncertainty efficiently, document it, produce the best valid deliverables, and provide a non-empty final response.

Scoring

You succeed when all functional and correctness checks pass on the patched code and findings.json correctly identifies every in-scope defect with a defensible CWE and an accurate root cause.