Skip to content
Agent Field Notes
Course contentsExpand a topic to choose a lesson.

SYSTEMATIC LEARNING / FOUR-LEVEL COURSE

Objects, sources, and bitemporal reasoning in memory conflicts

Examine fact versions, validity times, source priority, and conflict presentation.

Learning objectives: Two memories will conflict only if they have the same object, the same attributes, the same scope and overlapping validity time. The recording time cannot replace the business effective time, and similarity cannot determine the facts.

Content checked: 2026-10-03 · Each level has independent explanations, tasks and inspections

Choose a starting point based on your familiarity with this topic. Current level: Design · Explain the trade-offs. After completing the task, continue to the next level. Reading and self-checks alone do not establish mastery.

On this level

Review the prerequisites

Suitable for: Backend developers learning Agent applications.

Objects, sources, and bitemporal reasoning in memory conflicts
Two memories will conflict only if they have the same object, the same attributes, the same scope and overlapping validity time. The recording time cannot replace the business effective time, and similarity cannot determine the facts.

How does the mechanism work?

Step-by-step explanation
  1. Is the latest imported one necessarily the latest and valid?

    Move from apparent conflicts to distinctions between time dimensions.

  2. How to isolate the technology stacks of different projects for the same user?

    Contradictory descriptions may concern different entities; separate them before resolving the conflict.

  3. Can it still be displayed for historical query after cancellation?

    A fact's historical validity and current read authorization are independent dimensions.

Design · Explain the trade-offs

Changed constraints and integration decision

Objectives of this level: effective/observed time, explicit correction and conflict provenance — Apply a changed constraint and scope the proposed platform adapter.

Visual guide · Two clocks and current access

Two clocks and current access

Resolve conflicts only among the same object, attribute and scope with overlapping validity. Observation time is not business effective time. Select the figure to open it at full size.

Changed constraints and integration decision

Use explicit-correction but known_at=5: f-old/en. Keep known_at30 but move valid_at to5: the new fact starting10 is ineligible. Set f-old.revoked=True: old access disappears even in a past-time query. Write an adapter design with trusted metadata/CAS and retention/deletion decisions; the pure view neither persists history nor compensates actions already taken. Deliver a new-input JSON/result pair, an adapter boundary sketch and a short ADR comparing two alternatives, rejection/reconciliation behavior, ownership and reversal conditions. State implemented_local versus planned; connect to the same after-sales proposal/approval/merchant/receipt chain without inventing existing runtime features. Save the following block as memory_conflict_time_variants.py beside your student module, then run it after implementation. It imports your own function, reads the public complete inputs and changes the declared fields; these two rule-visible variants are not unseen assessment.

import copy, json
from pathlib import Path
from memory_conflict_time_student import resolve_memory

checks = json.loads(Path("cases/memory-conflict-time.json").read_text())["checks"]

payload = copy.deepcopy(checks[1]["input"])
payload["query"]["valid_at"] = 5
before = copy.deepcopy(payload)
try:
    actual = resolve_memory(payload)
except ValueError as exc:
    actual = "ValueError:" + str(exc)
assert payload == before, "input_mutation"
expected = {'state': 'value', 'value': 'en', 'sources': ['f-old']}
assert actual == expected, (actual, expected)
print(json.dumps({"variant":1,"input":payload,"actual":actual}, sort_keys=True))

payload = copy.deepcopy(checks[0]["input"])
payload["facts"][0]["revoked"] = True
before = copy.deepcopy(payload)
try:
    actual = resolve_memory(payload)
except ValueError as exc:
    actual = "ValueError:" + str(exc)
assert payload == before, "input_mutation"
expected = {'state': 'missing', 'value': None, 'sources': []}
assert actual == expected, (actual, expected)
print(json.dumps({"variant":2,"input":payload,"actual":actual}, sort_keys=True))
python3 memory_conflict_time_variants.py

Starting point and evidence

Download the source-only ZIP, extract it, and work in extended-agent-practice-v1 with lab_runner.py beside cases/. Python3.9+ standard library; no model, cloud, network or business request is made. Scaffold once in a fresh directory; it refuses overwrite. Reuse your module in later tracks. The empty template must exit1 on grade; scaffold exits0, overwrite exits2. Grade exits0 only when every fixed case passes and otherwise exits1.

  • https://ai.lwkjob.com/downloads/extended-agent-practice-v1.zip
  • https://ai.lwkjob.com/lab/extended-practice/lab_runner.py
  • https://ai.lwkjob.com/lab/extended-practice/cases/memory-conflict-time.json
python3 lab_runner.py scaffold --course memory-conflict-time --out memory_conflict_time_student.py
python3 lab_runner.py grade --course memory-conflict-time --module memory_conflict_time_student.py --out memory_conflict_time_before.json

This course has12 public fixed cases. Each calls your resolve_memory(payload), records input/expected/actual/error, strict JSON types, input immutability and no output-container aliases, plus module/runner/cases SHA and Python version. Inputs are complete JSON fixtures. Unknown or missing keys, null outside explicitly allowed fields, wrong types, duplicate IDs/list members where uniqueness is required raise ValueError:input_shape; booleans are not integers. Exceptions match exact class:message. Return fresh JSON values without mutating input.

Trusted identity, approvals, receipts and policy/index metadata are fixtures assembled by the exercise. In a real service the server must obtain them from authenticated/current authority sources; accepting client JSON with these labels does not authenticate it. The function is a decision over that trusted snapshot, not the adapter or race-proof enforcement.

Local function contract

payload exactly principal/query/facts. principal exactly tenant/user/project(nonempty str),enabled(strict bool). query exactly attribute(nonempty str),valid_at/known_at(strict nonnegative int). facts may be empty; each exactly id/tenant/user/project/attribute/value(nonempty str),valid_from/observed_at(strict nonnegative int),valid_to(None or strict int>valid_from),source(confirmed/inferred),supersedes(None or nonempty str),revoked(strict bool); unique IDs globally. Shape validation first. Disabled principal returns denied/None/[] using keys state/value/sources. Select same tenant/user/project/attribute,currently not revoked,valid_from<=valid_at<valid_to(no upper bound when None),observed_at<=known_at. If any eligible confirmed facts exist, discard eligible inferred facts. Build supersedes links only between remaining eligible IDs; a self/cyclic correction chain raises ValueError:correction_cycle. Remove IDs explicitly superseded by remaining eligible facts. No survivors: missing/None/[]; all survivor values equal: value/that value/sorted source IDs; differing values: conflict/None/sorted source IDs. Output is exactly state,value,sources; preserve multiple same-value sources. No observation-recency tie breaker or invented merged value.

def resolve_memory(payload):
    raise NotImplementedError("Implement the public local contract")

Three reviewable inputs

explicit-correction

{
  "principal": {
    "tenant": "acme",
    "user": "alice",
    "project": "after-sales",
    "enabled": true
  },
  "query": {
    "attribute": "report_language",
    "valid_at": 15,
    "known_at": 30
  },
  "facts": [
    {
      "id": "f-old",
      "tenant": "acme",
      "user": "alice",
      "project": "after-sales",
      "attribute": "report_language",
      "value": "en",
      "valid_from": 0,
      "valid_to": null,
      "observed_at": 1,
      "source": "confirmed",
      "supersedes": null,
      "revoked": false
    },
    {
      "id": "f-new",
      "tenant": "acme",
      "user": "alice",
      "project": "after-sales",
      "attribute": "report_language",
      "value": "zh",
      "valid_from": 10,
      "valid_to": null,
      "observed_at": 12,
      "source": "confirmed",
      "supersedes": "f-old",
      "revoked": false
    }
  ]
}

Expected / 预期: {"sources": ["f-new"], "state": "value", "value": "zh"}

late-old-import

{
  "principal": {
    "tenant": "acme",
    "user": "alice",
    "project": "after-sales",
    "enabled": true
  },
  "query": {
    "attribute": "report_language",
    "valid_at": 15,
    "known_at": 30
  },
  "facts": [
    {
      "id": "f-old",
      "tenant": "acme",
      "user": "alice",
      "project": "after-sales",
      "attribute": "report_language",
      "value": "en",
      "valid_from": 0,
      "valid_to": 10,
      "observed_at": 1,
      "source": "confirmed",
      "supersedes": null,
      "revoked": false
    },
    {
      "id": "f-new",
      "tenant": "acme",
      "user": "alice",
      "project": "after-sales",
      "attribute": "report_language",
      "value": "zh",
      "valid_from": 10,
      "valid_to": null,
      "observed_at": 12,
      "source": "confirmed",
      "supersedes": null,
      "revoked": false
    },
    {
      "id": "f-late",
      "tenant": "acme",
      "user": "alice",
      "project": "after-sales",
      "attribute": "report_language",
      "value": "fr",
      "valid_from": 0,
      "valid_to": 10,
      "observed_at": 25,
      "source": "confirmed",
      "supersedes": null,
      "revoked": false
    }
  ]
}

Expected / 预期: {"sources": ["f-new"], "state": "value", "value": "zh"}

equally-confirmed-conflict

{
  "principal": {
    "tenant": "acme",
    "user": "alice",
    "project": "after-sales",
    "enabled": true
  },
  "query": {
    "attribute": "report_language",
    "valid_at": 15,
    "known_at": 30
  },
  "facts": [
    {
      "id": "f-old",
      "tenant": "acme",
      "user": "alice",
      "project": "after-sales",
      "attribute": "report_language",
      "value": "en",
      "valid_from": 0,
      "valid_to": null,
      "observed_at": 1,
      "source": "confirmed",
      "supersedes": null,
      "revoked": false
    },
    {
      "id": "f-second",
      "tenant": "acme",
      "user": "alice",
      "project": "after-sales",
      "attribute": "report_language",
      "value": "zh",
      "valid_from": 0,
      "valid_to": null,
      "observed_at": 20,
      "source": "confirmed",
      "supersedes": null,
      "revoked": false
    }
  ]
}

Expected / 预期: {"sources": ["f-old", "f-second"], "state": "conflict", "value": null}

Responsibility and limits

Junior derives valid/observed-time views and implements conflict outputs. Intermediate would add source/correction lineage and conditional writes with historical/new-task regression. Senior decides when bitemporal complexity is warranted and owns privacy, restore/tombstone, concurrent corrections and audit failure windows. This integer-time fixture does not implement a production bitemporal database. The four tracks are learning activities, not job ranks. Fixed authored examples and known repairs cannot prove independent diagnosis, real-world security or hiring readiness. Keep source, initial failure, personal diff, same-input rerun and a declared changed-condition result. A reviewer-new complete contract and observed personal work are separate; disclose assistance. The five-second worker guard is not a performance SLO or hostile-code sandbox.

Continue to do advanced research experiments

Why can’t the old context continue to be used after the policy changes?

Transferring pre-retrieval filtered ideas to memory versions and recovery. Observe how existing drafts become invalid after cancellation.

Read full text and fault analysis → · Download experiment package ↓

python3 cli.py memory-put --db memory.sqlite
python3 cli.py submit --db memory.sqlite
python3 cli.py run --db memory.sqlite --lease-seconds 2 --fault after_draft
python3 cli.py memory-forget --db memory.sqlite
# 等待至少 2 秒后分别执行
python3 cli.py run --db memory.sqlite
python3 cli.py inspect --db memory.sqlite

Keep evidence and check item by item

  • The draft checkpoint already exists after the first exit.
  • Recovery after memory-forget gets failed with memory_changed_or_expired.
  • No publish checkpoint; explain the difference between fail blocking and complete deletion.

Verify local scope, version, and undo blocking; old checkpoints remain, no complete deletion of logs, backups, or checkpoints is provided.

code example

Changed constraints and integration decision — equally-confirmed-conflict

Additional review: explain why this case follows the contract and which single-field change would alter the branch. Public case: equally-confirmed-conflict Expected / 预期: {"sources": ["f-old", "f-second"], "state": "conflict", "value": null} https://ai.lwkjob.com/lab/extended-practice/cases/memory-conflict-time.json

Acceptance task for this level

effective/observed time, explicit correction and conflict provenance — Execute the declared changed inputs and deliver result pairs plus an adapter/ADR with implemented versus planned boundaries.

Acceptance self-checks

Reading this browser’s record…

Hide the answer and check your understanding

May a historical query revive revoked content?

Further explanations and practice

When encountering unfamiliar principles, first read the implementation, continuous questioning and migration cases, and then independently explain the premise and boundaries. Answers and notes are saved to the original account record.

All linked explanations and exercises (1 )

Sources and verification scope

The principles are based on public information; the numbers, cases and tasks are the teaching design of this website. Offline experiments verify the range noted on this page, and the learning effect still needs to be judged through independent tasks and feedback.